blob: a41fc43ea4675d36f5a8e4b59a710b0cfccd62eb [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
bsalomon@google.com8d67c072012-12-13 20:38:14 +000011#include "GrClipData.h"
joshualitt6db519c2014-10-29 08:48:18 -070012#include "GrClipMaskManager.h"
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000013#include "GrContext.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000014#include "GrDrawState.h"
bsalomon@google.com934c5702012-03-20 21:17:58 +000015#include "GrIndexBuffer.h"
kkinnunenccdaa042014-08-20 01:36:23 -070016#include "GrPathRendering.h"
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000017#include "GrTraceMarker.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000018
bsalomon@google.com8d67c072012-12-13 20:38:14 +000019#include "SkClipStack.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000020#include "SkMatrix.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000021#include "SkPath.h"
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +000022#include "SkStrokeRec.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000023#include "SkTArray.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000024#include "SkTLazy.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000025#include "SkTypes.h"
bsalomon@google.com8d67c072012-12-13 20:38:14 +000026#include "SkXfermode.h"
Scroggo97c88c22011-05-11 14:05:25 +000027
robertphillips@google.coma2d71482012-08-01 20:08:47 +000028class GrClipData;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000029class GrDrawTargetCaps;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000030class GrPath;
cdaltonb85a0aa2014-07-21 15:32:44 -070031class GrPathRange;
reed@google.comac10a2d2010-12-22 21:39:39 +000032class GrVertexBuffer;
sugoi@google.com12b4e272012-12-06 20:13:11 +000033
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000034class GrDrawTarget : public SkRefCnt {
bsalomon@google.comf6601872012-08-28 21:11:35 +000035public:
36 SK_DECLARE_INST_COUNT(GrDrawTarget)
37
kkinnunenccdaa042014-08-20 01:36:23 -070038 typedef GrPathRendering::PathTransformType PathTransformType ;
39
reed@google.comac10a2d2010-12-22 21:39:39 +000040 ///////////////////////////////////////////////////////////////////////////
41
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000042 // The context may not be fully constructed and should not be used during GrDrawTarget
43 // construction.
44 GrDrawTarget(GrContext* context);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000045 virtual ~GrDrawTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +000046
47 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000048 * Gets the capabilities of the draw target.
49 */
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000050 const GrDrawTargetCaps* caps() const { return fCaps.get(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000051
52 /**
reed@google.comac10a2d2010-12-22 21:39:39 +000053 * Sets the current clip to the region specified by clip. All draws will be
54 * clipped against this clip if kClip_StateBit is enabled.
55 *
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000056 * Setting the clip may (or may not) zero out the client's stencil bits.
57 *
reed@google.comac10a2d2010-12-22 21:39:39 +000058 * @param description of the clipping region
59 */
robertphillips@google.combeb1af72012-07-26 18:52:16 +000060 void setClip(const GrClipData* clip);
reed@google.comac10a2d2010-12-22 21:39:39 +000061
62 /**
63 * Gets the current clip.
64 *
65 * @return the clip.
66 */
robertphillips@google.combeb1af72012-07-26 18:52:16 +000067 const GrClipData* getClip() const;
reed@google.comac10a2d2010-12-22 21:39:39 +000068
bsalomon@google.coma5d056a2012-03-27 15:59:58 +000069 /**
bsalomon@google.come3d70952012-03-13 12:40:53 +000070 * There are three types of "sources" of geometry (vertices and indices) for
71 * draw calls made on the target. When performing an indexed draw, the
72 * indices and vertices can use different source types. Once a source is
bsalomon@google.com934c5702012-03-20 21:17:58 +000073 * specified it can be used for multiple draws. However, the time at which
74 * the geometry data is no longer editable depends on the source type.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000075 *
76 * Sometimes it is necessary to perform a draw while upstack code has
bsalomon@google.come3d70952012-03-13 12:40:53 +000077 * already specified geometry that it isn't finished with. So there are push
78 * and pop methods. This allows the client to push the sources, draw
79 * something using alternate sources, and then pop to restore the original
80 * sources.
bsalomon@google.com1c13c962011-02-14 16:51:21 +000081 *
bsalomon@google.come3d70952012-03-13 12:40:53 +000082 * Aside from pushes and pops, a source remains valid until another source
83 * is set or resetVertexSource / resetIndexSource is called. Drawing from
84 * a reset source is an error.
85 *
86 * The three types of sources are:
87 *
88 * 1. A cpu array (set*SourceToArray). This is useful when the caller
89 * already provided vertex data in a format compatible with a
90 * GrVertexLayout. The data in the array is consumed at the time that
91 * set*SourceToArray is called and subsequent edits to the array will not
92 * be reflected in draws.
bsalomon@google.com1c13c962011-02-14 16:51:21 +000093 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000094 * 2. Reserve. This is most useful when the caller has data it must
95 * transform before drawing and is not long-lived. The caller requests
96 * that the draw target make room for some amount of vertex and/or index
97 * data. The target provides ptrs to hold the vertex and/or index data.
98 *
rmistry@google.comd6176b02012-08-23 18:14:13 +000099 * The data is writable up until the next drawIndexed, drawNonIndexed,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000100 * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At
101 * this point the data is frozen and the ptrs are no longer valid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000102 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000103 * Where the space is allocated and how it is uploaded to the GPU is
104 * subclass-dependent.
105 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000106 * 3. Vertex and Index Buffers. This is most useful for geometry that will
bsalomon@google.come3d70952012-03-13 12:40:53 +0000107 * is long-lived. When the data in the buffer is consumed depends on the
rmistry@google.comd6176b02012-08-23 18:14:13 +0000108 * GrDrawTarget subclass. For deferred subclasses the caller has to
bsalomon@google.come3d70952012-03-13 12:40:53 +0000109 * guarantee that the data is still available in the buffers at playback.
110 * (TODO: Make this more automatic as we have done for read/write pixels)
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000111 *
112 * The size of each vertex is determined by querying the current GrDrawState.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000113 */
114
115 /**
bsalomon@google.come3d70952012-03-13 12:40:53 +0000116 * Reserves space for vertices and/or indices. Zero can be specifed as
117 * either the vertex or index count if the caller desires to only reserve
rmistry@google.comd6176b02012-08-23 18:14:13 +0000118 * space for only indices or only vertices. If zero is specifed for
bsalomon@google.come3d70952012-03-13 12:40:53 +0000119 * vertexCount then the vertex source will be unmodified and likewise for
120 * indexCount.
reed@google.comac10a2d2010-12-22 21:39:39 +0000121 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000122 * If the function returns true then the reserve suceeded and the vertices
123 * and indices pointers will point to the space created.
reed@google.comac10a2d2010-12-22 21:39:39 +0000124 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000125 * If the target cannot make space for the request then this function will
126 * return false. If vertexCount was non-zero then upon failure the vertex
127 * source is reset and likewise for indexCount.
reed@google.comac10a2d2010-12-22 21:39:39 +0000128 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000129 * The pointers to the space allocated for vertices and indices remain valid
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000130 * until a drawIndexed, drawNonIndexed, drawIndexedInstances, drawRect,
131 * copySurface, or push/popGeomtrySource is called. At that point logically a
132 * snapshot of the data is made and the pointers are invalid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000133 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000134 * @param vertexCount the number of vertices to reserve space for. Can be
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000135 * 0. Vertex size is queried from the current GrDrawState.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000136 * @param indexCount the number of indices to reserve space for. Can be 0.
bsalomon@google.come3d70952012-03-13 12:40:53 +0000137 * @param vertices will point to reserved vertex space if vertexCount is
rmistry@google.comd6176b02012-08-23 18:14:13 +0000138 * non-zero. Illegal to pass NULL if vertexCount > 0.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000139 * @param indices will point to reserved index space if indexCount is
140 * non-zero. Illegal to pass NULL if indexCount > 0.
141 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000142 bool reserveVertexAndIndexSpace(int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800143 size_t vertexStride,
bsalomon@google.com97805382012-03-13 14:32:07 +0000144 int indexCount,
145 void** vertices,
146 void** indices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000147
reed@google.comac10a2d2010-12-22 21:39:39 +0000148 /**
149 * Provides hints to caller about the number of vertices and indices
150 * that can be allocated cheaply. This can be useful if caller is reserving
151 * space but doesn't know exactly how much geometry is needed.
152 *
153 * Also may hint whether the draw target should be flushed first. This is
154 * useful for deferred targets.
155 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000156 * @param vertexCount in: hint about how many vertices the caller would
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000157 * like to allocate. Vertex size is queried from the
158 * current GrDrawState.
reed@google.comac10a2d2010-12-22 21:39:39 +0000159 * out: a hint about the number of vertices that can be
160 * allocated cheaply. Negative means no hint.
161 * Ignored if NULL.
162 * @param indexCount in: hint about how many indices the caller would
163 * like to allocate.
164 * out: a hint about the number of indices that can be
165 * allocated cheaply. Negative means no hint.
166 * Ignored if NULL.
167 *
168 * @return true if target should be flushed based on the input values.
169 */
joshualitt9853cce2014-11-17 14:22:48 -0800170 virtual bool geometryHints(size_t vertexStride, int* vertexCount, int* indexCount) const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000171
172 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000173 * Sets source of vertex data for the next draw. Data does not have to be
bsalomon@google.com934c5702012-03-20 21:17:58 +0000174 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
reed@google.comac10a2d2010-12-22 21:39:39 +0000175 *
176 * @param buffer vertex buffer containing vertex data. Must be
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000177 * unlocked before draw call. Vertex size is queried
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000178 * from current GrDrawState.
reed@google.comac10a2d2010-12-22 21:39:39 +0000179 */
joshualitt9853cce2014-11-17 14:22:48 -0800180 void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride);
reed@google.comac10a2d2010-12-22 21:39:39 +0000181
182 /**
183 * Sets source of index data for the next indexed draw. Data does not have
bsalomon@google.com934c5702012-03-20 21:17:58 +0000184 * to be in the buffer until drawIndexed.
reed@google.comac10a2d2010-12-22 21:39:39 +0000185 *
186 * @param buffer index buffer containing indices. Must be unlocked
187 * before indexed draw call.
188 */
189 void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000190
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000191 /**
192 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
193 * source to reserved, array, or buffer before next draw. May be able to free
194 * up temporary storage allocated by setVertexSourceToArray or
195 * reserveVertexSpace.
196 */
197 void resetVertexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000198
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000199 /**
200 * Resets index source. Indexed Drawing from reset indices is illegal. Set
201 * index source to reserved, array, or buffer before next indexed draw. May
202 * be able to free up temporary storage allocated by setIndexSourceToArray
203 * or reserveIndexSpace.
204 */
bsalomon@google.com97805382012-03-13 14:32:07 +0000205 void resetIndexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000206
bsalomon@google.com97805382012-03-13 14:32:07 +0000207 /**
208 * Query to find out if the vertex or index source is reserved.
209 */
210 bool hasReservedVerticesOrIndices() const {
bsalomon@google.com73d98aa2012-03-13 14:41:19 +0000211 return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc ||
bsalomon@google.com97805382012-03-13 14:32:07 +0000212 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
213 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000214
215 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000216 * Pushes and resets the vertex/index sources. Any reserved vertex / index
217 * data is finalized (i.e. cannot be updated after the matching pop but can
218 * be drawn from). Must be balanced by a pop.
219 */
220 void pushGeometrySource();
221
222 /**
223 * Pops the vertex / index sources from the matching push.
224 */
225 void popGeometrySource();
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000226
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000227 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000228 * Draws indexed geometry using the current state and current vertex / index
229 * sources.
230 *
231 * @param type The type of primitives to draw.
232 * @param startVertex the vertex in the vertex array/buffer corresponding
233 * to index 0
234 * @param startIndex first index to read from index src.
235 * @param vertexCount one greater than the max index.
236 * @param indexCount the number of index elements to read. The index count
237 * is effectively trimmed to the last completely
238 * specified primitive.
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000239 * @param devBounds optional bounds hint. This is a promise from the caller,
240 * not a request for clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000241 */
joshualitt9853cce2014-11-17 14:22:48 -0800242 void drawIndexed(GrDrawState*,
243 GrPrimitiveType type,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000244 int startVertex,
245 int startIndex,
246 int vertexCount,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000247 int indexCount,
248 const SkRect* devBounds = NULL);
reed@google.comac10a2d2010-12-22 21:39:39 +0000249
250 /**
251 * Draws non-indexed geometry using the current state and current vertex
252 * sources.
253 *
254 * @param type The type of primitives to draw.
255 * @param startVertex the vertex in the vertex array/buffer corresponding
256 * to index 0
257 * @param vertexCount one greater than the max index.
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000258 * @param devBounds optional bounds hint. This is a promise from the caller,
259 * not a request for clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000260 */
joshualitt9853cce2014-11-17 14:22:48 -0800261 void drawNonIndexed(GrDrawState*,
262 GrPrimitiveType type,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000263 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000264 int vertexCount,
265 const SkRect* devBounds = NULL);
reed@google.comac10a2d2010-12-22 21:39:39 +0000266
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000267 /**
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000268 * Draws path into the stencil buffer. The fill must be either even/odd or
269 * winding (not inverse or hairline). It will respect the HW antialias flag
joshualitt92e496f2014-10-31 13:56:50 -0700270 * on the draw state (if possible in the 3D API). Note, we will never have an inverse fill
271 * with stencil path
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000272 */
joshualitt9853cce2014-11-17 14:22:48 -0800273 void stencilPath(GrDrawState*, const GrPath*, GrPathRendering::FillType fill);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000274
275 /**
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000276 * Draws a path. Fill must not be a hairline. It will respect the HW
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000277 * antialias flag on the draw state (if possible in the 3D API).
278 */
joshualitt9853cce2014-11-17 14:22:48 -0800279 void drawPath(GrDrawState*, const GrPath*, GrPathRendering::FillType fill);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000280
281 /**
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000282 * Draws many paths. It will respect the HW
283 * antialias flag on the draw state (if possible in the 3D API).
284 *
cdaltonb85a0aa2014-07-21 15:32:44 -0700285 * @param pathRange Source of paths to draw from
286 * @param indices Array of indices into the the pathRange
287 * @param count Number of paths to draw (length of indices array)
288 * @param transforms Array of individual transforms, one for each path
289 * @param transformsType Type of transformations in the array. Array contains
bsalomondb1f1562014-08-12 06:58:16 -0700290 PathTransformSize(transformsType) * count elements
cdaltonb85a0aa2014-07-21 15:32:44 -0700291 * @param fill Fill type for drawing all the paths
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000292 */
joshualitt9853cce2014-11-17 14:22:48 -0800293 void drawPaths(GrDrawState*, const GrPathRange* pathRange,
294 const uint32_t indices[],
295 int count,
296 const float transforms[],
297 PathTransformType transformsType,
joshualitt92e496f2014-10-31 13:56:50 -0700298 GrPathRendering::FillType fill);
cdaltonb85a0aa2014-07-21 15:32:44 -0700299
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000300 /**
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000301 * Helper function for drawing rects. It performs a geometry src push and pop
302 * and thus will finalize any reserved geometry.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000303 *
bsalomon@google.comc7818882013-03-20 19:19:53 +0000304 * @param rect the rect to draw
bsalomon@google.comc7818882013-03-20 19:19:53 +0000305 * @param localRect optional rect that specifies local coords to map onto
306 * rect. If NULL then rect serves as the local coords.
307 * @param localMatrix optional matrix applied to localRect. If
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000308 * srcRect is non-NULL and srcMatrix is non-NULL
309 * then srcRect will be transformed by srcMatrix.
jvanverth@google.com39768252013-02-14 15:25:44 +0000310 * srcMatrix can be NULL when no srcMatrix is desired.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000311 */
joshualitt9853cce2014-11-17 14:22:48 -0800312 void drawRect(GrDrawState* ds,
313 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000314 const SkRect* localRect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000315 const SkMatrix* localMatrix) {
316 AutoGeometryPush agp(this);
joshualitt9853cce2014-11-17 14:22:48 -0800317 this->onDrawRect(ds, rect, localRect, localMatrix);
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000318 }
jvanverth@google.com39768252013-02-14 15:25:44 +0000319
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000320 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000321 * Helper for drawRect when the caller doesn't need separate local rects or matrices.
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000322 */
joshualitt9853cce2014-11-17 14:22:48 -0800323 void drawSimpleRect(GrDrawState* ds, const SkRect& rect) {
324 this->drawRect(ds, rect, NULL, NULL);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000325 }
joshualitt9853cce2014-11-17 14:22:48 -0800326 void drawSimpleRect(GrDrawState* ds, const SkIRect& irect) {
reed@google.com44699382013-10-31 17:28:30 +0000327 SkRect rect = SkRect::Make(irect);
joshualitt9853cce2014-11-17 14:22:48 -0800328 this->drawRect(ds, rect, NULL, NULL);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000329 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000330
331 /**
bsalomon@google.com934c5702012-03-20 21:17:58 +0000332 * This call is used to draw multiple instances of some geometry with a
333 * given number of vertices (V) and indices (I) per-instance. The indices in
334 * the index source must have the form i[k+I] == i[k] + V. Also, all indices
335 * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a
336 * concrete example, the following index buffer for drawing a series of
337 * quads each as two triangles each satisfies these conditions with V=4 and
338 * I=6:
339 * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...)
340 *
341 * The call assumes that the pattern of indices fills the entire index
342 * source. The size of the index buffer limits the number of instances that
343 * can be drawn by the GPU in a single draw. However, the caller may specify
344 * any (positive) number for instanceCount and if necessary multiple GPU
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000345 * draws will be issued. Moreover, when drawIndexedInstances is called
bsalomon@google.com934c5702012-03-20 21:17:58 +0000346 * multiple times it may be possible for GrDrawTarget to group them into a
347 * single GPU draw.
348 *
349 * @param type the type of primitives to draw
350 * @param instanceCount the number of instances to draw. Each instance
351 * consists of verticesPerInstance vertices indexed by
352 * indicesPerInstance indices drawn as the primitive
353 * type specified by type.
354 * @param verticesPerInstance The number of vertices in each instance (V
355 * in the above description).
356 * @param indicesPerInstance The number of indices in each instance (I
357 * in the above description).
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000358 * @param devBounds optional bounds hint. This is a promise from the caller,
359 * not a request for clipping.
bsalomon@google.com934c5702012-03-20 21:17:58 +0000360 */
joshualitt9853cce2014-11-17 14:22:48 -0800361 void drawIndexedInstances(GrDrawState*,
362 GrPrimitiveType type,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000363 int instanceCount,
364 int verticesPerInstance,
365 int indicesPerInstance,
366 const SkRect* devBounds = NULL);
bsalomon@google.com934c5702012-03-20 21:17:58 +0000367
368 /**
bsalomon89c62982014-11-03 12:08:42 -0800369 * Clear the passed in render target. Ignores the draw state and clip. Clears the whole thing if
370 * rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire render target
371 * can be optionally cleared.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000372 */
joshualitt9853cce2014-11-17 14:22:48 -0800373 void clear(const SkIRect* rect,
374 GrColor color,
375 bool canIgnoreRect,
bsalomon63b21962014-11-05 07:05:34 -0800376 GrRenderTarget* renderTarget);
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000377
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000378 /**
bsalomon89c62982014-11-03 12:08:42 -0800379 * Discards the contents render target.
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000380 **/
bsalomon89c62982014-11-03 12:08:42 -0800381 virtual void discard(GrRenderTarget*) = 0;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000382
383 /**
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000384 * Called at start and end of gpu trace marking
385 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start
386 * and end of a code block respectively
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000387 */
egdaniel3eee3832014-06-18 13:09:11 -0700388 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
389 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
390
391 /**
392 * Takes the current active set of markers and stores them for later use. Any current marker
393 * in the active set is removed from the active set and the targets remove function is called.
394 * These functions do not work as a stack so you cannot call save a second time before calling
395 * restore. Also, it is assumed that when restore is called the current active set of markers
396 * is empty. When the stored markers are added back into the active set, the targets add marker
397 * is called.
398 */
399 void saveActiveTraceMarkers();
400 void restoreActiveTraceMarkers();
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000401
402 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000403 * Copies a pixel rectangle from one surface to another. This call may finalize
404 * reserved vertex/index data (as though a draw call was made). The src pixels
405 * copied are specified by srcRect. They are copied to a rect of the same
406 * size in dst with top left at dstPoint. If the src rect is clipped by the
407 * src bounds then pixel values in the dst rect corresponding to area clipped
408 * by the src rect are not overwritten. This method can fail and return false
409 * depending on the type of surface, configs, etc, and the backend-specific
410 * limitations. If rect is clipped out entirely by the src or dst bounds then
411 * true is returned since there is no actual copy necessary to succeed.
412 */
joshualitta7024152014-11-03 14:16:35 -0800413 virtual bool copySurface(GrSurface* dst,
414 GrSurface* src,
415 const SkIRect& srcRect,
416 const SkIPoint& dstPoint);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000417 /**
418 * Function that determines whether a copySurface call would succeed without
419 * performing the copy.
420 */
joshualitt9853cce2014-11-17 14:22:48 -0800421 virtual bool canCopySurface(const GrSurface* dst,
422 const GrSurface* src,
joshualitta7024152014-11-03 14:16:35 -0800423 const SkIRect& srcRect,
424 const SkIPoint& dstPoint);
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000425
robertphillips@google.comff175842012-05-14 19:31:39 +0000426 /**
bsalomon@google.comeb851172013-04-15 13:51:00 +0000427 * This is can be called before allocating a texture to be a dst for copySurface. It will
428 * populate the origin, config, and flags fields of the desc such that copySurface is more
429 * likely to succeed and be efficient.
430 */
bsalomonf2703d82014-10-28 14:33:06 -0700431 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc);
bsalomon@google.comeb851172013-04-15 13:51:00 +0000432
433
434 /**
robertphillips@google.comff175842012-05-14 19:31:39 +0000435 * Release any resources that are cached but not currently in use. This
436 * is intended to give an application some recourse when resources are low.
437 */
438 virtual void purgeResources() {};
439
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000440 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000441
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000442 class AutoReleaseGeometry : public ::SkNoncopyable {
reed@google.comac10a2d2010-12-22 21:39:39 +0000443 public:
444 AutoReleaseGeometry(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000445 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800446 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000447 int indexCount);
448 AutoReleaseGeometry();
449 ~AutoReleaseGeometry();
bsalomon@google.com5782d712011-01-21 21:03:59 +0000450 bool set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000451 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800452 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000453 int indexCount);
bsalomon49f085d2014-09-05 13:34:00 -0700454 bool succeeded() const { return SkToBool(fTarget); }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000455 void* vertices() const { SkASSERT(this->succeeded()); return fVertices; }
456 void* indices() const { SkASSERT(this->succeeded()); return fIndices; }
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000457 SkPoint* positions() const {
458 return static_cast<SkPoint*>(this->vertices());
reed@google.comac10a2d2010-12-22 21:39:39 +0000459 }
460
461 private:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000462 void reset();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000463
reed@google.comac10a2d2010-12-22 21:39:39 +0000464 GrDrawTarget* fTarget;
reed@google.comac10a2d2010-12-22 21:39:39 +0000465 void* fVertices;
466 void* fIndices;
467 };
468
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000469 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000470
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000471 class AutoClipRestore : public ::SkNoncopyable {
reed@google.comac10a2d2010-12-22 21:39:39 +0000472 public:
473 AutoClipRestore(GrDrawTarget* target) {
474 fTarget = target;
475 fClip = fTarget->getClip();
476 }
477
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000478 AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip);
479
reed@google.comac10a2d2010-12-22 21:39:39 +0000480 ~AutoClipRestore() {
481 fTarget->setClip(fClip);
482 }
483 private:
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000484 GrDrawTarget* fTarget;
485 const GrClipData* fClip;
486 SkTLazy<SkClipStack> fStack;
487 GrClipData fReplacementClip;
reed@google.comac10a2d2010-12-22 21:39:39 +0000488 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000489
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000490 ////////////////////////////////////////////////////////////////////////////
rmistry@google.comd6176b02012-08-23 18:14:13 +0000491
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000492 /**
493 * Saves the geometry src state at construction and restores in the destructor. It also saves
494 * and then restores the vertex attrib state.
495 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000496 class AutoGeometryPush : public ::SkNoncopyable {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000497 public:
joshualitt9853cce2014-11-17 14:22:48 -0800498 AutoGeometryPush(GrDrawTarget* target) {
bsalomon49f085d2014-09-05 13:34:00 -0700499 SkASSERT(target);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000500 fTarget = target;
501 target->pushGeometrySource();
502 }
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000503
504 ~AutoGeometryPush() { fTarget->popGeometrySource(); }
505
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000506 private:
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000507 GrDrawTarget* fTarget;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000508 };
reed@google.comac10a2d2010-12-22 21:39:39 +0000509
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000510 ///////////////////////////////////////////////////////////////////////////
511 // Draw execution tracking (for font atlases and other resources)
512 class DrawToken {
513 public:
514 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) :
515 fDrawTarget(drawTarget), fDrawID(drawID) {}
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000516
bsalomon49f085d2014-09-05 13:34:00 -0700517 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000518
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000519 private:
520 GrDrawTarget* fDrawTarget;
521 uint32_t fDrawID; // this may wrap, but we're doing direct comparison
522 // so that should be okay
523 };
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000524
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000525 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000526
joshualitt3322fa42014-11-07 08:48:51 -0800527 /**
528 * Used to communicate draws to GPUs / subclasses
529 */
530 class DrawInfo {
531 public:
532 DrawInfo(const DrawInfo& di) { (*this) = di; }
533 DrawInfo& operator =(const DrawInfo& di);
534
535 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
536 int startVertex() const { return fStartVertex; }
537 int startIndex() const { return fStartIndex; }
538 int vertexCount() const { return fVertexCount; }
539 int indexCount() const { return fIndexCount; }
540 int verticesPerInstance() const { return fVerticesPerInstance; }
541 int indicesPerInstance() const { return fIndicesPerInstance; }
542 int instanceCount() const { return fInstanceCount; }
543
544 bool isIndexed() const { return fIndexCount > 0; }
545#ifdef SK_DEBUG
546 bool isInstanced() const; // this version is longer because of asserts
547#else
548 bool isInstanced() const { return fInstanceCount > 0; }
549#endif
550
551 // adds or remove instances
552 void adjustInstanceCount(int instanceOffset);
553 // shifts the start vertex
554 void adjustStartVertex(int vertexOffset);
555 // shifts the start index
556 void adjustStartIndex(int indexOffset);
557
558 void setDevBounds(const SkRect& bounds) {
559 fDevBoundsStorage = bounds;
560 fDevBounds = &fDevBoundsStorage;
561 }
562 const SkRect* getDevBounds() const { return fDevBounds; }
563
564 // NULL if no copy of the dst is needed for the draw.
565 const GrDeviceCoordTexture* getDstCopy() const {
566 if (fDstCopy.texture()) {
567 return &fDstCopy;
568 } else {
569 return NULL;
570 }
571 }
572
573 private:
574 DrawInfo() { fDevBounds = NULL; }
575
576 friend class GrDrawTarget;
577
578 GrPrimitiveType fPrimitiveType;
579
580 int fStartVertex;
581 int fStartIndex;
582 int fVertexCount;
583 int fIndexCount;
584
585 int fInstanceCount;
586 int fVerticesPerInstance;
587 int fIndicesPerInstance;
588
589 SkRect fDevBoundsStorage;
590 SkRect* fDevBounds;
591
592 GrDeviceCoordTexture fDstCopy;
593 };
joshualitt2c93efe2014-11-06 12:57:13 -0800594
595 bool programUnitTest(int maxStages);
596
reed@google.comac10a2d2010-12-22 21:39:39 +0000597protected:
egdaniel89af44a2014-09-26 06:15:04 -0700598 // Extend access to GrDrawState::convertToPEndeingExec to subclasses.
599 void convertDrawStateToPendingExec(GrDrawState* ds) {
bsalomon2a9ca782014-09-05 14:27:43 -0700600 ds->convertToPendingExec();
601 }
bsalomon@google.com471d4712011-08-23 15:45:25 +0000602
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000603 enum GeometrySrcType {
604 kNone_GeometrySrcType, //<! src has not been specified
605 kReserved_GeometrySrcType, //<! src was set using reserve*Space
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000606 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
607 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000608
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000609 struct GeometrySrcState {
610 GeometrySrcType fVertexSrc;
611 union {
612 // valid if src type is buffer
613 const GrVertexBuffer* fVertexBuffer;
614 // valid if src type is reserved or array
615 int fVertexCount;
616 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000617
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000618 GeometrySrcType fIndexSrc;
619 union {
620 // valid if src type is buffer
621 const GrIndexBuffer* fIndexBuffer;
622 // valid if src type is reserved or array
623 int fIndexCount;
624 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000625
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000626 size_t fVertexSize;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000627 };
bsalomon@google.com934c5702012-03-20 21:17:58 +0000628
629 int indexCountInCurrentSource() const {
630 const GeometrySrcState& src = this->getGeomSrc();
631 switch (src.fIndexSrc) {
632 case kNone_GeometrySrcType:
633 return 0;
634 case kReserved_GeometrySrcType:
bsalomon@google.com934c5702012-03-20 21:17:58 +0000635 return src.fIndexCount;
636 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000637 return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
bsalomon@google.com934c5702012-03-20 21:17:58 +0000638 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000639 SkFAIL("Unexpected Index Source.");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000640 return 0;
641 }
642 }
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000643
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000644 GrContext* getContext() { return fContext; }
645 const GrContext* getContext() const { return fContext; }
646
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000647 // subclasses must call this in their destructors to ensure all vertex
648 // and index sources have been released (including those held by
649 // pushGeometrySource())
650 void releaseGeometry();
651
652 // accessors for derived classes
653 const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); }
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000654 // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert.
655 size_t getVertexSize() const {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000656 // the vertex layout is only valid if a vertex source has been specified.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000657 SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType);
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000658 return this->getGeomSrc().fVertexSize;
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000659 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000660
bsalomon@google.combcce8922013-03-25 15:38:39 +0000661 // Subclass must initialize this in its constructor.
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000662 SkAutoTUnref<const GrDrawTargetCaps> fCaps;
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000663
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000664 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; }
665
joshualitt65171342014-10-09 07:25:36 -0700666 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
667 // but couldn't be made. Otherwise, returns true. This method needs to be protected because it
668 // needs to be accessed by GLPrograms to setup a correct drawstate
joshualitt9853cce2014-11-17 14:22:48 -0800669 bool setupDstReadIfNecessary(GrDrawState* ds, DrawInfo* info) {
670 return this->setupDstReadIfNecessary(ds, &info->fDstCopy, info->getDevBounds());
joshualitt65171342014-10-09 07:25:36 -0700671 }
joshualitt9853cce2014-11-17 14:22:48 -0800672 bool setupDstReadIfNecessary(GrDrawState*,
673 GrDeviceCoordTexture* dstCopy,
674 const SkRect* drawBounds);
joshualitt65171342014-10-09 07:25:36 -0700675
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000676private:
677 // A subclass can optionally overload this function to be notified before
678 // vertex and index space is reserved.
joshualitt9853cce2014-11-17 14:22:48 -0800679 virtual void willReserveVertexAndIndexSpace(int vertexCount,
680 size_t vertexStride,
681 int indexCount) {}
bsalomon@google.com97805382012-03-13 14:32:07 +0000682
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000683 // implemented by subclass to allocate space for reserved geom
jvanverth@google.coma6338982013-01-31 21:34:25 +0000684 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000685 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
686 // implemented by subclass to handle release of reserved geom space
687 virtual void releaseReservedVertexSpace() = 0;
688 virtual void releaseReservedIndexSpace() = 0;
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000689 // subclass overrides to be notified just before geo src state is pushed/popped.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000690 virtual void geometrySourceWillPush() = 0;
691 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
692 // subclass called to perform drawing
joshualitt9853cce2014-11-17 14:22:48 -0800693 virtual void onDraw(const GrDrawState&,
694 const DrawInfo&,
695 const GrClipMaskManager::ScissorState&) = 0;
joshualitt5478d422014-11-14 16:00:38 -0800696 // TODO copy in order drawbuffer onDrawRect to here
joshualitt9853cce2014-11-17 14:22:48 -0800697 virtual void onDrawRect(GrDrawState*,
698 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000699 const SkRect* localRect,
joshualitt5478d422014-11-14 16:00:38 -0800700 const SkMatrix* localMatrix) = 0;
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000701
joshualitt9853cce2014-11-17 14:22:48 -0800702 virtual void onStencilPath(const GrDrawState&,
703 const GrPath*,
joshualitt2c93efe2014-11-06 12:57:13 -0800704 const GrClipMaskManager::ScissorState&,
705 const GrStencilSettings&) = 0;
joshualitt9853cce2014-11-17 14:22:48 -0800706 virtual void onDrawPath(const GrDrawState&,
707 const GrPath*,
joshualitt2c93efe2014-11-06 12:57:13 -0800708 const GrClipMaskManager::ScissorState&,
709 const GrStencilSettings&,
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000710 const GrDeviceCoordTexture* dstCopy) = 0;
joshualitt9853cce2014-11-17 14:22:48 -0800711 virtual void onDrawPaths(const GrDrawState&,
712 const GrPathRange*,
joshualitt2c93efe2014-11-06 12:57:13 -0800713 const uint32_t indices[],
714 int count,
715 const float transforms[],
716 PathTransformType,
717 const GrClipMaskManager::ScissorState&,
718 const GrStencilSettings&,
719 const GrDeviceCoordTexture*) = 0;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000720
bsalomon63b21962014-11-05 07:05:34 -0800721 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
722 GrRenderTarget* renderTarget) = 0;
723
724
bsalomon@google.come3d70952012-03-13 12:40:53 +0000725 // helpers for reserving vertex and index space.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000726 bool reserveVertexSpace(size_t vertexSize,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000727 int vertexCount,
728 void** vertices);
729 bool reserveIndexSpace(int indexCount, void** indices);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000730
bsalomon@google.come8262622011-11-07 02:30:51 +0000731 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to
732 // indicate non-indexed drawing.
joshualitt9853cce2014-11-17 14:22:48 -0800733 bool checkDraw(const GrDrawState&,
734 GrPrimitiveType type,
735 int startVertex,
736 int startIndex,
737 int vertexCount,
bsalomon@google.come8262622011-11-07 02:30:51 +0000738 int indexCount) const;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000739 // called when setting a new vert/idx source to unref prev vb/ib
740 void releasePreviousVertexSource();
741 void releasePreviousIndexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000742
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000743 // Check to see if this set of draw commands has been sent out
744 virtual bool isIssued(uint32_t drawID) { return true; }
joshualitt9853cce2014-11-17 14:22:48 -0800745 void getPathStencilSettingsForFilltype(GrPathRendering::FillType,
746 const GrStencilBuffer*,
747 GrStencilSettings*);
joshualitta7024152014-11-03 14:16:35 -0800748 virtual GrClipMaskManager* clipMaskManager() = 0;
joshualitt2c93efe2014-11-06 12:57:13 -0800749 virtual bool setupClip(const SkRect* devBounds,
750 GrDrawState::AutoRestoreEffects* are,
751 GrDrawState::AutoRestoreStencil* ars,
joshualitt9853cce2014-11-17 14:22:48 -0800752 GrDrawState*,
joshualitt2c93efe2014-11-06 12:57:13 -0800753 GrClipMaskManager::ScissorState* scissorState) = 0;
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000754
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000755 enum {
756 kPreallocGeoSrcStateStackCnt = 4,
reed@google.comac10a2d2010-12-22 21:39:39 +0000757 };
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000758 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack;
759 const GrClipData* fClip;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000760 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget.
761 GrContext* fContext;
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000762 // To keep track that we always have at least as many debug marker adds as removes
763 int fGpuTraceMarkerCount;
764 GrTraceMarkerSet fActiveTraceMarkers;
egdaniel3eee3832014-06-18 13:09:11 -0700765 GrTraceMarkerSet fStoredTraceMarkers;
reed@google.comfa35e3d2012-06-26 20:16:17 +0000766
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000767 typedef SkRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000768};
769
joshualitt329bf482014-10-29 12:31:28 -0700770/*
771 * This class is JUST for clip mask manager. Everyone else should just use draw target above.
772 */
joshualitt6db519c2014-10-29 08:48:18 -0700773class GrClipTarget : public GrDrawTarget {
774public:
joshualitt329bf482014-10-29 12:31:28 -0700775 GrClipTarget(GrContext* context) : INHERITED(context) {
776 fClipMaskManager.setClipTarget(this);
777 }
778
779 /* Clip mask manager needs access to the context.
780 * TODO we only need a very small subset of context in the CMM.
781 */
782 GrContext* getContext() { return INHERITED::getContext(); }
783 const GrContext* getContext() const { return INHERITED::getContext(); }
784
joshualitt6db519c2014-10-29 08:48:18 -0700785 /**
786 * Clip Mask Manager(and no one else) needs to clear private stencil bits.
787 * ClipTarget subclass sets clip bit in the stencil buffer. The subclass
788 * is free to clear the remaining bits to zero if masked clears are more
789 * expensive than clearing all bits.
790 */
791 virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0;
792
joshualitt3bdd7dc2014-10-31 08:27:39 -0700793 /**
794 * Release any resources that are cached but not currently in use. This
795 * is intended to give an application some recourse when resources are low.
796 */
797 virtual void purgeResources() SK_OVERRIDE {
798 // The clip mask manager can rebuild all its clip masks so just
799 // get rid of them all.
800 fClipMaskManager.purgeResources();
801 };
802
joshualitt329bf482014-10-29 12:31:28 -0700803protected:
804 GrClipMaskManager fClipMaskManager;
805
joshualitt6db519c2014-10-29 08:48:18 -0700806private:
joshualitta7024152014-11-03 14:16:35 -0800807 GrClipMaskManager* clipMaskManager() { return &fClipMaskManager; }
joshualitt329bf482014-10-29 12:31:28 -0700808
joshualitt2c93efe2014-11-06 12:57:13 -0800809 virtual bool setupClip(const SkRect* devBounds,
810 GrDrawState::AutoRestoreEffects* are,
811 GrDrawState::AutoRestoreStencil* ars,
joshualitt9853cce2014-11-17 14:22:48 -0800812 GrDrawState*,
joshualitt2c93efe2014-11-06 12:57:13 -0800813 GrClipMaskManager::ScissorState* scissorState) SK_OVERRIDE;
814
joshualitt6db519c2014-10-29 08:48:18 -0700815 typedef GrDrawTarget INHERITED;
816};
817
reed@google.comac10a2d2010-12-22 21:39:39 +0000818#endif