blob: acd7b1ad911ee3e1ce92d5f40a8e846fdc66f243 [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
joshualitt44701df2015-02-23 14:44:57 -080011#include "GrClip.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000012#include "GrColor.h"
bsalomon@google.com288d9542012-10-17 12:53:54 +000013#include "GrPaint.h"
bsalomon@google.com45a15f52012-12-10 19:10:17 +000014#include "GrPathRendererChain.h"
rmistry@google.comfbfcd562012-08-23 18:09:54 +000015#include "GrRenderTarget.h"
bsalomond309e7a2015-04-30 14:18:54 -070016#include "GrTextureProvider.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000017#include "SkMatrix.h"
egdaniele61c4112014-06-12 10:24:21 -070018#include "SkPathEffect.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000019#include "SkTypes.h"
bsalomon@google.com27847de2011-02-22 20:59:41 +000020
jvanverth@google.combfe2b9d2013-09-06 16:57:29 +000021class GrAARectRenderer;
joshualitt7c3a2f82015-03-31 13:32:05 -070022class GrBatchFontCache;
bsalomon76228632015-05-29 08:02:10 -070023class GrCaps;
bsalomon682c2692015-05-22 14:01:46 -070024struct GrContextOptions;
robertphillipsea461502015-05-26 11:38:03 -070025class GrDrawContext;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000026class GrDrawTarget;
joshualittb0a8a372014-09-23 09:50:21 -070027class GrFragmentProcessor;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000028class GrGpu;
egdanielbbcb38d2014-06-19 10:19:29 -070029class GrGpuTraceMarker;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000030class GrIndexBuffer;
robertphillips@google.come930a072014-04-03 00:34:27 +000031class GrLayerCache;
commit-bot@chromium.org81312832013-03-22 18:34:09 +000032class GrOvalRenderer;
commit-bot@chromium.org5c8ee252013-11-01 15:23:44 +000033class GrPath;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000034class GrPathRenderer;
egdaniel8dd688b2015-01-22 10:16:09 -080035class GrPipelineBuilder;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000036class GrResourceEntry;
bsalomon0ea80f42015-02-11 10:49:59 -080037class GrResourceCache;
bsalomond309e7a2015-04-30 14:18:54 -070038class GrResourceProvider;
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000039class GrTestTarget;
joshualittb7133be2015-04-08 09:08:31 -070040class GrTextBlobCache;
kkinnunenc6cb56f2014-06-24 00:12:27 -070041class GrTextContext;
bsalomon@google.com288d9542012-10-17 12:53:54 +000042class GrTextureParams;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000043class GrVertexBuffer;
egdanield58a0ba2014-06-11 10:30:05 -070044class GrStrokeInfo;
robertphillips@google.com72176b22012-05-23 13:19:12 +000045class GrSoftwarePathRenderer;
joshualitt6e8cd962015-03-20 10:30:14 -070046class SkGpuDevice;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000047
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000048class SK_API GrContext : public SkRefCnt {
bsalomon@google.com27847de2011-02-22 20:59:41 +000049public:
reed@google.comfa35e3d2012-06-26 20:16:17 +000050 SK_DECLARE_INST_COUNT(GrContext)
51
bsalomon@google.com27847de2011-02-22 20:59:41 +000052 /**
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000053 * Creates a GrContext for a backend context.
bsalomon@google.com27847de2011-02-22 20:59:41 +000054 */
bsalomon682c2692015-05-22 14:01:46 -070055 static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options);
56 static GrContext* Create(GrBackend, GrBackendContext);
bsalomon@google.com27847de2011-02-22 20:59:41 +000057
bsalomon33435572014-11-05 14:47:41 -080058 /**
59 * Only defined in test apps.
60 */
61 static GrContext* CreateMockContext();
62
bsalomon@google.com27847de2011-02-22 20:59:41 +000063 virtual ~GrContext();
64
65 /**
66 * The GrContext normally assumes that no outsider is setting state
67 * within the underlying 3D API's context/device/whatever. This call informs
68 * the context that the state was modified and it should resend. Shouldn't
69 * be called frequently for good performance.
bsalomon@google.com0a208a12013-06-28 18:57:35 +000070 * The flag bits, state, is dpendent on which backend is used by the
71 * context, either GL or D3D (possible in future).
bsalomon@google.com27847de2011-02-22 20:59:41 +000072 */
bsalomon@google.com0a208a12013-06-28 18:57:35 +000073 void resetContext(uint32_t state = kAll_GrBackendState);
bsalomon@google.com27847de2011-02-22 20:59:41 +000074
bsalomon@google.com8fe72472011-03-30 21:26:44 +000075 /**
robertphillips@google.comcdb426d2012-09-24 19:33:59 +000076 * Callback function to allow classes to cleanup on GrContext destruction.
77 * The 'info' field is filled in with the 'info' passed to addCleanUp.
78 */
79 typedef void (*PFCleanUpFunc)(const GrContext* context, void* info);
80
81 /**
82 * Add a function to be called from within GrContext's destructor.
83 * This gives classes a chance to free resources held on a per context basis.
84 * The 'info' parameter will be stored and passed to the callback function.
85 */
86 void addCleanUp(PFCleanUpFunc cleanUp, void* info) {
87 CleanUpData* entry = fCleanUpData.push();
88
89 entry->fFunc = cleanUp;
90 entry->fInfo = info;
91 }
92
93 /**
bsalomon2354f842014-07-28 13:48:36 -070094 * Abandons all GPU resources and assumes the underlying backend 3D API
95 * context is not longer usable. Call this if you have lost the associated
96 * GPU context, and thus internal texture, buffer, etc. references/IDs are
97 * now invalid. Should be called even when GrContext is no longer going to
98 * be used for two reasons:
bsalomon@google.com8fe72472011-03-30 21:26:44 +000099 * 1) ~GrContext will not try to free the objects in the 3D API.
bsalomon2354f842014-07-28 13:48:36 -0700100 * 2) Any GrGpuResources created by this GrContext that outlive
101 * will be marked as invalid (GrGpuResource::wasDestroyed()) and
102 * when they're destroyed no 3D API calls will be made.
103 * Content drawn since the last GrContext::flush() may be lost. After this
104 * function is called the only valid action on the GrContext or
105 * GrGpuResources it created is to destroy them.
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000106 */
bsalomon2354f842014-07-28 13:48:36 -0700107 void abandonContext();
junov@google.com53a55842011-06-08 22:55:10 +0000108
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000109 ///////////////////////////////////////////////////////////////////////////
110 // Resource Cache
111
112 /**
113 * Return the current GPU resource cache limits.
114 *
115 * @param maxResources If non-null, returns maximum number of resources that
116 * can be held in the cache.
117 * @param maxResourceBytes If non-null, returns maximum number of bytes of
118 * video memory that can be held in the cache.
119 */
120 void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000121
122 /**
123 * Gets the current GPU resource cache usage.
124 *
125 * @param resourceCount If non-null, returns the number of resources that are held in the
126 * cache.
127 * @param maxResourceBytes If non-null, returns the total number of bytes of video memory held
128 * in the cache.
129 */
130 void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const;
131
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000132 /**
133 * Specify the GPU resource cache limits. If the current cache exceeds either
134 * of these, it will be purged (LRU) to keep the cache within these limits.
135 *
136 * @param maxResources The maximum number of resources that can be held in
137 * the cache.
138 * @param maxResourceBytes The maximum number of bytes of video memory
139 * that can be held in the cache.
140 */
141 void setResourceCacheLimits(int maxResources, size_t maxResourceBytes);
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000142
bsalomond309e7a2015-04-30 14:18:54 -0700143 GrTextureProvider* textureProvider() { return fTextureProvider; }
144 const GrTextureProvider* textureProvider() const { return fTextureProvider; }
145
junov@google.com53a55842011-06-08 22:55:10 +0000146 /**
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000147 * Frees GPU created by the context. Can be called to reduce GPU memory
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000148 * pressure.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000149 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000150 void freeGpuResources();
151
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000152 /**
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000153 * Purge all the unlocked resources from the cache.
154 * This entry point is mainly meant for timing texture uploads
155 * and is not defined in normal builds of Skia.
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000156 */
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000157 void purgeAllUnlockedResources();
158
bsalomon76228632015-05-29 08:02:10 -0700159 /** Access the context capabilities */
160 const GrCaps* caps() const { return fCaps; }
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000161
commit-bot@chromium.orgb471a322014-03-10 07:40:03 +0000162 /**
163 * Returns the recommended sample count for a render target when using this
164 * context.
165 *
166 * @param config the configuration of the render target.
167 * @param dpi the display density in dots per inch.
168 *
169 * @return sample count that should be perform well and have good enough
170 * rendering quality for the display. Alternatively returns 0 if
171 * MSAA is not supported or recommended to be used by default.
172 */
173 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
174
bsalomon@google.com27847de2011-02-22 20:59:41 +0000175 /**
robertphillipsea461502015-05-26 11:38:03 -0700176 * Returns a helper object to orchestrate draws.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000177 *
robertphillipsea461502015-05-26 11:38:03 -0700178 * @return a draw context
bsalomon@google.com27847de2011-02-22 20:59:41 +0000179 */
robertphillipsea461502015-05-26 11:38:03 -0700180 GrDrawContext* drawContext() {
181 return fDrawingMgr.drawContext();
joshualitt16b27892014-12-18 07:47:16 -0800182 }
bsalomon@google.com27847de2011-02-22 20:59:41 +0000183
bsalomon@google.com27847de2011-02-22 20:59:41 +0000184 ///////////////////////////////////////////////////////////////////////////
185 // Misc.
186
187 /**
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000188 * Flags that affect flush() behavior.
189 */
190 enum FlushBits {
191 /**
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000192 * A client may reach a point where it has partially rendered a frame
193 * through a GrContext that it knows the user will never see. This flag
194 * causes the flush to skip submission of deferred content to the 3D API
195 * during the flush.
196 */
197 kDiscard_FlushBit = 0x2,
198 };
199
200 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000201 * Call to ensure all drawing to the context has been issued to the
202 * underlying 3D API.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000203 * @param flagsBitfield flags that control the flushing behavior. See
204 * FlushBits.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000205 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000206 void flush(int flagsBitfield = 0);
bsalomon@google.com6f379512011-11-16 20:36:03 +0000207
robertphillipsea461502015-05-26 11:38:03 -0700208 void flushIfNecessary() {
209 if (fFlushToReduceCacheSize) {
210 this->flush();
211 }
212 }
213
bsalomon@google.com0342a852012-08-20 19:22:38 +0000214 /**
215 * These flags can be used with the read/write pixels functions below.
216 */
217 enum PixelOpsFlags {
bsalomonf80bfed2014-10-07 05:56:02 -0700218 /** The GrContext will not be flushed before the surface read or write. This means that
219 the read or write may occur before previous draws have executed. */
bsalomon@google.com0342a852012-08-20 19:22:38 +0000220 kDontFlush_PixelOpsFlag = 0x1,
bsalomonf80bfed2014-10-07 05:56:02 -0700221 /** Any surface writes should be flushed to the backend 3D API after the surface operation
222 is complete */
223 kFlushWrites_PixelOp = 0x2,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000224 /** The src for write or dst read is unpremultiplied. This is only respected if both the
225 config src and dst configs are an RGBA/BGRA 8888 format. */
bsalomonf80bfed2014-10-07 05:56:02 -0700226 kUnpremul_PixelOpsFlag = 0x4,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000227 };
228
bsalomon@google.com27847de2011-02-22 20:59:41 +0000229 /**
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000230 * Reads a rectangle of pixels from a render target.
bsalomon89c62982014-11-03 12:08:42 -0800231 * @param target the render target to read from.
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000232 * @param left left edge of the rectangle to read (inclusive)
233 * @param top top edge of the rectangle to read (inclusive)
234 * @param width width of rectangle to read in pixels.
235 * @param height height of rectangle to read in pixels.
236 * @param config the pixel config of the destination buffer
237 * @param buffer memory to read the rectangle into.
bsalomon@google.com0342a852012-08-20 19:22:38 +0000238 * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
239 * packed.
240 * @param pixelOpsFlags see PixelOpsFlags enum above.
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000241 *
bsalomon@google.com0342a852012-08-20 19:22:38 +0000242 * @return true if the read succeeded, false if not. The read can fail because of an unsupported
243 * pixel config or because no render target is currently set and NULL was passed for
244 * target.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000245 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000246 bool readRenderTargetPixels(GrRenderTarget* target,
247 int left, int top, int width, int height,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000248 GrPixelConfig config, void* buffer,
249 size_t rowBytes = 0,
250 uint32_t pixelOpsFlags = 0);
bsalomon@google.com6f379512011-11-16 20:36:03 +0000251
252 /**
bsalomon81beccc2014-10-13 12:32:55 -0700253 * Writes a rectangle of pixels to a surface.
254 * @param surface the surface to write to.
bsalomon@google.com6f379512011-11-16 20:36:03 +0000255 * @param left left edge of the rectangle to write (inclusive)
256 * @param top top edge of the rectangle to write (inclusive)
257 * @param width width of rectangle to write in pixels.
258 * @param height height of rectangle to write in pixels.
259 * @param config the pixel config of the source buffer
260 * @param buffer memory to read pixels from
bsalomon@google.com3cbaa2d2012-10-12 14:51:52 +0000261 * @param rowBytes number of bytes between consecutive rows. Zero
bsalomon@google.com6f379512011-11-16 20:36:03 +0000262 * means rows are tightly packed.
bsalomon@google.com0342a852012-08-20 19:22:38 +0000263 * @param pixelOpsFlags see PixelOpsFlags enum above.
bsalomon@google.com9c680582013-02-06 18:17:50 +0000264 * @return true if the write succeeded, false if not. The write can fail because of an
bsalomon81beccc2014-10-13 12:32:55 -0700265 * unsupported combination of surface and src configs.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000266 */
bsalomon81beccc2014-10-13 12:32:55 -0700267 bool writeSurfacePixels(GrSurface* surface,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000268 int left, int top, int width, int height,
269 GrPixelConfig config, const void* buffer,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000270 size_t rowBytes,
271 uint32_t pixelOpsFlags = 0);
272
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000273 /**
bsalomonf80bfed2014-10-07 05:56:02 -0700274 * Copies a rectangle of texels from src to dst.
scroggo@google.coma2a31922012-12-07 19:14:45 +0000275 * bounds.
bsalomonf80bfed2014-10-07 05:56:02 -0700276 * @param dst the surface to copy to.
277 * @param src the surface to copy from.
278 * @param srcRect the rectangle of the src that should be copied.
279 * @param dstPoint the translation applied when writing the srcRect's pixels to the dst.
280 * @param pixelOpsFlags see PixelOpsFlags enum above. (kUnpremul_PixelOpsFlag is not allowed).
senorblanco@chromium.orgef843cd2011-12-02 19:11:17 +0000281 */
bsalomonf80bfed2014-10-07 05:56:02 -0700282 void copySurface(GrSurface* dst,
283 GrSurface* src,
284 const SkIRect& srcRect,
285 const SkIPoint& dstPoint,
286 uint32_t pixelOpsFlags = 0);
287
288 /** Helper that copies the whole surface but fails when the two surfaces are not identically
289 sized. */
290 bool copySurface(GrSurface* dst, GrSurface* src) {
291 if (NULL == dst || NULL == src || dst->width() != src->width() ||
292 dst->height() != src->height()) {
293 return false;
294 }
295 this->copySurface(dst, src, SkIRect::MakeWH(dst->width(), dst->height()),
296 SkIPoint::Make(0,0));
297 return true;
298 }
299
300 /**
301 * After this returns any pending writes to the surface will have been issued to the backend 3D API.
302 */
303 void flushSurfaceWrites(GrSurface* surface);
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000304
305 /**
bsalomon87a94eb2014-11-03 14:28:32 -0800306 * Equivalent to flushSurfaceWrites but also performs MSAA resolve if necessary. This call is
307 * used to make the surface contents available to be read in the backend 3D API, usually for a
308 * compositing step external to Skia.
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000309 *
bsalomon87a94eb2014-11-03 14:28:32 -0800310 * It is not necessary to call this before reading the render target via Skia/GrContext.
311 * GrContext will detect when it must perform a resolve before reading pixels back from the
312 * surface or using it as a texture.
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000313 */
bsalomon87a94eb2014-11-03 14:28:32 -0800314 void prepareSurfaceForExternalRead(GrSurface*);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000315
316 /**
joshualitt0acd0d32015-05-07 08:23:19 -0700317 * An ID associated with this context, guaranteed to be unique.
318 */
319 uint32_t uniqueID() { return fUniqueID; }
320
bsalomon@google.com27847de2011-02-22 20:59:41 +0000321 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com27847de2011-02-22 20:59:41 +0000322 // Functions intended for internal use only.
323 GrGpu* getGpu() { return fGpu; }
bsalomon@google.com1f221a72011-08-23 20:54:07 +0000324 const GrGpu* getGpu() const { return fGpu; }
joshualitt7c3a2f82015-03-31 13:32:05 -0700325 GrBatchFontCache* getBatchFontCache() { return fBatchFontCache; }
robertphillips@google.come930a072014-04-03 00:34:27 +0000326 GrLayerCache* getLayerCache() { return fLayerCache.get(); }
joshualittb7133be2015-04-08 09:08:31 -0700327 GrTextBlobCache* getTextBlobCache() { return fTextBlobCache; }
robertphillipsea461502015-05-26 11:38:03 -0700328 bool abandoned() const { return fDrawingMgr.abandoned(); }
bsalomond309e7a2015-04-30 14:18:54 -0700329 GrResourceProvider* resourceProvider() { return fResourceProvider; }
330 const GrResourceProvider* resourceProvider() const { return fResourceProvider; }
bsalomon0ea80f42015-02-11 10:49:59 -0800331 GrResourceCache* getResourceCache() { return fResourceCache; }
bsalomon@google.com9923c2b2012-06-06 18:21:18 +0000332
commit-bot@chromium.org78a10782013-08-21 19:27:48 +0000333 // Called by tests that draw directly to the context via GrDrawTarget
334 void getTestTarget(GrTestTarget*);
335
egdanielbbcb38d2014-06-19 10:19:29 -0700336 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
337 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
338
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000339 GrPathRenderer* getPathRenderer(
joshualitt9853cce2014-11-17 14:22:48 -0800340 const GrDrawTarget* target,
egdaniel8dd688b2015-01-22 10:16:09 -0800341 const GrPipelineBuilder*,
joshualitt8059eb92014-12-29 15:10:07 -0800342 const SkMatrix& viewMatrix,
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000343 const SkPath& path,
kkinnunen18996512015-04-26 23:18:49 -0700344 const GrStrokeInfo& stroke,
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000345 bool allowSW,
robertphillips@google.come79f3202014-02-11 16:30:21 +0000346 GrPathRendererChain::DrawType drawType = GrPathRendererChain::kColor_DrawType,
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000347 GrPathRendererChain::StencilSupport* stencilSupport = NULL);
robertphillips@google.com2c756812012-05-22 20:28:23 +0000348
mtkleinb9eb4ac2015-02-02 18:26:03 -0800349 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */
350 void dumpCacheStats(SkString*) const;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000351 void printCacheStats() const;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000352
mtkleinb9eb4ac2015-02-02 18:26:03 -0800353 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */
354 void dumpGpuStats(SkString*) const;
355 void printGpuStats() const;
robertphillips754f4e92014-09-18 13:52:08 -0700356
bsalomon@google.com27847de2011-02-22 20:59:41 +0000357private:
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000358 GrGpu* fGpu;
bsalomon76228632015-05-29 08:02:10 -0700359 const GrCaps* fCaps;
bsalomon0ea80f42015-02-11 10:49:59 -0800360 GrResourceCache* fResourceCache;
bsalomond309e7a2015-04-30 14:18:54 -0700361 // this union exists because the inheritance of GrTextureProvider->GrResourceProvider
362 // is in a private header.
363 union {
364 GrResourceProvider* fResourceProvider;
365 GrTextureProvider* fTextureProvider;
366 };
367
joshualitt7c3a2f82015-03-31 13:32:05 -0700368 GrBatchFontCache* fBatchFontCache;
robertphillips@google.come930a072014-04-03 00:34:27 +0000369 SkAutoTDelete<GrLayerCache> fLayerCache;
joshualittb7133be2015-04-08 09:08:31 -0700370 SkAutoTDelete<GrTextBlobCache> fTextBlobCache;
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000371
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000372 GrPathRendererChain* fPathRendererChain;
373 GrSoftwarePathRenderer* fSoftwarePathRenderer;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000374
bsalomonf21dab92014-11-13 13:33:28 -0800375 // Set by OverbudgetCB() to request that GrContext flush before exiting a draw.
376 bool fFlushToReduceCacheSize;
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000377 bool fDidTestPMConversions;
378 int fPMToUPMConversion;
379 int fUPMToPMConversion;
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000380
robertphillips@google.comcdb426d2012-09-24 19:33:59 +0000381 struct CleanUpData {
382 PFCleanUpFunc fFunc;
383 void* fInfo;
384 };
385
robertphillips@google.com44a91dc2013-07-25 15:32:06 +0000386 SkTDArray<CleanUpData> fCleanUpData;
387
joshualitt0acd0d32015-05-07 08:23:19 -0700388 const uint32_t fUniqueID;
krajcevski9c6d4d72014-08-12 07:26:25 -0700389
bsalomon682c2692015-05-22 14:01:46 -0700390 GrContext(); // init must be called after the constructor.
391 bool init(GrBackend, GrBackendContext, const GrContextOptions& options);
robertphillipsea461502015-05-26 11:38:03 -0700392
393 // Currently the DrawingMgr just wraps the single GrDrawTarget in a single
394 // GrDrawContext and hands it out. In the future this class will allocate
395 // a new GrDrawContext for each GrRenderTarget/GrDrawTarget and manage
396 // the DAG.
397 class DrawingMgr {
398 public:
399 DrawingMgr()
400 : fDrawTarget(NULL)
401 , fDrawContext(NULL) {
402 }
403
404 ~DrawingMgr();
405
406 void init(GrContext* context);
407
408 void abandon();
409 bool abandoned() const { return NULL == fDrawTarget; }
410
411 void purgeResources();
412 void reset();
413 void flush();
414
415 // Callers should take a ref if they rely on the GrDrawContext sticking around.
416 // NULL will be returned if the context has been abandoned.
417 GrDrawContext* drawContext();
418
419 private:
420 friend class GrContext; // for access to fDrawTarget for testing
421
422 GrDrawTarget* fDrawTarget;
423
424 GrDrawContext* fDrawContext;
425 };
426
427 DrawingMgr fDrawingMgr;
428
bsalomon33435572014-11-05 14:47:41 -0800429 void initMockContext();
430 void initCommon();
bsalomon@google.com205d4602011-04-25 12:43:45 +0000431
skia.committer@gmail.comcdcb2ce2013-01-29 07:05:52 +0000432 /**
joshualitt6e8cd962015-03-20 10:30:14 -0700433 * Creates a new text rendering context that is optimal for the
434 * render target and the context. Caller assumes the ownership
435 * of the returned object. The returned object must be deleted
436 * before the context is destroyed.
robertphillipsccb1b572015-05-27 11:02:55 -0700437 * TODO bury this behind context!
joshualitt6e8cd962015-03-20 10:30:14 -0700438 */
439 GrTextContext* createTextContext(GrRenderTarget*,
joshualitt6e8cd962015-03-20 10:30:14 -0700440 const SkDeviceProperties&,
441 bool enableDistanceFieldFonts);
442
443
444 /**
bsalomon@google.comadc65362013-01-28 14:26:09 +0000445 * These functions create premul <-> unpremul effects if it is possible to generate a pair
446 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. Otherwise, they
447 * return NULL.
448 */
joshualittb0a8a372014-09-23 09:50:21 -0700449 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, const SkMatrix&);
450 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, const SkMatrix&);
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000451
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000452 /**
453 * This callback allows the resource cache to callback into the GrContext
bsalomon71cb0c22014-11-14 12:10:14 -0800454 * when the cache is still over budget after a purge.
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000455 */
bsalomon71cb0c22014-11-14 12:10:14 -0800456 static void OverBudgetCB(void* data);
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000457
joshualitt0db6dfa2015-04-10 07:01:30 -0700458 /**
459 * A callback similar to the above for use by the TextBlobCache
460 * TODO move textblob draw calls below context so we can use the call above.
461 */
462 static void TextBlobCacheOverBudgetCB(void* data);
463
joshualitt6e8cd962015-03-20 10:30:14 -0700464 // TODO see note on createTextContext
465 friend class SkGpuDevice;
466
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000467 typedef SkRefCnt INHERITED;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000468};
469
bsalomon@google.com27847de2011-02-22 20:59:41 +0000470#endif