blob: 1d07b9eec22725e6695fcde68d0d49a76335bc04 [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;
joshualitt5bf99f12015-03-13 11:47:42 -070034class GrGeometryProcessor;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000035class GrPath;
cdaltonb85a0aa2014-07-21 15:32:44 -070036class GrPathRange;
egdaniele36914c2015-02-13 09:00:33 -080037class GrPipeline;
sugoi@google.com12b4e272012-12-06 20:13:11 +000038
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000039class GrDrawTarget : public SkRefCnt {
bsalomon@google.comf6601872012-08-28 21:11:35 +000040public:
41 SK_DECLARE_INST_COUNT(GrDrawTarget)
42
cdalton55b24af2014-11-25 11:00:56 -080043 typedef GrPathRange::PathIndexType PathIndexType;
44 typedef GrPathRendering::PathTransformType PathTransformType;
kkinnunenccdaa042014-08-20 01:36:23 -070045
reed@google.comac10a2d2010-12-22 21:39:39 +000046 ///////////////////////////////////////////////////////////////////////////
47
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000048 // The context may not be fully constructed and should not be used during GrDrawTarget
49 // construction.
50 GrDrawTarget(GrContext* context);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000051 virtual ~GrDrawTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +000052
53 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000054 * Gets the capabilities of the draw target.
55 */
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000056 const GrDrawTargetCaps* caps() const { return fCaps.get(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000057
58 /**
bsalomonf90a02b2014-11-26 12:28:00 -080059 * There are two types of "sources" of geometry (vertices and indices) for
bsalomon@google.come3d70952012-03-13 12:40:53 +000060 * draw calls made on the target. When performing an indexed draw, the
61 * indices and vertices can use different source types. Once a source is
bsalomon@google.com934c5702012-03-20 21:17:58 +000062 * specified it can be used for multiple draws. However, the time at which
63 * the geometry data is no longer editable depends on the source type.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000064 *
65 * Sometimes it is necessary to perform a draw while upstack code has
bsalomon@google.come3d70952012-03-13 12:40:53 +000066 * already specified geometry that it isn't finished with. So there are push
67 * and pop methods. This allows the client to push the sources, draw
68 * something using alternate sources, and then pop to restore the original
69 * sources.
bsalomon@google.com1c13c962011-02-14 16:51:21 +000070 *
bsalomon@google.come3d70952012-03-13 12:40:53 +000071 * Aside from pushes and pops, a source remains valid until another source
72 * is set or resetVertexSource / resetIndexSource is called. Drawing from
73 * a reset source is an error.
74 *
bsalomonf90a02b2014-11-26 12:28:00 -080075 * The two types of sources are:
bsalomon@google.come3d70952012-03-13 12:40:53 +000076 *
bsalomonf90a02b2014-11-26 12:28:00 -080077 * 1. Reserve. This is most useful when the caller has data it must
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000078 * transform before drawing and is not long-lived. The caller requests
79 * that the draw target make room for some amount of vertex and/or index
80 * data. The target provides ptrs to hold the vertex and/or index data.
81 *
rmistry@google.comd6176b02012-08-23 18:14:13 +000082 * The data is writable up until the next drawIndexed, drawNonIndexed,
bsalomon@google.come4617bf2013-04-03 14:56:40 +000083 * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At
84 * this point the data is frozen and the ptrs are no longer valid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +000085 *
bsalomon@google.come3d70952012-03-13 12:40:53 +000086 * Where the space is allocated and how it is uploaded to the GPU is
87 * subclass-dependent.
88 *
bsalomonf90a02b2014-11-26 12:28:00 -080089 * 2. Vertex and Index Buffers. This is most useful for geometry that will
bsalomon@google.come3d70952012-03-13 12:40:53 +000090 * is long-lived. When the data in the buffer is consumed depends on the
rmistry@google.comd6176b02012-08-23 18:14:13 +000091 * GrDrawTarget subclass. For deferred subclasses the caller has to
bsalomon@google.come3d70952012-03-13 12:40:53 +000092 * guarantee that the data is still available in the buffers at playback.
93 * (TODO: Make this more automatic as we have done for read/write pixels)
bsalomon@google.com1c13c962011-02-14 16:51:21 +000094 */
95
96 /**
bsalomon@google.come3d70952012-03-13 12:40:53 +000097 * Reserves space for vertices and/or indices. Zero can be specifed as
98 * either the vertex or index count if the caller desires to only reserve
rmistry@google.comd6176b02012-08-23 18:14:13 +000099 * space for only indices or only vertices. If zero is specifed for
bsalomon@google.come3d70952012-03-13 12:40:53 +0000100 * vertexCount then the vertex source will be unmodified and likewise for
101 * indexCount.
reed@google.comac10a2d2010-12-22 21:39:39 +0000102 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000103 * If the function returns true then the reserve suceeded and the vertices
104 * and indices pointers will point to the space created.
reed@google.comac10a2d2010-12-22 21:39:39 +0000105 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000106 * If the target cannot make space for the request then this function will
107 * return false. If vertexCount was non-zero then upon failure the vertex
108 * source is reset and likewise for indexCount.
reed@google.comac10a2d2010-12-22 21:39:39 +0000109 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000110 * The pointers to the space allocated for vertices and indices remain valid
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000111 * until a drawIndexed, drawNonIndexed, drawIndexedInstances, drawRect,
112 * copySurface, or push/popGeomtrySource is called. At that point logically a
113 * snapshot of the data is made and the pointers are invalid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000114 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000115 * @param vertexCount the number of vertices to reserve space for. Can be
egdaniel8dd688b2015-01-22 10:16:09 -0800116 * 0. Vertex size is queried from the current GrPipelineBuilder.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000117 * @param indexCount the number of indices to reserve space for. Can be 0.
bsalomon@google.come3d70952012-03-13 12:40:53 +0000118 * @param vertices will point to reserved vertex space if vertexCount is
rmistry@google.comd6176b02012-08-23 18:14:13 +0000119 * non-zero. Illegal to pass NULL if vertexCount > 0.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000120 * @param indices will point to reserved index space if indexCount is
121 * non-zero. Illegal to pass NULL if indexCount > 0.
122 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000123 bool reserveVertexAndIndexSpace(int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800124 size_t vertexStride,
bsalomon@google.com97805382012-03-13 14:32:07 +0000125 int indexCount,
126 void** vertices,
127 void** indices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000128
reed@google.comac10a2d2010-12-22 21:39:39 +0000129 /**
130 * Provides hints to caller about the number of vertices and indices
131 * that can be allocated cheaply. This can be useful if caller is reserving
132 * space but doesn't know exactly how much geometry is needed.
133 *
134 * Also may hint whether the draw target should be flushed first. This is
135 * useful for deferred targets.
136 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000137 * @param vertexCount in: hint about how many vertices the caller would
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000138 * like to allocate. Vertex size is queried from the
egdaniel8dd688b2015-01-22 10:16:09 -0800139 * current GrPipelineBuilder.
reed@google.comac10a2d2010-12-22 21:39:39 +0000140 * out: a hint about the number of vertices that can be
141 * allocated cheaply. Negative means no hint.
142 * Ignored if NULL.
143 * @param indexCount in: hint about how many indices the caller would
144 * like to allocate.
145 * out: a hint about the number of indices that can be
146 * allocated cheaply. Negative means no hint.
147 * Ignored if NULL.
148 *
149 * @return true if target should be flushed based on the input values.
150 */
joshualitt9853cce2014-11-17 14:22:48 -0800151 virtual bool geometryHints(size_t vertexStride, int* vertexCount, int* indexCount) const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000152
153 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000154 * Sets source of vertex data for the next draw. Data does not have to be
bsalomon@google.com934c5702012-03-20 21:17:58 +0000155 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
reed@google.comac10a2d2010-12-22 21:39:39 +0000156 *
157 * @param buffer vertex buffer containing vertex data. Must be
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000158 * unlocked before draw call. Vertex size is queried
egdaniel8dd688b2015-01-22 10:16:09 -0800159 * from current GrPipelineBuilder.
reed@google.comac10a2d2010-12-22 21:39:39 +0000160 */
joshualitt9853cce2014-11-17 14:22:48 -0800161 void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride);
reed@google.comac10a2d2010-12-22 21:39:39 +0000162
163 /**
164 * Sets source of index data for the next indexed draw. Data does not have
bsalomon@google.com934c5702012-03-20 21:17:58 +0000165 * to be in the buffer until drawIndexed.
reed@google.comac10a2d2010-12-22 21:39:39 +0000166 *
167 * @param buffer index buffer containing indices. Must be unlocked
168 * before indexed draw call.
169 */
170 void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000171
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000172 /**
173 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
174 * source to reserved, array, or buffer before next draw. May be able to free
175 * up temporary storage allocated by setVertexSourceToArray or
176 * reserveVertexSpace.
177 */
178 void resetVertexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000179
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000180 /**
181 * Resets index source. Indexed Drawing from reset indices is illegal. Set
182 * index source to reserved, array, or buffer before next indexed draw. May
183 * be able to free up temporary storage allocated by setIndexSourceToArray
184 * or reserveIndexSpace.
185 */
bsalomon@google.com97805382012-03-13 14:32:07 +0000186 void resetIndexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000187
bsalomon@google.com97805382012-03-13 14:32:07 +0000188 /**
189 * Query to find out if the vertex or index source is reserved.
190 */
191 bool hasReservedVerticesOrIndices() const {
bsalomon@google.com73d98aa2012-03-13 14:41:19 +0000192 return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc ||
bsalomon@google.com97805382012-03-13 14:32:07 +0000193 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
194 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000195
196 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000197 * Pushes and resets the vertex/index sources. Any reserved vertex / index
198 * data is finalized (i.e. cannot be updated after the matching pop but can
199 * be drawn from). Must be balanced by a pop.
200 */
201 void pushGeometrySource();
202
203 /**
204 * Pops the vertex / index sources from the matching push.
205 */
206 void popGeometrySource();
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000207
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000208 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000209 * Draws indexed geometry using the current state and current vertex / index
210 * sources.
211 *
212 * @param type The type of primitives to draw.
213 * @param startVertex the vertex in the vertex array/buffer corresponding
214 * to index 0
215 * @param startIndex first index to read from index src.
216 * @param vertexCount one greater than the max index.
217 * @param indexCount the number of index elements to read. The index count
218 * is effectively trimmed to the last completely
219 * specified primitive.
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000220 * @param devBounds optional bounds hint. This is a promise from the caller,
221 * not a request for clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000222 */
egdaniel8dd688b2015-01-22 10:16:09 -0800223 void drawIndexed(GrPipelineBuilder*,
joshualitt56995b52014-12-11 15:44:02 -0800224 const GrGeometryProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800225 GrPrimitiveType type,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000226 int startVertex,
227 int startIndex,
228 int vertexCount,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000229 int indexCount,
230 const SkRect* devBounds = NULL);
reed@google.comac10a2d2010-12-22 21:39:39 +0000231
232 /**
233 * Draws non-indexed geometry using the current state and current vertex
234 * sources.
235 *
236 * @param type The type of primitives to draw.
237 * @param startVertex the vertex in the vertex array/buffer corresponding
238 * to index 0
239 * @param vertexCount one greater than the max index.
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000240 * @param devBounds optional bounds hint. This is a promise from the caller,
241 * not a request for clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000242 */
egdaniel8dd688b2015-01-22 10:16:09 -0800243 void drawNonIndexed(GrPipelineBuilder*,
joshualitt56995b52014-12-11 15:44:02 -0800244 const GrGeometryProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800245 GrPrimitiveType type,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000246 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000247 int vertexCount,
248 const SkRect* devBounds = NULL);
reed@google.comac10a2d2010-12-22 21:39:39 +0000249
joshualitt4d8da812015-01-28 12:53:54 -0800250 // TODO devbounds should live on the batch
joshualitt44701df2015-02-23 14:44:57 -0800251 void drawBatch(GrPipelineBuilder*, GrBatch*, const SkRect* devBounds = NULL);
joshualitt4d8da812015-01-28 12:53:54 -0800252
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000253 /**
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000254 * Draws path into the stencil buffer. The fill must be either even/odd or
255 * winding (not inverse or hairline). It will respect the HW antialias flag
egdaniel8dd688b2015-01-22 10:16:09 -0800256 * on the GrPipelineBuilder (if possible in the 3D API). Note, we will never have an inverse
257 * fill with stencil path
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000258 */
egdaniel8dd688b2015-01-22 10:16:09 -0800259 void stencilPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*,
260 GrPathRendering::FillType);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000261
262 /**
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000263 * Draws a path. Fill must not be a hairline. It will respect the HW
egdaniel8dd688b2015-01-22 10:16:09 -0800264 * antialias flag on the GrPipelineBuilder (if possible in the 3D API).
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000265 */
egdaniel8dd688b2015-01-22 10:16:09 -0800266 void drawPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*,
267 GrPathRendering::FillType);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000268
269 /**
cdalton55b24af2014-11-25 11:00:56 -0800270 * Draws the aggregate path from combining multiple. Note that this will not
271 * always be equivalent to back-to-back calls to drawPath(). It will respect
egdaniel8dd688b2015-01-22 10:16:09 -0800272 * the HW antialias flag on the GrPipelineBuilder (if possible in the 3D API).
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000273 *
cdalton55b24af2014-11-25 11:00:56 -0800274 * @param pathRange Source paths to draw from
275 * @param indices Array of path indices to draw
276 * @param indexType Data type of the array elements in indexBuffer
277 * @param transformValues Array of transforms for the individual paths
278 * @param transformType Type of transforms in transformBuffer
279 * @param count Number of paths to draw
cdaltonb85a0aa2014-07-21 15:32:44 -0700280 * @param fill Fill type for drawing all the paths
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000281 */
egdaniel8dd688b2015-01-22 10:16:09 -0800282 void drawPaths(GrPipelineBuilder*,
joshualitt56995b52014-12-11 15:44:02 -0800283 const GrPathProcessor*,
joshualitt2e3b3e32014-12-09 13:31:14 -0800284 const GrPathRange* pathRange,
cdalton55b24af2014-11-25 11:00:56 -0800285 const void* indices,
286 PathIndexType indexType,
287 const float transformValues[],
288 PathTransformType transformType,
joshualitt9853cce2014-11-17 14:22:48 -0800289 int count,
joshualitt92e496f2014-10-31 13:56:50 -0700290 GrPathRendering::FillType fill);
cdaltonb85a0aa2014-07-21 15:32:44 -0700291
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000292 /**
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000293 * Helper function for drawing rects. It performs a geometry src push and pop
294 * and thus will finalize any reserved geometry.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000295 *
bsalomon@google.comc7818882013-03-20 19:19:53 +0000296 * @param rect the rect to draw
bsalomon@google.comc7818882013-03-20 19:19:53 +0000297 * @param localRect optional rect that specifies local coords to map onto
298 * rect. If NULL then rect serves as the local coords.
joshualitt8fc6c2d2014-12-22 15:27:05 -0800299 * @param localMatrix Optional local matrix. The local coordinates are specified by localRect,
300 * or if it is NULL by rect. This matrix applies to the coordinate implied by
301 * that rectangle before it is input to GrCoordTransforms that read local
302 * coordinates
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000303 */
joshualitt4d8da812015-01-28 12:53:54 -0800304 void drawRect(GrPipelineBuilder* pipelineBuilder,
joshualitt2e3b3e32014-12-09 13:31:14 -0800305 GrColor color,
joshualitt8059eb92014-12-29 15:10:07 -0800306 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -0800307 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000308 const SkRect* localRect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000309 const SkMatrix* localMatrix) {
joshualitt4d8da812015-01-28 12:53:54 -0800310 this->onDrawRect(pipelineBuilder, color, viewMatrix, rect, localRect, localMatrix);
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000311 }
jvanverth@google.com39768252013-02-14 15:25:44 +0000312
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000313 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000314 * Helper for drawRect when the caller doesn't need separate local rects or matrices.
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000315 */
egdaniel8dd688b2015-01-22 10:16:09 -0800316 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM,
317 const SkRect& rect) {
joshualitt8059eb92014-12-29 15:10:07 -0800318 this->drawRect(ds, color, viewM, rect, NULL, NULL);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000319 }
egdaniel8dd688b2015-01-22 10:16:09 -0800320 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM,
joshualitt8059eb92014-12-29 15:10:07 -0800321 const SkIRect& irect) {
reed@google.com44699382013-10-31 17:28:30 +0000322 SkRect rect = SkRect::Make(irect);
joshualitt8059eb92014-12-29 15:10:07 -0800323 this->drawRect(ds, color, viewM, rect, NULL, NULL);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000324 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000325
326 /**
bsalomon@google.com934c5702012-03-20 21:17:58 +0000327 * This call is used to draw multiple instances of some geometry with a
328 * given number of vertices (V) and indices (I) per-instance. The indices in
329 * the index source must have the form i[k+I] == i[k] + V. Also, all indices
330 * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a
331 * concrete example, the following index buffer for drawing a series of
332 * quads each as two triangles each satisfies these conditions with V=4 and
333 * I=6:
334 * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...)
335 *
336 * The call assumes that the pattern of indices fills the entire index
337 * source. The size of the index buffer limits the number of instances that
338 * can be drawn by the GPU in a single draw. However, the caller may specify
339 * any (positive) number for instanceCount and if necessary multiple GPU
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000340 * draws will be issued. Moreover, when drawIndexedInstances is called
bsalomon@google.com934c5702012-03-20 21:17:58 +0000341 * multiple times it may be possible for GrDrawTarget to group them into a
342 * single GPU draw.
343 *
344 * @param type the type of primitives to draw
345 * @param instanceCount the number of instances to draw. Each instance
346 * consists of verticesPerInstance vertices indexed by
347 * indicesPerInstance indices drawn as the primitive
348 * type specified by type.
349 * @param verticesPerInstance The number of vertices in each instance (V
350 * in the above description).
351 * @param indicesPerInstance The number of indices in each instance (I
352 * in the above description).
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000353 * @param devBounds optional bounds hint. This is a promise from the caller,
354 * not a request for clipping.
bsalomon@google.com934c5702012-03-20 21:17:58 +0000355 */
egdaniel8dd688b2015-01-22 10:16:09 -0800356 void drawIndexedInstances(GrPipelineBuilder*,
joshualitt56995b52014-12-11 15:44:02 -0800357 const GrGeometryProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800358 GrPrimitiveType type,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000359 int instanceCount,
360 int verticesPerInstance,
361 int indicesPerInstance,
362 const SkRect* devBounds = NULL);
bsalomon@google.com934c5702012-03-20 21:17:58 +0000363
364 /**
egdaniel8dd688b2015-01-22 10:16:09 -0800365 * Clear the passed in render target. Ignores the GrPipelineBuilder and clip. Clears the whole
366 * thing if rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire
367 * render target can be optionally cleared.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000368 */
joshualitt9853cce2014-11-17 14:22:48 -0800369 void clear(const SkIRect* rect,
370 GrColor color,
371 bool canIgnoreRect,
bsalomon63b21962014-11-05 07:05:34 -0800372 GrRenderTarget* renderTarget);
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000373
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000374 /**
bsalomon89c62982014-11-03 12:08:42 -0800375 * Discards the contents render target.
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000376 **/
bsalomon89c62982014-11-03 12:08:42 -0800377 virtual void discard(GrRenderTarget*) = 0;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000378
379 /**
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000380 * Called at start and end of gpu trace marking
381 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start
382 * and end of a code block respectively
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000383 */
egdaniel3eee3832014-06-18 13:09:11 -0700384 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
385 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
386
387 /**
388 * Takes the current active set of markers and stores them for later use. Any current marker
389 * in the active set is removed from the active set and the targets remove function is called.
390 * These functions do not work as a stack so you cannot call save a second time before calling
391 * restore. Also, it is assumed that when restore is called the current active set of markers
392 * is empty. When the stored markers are added back into the active set, the targets add marker
393 * is called.
394 */
395 void saveActiveTraceMarkers();
396 void restoreActiveTraceMarkers();
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000397
398 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000399 * Copies a pixel rectangle from one surface to another. This call may finalize
400 * reserved vertex/index data (as though a draw call was made). The src pixels
401 * copied are specified by srcRect. They are copied to a rect of the same
402 * size in dst with top left at dstPoint. If the src rect is clipped by the
403 * src bounds then pixel values in the dst rect corresponding to area clipped
404 * by the src rect are not overwritten. This method can fail and return false
405 * depending on the type of surface, configs, etc, and the backend-specific
406 * limitations. If rect is clipped out entirely by the src or dst bounds then
407 * true is returned since there is no actual copy necessary to succeed.
408 */
bsalomonf90a02b2014-11-26 12:28:00 -0800409 bool copySurface(GrSurface* dst,
410 GrSurface* src,
411 const SkIRect& srcRect,
412 const SkIPoint& dstPoint);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000413 /**
bsalomonf90a02b2014-11-26 12:28:00 -0800414 * Function that determines whether a copySurface call would succeed without actually
bsalomon@google.com116ad842013-04-09 15:38:19 +0000415 * performing the copy.
416 */
bsalomonf90a02b2014-11-26 12:28:00 -0800417 bool canCopySurface(const GrSurface* dst,
418 const GrSurface* src,
419 const SkIRect& srcRect,
420 const SkIPoint& dstPoint);
bsalomon@google.comeb851172013-04-15 13:51:00 +0000421
422 /**
robertphillips@google.comff175842012-05-14 19:31:39 +0000423 * Release any resources that are cached but not currently in use. This
424 * is intended to give an application some recourse when resources are low.
425 */
426 virtual void purgeResources() {};
427
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000428 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000429
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000430 class AutoReleaseGeometry : public ::SkNoncopyable {
reed@google.comac10a2d2010-12-22 21:39:39 +0000431 public:
432 AutoReleaseGeometry(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000433 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800434 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000435 int indexCount);
436 AutoReleaseGeometry();
437 ~AutoReleaseGeometry();
bsalomon@google.com5782d712011-01-21 21:03:59 +0000438 bool set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000439 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800440 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000441 int indexCount);
bsalomon49f085d2014-09-05 13:34:00 -0700442 bool succeeded() const { return SkToBool(fTarget); }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000443 void* vertices() const { SkASSERT(this->succeeded()); return fVertices; }
444 void* indices() const { SkASSERT(this->succeeded()); return fIndices; }
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000445 SkPoint* positions() const {
446 return static_cast<SkPoint*>(this->vertices());
reed@google.comac10a2d2010-12-22 21:39:39 +0000447 }
448
449 private:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000450 void reset();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000451
reed@google.comac10a2d2010-12-22 21:39:39 +0000452 GrDrawTarget* fTarget;
reed@google.comac10a2d2010-12-22 21:39:39 +0000453 void* fVertices;
454 void* fIndices;
455 };
456
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000457 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000458
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000459 /**
460 * Saves the geometry src state at construction and restores in the destructor. It also saves
461 * and then restores the vertex attrib state.
462 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000463 class AutoGeometryPush : public ::SkNoncopyable {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000464 public:
joshualitt9853cce2014-11-17 14:22:48 -0800465 AutoGeometryPush(GrDrawTarget* target) {
bsalomon49f085d2014-09-05 13:34:00 -0700466 SkASSERT(target);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000467 fTarget = target;
468 target->pushGeometrySource();
469 }
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000470
471 ~AutoGeometryPush() { fTarget->popGeometrySource(); }
472
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000473 private:
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000474 GrDrawTarget* fTarget;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000475 };
reed@google.comac10a2d2010-12-22 21:39:39 +0000476
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000477 ///////////////////////////////////////////////////////////////////////////
478 // Draw execution tracking (for font atlases and other resources)
479 class DrawToken {
480 public:
481 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) :
482 fDrawTarget(drawTarget), fDrawID(drawID) {}
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000483
bsalomon49f085d2014-09-05 13:34:00 -0700484 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000485
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000486 private:
487 GrDrawTarget* fDrawTarget;
488 uint32_t fDrawID; // this may wrap, but we're doing direct comparison
489 // so that should be okay
490 };
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000491
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000492 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000493
joshualitt3322fa42014-11-07 08:48:51 -0800494 /**
495 * Used to communicate draws to GPUs / subclasses
496 */
497 class DrawInfo {
498 public:
joshualitt4d8da812015-01-28 12:53:54 -0800499 DrawInfo() { fDevBounds = NULL; }
joshualitt3322fa42014-11-07 08:48:51 -0800500 DrawInfo(const DrawInfo& di) { (*this) = di; }
501 DrawInfo& operator =(const DrawInfo& di);
502
503 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
504 int startVertex() const { return fStartVertex; }
505 int startIndex() const { return fStartIndex; }
506 int vertexCount() const { return fVertexCount; }
507 int indexCount() const { return fIndexCount; }
508 int verticesPerInstance() const { return fVerticesPerInstance; }
509 int indicesPerInstance() const { return fIndicesPerInstance; }
510 int instanceCount() const { return fInstanceCount; }
511
joshualitt4d8da812015-01-28 12:53:54 -0800512 void setPrimitiveType(GrPrimitiveType type) { fPrimitiveType = type; }
513 void setStartVertex(int startVertex) { fStartVertex = startVertex; }
514 void setStartIndex(int startIndex) { fStartIndex = startIndex; }
515 void setVertexCount(int vertexCount) { fVertexCount = vertexCount; }
516 void setIndexCount(int indexCount) { fIndexCount = indexCount; }
517 void setVerticesPerInstance(int verticesPerI) { fVerticesPerInstance = verticesPerI; }
518 void setIndicesPerInstance(int indicesPerI) { fIndicesPerInstance = indicesPerI; }
519 void setInstanceCount(int instanceCount) { fInstanceCount = instanceCount; }
520
joshualitt3322fa42014-11-07 08:48:51 -0800521 bool isIndexed() const { return fIndexCount > 0; }
522#ifdef SK_DEBUG
523 bool isInstanced() const; // this version is longer because of asserts
524#else
525 bool isInstanced() const { return fInstanceCount > 0; }
526#endif
527
528 // adds or remove instances
529 void adjustInstanceCount(int instanceOffset);
530 // shifts the start vertex
531 void adjustStartVertex(int vertexOffset);
532 // shifts the start index
533 void adjustStartIndex(int indexOffset);
534
535 void setDevBounds(const SkRect& bounds) {
536 fDevBoundsStorage = bounds;
537 fDevBounds = &fDevBoundsStorage;
538 }
joshualitt7eb8c7b2014-11-18 14:24:27 -0800539 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
540 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); }
541 void setVertexBuffer(const GrVertexBuffer* vb) {
542 fVertexBuffer.reset(vb);
543 }
544 void setIndexBuffer(const GrIndexBuffer* ib) {
545 fIndexBuffer.reset(ib);
546 }
joshualitt3322fa42014-11-07 08:48:51 -0800547 const SkRect* getDevBounds() const { return fDevBounds; }
548
joshualitt3322fa42014-11-07 08:48:51 -0800549 private:
joshualitt3322fa42014-11-07 08:48:51 -0800550 friend class GrDrawTarget;
551
552 GrPrimitiveType fPrimitiveType;
553
554 int fStartVertex;
555 int fStartIndex;
556 int fVertexCount;
557 int fIndexCount;
558
559 int fInstanceCount;
560 int fVerticesPerInstance;
561 int fIndicesPerInstance;
562
563 SkRect fDevBoundsStorage;
564 SkRect* fDevBounds;
565
joshualitt7eb8c7b2014-11-18 14:24:27 -0800566 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer;
567 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer;
joshualitt3322fa42014-11-07 08:48:51 -0800568 };
joshualitt2c93efe2014-11-06 12:57:13 -0800569
bsalomon371bcbc2014-12-01 08:19:34 -0800570 /**
571 * Used to populate the vertex and index buffer on the draw info before onDraw is called.
572 */
tfarina567ff2f2015-04-27 07:01:44 -0700573 virtual void setDrawBuffers(DrawInfo*, size_t vertexStride) = 0;
joshualitt2c93efe2014-11-06 12:57:13 -0800574 bool programUnitTest(int maxStages);
575
reed@google.comac10a2d2010-12-22 21:39:39 +0000576protected:
robertphillipsdad77942015-03-03 09:28:16 -0800577 friend class GrTargetCommands; // for PipelineInfo
578
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000579 enum GeometrySrcType {
580 kNone_GeometrySrcType, //<! src has not been specified
581 kReserved_GeometrySrcType, //<! src was set using reserve*Space
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000582 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
583 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000584
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000585 struct GeometrySrcState {
586 GeometrySrcType fVertexSrc;
587 union {
588 // valid if src type is buffer
589 const GrVertexBuffer* fVertexBuffer;
590 // valid if src type is reserved or array
591 int fVertexCount;
592 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000593
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000594 GeometrySrcType fIndexSrc;
595 union {
596 // valid if src type is buffer
597 const GrIndexBuffer* fIndexBuffer;
598 // valid if src type is reserved or array
599 int fIndexCount;
600 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000601
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000602 size_t fVertexSize;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000603 };
bsalomon@google.com934c5702012-03-20 21:17:58 +0000604
605 int indexCountInCurrentSource() const {
606 const GeometrySrcState& src = this->getGeomSrc();
607 switch (src.fIndexSrc) {
608 case kNone_GeometrySrcType:
609 return 0;
610 case kReserved_GeometrySrcType:
bsalomon@google.com934c5702012-03-20 21:17:58 +0000611 return src.fIndexCount;
612 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000613 return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
bsalomon@google.com934c5702012-03-20 21:17:58 +0000614 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000615 SkFAIL("Unexpected Index Source.");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000616 return 0;
617 }
618 }
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000619
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000620 GrContext* getContext() { return fContext; }
621 const GrContext* getContext() const { return fContext; }
622
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000623 // subclasses must call this in their destructors to ensure all vertex
624 // and index sources have been released (including those held by
625 // pushGeometrySource())
626 void releaseGeometry();
627
628 // accessors for derived classes
629 const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); }
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000630 // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert.
631 size_t getVertexSize() const {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000632 // the vertex layout is only valid if a vertex source has been specified.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000633 SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType);
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000634 return this->getGeomSrc().fVertexSize;
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000635 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000636
bsalomon@google.combcce8922013-03-25 15:38:39 +0000637 // Subclass must initialize this in its constructor.
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000638 SkAutoTUnref<const GrDrawTargetCaps> fCaps;
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000639
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000640 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; }
641
joshualitt65171342014-10-09 07:25:36 -0700642 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
643 // but couldn't be made. Otherwise, returns true. This method needs to be protected because it
644 // needs to be accessed by GLPrograms to setup a correct drawstate
bsalomon50785a32015-02-06 07:02:37 -0800645 bool setupDstReadIfNecessary(const GrPipelineBuilder&,
egdaniele36914c2015-02-13 09:00:33 -0800646 const GrProcOptInfo& colorPOI,
647 const GrProcOptInfo& coveragePOI,
joshualitt9853cce2014-11-17 14:22:48 -0800648 GrDeviceCoordTexture* dstCopy,
649 const SkRect* drawBounds);
joshualitt65171342014-10-09 07:25:36 -0700650
egdaniele36914c2015-02-13 09:00:33 -0800651 struct PipelineInfo {
652 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor,
joshualitt44701df2015-02-23 14:44:57 -0800653 const GrPrimitiveProcessor* primProc,
654 const SkRect* devBounds, GrDrawTarget* target);
egdaniele36914c2015-02-13 09:00:33 -0800655
656 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor,
joshualitt44701df2015-02-23 14:44:57 -0800657 const GrBatch* batch, const SkRect* devBounds,
658 GrDrawTarget* target);
egdaniele36914c2015-02-13 09:00:33 -0800659
660 bool willBlendWithDst(const GrPrimitiveProcessor* primProc) const {
661 return fPipelineBuilder->willBlendWithDst(primProc);
662 }
663 private:
664 friend class GrDrawTarget;
665
666 bool mustSkipDraw() const { return (NULL == fPipelineBuilder); }
667
668 GrPipelineBuilder* fPipelineBuilder;
669 GrScissorState* fScissor;
670 GrProcOptInfo fColorPOI;
671 GrProcOptInfo fCoveragePOI;
672 GrDeviceCoordTexture fDstCopy;
673 };
674
675 void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline);
676
robertphillips54fac8b2015-02-16 09:35:50 -0800677 // A subclass can optionally overload this function to be notified before
678 // vertex and index space is reserved.
679 virtual void willReserveVertexAndIndexSpace(int vertexCount,
680 size_t vertexStride,
681 int indexCount) {}
682
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000683private:
bsalomonf90a02b2014-11-26 12:28:00 -0800684 /**
685 * This will be called before allocating a texture as a dst for copySurface. This function
686 * populates the dstDesc's config, flags, and origin so as to maximize efficiency and guarantee
687 * success of the copySurface call.
688 */
689 void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) {
690 if (!this->onInitCopySurfaceDstDesc(src, dstDesc)) {
691 dstDesc->fOrigin = kDefault_GrSurfaceOrigin;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800692 dstDesc->fFlags = kRenderTarget_GrSurfaceFlag;
bsalomonf90a02b2014-11-26 12:28:00 -0800693 dstDesc->fConfig = src->config();
694 }
695 }
696
697 /** Internal implementation of canCopySurface. */
698 bool internalCanCopySurface(const GrSurface* dst,
699 const GrSurface* src,
700 const SkIRect& clippedSrcRect,
701 const SkIPoint& clippedDstRect);
702
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000703 // implemented by subclass to allocate space for reserved geom
jvanverth@google.coma6338982013-01-31 21:34:25 +0000704 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000705 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
706 // implemented by subclass to handle release of reserved geom space
707 virtual void releaseReservedVertexSpace() = 0;
708 virtual void releaseReservedIndexSpace() = 0;
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000709 // subclass overrides to be notified just before geo src state is pushed/popped.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000710 virtual void geometrySourceWillPush() = 0;
711 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
712 // subclass called to perform drawing
egdaniele36914c2015-02-13 09:00:33 -0800713 virtual void onDraw(const GrGeometryProcessor*, const DrawInfo&, const PipelineInfo&) = 0;
714 virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0;
joshualitt5478d422014-11-14 16:00:38 -0800715 // TODO copy in order drawbuffer onDrawRect to here
egdaniel8dd688b2015-01-22 10:16:09 -0800716 virtual void onDrawRect(GrPipelineBuilder*,
joshualitt2e3b3e32014-12-09 13:31:14 -0800717 GrColor color,
joshualitt8059eb92014-12-29 15:10:07 -0800718 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -0800719 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000720 const SkRect* localRect,
joshualitt5478d422014-11-14 16:00:38 -0800721 const SkMatrix* localMatrix) = 0;
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000722
egdaniel8dd688b2015-01-22 10:16:09 -0800723 virtual void onStencilPath(const GrPipelineBuilder&,
joshualitt56995b52014-12-11 15:44:02 -0800724 const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800725 const GrPath*,
bsalomon3e791242014-12-17 13:43:13 -0800726 const GrScissorState&,
joshualitt2c93efe2014-11-06 12:57:13 -0800727 const GrStencilSettings&) = 0;
egdaniele36914c2015-02-13 09:00:33 -0800728 virtual void onDrawPath(const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800729 const GrPath*,
joshualitt2c93efe2014-11-06 12:57:13 -0800730 const GrStencilSettings&,
egdaniele36914c2015-02-13 09:00:33 -0800731 const PipelineInfo&) = 0;
732 virtual void onDrawPaths(const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800733 const GrPathRange*,
cdalton55b24af2014-11-25 11:00:56 -0800734 const void* indices,
735 PathIndexType,
736 const float transformValues[],
joshualitt2c93efe2014-11-06 12:57:13 -0800737 PathTransformType,
cdalton55b24af2014-11-25 11:00:56 -0800738 int count,
joshualitt2c93efe2014-11-06 12:57:13 -0800739 const GrStencilSettings&,
egdaniele36914c2015-02-13 09:00:33 -0800740 const PipelineInfo&) = 0;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000741
bsalomon63b21962014-11-05 07:05:34 -0800742 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
743 GrRenderTarget* renderTarget) = 0;
744
bsalomonf90a02b2014-11-26 12:28:00 -0800745 /** The subclass will get a chance to copy the surface for falling back to the default
746 implementation, which simply draws a rectangle (and fails if dst isn't a render target). It
747 should assume that any clipping has already been performed on the rect and point. It won't
748 be called if the copy can be skipped. */
749 virtual bool onCopySurface(GrSurface* dst,
750 GrSurface* src,
751 const SkIRect& srcRect,
752 const SkIPoint& dstPoint) = 0;
753
754 /** Indicates whether onCopySurface would succeed. It should assume that any clipping has
755 already been performed on the rect and point. It won't be called if the copy can be
756 skipped. */
757 virtual bool onCanCopySurface(const GrSurface* dst,
758 const GrSurface* src,
759 const SkIRect& srcRect,
760 const SkIPoint& dstPoint) = 0;
761 /**
762 * This will be called before allocating a texture to be a dst for onCopySurface. Only the
763 * dstDesc's config, flags, and origin need be set by the function. If the subclass cannot
764 * create a surface that would succeed its implementation of onCopySurface, it should return
765 * false. The base class will fall back to creating a render target to draw into using the src.
766 */
767 virtual bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) = 0;
bsalomon63b21962014-11-05 07:05:34 -0800768
bsalomon@google.come3d70952012-03-13 12:40:53 +0000769 // helpers for reserving vertex and index space.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000770 bool reserveVertexSpace(size_t vertexSize,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000771 int vertexCount,
772 void** vertices);
773 bool reserveIndexSpace(int indexCount, void** indices);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000774
bsalomon@google.come8262622011-11-07 02:30:51 +0000775 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to
776 // indicate non-indexed drawing.
egdaniel8dd688b2015-01-22 10:16:09 -0800777 bool checkDraw(const GrPipelineBuilder&,
joshualitt56995b52014-12-11 15:44:02 -0800778 const GrGeometryProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800779 GrPrimitiveType type,
780 int startVertex,
781 int startIndex,
782 int vertexCount,
bsalomon@google.come8262622011-11-07 02:30:51 +0000783 int indexCount) const;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000784 // called when setting a new vert/idx source to unref prev vb/ib
785 void releasePreviousVertexSource();
786 void releasePreviousIndexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000787
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000788 // Check to see if this set of draw commands has been sent out
789 virtual bool isIssued(uint32_t drawID) { return true; }
joshualitt9853cce2014-11-17 14:22:48 -0800790 void getPathStencilSettingsForFilltype(GrPathRendering::FillType,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700791 const GrStencilAttachment*,
joshualitt9853cce2014-11-17 14:22:48 -0800792 GrStencilSettings*);
joshualitta7024152014-11-03 14:16:35 -0800793 virtual GrClipMaskManager* clipMaskManager() = 0;
egdaniel8dd688b2015-01-22 10:16:09 -0800794 virtual bool setupClip(GrPipelineBuilder*,
bsalomon6be6f7c2015-02-26 13:05:21 -0800795 GrPipelineBuilder::AutoRestoreFragmentProcessors*,
796 GrPipelineBuilder::AutoRestoreStencil*,
797 GrScissorState*,
joshualitt8059eb92014-12-29 15:10:07 -0800798 const SkRect* devBounds) = 0;
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000799
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000800 enum {
801 kPreallocGeoSrcStateStackCnt = 4,
reed@google.comac10a2d2010-12-22 21:39:39 +0000802 };
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000803 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000804 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget.
805 GrContext* fContext;
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000806 // To keep track that we always have at least as many debug marker adds as removes
807 int fGpuTraceMarkerCount;
808 GrTraceMarkerSet fActiveTraceMarkers;
egdaniel3eee3832014-06-18 13:09:11 -0700809 GrTraceMarkerSet fStoredTraceMarkers;
reed@google.comfa35e3d2012-06-26 20:16:17 +0000810
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000811 typedef SkRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000812};
813
joshualitt329bf482014-10-29 12:31:28 -0700814/*
815 * This class is JUST for clip mask manager. Everyone else should just use draw target above.
816 */
joshualitt6db519c2014-10-29 08:48:18 -0700817class GrClipTarget : public GrDrawTarget {
818public:
joshualitt329bf482014-10-29 12:31:28 -0700819 GrClipTarget(GrContext* context) : INHERITED(context) {
820 fClipMaskManager.setClipTarget(this);
821 }
822
823 /* Clip mask manager needs access to the context.
824 * TODO we only need a very small subset of context in the CMM.
825 */
826 GrContext* getContext() { return INHERITED::getContext(); }
827 const GrContext* getContext() const { return INHERITED::getContext(); }
828
joshualitt6db519c2014-10-29 08:48:18 -0700829 /**
830 * Clip Mask Manager(and no one else) needs to clear private stencil bits.
831 * ClipTarget subclass sets clip bit in the stencil buffer. The subclass
832 * is free to clear the remaining bits to zero if masked clears are more
833 * expensive than clearing all bits.
834 */
835 virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0;
836
joshualitt3bdd7dc2014-10-31 08:27:39 -0700837 /**
838 * Release any resources that are cached but not currently in use. This
839 * is intended to give an application some recourse when resources are low.
840 */
mtklein36352bf2015-03-25 18:17:31 -0700841 void purgeResources() override {
joshualitt3bdd7dc2014-10-31 08:27:39 -0700842 // The clip mask manager can rebuild all its clip masks so just
843 // get rid of them all.
844 fClipMaskManager.purgeResources();
845 };
846
joshualitt329bf482014-10-29 12:31:28 -0700847protected:
848 GrClipMaskManager fClipMaskManager;
849
joshualitt6db519c2014-10-29 08:48:18 -0700850private:
mtklein36352bf2015-03-25 18:17:31 -0700851 GrClipMaskManager* clipMaskManager() override { return &fClipMaskManager; }
joshualitt329bf482014-10-29 12:31:28 -0700852
egdaniel8dd688b2015-01-22 10:16:09 -0800853 virtual bool setupClip(GrPipelineBuilder*,
bsalomon6be6f7c2015-02-26 13:05:21 -0800854 GrPipelineBuilder::AutoRestoreFragmentProcessors*,
855 GrPipelineBuilder::AutoRestoreStencil*,
joshualitt8059eb92014-12-29 15:10:07 -0800856 GrScissorState* scissorState,
mtklein36352bf2015-03-25 18:17:31 -0700857 const SkRect* devBounds) override;
joshualitt2c93efe2014-11-06 12:57:13 -0800858
joshualitt6db519c2014-10-29 08:48:18 -0700859 typedef GrDrawTarget INHERITED;
860};
861
reed@google.comac10a2d2010-12-22 21:39:39 +0000862#endif