1 | /* |
2 | * Copyright 2016 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #ifndef GrContextPriv_DEFINED |
9 | #define GrContextPriv_DEFINED |
10 | |
11 | #include "include/gpu/GrDirectContext.h" |
12 | |
13 | class GrAtlasManager; |
14 | class GrBackendFormat; |
15 | class GrBackendRenderTarget; |
16 | class GrOpMemoryPool; |
17 | class GrOnFlushCallbackObject; |
18 | class GrRenderTargetProxy; |
19 | class GrSemaphore; |
20 | class GrSurfaceProxy; |
21 | |
22 | class SkDeferredDisplayList; |
23 | class SkTaskGroup; |
24 | |
25 | /** Class that adds methods to GrContext that are only intended for use internal to Skia. |
26 | This class is purely a privileged window into GrContext. It should never have additional |
27 | data members or virtual methods. */ |
28 | class GrContextPriv { |
29 | public: |
30 | |
31 | // from GrContext_Base |
32 | uint32_t contextID() const { return fContext->contextID(); } |
33 | |
34 | bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); } |
35 | |
36 | const GrContextOptions& options() const { return fContext->options(); } |
37 | |
38 | const GrCaps* caps() const { return fContext->caps(); } |
39 | sk_sp<const GrCaps> refCaps() const; |
40 | |
41 | GrImageContext* asImageContext() { return fContext->asImageContext(); } |
42 | GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); } |
43 | |
44 | // from GrImageContext |
45 | GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); } |
46 | const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); } |
47 | |
48 | /** This is only useful for debug purposes */ |
49 | SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } ) |
50 | |
51 | // from GrRecordingContext |
52 | GrDrawingManager* drawingManager() { return fContext->drawingManager(); } |
53 | |
54 | GrOpMemoryPool* opMemoryPool() { return fContext->arenas().opMemoryPool(); } |
55 | SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); } |
56 | GrRecordingContext::Arenas arenas() { return fContext->arenas(); } |
57 | |
58 | GrStrikeCache* getGrStrikeCache() { return fContext->fStrikeCache.get(); } |
59 | GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); } |
60 | |
61 | /** |
62 | * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.) |
63 | * |
64 | * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to |
65 | * ensure its lifetime is tied to that of the context. |
66 | */ |
67 | void addOnFlushCallbackObject(GrOnFlushCallbackObject*); |
68 | |
69 | GrAuditTrail* auditTrail() { return fContext->auditTrail(); } |
70 | |
71 | /** |
72 | * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves |
73 | * if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context |
74 | * will guarantee that the draws required for those proxies are flushed but it could do more. |
75 | * If no array is provided then all current work will be flushed. |
76 | * |
77 | * It is not necessary to call this before reading the render target via Skia/GrContext. |
78 | * GrContext will detect when it must perform a resolve before reading pixels back from the |
79 | * surface or using it as a texture. |
80 | */ |
81 | GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], int numProxies, const GrFlushInfo&); |
82 | |
83 | /** Version of above that flushes for a single proxy and uses a default GrFlushInfo. Null is |
84 | * allowed. */ |
85 | void flushSurface(GrSurfaceProxy*); |
86 | |
87 | /** |
88 | * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words, |
89 | * did we find a pair of round-trip preserving conversion effects? |
90 | */ |
91 | bool validPMUPMConversionExists(); |
92 | |
93 | /** |
94 | * These functions create premul <-> unpremul effects, using the specialized round-trip effects |
95 | * from GrConfigConversionEffect. |
96 | */ |
97 | std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>); |
98 | std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>); |
99 | |
100 | SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); } |
101 | |
102 | GrResourceProvider* resourceProvider() { return fContext->fResourceProvider; } |
103 | const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider; } |
104 | |
105 | GrResourceCache* getResourceCache() { return fContext->fResourceCache; } |
106 | |
107 | GrGpu* getGpu() { return fContext->fGpu.get(); } |
108 | const GrGpu* getGpu() const { return fContext->fGpu.get(); } |
109 | |
110 | // This accessor should only ever be called by the GrOpFlushState. |
111 | GrAtlasManager* getAtlasManager() { |
112 | return fContext->onGetAtlasManager(); |
113 | } |
114 | |
115 | // This accessor should only ever be called by the GrOpFlushState. |
116 | GrSmallPathAtlasMgr* getSmallPathAtlasMgr() { |
117 | return fContext->onGetSmallPathAtlasMgr(); |
118 | } |
119 | |
120 | void copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest); |
121 | |
122 | bool compile(const GrProgramDesc&, const GrProgramInfo&); |
123 | |
124 | GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; } |
125 | GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const { |
126 | return fContext->fShaderErrorHandler; |
127 | } |
128 | |
129 | GrClientMappedBufferManager* clientMappedBufferManager() { |
130 | return fContext->fMappedBufferManager.get(); |
131 | } |
132 | |
133 | #if GR_TEST_UTILS |
134 | /** Reset GPU stats */ |
135 | void resetGpuStats() const; |
136 | |
137 | /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ |
138 | void dumpCacheStats(SkString*) const; |
139 | void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
140 | void printCacheStats() const; |
141 | |
142 | /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ |
143 | void dumpGpuStats(SkString*) const; |
144 | void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
145 | void printGpuStats() const; |
146 | |
147 | /** These are only active if GR_GPU_STATS == 1. */ |
148 | void resetContextStats() const; |
149 | void dumpContextStats(SkString*) const; |
150 | void dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
151 | void printContextStats() const; |
152 | |
153 | /** Get pointer to atlas texture for given mask format. Note that this wraps an |
154 | actively mutating texture in an SkImage. This could yield unexpected results |
155 | if it gets cached or used more generally. */ |
156 | sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0); |
157 | |
158 | /** |
159 | * Purge all the unlocked resources from the cache. |
160 | * This entry point is mainly meant for timing texture uploads |
161 | * and is not defined in normal builds of Skia. |
162 | */ |
163 | void testingOnly_purgeAllUnlockedResources(); |
164 | |
165 | void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*); |
166 | #endif |
167 | |
168 | private: |
169 | explicit GrContextPriv(GrContext* context) : fContext(context) {} |
170 | GrContextPriv(const GrContextPriv&) = delete; |
171 | GrContextPriv& operator=(const GrContextPriv&) = delete; |
172 | |
173 | // No taking addresses of this type. |
174 | const GrContextPriv* operator&() const; |
175 | GrContextPriv* operator&(); |
176 | |
177 | GrContext* fContext; |
178 | |
179 | friend class GrContext; // to construct/copy this type. |
180 | }; |
181 | |
182 | inline GrContextPriv GrContext::priv() { return GrContextPriv(this); } |
183 | |
184 | inline const GrContextPriv GrContext::priv() const { // NOLINT(readability-const-return-type) |
185 | return GrContextPriv(const_cast<GrContext*>(this)); |
186 | } |
187 | |
188 | #endif |
189 | |