blob: 84f7eb2197a4aa736aabba9847b9ba5b08ab5518 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +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.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#ifndef GrDrawTarget_DEFINED
9#define GrDrawTarget_DEFINED
10
joshualitt44701df2015-02-23 14:44:57 -080011#include "GrClip.h"
joshualitt6db519c2014-10-29 08:48:18 -070012#include "GrClipMaskManager.h"
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000013#include "GrContext.h"
joshualitt8072caa2015-02-12 14:20:52 -080014#include "GrPathProcessor.h"
15#include "GrPrimitiveProcessor.h"
bsalomon@google.com934c5702012-03-20 21:17:58 +000016#include "GrIndexBuffer.h"
kkinnunenccdaa042014-08-20 01:36:23 -070017#include "GrPathRendering.h"
egdaniel8dd688b2015-01-22 10:16:09 -080018#include "GrPipelineBuilder.h"
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000019#include "GrTraceMarker.h"
joshualitt7eb8c7b2014-11-18 14:24:27 -080020#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000021
bsalomon@google.com8d67c072012-12-13 20:38:14 +000022#include "SkClipStack.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000023#include "SkMatrix.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000024#include "SkPath.h"
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +000025#include "SkStrokeRec.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000026#include "SkTArray.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000027#include "SkTLazy.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000028#include "SkTypes.h"
bsalomon@google.com8d67c072012-12-13 20:38:14 +000029#include "SkXfermode.h"
Scroggo97c88c22011-05-11 14:05:25 +000030
joshualitt44701df2015-02-23 14:44:57 -080031class GrClip;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000032class GrDrawTargetCaps;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000033class GrPath;
cdaltonb85a0aa2014-07-21 15:32:44 -070034class GrPathRange;
egdaniele36914c2015-02-13 09:00:33 -080035class GrPipeline;
sugoi@google.com12b4e272012-12-06 20:13:11 +000036
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000037class GrDrawTarget : public SkRefCnt {
bsalomon@google.comf6601872012-08-28 21:11:35 +000038public:
39 SK_DECLARE_INST_COUNT(GrDrawTarget)
40
cdalton55b24af2014-11-25 11:00:56 -080041 typedef GrPathRange::PathIndexType PathIndexType;
42 typedef GrPathRendering::PathTransformType PathTransformType;
kkinnunenccdaa042014-08-20 01:36:23 -070043
reed@google.comac10a2d2010-12-22 21:39:39 +000044 ///////////////////////////////////////////////////////////////////////////
45
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000046 // The context may not be fully constructed and should not be used during GrDrawTarget
47 // construction.
robertphillipse40d3972015-05-07 09:51:43 -070048 GrDrawTarget(GrContext* context);
bsalomona73239a2015-04-28 13:35:17 -070049
bsalomon72e3ae42015-04-28 08:08:46 -070050 virtual ~GrDrawTarget() {}
reed@google.comac10a2d2010-12-22 21:39:39 +000051
52 /**
bsalomona73239a2015-04-28 13:35:17 -070053 * Empties the draw buffer of any queued up draws.
54 */
robertphillipse40d3972015-05-07 09:51:43 -070055 void reset() { this->onReset(); }
bsalomona73239a2015-04-28 13:35:17 -070056
57 /**
58 * This plays any queued up draws to its GrGpu target. It also resets this object (i.e. flushing
59 * is destructive).
60 */
61 void flush();
62
63 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000064 * Gets the capabilities of the draw target.
65 */
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000066 const GrDrawTargetCaps* caps() const { return fCaps.get(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000067
joshualitt99c7c072015-05-01 13:43:30 -070068 void drawBatch(GrPipelineBuilder*, GrBatch*);
joshualitt4d8da812015-01-28 12:53:54 -080069
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000070 /**
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000071 * Draws path into the stencil buffer. The fill must be either even/odd or
72 * winding (not inverse or hairline). It will respect the HW antialias flag
egdaniel8dd688b2015-01-22 10:16:09 -080073 * on the GrPipelineBuilder (if possible in the 3D API). Note, we will never have an inverse
74 * fill with stencil path
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000075 */
egdaniel8dd688b2015-01-22 10:16:09 -080076 void stencilPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*,
77 GrPathRendering::FillType);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000078
79 /**
commit-bot@chromium.org32184d82013-10-09 15:14:18 +000080 * Draws a path. Fill must not be a hairline. It will respect the HW
egdaniel8dd688b2015-01-22 10:16:09 -080081 * antialias flag on the GrPipelineBuilder (if possible in the 3D API).
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000082 */
egdaniel8dd688b2015-01-22 10:16:09 -080083 void drawPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*,
84 GrPathRendering::FillType);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000085
86 /**
cdalton55b24af2014-11-25 11:00:56 -080087 * Draws the aggregate path from combining multiple. Note that this will not
88 * always be equivalent to back-to-back calls to drawPath(). It will respect
egdaniel8dd688b2015-01-22 10:16:09 -080089 * the HW antialias flag on the GrPipelineBuilder (if possible in the 3D API).
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +000090 *
cdalton55b24af2014-11-25 11:00:56 -080091 * @param pathRange Source paths to draw from
92 * @param indices Array of path indices to draw
93 * @param indexType Data type of the array elements in indexBuffer
94 * @param transformValues Array of transforms for the individual paths
95 * @param transformType Type of transforms in transformBuffer
96 * @param count Number of paths to draw
cdaltonb85a0aa2014-07-21 15:32:44 -070097 * @param fill Fill type for drawing all the paths
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +000098 */
egdaniel8dd688b2015-01-22 10:16:09 -080099 void drawPaths(GrPipelineBuilder*,
joshualitt56995b52014-12-11 15:44:02 -0800100 const GrPathProcessor*,
joshualitt2e3b3e32014-12-09 13:31:14 -0800101 const GrPathRange* pathRange,
cdalton55b24af2014-11-25 11:00:56 -0800102 const void* indices,
103 PathIndexType indexType,
104 const float transformValues[],
105 PathTransformType transformType,
joshualitt9853cce2014-11-17 14:22:48 -0800106 int count,
joshualitt92e496f2014-10-31 13:56:50 -0700107 GrPathRendering::FillType fill);
cdaltonb85a0aa2014-07-21 15:32:44 -0700108
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000109 /**
bsalomon72e3ae42015-04-28 08:08:46 -0700110 * Helper function for drawing rects.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000111 *
bsalomon@google.comc7818882013-03-20 19:19:53 +0000112 * @param rect the rect to draw
bsalomon@google.comc7818882013-03-20 19:19:53 +0000113 * @param localRect optional rect that specifies local coords to map onto
114 * rect. If NULL then rect serves as the local coords.
joshualitt8fc6c2d2014-12-22 15:27:05 -0800115 * @param localMatrix Optional local matrix. The local coordinates are specified by localRect,
116 * or if it is NULL by rect. This matrix applies to the coordinate implied by
117 * that rectangle before it is input to GrCoordTransforms that read local
118 * coordinates
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000119 */
joshualitt4d8da812015-01-28 12:53:54 -0800120 void drawRect(GrPipelineBuilder* pipelineBuilder,
joshualitt2e3b3e32014-12-09 13:31:14 -0800121 GrColor color,
joshualitt8059eb92014-12-29 15:10:07 -0800122 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -0800123 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000124 const SkRect* localRect,
joshualittad17cfc2015-05-05 10:45:57 -0700125 const SkMatrix* localMatrix);
jvanverth@google.com39768252013-02-14 15:25:44 +0000126
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000127 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000128 * Helper for drawRect when the caller doesn't need separate local rects or matrices.
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000129 */
egdaniel8dd688b2015-01-22 10:16:09 -0800130 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM,
131 const SkRect& rect) {
joshualitt8059eb92014-12-29 15:10:07 -0800132 this->drawRect(ds, color, viewM, rect, NULL, NULL);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000133 }
egdaniel8dd688b2015-01-22 10:16:09 -0800134 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM,
joshualitt8059eb92014-12-29 15:10:07 -0800135 const SkIRect& irect) {
reed@google.com44699382013-10-31 17:28:30 +0000136 SkRect rect = SkRect::Make(irect);
joshualitt8059eb92014-12-29 15:10:07 -0800137 this->drawRect(ds, color, viewM, rect, NULL, NULL);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000138 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000139
bsalomon@google.com934c5702012-03-20 21:17:58 +0000140
141 /**
egdaniel8dd688b2015-01-22 10:16:09 -0800142 * Clear the passed in render target. Ignores the GrPipelineBuilder and clip. Clears the whole
143 * thing if rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire
144 * render target can be optionally cleared.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000145 */
joshualitt9853cce2014-11-17 14:22:48 -0800146 void clear(const SkIRect* rect,
147 GrColor color,
148 bool canIgnoreRect,
bsalomon63b21962014-11-05 07:05:34 -0800149 GrRenderTarget* renderTarget);
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000150
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000151 /**
bsalomon89c62982014-11-03 12:08:42 -0800152 * Discards the contents render target.
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000153 **/
bsalomon89c62982014-11-03 12:08:42 -0800154 virtual void discard(GrRenderTarget*) = 0;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000155
156 /**
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000157 * Called at start and end of gpu trace marking
158 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start
159 * and end of a code block respectively
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000160 */
egdaniel3eee3832014-06-18 13:09:11 -0700161 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
162 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
163
164 /**
165 * Takes the current active set of markers and stores them for later use. Any current marker
166 * in the active set is removed from the active set and the targets remove function is called.
167 * These functions do not work as a stack so you cannot call save a second time before calling
168 * restore. Also, it is assumed that when restore is called the current active set of markers
169 * is empty. When the stored markers are added back into the active set, the targets add marker
170 * is called.
171 */
172 void saveActiveTraceMarkers();
173 void restoreActiveTraceMarkers();
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000174
175 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000176 * Copies a pixel rectangle from one surface to another. This call may finalize
177 * reserved vertex/index data (as though a draw call was made). The src pixels
178 * copied are specified by srcRect. They are copied to a rect of the same
179 * size in dst with top left at dstPoint. If the src rect is clipped by the
180 * src bounds then pixel values in the dst rect corresponding to area clipped
181 * by the src rect are not overwritten. This method can fail and return false
182 * depending on the type of surface, configs, etc, and the backend-specific
183 * limitations. If rect is clipped out entirely by the src or dst bounds then
184 * true is returned since there is no actual copy necessary to succeed.
185 */
bsalomonf90a02b2014-11-26 12:28:00 -0800186 bool copySurface(GrSurface* dst,
187 GrSurface* src,
188 const SkIRect& srcRect,
189 const SkIPoint& dstPoint);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000190 /**
bsalomonf90a02b2014-11-26 12:28:00 -0800191 * Function that determines whether a copySurface call would succeed without actually
bsalomon@google.com116ad842013-04-09 15:38:19 +0000192 * performing the copy.
193 */
bsalomonf90a02b2014-11-26 12:28:00 -0800194 bool canCopySurface(const GrSurface* dst,
195 const GrSurface* src,
196 const SkIRect& srcRect,
197 const SkIPoint& dstPoint);
bsalomon@google.comeb851172013-04-15 13:51:00 +0000198
199 /**
robertphillips@google.comff175842012-05-14 19:31:39 +0000200 * Release any resources that are cached but not currently in use. This
201 * is intended to give an application some recourse when resources are low.
202 */
203 virtual void purgeResources() {};
204
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000205 ///////////////////////////////////////////////////////////////////////////
206 // Draw execution tracking (for font atlases and other resources)
207 class DrawToken {
208 public:
209 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) :
210 fDrawTarget(drawTarget), fDrawID(drawID) {}
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000211
bsalomon49f085d2014-09-05 13:34:00 -0700212 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000213
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000214 private:
215 GrDrawTarget* fDrawTarget;
216 uint32_t fDrawID; // this may wrap, but we're doing direct comparison
217 // so that should be okay
218 };
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000219
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000220 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000221
joshualitt2c93efe2014-11-06 12:57:13 -0800222 bool programUnitTest(int maxStages);
223
reed@google.comac10a2d2010-12-22 21:39:39 +0000224protected:
joshualitte46760e2015-05-05 08:41:50 -0700225 friend class GrCommandBuilder; // for PipelineInfo
joshualittaf242952015-05-05 11:55:39 -0700226 friend class GrInOrderCommandBuilder; // for PipelineInfo
joshualitt3b58d752015-05-07 11:14:30 -0700227 friend class GrReorderCommandBuilder; // for PipelineInfo
robertphillipsdad77942015-03-03 09:28:16 -0800228 friend class GrTargetCommands; // for PipelineInfo
229
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000230 GrContext* getContext() { return fContext; }
231 const GrContext* getContext() const { return fContext; }
232
bsalomona73239a2015-04-28 13:35:17 -0700233 GrGpu* getGpu() {
234 SkASSERT(fContext && fContext->getGpu());
235 return fContext->getGpu();
236 }
237 const GrGpu* getGpu() const {
238 SkASSERT(fContext && fContext->getGpu());
239 return fContext->getGpu();
240 }
241
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000242 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; }
243
joshualitt65171342014-10-09 07:25:36 -0700244 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
245 // but couldn't be made. Otherwise, returns true. This method needs to be protected because it
246 // needs to be accessed by GLPrograms to setup a correct drawstate
bsalomon50785a32015-02-06 07:02:37 -0800247 bool setupDstReadIfNecessary(const GrPipelineBuilder&,
egdaniele36914c2015-02-13 09:00:33 -0800248 const GrProcOptInfo& colorPOI,
249 const GrProcOptInfo& coveragePOI,
joshualitt9853cce2014-11-17 14:22:48 -0800250 GrDeviceCoordTexture* dstCopy,
251 const SkRect* drawBounds);
joshualitt65171342014-10-09 07:25:36 -0700252
egdaniele36914c2015-02-13 09:00:33 -0800253 struct PipelineInfo {
254 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor,
joshualitt44701df2015-02-23 14:44:57 -0800255 const GrPrimitiveProcessor* primProc,
256 const SkRect* devBounds, GrDrawTarget* target);
egdaniele36914c2015-02-13 09:00:33 -0800257
258 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor,
joshualitt44701df2015-02-23 14:44:57 -0800259 const GrBatch* batch, const SkRect* devBounds,
260 GrDrawTarget* target);
egdaniele36914c2015-02-13 09:00:33 -0800261
262 bool willBlendWithDst(const GrPrimitiveProcessor* primProc) const {
263 return fPipelineBuilder->willBlendWithDst(primProc);
264 }
265 private:
266 friend class GrDrawTarget;
267
268 bool mustSkipDraw() const { return (NULL == fPipelineBuilder); }
269
270 GrPipelineBuilder* fPipelineBuilder;
271 GrScissorState* fScissor;
272 GrProcOptInfo fColorPOI;
273 GrProcOptInfo fCoveragePOI;
274 GrDeviceCoordTexture fDstCopy;
275 };
276
277 void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline);
278
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000279private:
bsalomona73239a2015-04-28 13:35:17 -0700280 virtual void onReset() = 0;
bsalomonf90a02b2014-11-26 12:28:00 -0800281
bsalomona73239a2015-04-28 13:35:17 -0700282 virtual void onFlush() = 0;
bsalomonf90a02b2014-11-26 12:28:00 -0800283
egdaniele36914c2015-02-13 09:00:33 -0800284 virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0;
egdaniel8dd688b2015-01-22 10:16:09 -0800285 virtual void onStencilPath(const GrPipelineBuilder&,
joshualitt56995b52014-12-11 15:44:02 -0800286 const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800287 const GrPath*,
bsalomon3e791242014-12-17 13:43:13 -0800288 const GrScissorState&,
joshualitt2c93efe2014-11-06 12:57:13 -0800289 const GrStencilSettings&) = 0;
egdaniele36914c2015-02-13 09:00:33 -0800290 virtual void onDrawPath(const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800291 const GrPath*,
joshualitt2c93efe2014-11-06 12:57:13 -0800292 const GrStencilSettings&,
egdaniele36914c2015-02-13 09:00:33 -0800293 const PipelineInfo&) = 0;
294 virtual void onDrawPaths(const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800295 const GrPathRange*,
cdalton55b24af2014-11-25 11:00:56 -0800296 const void* indices,
297 PathIndexType,
298 const float transformValues[],
joshualitt2c93efe2014-11-06 12:57:13 -0800299 PathTransformType,
cdalton55b24af2014-11-25 11:00:56 -0800300 int count,
joshualitt2c93efe2014-11-06 12:57:13 -0800301 const GrStencilSettings&,
egdaniele36914c2015-02-13 09:00:33 -0800302 const PipelineInfo&) = 0;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000303
bsalomon63b21962014-11-05 07:05:34 -0800304 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
305 GrRenderTarget* renderTarget) = 0;
306
bsalomona73239a2015-04-28 13:35:17 -0700307 /** The subclass's copy surface implementation. It should assume that any clipping has already
308 been performed on the rect and point and that the GrGpu supports the copy. */
309 virtual void onCopySurface(GrSurface* dst,
bsalomonf90a02b2014-11-26 12:28:00 -0800310 GrSurface* src,
311 const SkIRect& srcRect,
312 const SkIPoint& dstPoint) = 0;
313
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000314 // Check to see if this set of draw commands has been sent out
315 virtual bool isIssued(uint32_t drawID) { return true; }
joshualitt9853cce2014-11-17 14:22:48 -0800316 void getPathStencilSettingsForFilltype(GrPathRendering::FillType,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700317 const GrStencilAttachment*,
joshualitt9853cce2014-11-17 14:22:48 -0800318 GrStencilSettings*);
joshualitta7024152014-11-03 14:16:35 -0800319 virtual GrClipMaskManager* clipMaskManager() = 0;
egdaniel8dd688b2015-01-22 10:16:09 -0800320 virtual bool setupClip(GrPipelineBuilder*,
bsalomon6be6f7c2015-02-26 13:05:21 -0800321 GrPipelineBuilder::AutoRestoreFragmentProcessors*,
322 GrPipelineBuilder::AutoRestoreStencil*,
323 GrScissorState*,
joshualitt8059eb92014-12-29 15:10:07 -0800324 const SkRect* devBounds) = 0;
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000325
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000326 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget.
327 GrContext* fContext;
bsalomona73239a2015-04-28 13:35:17 -0700328 SkAutoTUnref<const GrDrawTargetCaps> fCaps;
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000329 // To keep track that we always have at least as many debug marker adds as removes
330 int fGpuTraceMarkerCount;
331 GrTraceMarkerSet fActiveTraceMarkers;
egdaniel3eee3832014-06-18 13:09:11 -0700332 GrTraceMarkerSet fStoredTraceMarkers;
bsalomona73239a2015-04-28 13:35:17 -0700333 bool fFlushing;
reed@google.comfa35e3d2012-06-26 20:16:17 +0000334
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000335 typedef SkRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000336};
337
joshualitt329bf482014-10-29 12:31:28 -0700338/*
339 * This class is JUST for clip mask manager. Everyone else should just use draw target above.
340 */
joshualitt6db519c2014-10-29 08:48:18 -0700341class GrClipTarget : public GrDrawTarget {
342public:
robertphillipse40d3972015-05-07 09:51:43 -0700343 GrClipTarget(GrContext* context)
344 : INHERITED(context) {
joshualitt329bf482014-10-29 12:31:28 -0700345 fClipMaskManager.setClipTarget(this);
346 }
347
348 /* Clip mask manager needs access to the context.
349 * TODO we only need a very small subset of context in the CMM.
350 */
351 GrContext* getContext() { return INHERITED::getContext(); }
352 const GrContext* getContext() const { return INHERITED::getContext(); }
353
joshualitt6db519c2014-10-29 08:48:18 -0700354 /**
355 * Clip Mask Manager(and no one else) needs to clear private stencil bits.
356 * ClipTarget subclass sets clip bit in the stencil buffer. The subclass
357 * is free to clear the remaining bits to zero if masked clears are more
358 * expensive than clearing all bits.
359 */
360 virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0;
361
joshualitt3bdd7dc2014-10-31 08:27:39 -0700362 /**
363 * Release any resources that are cached but not currently in use. This
364 * is intended to give an application some recourse when resources are low.
365 */
mtklein36352bf2015-03-25 18:17:31 -0700366 void purgeResources() override {
joshualitt3bdd7dc2014-10-31 08:27:39 -0700367 // The clip mask manager can rebuild all its clip masks so just
368 // get rid of them all.
369 fClipMaskManager.purgeResources();
370 };
371
joshualitt329bf482014-10-29 12:31:28 -0700372protected:
373 GrClipMaskManager fClipMaskManager;
374
joshualitt6db519c2014-10-29 08:48:18 -0700375private:
mtklein36352bf2015-03-25 18:17:31 -0700376 GrClipMaskManager* clipMaskManager() override { return &fClipMaskManager; }
joshualitt329bf482014-10-29 12:31:28 -0700377
egdaniel8dd688b2015-01-22 10:16:09 -0800378 virtual bool setupClip(GrPipelineBuilder*,
bsalomon6be6f7c2015-02-26 13:05:21 -0800379 GrPipelineBuilder::AutoRestoreFragmentProcessors*,
380 GrPipelineBuilder::AutoRestoreStencil*,
joshualitt8059eb92014-12-29 15:10:07 -0800381 GrScissorState* scissorState,
mtklein36352bf2015-03-25 18:17:31 -0700382 const SkRect* devBounds) override;
joshualitt2c93efe2014-11-06 12:57:13 -0800383
joshualitt6db519c2014-10-29 08:48:18 -0700384 typedef GrDrawTarget INHERITED;
385};
386
reed@google.comac10a2d2010-12-22 21:39:39 +0000387#endif