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 | |
Brian Osman | a5842bc | 2021-05-11 13:41:46 -0400 | [diff] [blame] | 11 | #include "include/core/SkSpan.h" |
Robert Phillips | 80bfda8 | 2020-11-12 09:23:36 -0500 | [diff] [blame] | 12 | #include "include/core/SkSurface.h" |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 13 | #include "include/gpu/GrDirectContext.h" |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 14 | #include "src/gpu/BaseDevice.h" |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 15 | |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 16 | class GrAtlasManager; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 17 | class GrBackendFormat; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 18 | class GrBackendRenderTarget; |
Robert Phillips | 33bf2b5 | 2021-08-02 11:14:38 -0400 | [diff] [blame] | 19 | class GrImageInfo; |
Herb Derby | e32e1ab | 2020-10-27 10:29:46 -0400 | [diff] [blame] | 20 | class GrMemoryPool; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 21 | class GrOnFlushCallbackObject; |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 22 | class GrRenderTargetProxy; |
Greg Daniel | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 23 | class GrSemaphore; |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 24 | class GrSurfaceProxy; |
| 25 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 26 | class SkDeferredDisplayList; |
Robert Phillips | bc42944 | 2019-02-20 08:26:03 -0500 | [diff] [blame] | 27 | class SkTaskGroup; |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 28 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 29 | /** Class that adds methods to GrDirectContext that are only intended for use internal to Skia. |
| 30 | 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] | 31 | data members or virtual methods. */ |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 32 | class GrDirectContextPriv { |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 33 | public: |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 34 | |
| 35 | // from GrContext_Base |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 36 | uint32_t contextID() const { return fContext->contextID(); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 37 | |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 38 | bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); } |
| 39 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 40 | const GrContextOptions& options() const { return fContext->options(); } |
| 41 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 42 | const GrCaps* caps() const { return fContext->caps(); } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 43 | sk_sp<const GrCaps> refCaps() const; |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 44 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 45 | GrImageContext* asImageContext() { return fContext->asImageContext(); } |
| 46 | GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 47 | |
Adlai Holler | 17776e3 | 2021-02-18 13:09:36 -0500 | [diff] [blame] | 48 | // from GrRecordingContext |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 49 | GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); } |
| 50 | const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); } |
| 51 | |
| 52 | /** This is only useful for debug purposes */ |
| 53 | SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } ) |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 54 | |
| 55 | // from GrRecordingContext |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 56 | GrDrawingManager* drawingManager() { return fContext->drawingManager(); } |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 57 | |
Michael Ludwig | 2c316bd | 2019-12-19 14:50:44 -0500 | [diff] [blame] | 58 | SkArenaAlloc* recordTimeAllocator() { return fContext->arenas().recordTimeAllocator(); } |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 59 | GrRecordingContext::Arenas arenas() { return fContext->arenas(); } |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 60 | |
Robert Phillips | 4d932d1 | 2020-04-09 08:58:52 -0400 | [diff] [blame] | 61 | GrStrikeCache* getGrStrikeCache() { return fContext->fStrikeCache.get(); } |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 62 | GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); } |
| 63 | |
Robert Phillips | d464feb | 2020-10-08 11:00:02 -0400 | [diff] [blame] | 64 | GrThreadSafeCache* threadSafeCache() { return fContext->threadSafeCache(); } |
Robert Phillips | 12d06a3 | 2020-09-16 12:31:34 -0400 | [diff] [blame] | 65 | |
Robert Phillips | c5058a6 | 2019-02-15 12:52:59 -0500 | [diff] [blame] | 66 | /** |
| 67 | * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.) |
| 68 | * |
| 69 | * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to |
| 70 | * ensure its lifetime is tied to that of the context. |
| 71 | */ |
| 72 | void addOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 73 | |
Robert Phillips | a92913e | 2021-07-12 16:31:52 -0400 | [diff] [blame] | 74 | GrAuditTrail* auditTrail() { return fContext->fAuditTrail.get(); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 75 | |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 76 | /** |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 77 | * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves |
| 78 | * if necessary. The GrSurfaceProxy array is treated as a hint. If it is supplied the context |
| 79 | * will guarantee that the draws required for those proxies are flushed but it could do more. |
| 80 | * If no array is provided then all current work will be flushed. |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 81 | * |
| 82 | * It is not necessary to call this before reading the render target via Skia/GrContext. |
| 83 | * GrContext will detect when it must perform a resolve before reading pixels back from the |
| 84 | * surface or using it as a texture. |
| 85 | */ |
Robert Phillips | 80bfda8 | 2020-11-12 09:23:36 -0500 | [diff] [blame] | 86 | GrSemaphoresSubmitted flushSurfaces( |
| 87 | SkSpan<GrSurfaceProxy*>, |
| 88 | SkSurface::BackendSurfaceAccess = SkSurface::BackendSurfaceAccess::kNoAccess, |
| 89 | const GrFlushInfo& = {}, |
| 90 | const GrBackendSurfaceMutableState* newState = nullptr); |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 91 | |
Robert Phillips | 80bfda8 | 2020-11-12 09:23:36 -0500 | [diff] [blame] | 92 | /** Version of above that flushes for a single proxy. Null is allowed. */ |
| 93 | GrSemaphoresSubmitted flushSurface( |
| 94 | GrSurfaceProxy* proxy, |
| 95 | SkSurface::BackendSurfaceAccess access = SkSurface::BackendSurfaceAccess::kNoAccess, |
| 96 | const GrFlushInfo& info = {}, |
| 97 | const GrBackendSurfaceMutableState* newState = nullptr) { |
| 98 | size_t size = proxy ? 1 : 0; |
| 99 | return this->flushSurfaces({&proxy, size}, access, info, newState); |
| 100 | } |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 101 | |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 102 | /** |
| 103 | * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words, |
| 104 | * did we find a pair of round-trip preserving conversion effects? |
| 105 | */ |
| 106 | bool validPMUPMConversionExists(); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 107 | |
| 108 | /** |
Brian Osman | 4c886ee | 2021-07-07 13:34:50 -0400 | [diff] [blame] | 109 | * These functions create premul <-> unpremul effects, using specialized round-trip effects. |
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 | eb54bb5 | 2021-01-08 17:20:18 -0500 | [diff] [blame] | 134 | void createDDLTask(sk_sp<const SkDeferredDisplayList>, |
| 135 | sk_sp<GrRenderTargetProxy> newDest, |
Robert Phillips | 88b2961 | 2020-11-16 15:15:08 -0500 | [diff] [blame] | 136 | SkIPoint offset); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 137 | |
Robert Phillips | 43e7e4f | 2020-05-06 13:34:45 -0400 | [diff] [blame] | 138 | bool compile(const GrProgramDesc&, const GrProgramInfo&); |
Robert Phillips | 979b223 | 2020-02-20 10:47:29 -0500 | [diff] [blame] | 139 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 140 | GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; } |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 141 | GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const { |
| 142 | return fContext->fShaderErrorHandler; |
| 143 | } |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 144 | |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 145 | GrClientMappedBufferManager* clientMappedBufferManager() { |
| 146 | return fContext->fMappedBufferManager.get(); |
| 147 | } |
| 148 | |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 149 | sk_sp<skgpu::BaseDevice> createDevice(GrColorType, |
| 150 | sk_sp<GrSurfaceProxy>, |
| 151 | sk_sp<SkColorSpace>, |
| 152 | GrSurfaceOrigin, |
| 153 | const SkSurfaceProps&, |
| 154 | skgpu::BaseDevice::InitContents); |
| 155 | sk_sp<skgpu::BaseDevice> createDevice(SkBudgeted, |
| 156 | const SkImageInfo&, |
| 157 | SkBackingFit, |
| 158 | int sampleCount, |
| 159 | GrMipmapped, |
| 160 | GrProtected, |
| 161 | GrSurfaceOrigin, |
| 162 | const SkSurfaceProps&, |
| 163 | skgpu::BaseDevice::InitContents); |
Robert Phillips | 516405c | 2021-06-04 16:37:30 -0400 | [diff] [blame] | 164 | |
Robert Phillips | 33bf2b5 | 2021-08-02 11:14:38 -0400 | [diff] [blame] | 165 | std::unique_ptr<GrSurfaceContext> makeSC(GrSurfaceProxyView readView, const GrColorInfo&); |
| 166 | |
| 167 | std::unique_ptr<GrSurfaceFillContext> makeSFC(GrImageInfo, |
| 168 | SkBackingFit = SkBackingFit::kExact, |
| 169 | int sampleCount = 1, |
| 170 | GrMipmapped = GrMipmapped::kNo, |
| 171 | GrProtected = GrProtected::kNo, |
| 172 | GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin, |
| 173 | SkBudgeted = SkBudgeted::kYes); |
| 174 | |
| 175 | std::unique_ptr<GrSurfaceFillContext> makeSFCWithFallback( |
| 176 | GrImageInfo, |
| 177 | SkBackingFit = SkBackingFit::kExact, |
| 178 | int sampleCount = 1, |
| 179 | GrMipmapped = GrMipmapped::kNo, |
| 180 | GrProtected = GrProtected::kNo, |
| 181 | GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin, |
| 182 | SkBudgeted = SkBudgeted::kYes); |
| 183 | |
| 184 | std::unique_ptr<GrSurfaceFillContext> makeSFCFromBackendTexture( |
| 185 | GrColorInfo, |
| 186 | const GrBackendTexture&, |
| 187 | int sampleCount, |
| 188 | GrSurfaceOrigin, |
| 189 | sk_sp<GrRefCntedCallback> releaseHelper); |
| 190 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 191 | #if GR_TEST_UTILS |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 192 | /** Reset GPU stats */ |
Robert Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 193 | void resetGpuStats() const; |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 194 | |
| 195 | /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ |
| 196 | void dumpCacheStats(SkString*) const; |
| 197 | void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
| 198 | void printCacheStats() const; |
| 199 | |
| 200 | /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ |
| 201 | void dumpGpuStats(SkString*) const; |
| 202 | void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
| 203 | void printGpuStats() const; |
| 204 | |
Robert Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 205 | /** These are only active if GR_GPU_STATS == 1. */ |
| 206 | void resetContextStats() const; |
| 207 | void dumpContextStats(SkString*) const; |
| 208 | void dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
| 209 | void printContextStats() const; |
| 210 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 211 | /** Get pointer to atlas texture for given mask format. Note that this wraps an |
| 212 | actively mutating texture in an SkImage. This could yield unexpected results |
| 213 | if it gets cached or used more generally. */ |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 214 | sk_sp<SkImage> testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index = 0); |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 215 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 216 | void testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject*); |
| 217 | #endif |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 218 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 219 | private: |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 220 | explicit GrDirectContextPriv(GrDirectContext* context) : fContext(context) {} |
| 221 | GrDirectContextPriv(const GrDirectContextPriv&) = delete; |
| 222 | GrDirectContextPriv& operator=(const GrDirectContextPriv&) = delete; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 223 | |
| 224 | // No taking addresses of this type. |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 225 | const GrDirectContextPriv* operator&() const; |
| 226 | GrDirectContextPriv* operator&(); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 227 | |
Adlai Holler | 53cf44c | 2020-10-13 17:40:21 -0400 | [diff] [blame] | 228 | GrDirectContext* fContext; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 229 | |
Adlai Holler | 53cf44c | 2020-10-13 17:40:21 -0400 | [diff] [blame] | 230 | friend class GrDirectContext; // to construct/copy this type. |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 233 | inline GrDirectContextPriv GrDirectContext::priv() { return GrDirectContextPriv(this); } |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 234 | |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 235 | // NOLINTNEXTLINE(readability-const-return-type) |
| 236 | inline const GrDirectContextPriv GrDirectContext::priv() const { |
| 237 | return GrDirectContextPriv(const_cast<GrDirectContext*>(this)); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | #endif |