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 | |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 11 | #include "GrCaps.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 12 | #include "SkMatrix.h" |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 13 | #include "SkPathEffect.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 14 | #include "SkTypes.h" |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 15 | #include "../private/GrAuditTrail.h" |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 16 | #include "../private/GrSingleOwner.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 | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 19 | class GrAtlasGlyphCache; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 20 | class GrBackendSemaphore; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 21 | class GrContextPriv; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 22 | class GrContextThreadSafeProxy; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 23 | class GrDrawingManager; |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 24 | struct GrDrawOpAtlasConfig; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 25 | class GrFragmentProcessor; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 26 | struct GrGLInterface; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 27 | class GrGpu; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 28 | class GrIndexBuffer; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 29 | struct GrMockOptions; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 30 | class GrOvalRenderer; |
commit-bot@chromium.org | 5c8ee25 | 2013-11-01 15:23:44 +0000 | [diff] [blame] | 31 | class GrPath; |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 32 | class GrProxyProvider; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 33 | class GrRenderTargetContext; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 34 | class GrResourceEntry; |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 35 | class GrResourceCache; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 36 | class GrResourceProvider; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 37 | class GrSamplerState; |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 38 | class GrSurfaceProxy; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 39 | class GrTextBlobCache; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 40 | class GrTextContext; |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 41 | class GrTextureProxy; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 42 | class GrVertexBuffer; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 43 | struct GrVkBackendContext; |
bsalomon | 6c9cd55 | 2016-01-22 07:17:34 -0800 | [diff] [blame] | 44 | class GrSwizzle; |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 45 | class SkTraceMemoryDump; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 46 | |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 47 | class SkImage; |
| 48 | class SkSurfaceProps; |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 49 | class SkTaskGroup; |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 50 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 51 | class SK_API GrContext : public SkRefCnt { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 52 | public: |
| 53 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 54 | * Creates a GrContext for a backend context. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 55 | */ |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 56 | static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options); |
| 57 | static GrContext* Create(GrBackend, GrBackendContext); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 58 | |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 59 | static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&); |
| 60 | static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>); |
Brian Salomon | 990014d | 2017-12-07 16:23:39 -0500 | [diff] [blame] | 61 | // Deprecated |
| 62 | static sk_sp<GrContext> MakeGL(const GrGLInterface*); |
| 63 | static sk_sp<GrContext> MakeGL(const GrGLInterface*, const GrContextOptions&); |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 64 | |
| 65 | #ifdef SK_VULKAN |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 66 | static sk_sp<GrContext> MakeVulkan(sk_sp<const GrVkBackendContext>, const GrContextOptions&); |
| 67 | static sk_sp<GrContext> MakeVulkan(sk_sp<const GrVkBackendContext>); |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 68 | #endif |
| 69 | |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 70 | #ifdef SK_METAL |
| 71 | /** |
| 72 | * Makes a GrContext which uses Metal as the backend. The device parameter is an MTLDevice |
| 73 | * and queue is an MTLCommandQueue which should be used by the backend. These objects must |
| 74 | * have a ref on them which can be transferred to Ganesh which will release the ref when the |
| 75 | * GrContext is destroyed. |
| 76 | */ |
| 77 | static sk_sp<GrContext> MakeMetal(void* device, void* queue, const GrContextOptions& options); |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 78 | static sk_sp<GrContext> MakeMetal(void* device, void* queue); |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 79 | #endif |
| 80 | |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 81 | static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&); |
| 82 | static sk_sp<GrContext> MakeMock(const GrMockOptions*); |
| 83 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 84 | virtual ~GrContext(); |
| 85 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 86 | sk_sp<GrContextThreadSafeProxy> threadSafeProxy(); |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 87 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 88 | /** |
| 89 | * The GrContext normally assumes that no outsider is setting state |
| 90 | * within the underlying 3D API's context/device/whatever. This call informs |
| 91 | * the context that the state was modified and it should resend. Shouldn't |
| 92 | * be called frequently for good performance. |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 93 | * The flag bits, state, is dpendent on which backend is used by the |
| 94 | * context, either GL or D3D (possible in future). |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 95 | */ |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 96 | void resetContext(uint32_t state = kAll_GrBackendState); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 97 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 98 | /** |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 99 | * Callback function to allow classes to cleanup on GrContext destruction. |
| 100 | * The 'info' field is filled in with the 'info' passed to addCleanUp. |
| 101 | */ |
| 102 | typedef void (*PFCleanUpFunc)(const GrContext* context, void* info); |
| 103 | |
| 104 | /** |
| 105 | * Add a function to be called from within GrContext's destructor. |
| 106 | * This gives classes a chance to free resources held on a per context basis. |
| 107 | * The 'info' parameter will be stored and passed to the callback function. |
| 108 | */ |
| 109 | void addCleanUp(PFCleanUpFunc cleanUp, void* info) { |
| 110 | CleanUpData* entry = fCleanUpData.push(); |
| 111 | |
| 112 | entry->fFunc = cleanUp; |
| 113 | entry->fInfo = info; |
| 114 | } |
| 115 | |
| 116 | /** |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 117 | * 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] | 118 | * usable. Call this if you have lost the associated GPU context, and thus internal texture, |
| 119 | * buffer, etc. references/IDs are now invalid. Calling this ensures that the destructors of the |
| 120 | * GrContext and any of its created resource objects will not make backend 3D API calls. Content |
| 121 | * rendered but not previously flushed may be lost. After this function is called all subsequent |
| 122 | * calls on the GrContext will fail or be no-ops. |
| 123 | * |
| 124 | * The typical use case for this function is that the underlying 3D context was lost and further |
| 125 | * API calls may crash. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 126 | */ |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 127 | void abandonContext(); |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 128 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 129 | /** |
| 130 | * This is similar to abandonContext() however the underlying 3D context is not yet lost and |
| 131 | * the GrContext will cleanup all allocated resources before returning. After returning it will |
| 132 | * assume that the underlying context may no longer be valid. |
| 133 | * |
| 134 | * The typical use case for this function is that the client is going to destroy the 3D context |
| 135 | * but can't guarantee that GrContext will be destroyed first (perhaps because it may be ref'ed |
| 136 | * elsewhere by either the client or Skia objects). |
| 137 | */ |
| 138 | void releaseResourcesAndAbandonContext(); |
| 139 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 140 | /////////////////////////////////////////////////////////////////////////// |
| 141 | // Resource Cache |
| 142 | |
| 143 | /** |
| 144 | * Return the current GPU resource cache limits. |
| 145 | * |
| 146 | * @param maxResources If non-null, returns maximum number of resources that |
| 147 | * can be held in the cache. |
| 148 | * @param maxResourceBytes If non-null, returns maximum number of bytes of |
| 149 | * video memory that can be held in the cache. |
| 150 | */ |
| 151 | void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * Gets the current GPU resource cache usage. |
| 155 | * |
| 156 | * @param resourceCount If non-null, returns the number of resources that are held in the |
| 157 | * cache. |
| 158 | * @param maxResourceBytes If non-null, returns the total number of bytes of video memory held |
| 159 | * in the cache. |
| 160 | */ |
| 161 | void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const; |
| 162 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 163 | /** |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 164 | * Gets the number of bytes in the cache consumed by purgeable (e.g. unlocked) resources. |
| 165 | */ |
| 166 | size_t getResourceCachePurgeableBytes() const; |
| 167 | |
| 168 | /** |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 169 | * Specify the GPU resource cache limits. If the current cache exceeds either |
| 170 | * of these, it will be purged (LRU) to keep the cache within these limits. |
| 171 | * |
| 172 | * @param maxResources The maximum number of resources that can be held in |
| 173 | * the cache. |
| 174 | * @param maxResourceBytes The maximum number of bytes of video memory |
| 175 | * that can be held in the cache. |
| 176 | */ |
| 177 | void setResourceCacheLimits(int maxResources, size_t maxResourceBytes); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 178 | |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 179 | /** |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 180 | * 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] | 181 | * pressure. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 182 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 183 | void freeGpuResources(); |
| 184 | |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 185 | /** |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 186 | * Purge all the unlocked resources from the cache. |
| 187 | * This entry point is mainly meant for timing texture uploads |
| 188 | * and is not defined in normal builds of Skia. |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 189 | */ |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 190 | void purgeAllUnlockedResources(); |
| 191 | |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 192 | /** |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 193 | * Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are |
| 194 | * otherwise marked for deletion, regardless of whether the context is under budget. |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 195 | */ |
Jim Van Verth | 76d917c | 2017-12-13 09:26:37 -0500 | [diff] [blame] | 196 | void performDeferredCleanup(std::chrono::milliseconds msNotUsed); |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 197 | |
Mike Klein | 4b6bde7 | 2017-12-14 07:46:55 -0500 | [diff] [blame] | 198 | // Temporary compatibility API for Android. |
| 199 | void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed) { |
| 200 | this->performDeferredCleanup(msNotUsed); |
| 201 | } |
| 202 | |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 203 | /** |
| 204 | * Purge unlocked resources from the cache until the the provided byte count has been reached |
| 205 | * or we have purged all unlocked resources. The default policy is to purge in LRU order, but |
| 206 | * can be overridden to prefer purging scratch resources (in LRU order) prior to purging other |
| 207 | * resource types. |
| 208 | * |
| 209 | * @param maxBytesToPurge the desired number of bytes to be purged. |
| 210 | * @param preferScratchResources If true scratch resources will be purged prior to other |
| 211 | * resource types. |
| 212 | */ |
| 213 | void purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources); |
| 214 | |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 215 | /** Access the context capabilities */ |
Brian Salomon | eace8cd | 2017-12-08 13:11:11 -0500 | [diff] [blame] | 216 | const GrCaps* caps() const { return fCaps.get(); } |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 217 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 218 | /** |
| 219 | * Can a SkImage be created with the given color type. |
| 220 | */ |
| 221 | bool colorTypeSupportedAsImage(SkColorType) const; |
| 222 | |
| 223 | /** |
| 224 | * Can a SkSurface be created with the given color type. To check whether MSAA is supported |
| 225 | * use maxSurfaceSampleCountForColorType(). |
| 226 | */ |
| 227 | bool colorTypeSupportedAsSurface(SkColorType colorType) const { |
| 228 | return this->maxSurfaceSampleCountForColorType(colorType) > 0; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA |
| 233 | * rendering is supported for the color type. 0 is returned if rendering to this color type |
| 234 | * is not supported at all. |
| 235 | */ |
| 236 | int maxSurfaceSampleCountForColorType(SkColorType) const; |
| 237 | |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 238 | /* |
| 239 | * Create a new render target context backed by a deferred-style |
| 240 | * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for |
| 241 | * renderTargetContexts created via this entry point. |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 242 | */ |
Robert Phillips | 2af746c | 2017-04-21 12:28:48 +0000 | [diff] [blame] | 243 | sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext( |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 244 | SkBackingFit fit, |
Robert Phillips | 2af746c | 2017-04-21 12:28:48 +0000 | [diff] [blame] | 245 | int width, int height, |
| 246 | GrPixelConfig config, |
| 247 | sk_sp<SkColorSpace> colorSpace, |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 248 | int sampleCnt = 1, |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 249 | GrMipMapped = GrMipMapped::kNo, |
Robert Phillips | 2af746c | 2017-04-21 12:28:48 +0000 | [diff] [blame] | 250 | GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin, |
| 251 | const SkSurfaceProps* surfaceProps = nullptr, |
| 252 | SkBudgeted = SkBudgeted::kYes); |
robertphillips | 48fde9c | 2016-09-06 05:20:20 -0700 | [diff] [blame] | 253 | /* |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 254 | * This method will attempt to create a renderTargetContext that has, at least, the number of |
robertphillips | 48fde9c | 2016-09-06 05:20:20 -0700 | [diff] [blame] | 255 | * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be |
| 256 | * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA). |
| 257 | * SRGB-ness will be preserved. |
| 258 | */ |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 259 | sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback( |
| 260 | SkBackingFit fit, |
| 261 | int width, int height, |
| 262 | GrPixelConfig config, |
| 263 | sk_sp<SkColorSpace> colorSpace, |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 264 | int sampleCnt = 1, |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 265 | GrMipMapped = GrMipMapped::kNo, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 266 | GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin, |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 267 | const SkSurfaceProps* surfaceProps = nullptr, |
| 268 | SkBudgeted budgeted = SkBudgeted::kYes); |
| 269 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 270 | /////////////////////////////////////////////////////////////////////////// |
| 271 | // Misc. |
| 272 | |
| 273 | /** |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 274 | * 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] | 275 | */ |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 276 | void flush(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 277 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 278 | /** |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 279 | * Call to ensure all drawing to the context has been issued to the underlying 3D API. After |
| 280 | * issuing all commands, numSemaphore semaphores will be signaled by the gpu. The client passes |
| 281 | * in an array of numSemaphores GrBackendSemaphores. In general these GrBackendSemaphore's can |
| 282 | * be either initialized or not. If they are initialized, the backend uses the passed in |
| 283 | * semaphore. If it is not initialized, a new semaphore is created and the GrBackendSemaphore |
| 284 | * object is initialized with that semaphore. |
| 285 | * |
| 286 | * The client will own and be responsible for deleting the underlying semaphores that are stored |
| 287 | * and returned in initialized GrBackendSemaphore objects. The GrBackendSemaphore objects |
| 288 | * themselves can be deleted as soon as this function returns. |
| 289 | * |
| 290 | * If the backend API is OpenGL only uninitialized GrBackendSemaphores are supported. |
| 291 | * If the backend API is Vulkan either initialized or unitialized semaphores are supported. |
| 292 | * If unitialized, the semaphores which are created will be valid for use only with the VkDevice |
| 293 | * with which they were created. |
| 294 | * |
| 295 | * If this call returns GrSemaphoresSubmited::kNo, the GPU backend will not have created or |
| 296 | * added any semaphores to signal on the GPU. Thus the client should not have the GPU wait on |
| 297 | * any of the semaphores. However, any pending commands to the context will still be flushed. |
| 298 | */ |
| 299 | GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores, |
| 300 | GrBackendSemaphore signalSemaphores[]); |
| 301 | |
| 302 | /** |
joshualitt | 0acd0d3 | 2015-05-07 08:23:19 -0700 | [diff] [blame] | 303 | * An ID associated with this context, guaranteed to be unique. |
| 304 | */ |
| 305 | uint32_t uniqueID() { return fUniqueID; } |
| 306 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 307 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 308 | // Functions intended for internal use only. |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 309 | bool abandoned() const; |
bsalomon@google.com | 9923c2b | 2012-06-06 18:21:18 +0000 | [diff] [blame] | 310 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 311 | /** Reset GPU stats */ |
| 312 | void resetGpuStats() const ; |
| 313 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 314 | /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ |
| 315 | void dumpCacheStats(SkString*) const; |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 316 | void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 317 | void printCacheStats() const; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 318 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 319 | /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ |
| 320 | void dumpGpuStats(SkString*) const; |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 321 | void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 322 | void printGpuStats() const; |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 323 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 324 | /** Returns a string with detailed information about the context & GPU, in JSON format. */ |
| 325 | SkString dump() const; |
| 326 | |
joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 327 | /** Specify the TextBlob cache limit. If the current cache exceeds this limit it will purge. |
| 328 | this is for testing only */ |
| 329 | void setTextBlobCacheLimit_ForTesting(size_t bytes); |
| 330 | |
joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 331 | /** Specify the sizes of the GrAtlasTextContext atlases. The configs pointer below should be |
| 332 | to an array of 3 entries */ |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 333 | void setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs); |
joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 334 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 335 | /** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */ |
| 336 | void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; |
| 337 | |
Robert Phillips | 33667da | 2016-12-20 11:05:30 -0500 | [diff] [blame] | 338 | /** Get pointer to atlas texture for given mask format. Note that this wraps an |
| 339 | actively mutating texture in an SkImage. This could yield unexpected results |
| 340 | if it gets cached or used more generally. */ |
Jim Van Verth | 87d18ce | 2018-01-22 12:45:47 -0500 | [diff] [blame] | 341 | sk_sp<SkImage> getFontAtlasImage_ForTesting(GrMaskFormat format, uint32_t index = 0); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 342 | |
joshualitt | 5651ee6 | 2016-01-11 10:39:11 -0800 | [diff] [blame] | 343 | GrAuditTrail* getAuditTrail() { return &fAuditTrail; } |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 344 | |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 345 | GrContextOptions::PersistentCache* getPersistentCache() { return fPersistentCache; } |
| 346 | |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 347 | /** This is only useful for debug purposes */ |
| 348 | SkDEBUGCODE(GrSingleOwner* debugSingleOwner() const { return &fSingleOwner; } ) |
| 349 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 350 | // Provides access to functions that aren't part of the public API. |
| 351 | GrContextPriv contextPriv(); |
| 352 | const GrContextPriv contextPriv() const; |
| 353 | |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 354 | protected: |
| 355 | GrContext(GrContextThreadSafeProxy*); |
| 356 | GrContext(GrBackend); |
| 357 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 358 | private: |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 359 | sk_sp<GrGpu> fGpu; |
Brian Salomon | eace8cd | 2017-12-08 13:11:11 -0500 | [diff] [blame] | 360 | sk_sp<const GrCaps> fCaps; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 361 | GrResourceCache* fResourceCache; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 362 | GrResourceProvider* fResourceProvider; |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 363 | GrProxyProvider* fProxyProvider; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 364 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 365 | sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 366 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 367 | GrAtlasGlyphCache* fAtlasGlyphCache; |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 368 | std::unique_ptr<GrTextBlobCache> fTextBlobCache; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 369 | |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 370 | bool fDisableGpuYUVConversion; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 371 | bool fDidTestPMConversions; |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 372 | // true if the PM/UPM conversion succeeded; false otherwise |
| 373 | bool fPMUPMConversionsRoundTrip; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 374 | |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 375 | // In debug builds we guard against improper thread handling |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 376 | // 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] | 377 | // GrRenderTargetContexts. It is also passed to the GrResourceProvider and SkGpuDevice. |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 378 | mutable GrSingleOwner fSingleOwner; |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 379 | |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 380 | std::unique_ptr<SkTaskGroup> fTaskGroup; |
| 381 | |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 382 | struct CleanUpData { |
| 383 | PFCleanUpFunc fFunc; |
| 384 | void* fInfo; |
| 385 | }; |
| 386 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 387 | SkTDArray<CleanUpData> fCleanUpData; |
robertphillips@google.com | 44a91dc | 2013-07-25 15:32:06 +0000 | [diff] [blame] | 388 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 389 | const uint32_t fUniqueID; |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 390 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 391 | std::unique_ptr<GrDrawingManager> fDrawingManager; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 392 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 393 | GrAuditTrail fAuditTrail; |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 394 | |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 395 | const GrBackend fBackend; |
Greg Daniel | fc978fd | 2017-04-13 09:54:12 -0400 | [diff] [blame] | 396 | |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 397 | GrContextOptions::PersistentCache* fPersistentCache; |
| 398 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 399 | // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 400 | friend class GrContextPriv; |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 401 | |
Robert Phillips | 88260b5 | 2018-01-19 12:56:09 -0500 | [diff] [blame] | 402 | bool init(const GrContextOptions&); // init must be called after either constructor. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 403 | |
skia.committer@gmail.com | cdcb2ce | 2013-01-29 07:05:52 +0000 | [diff] [blame] | 404 | /** |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 405 | * These functions create premul <-> unpremul effects. If the second argument is 'true', they |
| 406 | * use the specialized round-trip effects from GrConfigConversionEffect, otherwise they |
| 407 | * create effects that do naive multiply or divide. |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 408 | */ |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 409 | std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>, |
| 410 | bool useConfigConversionEffect); |
| 411 | std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>, |
| 412 | bool useConfigConversionEffect); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 413 | |
| 414 | /** |
| 415 | * Returns true if createPMtoUPMEffect and createUPMToPMEffect will succeed for non-sRGB 8888 |
| 416 | * configs. In other words, did we find a pair of round-trip preserving conversion effects? |
| 417 | */ |
| 418 | bool validPMUPMConversionExists(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 419 | |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 420 | /** |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 421 | * A callback similar to the above for use by the TextBlobCache |
| 422 | * TODO move textblob draw calls below context so we can use the call above. |
| 423 | */ |
| 424 | static void TextBlobCacheOverBudgetCB(void* data); |
| 425 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 426 | typedef SkRefCnt INHERITED; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 427 | }; |
| 428 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 429 | /** |
| 430 | * Can be used to perform actions related to the generating GrContext in a thread safe manner. The |
| 431 | * proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrContext. |
| 432 | */ |
| 433 | class GrContextThreadSafeProxy : public SkRefCnt { |
Robert Phillips | 8def8bf | 2017-11-30 08:46:03 -0500 | [diff] [blame] | 434 | public: |
| 435 | bool matches(GrContext* context) const { return context->uniqueID() == fContextUniqueID; } |
| 436 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 437 | private: |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 438 | // DDL TODO: need to add unit tests for backend & maybe options |
| 439 | GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, |
| 440 | uint32_t uniqueID, |
| 441 | GrBackend backend, |
| 442 | const GrContextOptions& options) |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 443 | : fCaps(std::move(caps)) |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 444 | , fContextUniqueID(uniqueID) |
| 445 | , fBackend(backend) |
| 446 | , fOptions(options) { |
| 447 | } |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 448 | |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 449 | sk_sp<const GrCaps> fCaps; |
| 450 | const uint32_t fContextUniqueID; |
| 451 | const GrBackend fBackend; |
| 452 | const GrContextOptions fOptions; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 453 | |
| 454 | friend class GrContext; |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 455 | friend class GrContextPriv; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 456 | friend class SkImage; |
| 457 | |
| 458 | typedef SkRefCnt INHERITED; |
| 459 | }; |
| 460 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 461 | #endif |