robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 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 | |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 11 | #include "include/gpu/GrDirectContext.h" |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 12 | |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 13 | class GrAtlasManager; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 14 | class GrBackendFormat; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 15 | class GrBackendRenderTarget; |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 16 | class GrOpMemoryPool; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 17 | class GrOnFlushCallbackObject; |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 18 | class GrRenderTargetProxy; |
Greg Daniel | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 19 | class GrSemaphore; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 20 | class GrSurfaceProxy; |
| 21 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 22 | class SkDeferredDisplayList; |
Robert Phillips | bc42944 | 2019-02-20 08:26:03 -0500 | [diff] [blame] | 23 | class SkTaskGroup; |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 24 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 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: |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 30 | |
| 31 | // from GrContext_Base |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 32 | uint32_t contextID() const { return fContext->contextID(); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 33 | |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 34 | bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); } |
| 35 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 36 | const GrContextOptions& options() const { return fContext->options(); } |
| 37 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 38 | const GrCaps* caps() const { return fContext->caps(); } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 39 | sk_sp<const GrCaps> refCaps() const; |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 40 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 41 | GrImageContext* asImageContext() { return fContext->asImageContext(); } |
| 42 | GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 43 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 44 | // from GrImageContext |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 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(); } ) |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 50 | |
| 51 | // from GrRecordingContext |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 52 | GrDrawingManager* drawingManager() { return fContext->drawingManager(); } |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 53 | |
Michael Ludwig | 2c316bd | 2019-12-19 14:50:44 -0500 | [diff] [blame] | 54 | GrOpMemoryPool* opMemoryPool() { return fContext->arenas().opMemoryPool(); } |
| 55 | SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); } |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 56 | GrRecordingContext::Arenas arenas() { return fContext->arenas(); } |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 57 | |
Robert Phillips | 4d932d1 | 2020-04-09 08:58:52 -0400 | [diff] [blame] | 58 | GrStrikeCache* getGrStrikeCache() { return fContext->fStrikeCache.get(); } |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 59 | GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); } |
| 60 | |
Robert Phillips | 12d06a3 | 2020-09-16 12:31:34 -0400 | [diff] [blame^] | 61 | GrThreadSafeUniquelyKeyedProxyViewCache* threadSafeViewCache() { |
| 62 | return fContext->threadSafeViewCache(); |
| 63 | } |
| 64 | |
Robert Phillips | c5058a6 | 2019-02-15 12:52:59 -0500 | [diff] [blame] | 65 | /** |
| 66 | * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.) |
| 67 | * |
| 68 | * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to |
| 69 | * ensure its lifetime is tied to that of the context. |
| 70 | */ |
| 71 | void addOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 72 | |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 73 | GrAuditTrail* auditTrail() { return fContext->auditTrail(); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 74 | |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 75 | /** |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 76 | * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves |
| 77 | * if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context |
| 78 | * will guarantee that the draws required for those proxies are flushed but it could do more. |
| 79 | * If no array is provided then all current work will be flushed. |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 80 | * |
| 81 | * It is not necessary to call this before reading the render target via Skia/GrContext. |
| 82 | * GrContext will detect when it must perform a resolve before reading pixels back from the |
| 83 | * surface or using it as a texture. |
| 84 | */ |
Greg Daniel | 55f040b | 2020-02-13 15:38:32 +0000 | [diff] [blame] | 85 | GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], int numProxies, const GrFlushInfo&); |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 86 | |
Greg Daniel | 55f040b | 2020-02-13 15:38:32 +0000 | [diff] [blame] | 87 | /** Version of above that flushes for a single proxy and uses a default GrFlushInfo. Null is |
| 88 | * allowed. */ |
| 89 | void flushSurface(GrSurfaceProxy*); |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 90 | |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 91 | /** |
| 92 | * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words, |
| 93 | * did we find a pair of round-trip preserving conversion effects? |
| 94 | */ |
| 95 | bool validPMUPMConversionExists(); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 96 | |
| 97 | /** |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 98 | * These functions create premul <-> unpremul effects, using the specialized round-trip effects |
| 99 | * from GrConfigConversionEffect. |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 100 | */ |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 101 | std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>); |
| 102 | std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 103 | |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 104 | SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); } |
| 105 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 106 | GrResourceProvider* resourceProvider() { return fContext->fResourceProvider; } |
| 107 | const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider; } |
| 108 | |
| 109 | GrResourceCache* getResourceCache() { return fContext->fResourceCache; } |
| 110 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 111 | GrGpu* getGpu() { return fContext->fGpu.get(); } |
| 112 | const GrGpu* getGpu() const { return fContext->fGpu.get(); } |
| 113 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 114 | // This accessor should only ever be called by the GrOpFlushState. |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 115 | GrAtlasManager* getAtlasManager() { |
| 116 | return fContext->onGetAtlasManager(); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 117 | } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 118 | |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 119 | // This accessor should only ever be called by the GrOpFlushState. |
| 120 | GrSmallPathAtlasMgr* getSmallPathAtlasMgr() { |
| 121 | return fContext->onGetSmallPathAtlasMgr(); |
| 122 | } |
| 123 | |
Adlai Holler | 7580ad4 | 2020-06-24 13:45:25 -0400 | [diff] [blame] | 124 | void copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 125 | |
Robert Phillips | 43e7e4f | 2020-05-06 13:34:45 -0400 | [diff] [blame] | 126 | bool compile(const GrProgramDesc&, const GrProgramInfo&); |
Robert Phillips | 979b223 | 2020-02-20 10:47:29 -0500 | [diff] [blame] | 127 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 128 | GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; } |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 129 | GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const { |
| 130 | return fContext->fShaderErrorHandler; |
| 131 | } |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 132 | |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 133 | GrClientMappedBufferManager* clientMappedBufferManager() { |
| 134 | return fContext->fMappedBufferManager.get(); |
| 135 | } |
| 136 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 137 | #if GR_TEST_UTILS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 138 | /** Reset GPU stats */ |
Robert Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 139 | void resetGpuStats() const; |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 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 | |
Robert Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 151 | /** These are only active if GR_GPU_STATS == 1. */ |
| 152 | void resetContextStats() const; |
| 153 | void dumpContextStats(SkString*) const; |
| 154 | void dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
| 155 | void printContextStats() const; |
| 156 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 157 | /** Get pointer to atlas texture for given mask format. Note that this wraps an |
| 158 | actively mutating texture in an SkImage. This could yield unexpected results |
| 159 | if it gets cached or used more generally. */ |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 160 | sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0); |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 161 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 162 | /** |
| 163 | * Purge all the unlocked resources from the cache. |
| 164 | * This entry point is mainly meant for timing texture uploads |
| 165 | * and is not defined in normal builds of Skia. |
| 166 | */ |
| 167 | void testingOnly_purgeAllUnlockedResources(); |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 168 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 169 | void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 170 | #endif |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 171 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 172 | private: |
| 173 | explicit GrContextPriv(GrContext* context) : fContext(context) {} |
John Stiles | b35c3b8 | 2020-08-06 19:58:52 -0400 | [diff] [blame] | 174 | GrContextPriv(const GrContextPriv&) = delete; |
| 175 | GrContextPriv& operator=(const GrContextPriv&) = delete; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 176 | |
| 177 | // No taking addresses of this type. |
| 178 | const GrContextPriv* operator&() const; |
| 179 | GrContextPriv* operator&(); |
| 180 | |
| 181 | GrContext* fContext; |
| 182 | |
| 183 | friend class GrContext; // to construct/copy this type. |
| 184 | }; |
| 185 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 186 | inline GrContextPriv GrContext::priv() { return GrContextPriv(this); } |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 187 | |
John Stiles | ec9b4aa | 2020-08-07 13:05:14 -0400 | [diff] [blame] | 188 | inline const GrContextPriv GrContext::priv() const { // NOLINT(readability-const-return-type) |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 189 | return GrContextPriv(const_cast<GrContext*>(this)); |
| 190 | } |
| 191 | |
| 192 | #endif |