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 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 8 | #ifndef GrDirectContextPriv_DEFINED |
| 9 | #define GrDirectContextPriv_DEFINED |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 10 | |
Robert Phillips | 80bfda8 | 2020-11-12 09:23:36 -0500 | [diff] [blame^] | 11 | #include "include/core/SkSurface.h" |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 12 | #include "include/gpu/GrDirectContext.h" |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 13 | #include "src/core/SkSpan.h" |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 14 | |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 15 | class GrAtlasManager; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 16 | class GrBackendFormat; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 17 | class GrBackendRenderTarget; |
Herb Derby | e32e1ab | 2020-10-27 10:29:46 -0400 | [diff] [blame] | 18 | class GrMemoryPool; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 19 | class GrOnFlushCallbackObject; |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 20 | class GrRenderTargetProxy; |
Greg Daniel | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 21 | class GrSemaphore; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 22 | class GrSurfaceProxy; |
| 23 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 24 | class SkDeferredDisplayList; |
Robert Phillips | bc42944 | 2019-02-20 08:26:03 -0500 | [diff] [blame] | 25 | class SkTaskGroup; |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 26 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 27 | /** Class that adds methods to GrDirectContext that are only intended for use internal to Skia. |
| 28 | This class is purely a privileged window into GrDirectContext. It should never have additional |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 29 | data members or virtual methods. */ |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 30 | class GrDirectContextPriv { |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 31 | public: |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 32 | |
| 33 | // from GrContext_Base |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 34 | uint32_t contextID() const { return fContext->contextID(); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 35 | |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 36 | bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); } |
| 37 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 38 | const GrContextOptions& options() const { return fContext->options(); } |
| 39 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 40 | const GrCaps* caps() const { return fContext->caps(); } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 41 | sk_sp<const GrCaps> refCaps() const; |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 42 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 43 | GrImageContext* asImageContext() { return fContext->asImageContext(); } |
| 44 | GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 45 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 46 | // from GrImageContext |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 47 | GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); } |
| 48 | const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); } |
| 49 | |
| 50 | /** This is only useful for debug purposes */ |
| 51 | SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } ) |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 52 | |
| 53 | // from GrRecordingContext |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 54 | GrDrawingManager* drawingManager() { return fContext->drawingManager(); } |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 55 | |
Herb Derby | e32e1ab | 2020-10-27 10:29:46 -0400 | [diff] [blame] | 56 | GrMemoryPool* opMemoryPool() { return fContext->arenas().opMemoryPool(); } |
Michael Ludwig | 2c316bd | 2019-12-19 14:50:44 -0500 | [diff] [blame] | 57 | SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); } |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 58 | GrRecordingContext::Arenas arenas() { return fContext->arenas(); } |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 59 | |
Robert Phillips | 4d932d1 | 2020-04-09 08:58:52 -0400 | [diff] [blame] | 60 | GrStrikeCache* getGrStrikeCache() { return fContext->fStrikeCache.get(); } |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 61 | GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); } |
| 62 | |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 63 | GrThreadSafeCache* threadSafeCache() { return fContext->threadSafeCache(); } |
Robert Phillips | 12d06a3 | 2020-09-16 12:31:34 -0400 | [diff] [blame] | 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 | */ |
Robert Phillips | 80bfda8 | 2020-11-12 09:23:36 -0500 | [diff] [blame^] | 85 | GrSemaphoresSubmitted flushSurfaces( |
| 86 | SkSpan<GrSurfaceProxy*>, |
| 87 | SkSurface::BackendSurfaceAccess = SkSurface::BackendSurfaceAccess::kNoAccess, |
| 88 | const GrFlushInfo& = {}, |
| 89 | const GrBackendSurfaceMutableState* newState = nullptr); |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 90 | |
Robert Phillips | 80bfda8 | 2020-11-12 09:23:36 -0500 | [diff] [blame^] | 91 | /** Version of above that flushes for a single proxy. Null is allowed. */ |
| 92 | GrSemaphoresSubmitted flushSurface( |
| 93 | GrSurfaceProxy* proxy, |
| 94 | SkSurface::BackendSurfaceAccess access = SkSurface::BackendSurfaceAccess::kNoAccess, |
| 95 | const GrFlushInfo& info = {}, |
| 96 | const GrBackendSurfaceMutableState* newState = nullptr) { |
| 97 | size_t size = proxy ? 1 : 0; |
| 98 | return this->flushSurfaces({&proxy, size}, access, info, newState); |
| 99 | } |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 100 | |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 101 | /** |
| 102 | * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words, |
| 103 | * did we find a pair of round-trip preserving conversion effects? |
| 104 | */ |
| 105 | bool validPMUPMConversionExists(); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 106 | |
| 107 | /** |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 108 | * These functions create premul <-> unpremul effects, using the specialized round-trip effects |
| 109 | * from GrConfigConversionEffect. |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 110 | */ |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 111 | std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>); |
| 112 | std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 113 | |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 114 | SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); } |
| 115 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 116 | GrResourceProvider* resourceProvider() { return fContext->fResourceProvider.get(); } |
| 117 | const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider.get(); } |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 118 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 119 | GrResourceCache* getResourceCache() { return fContext->fResourceCache.get(); } |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 120 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 121 | GrGpu* getGpu() { return fContext->fGpu.get(); } |
| 122 | const GrGpu* getGpu() const { return fContext->fGpu.get(); } |
| 123 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 124 | // This accessor should only ever be called by the GrOpFlushState. |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 125 | GrAtlasManager* getAtlasManager() { |
| 126 | return fContext->onGetAtlasManager(); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 127 | } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 128 | |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 129 | // This accessor should only ever be called by the GrOpFlushState. |
| 130 | GrSmallPathAtlasMgr* getSmallPathAtlasMgr() { |
| 131 | return fContext->onGetSmallPathAtlasMgr(); |
| 132 | } |
| 133 | |
Robert Phillips | a0e248d | 2020-11-11 09:39:27 -0500 | [diff] [blame] | 134 | void copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 135 | |
Robert Phillips | 43e7e4f | 2020-05-06 13:34:45 -0400 | [diff] [blame] | 136 | bool compile(const GrProgramDesc&, const GrProgramInfo&); |
Robert Phillips | 979b223 | 2020-02-20 10:47:29 -0500 | [diff] [blame] | 137 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 138 | GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; } |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 139 | GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const { |
| 140 | return fContext->fShaderErrorHandler; |
| 141 | } |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 142 | |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 143 | GrClientMappedBufferManager* clientMappedBufferManager() { |
| 144 | return fContext->fMappedBufferManager.get(); |
| 145 | } |
| 146 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 147 | #if GR_TEST_UTILS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 148 | /** Reset GPU stats */ |
Robert Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 149 | void resetGpuStats() const; |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 150 | |
| 151 | /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ |
| 152 | void dumpCacheStats(SkString*) const; |
| 153 | void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
| 154 | void printCacheStats() const; |
| 155 | |
| 156 | /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ |
| 157 | void dumpGpuStats(SkString*) const; |
| 158 | void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
| 159 | void printGpuStats() const; |
| 160 | |
Robert Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 161 | /** These are only active if GR_GPU_STATS == 1. */ |
| 162 | void resetContextStats() const; |
| 163 | void dumpContextStats(SkString*) const; |
| 164 | void dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
| 165 | void printContextStats() const; |
| 166 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 167 | /** Get pointer to atlas texture for given mask format. Note that this wraps an |
| 168 | actively mutating texture in an SkImage. This could yield unexpected results |
| 169 | if it gets cached or used more generally. */ |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 170 | sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0); |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 171 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 172 | /** |
| 173 | * Purge all the unlocked resources from the cache. |
| 174 | * This entry point is mainly meant for timing texture uploads |
| 175 | * and is not defined in normal builds of Skia. |
| 176 | */ |
| 177 | void testingOnly_purgeAllUnlockedResources(); |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 178 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 179 | void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 180 | #endif |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 181 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 182 | private: |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 183 | explicit GrDirectContextPriv(GrDirectContext* context) : fContext(context) {} |
| 184 | GrDirectContextPriv(const GrDirectContextPriv&) = delete; |
| 185 | GrDirectContextPriv& operator=(const GrDirectContextPriv&) = delete; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 186 | |
| 187 | // No taking addresses of this type. |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 188 | const GrDirectContextPriv* operator&() const; |
| 189 | GrDirectContextPriv* operator&(); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 190 | |
Adlai Holler | 53cf44c | 2020-10-13 17:40:21 -0400 | [diff] [blame] | 191 | GrDirectContext* fContext; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 192 | |
Adlai Holler | 53cf44c | 2020-10-13 17:40:21 -0400 | [diff] [blame] | 193 | friend class GrDirectContext; // to construct/copy this type. |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 196 | inline GrDirectContextPriv GrDirectContext::priv() { return GrDirectContextPriv(this); } |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 197 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 198 | // NOLINTNEXTLINE(readability-const-return-type) |
| 199 | inline const GrDirectContextPriv GrDirectContext::priv() const { |
| 200 | return GrDirectContextPriv(const_cast<GrDirectContext*>(this)); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | #endif |