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 "GrColor.h" |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 13 | #include "GrRenderTarget.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 14 | #include "SkMatrix.h" |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 15 | #include "SkPathEffect.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 16 | #include "SkTypes.h" |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 17 | #include "../private/GrAuditTrail.h" |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 18 | #include "../private/GrSingleOwner.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 19 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 20 | class GrAtlasGlyphCache; |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 21 | struct GrContextOptions; |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 22 | class GrContextPriv; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 23 | class GrContextThreadSafeProxy; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 24 | class GrDrawingManager; |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 25 | struct GrDrawOpAtlasConfig; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 26 | class GrRenderTargetContext; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 27 | class GrFragmentProcessor; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 28 | class GrGpu; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 29 | class GrIndexBuffer; |
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; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 32 | class GrPipelineBuilder; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 33 | class GrResourceEntry; |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 34 | class GrResourceCache; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 35 | class GrResourceProvider; |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 36 | class GrSamplerParams; |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame^] | 37 | class GrSurfaceProxy; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 38 | class GrTextBlobCache; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 39 | class GrTextContext; |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 40 | class GrTextureProxy; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 41 | class GrVertexBuffer; |
bsalomon | 6c9cd55 | 2016-01-22 07:17:34 -0800 | [diff] [blame] | 42 | class GrSwizzle; |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 43 | class SkTraceMemoryDump; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 44 | |
Mike Reed | 84dd857 | 2017-03-08 22:21:00 -0500 | [diff] [blame] | 45 | class SkImage; |
| 46 | class SkSurfaceProps; |
| 47 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 48 | class SK_API GrContext : public SkRefCnt { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 49 | public: |
| 50 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 51 | * Creates a GrContext for a backend context. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 52 | */ |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 53 | static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options); |
| 54 | static GrContext* Create(GrBackend, GrBackendContext); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 55 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 56 | /** |
| 57 | * Only defined in test apps. |
| 58 | */ |
| 59 | static GrContext* CreateMockContext(); |
| 60 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 61 | virtual ~GrContext(); |
| 62 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 63 | sk_sp<GrContextThreadSafeProxy> threadSafeProxy(); |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 64 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 65 | /** |
| 66 | * The GrContext normally assumes that no outsider is setting state |
| 67 | * within the underlying 3D API's context/device/whatever. This call informs |
| 68 | * the context that the state was modified and it should resend. Shouldn't |
| 69 | * be called frequently for good performance. |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 70 | * The flag bits, state, is dpendent on which backend is used by the |
| 71 | * context, either GL or D3D (possible in future). |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 72 | */ |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 73 | void resetContext(uint32_t state = kAll_GrBackendState); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 74 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 75 | /** |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 76 | * Callback function to allow classes to cleanup on GrContext destruction. |
| 77 | * The 'info' field is filled in with the 'info' passed to addCleanUp. |
| 78 | */ |
| 79 | typedef void (*PFCleanUpFunc)(const GrContext* context, void* info); |
| 80 | |
| 81 | /** |
| 82 | * Add a function to be called from within GrContext's destructor. |
| 83 | * This gives classes a chance to free resources held on a per context basis. |
| 84 | * The 'info' parameter will be stored and passed to the callback function. |
| 85 | */ |
| 86 | void addCleanUp(PFCleanUpFunc cleanUp, void* info) { |
| 87 | CleanUpData* entry = fCleanUpData.push(); |
| 88 | |
| 89 | entry->fFunc = cleanUp; |
| 90 | entry->fInfo = info; |
| 91 | } |
| 92 | |
| 93 | /** |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 94 | * Abandons all GPU resources and assumes the underlying backend 3D API context is not longer |
| 95 | * usable. Call this if you have lost the associated GPU context, and thus internal texture, |
| 96 | * buffer, etc. references/IDs are now invalid. Calling this ensures that the destructors of the |
| 97 | * GrContext and any of its created resource objects will not make backend 3D API calls. Content |
| 98 | * rendered but not previously flushed may be lost. After this function is called all subsequent |
| 99 | * calls on the GrContext will fail or be no-ops. |
| 100 | * |
| 101 | * The typical use case for this function is that the underlying 3D context was lost and further |
| 102 | * API calls may crash. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 103 | */ |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 104 | void abandonContext(); |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 105 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 106 | /** |
| 107 | * This is similar to abandonContext() however the underlying 3D context is not yet lost and |
| 108 | * the GrContext will cleanup all allocated resources before returning. After returning it will |
| 109 | * assume that the underlying context may no longer be valid. |
| 110 | * |
| 111 | * The typical use case for this function is that the client is going to destroy the 3D context |
| 112 | * but can't guarantee that GrContext will be destroyed first (perhaps because it may be ref'ed |
| 113 | * elsewhere by either the client or Skia objects). |
| 114 | */ |
| 115 | void releaseResourcesAndAbandonContext(); |
| 116 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 117 | /////////////////////////////////////////////////////////////////////////// |
| 118 | // Resource Cache |
| 119 | |
| 120 | /** |
| 121 | * Return the current GPU resource cache limits. |
| 122 | * |
| 123 | * @param maxResources If non-null, returns maximum number of resources that |
| 124 | * can be held in the cache. |
| 125 | * @param maxResourceBytes If non-null, returns maximum number of bytes of |
| 126 | * video memory that can be held in the cache. |
| 127 | */ |
| 128 | void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * Gets the current GPU resource cache usage. |
| 132 | * |
| 133 | * @param resourceCount If non-null, returns the number of resources that are held in the |
| 134 | * cache. |
| 135 | * @param maxResourceBytes If non-null, returns the total number of bytes of video memory held |
| 136 | * in the cache. |
| 137 | */ |
| 138 | void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const; |
| 139 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 140 | /** |
| 141 | * Specify the GPU resource cache limits. If the current cache exceeds either |
| 142 | * of these, it will be purged (LRU) to keep the cache within these limits. |
| 143 | * |
| 144 | * @param maxResources The maximum number of resources that can be held in |
| 145 | * the cache. |
| 146 | * @param maxResourceBytes The maximum number of bytes of video memory |
| 147 | * that can be held in the cache. |
| 148 | */ |
| 149 | void setResourceCacheLimits(int maxResources, size_t maxResourceBytes); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 150 | |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 151 | /** |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 152 | * 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] | 153 | * pressure. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 154 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 155 | void freeGpuResources(); |
| 156 | |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 157 | /** |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 158 | * Purge all the unlocked resources from the cache. |
| 159 | * This entry point is mainly meant for timing texture uploads |
| 160 | * and is not defined in normal builds of Skia. |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 161 | */ |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 162 | void purgeAllUnlockedResources(); |
| 163 | |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 164 | /** |
| 165 | * Purge GPU resources that haven't been used in the past 'ms' milliseconds, regardless of |
| 166 | * whether the context is currently under budget. |
| 167 | */ |
| 168 | void purgeResourcesNotUsedInMs(std::chrono::milliseconds ms); |
| 169 | |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 170 | /** Access the context capabilities */ |
| 171 | const GrCaps* caps() const { return fCaps; } |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 172 | |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 173 | /** |
| 174 | * Returns the recommended sample count for a render target when using this |
| 175 | * context. |
| 176 | * |
| 177 | * @param config the configuration of the render target. |
| 178 | * @param dpi the display density in dots per inch. |
| 179 | * |
| 180 | * @return sample count that should be perform well and have good enough |
| 181 | * rendering quality for the display. Alternatively returns 0 if |
| 182 | * MSAA is not supported or recommended to be used by default. |
| 183 | */ |
| 184 | int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; |
| 185 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 186 | /** |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 187 | * Create both a GrRenderTarget and a matching GrRenderTargetContext to wrap it. |
| 188 | * We guarantee that "asTexture" will succeed for renderTargetContexts created |
robertphillips | ebf30e8 | 2016-05-11 08:34:39 -0700 | [diff] [blame] | 189 | * via this entry point. |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 190 | */ |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 191 | sk_sp<GrRenderTargetContext> makeRenderTargetContext( |
| 192 | SkBackingFit fit, |
| 193 | int width, int height, |
| 194 | GrPixelConfig config, |
| 195 | sk_sp<SkColorSpace> colorSpace, |
| 196 | int sampleCnt = 0, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 197 | GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 198 | const SkSurfaceProps* surfaceProps = nullptr, |
| 199 | SkBudgeted = SkBudgeted::kYes); |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 200 | |
Brian Salomon | aeac5d8 | 2016-10-29 00:13:29 -0400 | [diff] [blame] | 201 | // Create a new render target context as above but have it backed by a deferred-style |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 202 | // GrRenderTargetProxy rather than one that is backed by an actual GrRenderTarget |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 203 | sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext( |
| 204 | SkBackingFit fit, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 205 | int width, int height, |
| 206 | GrPixelConfig config, |
| 207 | sk_sp<SkColorSpace> colorSpace, |
| 208 | int sampleCnt = 0, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 209 | GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 210 | const SkSurfaceProps* surfaceProps = nullptr, |
| 211 | SkBudgeted = SkBudgeted::kYes); |
robertphillips | 48fde9c | 2016-09-06 05:20:20 -0700 | [diff] [blame] | 212 | /* |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 213 | * 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] | 214 | * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be |
| 215 | * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA). |
| 216 | * SRGB-ness will be preserved. |
| 217 | */ |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 218 | sk_sp<GrRenderTargetContext> makeRenderTargetContextWithFallback( |
robertphillips | 48fde9c | 2016-09-06 05:20:20 -0700 | [diff] [blame] | 219 | SkBackingFit fit, |
| 220 | int width, int height, |
| 221 | GrPixelConfig config, |
| 222 | sk_sp<SkColorSpace> colorSpace, |
| 223 | int sampleCnt = 0, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 224 | GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin, |
robertphillips | 48fde9c | 2016-09-06 05:20:20 -0700 | [diff] [blame] | 225 | const SkSurfaceProps* surfaceProps = nullptr, |
| 226 | SkBudgeted budgeted = SkBudgeted::kYes); |
| 227 | |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 228 | // Create a new render target context as above but have it backed by a deferred-style |
| 229 | // GrRenderTargetProxy rather than one that is backed by an actual GrRenderTarget |
| 230 | sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback( |
| 231 | SkBackingFit fit, |
| 232 | int width, int height, |
| 233 | GrPixelConfig config, |
| 234 | sk_sp<SkColorSpace> colorSpace, |
| 235 | int sampleCnt = 0, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 236 | GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin, |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 237 | const SkSurfaceProps* surfaceProps = nullptr, |
| 238 | SkBudgeted budgeted = SkBudgeted::kYes); |
| 239 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 240 | /////////////////////////////////////////////////////////////////////////// |
| 241 | // Misc. |
| 242 | |
| 243 | /** |
| 244 | * Call to ensure all drawing to the context has been issued to the |
| 245 | * underlying 3D API. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 246 | */ |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 247 | void flush(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 248 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 249 | /** |
| 250 | * These flags can be used with the read/write pixels functions below. |
| 251 | */ |
| 252 | enum PixelOpsFlags { |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 253 | /** The GrContext will not be flushed before the surface read or write. This means that |
| 254 | the read or write may occur before previous draws have executed. */ |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 255 | kDontFlush_PixelOpsFlag = 0x1, |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 256 | /** Any surface writes should be flushed to the backend 3D API after the surface operation |
| 257 | is complete */ |
| 258 | kFlushWrites_PixelOp = 0x2, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 259 | /** The src for write or dst read is unpremultiplied. This is only respected if both the |
| 260 | config src and dst configs are an RGBA/BGRA 8888 format. */ |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 261 | kUnpremul_PixelOpsFlag = 0x4, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 262 | }; |
| 263 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 264 | /** |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 265 | * Reads a rectangle of pixels from a surface. |
| 266 | * @param surface the surface to read from. |
Brian Osman | b62ea22 | 2016-12-22 11:12:16 -0500 | [diff] [blame] | 267 | * @param srcColorSpace color space of the surface |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 268 | * @param left left edge of the rectangle to read (inclusive) |
| 269 | * @param top top edge of the rectangle to read (inclusive) |
| 270 | * @param width width of rectangle to read in pixels. |
| 271 | * @param height height of rectangle to read in pixels. |
| 272 | * @param config the pixel config of the destination buffer |
Brian Osman | b62ea22 | 2016-12-22 11:12:16 -0500 | [diff] [blame] | 273 | * @param dstColorSpace color space of the destination buffer |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 274 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 275 | * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly |
| 276 | * packed. |
| 277 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 278 | * |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 279 | * @return true if the read succeeded, false if not. The read can fail because of an unsupported |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 280 | * pixel configs |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 281 | */ |
Brian Osman | b62ea22 | 2016-12-22 11:12:16 -0500 | [diff] [blame] | 282 | bool readSurfacePixels(GrSurface* surface, SkColorSpace* srcColorSpace, |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 283 | int left, int top, int width, int height, |
Brian Osman | b62ea22 | 2016-12-22 11:12:16 -0500 | [diff] [blame] | 284 | GrPixelConfig config, SkColorSpace* dstColorSpace, void* buffer, |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 285 | size_t rowBytes = 0, |
| 286 | uint32_t pixelOpsFlags = 0); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 287 | |
| 288 | /** |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 289 | * Writes a rectangle of pixels to a surface. |
| 290 | * @param surface the surface to write to. |
Brian Osman | b62ea22 | 2016-12-22 11:12:16 -0500 | [diff] [blame] | 291 | * @param dstColorSpace color space of the surface |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 292 | * @param left left edge of the rectangle to write (inclusive) |
| 293 | * @param top top edge of the rectangle to write (inclusive) |
| 294 | * @param width width of rectangle to write in pixels. |
| 295 | * @param height height of rectangle to write in pixels. |
| 296 | * @param config the pixel config of the source buffer |
Brian Osman | b62ea22 | 2016-12-22 11:12:16 -0500 | [diff] [blame] | 297 | * @param srcColorSpace color space of the source buffer |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 298 | * @param buffer memory to read pixels from |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 299 | * @param rowBytes number of bytes between consecutive rows. Zero |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 300 | * means rows are tightly packed. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 301 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 302 | * @return true if the write succeeded, false if not. The write can fail because of an |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 303 | * unsupported combination of surface and src configs. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 304 | */ |
Brian Osman | b62ea22 | 2016-12-22 11:12:16 -0500 | [diff] [blame] | 305 | bool writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpace, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 306 | int left, int top, int width, int height, |
Brian Osman | b62ea22 | 2016-12-22 11:12:16 -0500 | [diff] [blame] | 307 | GrPixelConfig config, SkColorSpace* srcColorSpace, const void* buffer, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 308 | size_t rowBytes, |
| 309 | uint32_t pixelOpsFlags = 0); |
| 310 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 311 | /** |
joshualitt | 0acd0d3 | 2015-05-07 08:23:19 -0700 | [diff] [blame] | 312 | * An ID associated with this context, guaranteed to be unique. |
| 313 | */ |
| 314 | uint32_t uniqueID() { return fUniqueID; } |
| 315 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 316 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 317 | // Functions intended for internal use only. |
| 318 | GrGpu* getGpu() { return fGpu; } |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 319 | const GrGpu* getGpu() const { return fGpu; } |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 320 | GrAtlasGlyphCache* getAtlasGlyphCache() { return fAtlasGlyphCache; } |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 321 | GrTextBlobCache* getTextBlobCache() { return fTextBlobCache.get(); } |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 322 | bool abandoned() const; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 323 | GrResourceProvider* resourceProvider() { return fResourceProvider; } |
| 324 | const GrResourceProvider* resourceProvider() const { return fResourceProvider; } |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 325 | GrResourceCache* getResourceCache() { return fResourceCache; } |
bsalomon@google.com | 9923c2b | 2012-06-06 18:21:18 +0000 | [diff] [blame] | 326 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 327 | /** Reset GPU stats */ |
| 328 | void resetGpuStats() const ; |
| 329 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 330 | /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ |
| 331 | void dumpCacheStats(SkString*) const; |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 332 | void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 333 | void printCacheStats() const; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 334 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 335 | /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ |
| 336 | void dumpGpuStats(SkString*) const; |
joshualitt | dc5685a | 2015-12-02 14:08:25 -0800 | [diff] [blame] | 337 | void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 338 | void printGpuStats() const; |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 339 | |
joshualitt | 17d833b | 2015-08-03 10:17:44 -0700 | [diff] [blame] | 340 | /** Specify the TextBlob cache limit. If the current cache exceeds this limit it will purge. |
| 341 | this is for testing only */ |
| 342 | void setTextBlobCacheLimit_ForTesting(size_t bytes); |
| 343 | |
joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 344 | /** Specify the sizes of the GrAtlasTextContext atlases. The configs pointer below should be |
| 345 | to an array of 3 entries */ |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 346 | void setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs); |
joshualitt | da04e0e | 2015-08-19 08:16:43 -0700 | [diff] [blame] | 347 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 348 | /** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */ |
| 349 | void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; |
| 350 | |
Robert Phillips | 33667da | 2016-12-20 11:05:30 -0500 | [diff] [blame] | 351 | /** Get pointer to atlas texture for given mask format. Note that this wraps an |
| 352 | actively mutating texture in an SkImage. This could yield unexpected results |
| 353 | if it gets cached or used more generally. */ |
Robert Phillips | c37e614 | 2017-01-20 10:03:25 -0500 | [diff] [blame] | 354 | sk_sp<SkImage> getFontAtlasImage_ForTesting(GrMaskFormat format); |
jvanverth | 629162d | 2015-11-08 08:07:24 -0800 | [diff] [blame] | 355 | |
joshualitt | 5651ee6 | 2016-01-11 10:39:11 -0800 | [diff] [blame] | 356 | GrAuditTrail* getAuditTrail() { return &fAuditTrail; } |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 357 | |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 358 | /** This is only useful for debug purposes */ |
| 359 | SkDEBUGCODE(GrSingleOwner* debugSingleOwner() const { return &fSingleOwner; } ) |
| 360 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 361 | // Provides access to functions that aren't part of the public API. |
| 362 | GrContextPriv contextPriv(); |
| 363 | const GrContextPriv contextPriv() const; |
| 364 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 365 | private: |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 366 | GrGpu* fGpu; |
| 367 | const GrCaps* fCaps; |
| 368 | GrResourceCache* fResourceCache; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 369 | GrResourceProvider* fResourceProvider; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 370 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 371 | sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 372 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 373 | GrAtlasGlyphCache* fAtlasGlyphCache; |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 374 | std::unique_ptr<GrTextBlobCache> fTextBlobCache; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 375 | |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 376 | bool fDisableGpuYUVConversion; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 377 | bool fDidTestPMConversions; |
| 378 | int fPMToUPMConversion; |
| 379 | int fUPMToPMConversion; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 380 | |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 381 | // In debug builds we guard against improper thread handling |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 382 | // 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] | 383 | // GrRenderTargetContexts. It is also passed to the GrResourceProvider and SkGpuDevice. |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 384 | mutable GrSingleOwner fSingleOwner; |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 385 | |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 386 | struct CleanUpData { |
| 387 | PFCleanUpFunc fFunc; |
| 388 | void* fInfo; |
| 389 | }; |
| 390 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 391 | SkTDArray<CleanUpData> fCleanUpData; |
robertphillips@google.com | 44a91dc | 2013-07-25 15:32:06 +0000 | [diff] [blame] | 392 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 393 | const uint32_t fUniqueID; |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 394 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 395 | std::unique_ptr<GrDrawingManager> fDrawingManager; |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 396 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 397 | GrAuditTrail fAuditTrail; |
joshualitt | 27a48dc | 2016-01-08 07:19:47 -0800 | [diff] [blame] | 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 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 402 | GrContext(); // init must be called after the constructor. |
| 403 | bool init(GrBackend, GrBackendContext, const GrContextOptions& options); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 404 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 405 | void initMockContext(); |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 406 | void initCommon(const GrContextOptions&); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 407 | |
skia.committer@gmail.com | cdcb2ce | 2013-01-29 07:05:52 +0000 | [diff] [blame] | 408 | /** |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 409 | * These functions create premul <-> unpremul effects if it is possible to generate a pair |
| 410 | * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. Otherwise, they |
bsalomon | 6c9cd55 | 2016-01-22 07:17:34 -0800 | [diff] [blame] | 411 | * return NULL. They also can perform a swizzle as part of the draw. |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 412 | */ |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 413 | sk_sp<GrFragmentProcessor> createPMToUPMEffect(sk_sp<GrTextureProxy>, const SkMatrix&); |
| 414 | sk_sp<GrFragmentProcessor> createUPMToPMEffect(sk_sp<GrTextureProxy>, const SkMatrix&); |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 415 | /** Called before either of the above two functions to determine the appropriate fragment |
Robert Phillips | 65115a1 | 2016-12-13 12:42:19 -0500 | [diff] [blame] | 416 | processors for conversions. */ |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 417 | void testPMConversionsIfNecessary(uint32_t flags); |
Brian Osman | de1a605 | 2017-03-22 10:57:00 -0400 | [diff] [blame] | 418 | /** Returns true if we've determined that createPMtoUPMEffect and createUPMToPMEffect will |
| 419 | succeed for the passed in config. Otherwise we fall back to SW conversion. */ |
| 420 | bool validPMUPMConversionExists(GrPixelConfig) const; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 421 | |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 422 | /** |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 423 | * A callback similar to the above for use by the TextBlobCache |
| 424 | * TODO move textblob draw calls below context so we can use the call above. |
| 425 | */ |
| 426 | static void TextBlobCacheOverBudgetCB(void* data); |
| 427 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 428 | typedef SkRefCnt INHERITED; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 429 | }; |
| 430 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 431 | /** |
| 432 | * Can be used to perform actions related to the generating GrContext in a thread safe manner. The |
| 433 | * proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrContext. |
| 434 | */ |
| 435 | class GrContextThreadSafeProxy : public SkRefCnt { |
| 436 | private: |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 437 | GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, uint32_t uniqueID) |
| 438 | : fCaps(std::move(caps)) |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 439 | , fContextUniqueID(uniqueID) {} |
| 440 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 441 | sk_sp<const GrCaps> fCaps; |
| 442 | uint32_t fContextUniqueID; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 443 | |
| 444 | friend class GrContext; |
| 445 | friend class SkImage; |
| 446 | |
| 447 | typedef SkRefCnt INHERITED; |
| 448 | }; |
| 449 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 450 | #endif |