blob: dc1be12ee62263fa4330ec25afd425d2ebe307f6 [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
joshualitt4d8da812015-01-28 12:53:54 -080031class GrBatch;
joshualitt44701df2015-02-23 14:44:57 -080032class GrClip;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000033class GrDrawTargetCaps;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000034class GrPath;
cdaltonb85a0aa2014-07-21 15:32:44 -070035class GrPathRange;
egdaniele36914c2015-02-13 09:00:33 -080036class GrPipeline;
sugoi@google.com12b4e272012-12-06 20:13:11 +000037
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000038class GrDrawTarget : public SkRefCnt {
bsalomon@google.comf6601872012-08-28 21:11:35 +000039public:
40 SK_DECLARE_INST_COUNT(GrDrawTarget)
41
cdalton55b24af2014-11-25 11:00:56 -080042 typedef GrPathRange::PathIndexType PathIndexType;
43 typedef GrPathRendering::PathTransformType PathTransformType;
kkinnunenccdaa042014-08-20 01:36:23 -070044
reed@google.comac10a2d2010-12-22 21:39:39 +000045 ///////////////////////////////////////////////////////////////////////////
46
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000047 // The context may not be fully constructed and should not be used during GrDrawTarget
48 // construction.
49 GrDrawTarget(GrContext* context);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000050 virtual ~GrDrawTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +000051
52 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000053 * Gets the capabilities of the draw target.
54 */
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000055 const GrDrawTargetCaps* caps() const { return fCaps.get(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000056
57 /**
bsalomonf90a02b2014-11-26 12:28:00 -080058 * There are two types of "sources" of geometry (vertices and indices) for
bsalomon@google.come3d70952012-03-13 12:40:53 +000059 * draw calls made on the target. When performing an indexed draw, the
60 * indices and vertices can use different source types. Once a source is
bsalomon@google.com934c5702012-03-20 21:17:58 +000061 * specified it can be used for multiple draws. However, the time at which
62 * the geometry data is no longer editable depends on the source type.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000063 *
64 * Sometimes it is necessary to perform a draw while upstack code has
bsalomon@google.come3d70952012-03-13 12:40:53 +000065 * already specified geometry that it isn't finished with. So there are push
66 * and pop methods. This allows the client to push the sources, draw
67 * something using alternate sources, and then pop to restore the original
68 * sources.
bsalomon@google.com1c13c962011-02-14 16:51:21 +000069 *
bsalomon@google.come3d70952012-03-13 12:40:53 +000070 * Aside from pushes and pops, a source remains valid until another source
71 * is set or resetVertexSource / resetIndexSource is called. Drawing from
72 * a reset source is an error.
73 *
bsalomonf90a02b2014-11-26 12:28:00 -080074 * The two types of sources are:
bsalomon@google.come3d70952012-03-13 12:40:53 +000075 *
bsalomonf90a02b2014-11-26 12:28:00 -080076 * 1. Reserve. This is most useful when the caller has data it must
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000077 * transform before drawing and is not long-lived. The caller requests
78 * that the draw target make room for some amount of vertex and/or index
79 * data. The target provides ptrs to hold the vertex and/or index data.
80 *
rmistry@google.comd6176b02012-08-23 18:14:13 +000081 * The data is writable up until the next drawIndexed, drawNonIndexed,
bsalomon@google.come4617bf2013-04-03 14:56:40 +000082 * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At
83 * this point the data is frozen and the ptrs are no longer valid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +000084 *
bsalomon@google.come3d70952012-03-13 12:40:53 +000085 * Where the space is allocated and how it is uploaded to the GPU is
86 * subclass-dependent.
87 *
bsalomonf90a02b2014-11-26 12:28:00 -080088 * 2. Vertex and Index Buffers. This is most useful for geometry that will
bsalomon@google.come3d70952012-03-13 12:40:53 +000089 * is long-lived. When the data in the buffer is consumed depends on the
rmistry@google.comd6176b02012-08-23 18:14:13 +000090 * GrDrawTarget subclass. For deferred subclasses the caller has to
bsalomon@google.come3d70952012-03-13 12:40:53 +000091 * guarantee that the data is still available in the buffers at playback.
92 * (TODO: Make this more automatic as we have done for read/write pixels)
bsalomon@google.com1c13c962011-02-14 16:51:21 +000093 */
94
95 /**
bsalomon@google.come3d70952012-03-13 12:40:53 +000096 * Reserves space for vertices and/or indices. Zero can be specifed as
97 * either the vertex or index count if the caller desires to only reserve
rmistry@google.comd6176b02012-08-23 18:14:13 +000098 * space for only indices or only vertices. If zero is specifed for
bsalomon@google.come3d70952012-03-13 12:40:53 +000099 * vertexCount then the vertex source will be unmodified and likewise for
100 * indexCount.
reed@google.comac10a2d2010-12-22 21:39:39 +0000101 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000102 * If the function returns true then the reserve suceeded and the vertices
103 * and indices pointers will point to the space created.
reed@google.comac10a2d2010-12-22 21:39:39 +0000104 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000105 * If the target cannot make space for the request then this function will
106 * return false. If vertexCount was non-zero then upon failure the vertex
107 * source is reset and likewise for indexCount.
reed@google.comac10a2d2010-12-22 21:39:39 +0000108 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000109 * The pointers to the space allocated for vertices and indices remain valid
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000110 * until a drawIndexed, drawNonIndexed, drawIndexedInstances, drawRect,
111 * copySurface, or push/popGeomtrySource is called. At that point logically a
112 * snapshot of the data is made and the pointers are invalid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000113 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000114 * @param vertexCount the number of vertices to reserve space for. Can be
egdaniel8dd688b2015-01-22 10:16:09 -0800115 * 0. Vertex size is queried from the current GrPipelineBuilder.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000116 * @param indexCount the number of indices to reserve space for. Can be 0.
bsalomon@google.come3d70952012-03-13 12:40:53 +0000117 * @param vertices will point to reserved vertex space if vertexCount is
rmistry@google.comd6176b02012-08-23 18:14:13 +0000118 * non-zero. Illegal to pass NULL if vertexCount > 0.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000119 * @param indices will point to reserved index space if indexCount is
120 * non-zero. Illegal to pass NULL if indexCount > 0.
121 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000122 bool reserveVertexAndIndexSpace(int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800123 size_t vertexStride,
bsalomon@google.com97805382012-03-13 14:32:07 +0000124 int indexCount,
125 void** vertices,
126 void** indices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000127
reed@google.comac10a2d2010-12-22 21:39:39 +0000128 /**
129 * Provides hints to caller about the number of vertices and indices
130 * that can be allocated cheaply. This can be useful if caller is reserving
131 * space but doesn't know exactly how much geometry is needed.
132 *
133 * Also may hint whether the draw target should be flushed first. This is
134 * useful for deferred targets.
135 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000136 * @param vertexCount in: hint about how many vertices the caller would
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000137 * like to allocate. Vertex size is queried from the
egdaniel8dd688b2015-01-22 10:16:09 -0800138 * current GrPipelineBuilder.
reed@google.comac10a2d2010-12-22 21:39:39 +0000139 * out: a hint about the number of vertices that can be
140 * allocated cheaply. Negative means no hint.
141 * Ignored if NULL.
142 * @param indexCount in: hint about how many indices the caller would
143 * like to allocate.
144 * out: a hint about the number of indices that can be
145 * allocated cheaply. Negative means no hint.
146 * Ignored if NULL.
147 *
148 * @return true if target should be flushed based on the input values.
149 */
joshualitt9853cce2014-11-17 14:22:48 -0800150 virtual bool geometryHints(size_t vertexStride, int* vertexCount, int* indexCount) const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000151
152 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000153 * Sets source of vertex data for the next draw. Data does not have to be
bsalomon@google.com934c5702012-03-20 21:17:58 +0000154 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
reed@google.comac10a2d2010-12-22 21:39:39 +0000155 *
156 * @param buffer vertex buffer containing vertex data. Must be
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000157 * unlocked before draw call. Vertex size is queried
egdaniel8dd688b2015-01-22 10:16:09 -0800158 * from current GrPipelineBuilder.
reed@google.comac10a2d2010-12-22 21:39:39 +0000159 */
joshualitt9853cce2014-11-17 14:22:48 -0800160 void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride);
reed@google.comac10a2d2010-12-22 21:39:39 +0000161
162 /**
163 * Sets source of index data for the next indexed draw. Data does not have
bsalomon@google.com934c5702012-03-20 21:17:58 +0000164 * to be in the buffer until drawIndexed.
reed@google.comac10a2d2010-12-22 21:39:39 +0000165 *
166 * @param buffer index buffer containing indices. Must be unlocked
167 * before indexed draw call.
168 */
169 void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000170
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000171 /**
172 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
173 * source to reserved, array, or buffer before next draw. May be able to free
174 * up temporary storage allocated by setVertexSourceToArray or
175 * reserveVertexSpace.
176 */
177 void resetVertexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000178
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000179 /**
180 * Resets index source. Indexed Drawing from reset indices is illegal. Set
181 * index source to reserved, array, or buffer before next indexed draw. May
182 * be able to free up temporary storage allocated by setIndexSourceToArray
183 * or reserveIndexSpace.
184 */
bsalomon@google.com97805382012-03-13 14:32:07 +0000185 void resetIndexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000186
bsalomon@google.com97805382012-03-13 14:32:07 +0000187 /**
188 * Query to find out if the vertex or index source is reserved.
189 */
190 bool hasReservedVerticesOrIndices() const {
bsalomon@google.com73d98aa2012-03-13 14:41:19 +0000191 return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc ||
bsalomon@google.com97805382012-03-13 14:32:07 +0000192 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
193 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000194
195 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000196 * Pushes and resets the vertex/index sources. Any reserved vertex / index
197 * data is finalized (i.e. cannot be updated after the matching pop but can
198 * be drawn from). Must be balanced by a pop.
199 */
200 void pushGeometrySource();
201
202 /**
203 * Pops the vertex / index sources from the matching push.
204 */
205 void popGeometrySource();
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000206
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000207 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000208 * Draws indexed geometry using the current state and current vertex / index
209 * sources.
210 *
211 * @param type The type of primitives to draw.
212 * @param startVertex the vertex in the vertex array/buffer corresponding
213 * to index 0
214 * @param startIndex first index to read from index src.
215 * @param vertexCount one greater than the max index.
216 * @param indexCount the number of index elements to read. The index count
217 * is effectively trimmed to the last completely
218 * specified primitive.
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000219 * @param devBounds optional bounds hint. This is a promise from the caller,
220 * not a request for clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000221 */
egdaniel8dd688b2015-01-22 10:16:09 -0800222 void drawIndexed(GrPipelineBuilder*,
joshualitt56995b52014-12-11 15:44:02 -0800223 const GrGeometryProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800224 GrPrimitiveType type,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000225 int startVertex,
226 int startIndex,
227 int vertexCount,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000228 int indexCount,
229 const SkRect* devBounds = NULL);
reed@google.comac10a2d2010-12-22 21:39:39 +0000230
231 /**
232 * Draws non-indexed geometry using the current state and current vertex
233 * sources.
234 *
235 * @param type The type of primitives to draw.
236 * @param startVertex the vertex in the vertex array/buffer corresponding
237 * to index 0
238 * @param vertexCount one greater than the max index.
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 */
egdaniel8dd688b2015-01-22 10:16:09 -0800242 void drawNonIndexed(GrPipelineBuilder*,
joshualitt56995b52014-12-11 15:44:02 -0800243 const GrGeometryProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800244 GrPrimitiveType type,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000245 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000246 int vertexCount,
247 const SkRect* devBounds = NULL);
reed@google.comac10a2d2010-12-22 21:39:39 +0000248
joshualitt4d8da812015-01-28 12:53:54 -0800249 // TODO devbounds should live on the batch
joshualitt44701df2015-02-23 14:44:57 -0800250 void drawBatch(GrPipelineBuilder*, GrBatch*, const SkRect* devBounds = NULL);
joshualitt4d8da812015-01-28 12:53:54 -0800251
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000252 /**
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000253 * Draws path into the stencil buffer. The fill must be either even/odd or
254 * winding (not inverse or hairline). It will respect the HW antialias flag
egdaniel8dd688b2015-01-22 10:16:09 -0800255 * on the GrPipelineBuilder (if possible in the 3D API). Note, we will never have an inverse
256 * fill with stencil path
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000257 */
egdaniel8dd688b2015-01-22 10:16:09 -0800258 void stencilPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*,
259 GrPathRendering::FillType);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000260
261 /**
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000262 * Draws a path. Fill must not be a hairline. It will respect the HW
egdaniel8dd688b2015-01-22 10:16:09 -0800263 * antialias flag on the GrPipelineBuilder (if possible in the 3D API).
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000264 */
egdaniel8dd688b2015-01-22 10:16:09 -0800265 void drawPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*,
266 GrPathRendering::FillType);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000267
268 /**
cdalton55b24af2014-11-25 11:00:56 -0800269 * Draws the aggregate path from combining multiple. Note that this will not
270 * always be equivalent to back-to-back calls to drawPath(). It will respect
egdaniel8dd688b2015-01-22 10:16:09 -0800271 * the HW antialias flag on the GrPipelineBuilder (if possible in the 3D API).
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000272 *
cdalton55b24af2014-11-25 11:00:56 -0800273 * @param pathRange Source paths to draw from
274 * @param indices Array of path indices to draw
275 * @param indexType Data type of the array elements in indexBuffer
276 * @param transformValues Array of transforms for the individual paths
277 * @param transformType Type of transforms in transformBuffer
278 * @param count Number of paths to draw
cdaltonb85a0aa2014-07-21 15:32:44 -0700279 * @param fill Fill type for drawing all the paths
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000280 */
egdaniel8dd688b2015-01-22 10:16:09 -0800281 void drawPaths(GrPipelineBuilder*,
joshualitt56995b52014-12-11 15:44:02 -0800282 const GrPathProcessor*,
joshualitt2e3b3e32014-12-09 13:31:14 -0800283 const GrPathRange* pathRange,
cdalton55b24af2014-11-25 11:00:56 -0800284 const void* indices,
285 PathIndexType indexType,
286 const float transformValues[],
287 PathTransformType transformType,
joshualitt9853cce2014-11-17 14:22:48 -0800288 int count,
joshualitt92e496f2014-10-31 13:56:50 -0700289 GrPathRendering::FillType fill);
cdaltonb85a0aa2014-07-21 15:32:44 -0700290
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000291 /**
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000292 * Helper function for drawing rects. It performs a geometry src push and pop
293 * and thus will finalize any reserved geometry.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000294 *
bsalomon@google.comc7818882013-03-20 19:19:53 +0000295 * @param rect the rect to draw
bsalomon@google.comc7818882013-03-20 19:19:53 +0000296 * @param localRect optional rect that specifies local coords to map onto
297 * rect. If NULL then rect serves as the local coords.
joshualitt8fc6c2d2014-12-22 15:27:05 -0800298 * @param localMatrix Optional local matrix. The local coordinates are specified by localRect,
299 * or if it is NULL by rect. This matrix applies to the coordinate implied by
300 * that rectangle before it is input to GrCoordTransforms that read local
301 * coordinates
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000302 */
joshualitt4d8da812015-01-28 12:53:54 -0800303 void drawRect(GrPipelineBuilder* pipelineBuilder,
joshualitt2e3b3e32014-12-09 13:31:14 -0800304 GrColor color,
joshualitt8059eb92014-12-29 15:10:07 -0800305 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -0800306 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000307 const SkRect* localRect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000308 const SkMatrix* localMatrix) {
joshualitt4d8da812015-01-28 12:53:54 -0800309 this->onDrawRect(pipelineBuilder, color, viewMatrix, rect, localRect, localMatrix);
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000310 }
jvanverth@google.com39768252013-02-14 15:25:44 +0000311
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000312 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000313 * Helper for drawRect when the caller doesn't need separate local rects or matrices.
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000314 */
egdaniel8dd688b2015-01-22 10:16:09 -0800315 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM,
316 const SkRect& rect) {
joshualitt8059eb92014-12-29 15:10:07 -0800317 this->drawRect(ds, color, viewM, rect, NULL, NULL);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000318 }
egdaniel8dd688b2015-01-22 10:16:09 -0800319 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM,
joshualitt8059eb92014-12-29 15:10:07 -0800320 const SkIRect& irect) {
reed@google.com44699382013-10-31 17:28:30 +0000321 SkRect rect = SkRect::Make(irect);
joshualitt8059eb92014-12-29 15:10:07 -0800322 this->drawRect(ds, color, viewM, rect, NULL, NULL);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000323 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000324
325 /**
bsalomon@google.com934c5702012-03-20 21:17:58 +0000326 * This call is used to draw multiple instances of some geometry with a
327 * given number of vertices (V) and indices (I) per-instance. The indices in
328 * the index source must have the form i[k+I] == i[k] + V. Also, all indices
329 * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a
330 * concrete example, the following index buffer for drawing a series of
331 * quads each as two triangles each satisfies these conditions with V=4 and
332 * I=6:
333 * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...)
334 *
335 * The call assumes that the pattern of indices fills the entire index
336 * source. The size of the index buffer limits the number of instances that
337 * can be drawn by the GPU in a single draw. However, the caller may specify
338 * any (positive) number for instanceCount and if necessary multiple GPU
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000339 * draws will be issued. Moreover, when drawIndexedInstances is called
bsalomon@google.com934c5702012-03-20 21:17:58 +0000340 * multiple times it may be possible for GrDrawTarget to group them into a
341 * single GPU draw.
342 *
343 * @param type the type of primitives to draw
344 * @param instanceCount the number of instances to draw. Each instance
345 * consists of verticesPerInstance vertices indexed by
346 * indicesPerInstance indices drawn as the primitive
347 * type specified by type.
348 * @param verticesPerInstance The number of vertices in each instance (V
349 * in the above description).
350 * @param indicesPerInstance The number of indices in each instance (I
351 * in the above description).
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000352 * @param devBounds optional bounds hint. This is a promise from the caller,
353 * not a request for clipping.
bsalomon@google.com934c5702012-03-20 21:17:58 +0000354 */
egdaniel8dd688b2015-01-22 10:16:09 -0800355 void drawIndexedInstances(GrPipelineBuilder*,
joshualitt56995b52014-12-11 15:44:02 -0800356 const GrGeometryProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800357 GrPrimitiveType type,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000358 int instanceCount,
359 int verticesPerInstance,
360 int indicesPerInstance,
361 const SkRect* devBounds = NULL);
bsalomon@google.com934c5702012-03-20 21:17:58 +0000362
363 /**
egdaniel8dd688b2015-01-22 10:16:09 -0800364 * Clear the passed in render target. Ignores the GrPipelineBuilder and clip. Clears the whole
365 * thing if rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire
366 * render target can be optionally cleared.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000367 */
joshualitt9853cce2014-11-17 14:22:48 -0800368 void clear(const SkIRect* rect,
369 GrColor color,
370 bool canIgnoreRect,
bsalomon63b21962014-11-05 07:05:34 -0800371 GrRenderTarget* renderTarget);
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000372
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000373 /**
bsalomon89c62982014-11-03 12:08:42 -0800374 * Discards the contents render target.
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000375 **/
bsalomon89c62982014-11-03 12:08:42 -0800376 virtual void discard(GrRenderTarget*) = 0;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000377
378 /**
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000379 * Called at start and end of gpu trace marking
380 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start
381 * and end of a code block respectively
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000382 */
egdaniel3eee3832014-06-18 13:09:11 -0700383 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
384 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
385
386 /**
387 * Takes the current active set of markers and stores them for later use. Any current marker
388 * in the active set is removed from the active set and the targets remove function is called.
389 * These functions do not work as a stack so you cannot call save a second time before calling
390 * restore. Also, it is assumed that when restore is called the current active set of markers
391 * is empty. When the stored markers are added back into the active set, the targets add marker
392 * is called.
393 */
394 void saveActiveTraceMarkers();
395 void restoreActiveTraceMarkers();
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000396
397 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000398 * Copies a pixel rectangle from one surface to another. This call may finalize
399 * reserved vertex/index data (as though a draw call was made). The src pixels
400 * copied are specified by srcRect. They are copied to a rect of the same
401 * size in dst with top left at dstPoint. If the src rect is clipped by the
402 * src bounds then pixel values in the dst rect corresponding to area clipped
403 * by the src rect are not overwritten. This method can fail and return false
404 * depending on the type of surface, configs, etc, and the backend-specific
405 * limitations. If rect is clipped out entirely by the src or dst bounds then
406 * true is returned since there is no actual copy necessary to succeed.
407 */
bsalomonf90a02b2014-11-26 12:28:00 -0800408 bool copySurface(GrSurface* dst,
409 GrSurface* src,
410 const SkIRect& srcRect,
411 const SkIPoint& dstPoint);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000412 /**
bsalomonf90a02b2014-11-26 12:28:00 -0800413 * Function that determines whether a copySurface call would succeed without actually
bsalomon@google.com116ad842013-04-09 15:38:19 +0000414 * performing the copy.
415 */
bsalomonf90a02b2014-11-26 12:28:00 -0800416 bool canCopySurface(const GrSurface* dst,
417 const GrSurface* src,
418 const SkIRect& srcRect,
419 const SkIPoint& dstPoint);
bsalomon@google.comeb851172013-04-15 13:51:00 +0000420
421 /**
robertphillips@google.comff175842012-05-14 19:31:39 +0000422 * Release any resources that are cached but not currently in use. This
423 * is intended to give an application some recourse when resources are low.
424 */
425 virtual void purgeResources() {};
426
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000427 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000428
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000429 class AutoReleaseGeometry : public ::SkNoncopyable {
reed@google.comac10a2d2010-12-22 21:39:39 +0000430 public:
431 AutoReleaseGeometry(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000432 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800433 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000434 int indexCount);
435 AutoReleaseGeometry();
436 ~AutoReleaseGeometry();
bsalomon@google.com5782d712011-01-21 21:03:59 +0000437 bool set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000438 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800439 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000440 int indexCount);
bsalomon49f085d2014-09-05 13:34:00 -0700441 bool succeeded() const { return SkToBool(fTarget); }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000442 void* vertices() const { SkASSERT(this->succeeded()); return fVertices; }
443 void* indices() const { SkASSERT(this->succeeded()); return fIndices; }
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000444 SkPoint* positions() const {
445 return static_cast<SkPoint*>(this->vertices());
reed@google.comac10a2d2010-12-22 21:39:39 +0000446 }
447
448 private:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000449 void reset();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000450
reed@google.comac10a2d2010-12-22 21:39:39 +0000451 GrDrawTarget* fTarget;
reed@google.comac10a2d2010-12-22 21:39:39 +0000452 void* fVertices;
453 void* fIndices;
454 };
455
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000456 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000457
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000458 /**
459 * Saves the geometry src state at construction and restores in the destructor. It also saves
460 * and then restores the vertex attrib state.
461 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000462 class AutoGeometryPush : public ::SkNoncopyable {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000463 public:
joshualitt9853cce2014-11-17 14:22:48 -0800464 AutoGeometryPush(GrDrawTarget* target) {
bsalomon49f085d2014-09-05 13:34:00 -0700465 SkASSERT(target);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000466 fTarget = target;
467 target->pushGeometrySource();
468 }
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000469
470 ~AutoGeometryPush() { fTarget->popGeometrySource(); }
471
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000472 private:
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000473 GrDrawTarget* fTarget;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000474 };
reed@google.comac10a2d2010-12-22 21:39:39 +0000475
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000476 ///////////////////////////////////////////////////////////////////////////
477 // Draw execution tracking (for font atlases and other resources)
478 class DrawToken {
479 public:
480 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) :
481 fDrawTarget(drawTarget), fDrawID(drawID) {}
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000482
bsalomon49f085d2014-09-05 13:34:00 -0700483 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000484
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000485 private:
486 GrDrawTarget* fDrawTarget;
487 uint32_t fDrawID; // this may wrap, but we're doing direct comparison
488 // so that should be okay
489 };
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000490
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000491 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000492
joshualitt3322fa42014-11-07 08:48:51 -0800493 /**
494 * Used to communicate draws to GPUs / subclasses
495 */
496 class DrawInfo {
497 public:
joshualitt4d8da812015-01-28 12:53:54 -0800498 DrawInfo() { fDevBounds = NULL; }
joshualitt3322fa42014-11-07 08:48:51 -0800499 DrawInfo(const DrawInfo& di) { (*this) = di; }
500 DrawInfo& operator =(const DrawInfo& di);
501
502 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
503 int startVertex() const { return fStartVertex; }
504 int startIndex() const { return fStartIndex; }
505 int vertexCount() const { return fVertexCount; }
506 int indexCount() const { return fIndexCount; }
507 int verticesPerInstance() const { return fVerticesPerInstance; }
508 int indicesPerInstance() const { return fIndicesPerInstance; }
509 int instanceCount() const { return fInstanceCount; }
510
joshualitt4d8da812015-01-28 12:53:54 -0800511 void setPrimitiveType(GrPrimitiveType type) { fPrimitiveType = type; }
512 void setStartVertex(int startVertex) { fStartVertex = startVertex; }
513 void setStartIndex(int startIndex) { fStartIndex = startIndex; }
514 void setVertexCount(int vertexCount) { fVertexCount = vertexCount; }
515 void setIndexCount(int indexCount) { fIndexCount = indexCount; }
516 void setVerticesPerInstance(int verticesPerI) { fVerticesPerInstance = verticesPerI; }
517 void setIndicesPerInstance(int indicesPerI) { fIndicesPerInstance = indicesPerI; }
518 void setInstanceCount(int instanceCount) { fInstanceCount = instanceCount; }
519
joshualitt3322fa42014-11-07 08:48:51 -0800520 bool isIndexed() const { return fIndexCount > 0; }
521#ifdef SK_DEBUG
522 bool isInstanced() const; // this version is longer because of asserts
523#else
524 bool isInstanced() const { return fInstanceCount > 0; }
525#endif
526
527 // adds or remove instances
528 void adjustInstanceCount(int instanceOffset);
529 // shifts the start vertex
530 void adjustStartVertex(int vertexOffset);
531 // shifts the start index
532 void adjustStartIndex(int indexOffset);
533
534 void setDevBounds(const SkRect& bounds) {
535 fDevBoundsStorage = bounds;
536 fDevBounds = &fDevBoundsStorage;
537 }
joshualitt7eb8c7b2014-11-18 14:24:27 -0800538 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
539 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); }
540 void setVertexBuffer(const GrVertexBuffer* vb) {
541 fVertexBuffer.reset(vb);
542 }
543 void setIndexBuffer(const GrIndexBuffer* ib) {
544 fIndexBuffer.reset(ib);
545 }
joshualitt3322fa42014-11-07 08:48:51 -0800546 const SkRect* getDevBounds() const { return fDevBounds; }
547
joshualitt3322fa42014-11-07 08:48:51 -0800548 private:
joshualitt3322fa42014-11-07 08:48:51 -0800549 friend class GrDrawTarget;
550
551 GrPrimitiveType fPrimitiveType;
552
553 int fStartVertex;
554 int fStartIndex;
555 int fVertexCount;
556 int fIndexCount;
557
558 int fInstanceCount;
559 int fVerticesPerInstance;
560 int fIndicesPerInstance;
561
562 SkRect fDevBoundsStorage;
563 SkRect* fDevBounds;
564
joshualitt7eb8c7b2014-11-18 14:24:27 -0800565 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer;
566 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer;
joshualitt3322fa42014-11-07 08:48:51 -0800567 };
joshualitt2c93efe2014-11-06 12:57:13 -0800568
bsalomon371bcbc2014-12-01 08:19:34 -0800569 /**
570 * Used to populate the vertex and index buffer on the draw info before onDraw is called.
571 */
572 virtual void setDrawBuffers(DrawInfo*, size_t vertexStride) = 0;;
joshualitt2c93efe2014-11-06 12:57:13 -0800573 bool programUnitTest(int maxStages);
574
reed@google.comac10a2d2010-12-22 21:39:39 +0000575protected:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000576 enum GeometrySrcType {
577 kNone_GeometrySrcType, //<! src has not been specified
578 kReserved_GeometrySrcType, //<! src was set using reserve*Space
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000579 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
580 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000581
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000582 struct GeometrySrcState {
583 GeometrySrcType fVertexSrc;
584 union {
585 // valid if src type is buffer
586 const GrVertexBuffer* fVertexBuffer;
587 // valid if src type is reserved or array
588 int fVertexCount;
589 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000590
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000591 GeometrySrcType fIndexSrc;
592 union {
593 // valid if src type is buffer
594 const GrIndexBuffer* fIndexBuffer;
595 // valid if src type is reserved or array
596 int fIndexCount;
597 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000598
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000599 size_t fVertexSize;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000600 };
bsalomon@google.com934c5702012-03-20 21:17:58 +0000601
602 int indexCountInCurrentSource() const {
603 const GeometrySrcState& src = this->getGeomSrc();
604 switch (src.fIndexSrc) {
605 case kNone_GeometrySrcType:
606 return 0;
607 case kReserved_GeometrySrcType:
bsalomon@google.com934c5702012-03-20 21:17:58 +0000608 return src.fIndexCount;
609 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000610 return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
bsalomon@google.com934c5702012-03-20 21:17:58 +0000611 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000612 SkFAIL("Unexpected Index Source.");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000613 return 0;
614 }
615 }
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000616
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000617 GrContext* getContext() { return fContext; }
618 const GrContext* getContext() const { return fContext; }
619
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000620 // subclasses must call this in their destructors to ensure all vertex
621 // and index sources have been released (including those held by
622 // pushGeometrySource())
623 void releaseGeometry();
624
625 // accessors for derived classes
626 const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); }
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000627 // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert.
628 size_t getVertexSize() const {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000629 // the vertex layout is only valid if a vertex source has been specified.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000630 SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType);
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000631 return this->getGeomSrc().fVertexSize;
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000632 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000633
bsalomon@google.combcce8922013-03-25 15:38:39 +0000634 // Subclass must initialize this in its constructor.
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000635 SkAutoTUnref<const GrDrawTargetCaps> fCaps;
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000636
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000637 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; }
638
joshualitt65171342014-10-09 07:25:36 -0700639 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
640 // but couldn't be made. Otherwise, returns true. This method needs to be protected because it
641 // needs to be accessed by GLPrograms to setup a correct drawstate
bsalomon50785a32015-02-06 07:02:37 -0800642 bool setupDstReadIfNecessary(const GrPipelineBuilder&,
egdaniele36914c2015-02-13 09:00:33 -0800643 const GrProcOptInfo& colorPOI,
644 const GrProcOptInfo& coveragePOI,
joshualitt9853cce2014-11-17 14:22:48 -0800645 GrDeviceCoordTexture* dstCopy,
646 const SkRect* drawBounds);
joshualitt65171342014-10-09 07:25:36 -0700647
egdaniele36914c2015-02-13 09:00:33 -0800648 struct PipelineInfo {
649 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor,
joshualitt44701df2015-02-23 14:44:57 -0800650 const GrPrimitiveProcessor* primProc,
651 const SkRect* devBounds, GrDrawTarget* target);
egdaniele36914c2015-02-13 09:00:33 -0800652
653 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor,
joshualitt44701df2015-02-23 14:44:57 -0800654 const GrBatch* batch, const SkRect* devBounds,
655 GrDrawTarget* target);
egdaniele36914c2015-02-13 09:00:33 -0800656
657 bool willBlendWithDst(const GrPrimitiveProcessor* primProc) const {
658 return fPipelineBuilder->willBlendWithDst(primProc);
659 }
660 private:
661 friend class GrDrawTarget;
662
663 bool mustSkipDraw() const { return (NULL == fPipelineBuilder); }
664
665 GrPipelineBuilder* fPipelineBuilder;
666 GrScissorState* fScissor;
667 GrProcOptInfo fColorPOI;
668 GrProcOptInfo fCoveragePOI;
669 GrDeviceCoordTexture fDstCopy;
670 };
671
672 void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline);
673
robertphillips54fac8b2015-02-16 09:35:50 -0800674 // A subclass can optionally overload this function to be notified before
675 // vertex and index space is reserved.
676 virtual void willReserveVertexAndIndexSpace(int vertexCount,
677 size_t vertexStride,
678 int indexCount) {}
679
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000680private:
bsalomonf90a02b2014-11-26 12:28:00 -0800681 /**
682 * This will be called before allocating a texture as a dst for copySurface. This function
683 * populates the dstDesc's config, flags, and origin so as to maximize efficiency and guarantee
684 * success of the copySurface call.
685 */
686 void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) {
687 if (!this->onInitCopySurfaceDstDesc(src, dstDesc)) {
688 dstDesc->fOrigin = kDefault_GrSurfaceOrigin;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800689 dstDesc->fFlags = kRenderTarget_GrSurfaceFlag;
bsalomonf90a02b2014-11-26 12:28:00 -0800690 dstDesc->fConfig = src->config();
691 }
692 }
693
694 /** Internal implementation of canCopySurface. */
695 bool internalCanCopySurface(const GrSurface* dst,
696 const GrSurface* src,
697 const SkIRect& clippedSrcRect,
698 const SkIPoint& clippedDstRect);
699
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000700 // implemented by subclass to allocate space for reserved geom
jvanverth@google.coma6338982013-01-31 21:34:25 +0000701 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000702 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
703 // implemented by subclass to handle release of reserved geom space
704 virtual void releaseReservedVertexSpace() = 0;
705 virtual void releaseReservedIndexSpace() = 0;
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000706 // subclass overrides to be notified just before geo src state is pushed/popped.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000707 virtual void geometrySourceWillPush() = 0;
708 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
709 // subclass called to perform drawing
egdaniele36914c2015-02-13 09:00:33 -0800710 virtual void onDraw(const GrGeometryProcessor*, const DrawInfo&, const PipelineInfo&) = 0;
711 virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0;
joshualitt5478d422014-11-14 16:00:38 -0800712 // TODO copy in order drawbuffer onDrawRect to here
egdaniel8dd688b2015-01-22 10:16:09 -0800713 virtual void onDrawRect(GrPipelineBuilder*,
joshualitt2e3b3e32014-12-09 13:31:14 -0800714 GrColor color,
joshualitt8059eb92014-12-29 15:10:07 -0800715 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -0800716 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000717 const SkRect* localRect,
joshualitt5478d422014-11-14 16:00:38 -0800718 const SkMatrix* localMatrix) = 0;
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000719
egdaniel8dd688b2015-01-22 10:16:09 -0800720 virtual void onStencilPath(const GrPipelineBuilder&,
joshualitt56995b52014-12-11 15:44:02 -0800721 const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800722 const GrPath*,
bsalomon3e791242014-12-17 13:43:13 -0800723 const GrScissorState&,
joshualitt2c93efe2014-11-06 12:57:13 -0800724 const GrStencilSettings&) = 0;
egdaniele36914c2015-02-13 09:00:33 -0800725 virtual void onDrawPath(const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800726 const GrPath*,
joshualitt2c93efe2014-11-06 12:57:13 -0800727 const GrStencilSettings&,
egdaniele36914c2015-02-13 09:00:33 -0800728 const PipelineInfo&) = 0;
729 virtual void onDrawPaths(const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800730 const GrPathRange*,
cdalton55b24af2014-11-25 11:00:56 -0800731 const void* indices,
732 PathIndexType,
733 const float transformValues[],
joshualitt2c93efe2014-11-06 12:57:13 -0800734 PathTransformType,
cdalton55b24af2014-11-25 11:00:56 -0800735 int count,
joshualitt2c93efe2014-11-06 12:57:13 -0800736 const GrStencilSettings&,
egdaniele36914c2015-02-13 09:00:33 -0800737 const PipelineInfo&) = 0;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000738
bsalomon63b21962014-11-05 07:05:34 -0800739 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
740 GrRenderTarget* renderTarget) = 0;
741
bsalomonf90a02b2014-11-26 12:28:00 -0800742 /** The subclass will get a chance to copy the surface for falling back to the default
743 implementation, which simply draws a rectangle (and fails if dst isn't a render target). It
744 should assume that any clipping has already been performed on the rect and point. It won't
745 be called if the copy can be skipped. */
746 virtual bool onCopySurface(GrSurface* dst,
747 GrSurface* src,
748 const SkIRect& srcRect,
749 const SkIPoint& dstPoint) = 0;
750
751 /** Indicates whether onCopySurface would succeed. It should assume that any clipping has
752 already been performed on the rect and point. It won't be called if the copy can be
753 skipped. */
754 virtual bool onCanCopySurface(const GrSurface* dst,
755 const GrSurface* src,
756 const SkIRect& srcRect,
757 const SkIPoint& dstPoint) = 0;
758 /**
759 * This will be called before allocating a texture to be a dst for onCopySurface. Only the
760 * dstDesc's config, flags, and origin need be set by the function. If the subclass cannot
761 * create a surface that would succeed its implementation of onCopySurface, it should return
762 * false. The base class will fall back to creating a render target to draw into using the src.
763 */
764 virtual bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) = 0;
bsalomon63b21962014-11-05 07:05:34 -0800765
bsalomon@google.come3d70952012-03-13 12:40:53 +0000766 // helpers for reserving vertex and index space.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000767 bool reserveVertexSpace(size_t vertexSize,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000768 int vertexCount,
769 void** vertices);
770 bool reserveIndexSpace(int indexCount, void** indices);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000771
bsalomon@google.come8262622011-11-07 02:30:51 +0000772 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to
773 // indicate non-indexed drawing.
egdaniel8dd688b2015-01-22 10:16:09 -0800774 bool checkDraw(const GrPipelineBuilder&,
joshualitt56995b52014-12-11 15:44:02 -0800775 const GrGeometryProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800776 GrPrimitiveType type,
777 int startVertex,
778 int startIndex,
779 int vertexCount,
bsalomon@google.come8262622011-11-07 02:30:51 +0000780 int indexCount) const;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000781 // called when setting a new vert/idx source to unref prev vb/ib
782 void releasePreviousVertexSource();
783 void releasePreviousIndexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000784
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000785 // Check to see if this set of draw commands has been sent out
786 virtual bool isIssued(uint32_t drawID) { return true; }
joshualitt9853cce2014-11-17 14:22:48 -0800787 void getPathStencilSettingsForFilltype(GrPathRendering::FillType,
788 const GrStencilBuffer*,
789 GrStencilSettings*);
joshualitta7024152014-11-03 14:16:35 -0800790 virtual GrClipMaskManager* clipMaskManager() = 0;
egdaniel8dd688b2015-01-22 10:16:09 -0800791 virtual bool setupClip(GrPipelineBuilder*,
bsalomon6be6f7c2015-02-26 13:05:21 -0800792 GrPipelineBuilder::AutoRestoreFragmentProcessors*,
793 GrPipelineBuilder::AutoRestoreStencil*,
794 GrScissorState*,
joshualitt8059eb92014-12-29 15:10:07 -0800795 const SkRect* devBounds) = 0;
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000796
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000797 enum {
798 kPreallocGeoSrcStateStackCnt = 4,
reed@google.comac10a2d2010-12-22 21:39:39 +0000799 };
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000800 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000801 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget.
802 GrContext* fContext;
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000803 // To keep track that we always have at least as many debug marker adds as removes
804 int fGpuTraceMarkerCount;
805 GrTraceMarkerSet fActiveTraceMarkers;
egdaniel3eee3832014-06-18 13:09:11 -0700806 GrTraceMarkerSet fStoredTraceMarkers;
reed@google.comfa35e3d2012-06-26 20:16:17 +0000807
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000808 typedef SkRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000809};
810
joshualitt329bf482014-10-29 12:31:28 -0700811/*
812 * This class is JUST for clip mask manager. Everyone else should just use draw target above.
813 */
joshualitt6db519c2014-10-29 08:48:18 -0700814class GrClipTarget : public GrDrawTarget {
815public:
joshualitt329bf482014-10-29 12:31:28 -0700816 GrClipTarget(GrContext* context) : INHERITED(context) {
817 fClipMaskManager.setClipTarget(this);
818 }
819
820 /* Clip mask manager needs access to the context.
821 * TODO we only need a very small subset of context in the CMM.
822 */
823 GrContext* getContext() { return INHERITED::getContext(); }
824 const GrContext* getContext() const { return INHERITED::getContext(); }
825
joshualitt6db519c2014-10-29 08:48:18 -0700826 /**
827 * Clip Mask Manager(and no one else) needs to clear private stencil bits.
828 * ClipTarget subclass sets clip bit in the stencil buffer. The subclass
829 * is free to clear the remaining bits to zero if masked clears are more
830 * expensive than clearing all bits.
831 */
832 virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0;
833
joshualitt3bdd7dc2014-10-31 08:27:39 -0700834 /**
835 * Release any resources that are cached but not currently in use. This
836 * is intended to give an application some recourse when resources are low.
837 */
mtklein72c9faa2015-01-09 10:06:39 -0800838 void purgeResources() SK_OVERRIDE {
joshualitt3bdd7dc2014-10-31 08:27:39 -0700839 // The clip mask manager can rebuild all its clip masks so just
840 // get rid of them all.
841 fClipMaskManager.purgeResources();
842 };
843
joshualitt329bf482014-10-29 12:31:28 -0700844protected:
845 GrClipMaskManager fClipMaskManager;
846
joshualitt6db519c2014-10-29 08:48:18 -0700847private:
tfarina912ed6e2014-12-14 15:20:10 -0800848 GrClipMaskManager* clipMaskManager() SK_OVERRIDE { return &fClipMaskManager; }
joshualitt329bf482014-10-29 12:31:28 -0700849
egdaniel8dd688b2015-01-22 10:16:09 -0800850 virtual bool setupClip(GrPipelineBuilder*,
bsalomon6be6f7c2015-02-26 13:05:21 -0800851 GrPipelineBuilder::AutoRestoreFragmentProcessors*,
852 GrPipelineBuilder::AutoRestoreStencil*,
joshualitt8059eb92014-12-29 15:10:07 -0800853 GrScissorState* scissorState,
854 const SkRect* devBounds) SK_OVERRIDE;
joshualitt2c93efe2014-11-06 12:57:13 -0800855
joshualitt6db519c2014-10-29 08:48:18 -0700856 typedef GrDrawTarget INHERITED;
857};
858
reed@google.comac10a2d2010-12-22 21:39:39 +0000859#endif