blob: 71f903c3991f08792f1f33486b5ba2c164d1d8ba [file] [log] [blame]
bsalomon@google.com27847de2011-02-22 20:59:41 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.com27847de2011-02-22 20:59:41 +00006 */
7
8#ifndef GrContext_DEFINED
9#define GrContext_DEFINED
10
robertphillipscaef3452015-11-11 13:18:11 -080011#include "GrCaps.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000012#include "GrColor.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000013#include "SkMatrix.h"
egdaniele61c4112014-06-12 10:24:21 -070014#include "SkPathEffect.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000015#include "SkTypes.h"
joshualitt27a48dc2016-01-08 07:19:47 -080016#include "../private/GrAuditTrail.h"
joshualitt1de610a2016-01-06 08:26:09 -080017#include "../private/GrSingleOwner.h"
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -040018#include "GrContextOptions.h"
bsalomon@google.com27847de2011-02-22 20:59:41 +000019
Brian Salomonf856fd12016-12-16 14:24:34 -050020class GrAtlasGlyphCache;
Greg Daniel51316782017-08-02 15:10:09 +000021class GrBackendSemaphore;
robertphillips4fd74ae2016-08-03 14:26:53 -070022class GrContextPriv;
bsalomon41b952c2016-03-11 06:46:33 -080023class GrContextThreadSafeProxy;
robertphillips77a2e522015-10-17 07:43:27 -070024class GrDrawingManager;
Brian Salomon2ee084e2016-12-16 18:59:19 -050025struct GrDrawOpAtlasConfig;
joshualittb0a8a372014-09-23 09:50:21 -070026class GrFragmentProcessor;
Greg Daniel02611d92017-07-25 10:05:01 -040027struct GrGLInterface;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000028class GrGpu;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000029class GrIndexBuffer;
Greg Daniel02611d92017-07-25 10:05:01 -040030struct GrMockOptions;
commit-bot@chromium.org81312832013-03-22 18:34:09 +000031class GrOvalRenderer;
commit-bot@chromium.org5c8ee252013-11-01 15:23:44 +000032class GrPath;
Robert Phillips1afd4cd2018-01-08 13:40:32 -050033class GrProxyProvider;
Greg Daniel02611d92017-07-25 10:05:01 -040034class GrRenderTargetContext;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000035class GrResourceEntry;
bsalomon0ea80f42015-02-11 10:49:59 -080036class GrResourceCache;
bsalomond309e7a2015-04-30 14:18:54 -070037class GrResourceProvider;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040038class GrSamplerState;
Robert Phillips7ee385e2017-03-30 08:02:11 -040039class GrSurfaceProxy;
joshualittb7133be2015-04-08 09:08:31 -070040class GrTextBlobCache;
kkinnunenc6cb56f2014-06-24 00:12:27 -070041class GrTextContext;
Mike Reed84dd8572017-03-08 22:21:00 -050042class GrTextureProxy;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000043class GrVertexBuffer;
Greg Daniel02611d92017-07-25 10:05:01 -040044struct GrVkBackendContext;
bsalomon6c9cd552016-01-22 07:17:34 -080045class GrSwizzle;
ericrk0a5fa482015-09-15 14:16:10 -070046class SkTraceMemoryDump;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000047
Mike Reed84dd8572017-03-08 22:21:00 -050048class SkImage;
49class SkSurfaceProps;
Brian Osman51279982017-08-23 10:12:00 -040050class SkTaskGroup;
Mike Reed84dd8572017-03-08 22:21:00 -050051
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000052class SK_API GrContext : public SkRefCnt {
bsalomon@google.com27847de2011-02-22 20:59:41 +000053public:
54 /**
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000055 * Creates a GrContext for a backend context.
bsalomon@google.com27847de2011-02-22 20:59:41 +000056 */
bsalomon682c2692015-05-22 14:01:46 -070057 static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options);
58 static GrContext* Create(GrBackend, GrBackendContext);
bsalomon@google.com27847de2011-02-22 20:59:41 +000059
Brian Salomon384fab42017-12-07 12:33:05 -050060 static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&);
61 static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>);
Brian Salomon990014d2017-12-07 16:23:39 -050062 // Deprecated
63 static sk_sp<GrContext> MakeGL(const GrGLInterface*);
64 static sk_sp<GrContext> MakeGL(const GrGLInterface*, const GrContextOptions&);
Greg Daniel02611d92017-07-25 10:05:01 -040065
66#ifdef SK_VULKAN
Brian Salomon384fab42017-12-07 12:33:05 -050067 static sk_sp<GrContext> MakeVulkan(sk_sp<const GrVkBackendContext>, const GrContextOptions&);
68 static sk_sp<GrContext> MakeVulkan(sk_sp<const GrVkBackendContext>);
Greg Daniel02611d92017-07-25 10:05:01 -040069#endif
70
Greg Danielb76a72a2017-07-13 15:07:54 -040071#ifdef SK_METAL
72 /**
73 * Makes a GrContext which uses Metal as the backend. The device parameter is an MTLDevice
74 * and queue is an MTLCommandQueue which should be used by the backend. These objects must
75 * have a ref on them which can be transferred to Ganesh which will release the ref when the
76 * GrContext is destroyed.
77 */
78 static sk_sp<GrContext> MakeMetal(void* device, void* queue, const GrContextOptions& options);
Greg Daniel02611d92017-07-25 10:05:01 -040079 static sk_sp<GrContext> MakeMetal(void* device, void* queue);
Greg Danielb76a72a2017-07-13 15:07:54 -040080#endif
81
Greg Daniel02611d92017-07-25 10:05:01 -040082 static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
83 static sk_sp<GrContext> MakeMock(const GrMockOptions*);
84
bsalomon@google.com27847de2011-02-22 20:59:41 +000085 virtual ~GrContext();
86
bungeman6bd52842016-10-27 09:30:08 -070087 sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
bsalomon41b952c2016-03-11 06:46:33 -080088
bsalomon@google.com27847de2011-02-22 20:59:41 +000089 /**
90 * The GrContext normally assumes that no outsider is setting state
91 * within the underlying 3D API's context/device/whatever. This call informs
92 * the context that the state was modified and it should resend. Shouldn't
93 * be called frequently for good performance.
bsalomon@google.com0a208a12013-06-28 18:57:35 +000094 * The flag bits, state, is dpendent on which backend is used by the
95 * context, either GL or D3D (possible in future).
bsalomon@google.com27847de2011-02-22 20:59:41 +000096 */
bsalomon@google.com0a208a12013-06-28 18:57:35 +000097 void resetContext(uint32_t state = kAll_GrBackendState);
bsalomon@google.com27847de2011-02-22 20:59:41 +000098
bsalomon@google.com8fe72472011-03-30 21:26:44 +000099 /**
robertphillips@google.comcdb426d2012-09-24 19:33:59 +0000100 * Callback function to allow classes to cleanup on GrContext destruction.
101 * The 'info' field is filled in with the 'info' passed to addCleanUp.
102 */
103 typedef void (*PFCleanUpFunc)(const GrContext* context, void* info);
104
105 /**
106 * Add a function to be called from within GrContext's destructor.
107 * This gives classes a chance to free resources held on a per context basis.
108 * The 'info' parameter will be stored and passed to the callback function.
109 */
110 void addCleanUp(PFCleanUpFunc cleanUp, void* info) {
111 CleanUpData* entry = fCleanUpData.push();
112
113 entry->fFunc = cleanUp;
114 entry->fInfo = info;
115 }
116
117 /**
Robert Phillips88260b52018-01-19 12:56:09 -0500118 * Abandons all GPU resources and assumes the underlying backend 3D API context is no longer
bsalomon6e2aad42016-04-01 11:54:31 -0700119 * usable. Call this if you have lost the associated GPU context, and thus internal texture,
120 * buffer, etc. references/IDs are now invalid. Calling this ensures that the destructors of the
121 * GrContext and any of its created resource objects will not make backend 3D API calls. Content
122 * rendered but not previously flushed may be lost. After this function is called all subsequent
123 * calls on the GrContext will fail or be no-ops.
124 *
125 * The typical use case for this function is that the underlying 3D context was lost and further
126 * API calls may crash.
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000127 */
bsalomon2354f842014-07-28 13:48:36 -0700128 void abandonContext();
junov@google.com53a55842011-06-08 22:55:10 +0000129
bsalomon6e2aad42016-04-01 11:54:31 -0700130 /**
131 * This is similar to abandonContext() however the underlying 3D context is not yet lost and
132 * the GrContext will cleanup all allocated resources before returning. After returning it will
133 * assume that the underlying context may no longer be valid.
134 *
135 * The typical use case for this function is that the client is going to destroy the 3D context
136 * but can't guarantee that GrContext will be destroyed first (perhaps because it may be ref'ed
137 * elsewhere by either the client or Skia objects).
138 */
139 void releaseResourcesAndAbandonContext();
140
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000141 ///////////////////////////////////////////////////////////////////////////
142 // Resource Cache
143
144 /**
145 * Return the current GPU resource cache limits.
146 *
147 * @param maxResources If non-null, returns maximum number of resources that
148 * can be held in the cache.
149 * @param maxResourceBytes If non-null, returns maximum number of bytes of
150 * video memory that can be held in the cache.
151 */
152 void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000153
154 /**
155 * Gets the current GPU resource cache usage.
156 *
157 * @param resourceCount If non-null, returns the number of resources that are held in the
158 * cache.
159 * @param maxResourceBytes If non-null, returns the total number of bytes of video memory held
160 * in the cache.
161 */
162 void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const;
163
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000164 /**
Derek Sollenbergeree479142017-05-24 11:41:33 -0400165 * Gets the number of bytes in the cache consumed by purgeable (e.g. unlocked) resources.
166 */
167 size_t getResourceCachePurgeableBytes() const;
168
169 /**
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000170 * Specify the GPU resource cache limits. If the current cache exceeds either
171 * of these, it will be purged (LRU) to keep the cache within these limits.
172 *
173 * @param maxResources The maximum number of resources that can be held in
174 * the cache.
175 * @param maxResourceBytes The maximum number of bytes of video memory
176 * that can be held in the cache.
177 */
178 void setResourceCacheLimits(int maxResources, size_t maxResourceBytes);
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000179
junov@google.com53a55842011-06-08 22:55:10 +0000180 /**
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000181 * Frees GPU created by the context. Can be called to reduce GPU memory
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000182 * pressure.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000183 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000184 void freeGpuResources();
185
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000186 /**
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000187 * Purge all the unlocked resources from the cache.
188 * This entry point is mainly meant for timing texture uploads
189 * and is not defined in normal builds of Skia.
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000190 */
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000191 void purgeAllUnlockedResources();
192
Brian Salomon5e150852017-03-22 14:53:13 -0400193 /**
Jim Van Verth76d917c2017-12-13 09:26:37 -0500194 * Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are
195 * otherwise marked for deletion, regardless of whether the context is under budget.
Brian Salomon5e150852017-03-22 14:53:13 -0400196 */
Jim Van Verth76d917c2017-12-13 09:26:37 -0500197 void performDeferredCleanup(std::chrono::milliseconds msNotUsed);
Brian Salomon5e150852017-03-22 14:53:13 -0400198
Mike Klein4b6bde72017-12-14 07:46:55 -0500199 // Temporary compatibility API for Android.
200 void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed) {
201 this->performDeferredCleanup(msNotUsed);
202 }
203
Derek Sollenberger5480a182017-05-25 16:43:59 -0400204 /**
205 * Purge unlocked resources from the cache until the the provided byte count has been reached
206 * or we have purged all unlocked resources. The default policy is to purge in LRU order, but
207 * can be overridden to prefer purging scratch resources (in LRU order) prior to purging other
208 * resource types.
209 *
210 * @param maxBytesToPurge the desired number of bytes to be purged.
211 * @param preferScratchResources If true scratch resources will be purged prior to other
212 * resource types.
213 */
214 void purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources);
215
bsalomon76228632015-05-29 08:02:10 -0700216 /** Access the context capabilities */
Brian Salomoneace8cd2017-12-08 13:11:11 -0500217 const GrCaps* caps() const { return fCaps.get(); }
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000218
commit-bot@chromium.orgb471a322014-03-10 07:40:03 +0000219 /**
220 * Returns the recommended sample count for a render target when using this
221 * context.
222 *
223 * @param config the configuration of the render target.
224 * @param dpi the display density in dots per inch.
225 *
226 * @return sample count that should be perform well and have good enough
227 * rendering quality for the display. Alternatively returns 0 if
228 * MSAA is not supported or recommended to be used by default.
229 */
230 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
231
Robert Phillipsdd3b3f42017-04-24 10:57:28 -0400232 /*
233 * Create a new render target context backed by a deferred-style
234 * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for
235 * renderTargetContexts created via this entry point.
robertphillipsd4c741e2016-04-28 09:55:15 -0700236 */
Robert Phillips2af746c2017-04-21 12:28:48 +0000237 sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext(
Robert Phillipsdd3b3f42017-04-24 10:57:28 -0400238 SkBackingFit fit,
Robert Phillips2af746c2017-04-21 12:28:48 +0000239 int width, int height,
240 GrPixelConfig config,
241 sk_sp<SkColorSpace> colorSpace,
242 int sampleCnt = 0,
Greg Daniel45d63032017-10-30 13:41:26 -0400243 GrMipMapped = GrMipMapped::kNo,
Robert Phillips2af746c2017-04-21 12:28:48 +0000244 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
245 const SkSurfaceProps* surfaceProps = nullptr,
246 SkBudgeted = SkBudgeted::kYes);
robertphillips48fde9c2016-09-06 05:20:20 -0700247 /*
Brian Osman11052242016-10-27 14:47:55 -0400248 * This method will attempt to create a renderTargetContext that has, at least, the number of
robertphillips48fde9c2016-09-06 05:20:20 -0700249 * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be
250 * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA).
251 * SRGB-ness will be preserved.
252 */
robertphillipsd728f0c2016-11-21 11:05:03 -0800253 sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
254 SkBackingFit fit,
255 int width, int height,
256 GrPixelConfig config,
257 sk_sp<SkColorSpace> colorSpace,
258 int sampleCnt = 0,
Greg Daniel45d63032017-10-30 13:41:26 -0400259 GrMipMapped = GrMipMapped::kNo,
Robert Phillips40fd7c92017-01-30 08:06:27 -0500260 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
robertphillipsd728f0c2016-11-21 11:05:03 -0800261 const SkSurfaceProps* surfaceProps = nullptr,
262 SkBudgeted budgeted = SkBudgeted::kYes);
263
bsalomon@google.com27847de2011-02-22 20:59:41 +0000264 ///////////////////////////////////////////////////////////////////////////
265 // Misc.
266
267 /**
Greg Daniel51316782017-08-02 15:10:09 +0000268 * Call to ensure all drawing to the context has been issued to the underlying 3D API.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000269 */
bsalomonb77a9072016-09-07 10:02:04 -0700270 void flush();
robertphillipsea461502015-05-26 11:38:03 -0700271
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000272 /**
Greg Daniel51316782017-08-02 15:10:09 +0000273 * Call to ensure all drawing to the context has been issued to the underlying 3D API. After
274 * issuing all commands, numSemaphore semaphores will be signaled by the gpu. The client passes
275 * in an array of numSemaphores GrBackendSemaphores. In general these GrBackendSemaphore's can
276 * be either initialized or not. If they are initialized, the backend uses the passed in
277 * semaphore. If it is not initialized, a new semaphore is created and the GrBackendSemaphore
278 * object is initialized with that semaphore.
279 *
280 * The client will own and be responsible for deleting the underlying semaphores that are stored
281 * and returned in initialized GrBackendSemaphore objects. The GrBackendSemaphore objects
282 * themselves can be deleted as soon as this function returns.
283 *
284 * If the backend API is OpenGL only uninitialized GrBackendSemaphores are supported.
285 * If the backend API is Vulkan either initialized or unitialized semaphores are supported.
286 * If unitialized, the semaphores which are created will be valid for use only with the VkDevice
287 * with which they were created.
288 *
289 * If this call returns GrSemaphoresSubmited::kNo, the GPU backend will not have created or
290 * added any semaphores to signal on the GPU. Thus the client should not have the GPU wait on
291 * any of the semaphores. However, any pending commands to the context will still be flushed.
292 */
293 GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores,
294 GrBackendSemaphore signalSemaphores[]);
295
296 /**
joshualitt0acd0d32015-05-07 08:23:19 -0700297 * An ID associated with this context, guaranteed to be unique.
298 */
299 uint32_t uniqueID() { return fUniqueID; }
300
bsalomon@google.com27847de2011-02-22 20:59:41 +0000301 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com27847de2011-02-22 20:59:41 +0000302 // Functions intended for internal use only.
Hal Canary07320e42018-01-19 18:18:20 +0000303 GrGpu* getGpu() { return fGpu.get(); }
304 const GrGpu* getGpu() const { return fGpu.get(); }
305 GrAtlasGlyphCache* getAtlasGlyphCache() { return fAtlasGlyphCache; }
306 GrTextBlobCache* getTextBlobCache() { return fTextBlobCache.get(); }
robertphillips77a2e522015-10-17 07:43:27 -0700307 bool abandoned() const;
bsalomon@google.com9923c2b2012-06-06 18:21:18 +0000308
joshualitte45c81c2015-12-02 09:05:37 -0800309 /** Reset GPU stats */
310 void resetGpuStats() const ;
311
mtkleinb9eb4ac2015-02-02 18:26:03 -0800312 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */
313 void dumpCacheStats(SkString*) const;
joshualittdc5685a2015-12-02 14:08:25 -0800314 void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000315 void printCacheStats() const;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000316
mtkleinb9eb4ac2015-02-02 18:26:03 -0800317 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */
318 void dumpGpuStats(SkString*) const;
joshualittdc5685a2015-12-02 14:08:25 -0800319 void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800320 void printGpuStats() const;
robertphillips754f4e92014-09-18 13:52:08 -0700321
Brian Osman71a18892017-08-10 10:23:25 -0400322 /** Returns a string with detailed information about the context & GPU, in JSON format. */
323 SkString dump() const;
324
joshualitt17d833b2015-08-03 10:17:44 -0700325 /** Specify the TextBlob cache limit. If the current cache exceeds this limit it will purge.
326 this is for testing only */
327 void setTextBlobCacheLimit_ForTesting(size_t bytes);
328
joshualittda04e0e2015-08-19 08:16:43 -0700329 /** Specify the sizes of the GrAtlasTextContext atlases. The configs pointer below should be
330 to an array of 3 entries */
Brian Salomon2ee084e2016-12-16 18:59:19 -0500331 void setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs);
joshualittda04e0e2015-08-19 08:16:43 -0700332
ericrk0a5fa482015-09-15 14:16:10 -0700333 /** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */
334 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
335
Robert Phillips33667da2016-12-20 11:05:30 -0500336 /** Get pointer to atlas texture for given mask format. Note that this wraps an
337 actively mutating texture in an SkImage. This could yield unexpected results
338 if it gets cached or used more generally. */
Robert Phillipsc37e6142017-01-20 10:03:25 -0500339 sk_sp<SkImage> getFontAtlasImage_ForTesting(GrMaskFormat format);
jvanverth629162d2015-11-08 08:07:24 -0800340
joshualitt5651ee62016-01-11 10:39:11 -0800341 GrAuditTrail* getAuditTrail() { return &fAuditTrail; }
joshualitt27a48dc2016-01-08 07:19:47 -0800342
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400343 GrContextOptions::PersistentCache* getPersistentCache() { return fPersistentCache; }
344
joshualittce894002016-01-11 13:29:31 -0800345 /** This is only useful for debug purposes */
346 SkDEBUGCODE(GrSingleOwner* debugSingleOwner() const { return &fSingleOwner; } )
347
robertphillips4fd74ae2016-08-03 14:26:53 -0700348 // Provides access to functions that aren't part of the public API.
349 GrContextPriv contextPriv();
350 const GrContextPriv contextPriv() const;
351
Robert Phillips88260b52018-01-19 12:56:09 -0500352protected:
353 GrContext(GrContextThreadSafeProxy*);
354 GrContext(GrBackend);
355
bsalomon@google.com27847de2011-02-22 20:59:41 +0000356private:
Brian Salomon384fab42017-12-07 12:33:05 -0500357 sk_sp<GrGpu> fGpu;
Brian Salomoneace8cd2017-12-08 13:11:11 -0500358 sk_sp<const GrCaps> fCaps;
bsalomon41b952c2016-03-11 06:46:33 -0800359 GrResourceCache* fResourceCache;
Brian Osman32342f02017-03-04 08:12:46 -0500360 GrResourceProvider* fResourceProvider;
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500361 GrProxyProvider* fProxyProvider;
bsalomond309e7a2015-04-30 14:18:54 -0700362
bungeman6bd52842016-10-27 09:30:08 -0700363 sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy;
bsalomon41b952c2016-03-11 06:46:33 -0800364
Brian Salomonf856fd12016-12-16 14:24:34 -0500365 GrAtlasGlyphCache* fAtlasGlyphCache;
bungeman6bd52842016-10-27 09:30:08 -0700366 std::unique_ptr<GrTextBlobCache> fTextBlobCache;
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000367
Brian Osman46da1cc2017-02-14 14:15:48 -0500368 bool fDisableGpuYUVConversion;
bsalomon41b952c2016-03-11 06:46:33 -0800369 bool fDidTestPMConversions;
Brian Osman28804f32017-04-20 10:24:36 -0400370 // true if the PM/UPM conversion succeeded; false otherwise
371 bool fPMUPMConversionsRoundTrip;
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000372
joshualitt1de610a2016-01-06 08:26:09 -0800373 // In debug builds we guard against improper thread handling
joshualittde8dc7e2016-01-08 10:09:13 -0800374 // This guard is passed to the GrDrawingManager and, from there to all the
Brian Osman32342f02017-03-04 08:12:46 -0500375 // GrRenderTargetContexts. It is also passed to the GrResourceProvider and SkGpuDevice.
bsalomon41b952c2016-03-11 06:46:33 -0800376 mutable GrSingleOwner fSingleOwner;
joshualitt1de610a2016-01-06 08:26:09 -0800377
Brian Osman51279982017-08-23 10:12:00 -0400378 std::unique_ptr<SkTaskGroup> fTaskGroup;
379
robertphillips@google.comcdb426d2012-09-24 19:33:59 +0000380 struct CleanUpData {
381 PFCleanUpFunc fFunc;
382 void* fInfo;
383 };
384
bsalomon41b952c2016-03-11 06:46:33 -0800385 SkTDArray<CleanUpData> fCleanUpData;
robertphillips@google.com44a91dc2013-07-25 15:32:06 +0000386
bsalomon41b952c2016-03-11 06:46:33 -0800387 const uint32_t fUniqueID;
krajcevski9c6d4d72014-08-12 07:26:25 -0700388
bungeman6bd52842016-10-27 09:30:08 -0700389 std::unique_ptr<GrDrawingManager> fDrawingManager;
robertphillips77a2e522015-10-17 07:43:27 -0700390
bsalomon41b952c2016-03-11 06:46:33 -0800391 GrAuditTrail fAuditTrail;
joshualitt27a48dc2016-01-08 07:19:47 -0800392
Robert Phillipse42edcc2017-12-13 11:50:22 -0500393 const GrBackend fBackend;
Greg Danielfc978fd2017-04-13 09:54:12 -0400394
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400395 GrContextOptions::PersistentCache* fPersistentCache;
396
Brian Osman11052242016-10-27 14:47:55 -0400397 // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending
robertphillips4fd74ae2016-08-03 14:26:53 -0700398 friend class GrContextPriv;
csmartdaltonc6f411e2016-08-05 22:32:12 -0700399
Robert Phillips88260b52018-01-19 12:56:09 -0500400 bool init(const GrContextOptions&); // init must be called after either constructor.
robertphillipsea461502015-05-26 11:38:03 -0700401
skia.committer@gmail.comcdcb2ce2013-01-29 07:05:52 +0000402 /**
Brian Osman409e74f2017-04-17 11:48:28 -0400403 * These functions create premul <-> unpremul effects. If the second argument is 'true', they
404 * use the specialized round-trip effects from GrConfigConversionEffect, otherwise they
405 * create effects that do naive multiply or divide.
bsalomon@google.comadc65362013-01-28 14:26:09 +0000406 */
Brian Salomonaff329b2017-08-11 09:40:37 -0400407 std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>,
408 bool useConfigConversionEffect);
409 std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>,
410 bool useConfigConversionEffect);
Brian Osman409e74f2017-04-17 11:48:28 -0400411
412 /**
413 * Returns true if createPMtoUPMEffect and createUPMToPMEffect will succeed for non-sRGB 8888
414 * configs. In other words, did we find a pair of round-trip preserving conversion effects?
415 */
416 bool validPMUPMConversionExists();
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000417
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000418 /**
joshualitt0db6dfa2015-04-10 07:01:30 -0700419 * A callback similar to the above for use by the TextBlobCache
420 * TODO move textblob draw calls below context so we can use the call above.
421 */
422 static void TextBlobCacheOverBudgetCB(void* data);
423
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000424 typedef SkRefCnt INHERITED;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000425};
426
bsalomon41b952c2016-03-11 06:46:33 -0800427/**
428 * Can be used to perform actions related to the generating GrContext in a thread safe manner. The
429 * proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrContext.
430 */
431class GrContextThreadSafeProxy : public SkRefCnt {
Robert Phillips8def8bf2017-11-30 08:46:03 -0500432public:
433 bool matches(GrContext* context) const { return context->uniqueID() == fContextUniqueID; }
434
bsalomon41b952c2016-03-11 06:46:33 -0800435private:
Robert Phillipse42edcc2017-12-13 11:50:22 -0500436 // DDL TODO: need to add unit tests for backend & maybe options
437 GrContextThreadSafeProxy(sk_sp<const GrCaps> caps,
438 uint32_t uniqueID,
439 GrBackend backend,
440 const GrContextOptions& options)
bungeman6bd52842016-10-27 09:30:08 -0700441 : fCaps(std::move(caps))
Robert Phillipse42edcc2017-12-13 11:50:22 -0500442 , fContextUniqueID(uniqueID)
443 , fBackend(backend)
444 , fOptions(options) {
445 }
bsalomon41b952c2016-03-11 06:46:33 -0800446
Robert Phillipse42edcc2017-12-13 11:50:22 -0500447 sk_sp<const GrCaps> fCaps;
448 const uint32_t fContextUniqueID;
449 const GrBackend fBackend;
450 const GrContextOptions fOptions;
bsalomon41b952c2016-03-11 06:46:33 -0800451
452 friend class GrContext;
Robert Phillipse42edcc2017-12-13 11:50:22 -0500453 friend class GrContextPriv;
bsalomon41b952c2016-03-11 06:46:33 -0800454 friend class SkImage;
455
456 typedef SkRefCnt INHERITED;
457};
458
bsalomon@google.com27847de2011-02-22 20:59:41 +0000459#endif