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" |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 14 | #include "../private/GrAuditTrail.h" |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 15 | #include "../private/GrSingleOwner.h" |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 16 | #include "../private/GrSkSLFPFactoryCache.h" |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 17 | #include "GrContextOptions.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 18 | |
Brian Salomon | 79bf7ac | 2018-05-11 13:08:30 -0400 | [diff] [blame] | 19 | // We shouldn't need this but currently Android is relying on this being include transitively. |
| 20 | #include "SkUnPreMultiply.h" |
| 21 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 22 | class GrAtlasManager; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 23 | class GrBackendFormat; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 24 | class GrBackendSemaphore; |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 25 | class GrCaps; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 26 | class GrContextPriv; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 27 | class GrContextThreadSafeProxy; |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 28 | class GrContextThreadSafeProxyPriv; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 29 | class GrDrawingManager; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 30 | class GrFragmentProcessor; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 31 | struct GrGLInterface; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 32 | class GrGlyphCache; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 33 | class GrGpu; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 34 | struct GrMockOptions; |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 35 | class GrOpMemoryPool; |
commit-bot@chromium.org | 5c8ee25 | 2013-11-01 15:23:44 +0000 | [diff] [blame] | 36 | class GrPath; |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 37 | class GrProxyProvider; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 38 | class GrRenderTargetContext; |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 39 | class GrResourceCache; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 40 | class GrResourceProvider; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 41 | class GrSamplerState; |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 42 | class GrSurfaceProxy; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 43 | class GrSwizzle; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 44 | class GrTextBlobCache; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 45 | class GrTextContext; |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 46 | class GrTextureProxy; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 47 | struct GrVkBackendContext; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 48 | |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 49 | class SkImage; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 50 | class SkSurfaceCharacterization; |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 51 | class SkSurfaceProps; |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 52 | class SkTaskGroup; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 53 | class SkTraceMemoryDump; |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 54 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 55 | class SK_API GrContext : public SkRefCnt { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 56 | public: |
| 57 | /** |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 58 | * Creates a GrContext for a backend context. If no GrGLInterface is provided then the result of |
| 59 | * GrGLMakeNativeInterface() is used if it succeeds. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 60 | */ |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 61 | static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&); |
| 62 | static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>); |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 63 | static sk_sp<GrContext> MakeGL(const GrContextOptions&); |
| 64 | static sk_sp<GrContext> MakeGL(); |
| 65 | |
Greg Daniel | 10a83da | 2018-06-14 09:31:11 -0400 | [diff] [blame] | 66 | static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&); |
| 67 | static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&); |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 68 | |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 69 | #ifdef SK_METAL |
| 70 | /** |
| 71 | * Makes a GrContext which uses Metal as the backend. The device parameter is an MTLDevice |
| 72 | * and queue is an MTLCommandQueue which should be used by the backend. These objects must |
| 73 | * have a ref on them which can be transferred to Ganesh which will release the ref when the |
| 74 | * GrContext is destroyed. |
| 75 | */ |
| 76 | static sk_sp<GrContext> MakeMetal(void* device, void* queue, const GrContextOptions& options); |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 77 | static sk_sp<GrContext> MakeMetal(void* device, void* queue); |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 78 | #endif |
| 79 | |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 80 | static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&); |
| 81 | static sk_sp<GrContext> MakeMock(const GrMockOptions*); |
| 82 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 83 | virtual ~GrContext(); |
| 84 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 85 | sk_sp<GrContextThreadSafeProxy> threadSafeProxy(); |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 86 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 87 | /** |
| 88 | * The GrContext normally assumes that no outsider is setting state |
| 89 | * within the underlying 3D API's context/device/whatever. This call informs |
| 90 | * the context that the state was modified and it should resend. Shouldn't |
| 91 | * be called frequently for good performance. |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 92 | * The flag bits, state, is dpendent on which backend is used by the |
| 93 | * context, either GL or D3D (possible in future). |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 94 | */ |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 95 | void resetContext(uint32_t state = kAll_GrBackendState); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 96 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 97 | /** |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 98 | * 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] | 99 | * usable. Call this if you have lost the associated GPU context, and thus internal texture, |
| 100 | * buffer, etc. references/IDs are now invalid. Calling this ensures that the destructors of the |
| 101 | * GrContext and any of its created resource objects will not make backend 3D API calls. Content |
| 102 | * rendered but not previously flushed may be lost. After this function is called all subsequent |
| 103 | * calls on the GrContext will fail or be no-ops. |
| 104 | * |
| 105 | * The typical use case for this function is that the underlying 3D context was lost and further |
| 106 | * API calls may crash. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 107 | */ |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 108 | virtual void abandonContext(); |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 109 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 110 | /** |
Khushal | c421ca1 | 2018-06-26 14:38:34 -0700 | [diff] [blame] | 111 | * Returns true if the context was abandoned. |
| 112 | */ |
| 113 | bool abandoned() const; |
| 114 | |
| 115 | /** |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 116 | * This is similar to abandonContext() however the underlying 3D context is not yet lost and |
| 117 | * the GrContext will cleanup all allocated resources before returning. After returning it will |
| 118 | * assume that the underlying context may no longer be valid. |
| 119 | * |
| 120 | * The typical use case for this function is that the client is going to destroy the 3D context |
| 121 | * but can't guarantee that GrContext will be destroyed first (perhaps because it may be ref'ed |
| 122 | * elsewhere by either the client or Skia objects). |
| 123 | */ |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 124 | virtual void releaseResourcesAndAbandonContext(); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 125 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 126 | /////////////////////////////////////////////////////////////////////////// |
| 127 | // Resource Cache |
| 128 | |
| 129 | /** |
| 130 | * Return the current GPU resource cache limits. |
| 131 | * |
| 132 | * @param maxResources If non-null, returns maximum number of resources that |
| 133 | * can be held in the cache. |
| 134 | * @param maxResourceBytes If non-null, returns maximum number of bytes of |
| 135 | * video memory that can be held in the cache. |
| 136 | */ |
| 137 | void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 138 | |
| 139 | /** |
| 140 | * Gets the current GPU resource cache usage. |
| 141 | * |
| 142 | * @param resourceCount If non-null, returns the number of resources that are held in the |
| 143 | * cache. |
| 144 | * @param maxResourceBytes If non-null, returns the total number of bytes of video memory held |
| 145 | * in the cache. |
| 146 | */ |
| 147 | void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const; |
| 148 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 149 | /** |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 150 | * Gets the number of bytes in the cache consumed by purgeable (e.g. unlocked) resources. |
| 151 | */ |
| 152 | size_t getResourceCachePurgeableBytes() const; |
| 153 | |
| 154 | /** |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 155 | * Specify the GPU resource cache limits. If the current cache exceeds either |
| 156 | * of these, it will be purged (LRU) to keep the cache within these limits. |
| 157 | * |
| 158 | * @param maxResources The maximum number of resources that can be held in |
| 159 | * the cache. |
| 160 | * @param maxResourceBytes The maximum number of bytes of video memory |
| 161 | * that can be held in the cache. |
| 162 | */ |
| 163 | void setResourceCacheLimits(int maxResources, size_t maxResourceBytes); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 164 | |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 165 | /** |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 166 | * 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] | 167 | * pressure. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 168 | */ |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 169 | virtual void freeGpuResources(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 170 | |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 171 | /** |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 172 | * Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are |
| 173 | * otherwise marked for deletion, regardless of whether the context is under budget. |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 174 | */ |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 175 | void performDeferredCleanup(std::chrono::milliseconds msNotUsed); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 176 | |
Mike Klein | 4b6bde7 | 2017-12-14 07:46:55 -0500 | [diff] [blame] | 177 | // Temporary compatibility API for Android. |
| 178 | void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed) { |
| 179 | this->performDeferredCleanup(msNotUsed); |
| 180 | } |
| 181 | |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 182 | /** |
| 183 | * Purge unlocked resources from the cache until the the provided byte count has been reached |
| 184 | * or we have purged all unlocked resources. The default policy is to purge in LRU order, but |
| 185 | * can be overridden to prefer purging scratch resources (in LRU order) prior to purging other |
| 186 | * resource types. |
| 187 | * |
| 188 | * @param maxBytesToPurge the desired number of bytes to be purged. |
| 189 | * @param preferScratchResources If true scratch resources will be purged prior to other |
| 190 | * resource types. |
| 191 | */ |
| 192 | void purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources); |
| 193 | |
Robert Phillips | 6eba063 | 2018-03-28 12:25:42 -0400 | [diff] [blame] | 194 | /** |
| 195 | * This entry point is intended for instances where an app has been backgrounded or |
| 196 | * suspended. |
| 197 | * If 'scratchResourcesOnly' is true all unlocked scratch resources will be purged but the |
| 198 | * unlocked resources with persistent data will remain. If 'scratchResourcesOnly' is false |
| 199 | * then all unlocked resources will be purged. |
| 200 | * In either case, after the unlocked resources are purged a separate pass will be made to |
| 201 | * ensure that resource usage is under budget (i.e., even if 'scratchResourcesOnly' is true |
| 202 | * some resources with persistent data may be purged to be under budget). |
| 203 | * |
| 204 | * @param scratchResourcesOnly If true only unlocked scratch resources will be purged prior |
| 205 | * enforcing the budget requirements. |
| 206 | */ |
| 207 | void purgeUnlockedResources(bool scratchResourcesOnly); |
| 208 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 209 | /** |
Brian Salomon | f932a63 | 2018-04-05 12:46:09 -0400 | [diff] [blame] | 210 | * Gets the maximum supported texture size. |
| 211 | */ |
| 212 | int maxTextureSize() const; |
| 213 | |
| 214 | /** |
| 215 | * Gets the maximum supported render target size. |
| 216 | */ |
| 217 | int maxRenderTargetSize() const; |
| 218 | |
| 219 | /** |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 220 | * Can a SkImage be created with the given color type. |
| 221 | */ |
| 222 | bool colorTypeSupportedAsImage(SkColorType) const; |
| 223 | |
| 224 | /** |
| 225 | * Can a SkSurface be created with the given color type. To check whether MSAA is supported |
| 226 | * use maxSurfaceSampleCountForColorType(). |
| 227 | */ |
| 228 | bool colorTypeSupportedAsSurface(SkColorType colorType) const { |
| 229 | return this->maxSurfaceSampleCountForColorType(colorType) > 0; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA |
| 234 | * rendering is supported for the color type. 0 is returned if rendering to this color type |
| 235 | * is not supported at all. |
| 236 | */ |
| 237 | int maxSurfaceSampleCountForColorType(SkColorType) const; |
| 238 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 239 | /////////////////////////////////////////////////////////////////////////// |
| 240 | // Misc. |
| 241 | |
| 242 | /** |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 243 | * 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] | 244 | */ |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 245 | void flush(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 246 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 247 | /** |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 248 | * Call to ensure all drawing to the context has been issued to the underlying 3D API. After |
| 249 | * issuing all commands, numSemaphore semaphores will be signaled by the gpu. The client passes |
| 250 | * in an array of numSemaphores GrBackendSemaphores. In general these GrBackendSemaphore's can |
| 251 | * be either initialized or not. If they are initialized, the backend uses the passed in |
| 252 | * semaphore. If it is not initialized, a new semaphore is created and the GrBackendSemaphore |
| 253 | * object is initialized with that semaphore. |
| 254 | * |
| 255 | * The client will own and be responsible for deleting the underlying semaphores that are stored |
| 256 | * and returned in initialized GrBackendSemaphore objects. The GrBackendSemaphore objects |
| 257 | * themselves can be deleted as soon as this function returns. |
| 258 | * |
| 259 | * If the backend API is OpenGL only uninitialized GrBackendSemaphores are supported. |
| 260 | * If the backend API is Vulkan either initialized or unitialized semaphores are supported. |
| 261 | * If unitialized, the semaphores which are created will be valid for use only with the VkDevice |
| 262 | * with which they were created. |
| 263 | * |
| 264 | * If this call returns GrSemaphoresSubmited::kNo, the GPU backend will not have created or |
| 265 | * added any semaphores to signal on the GPU. Thus the client should not have the GPU wait on |
| 266 | * any of the semaphores. However, any pending commands to the context will still be flushed. |
| 267 | */ |
| 268 | GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores, |
| 269 | GrBackendSemaphore signalSemaphores[]); |
| 270 | |
| 271 | /** |
joshualitt | 0acd0d3 | 2015-05-07 08:23:19 -0700 | [diff] [blame] | 272 | * An ID associated with this context, guaranteed to be unique. |
| 273 | */ |
| 274 | uint32_t uniqueID() { return fUniqueID; } |
| 275 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 276 | // Provides access to functions that aren't part of the public API. |
| 277 | GrContextPriv contextPriv(); |
| 278 | const GrContextPriv contextPriv() const; |
| 279 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 280 | /** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */ |
| 281 | // Chrome is using this! |
| 282 | void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; |
| 283 | |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 284 | bool supportsDistanceFieldText() const; |
| 285 | |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 286 | protected: |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 287 | GrContext(GrBackendApi, int32_t id = SK_InvalidGenID); |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 288 | |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 289 | bool initCommon(const GrContextOptions&); |
| 290 | virtual bool init(const GrContextOptions&) = 0; // must be called after the ctor! |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 291 | |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 292 | virtual GrAtlasManager* onGetAtlasManager() = 0; |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 293 | |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 294 | const GrBackendApi fBackend; |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 295 | sk_sp<const GrCaps> fCaps; |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 296 | sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy; |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 297 | sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache; |
Robert Phillips | 1056eb8 | 2018-03-01 14:16:41 -0500 | [diff] [blame] | 298 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 299 | private: |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame^] | 300 | // fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed |
| 301 | // after all of its users. Clients of fTaskGroup will generally want to ensure that they call |
| 302 | // wait() on it as they are being destroyed, to avoid the possibility of pending tasks being |
| 303 | // invoked after objects they depend upon have already been destroyed. |
| 304 | std::unique_ptr<SkTaskGroup> fTaskGroup; |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 305 | sk_sp<GrGpu> fGpu; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 306 | GrResourceCache* fResourceCache; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 307 | GrResourceProvider* fResourceProvider; |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 308 | GrProxyProvider* fProxyProvider; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 309 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 310 | // All the GrOp-derived classes use this pool. |
| 311 | sk_sp<GrOpMemoryPool> fOpMemoryPool; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 312 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 313 | GrGlyphCache* fGlyphCache; |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 314 | std::unique_ptr<GrTextBlobCache> fTextBlobCache; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 315 | |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 316 | bool fDisableGpuYUVConversion; |
Brian Osman | 8a83ca4 | 2018-02-12 14:32:17 -0500 | [diff] [blame] | 317 | bool fSharpenMipmappedTextures; |
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 | |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 322 | // In debug builds we guard against improper thread handling |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 323 | // This guard is passed to the GrDrawingManager and, from there to all the |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 324 | // GrRenderTargetContexts. It is also passed to the GrResourceProvider and SkGpuDevice. |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 325 | mutable GrSingleOwner fSingleOwner; |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 326 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 327 | const uint32_t fUniqueID; |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 328 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 329 | std::unique_ptr<GrDrawingManager> fDrawingManager; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 330 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 331 | GrAuditTrail fAuditTrail; |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 332 | |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 333 | GrContextOptions::PersistentCache* fPersistentCache; |
| 334 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 335 | // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 336 | friend class GrContextPriv; |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 337 | |
skia.committer@gmail.com | cdcb2ce | 2013-01-29 07:05:52 +0000 | [diff] [blame] | 338 | /** |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 339 | * These functions create premul <-> unpremul effects, using the specialized round-trip effects |
| 340 | * from GrConfigConversionEffect. |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 341 | */ |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 342 | std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>); |
| 343 | std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 344 | |
| 345 | /** |
Brian Osman | 5ea96bf | 2018-10-02 14:58:05 -0400 | [diff] [blame] | 346 | * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words, |
| 347 | * did we find a pair of round-trip preserving conversion effects? |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 348 | */ |
| 349 | bool validPMUPMConversionExists(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 350 | |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 351 | /** |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 352 | * A callback similar to the above for use by the TextBlobCache |
| 353 | * TODO move textblob draw calls below context so we can use the call above. |
| 354 | */ |
| 355 | static void TextBlobCacheOverBudgetCB(void* data); |
| 356 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 357 | typedef SkRefCnt INHERITED; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 358 | }; |
| 359 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 360 | /** |
| 361 | * Can be used to perform actions related to the generating GrContext in a thread safe manner. The |
| 362 | * proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrContext. |
| 363 | */ |
Robert Phillips | 155dd71 | 2018-03-29 17:20:46 -0400 | [diff] [blame] | 364 | class SK_API GrContextThreadSafeProxy : public SkRefCnt { |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 365 | public: |
Brian Salomon | 103d6f6 | 2018-05-11 11:19:22 -0400 | [diff] [blame] | 366 | ~GrContextThreadSafeProxy(); |
| 367 | |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 368 | bool matches(GrContext* context) const { return context->uniqueID() == fContextUniqueID; } |
| 369 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 370 | /** |
| 371 | * Create a surface characterization for a DDL that will be replayed into the GrContext |
| 372 | * that created this proxy. On failure the resulting characterization will be invalid (i.e., |
| 373 | * "!c.isValid()"). |
| 374 | * |
| 375 | * @param cacheMaxResourceBytes The max resource bytes limit that will be in effect when the |
| 376 | * DDL created with this characterization is replayed. |
| 377 | * Note: the contract here is that the DDL will be created as |
| 378 | * if it had a full 'cacheMaxResourceBytes' to use. If replayed |
| 379 | * into a GrContext that already has locked GPU memory, the |
| 380 | * replay can exceed the budget. To rephrase, all resource |
| 381 | * allocation decisions are made at record time and at playback |
| 382 | * time the budget limits will be ignored. |
| 383 | * @param ii The image info specifying properties of the SkSurface that |
| 384 | * the DDL created with this characterization will be replayed |
| 385 | * into. |
| 386 | * Note: Ganesh doesn't make use of the SkImageInfo's alphaType |
| 387 | * @param backendFormat Information about the format of the GPU surface that will |
| 388 | * back the SkSurface upon replay |
| 389 | * @param sampleCount The sample count of the SkSurface that the DDL created with |
| 390 | * this characterization will be replayed into |
| 391 | * @param origin The origin of the SkSurface that the DDL created with this |
| 392 | * characterization will be replayed into |
| 393 | * @param surfaceProps The surface properties of the SkSurface that the DDL created |
| 394 | * with this characterization will be replayed into |
| 395 | * @param isMipMapped Will the surface the DDL will be replayed into have space |
| 396 | * allocated for mipmaps? |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 397 | * @param willUseGLFBO0 Will the surface the DDL will be replayed into be backed by GL |
| 398 | * FBO 0. This flag is only valid if using an GL backend. |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 399 | */ |
| 400 | SkSurfaceCharacterization createCharacterization( |
| 401 | size_t cacheMaxResourceBytes, |
| 402 | const SkImageInfo& ii, const GrBackendFormat& backendFormat, |
| 403 | int sampleCount, GrSurfaceOrigin origin, |
| 404 | const SkSurfaceProps& surfaceProps, |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 405 | bool isMipMapped, bool willUseGLFBO0 = false); |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 406 | |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 407 | bool operator==(const GrContextThreadSafeProxy& that) const { |
| 408 | // Each GrContext should only ever have a single thread-safe proxy. |
| 409 | SkASSERT((this == &that) == (fContextUniqueID == that.fContextUniqueID)); |
| 410 | return this == &that; |
| 411 | } |
| 412 | |
| 413 | bool operator!=(const GrContextThreadSafeProxy& that) const { return !(*this == that); } |
| 414 | |
| 415 | // Provides access to functions that aren't part of the public API. |
| 416 | GrContextThreadSafeProxyPriv priv(); |
| 417 | const GrContextThreadSafeProxyPriv priv() const; |
Robert Phillips | 94458ee | 2018-03-06 13:41:51 -0500 | [diff] [blame] | 418 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 419 | private: |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 420 | // DDL TODO: need to add unit tests for backend & maybe options |
| 421 | GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, |
| 422 | uint32_t uniqueID, |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 423 | GrBackendApi backend, |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 424 | const GrContextOptions& options, |
| 425 | sk_sp<GrSkSLFPFactoryCache> cache); |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 426 | |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 427 | sk_sp<const GrCaps> fCaps; |
| 428 | const uint32_t fContextUniqueID; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 429 | const GrBackendApi fBackend; |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 430 | const GrContextOptions fOptions; |
| 431 | sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 432 | |
Robert Phillips | fde6fa0 | 2018-03-02 08:53:14 -0500 | [diff] [blame] | 433 | friend class GrDirectContext; // To construct this object |
Brian Salomon | 52aacd6 | 2018-05-10 12:57:17 -0400 | [diff] [blame] | 434 | friend class GrContextThreadSafeProxyPriv; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 435 | |
| 436 | typedef SkRefCnt INHERITED; |
| 437 | }; |
| 438 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 439 | #endif |