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