blob: 57500cd22e86aafe04f976802807d2096d3edd0c [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"
rmistry@google.comfbfcd562012-08-23 18:09:54 +000013#include "GrRenderTarget.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000014#include "SkMatrix.h"
egdaniele61c4112014-06-12 10:24:21 -070015#include "SkPathEffect.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000016#include "SkTypes.h"
joshualitt27a48dc2016-01-08 07:19:47 -080017#include "../private/GrAuditTrail.h"
joshualitt1de610a2016-01-06 08:26:09 -080018#include "../private/GrSingleOwner.h"
bsalomon@google.com27847de2011-02-22 20:59:41 +000019
Brian Salomonf856fd12016-12-16 14:24:34 -050020class GrAtlasGlyphCache;
bsalomon682c2692015-05-22 14:01:46 -070021struct GrContextOptions;
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;
Brian Osman11052242016-10-27 14:47:55 -040026class GrRenderTargetContext;
joshualittb0a8a372014-09-23 09:50:21 -070027class GrFragmentProcessor;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000028class GrGpu;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000029class GrIndexBuffer;
commit-bot@chromium.org81312832013-03-22 18:34:09 +000030class GrOvalRenderer;
commit-bot@chromium.org5c8ee252013-11-01 15:23:44 +000031class GrPath;
egdaniel8dd688b2015-01-22 10:16:09 -080032class GrPipelineBuilder;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000033class GrResourceEntry;
bsalomon0ea80f42015-02-11 10:49:59 -080034class GrResourceCache;
bsalomond309e7a2015-04-30 14:18:54 -070035class GrResourceProvider;
Mike Reed84dd8572017-03-08 22:21:00 -050036class GrSamplerParams;
joshualittb7133be2015-04-08 09:08:31 -070037class GrTextBlobCache;
kkinnunenc6cb56f2014-06-24 00:12:27 -070038class GrTextContext;
Mike Reed84dd8572017-03-08 22:21:00 -050039class GrTextureProxy;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000040class GrVertexBuffer;
bsalomon6c9cd552016-01-22 07:17:34 -080041class GrSwizzle;
ericrk0a5fa482015-09-15 14:16:10 -070042class SkTraceMemoryDump;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000043
Mike Reed84dd8572017-03-08 22:21:00 -050044class SkImage;
45class SkSurfaceProps;
46
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000047class SK_API GrContext : public SkRefCnt {
bsalomon@google.com27847de2011-02-22 20:59:41 +000048public:
49 /**
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000050 * Creates a GrContext for a backend context.
bsalomon@google.com27847de2011-02-22 20:59:41 +000051 */
bsalomon682c2692015-05-22 14:01:46 -070052 static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options);
53 static GrContext* Create(GrBackend, GrBackendContext);
bsalomon@google.com27847de2011-02-22 20:59:41 +000054
bsalomon33435572014-11-05 14:47:41 -080055 /**
56 * Only defined in test apps.
57 */
58 static GrContext* CreateMockContext();
59
bsalomon@google.com27847de2011-02-22 20:59:41 +000060 virtual ~GrContext();
61
bungeman6bd52842016-10-27 09:30:08 -070062 sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
bsalomon41b952c2016-03-11 06:46:33 -080063
bsalomon@google.com27847de2011-02-22 20:59:41 +000064 /**
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.com0a208a12013-06-28 18:57:35 +000069 * The flag bits, state, is dpendent on which backend is used by the
70 * context, either GL or D3D (possible in future).
bsalomon@google.com27847de2011-02-22 20:59:41 +000071 */
bsalomon@google.com0a208a12013-06-28 18:57:35 +000072 void resetContext(uint32_t state = kAll_GrBackendState);
bsalomon@google.com27847de2011-02-22 20:59:41 +000073
bsalomon@google.com8fe72472011-03-30 21:26:44 +000074 /**
robertphillips@google.comcdb426d2012-09-24 19:33:59 +000075 * 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 /**
bsalomon6e2aad42016-04-01 11:54:31 -070093 * 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.com8fe72472011-03-30 21:26:44 +0000102 */
bsalomon2354f842014-07-28 13:48:36 -0700103 void abandonContext();
junov@google.com53a55842011-06-08 22:55:10 +0000104
bsalomon6e2aad42016-04-01 11:54:31 -0700105 /**
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.org95c20032014-05-09 14:29:32 +0000116 ///////////////////////////////////////////////////////////////////////////
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.org95c20032014-05-09 14:29:32 +0000128
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.org95c20032014-05-09 14:29:32 +0000139 /**
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.org95c20032014-05-09 14:29:32 +0000149
junov@google.com53a55842011-06-08 22:55:10 +0000150 /**
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000151 * Frees GPU created by the context. Can be called to reduce GPU memory
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000152 * pressure.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000153 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000154 void freeGpuResources();
155
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000156 /**
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000157 * 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.orgd8a57af2014-03-19 21:19:16 +0000160 */
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000161 void purgeAllUnlockedResources();
162
bsalomon76228632015-05-29 08:02:10 -0700163 /** Access the context capabilities */
164 const GrCaps* caps() const { return fCaps; }
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000165
commit-bot@chromium.orgb471a322014-03-10 07:40:03 +0000166 /**
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.com27847de2011-02-22 20:59:41 +0000179 /**
Brian Osman11052242016-10-27 14:47:55 -0400180 * Create both a GrRenderTarget and a matching GrRenderTargetContext to wrap it.
181 * We guarantee that "asTexture" will succeed for renderTargetContexts created
robertphillipsebf30e82016-05-11 08:34:39 -0700182 * via this entry point.
robertphillipsd4c741e2016-04-28 09:55:15 -0700183 */
Brian Osman11052242016-10-27 14:47:55 -0400184 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 Phillips40fd7c92017-01-30 08:06:27 -0500190 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
Brian Osman11052242016-10-27 14:47:55 -0400191 const SkSurfaceProps* surfaceProps = nullptr,
192 SkBudgeted = SkBudgeted::kYes);
robertphillipsd4c741e2016-04-28 09:55:15 -0700193
Brian Salomonaeac5d82016-10-29 00:13:29 -0400194 // Create a new render target context as above but have it backed by a deferred-style
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400195 // GrRenderTargetProxy rather than one that is backed by an actual GrRenderTarget
robertphillipsd728f0c2016-11-21 11:05:03 -0800196 sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext(
197 SkBackingFit fit,
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400198 int width, int height,
199 GrPixelConfig config,
200 sk_sp<SkColorSpace> colorSpace,
201 int sampleCnt = 0,
Robert Phillips40fd7c92017-01-30 08:06:27 -0500202 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400203 const SkSurfaceProps* surfaceProps = nullptr,
204 SkBudgeted = SkBudgeted::kYes);
robertphillips48fde9c2016-09-06 05:20:20 -0700205 /*
Brian Osman11052242016-10-27 14:47:55 -0400206 * This method will attempt to create a renderTargetContext that has, at least, the number of
robertphillips48fde9c2016-09-06 05:20:20 -0700207 * 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 Osman11052242016-10-27 14:47:55 -0400211 sk_sp<GrRenderTargetContext> makeRenderTargetContextWithFallback(
robertphillips48fde9c2016-09-06 05:20:20 -0700212 SkBackingFit fit,
213 int width, int height,
214 GrPixelConfig config,
215 sk_sp<SkColorSpace> colorSpace,
216 int sampleCnt = 0,
Robert Phillips40fd7c92017-01-30 08:06:27 -0500217 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
robertphillips48fde9c2016-09-06 05:20:20 -0700218 const SkSurfaceProps* surfaceProps = nullptr,
219 SkBudgeted budgeted = SkBudgeted::kYes);
220
robertphillipsd728f0c2016-11-21 11:05:03 -0800221 // 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 Phillips40fd7c92017-01-30 08:06:27 -0500229 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
robertphillipsd728f0c2016-11-21 11:05:03 -0800230 const SkSurfaceProps* surfaceProps = nullptr,
231 SkBudgeted budgeted = SkBudgeted::kYes);
232
bsalomon@google.com27847de2011-02-22 20:59:41 +0000233 ///////////////////////////////////////////////////////////////////////////
234 // Misc.
235
236 /**
237 * Call to ensure all drawing to the context has been issued to the
238 * underlying 3D API.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000239 */
bsalomonb77a9072016-09-07 10:02:04 -0700240 void flush();
robertphillipsea461502015-05-26 11:38:03 -0700241
bsalomon@google.com0342a852012-08-20 19:22:38 +0000242 /**
243 * These flags can be used with the read/write pixels functions below.
244 */
245 enum PixelOpsFlags {
bsalomonf80bfed2014-10-07 05:56:02 -0700246 /** 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.com0342a852012-08-20 19:22:38 +0000248 kDontFlush_PixelOpsFlag = 0x1,
bsalomonf80bfed2014-10-07 05:56:02 -0700249 /** Any surface writes should be flushed to the backend 3D API after the surface operation
250 is complete */
251 kFlushWrites_PixelOp = 0x2,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000252 /** 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. */
bsalomonf80bfed2014-10-07 05:56:02 -0700254 kUnpremul_PixelOpsFlag = 0x4,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000255 };
256
bsalomon@google.com27847de2011-02-22 20:59:41 +0000257 /**
bsalomone8d21e82015-07-16 08:23:13 -0700258 * Reads a rectangle of pixels from a surface.
259 * @param surface the surface to read from.
Brian Osmanb62ea222016-12-22 11:12:16 -0500260 * @param srcColorSpace color space of the surface
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000261 * @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 Osmanb62ea222016-12-22 11:12:16 -0500266 * @param dstColorSpace color space of the destination buffer
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000267 * @param buffer memory to read the rectangle into.
bsalomon@google.com0342a852012-08-20 19:22:38 +0000268 * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
269 * packed.
270 * @param pixelOpsFlags see PixelOpsFlags enum above.
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000271 *
bsalomon@google.com0342a852012-08-20 19:22:38 +0000272 * @return true if the read succeeded, false if not. The read can fail because of an unsupported
bsalomone8d21e82015-07-16 08:23:13 -0700273 * pixel configs
bsalomon@google.com27847de2011-02-22 20:59:41 +0000274 */
Brian Osmanb62ea222016-12-22 11:12:16 -0500275 bool readSurfacePixels(GrSurface* surface, SkColorSpace* srcColorSpace,
bsalomone8d21e82015-07-16 08:23:13 -0700276 int left, int top, int width, int height,
Brian Osmanb62ea222016-12-22 11:12:16 -0500277 GrPixelConfig config, SkColorSpace* dstColorSpace, void* buffer,
bsalomone8d21e82015-07-16 08:23:13 -0700278 size_t rowBytes = 0,
279 uint32_t pixelOpsFlags = 0);
bsalomon@google.com6f379512011-11-16 20:36:03 +0000280
281 /**
bsalomon81beccc2014-10-13 12:32:55 -0700282 * Writes a rectangle of pixels to a surface.
283 * @param surface the surface to write to.
Brian Osmanb62ea222016-12-22 11:12:16 -0500284 * @param dstColorSpace color space of the surface
bsalomon@google.com6f379512011-11-16 20:36:03 +0000285 * @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 Osmanb62ea222016-12-22 11:12:16 -0500290 * @param srcColorSpace color space of the source buffer
bsalomon@google.com6f379512011-11-16 20:36:03 +0000291 * @param buffer memory to read pixels from
bsalomon@google.com3cbaa2d2012-10-12 14:51:52 +0000292 * @param rowBytes number of bytes between consecutive rows. Zero
bsalomon@google.com6f379512011-11-16 20:36:03 +0000293 * means rows are tightly packed.
bsalomon@google.com0342a852012-08-20 19:22:38 +0000294 * @param pixelOpsFlags see PixelOpsFlags enum above.
bsalomon@google.com9c680582013-02-06 18:17:50 +0000295 * @return true if the write succeeded, false if not. The write can fail because of an
bsalomon81beccc2014-10-13 12:32:55 -0700296 * unsupported combination of surface and src configs.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000297 */
Brian Osmanb62ea222016-12-22 11:12:16 -0500298 bool writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpace,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000299 int left, int top, int width, int height,
Brian Osmanb62ea222016-12-22 11:12:16 -0500300 GrPixelConfig config, SkColorSpace* srcColorSpace, const void* buffer,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000301 size_t rowBytes,
302 uint32_t pixelOpsFlags = 0);
303
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000304 /**
bsalomonf80bfed2014-10-07 05:56:02 -0700305 * 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.com75f9f252012-01-31 13:35:56 +0000308
309 /**
ajuma95243eb2016-08-24 08:19:02 -0700310 * 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 /**
bsalomonc49e8682015-06-30 11:37:35 -0700316 * Finalizes all pending reads and writes to the surface and also performs an MSAA resolve
317 * if necessary.
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000318 *
bsalomon87a94eb2014-11-03 14:28:32 -0800319 * 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.com75f9f252012-01-31 13:35:56 +0000322 */
bsalomonc49e8682015-06-30 11:37:35 -0700323 void prepareSurfaceForExternalIO(GrSurface*);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000324
325 /**
joshualitt0acd0d32015-05-07 08:23:19 -0700326 * An ID associated with this context, guaranteed to be unique.
327 */
328 uint32_t uniqueID() { return fUniqueID; }
329
bsalomon@google.com27847de2011-02-22 20:59:41 +0000330 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com27847de2011-02-22 20:59:41 +0000331 // Functions intended for internal use only.
332 GrGpu* getGpu() { return fGpu; }
bsalomon@google.com1f221a72011-08-23 20:54:07 +0000333 const GrGpu* getGpu() const { return fGpu; }
Brian Salomonf856fd12016-12-16 14:24:34 -0500334 GrAtlasGlyphCache* getAtlasGlyphCache() { return fAtlasGlyphCache; }
bungeman6bd52842016-10-27 09:30:08 -0700335 GrTextBlobCache* getTextBlobCache() { return fTextBlobCache.get(); }
robertphillips77a2e522015-10-17 07:43:27 -0700336 bool abandoned() const;
bsalomond309e7a2015-04-30 14:18:54 -0700337 GrResourceProvider* resourceProvider() { return fResourceProvider; }
338 const GrResourceProvider* resourceProvider() const { return fResourceProvider; }
bsalomon0ea80f42015-02-11 10:49:59 -0800339 GrResourceCache* getResourceCache() { return fResourceCache; }
bsalomon@google.com9923c2b2012-06-06 18:21:18 +0000340
joshualitte45c81c2015-12-02 09:05:37 -0800341 /** Reset GPU stats */
342 void resetGpuStats() const ;
343
mtkleinb9eb4ac2015-02-02 18:26:03 -0800344 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */
345 void dumpCacheStats(SkString*) const;
joshualittdc5685a2015-12-02 14:08:25 -0800346 void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000347 void printCacheStats() const;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000348
mtkleinb9eb4ac2015-02-02 18:26:03 -0800349 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */
350 void dumpGpuStats(SkString*) const;
joshualittdc5685a2015-12-02 14:08:25 -0800351 void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800352 void printGpuStats() const;
robertphillips754f4e92014-09-18 13:52:08 -0700353
joshualitt17d833b2015-08-03 10:17:44 -0700354 /** 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
joshualittda04e0e2015-08-19 08:16:43 -0700358 /** Specify the sizes of the GrAtlasTextContext atlases. The configs pointer below should be
359 to an array of 3 entries */
Brian Salomon2ee084e2016-12-16 18:59:19 -0500360 void setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs);
joshualittda04e0e2015-08-19 08:16:43 -0700361
ericrk0a5fa482015-09-15 14:16:10 -0700362 /** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */
363 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
364
Robert Phillips33667da2016-12-20 11:05:30 -0500365 /** 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 Phillipsc37e6142017-01-20 10:03:25 -0500368 sk_sp<SkImage> getFontAtlasImage_ForTesting(GrMaskFormat format);
jvanverth629162d2015-11-08 08:07:24 -0800369
joshualitt5651ee62016-01-11 10:39:11 -0800370 GrAuditTrail* getAuditTrail() { return &fAuditTrail; }
joshualitt27a48dc2016-01-08 07:19:47 -0800371
joshualittce894002016-01-11 13:29:31 -0800372 /** This is only useful for debug purposes */
373 SkDEBUGCODE(GrSingleOwner* debugSingleOwner() const { return &fSingleOwner; } )
374
robertphillips4fd74ae2016-08-03 14:26:53 -0700375 // Provides access to functions that aren't part of the public API.
376 GrContextPriv contextPriv();
377 const GrContextPriv contextPriv() const;
378
bsalomon@google.com27847de2011-02-22 20:59:41 +0000379private:
bsalomon41b952c2016-03-11 06:46:33 -0800380 GrGpu* fGpu;
381 const GrCaps* fCaps;
382 GrResourceCache* fResourceCache;
Brian Osman32342f02017-03-04 08:12:46 -0500383 GrResourceProvider* fResourceProvider;
bsalomond309e7a2015-04-30 14:18:54 -0700384
bungeman6bd52842016-10-27 09:30:08 -0700385 sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy;
bsalomon41b952c2016-03-11 06:46:33 -0800386
Brian Salomonf856fd12016-12-16 14:24:34 -0500387 GrAtlasGlyphCache* fAtlasGlyphCache;
bungeman6bd52842016-10-27 09:30:08 -0700388 std::unique_ptr<GrTextBlobCache> fTextBlobCache;
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000389
Brian Osman46da1cc2017-02-14 14:15:48 -0500390 bool fDisableGpuYUVConversion;
bsalomon41b952c2016-03-11 06:46:33 -0800391 bool fDidTestPMConversions;
392 int fPMToUPMConversion;
393 int fUPMToPMConversion;
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000394
joshualitt1de610a2016-01-06 08:26:09 -0800395 // In debug builds we guard against improper thread handling
joshualittde8dc7e2016-01-08 10:09:13 -0800396 // This guard is passed to the GrDrawingManager and, from there to all the
Brian Osman32342f02017-03-04 08:12:46 -0500397 // GrRenderTargetContexts. It is also passed to the GrResourceProvider and SkGpuDevice.
bsalomon41b952c2016-03-11 06:46:33 -0800398 mutable GrSingleOwner fSingleOwner;
joshualitt1de610a2016-01-06 08:26:09 -0800399
robertphillips@google.comcdb426d2012-09-24 19:33:59 +0000400 struct CleanUpData {
401 PFCleanUpFunc fFunc;
402 void* fInfo;
403 };
404
bsalomon41b952c2016-03-11 06:46:33 -0800405 SkTDArray<CleanUpData> fCleanUpData;
robertphillips@google.com44a91dc2013-07-25 15:32:06 +0000406
bsalomon41b952c2016-03-11 06:46:33 -0800407 const uint32_t fUniqueID;
krajcevski9c6d4d72014-08-12 07:26:25 -0700408
bungeman6bd52842016-10-27 09:30:08 -0700409 std::unique_ptr<GrDrawingManager> fDrawingManager;
robertphillips77a2e522015-10-17 07:43:27 -0700410
bsalomon41b952c2016-03-11 06:46:33 -0800411 GrAuditTrail fAuditTrail;
joshualitt27a48dc2016-01-08 07:19:47 -0800412
Brian Osman11052242016-10-27 14:47:55 -0400413 // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending
robertphillips4fd74ae2016-08-03 14:26:53 -0700414 friend class GrContextPriv;
csmartdaltonc6f411e2016-08-05 22:32:12 -0700415
bsalomon682c2692015-05-22 14:01:46 -0700416 GrContext(); // init must be called after the constructor.
417 bool init(GrBackend, GrBackendContext, const GrContextOptions& options);
robertphillipsea461502015-05-26 11:38:03 -0700418
bsalomon33435572014-11-05 14:47:41 -0800419 void initMockContext();
bsalomon69cfe952015-11-30 13:27:47 -0800420 void initCommon(const GrContextOptions&);
bsalomon@google.com205d4602011-04-25 12:43:45 +0000421
skia.committer@gmail.comcdcb2ce2013-01-29 07:05:52 +0000422 /**
bsalomon@google.comadc65362013-01-28 14:26:09 +0000423 * 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
bsalomon6c9cd552016-01-22 07:17:34 -0800425 * return NULL. They also can perform a swizzle as part of the draw.
bsalomon@google.comadc65362013-01-28 14:26:09 +0000426 */
Robert Phillips757914d2017-01-25 15:48:30 -0500427 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&);
bsalomon6c6f6582015-09-10 08:12:46 -0700432 /** Called before either of the above two functions to determine the appropriate fragment
Robert Phillips65115a12016-12-13 12:42:19 -0500433 processors for conversions. */
bsalomon6c6f6582015-09-10 08:12:46 -0700434 void testPMConversionsIfNecessary(uint32_t flags);
bsalomon636e8022015-07-29 06:08:46 -0700435 /** 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.coma04e8e82012-08-27 12:53:13 +0000438
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000439 /**
joshualitt0db6dfa2015-04-10 07:01:30 -0700440 * 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.orga4de8c22013-09-09 13:38:37 +0000445 typedef SkRefCnt INHERITED;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000446};
447
bsalomon41b952c2016-03-11 06:46:33 -0800448/**
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 */
452class GrContextThreadSafeProxy : public SkRefCnt {
453private:
bungeman6bd52842016-10-27 09:30:08 -0700454 GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, uint32_t uniqueID)
455 : fCaps(std::move(caps))
bsalomon41b952c2016-03-11 06:46:33 -0800456 , fContextUniqueID(uniqueID) {}
457
bungeman6bd52842016-10-27 09:30:08 -0700458 sk_sp<const GrCaps> fCaps;
459 uint32_t fContextUniqueID;
bsalomon41b952c2016-03-11 06:46:33 -0800460
461 friend class GrContext;
462 friend class SkImage;
463
464 typedef SkRefCnt INHERITED;
465};
466
bsalomon@google.com27847de2011-02-22 20:59:41 +0000467#endif