bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 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. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef GrContext_DEFINED |
| 9 | #define GrContext_DEFINED |
| 10 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 11 | #include "SkMatrix.h" |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 12 | #include "SkPathEffect.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 13 | #include "SkTypes.h" |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 14 | #include "../private/GrRecordingContext.h" |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 15 | #include "GrContextOptions.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 16 | |
Brian Salomon | 79bf7ac | 2018-05-11 13:08:30 -0400 | [diff] [blame] | 17 | // We shouldn't need this but currently Android is relying on this being include transitively. |
| 18 | #include "SkUnPreMultiply.h" |
| 19 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 20 | class GrAtlasManager; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 21 | class GrBackendFormat; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 22 | class GrBackendSemaphore; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 23 | class GrCaps; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 24 | class GrContextPriv; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 25 | class GrContextThreadSafeProxy; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 26 | class GrFragmentProcessor; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 27 | struct GrGLInterface; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 28 | class GrGpu; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 29 | struct GrMockOptions; |
commit-bot@chromium.org | 5c8ee25 | 2013-11-01 15:23:44 +0000 | [diff] [blame] | 30 | class GrPath; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 31 | class GrRenderTargetContext; |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 32 | class GrResourceCache; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 33 | class GrResourceProvider; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 34 | class GrSamplerState; |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 35 | class GrSkSLFPFactoryCache; |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 36 | class GrSurfaceProxy; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 37 | class GrSwizzle; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 38 | class GrTextContext; |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 39 | class GrTextureProxy; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 40 | struct GrVkBackendContext; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 41 | |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 42 | class SkImage; |
| 43 | class SkSurfaceProps; |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 44 | class SkTaskGroup; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 45 | class SkTraceMemoryDump; |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 46 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 47 | class SK_API GrContext : public GrRecordingContext { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 48 | public: |
| 49 | /** |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 50 | * Creates a GrContext for a backend context. If no GrGLInterface is provided then the result of |
| 51 | * GrGLMakeNativeInterface() is used if it succeeds. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 52 | */ |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 53 | static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&); |
| 54 | static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>); |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 55 | static sk_sp<GrContext> MakeGL(const GrContextOptions&); |
| 56 | static sk_sp<GrContext> MakeGL(); |
| 57 | |
Greg Daniel | 10a83da | 2018-06-14 09:31:11 -0400 | [diff] [blame] | 58 | static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&); |
| 59 | static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&); |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 60 | |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 61 | #ifdef SK_METAL |
| 62 | /** |
| 63 | * Makes a GrContext which uses Metal as the backend. The device parameter is an MTLDevice |
| 64 | * and queue is an MTLCommandQueue which should be used by the backend. These objects must |
| 65 | * have a ref on them which can be transferred to Ganesh which will release the ref when the |
| 66 | * GrContext is destroyed. |
| 67 | */ |
| 68 | static sk_sp<GrContext> MakeMetal(void* device, void* queue, const GrContextOptions& options); |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 69 | static sk_sp<GrContext> MakeMetal(void* device, void* queue); |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 70 | #endif |
| 71 | |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 72 | static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&); |
| 73 | static sk_sp<GrContext> MakeMock(const GrMockOptions*); |
| 74 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 75 | ~GrContext() override; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 76 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 77 | sk_sp<GrContextThreadSafeProxy> threadSafeProxy(); |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 78 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 79 | /** |
| 80 | * The GrContext normally assumes that no outsider is setting state |
| 81 | * within the underlying 3D API's context/device/whatever. This call informs |
| 82 | * the context that the state was modified and it should resend. Shouldn't |
| 83 | * be called frequently for good performance. |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 84 | * The flag bits, state, is dpendent on which backend is used by the |
| 85 | * context, either GL or D3D (possible in future). |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 86 | */ |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 87 | void resetContext(uint32_t state = kAll_GrBackendState); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 88 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 89 | /** |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 90 | * If the backend is GrBackendApi::kOpenGL, then all texture unit/target combinations for which |
| 91 | * the GrContext has modified the bound texture will have texture id 0 bound. This does not |
| 92 | * flush the GrContext. Calling resetContext() does not change the set that will be bound |
| 93 | * to texture id 0 on the next call to resetGLTextureBindings(). After this is called |
| 94 | * all unit/target combinations are considered to have unmodified bindings until the GrContext |
| 95 | * subsequently modifies them (meaning if this is called twice in a row with no intervening |
| 96 | * GrContext usage then the second call is a no-op.) |
| 97 | */ |
| 98 | void resetGLTextureBindings(); |
| 99 | |
| 100 | /** |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 101 | * Abandons all GPU resources and assumes the underlying backend 3D API context is no longer |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 102 | * usable. Call this if you have lost the associated GPU context, and thus internal texture, |
| 103 | * buffer, etc. references/IDs are now invalid. Calling this ensures that the destructors of the |
| 104 | * GrContext and any of its created resource objects will not make backend 3D API calls. Content |
| 105 | * rendered but not previously flushed may be lost. After this function is called all subsequent |
| 106 | * calls on the GrContext will fail or be no-ops. |
| 107 | * |
| 108 | * The typical use case for this function is that the underlying 3D context was lost and further |
| 109 | * API calls may crash. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 110 | */ |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 111 | void abandonContext() override; |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 112 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 113 | /** |
Khushal | c421ca1 | 2018-06-26 14:38:34 -0700 | [diff] [blame] | 114 | * Returns true if the context was abandoned. |
| 115 | */ |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 116 | using GrImageContext::abandoned; |
Khushal | c421ca1 | 2018-06-26 14:38:34 -0700 | [diff] [blame] | 117 | |
| 118 | /** |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 119 | * This is similar to abandonContext() however the underlying 3D context is not yet lost and |
| 120 | * the GrContext will cleanup all allocated resources before returning. After returning it will |
| 121 | * assume that the underlying context may no longer be valid. |
| 122 | * |
| 123 | * The typical use case for this function is that the client is going to destroy the 3D context |
| 124 | * but can't guarantee that GrContext will be destroyed first (perhaps because it may be ref'ed |
| 125 | * elsewhere by either the client or Skia objects). |
| 126 | */ |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 127 | virtual void releaseResourcesAndAbandonContext(); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 128 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 129 | /////////////////////////////////////////////////////////////////////////// |
| 130 | // Resource Cache |
| 131 | |
| 132 | /** |
| 133 | * Return the current GPU resource cache limits. |
| 134 | * |
| 135 | * @param maxResources If non-null, returns maximum number of resources that |
| 136 | * can be held in the cache. |
| 137 | * @param maxResourceBytes If non-null, returns maximum number of bytes of |
| 138 | * video memory that can be held in the cache. |
| 139 | */ |
| 140 | void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * Gets the current GPU resource cache usage. |
| 144 | * |
| 145 | * @param resourceCount If non-null, returns the number of resources that are held in the |
| 146 | * cache. |
| 147 | * @param maxResourceBytes If non-null, returns the total number of bytes of video memory held |
| 148 | * in the cache. |
| 149 | */ |
| 150 | void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const; |
| 151 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 152 | /** |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 153 | * Gets the number of bytes in the cache consumed by purgeable (e.g. unlocked) resources. |
| 154 | */ |
| 155 | size_t getResourceCachePurgeableBytes() const; |
| 156 | |
| 157 | /** |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 158 | * Specify the GPU resource cache limits. If the current cache exceeds either |
| 159 | * of these, it will be purged (LRU) to keep the cache within these limits. |
| 160 | * |
| 161 | * @param maxResources The maximum number of resources that can be held in |
| 162 | * the cache. |
| 163 | * @param maxResourceBytes The maximum number of bytes of video memory |
| 164 | * that can be held in the cache. |
| 165 | */ |
| 166 | void setResourceCacheLimits(int maxResources, size_t maxResourceBytes); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 167 | |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 168 | /** |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 169 | * Frees GPU created by the context. Can be called to reduce GPU memory |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 170 | * pressure. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 171 | */ |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 172 | virtual void freeGpuResources(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 173 | |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 174 | /** |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 175 | * Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are |
| 176 | * otherwise marked for deletion, regardless of whether the context is under budget. |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 177 | */ |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 178 | void performDeferredCleanup(std::chrono::milliseconds msNotUsed); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 179 | |
Mike Klein | 4b6bde7 | 2017-12-14 07:46:55 -0500 | [diff] [blame] | 180 | // Temporary compatibility API for Android. |
| 181 | void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed) { |
| 182 | this->performDeferredCleanup(msNotUsed); |
| 183 | } |
| 184 | |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 185 | /** |
| 186 | * Purge unlocked resources from the cache until the the provided byte count has been reached |
| 187 | * or we have purged all unlocked resources. The default policy is to purge in LRU order, but |
| 188 | * can be overridden to prefer purging scratch resources (in LRU order) prior to purging other |
| 189 | * resource types. |
| 190 | * |
| 191 | * @param maxBytesToPurge the desired number of bytes to be purged. |
| 192 | * @param preferScratchResources If true scratch resources will be purged prior to other |
| 193 | * resource types. |
| 194 | */ |
| 195 | void purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources); |
| 196 | |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 197 | /** |
| 198 | * This entry point is intended for instances where an app has been backgrounded or |
| 199 | * suspended. |
| 200 | * If 'scratchResourcesOnly' is true all unlocked scratch resources will be purged but the |
| 201 | * unlocked resources with persistent data will remain. If 'scratchResourcesOnly' is false |
| 202 | * then all unlocked resources will be purged. |
| 203 | * In either case, after the unlocked resources are purged a separate pass will be made to |
| 204 | * ensure that resource usage is under budget (i.e., even if 'scratchResourcesOnly' is true |
| 205 | * some resources with persistent data may be purged to be under budget). |
| 206 | * |
| 207 | * @param scratchResourcesOnly If true only unlocked scratch resources will be purged prior |
| 208 | * enforcing the budget requirements. |
| 209 | */ |
| 210 | void purgeUnlockedResources(bool scratchResourcesOnly); |
| 211 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 212 | /** |
Brian Salomon | f932a63 | 2018-04-05 12:46:09 -0400 | [diff] [blame] | 213 | * Gets the maximum supported texture size. |
| 214 | */ |
| 215 | int maxTextureSize() const; |
| 216 | |
| 217 | /** |
| 218 | * Gets the maximum supported render target size. |
| 219 | */ |
| 220 | int maxRenderTargetSize() const; |
| 221 | |
| 222 | /** |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 223 | * Can a SkImage be created with the given color type. |
| 224 | */ |
| 225 | bool colorTypeSupportedAsImage(SkColorType) const; |
| 226 | |
| 227 | /** |
| 228 | * Can a SkSurface be created with the given color type. To check whether MSAA is supported |
| 229 | * use maxSurfaceSampleCountForColorType(). |
| 230 | */ |
| 231 | bool colorTypeSupportedAsSurface(SkColorType colorType) const { |
| 232 | return this->maxSurfaceSampleCountForColorType(colorType) > 0; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA |
| 237 | * rendering is supported for the color type. 0 is returned if rendering to this color type |
| 238 | * is not supported at all. |
| 239 | */ |
| 240 | int maxSurfaceSampleCountForColorType(SkColorType) const; |
| 241 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 242 | /////////////////////////////////////////////////////////////////////////// |
| 243 | // Misc. |
| 244 | |
| 245 | /** |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 246 | * Call to ensure all drawing to the context has been issued to the underlying 3D API. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 247 | */ |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 248 | void flush(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 249 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 250 | /** |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 251 | * Call to ensure all drawing to the context has been issued to the underlying 3D API. After |
| 252 | * issuing all commands, numSemaphore semaphores will be signaled by the gpu. The client passes |
| 253 | * in an array of numSemaphores GrBackendSemaphores. In general these GrBackendSemaphore's can |
| 254 | * be either initialized or not. If they are initialized, the backend uses the passed in |
| 255 | * semaphore. If it is not initialized, a new semaphore is created and the GrBackendSemaphore |
| 256 | * object is initialized with that semaphore. |
| 257 | * |
| 258 | * The client will own and be responsible for deleting the underlying semaphores that are stored |
| 259 | * and returned in initialized GrBackendSemaphore objects. The GrBackendSemaphore objects |
| 260 | * themselves can be deleted as soon as this function returns. |
| 261 | * |
| 262 | * If the backend API is OpenGL only uninitialized GrBackendSemaphores are supported. |
| 263 | * If the backend API is Vulkan either initialized or unitialized semaphores are supported. |
| 264 | * If unitialized, the semaphores which are created will be valid for use only with the VkDevice |
| 265 | * with which they were created. |
| 266 | * |
| 267 | * If this call returns GrSemaphoresSubmited::kNo, the GPU backend will not have created or |
| 268 | * added any semaphores to signal on the GPU. Thus the client should not have the GPU wait on |
| 269 | * any of the semaphores. However, any pending commands to the context will still be flushed. |
| 270 | */ |
Greg Daniel | b9990e4 | 2019-04-10 16:28:52 -0400 | [diff] [blame^] | 271 | GrSemaphoresSubmitted flush(GrFlushFlags flags, int numSemaphores, |
| 272 | GrBackendSemaphore signalSemaphores[]); |
| 273 | |
| 274 | /** |
| 275 | * Deprecated. |
| 276 | */ |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 277 | GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores, |
Greg Daniel | b9990e4 | 2019-04-10 16:28:52 -0400 | [diff] [blame^] | 278 | GrBackendSemaphore signalSemaphores[]) { |
| 279 | return this->flush(kNone_GrFlushFlags, numSemaphores, signalSemaphores); |
| 280 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 281 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 282 | // Provides access to functions that aren't part of the public API. |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 283 | GrContextPriv priv(); |
| 284 | const GrContextPriv priv() const; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 285 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 286 | /** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */ |
| 287 | // Chrome is using this! |
| 288 | void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; |
| 289 | |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 290 | bool supportsDistanceFieldText() const; |
| 291 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 292 | void storeVkPipelineCacheData(); |
| 293 | |
Adrienne Walker | 0f82797 | 2019-03-26 13:46:14 -0700 | [diff] [blame] | 294 | static size_t ComputeTextureSize(SkColorType type, int width, int height, GrMipMapped, |
| 295 | bool useNextPow2 = false); |
| 296 | |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 297 | protected: |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 298 | GrContext(GrBackendApi, const GrContextOptions&, int32_t contextID = SK_InvalidGenID); |
| 299 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 300 | bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>) override; |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 301 | |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 302 | GrContext* asDirectContext() override { return this; } |
| 303 | |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 304 | virtual GrAtlasManager* onGetAtlasManager() = 0; |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 305 | |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 306 | sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy; |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 307 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 308 | private: |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 309 | // fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed |
| 310 | // after all of its users. Clients of fTaskGroup will generally want to ensure that they call |
| 311 | // wait() on it as they are being destroyed, to avoid the possibility of pending tasks being |
| 312 | // invoked after objects they depend upon have already been destroyed. |
| 313 | std::unique_ptr<SkTaskGroup> fTaskGroup; |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 314 | sk_sp<GrGpu> fGpu; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 315 | GrResourceCache* fResourceCache; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 316 | GrResourceProvider* fResourceProvider; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 317 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 318 | bool fDidTestPMConversions; |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 319 | // true if the PM/UPM conversion succeeded; false otherwise |
| 320 | bool fPMUPMConversionsRoundTrip; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 321 | |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 322 | GrContextOptions::PersistentCache* fPersistentCache; |
| 323 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 324 | // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 325 | friend class GrContextPriv; |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 326 | |
skia.committer@gmail.com | cdcb2ce | 2013-01-29 07:05:52 +0000 | [diff] [blame] | 327 | /** |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 328 | * These functions create premul <-> unpremul effects, using the specialized round-trip effects |
| 329 | * from GrConfigConversionEffect. |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 330 | */ |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 331 | std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>); |
| 332 | std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 333 | |
| 334 | /** |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 335 | * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words, |
| 336 | * did we find a pair of round-trip preserving conversion effects? |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 337 | */ |
| 338 | bool validPMUPMConversionExists(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 339 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 340 | typedef GrRecordingContext INHERITED; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 341 | }; |
| 342 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 343 | #endif |