blob: 250fe45e2f26521050e5cf11c94e1405d8ca14ee [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"
bsalomon@google.com288d9542012-10-17 12:53:54 +000016#include "GrTexture.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;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000023class GrDrawTarget;
joshualittb0a8a372014-09-23 09:50:21 -070024class GrFragmentProcessor;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000025class GrGpu;
egdanielbbcb38d2014-06-19 10:19:29 -070026class GrGpuTraceMarker;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000027class GrIndexBuffer;
bsalomon@google.com27847de2011-02-22 20:59:41 +000028class GrIndexBufferAllocPool;
robertphillips@google.come930a072014-04-03 00:34:27 +000029class GrLayerCache;
commit-bot@chromium.org81312832013-03-22 18:34:09 +000030class GrOvalRenderer;
commit-bot@chromium.org5c8ee252013-11-01 15:23:44 +000031class GrPath;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000032class GrPathRenderer;
egdaniel8dd688b2015-01-22 10:16:09 -080033class GrPipelineBuilder;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000034class GrResourceEntry;
bsalomon0ea80f42015-02-11 10:49:59 -080035class GrResourceCache;
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000036class GrTestTarget;
joshualittb7133be2015-04-08 09:08:31 -070037class GrTextBlobCache;
kkinnunenc6cb56f2014-06-24 00:12:27 -070038class GrTextContext;
bsalomon@google.com288d9542012-10-17 12:53:54 +000039class GrTextureParams;
bsalomon@google.com583a1e32011-08-17 13:42:46 +000040class GrVertexBuffer;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000041class GrVertexBufferAllocPool;
egdanield58a0ba2014-06-11 10:30:05 -070042class GrStrokeInfo;
robertphillips@google.com72176b22012-05-23 13:19:12 +000043class GrSoftwarePathRenderer;
joshualitt6e8cd962015-03-20 10:30:14 -070044class SkGpuDevice;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000045
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000046class SK_API GrContext : public SkRefCnt {
bsalomon@google.com27847de2011-02-22 20:59:41 +000047public:
reed@google.comfa35e3d2012-06-26 20:16:17 +000048 SK_DECLARE_INST_COUNT(GrContext)
49
krajcevski9c6d4d72014-08-12 07:26:25 -070050 struct Options {
51 Options() : fDrawPathToCompressedTexture(false) { }
52
53 // EXPERIMENTAL
54 // May be removed in the future, or may become standard depending
55 // on the outcomes of a variety of internal tests.
56 bool fDrawPathToCompressedTexture;
57 };
58
bsalomon@google.com27847de2011-02-22 20:59:41 +000059 /**
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000060 * Creates a GrContext for a backend context.
bsalomon@google.com27847de2011-02-22 20:59:41 +000061 */
krajcevski9c6d4d72014-08-12 07:26:25 -070062 static GrContext* Create(GrBackend, GrBackendContext, const Options* opts = NULL);
bsalomon@google.com27847de2011-02-22 20:59:41 +000063
bsalomon33435572014-11-05 14:47:41 -080064 /**
65 * Only defined in test apps.
66 */
67 static GrContext* CreateMockContext();
68
bsalomon@google.com27847de2011-02-22 20:59:41 +000069 virtual ~GrContext();
70
71 /**
72 * The GrContext normally assumes that no outsider is setting state
73 * within the underlying 3D API's context/device/whatever. This call informs
74 * the context that the state was modified and it should resend. Shouldn't
75 * be called frequently for good performance.
bsalomon@google.com0a208a12013-06-28 18:57:35 +000076 * The flag bits, state, is dpendent on which backend is used by the
77 * context, either GL or D3D (possible in future).
bsalomon@google.com27847de2011-02-22 20:59:41 +000078 */
bsalomon@google.com0a208a12013-06-28 18:57:35 +000079 void resetContext(uint32_t state = kAll_GrBackendState);
bsalomon@google.com27847de2011-02-22 20:59:41 +000080
bsalomon@google.com8fe72472011-03-30 21:26:44 +000081 /**
robertphillips@google.comcdb426d2012-09-24 19:33:59 +000082 * Callback function to allow classes to cleanup on GrContext destruction.
83 * The 'info' field is filled in with the 'info' passed to addCleanUp.
84 */
85 typedef void (*PFCleanUpFunc)(const GrContext* context, void* info);
86
87 /**
88 * Add a function to be called from within GrContext's destructor.
89 * This gives classes a chance to free resources held on a per context basis.
90 * The 'info' parameter will be stored and passed to the callback function.
91 */
92 void addCleanUp(PFCleanUpFunc cleanUp, void* info) {
93 CleanUpData* entry = fCleanUpData.push();
94
95 entry->fFunc = cleanUp;
96 entry->fInfo = info;
97 }
98
99 /**
bsalomon2354f842014-07-28 13:48:36 -0700100 * Abandons all GPU resources and assumes the underlying backend 3D API
101 * context is not longer usable. Call this if you have lost the associated
102 * GPU context, and thus internal texture, buffer, etc. references/IDs are
103 * now invalid. Should be called even when GrContext is no longer going to
104 * be used for two reasons:
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000105 * 1) ~GrContext will not try to free the objects in the 3D API.
bsalomon2354f842014-07-28 13:48:36 -0700106 * 2) Any GrGpuResources created by this GrContext that outlive
107 * will be marked as invalid (GrGpuResource::wasDestroyed()) and
108 * when they're destroyed no 3D API calls will be made.
109 * Content drawn since the last GrContext::flush() may be lost. After this
110 * function is called the only valid action on the GrContext or
111 * GrGpuResources it created is to destroy them.
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000112 */
bsalomon2354f842014-07-28 13:48:36 -0700113 void abandonContext();
114 void contextDestroyed() { this->abandonContext(); } // legacy alias
junov@google.com53a55842011-06-08 22:55:10 +0000115
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 * This method should be called whenever a GrResource is unreffed or
158 * switched from exclusive to non-exclusive. This
159 * gives the resource cache a chance to discard unneeded resources.
160 * Note: this entry point will be removed once totally ref-driven
161 * cache maintenance is implemented.
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000162 */
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000163 void purgeCache();
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000164
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000165 /**
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000166 * Purge all the unlocked resources from the cache.
167 * This entry point is mainly meant for timing texture uploads
168 * and is not defined in normal builds of Skia.
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000169 */
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000170 void purgeAllUnlockedResources();
171
bsalomonf99e9612015-02-19 08:24:16 -0800172 /**
173 * Sets a unique key on the resource. Upon key collision this resource takes the place of the
174 * previous resource that had the key.
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000175 */
bsalomonf99e9612015-02-19 08:24:16 -0800176 void addResourceToCache(const GrUniqueKey&, GrGpuResource*);
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000177
178 /**
179 * Finds a resource in the cache, based on the specified key. This is intended for use in
180 * conjunction with addResourceToCache(). The return value will be NULL if not found. The
181 * caller must balance with a call to unref().
182 */
bsalomon8718aaf2015-02-19 07:24:21 -0800183 GrGpuResource* findAndRefCachedResource(const GrUniqueKey&);
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000184
bsalomon37f9a262015-02-02 13:00:10 -0800185 /** Helper for casting resource to a texture. Caller must be sure that the resource cached
186 with the key is either NULL or a texture and not another resource type. */
bsalomon8718aaf2015-02-19 07:24:21 -0800187 GrTexture* findAndRefCachedTexture(const GrUniqueKey& key) {
bsalomon37f9a262015-02-02 13:00:10 -0800188 GrGpuResource* resource = this->findAndRefCachedResource(key);
189 if (resource) {
190 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
191 SkASSERT(texture);
192 return texture;
193 }
194 return NULL;
195 }
196
197 /**
198 * Determines whether a resource is in the cache. If the resource is found it
199 * will not be locked or returned. This call does not affect the priority of
200 * the resource for deletion.
201 */
bsalomon8718aaf2015-02-19 07:24:21 -0800202 bool isResourceInCache(const GrUniqueKey& key) const;
bsalomon37f9a262015-02-02 13:00:10 -0800203
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000204 ///////////////////////////////////////////////////////////////////////////
205 // Textures
bsalomon@google.com27847de2011-02-22 20:59:41 +0000206
207 /**
bsalomon37f9a262015-02-02 13:00:10 -0800208 * Creates a new texture in the resource cache and returns it. The caller owns a
bsalomon@google.com95ed55a2013-01-24 14:46:47 +0000209 * ref on the returned texture which must be balanced by a call to unref.
bsalomon@google.com1fadb202011-12-12 16:10:08 +0000210 *
bsalomon@google.com1fadb202011-12-12 16:10:08 +0000211 * @param desc Description of the texture properties.
bsalomond0423582015-02-06 08:49:24 -0800212 * @param budgeted Does the texture count against the resource cache budget?
213 * @param srcData Pointer to the pixel values (optional).
bsalomon@google.com1fadb202011-12-12 16:10:08 +0000214 * @param rowBytes The number of bytes between rows of the texture. Zero
krajcevski9c0e6292014-06-02 07:38:14 -0700215 * implies tightly packed rows. For compressed pixel configs, this
216 * field is ignored.
bsalomon@google.com1fadb202011-12-12 16:10:08 +0000217 */
bsalomond0423582015-02-06 08:49:24 -0800218 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData,
219 size_t rowBytes);
bsalomon37f9a262015-02-02 13:00:10 -0800220
bsalomond0423582015-02-06 08:49:24 -0800221 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted) {
222 return this->createTexture(desc, budgeted, NULL, 0);
bsalomon37f9a262015-02-02 13:00:10 -0800223 }
224
bsalomon@google.com1fadb202011-12-12 16:10:08 +0000225 /**
bsalomond0423582015-02-06 08:49:24 -0800226 * DEPRECATED: use createTexture().
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000227 */
bsalomond0423582015-02-06 08:49:24 -0800228 GrTexture* createUncachedTexture(const GrSurfaceDesc& desc, void* srcData, size_t rowBytes) {
229 return this->createTexture(desc, false, srcData, rowBytes);
230 }
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000231
232 /**
233 * Enum that determines how closely a returned scratch texture must match
bsalomond0423582015-02-06 08:49:24 -0800234 * a provided GrSurfaceDesc. TODO: Remove this. createTexture() should be used
235 * for exact match and refScratchTexture() should be replaced with createApproxTexture().
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000236 */
237 enum ScratchTexMatch {
238 /**
239 * Finds a texture that exactly matches the descriptor.
240 */
241 kExact_ScratchTexMatch,
242 /**
243 * Finds a texture that approximately matches the descriptor. Will be
244 * at least as large in width and height as desc specifies. If desc
245 * specifies that texture is a render target then result will be a
246 * render target. If desc specifies a render target and doesn't set the
247 * no stencil flag then result will have a stencil. Format and aa level
248 * will always match.
249 */
250 kApprox_ScratchTexMatch
251 };
bsalomon@google.com27847de2011-02-22 20:59:41 +0000252
253 /**
bsalomone3059732014-10-14 11:47:22 -0700254 * Returns a texture matching the desc. It's contents are unknown. The caller
bsalomon@google.com95ed55a2013-01-24 14:46:47 +0000255 * owns a ref on the returned texture and must balance with a call to unref.
bsalomone3059732014-10-14 11:47:22 -0700256 * It is guaranteed that the same texture will not be returned in subsequent
257 * calls until all refs to the texture are dropped.
bsalomon@google.coma39f4042011-04-26 13:18:16 +0000258 *
bsalomone3059732014-10-14 11:47:22 -0700259 * Textures created by createTexture() hide the complications of
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000260 * tiling non-power-of-two textures on APIs that don't support this (e.g.
bsalomone3059732014-10-14 11:47:22 -0700261 * unextended GLES2). NPOT scratch textures are not tilable on such APIs.
bsalomonbcf0a522014-10-08 08:40:09 -0700262 *
263 * internalFlag is a temporary workaround until changes in the internal
264 * architecture are complete. Use the default value.
bsalomond0423582015-02-06 08:49:24 -0800265 *
266 * TODO: Once internal flag can be removed, this should be replaced with
267 * createApproxTexture() and exact textures should be created with
268 * createTexture().
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000269 */
bsalomonf2703d82014-10-28 14:33:06 -0700270 GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match,
bsalomone3059732014-10-14 11:47:22 -0700271 bool internalFlag = false);
robertphillipsdbe60742014-09-30 06:54:17 -0700272
273 /**
bsalomond2a6f4e2015-02-04 10:55:54 -0800274 * Can the provided configuration act as a texture?
bsalomon@google.com27847de2011-02-22 20:59:41 +0000275 */
bsalomond2a6f4e2015-02-04 10:55:54 -0800276 bool isConfigTexturable(GrPixelConfig) const;
277
278 /**
279 * Can non-power-of-two textures be used with tile modes other than clamp?
280 */
281 bool npotTextureTileSupport() const;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000282
283 /**
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000284 * Return the max width or height of a texture supported by the current GPU.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000285 */
bsalomon@google.com91958362011-06-13 17:58:13 +0000286 int getMaxTextureSize() const;
287
robertphillips@google.com44a91dc2013-07-25 15:32:06 +0000288 /**
skia.committer@gmail.com956b3102013-07-26 07:00:58 +0000289 * Temporarily override the true max texture size. Note: an override
robertphillips@google.com44a91dc2013-07-25 15:32:06 +0000290 * larger then the true max texture size will have no effect.
291 * This entry point is mainly meant for testing texture size dependent
292 * features and is only available if defined outside of Skia (see
293 * bleed GM.
294 */
295 void setMaxTextureSizeOverride(int maxTextureSizeOverride);
296
robertphillips@google.com99a5ac02012-04-10 19:26:38 +0000297 /**
298 * Can the provided configuration act as a color render target?
299 */
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000300 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const;
robertphillips@google.com99a5ac02012-04-10 19:26:38 +0000301
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000302 /**
303 * Return the max width or height of a render target supported by the
304 * current GPU.
305 */
306 int getMaxRenderTargetSize() const;
307
308 /**
309 * Returns the max sample count for a render target. It will be 0 if MSAA
310 * is not supported.
311 */
312 int getMaxSampleCount() const;
313
commit-bot@chromium.orgb471a322014-03-10 07:40:03 +0000314 /**
315 * Returns the recommended sample count for a render target when using this
316 * context.
317 *
318 * @param config the configuration of the render target.
319 * @param dpi the display density in dots per inch.
320 *
321 * @return sample count that should be perform well and have good enough
322 * rendering quality for the display. Alternatively returns 0 if
323 * MSAA is not supported or recommended to be used by default.
324 */
325 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
326
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000327 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000328 // Backend Surfaces
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000329
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000330 /**
bsalomon@google.come269f212011-11-07 13:29:52 +0000331 * Wraps an existing texture with a GrTexture object.
332 *
333 * OpenGL: if the object is a texture Gr may change its GL texture params
334 * when it is drawn.
335 *
336 * @param desc description of the object to create.
337 *
338 * @return GrTexture object or NULL on failure.
339 */
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000340 GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc);
bsalomon@google.come269f212011-11-07 13:29:52 +0000341
342 /**
343 * Wraps an existing render target with a GrRenderTarget object. It is
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000344 * similar to wrapBackendTexture but can be used to draw into surfaces
bsalomon@google.come269f212011-11-07 13:29:52 +0000345 * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that
346 * the client will resolve to a texture).
347 *
348 * @param desc description of the object to create.
349 *
350 * @return GrTexture object or NULL on failure.
351 */
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000352 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc);
bsalomon@google.come269f212011-11-07 13:29:52 +0000353
bsalomon@google.com27847de2011-02-22 20:59:41 +0000354 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com27847de2011-02-22 20:59:41 +0000355 // Draws
356
357 /**
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000358 * Clear the entire or rect of the render target, ignoring any clips.
359 * @param rect the rect to clear or the whole thing if rect is NULL.
360 * @param color the color to clear to.
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000361 * @param canIgnoreRect allows partial clears to be converted to whole
362 * clears on platforms for which that is cheap
bsalomon89c62982014-11-03 12:08:42 -0800363 * @param target The render target to clear.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000364 */
bsalomon89c62982014-11-03 12:08:42 -0800365 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, GrRenderTarget* target);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000366
367 /**
368 * Draw everywhere (respecting the clip) with the paint.
369 */
joshualitt570d2f82015-02-25 13:19:48 -0800370 void drawPaint(GrRenderTarget*, const GrClip&, const GrPaint&, const SkMatrix& viewMatrix);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000371
372 /**
373 * Draw the rect using a paint.
374 * @param paint describes how to color pixels.
joshualitt5531d512014-12-17 15:50:11 -0800375 * @param viewMatrix transformation matrix
egdanield58a0ba2014-06-11 10:30:05 -0700376 * @param strokeInfo the stroke information (width, join, cap), and.
377 * the dash information (intervals, count, phase).
378 * If strokeInfo == NULL, then the rect is filled.
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +0000379 * Otherwise, if stroke width == 0, then the stroke
skia.committer@gmail.com26144182013-11-07 07:02:19 +0000380 * is always a single pixel thick, else the rect is
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +0000381 * mitered/beveled stroked based on stroke width.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000382 * The rects coords are used to access the paint (through texture matrix)
383 */
joshualitt25d9c152015-02-18 12:29:52 -0800384 void drawRect(GrRenderTarget*,
joshualitt570d2f82015-02-25 13:19:48 -0800385 const GrClip&,
joshualitt25d9c152015-02-18 12:29:52 -0800386 const GrPaint& paint,
joshualitt5531d512014-12-17 15:50:11 -0800387 const SkMatrix& viewMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000388 const SkRect&,
bsalomon01c8da12014-08-04 09:21:30 -0700389 const GrStrokeInfo* strokeInfo = NULL);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000390
391 /**
joshualitt16b27892014-12-18 07:47:16 -0800392 * Maps a rectangle of shader coordinates to a rectangle and draws that rectangle
bsalomon@google.com27847de2011-02-22 20:59:41 +0000393 *
bsalomon@google.comc7818882013-03-20 19:19:53 +0000394 * @param paint describes how to color pixels.
joshualitt16b27892014-12-18 07:47:16 -0800395 * @param viewMatrix transformation matrix which applies to rectToDraw
396 * @param rectToDraw the rectangle to draw
397 * @param localRect the rectangle of shader coordinates applied to rectToDraw
398 * @param localMatrix an optional matrix to transform the shader coordinates before applying
399 * to rectToDraw
bsalomon@google.com27847de2011-02-22 20:59:41 +0000400 */
joshualitt25d9c152015-02-18 12:29:52 -0800401 void drawNonAARectToRect(GrRenderTarget*,
joshualitt570d2f82015-02-25 13:19:48 -0800402 const GrClip&,
joshualitt25d9c152015-02-18 12:29:52 -0800403 const GrPaint& paint,
joshualitt16b27892014-12-18 07:47:16 -0800404 const SkMatrix& viewMatrix,
405 const SkRect& rectToDraw,
406 const SkRect& localRect,
407 const SkMatrix* localMatrix = NULL);
408
409 /**
410 * Draws a non-AA rect with paint and a localMatrix
411 */
joshualitt25d9c152015-02-18 12:29:52 -0800412 void drawNonAARectWithLocalMatrix(GrRenderTarget* rt,
joshualitt570d2f82015-02-25 13:19:48 -0800413 const GrClip& clip,
joshualitt25d9c152015-02-18 12:29:52 -0800414 const GrPaint& paint,
joshualitt16b27892014-12-18 07:47:16 -0800415 const SkMatrix& viewMatrix,
416 const SkRect& rect,
417 const SkMatrix& localMatrix) {
joshualitt570d2f82015-02-25 13:19:48 -0800418 this->drawNonAARectToRect(rt, clip, paint, viewMatrix, rect, rect, &localMatrix);
joshualitt16b27892014-12-18 07:47:16 -0800419 }
bsalomon@google.com27847de2011-02-22 20:59:41 +0000420
421 /**
commit-bot@chromium.orgf2bfd542013-04-25 15:27:00 +0000422 * Draw a roundrect using a paint.
423 *
424 * @param paint describes how to color pixels.
joshualitt5531d512014-12-17 15:50:11 -0800425 * @param viewMatrix transformation matrix
commit-bot@chromium.orgf2bfd542013-04-25 15:27:00 +0000426 * @param rrect the roundrect to draw
egdanield58a0ba2014-06-11 10:30:05 -0700427 * @param strokeInfo the stroke information (width, join, cap) and
428 * the dash information (intervals, count, phase).
commit-bot@chromium.orgf2bfd542013-04-25 15:27:00 +0000429 */
joshualitt25d9c152015-02-18 12:29:52 -0800430 void drawRRect(GrRenderTarget*,
joshualitt570d2f82015-02-25 13:19:48 -0800431 const GrClip&,
joshualitt25d9c152015-02-18 12:29:52 -0800432 const GrPaint&,
433 const SkMatrix& viewMatrix,
434 const SkRRect& rrect,
joshualitt5531d512014-12-17 15:50:11 -0800435 const GrStrokeInfo&);
commit-bot@chromium.org0a09d712014-04-09 21:26:11 +0000436
437 /**
438 * Shortcut for drawing an SkPath consisting of nested rrects using a paint.
439 * Does not support stroking. The result is undefined if outer does not contain
440 * inner.
441 *
442 * @param paint describes how to color pixels.
joshualitt5531d512014-12-17 15:50:11 -0800443 * @param viewMatrix transformation matrix
commit-bot@chromium.org0a09d712014-04-09 21:26:11 +0000444 * @param outer the outer roundrect
445 * @param inner the inner roundrect
446 */
joshualitt25d9c152015-02-18 12:29:52 -0800447 void drawDRRect(GrRenderTarget*,
joshualitt570d2f82015-02-25 13:19:48 -0800448 const GrClip&,
joshualitt25d9c152015-02-18 12:29:52 -0800449 const GrPaint&,
450 const SkMatrix& viewMatrix,
451 const SkRRect& outer,
joshualitt5531d512014-12-17 15:50:11 -0800452 const SkRRect& inner);
commit-bot@chromium.org0a09d712014-04-09 21:26:11 +0000453
commit-bot@chromium.orgf2bfd542013-04-25 15:27:00 +0000454
455 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000456 * Draws a path.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000457 *
458 * @param paint describes how to color pixels.
joshualitt5531d512014-12-17 15:50:11 -0800459 * @param viewMatrix transformation matrix
reed@google.com07f3ee12011-05-16 17:21:57 +0000460 * @param path the path to draw
egdanield58a0ba2014-06-11 10:30:05 -0700461 * @param strokeInfo the stroke information (width, join, cap) and
462 * the dash information (intervals, count, phase).
bsalomon@google.com27847de2011-02-22 20:59:41 +0000463 */
joshualitt25d9c152015-02-18 12:29:52 -0800464 void drawPath(GrRenderTarget*,
joshualitt570d2f82015-02-25 13:19:48 -0800465 const GrClip&,
joshualitt25d9c152015-02-18 12:29:52 -0800466 const GrPaint&,
467 const SkMatrix& viewMatrix,
468 const SkPath&,
469 const GrStrokeInfo&);
reed@google.com07f3ee12011-05-16 17:21:57 +0000470
bsalomon@google.com27847de2011-02-22 20:59:41 +0000471 /**
472 * Draws vertices with a paint.
473 *
474 * @param paint describes how to color pixels.
joshualitt5531d512014-12-17 15:50:11 -0800475 * @param viewMatrix transformation matrix
bsalomon@google.com27847de2011-02-22 20:59:41 +0000476 * @param primitiveType primitives type to draw.
477 * @param vertexCount number of vertices.
478 * @param positions array of vertex positions, required.
479 * @param texCoords optional array of texture coordinates used
480 * to access the paint.
481 * @param colors optional array of per-vertex colors, supercedes
482 * the paint's color field.
483 * @param indices optional array of indices. If NULL vertices
484 * are drawn non-indexed.
485 * @param indexCount if indices is non-null then this is the
486 * number of indices.
487 */
joshualitt25d9c152015-02-18 12:29:52 -0800488 void drawVertices(GrRenderTarget*,
joshualitt570d2f82015-02-25 13:19:48 -0800489 const GrClip&,
joshualitt25d9c152015-02-18 12:29:52 -0800490 const GrPaint& paint,
joshualitt5531d512014-12-17 15:50:11 -0800491 const SkMatrix& viewMatrix,
bsalomon@google.com27847de2011-02-22 20:59:41 +0000492 GrPrimitiveType primitiveType,
493 int vertexCount,
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000494 const SkPoint positions[],
495 const SkPoint texs[],
bsalomon@google.com27847de2011-02-22 20:59:41 +0000496 const GrColor colors[],
497 const uint16_t indices[],
498 int indexCount);
499
bsalomon@google.com93c96602012-04-27 13:05:21 +0000500 /**
501 * Draws an oval.
502 *
503 * @param paint describes how to color pixels.
joshualitt5531d512014-12-17 15:50:11 -0800504 * @param viewMatrix transformation matrix
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000505 * @param oval the bounding rect of the oval.
egdanield58a0ba2014-06-11 10:30:05 -0700506 * @param strokeInfo the stroke information (width, join, cap) and
507 * the dash information (intervals, count, phase).
bsalomon@google.com93c96602012-04-27 13:05:21 +0000508 */
joshualitt25d9c152015-02-18 12:29:52 -0800509 void drawOval(GrRenderTarget*,
joshualitt570d2f82015-02-25 13:19:48 -0800510 const GrClip&,
joshualitt25d9c152015-02-18 12:29:52 -0800511 const GrPaint& paint,
joshualitt5531d512014-12-17 15:50:11 -0800512 const SkMatrix& viewMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000513 const SkRect& oval,
egdanield58a0ba2014-06-11 10:30:05 -0700514 const GrStrokeInfo& strokeInfo);
bsalomon@google.com93c96602012-04-27 13:05:21 +0000515
bsalomon@google.com27847de2011-02-22 20:59:41 +0000516 ///////////////////////////////////////////////////////////////////////////
517 // Misc.
518
519 /**
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000520 * Flags that affect flush() behavior.
521 */
522 enum FlushBits {
523 /**
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000524 * A client may reach a point where it has partially rendered a frame
525 * through a GrContext that it knows the user will never see. This flag
526 * causes the flush to skip submission of deferred content to the 3D API
527 * during the flush.
528 */
529 kDiscard_FlushBit = 0x2,
530 };
531
532 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000533 * Call to ensure all drawing to the context has been issued to the
534 * underlying 3D API.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000535 * @param flagsBitfield flags that control the flushing behavior. See
536 * FlushBits.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000537 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000538 void flush(int flagsBitfield = 0);
bsalomon@google.com6f379512011-11-16 20:36:03 +0000539
bsalomon@google.com0342a852012-08-20 19:22:38 +0000540 /**
541 * These flags can be used with the read/write pixels functions below.
542 */
543 enum PixelOpsFlags {
bsalomonf80bfed2014-10-07 05:56:02 -0700544 /** The GrContext will not be flushed before the surface read or write. This means that
545 the read or write may occur before previous draws have executed. */
bsalomon@google.com0342a852012-08-20 19:22:38 +0000546 kDontFlush_PixelOpsFlag = 0x1,
bsalomonf80bfed2014-10-07 05:56:02 -0700547 /** Any surface writes should be flushed to the backend 3D API after the surface operation
548 is complete */
549 kFlushWrites_PixelOp = 0x2,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000550 /** The src for write or dst read is unpremultiplied. This is only respected if both the
551 config src and dst configs are an RGBA/BGRA 8888 format. */
bsalomonf80bfed2014-10-07 05:56:02 -0700552 kUnpremul_PixelOpsFlag = 0x4,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000553 };
554
bsalomon@google.com27847de2011-02-22 20:59:41 +0000555 /**
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000556 * Reads a rectangle of pixels from a render target.
bsalomon89c62982014-11-03 12:08:42 -0800557 * @param target the render target to read from.
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000558 * @param left left edge of the rectangle to read (inclusive)
559 * @param top top edge of the rectangle to read (inclusive)
560 * @param width width of rectangle to read in pixels.
561 * @param height height of rectangle to read in pixels.
562 * @param config the pixel config of the destination buffer
563 * @param buffer memory to read the rectangle into.
bsalomon@google.com0342a852012-08-20 19:22:38 +0000564 * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
565 * packed.
566 * @param pixelOpsFlags see PixelOpsFlags enum above.
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000567 *
bsalomon@google.com0342a852012-08-20 19:22:38 +0000568 * @return true if the read succeeded, false if not. The read can fail because of an unsupported
569 * pixel config or because no render target is currently set and NULL was passed for
570 * target.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000571 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000572 bool readRenderTargetPixels(GrRenderTarget* target,
573 int left, int top, int width, int height,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000574 GrPixelConfig config, void* buffer,
575 size_t rowBytes = 0,
576 uint32_t pixelOpsFlags = 0);
bsalomon@google.com6f379512011-11-16 20:36:03 +0000577
578 /**
bsalomon81beccc2014-10-13 12:32:55 -0700579 * Writes a rectangle of pixels to a surface.
580 * @param surface the surface to write to.
bsalomon@google.com6f379512011-11-16 20:36:03 +0000581 * @param left left edge of the rectangle to write (inclusive)
582 * @param top top edge of the rectangle to write (inclusive)
583 * @param width width of rectangle to write in pixels.
584 * @param height height of rectangle to write in pixels.
585 * @param config the pixel config of the source buffer
586 * @param buffer memory to read pixels from
bsalomon@google.com3cbaa2d2012-10-12 14:51:52 +0000587 * @param rowBytes number of bytes between consecutive rows. Zero
bsalomon@google.com6f379512011-11-16 20:36:03 +0000588 * means rows are tightly packed.
bsalomon@google.com0342a852012-08-20 19:22:38 +0000589 * @param pixelOpsFlags see PixelOpsFlags enum above.
bsalomon@google.com9c680582013-02-06 18:17:50 +0000590 * @return true if the write succeeded, false if not. The write can fail because of an
bsalomon81beccc2014-10-13 12:32:55 -0700591 * unsupported combination of surface and src configs.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000592 */
bsalomon81beccc2014-10-13 12:32:55 -0700593 bool writeSurfacePixels(GrSurface* surface,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000594 int left, int top, int width, int height,
595 GrPixelConfig config, const void* buffer,
bsalomon@google.com0342a852012-08-20 19:22:38 +0000596 size_t rowBytes,
597 uint32_t pixelOpsFlags = 0);
598
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000599 /**
bsalomonf80bfed2014-10-07 05:56:02 -0700600 * Copies a rectangle of texels from src to dst.
scroggo@google.coma2a31922012-12-07 19:14:45 +0000601 * bounds.
bsalomonf80bfed2014-10-07 05:56:02 -0700602 * @param dst the surface to copy to.
603 * @param src the surface to copy from.
604 * @param srcRect the rectangle of the src that should be copied.
605 * @param dstPoint the translation applied when writing the srcRect's pixels to the dst.
606 * @param pixelOpsFlags see PixelOpsFlags enum above. (kUnpremul_PixelOpsFlag is not allowed).
senorblanco@chromium.orgef843cd2011-12-02 19:11:17 +0000607 */
bsalomonf80bfed2014-10-07 05:56:02 -0700608 void copySurface(GrSurface* dst,
609 GrSurface* src,
610 const SkIRect& srcRect,
611 const SkIPoint& dstPoint,
612 uint32_t pixelOpsFlags = 0);
613
614 /** Helper that copies the whole surface but fails when the two surfaces are not identically
615 sized. */
616 bool copySurface(GrSurface* dst, GrSurface* src) {
617 if (NULL == dst || NULL == src || dst->width() != src->width() ||
618 dst->height() != src->height()) {
619 return false;
620 }
621 this->copySurface(dst, src, SkIRect::MakeWH(dst->width(), dst->height()),
622 SkIPoint::Make(0,0));
623 return true;
624 }
625
626 /**
627 * After this returns any pending writes to the surface will have been issued to the backend 3D API.
628 */
629 void flushSurfaceWrites(GrSurface* surface);
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000630
631 /**
bsalomon87a94eb2014-11-03 14:28:32 -0800632 * Equivalent to flushSurfaceWrites but also performs MSAA resolve if necessary. This call is
633 * used to make the surface contents available to be read in the backend 3D API, usually for a
634 * compositing step external to Skia.
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000635 *
bsalomon87a94eb2014-11-03 14:28:32 -0800636 * It is not necessary to call this before reading the render target via Skia/GrContext.
637 * GrContext will detect when it must perform a resolve before reading pixels back from the
638 * surface or using it as a texture.
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000639 */
bsalomon87a94eb2014-11-03 14:28:32 -0800640 void prepareSurfaceForExternalRead(GrSurface*);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000641
642 /**
643 * Provides a perfomance hint that the render target's contents are allowed
644 * to become undefined.
645 */
646 void discardRenderTarget(GrRenderTarget*);
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000647
bsalomon@google.com27847de2011-02-22 20:59:41 +0000648 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com27847de2011-02-22 20:59:41 +0000649 // Functions intended for internal use only.
650 GrGpu* getGpu() { return fGpu; }
bsalomon@google.com1f221a72011-08-23 20:54:07 +0000651 const GrGpu* getGpu() const { return fGpu; }
joshualitt7c3a2f82015-03-31 13:32:05 -0700652 GrBatchFontCache* getBatchFontCache() { return fBatchFontCache; }
robertphillips@google.come930a072014-04-03 00:34:27 +0000653 GrLayerCache* getLayerCache() { return fLayerCache.get(); }
joshualittb7133be2015-04-08 09:08:31 -0700654 GrTextBlobCache* getTextBlobCache() { return fTextBlobCache; }
bsalomon@google.com21c10c52013-06-13 17:44:07 +0000655 GrDrawTarget* getTextTarget();
bsalomon@google.com27847de2011-02-22 20:59:41 +0000656 const GrIndexBuffer* getQuadIndexBuffer() const;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000657 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; }
bsalomon0ea80f42015-02-11 10:49:59 -0800658 GrResourceCache* getResourceCache() { return fResourceCache; }
bsalomon@google.com9923c2b2012-06-06 18:21:18 +0000659
commit-bot@chromium.org78a10782013-08-21 19:27:48 +0000660 // Called by tests that draw directly to the context via GrDrawTarget
661 void getTestTarget(GrTestTarget*);
662
egdanielbbcb38d2014-06-19 10:19:29 -0700663 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
664 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
665
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000666 GrPathRenderer* getPathRenderer(
joshualitt9853cce2014-11-17 14:22:48 -0800667 const GrDrawTarget* target,
egdaniel8dd688b2015-01-22 10:16:09 -0800668 const GrPipelineBuilder*,
joshualitt8059eb92014-12-29 15:10:07 -0800669 const SkMatrix& viewMatrix,
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000670 const SkPath& path,
kkinnunen18996512015-04-26 23:18:49 -0700671 const GrStrokeInfo& stroke,
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000672 bool allowSW,
robertphillips@google.come79f3202014-02-11 16:30:21 +0000673 GrPathRendererChain::DrawType drawType = GrPathRendererChain::kColor_DrawType,
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000674 GrPathRendererChain::StencilSupport* stencilSupport = NULL);
robertphillips@google.com2c756812012-05-22 20:28:23 +0000675
krajcevski9c6d4d72014-08-12 07:26:25 -0700676 /**
677 * This returns a copy of the the GrContext::Options that was passed to the
678 * constructor of this class.
679 */
680 const Options& getOptions() const { return fOptions; }
681
mtkleinb9eb4ac2015-02-02 18:26:03 -0800682 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */
683 void dumpCacheStats(SkString*) const;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000684 void printCacheStats() const;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000685
mtkleinb9eb4ac2015-02-02 18:26:03 -0800686 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */
687 void dumpGpuStats(SkString*) const;
688 void printGpuStats() const;
robertphillips754f4e92014-09-18 13:52:08 -0700689
bsalomon@google.com27847de2011-02-22 20:59:41 +0000690private:
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000691 GrGpu* fGpu;
bsalomon@google.com10e04bf2012-03-30 14:35:04 +0000692
bsalomon0ea80f42015-02-11 10:49:59 -0800693 GrResourceCache* fResourceCache;
joshualitt7c3a2f82015-03-31 13:32:05 -0700694 GrBatchFontCache* fBatchFontCache;
robertphillips@google.come930a072014-04-03 00:34:27 +0000695 SkAutoTDelete<GrLayerCache> fLayerCache;
joshualittb7133be2015-04-08 09:08:31 -0700696 SkAutoTDelete<GrTextBlobCache> fTextBlobCache;
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000697
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000698 GrPathRendererChain* fPathRendererChain;
699 GrSoftwarePathRenderer* fSoftwarePathRenderer;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000700
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000701 GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
702 GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
bsalomona73239a2015-04-28 13:35:17 -0700703 GrDrawTarget* fDrawBuffer;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000704
bsalomonf21dab92014-11-13 13:33:28 -0800705 // Set by OverbudgetCB() to request that GrContext flush before exiting a draw.
706 bool fFlushToReduceCacheSize;
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000707 GrAARectRenderer* fAARectRenderer;
708 GrOvalRenderer* fOvalRenderer;
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000709
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +0000710 bool fDidTestPMConversions;
711 int fPMToUPMConversion;
712 int fUPMToPMConversion;
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000713
robertphillips@google.comcdb426d2012-09-24 19:33:59 +0000714 struct CleanUpData {
715 PFCleanUpFunc fFunc;
716 void* fInfo;
717 };
718
robertphillips@google.com44a91dc2013-07-25 15:32:06 +0000719 SkTDArray<CleanUpData> fCleanUpData;
720
skia.committer@gmail.com956b3102013-07-26 07:00:58 +0000721 int fMaxTextureSizeOverride;
robertphillips@google.comcdb426d2012-09-24 19:33:59 +0000722
krajcevski9c6d4d72014-08-12 07:26:25 -0700723 const Options fOptions;
724
725 GrContext(const Options&); // init must be called after the constructor.
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000726 bool init(GrBackend, GrBackendContext);
bsalomon33435572014-11-05 14:47:41 -0800727 void initMockContext();
728 void initCommon();
bsalomon@google.com205d4602011-04-25 12:43:45 +0000729
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000730 void setupDrawBuffer();
731
bsalomonf21dab92014-11-13 13:33:28 -0800732 class AutoCheckFlush;
joshualitt570d2f82015-02-25 13:19:48 -0800733 // Sets the paint and returns the target to draw into.
734 GrDrawTarget* prepareToDraw(GrPipelineBuilder*,
735 GrRenderTarget* rt,
736 const GrClip&,
737 const GrPaint* paint,
joshualitt25d9c152015-02-18 12:29:52 -0800738 const AutoCheckFlush*);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000739
joshualitt570d2f82015-02-25 13:19:48 -0800740 // A simpler version of the above which just returns the draw target. Clip is *NOT* set
741 GrDrawTarget* prepareToDraw();
742
joshualitt9853cce2014-11-17 14:22:48 -0800743 void internalDrawPath(GrDrawTarget*,
egdaniel8dd688b2015-01-22 10:16:09 -0800744 GrPipelineBuilder*,
joshualitt5531d512014-12-17 15:50:11 -0800745 const SkMatrix& viewMatrix,
joshualitt2e3b3e32014-12-09 13:31:14 -0800746 GrColor,
joshualitt9853cce2014-11-17 14:22:48 -0800747 bool useAA,
748 const SkPath&,
749 const GrStrokeInfo&);
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000750
bsalomond0423582015-02-06 08:49:24 -0800751 GrTexture* internalRefScratchTexture(const GrSurfaceDesc&, uint32_t flags);
robertphillips@google.com3319f332012-08-13 18:00:36 +0000752
skia.committer@gmail.comcdcb2ce2013-01-29 07:05:52 +0000753 /**
joshualitt6e8cd962015-03-20 10:30:14 -0700754 * Creates a new text rendering context that is optimal for the
755 * render target and the context. Caller assumes the ownership
756 * of the returned object. The returned object must be deleted
757 * before the context is destroyed.
758 * TODO we can possibly bury this behind context, but we need to be able to use the
759 * drawText_asPaths logic on SkGpuDevice
760 */
761 GrTextContext* createTextContext(GrRenderTarget*,
762 SkGpuDevice*,
763 const SkDeviceProperties&,
764 bool enableDistanceFieldFonts);
765
766
767 /**
bsalomon@google.comadc65362013-01-28 14:26:09 +0000768 * These functions create premul <-> unpremul effects if it is possible to generate a pair
769 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. Otherwise, they
770 * return NULL.
771 */
joshualittb0a8a372014-09-23 09:50:21 -0700772 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, const SkMatrix&);
773 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, const SkMatrix&);
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000774
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000775 /**
776 * This callback allows the resource cache to callback into the GrContext
bsalomon71cb0c22014-11-14 12:10:14 -0800777 * when the cache is still over budget after a purge.
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000778 */
bsalomon71cb0c22014-11-14 12:10:14 -0800779 static void OverBudgetCB(void* data);
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000780
joshualitt0db6dfa2015-04-10 07:01:30 -0700781 /**
782 * A callback similar to the above for use by the TextBlobCache
783 * TODO move textblob draw calls below context so we can use the call above.
784 */
785 static void TextBlobCacheOverBudgetCB(void* data);
786
joshualitt6e8cd962015-03-20 10:30:14 -0700787 // TODO see note on createTextContext
788 friend class SkGpuDevice;
789
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000790 typedef SkRefCnt INHERITED;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000791};
792
bsalomon@google.com27847de2011-02-22 20:59:41 +0000793#endif