| 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/GrContext.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 | GrContext* asDirectContext() { return fContext->asDirectContext(); } |
| 44 | |
| 45 | // from GrImageContext |
| 46 | GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); } |
| 47 | const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); } |
| 48 | |
| 49 | bool abandoned() const { return fContext->abandoned(); } |
| 50 | |
| 51 | /** This is only useful for debug purposes */ |
| 52 | SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } ) |
| 53 | |
| 54 | // from GrRecordingContext |
| 55 | GrDrawingManager* drawingManager() { return fContext->drawingManager(); } |
| 56 | |
| 57 | GrOpMemoryPool* opMemoryPool() { return fContext->arenas().opMemoryPool(); } |
| 58 | SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); } |
| 59 | GrRecordingContext::Arenas arenas() { return fContext->arenas(); } |
| 60 | |
| 61 | GrStrikeCache* getGrStrikeCache() { return fContext->fStrikeCache.get(); } |
| 62 | GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); } |
| 63 | |
| 64 | /** |
| 65 | * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.) |
| 66 | * |
| 67 | * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to |
| 68 | * ensure its lifetime is tied to that of the context. |
| 69 | */ |
| 70 | void addOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 71 | |
| 72 | GrAuditTrail* auditTrail() { return fContext->auditTrail(); } |
| 73 | |
| 74 | /** |
| 75 | * Create a GrContext without a resource cache |
| 76 | */ |
| 77 | static sk_sp<GrContext> MakeDDL(const sk_sp<GrContextThreadSafeProxy>&); |
| 78 | |
| 79 | /** |
| 80 | * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves |
| 81 | * if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context |
| 82 | * will guarantee that the draws required for those proxies are flushed but it could do more. |
| 83 | * If no array is provided then all current work will be flushed. |
| 84 | * |
| 85 | * It is not necessary to call this before reading the render target via Skia/GrContext. |
| 86 | * GrContext will detect when it must perform a resolve before reading pixels back from the |
| 87 | * surface or using it as a texture. |
| 88 | */ |
| 89 | GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], int numProxies, const GrFlushInfo&); |
| 90 | |
| 91 | /** Version of above that flushes for a single proxy and uses a default GrFlushInfo. Null is |
| 92 | * allowed. */ |
| 93 | void flushSurface(GrSurfaceProxy*); |
| 94 | |
| 95 | /** |
| 96 | * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words, |
| 97 | * did we find a pair of round-trip preserving conversion effects? |
| 98 | */ |
| 99 | bool validPMUPMConversionExists(); |
| 100 | |
| 101 | /** |
| 102 | * These functions create premul <-> unpremul effects, using the specialized round-trip effects |
| 103 | * from GrConfigConversionEffect. |
| 104 | */ |
| 105 | std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>); |
| 106 | std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>); |
| 107 | |
| 108 | SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); } |
| 109 | |
| 110 | GrResourceProvider* resourceProvider() { return fContext->fResourceProvider; } |
| 111 | const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider; } |
| 112 | |
| 113 | GrResourceCache* getResourceCache() { return fContext->fResourceCache; } |
| 114 | |
| 115 | GrGpu* getGpu() { return fContext->fGpu.get(); } |
| 116 | const GrGpu* getGpu() const { return fContext->fGpu.get(); } |
| 117 | |
| 118 | // This accessor should only ever be called by the GrOpFlushState. |
| 119 | GrAtlasManager* getAtlasManager() { |
| 120 | return fContext->onGetAtlasManager(); |
| 121 | } |
| 122 | |
| 123 | void moveRenderTasksToDDL(SkDeferredDisplayList*); |
| 124 | void copyRenderTasksFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest); |
| 125 | |
| 126 | void compile(const GrProgramDesc&, const GrProgramInfo&); |
| 127 | |
| 128 | GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; } |
| 129 | GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const { |
| 130 | return fContext->fShaderErrorHandler; |
| 131 | } |
| 132 | |
| 133 | GrClientMappedBufferManager* clientMappedBufferManager() { |
| 134 | return fContext->fMappedBufferManager.get(); |
| 135 | } |
| 136 | |
| 137 | #if GR_TEST_UTILS |
| 138 | /** Reset GPU stats */ |
| 139 | void resetGpuStats() const ; |
| 140 | |
| 141 | /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ |
| 142 | void dumpCacheStats(SkString*) const; |
| 143 | void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
| 144 | void printCacheStats() const; |
| 145 | |
| 146 | /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ |
| 147 | void dumpGpuStats(SkString*) const; |
| 148 | void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
| 149 | void printGpuStats() const; |
| 150 | |
| 151 | /** Specify the TextBlob cache limit. If the current cache exceeds this limit it will purge. |
| 152 | this is for testing only */ |
| 153 | void testingOnly_setTextBlobCacheLimit(size_t bytes); |
| 154 | |
| 155 | /** Get pointer to atlas texture for given mask format. Note that this wraps an |
| 156 | actively mutating texture in an SkImage. This could yield unexpected results |
| 157 | if it gets cached or used more generally. */ |
| 158 | sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0); |
| 159 | |
| 160 | /** |
| 161 | * Purge all the unlocked resources from the cache. |
| 162 | * This entry point is mainly meant for timing texture uploads |
| 163 | * and is not defined in normal builds of Skia. |
| 164 | */ |
| 165 | void testingOnly_purgeAllUnlockedResources(); |
| 166 | |
| 167 | void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 168 | #endif |
| 169 | |
| 170 | private: |
| 171 | explicit GrContextPriv(GrContext* context) : fContext(context) {} |
| 172 | GrContextPriv(const GrContextPriv&); // unimpl |
| 173 | GrContextPriv& operator=(const GrContextPriv&); // unimpl |
| 174 | |
| 175 | // No taking addresses of this type. |
| 176 | const GrContextPriv* operator&() const; |
| 177 | GrContextPriv* operator&(); |
| 178 | |
| 179 | GrContext* fContext; |
| 180 | |
| 181 | friend class GrContext; // to construct/copy this type. |
| 182 | }; |
| 183 | |
| 184 | inline GrContextPriv GrContext::priv() { return GrContextPriv(this); } |
| 185 | |
| 186 | inline const GrContextPriv GrContext::priv() const { |
| 187 | return GrContextPriv(const_cast<GrContext*>(this)); |
| 188 | } |
| 189 | |
| 190 | #endif |
| 191 |