blob: 069b07182f43658293a66cabd68f60f0c7df0459 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkMatrix.h"
12#include "include/core/SkPathEffect.h"
13#include "include/core/SkTypes.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040014#include "include/gpu/GrBackendSurface.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "include/gpu/GrContextOptions.h"
16#include "include/private/GrRecordingContext.h"
bsalomon@google.com27847de2011-02-22 20:59:41 +000017
Brian Salomon79bf7ac2018-05-11 13:08:30 -040018// We shouldn't need this but currently Android is relying on this being include transitively.
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "include/core/SkUnPreMultiply.h"
Brian Salomon79bf7ac2018-05-11 13:08:30 -040020
Robert Phillipsc4039ea2018-03-01 11:36:45 -050021class GrAtlasManager;
Greg Daniel51316782017-08-02 15:10:09 +000022class GrBackendSemaphore;
Brian Salomonc7fe0f72018-05-11 10:14:21 -040023class GrCaps;
robertphillips4fd74ae2016-08-03 14:26:53 -070024class GrContextPriv;
bsalomon41b952c2016-03-11 06:46:33 -080025class GrContextThreadSafeProxy;
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;
Greg Daniel02611d92017-07-25 10:05:01 -040029struct GrMockOptions;
commit-bot@chromium.org5c8ee252013-11-01 15:23:44 +000030class GrPath;
Greg Daniel02611d92017-07-25 10:05:01 -040031class GrRenderTargetContext;
bsalomon0ea80f42015-02-11 10:49:59 -080032class GrResourceCache;
bsalomond309e7a2015-04-30 14:18:54 -070033class GrResourceProvider;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040034class GrSamplerState;
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050035class GrSkSLFPFactoryCache;
Robert Phillips7ee385e2017-03-30 08:02:11 -040036class GrSurfaceProxy;
Robert Phillipsfc711a22018-02-13 17:03:00 -050037class GrSwizzle;
kkinnunenc6cb56f2014-06-24 00:12:27 -070038class GrTextContext;
Mike Reed84dd8572017-03-08 22:21:00 -050039class GrTextureProxy;
Greg Daniel02611d92017-07-25 10:05:01 -040040struct GrVkBackendContext;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000041
Mike Reed84dd8572017-03-08 22:21:00 -050042class SkImage;
Robert Phillips02dc0302019-07-02 17:58:27 -040043class SkSurfaceCharacterization;
Mike Reed84dd8572017-03-08 22:21:00 -050044class SkSurfaceProps;
Brian Osman51279982017-08-23 10:12:00 -040045class SkTaskGroup;
Robert Phillipsfc711a22018-02-13 17:03:00 -050046class SkTraceMemoryDump;
Mike Reed84dd8572017-03-08 22:21:00 -050047
Robert Phillips4217ea72019-01-30 13:08:28 -050048class SK_API GrContext : public GrRecordingContext {
bsalomon@google.com27847de2011-02-22 20:59:41 +000049public:
50 /**
Brian Salomonc1b9c102018-04-06 09:18:00 -040051 * Creates a GrContext for a backend context. If no GrGLInterface is provided then the result of
52 * GrGLMakeNativeInterface() is used if it succeeds.
bsalomon@google.com27847de2011-02-22 20:59:41 +000053 */
Brian Salomon384fab42017-12-07 12:33:05 -050054 static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&);
55 static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>);
Brian Salomonc1b9c102018-04-06 09:18:00 -040056 static sk_sp<GrContext> MakeGL(const GrContextOptions&);
57 static sk_sp<GrContext> MakeGL();
58
Greg Daniel10a83da2018-06-14 09:31:11 -040059 static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&);
60 static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&);
Greg Daniel02611d92017-07-25 10:05:01 -040061
Greg Danielb76a72a2017-07-13 15:07:54 -040062#ifdef SK_METAL
63 /**
64 * Makes a GrContext which uses Metal as the backend. The device parameter is an MTLDevice
Jim Van Verth7730d7c2019-05-28 03:03:45 +000065 * and queue is an MTLCommandQueue which should be used by the backend. These objects must
66 * have a ref on them which can be transferred to Ganesh which will release the ref when the
67 * GrContext is destroyed.
Greg Danielb76a72a2017-07-13 15:07:54 -040068 */
69 static sk_sp<GrContext> MakeMetal(void* device, void* queue, const GrContextOptions& options);
Greg Daniel02611d92017-07-25 10:05:01 -040070 static sk_sp<GrContext> MakeMetal(void* device, void* queue);
Greg Danielb76a72a2017-07-13 15:07:54 -040071#endif
72
Greg Daniel02611d92017-07-25 10:05:01 -040073 static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
74 static sk_sp<GrContext> MakeMock(const GrMockOptions*);
75
Robert Phillipsbb606772019-02-04 17:50:57 -050076 ~GrContext() override;
bsalomon@google.com27847de2011-02-22 20:59:41 +000077
bungeman6bd52842016-10-27 09:30:08 -070078 sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
bsalomon41b952c2016-03-11 06:46:33 -080079
bsalomon@google.com27847de2011-02-22 20:59:41 +000080 /**
81 * The GrContext normally assumes that no outsider is setting state
82 * within the underlying 3D API's context/device/whatever. This call informs
83 * the context that the state was modified and it should resend. Shouldn't
84 * be called frequently for good performance.
bsalomon@google.com0a208a12013-06-28 18:57:35 +000085 * The flag bits, state, is dpendent on which backend is used by the
86 * context, either GL or D3D (possible in future).
bsalomon@google.com27847de2011-02-22 20:59:41 +000087 */
bsalomon@google.com0a208a12013-06-28 18:57:35 +000088 void resetContext(uint32_t state = kAll_GrBackendState);
bsalomon@google.com27847de2011-02-22 20:59:41 +000089
bsalomon@google.com8fe72472011-03-30 21:26:44 +000090 /**
Brian Salomon1f05d452019-02-08 12:33:08 -050091 * If the backend is GrBackendApi::kOpenGL, then all texture unit/target combinations for which
92 * the GrContext has modified the bound texture will have texture id 0 bound. This does not
93 * flush the GrContext. Calling resetContext() does not change the set that will be bound
94 * to texture id 0 on the next call to resetGLTextureBindings(). After this is called
95 * all unit/target combinations are considered to have unmodified bindings until the GrContext
96 * subsequently modifies them (meaning if this is called twice in a row with no intervening
97 * GrContext usage then the second call is a no-op.)
98 */
99 void resetGLTextureBindings();
100
101 /**
Robert Phillips88260b52018-01-19 12:56:09 -0500102 * Abandons all GPU resources and assumes the underlying backend 3D API context is no longer
bsalomon6e2aad42016-04-01 11:54:31 -0700103 * usable. Call this if you have lost the associated GPU context, and thus internal texture,
104 * buffer, etc. references/IDs are now invalid. Calling this ensures that the destructors of the
105 * GrContext and any of its created resource objects will not make backend 3D API calls. Content
106 * rendered but not previously flushed may be lost. After this function is called all subsequent
107 * calls on the GrContext will fail or be no-ops.
108 *
109 * The typical use case for this function is that the underlying 3D context was lost and further
110 * API calls may crash.
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000111 */
Robert Phillipsa9162df2019-02-11 14:12:03 -0500112 void abandonContext() override;
junov@google.com53a55842011-06-08 22:55:10 +0000113
bsalomon6e2aad42016-04-01 11:54:31 -0700114 /**
Khushalc421ca12018-06-26 14:38:34 -0700115 * Returns true if the context was abandoned.
116 */
Robert Phillipsa9162df2019-02-11 14:12:03 -0500117 using GrImageContext::abandoned;
Khushalc421ca12018-06-26 14:38:34 -0700118
119 /**
bsalomon6e2aad42016-04-01 11:54:31 -0700120 * This is similar to abandonContext() however the underlying 3D context is not yet lost and
121 * the GrContext will cleanup all allocated resources before returning. After returning it will
122 * assume that the underlying context may no longer be valid.
123 *
124 * The typical use case for this function is that the client is going to destroy the 3D context
125 * but can't guarantee that GrContext will be destroyed first (perhaps because it may be ref'ed
126 * elsewhere by either the client or Skia objects).
127 */
Robert Phillips1056eb82018-03-01 14:16:41 -0500128 virtual void releaseResourcesAndAbandonContext();
bsalomon6e2aad42016-04-01 11:54:31 -0700129
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000130 ///////////////////////////////////////////////////////////////////////////
131 // Resource Cache
132
133 /**
134 * Return the current GPU resource cache limits.
135 *
136 * @param maxResources If non-null, returns maximum number of resources that
137 * can be held in the cache.
138 * @param maxResourceBytes If non-null, returns maximum number of bytes of
139 * video memory that can be held in the cache.
140 */
141 void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000142
143 /**
144 * Gets the current GPU resource cache usage.
145 *
146 * @param resourceCount If non-null, returns the number of resources that are held in the
147 * cache.
148 * @param maxResourceBytes If non-null, returns the total number of bytes of video memory held
149 * in the cache.
150 */
151 void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const;
152
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000153 /**
Derek Sollenbergeree479142017-05-24 11:41:33 -0400154 * Gets the number of bytes in the cache consumed by purgeable (e.g. unlocked) resources.
155 */
156 size_t getResourceCachePurgeableBytes() const;
157
158 /**
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000159 * Specify the GPU resource cache limits. If the current cache exceeds either
160 * of these, it will be purged (LRU) to keep the cache within these limits.
161 *
162 * @param maxResources The maximum number of resources that can be held in
163 * the cache.
164 * @param maxResourceBytes The maximum number of bytes of video memory
165 * that can be held in the cache.
166 */
167 void setResourceCacheLimits(int maxResources, size_t maxResourceBytes);
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000168
junov@google.com53a55842011-06-08 22:55:10 +0000169 /**
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000170 * Frees GPU created by the context. Can be called to reduce GPU memory
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000171 * pressure.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000172 */
Robert Phillips1056eb82018-03-01 14:16:41 -0500173 virtual void freeGpuResources();
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000174
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000175 /**
Jim Van Verth76d917c2017-12-13 09:26:37 -0500176 * Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are
177 * otherwise marked for deletion, regardless of whether the context is under budget.
Brian Salomon5e150852017-03-22 14:53:13 -0400178 */
Jim Van Verth76d917c2017-12-13 09:26:37 -0500179 void performDeferredCleanup(std::chrono::milliseconds msNotUsed);
Brian Salomon5e150852017-03-22 14:53:13 -0400180
Mike Klein4b6bde72017-12-14 07:46:55 -0500181 // Temporary compatibility API for Android.
182 void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed) {
183 this->performDeferredCleanup(msNotUsed);
184 }
185
Derek Sollenberger5480a182017-05-25 16:43:59 -0400186 /**
187 * Purge unlocked resources from the cache until the the provided byte count has been reached
188 * or we have purged all unlocked resources. The default policy is to purge in LRU order, but
189 * can be overridden to prefer purging scratch resources (in LRU order) prior to purging other
190 * resource types.
191 *
192 * @param maxBytesToPurge the desired number of bytes to be purged.
193 * @param preferScratchResources If true scratch resources will be purged prior to other
194 * resource types.
195 */
196 void purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources);
197
Robert Phillips6eba0632018-03-28 12:25:42 -0400198 /**
199 * This entry point is intended for instances where an app has been backgrounded or
200 * suspended.
201 * If 'scratchResourcesOnly' is true all unlocked scratch resources will be purged but the
202 * unlocked resources with persistent data will remain. If 'scratchResourcesOnly' is false
203 * then all unlocked resources will be purged.
204 * In either case, after the unlocked resources are purged a separate pass will be made to
205 * ensure that resource usage is under budget (i.e., even if 'scratchResourcesOnly' is true
206 * some resources with persistent data may be purged to be under budget).
207 *
208 * @param scratchResourcesOnly If true only unlocked scratch resources will be purged prior
209 * enforcing the budget requirements.
210 */
211 void purgeUnlockedResources(bool scratchResourcesOnly);
212
Brian Salomonbdecacf2018-02-02 20:32:49 -0500213 /**
Brian Salomonf932a632018-04-05 12:46:09 -0400214 * Gets the maximum supported texture size.
215 */
216 int maxTextureSize() const;
217
218 /**
219 * Gets the maximum supported render target size.
220 */
221 int maxRenderTargetSize() const;
222
223 /**
Brian Salomonbdecacf2018-02-02 20:32:49 -0500224 * Can a SkImage be created with the given color type.
225 */
226 bool colorTypeSupportedAsImage(SkColorType) const;
227
228 /**
229 * Can a SkSurface be created with the given color type. To check whether MSAA is supported
230 * use maxSurfaceSampleCountForColorType().
231 */
232 bool colorTypeSupportedAsSurface(SkColorType colorType) const {
233 return this->maxSurfaceSampleCountForColorType(colorType) > 0;
234 }
235
236 /**
237 * Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA
238 * rendering is supported for the color type. 0 is returned if rendering to this color type
239 * is not supported at all.
240 */
241 int maxSurfaceSampleCountForColorType(SkColorType) const;
242
bsalomon@google.com27847de2011-02-22 20:59:41 +0000243 ///////////////////////////////////////////////////////////////////////////
244 // Misc.
245
Greg Daniel06be0792019-04-22 15:53:23 -0400246
247 /**
248 * Inserts a list of GPU semaphores that the current GPU-backed API must wait on before
249 * executing any more commands on the GPU. Skia will take ownership of the underlying semaphores
250 * and delete them once they have been signaled and waited on. If this call returns false, then
251 * the GPU back-end will not wait on any passed in semaphores, and the client will still own the
252 * semaphores.
253 */
254 bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores);
255
bsalomon@google.com27847de2011-02-22 20:59:41 +0000256 /**
Greg Daniel51316782017-08-02 15:10:09 +0000257 * Call to ensure all drawing to the context has been issued to the underlying 3D API.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000258 */
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400259 void flush() {
Greg Daniel797efca2019-05-09 14:04:20 -0400260 this->flush(GrFlushInfo(), GrPrepareForExternalIORequests());
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400261 }
robertphillipsea461502015-05-26 11:38:03 -0700262
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000263 /**
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400264 * Call to ensure all drawing to the context has been issued to the underlying 3D API.
Greg Daniel51316782017-08-02 15:10:09 +0000265 *
Greg Daniela3aa75a2019-04-12 14:24:55 -0400266 * If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not have created or
Greg Daniel51316782017-08-02 15:10:09 +0000267 * added any semaphores to signal on the GPU. Thus the client should not have the GPU wait on
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400268 * any of the semaphores passed in with the GrFlushInfo. However, any pending commands to the
Greg Daniel797efca2019-05-09 14:04:20 -0400269 * context will still be flushed. It should be emphasized that a return value of
270 * GrSemaphoresSubmitted::kNo does not mean the flush did not happen. It simply means there were
271 * no semaphores submitted to the GPU. A caller should only take this as a failure if they
272 * passed in semaphores to be submitted.
Greg Daniel51316782017-08-02 15:10:09 +0000273 */
Greg Daniel797efca2019-05-09 14:04:20 -0400274 GrSemaphoresSubmitted flush(const GrFlushInfo& info) {
275 return this->flush(info, GrPrepareForExternalIORequests());
276 }
277
278 /**
279 * Call to ensure all drawing to the context has been issued to the underlying 3D API.
280 *
281 * If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not have created or
282 * added any semaphores to signal on the GPU. Thus the client should not have the GPU wait on
283 * any of the semaphores passed in with the GrFlushInfo. However, any pending commands to the
284 * context will still be flushed. It should be emphasized that a return value of
285 * GrSemaphoresSubmitted::kNo does not mean the flush did not happen. It simply means there were
286 * no semaphores submitted to the GPU. A caller should only take this as a failure if they
287 * passed in semaphores to be submitted.
288 *
289 * If the GrPrepareForExternalIORequests contains valid gpu backed SkSurfaces or SkImages, Skia
290 * will put the underlying backend objects into a state that is ready for external uses. See
291 * declaration of GrPreopareForExternalIORequests for more details.
292 */
293 GrSemaphoresSubmitted flush(const GrFlushInfo&, const GrPrepareForExternalIORequests&);
Greg Danielb9990e42019-04-10 16:28:52 -0400294
295 /**
296 * Deprecated.
297 */
Greg Danield10c9012019-04-22 10:22:41 -0400298 GrSemaphoresSubmitted flush(GrFlushFlags flags, int numSemaphores,
Greg Daniel5816b3d2019-04-22 11:46:41 -0400299 GrBackendSemaphore signalSemaphores[],
300 GrGpuFinishedProc finishedProc = nullptr,
301 GrGpuFinishedContext finishedContext = nullptr) {
Greg Danield10c9012019-04-22 10:22:41 -0400302 GrFlushInfo info;
303 info.fFlags = flags;
304 info.fNumSemaphores = numSemaphores;
305 info.fSignalSemaphores = signalSemaphores;
Greg Daniel5816b3d2019-04-22 11:46:41 -0400306 info.fFinishedProc = finishedProc;
307 info.fFinishedContext = finishedContext;
Greg Danield10c9012019-04-22 10:22:41 -0400308 return this->flush(info);
309 }
310
311 /**
312 * Deprecated.
313 */
Greg Daniel51316782017-08-02 15:10:09 +0000314 GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores,
Greg Danielb9990e42019-04-10 16:28:52 -0400315 GrBackendSemaphore signalSemaphores[]) {
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400316 GrFlushInfo info;
317 info.fNumSemaphores = numSemaphores;
318 info.fSignalSemaphores = signalSemaphores;
319 return this->flush(info);
Greg Danielb9990e42019-04-10 16:28:52 -0400320 }
Greg Daniel51316782017-08-02 15:10:09 +0000321
Brian Salomonb0d8b762019-05-06 16:58:22 -0400322 /**
323 * Checks whether any asynchronous work is complete and if so calls related callbacks.
324 */
325 void checkAsyncWorkCompletion();
326
robertphillips4fd74ae2016-08-03 14:26:53 -0700327 // Provides access to functions that aren't part of the public API.
Robert Phillips9da87e02019-02-04 13:26:26 -0500328 GrContextPriv priv();
329 const GrContextPriv priv() const;
robertphillips4fd74ae2016-08-03 14:26:53 -0700330
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500331 /** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */
332 // Chrome is using this!
333 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
334
Khushal3e7548c2018-05-23 15:45:01 -0700335 bool supportsDistanceFieldText() const;
336
Greg Daniela870b462019-01-08 15:49:46 -0500337 void storeVkPipelineCacheData();
338
Adrienne Walker0f827972019-03-26 13:46:14 -0700339 static size_t ComputeTextureSize(SkColorType type, int width, int height, GrMipMapped,
340 bool useNextPow2 = false);
341
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400342 /*
343 * The explicitly allocated backend texture API allows clients to use Skia to create backend
344 * objects outside of Skia proper (i.e., Skia's caching system will not know about them.)
345 *
346 * It is the client's responsibility to delete all these objects (using deleteBackendTexture)
347 * before deleting the GrContext used to create them. Additionally, clients should only
348 * delete these objects on the thread for which that GrContext is active.
349 *
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400350 * The client is responsible for ensuring synchronization between different uses
351 * of the backend object (i.e., wrapping it in a surface, rendering to it, deleting the
352 * surface, rewrapping it in a image and drawing the image will require explicit
353 * sychronization on the client's part).
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400354 */
355
356 // If possible, create an uninitialized backend texture. The client should ensure that the
357 // returned backend texture is valid.
Robert Phillipsd1d869d2019-06-07 14:21:31 -0400358 // For the Vulkan backend the layout of the created VkImage will be:
359 // VK_IMAGE_LAYOUT_UNDEFINED.
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400360 GrBackendTexture createBackendTexture(int width, int height,
Greg Danielf91aeb22019-06-18 09:58:02 -0400361 const GrBackendFormat&,
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400362 GrMipMapped,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400363 GrRenderable,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400364 GrProtected = GrProtected::kNo);
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400365
366 // If possible, create an uninitialized backend texture. The client should ensure that the
367 // returned backend texture is valid.
368 // If successful, the created backend texture will be compatible with the provided
369 // SkColorType.
Robert Phillipsd1d869d2019-06-07 14:21:31 -0400370 // For the Vulkan backend the layout of the created VkImage will be:
371 // VK_IMAGE_LAYOUT_UNDEFINED.
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400372 GrBackendTexture createBackendTexture(int width, int height,
373 SkColorType,
374 GrMipMapped,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400375 GrRenderable,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400376 GrProtected = GrProtected::kNo);
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400377
Robert Phillips02dc0302019-07-02 17:58:27 -0400378
379 // If possible, create an uninitialized backend texture that is compatible with the
380 // provided characterization. The client should ensure that the returned backend texture
381 // is valid.
382 // For the Vulkan backend the layout of the created VkImage will be:
383 // VK_IMAGE_LAYOUT_UNDEFINED.
384 GrBackendTexture createBackendTexture(const SkSurfaceCharacterization& characterization);
385
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400386 // If possible, create a backend texture initialized to a particular color. The client should
387 // ensure that the returned backend texture is valid.
Robert Phillipsd1d869d2019-06-07 14:21:31 -0400388 // For the Vulkan backend the layout of the created VkImage will be:
Robert Phillips02dc0302019-07-02 17:58:27 -0400389 // VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL if renderable is kNo
390 // and VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL if renderable is kYes
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400391 GrBackendTexture createBackendTexture(int width, int height,
Robert Phillips02dc0302019-07-02 17:58:27 -0400392 const GrBackendFormat&,
393 const SkColor4f& color,
394 GrMipMapped,
395 GrRenderable,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400396 GrProtected = GrProtected::kNo);
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400397
398 // If possible, create a backend texture initialized to a particular color. The client should
399 // ensure that the returned backend texture is valid.
400 // If successful, the created backend texture will be compatible with the provided
401 // SkColorType.
Robert Phillipsd1d869d2019-06-07 14:21:31 -0400402 // For the Vulkan backend the layout of the created VkImage will be:
Robert Phillips02dc0302019-07-02 17:58:27 -0400403 // VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL if renderable is kNo
404 // and VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL if renderable is kYes
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400405 GrBackendTexture createBackendTexture(int width, int height,
Robert Phillips02dc0302019-07-02 17:58:27 -0400406 SkColorType,
407 const SkColor4f& color,
408 GrMipMapped,
409 GrRenderable,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400410 GrProtected = GrProtected::kNo);
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400411
Robert Phillips02dc0302019-07-02 17:58:27 -0400412 // If possible, create a backend texture initialized to a particular color that is
413 // compatible with the provided characterization. The client should ensure that the
414 // returned backend texture is valid.
415 // For the Vulkan backend the layout of the created VkImage will be:
416 // VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
417 GrBackendTexture createBackendTexture(const SkSurfaceCharacterization& characterization,
418 const SkColor4f& color);
419
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400420 void deleteBackendTexture(GrBackendTexture);
421
Robert Phillips88260b52018-01-19 12:56:09 -0500422protected:
Robert Phillipsa41c6852019-02-07 10:44:10 -0500423 GrContext(GrBackendApi, const GrContextOptions&, int32_t contextID = SK_InvalidGenID);
424
Robert Phillipsbb606772019-02-04 17:50:57 -0500425 bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>) override;
Robert Phillips1056eb82018-03-01 14:16:41 -0500426
Robert Phillips292a6b22019-02-14 14:49:02 -0500427 GrContext* asDirectContext() override { return this; }
428
Robert Phillips5a66efb2018-03-07 15:13:18 -0500429 virtual GrAtlasManager* onGetAtlasManager() = 0;
Robert Phillips1056eb82018-03-01 14:16:41 -0500430
Robert Phillipsfde6fa02018-03-02 08:53:14 -0500431 sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy;
Robert Phillips1056eb82018-03-01 14:16:41 -0500432
bsalomon@google.com27847de2011-02-22 20:59:41 +0000433private:
Ethan Nicholas8e265a72018-12-12 16:22:40 -0500434 // fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed
435 // after all of its users. Clients of fTaskGroup will generally want to ensure that they call
436 // wait() on it as they are being destroyed, to avoid the possibility of pending tasks being
437 // invoked after objects they depend upon have already been destroyed.
438 std::unique_ptr<SkTaskGroup> fTaskGroup;
Brian Salomon384fab42017-12-07 12:33:05 -0500439 sk_sp<GrGpu> fGpu;
bsalomon41b952c2016-03-11 06:46:33 -0800440 GrResourceCache* fResourceCache;
Brian Osman32342f02017-03-04 08:12:46 -0500441 GrResourceProvider* fResourceProvider;
bsalomond309e7a2015-04-30 14:18:54 -0700442
bsalomon41b952c2016-03-11 06:46:33 -0800443 bool fDidTestPMConversions;
Brian Osman28804f32017-04-20 10:24:36 -0400444 // true if the PM/UPM conversion succeeded; false otherwise
445 bool fPMUPMConversionsRoundTrip;
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000446
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400447 GrContextOptions::PersistentCache* fPersistentCache;
Brian Osman5e7fbfd2019-05-03 13:13:35 -0400448 GrContextOptions::ShaderErrorHandler* fShaderErrorHandler;
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400449
Brian Osman11052242016-10-27 14:47:55 -0400450 // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending
robertphillips4fd74ae2016-08-03 14:26:53 -0700451 friend class GrContextPriv;
csmartdaltonc6f411e2016-08-05 22:32:12 -0700452
skia.committer@gmail.comcdcb2ce2013-01-29 07:05:52 +0000453 /**
Brian Osman5ea96bf2018-10-02 14:58:05 -0400454 * These functions create premul <-> unpremul effects, using the specialized round-trip effects
455 * from GrConfigConversionEffect.
bsalomon@google.comadc65362013-01-28 14:26:09 +0000456 */
Brian Osman5ea96bf2018-10-02 14:58:05 -0400457 std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>);
458 std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>);
Brian Osman409e74f2017-04-17 11:48:28 -0400459
Robert Phillips4217ea72019-01-30 13:08:28 -0500460 typedef GrRecordingContext INHERITED;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000461};
462
bsalomon@google.com27847de2011-02-22 20:59:41 +0000463#endif