blob: 458e6e14a99d787d65e532c81caf0d19ec32facc [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;
bsalomona73239a2015-04-28 13:35:17 -070034class GrIndexBufferAllocPool;
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;
bsalomona73239a2015-04-28 13:35:17 -070038class GrVertexBufferAllocPool;
sugoi@google.com12b4e272012-12-06 20:13:11 +000039
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000040class GrDrawTarget : public SkRefCnt {
bsalomon@google.comf6601872012-08-28 21:11:35 +000041public:
42 SK_DECLARE_INST_COUNT(GrDrawTarget)
43
cdalton55b24af2014-11-25 11:00:56 -080044 typedef GrPathRange::PathIndexType PathIndexType;
45 typedef GrPathRendering::PathTransformType PathTransformType;
kkinnunenccdaa042014-08-20 01:36:23 -070046
reed@google.comac10a2d2010-12-22 21:39:39 +000047 ///////////////////////////////////////////////////////////////////////////
48
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000049 // The context may not be fully constructed and should not be used during GrDrawTarget
50 // construction.
bsalomona73239a2015-04-28 13:35:17 -070051 GrDrawTarget(GrContext* context, GrVertexBufferAllocPool*, GrIndexBufferAllocPool*);
52
bsalomon72e3ae42015-04-28 08:08:46 -070053 virtual ~GrDrawTarget() {}
reed@google.comac10a2d2010-12-22 21:39:39 +000054
55 /**
bsalomona73239a2015-04-28 13:35:17 -070056 * Empties the draw buffer of any queued up draws.
57 */
58 void reset();
59
60 /**
61 * This plays any queued up draws to its GrGpu target. It also resets this object (i.e. flushing
62 * is destructive).
63 */
64 void flush();
65
66 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000067 * Gets the capabilities of the draw target.
68 */
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000069 const GrDrawTargetCaps* caps() const { return fCaps.get(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000070
joshualitt99c7c072015-05-01 13:43:30 -070071 void drawBatch(GrPipelineBuilder*, GrBatch*);
joshualitt4d8da812015-01-28 12:53:54 -080072
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000073 /**
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000074 * Draws path into the stencil buffer. The fill must be either even/odd or
75 * winding (not inverse or hairline). It will respect the HW antialias flag
egdaniel8dd688b2015-01-22 10:16:09 -080076 * on the GrPipelineBuilder (if possible in the 3D API). Note, we will never have an inverse
77 * fill with stencil path
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000078 */
egdaniel8dd688b2015-01-22 10:16:09 -080079 void stencilPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*,
80 GrPathRendering::FillType);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000081
82 /**
commit-bot@chromium.org32184d82013-10-09 15:14:18 +000083 * Draws a path. Fill must not be a hairline. It will respect the HW
egdaniel8dd688b2015-01-22 10:16:09 -080084 * antialias flag on the GrPipelineBuilder (if possible in the 3D API).
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000085 */
egdaniel8dd688b2015-01-22 10:16:09 -080086 void drawPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*,
87 GrPathRendering::FillType);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000088
89 /**
cdalton55b24af2014-11-25 11:00:56 -080090 * Draws the aggregate path from combining multiple. Note that this will not
91 * always be equivalent to back-to-back calls to drawPath(). It will respect
egdaniel8dd688b2015-01-22 10:16:09 -080092 * the HW antialias flag on the GrPipelineBuilder (if possible in the 3D API).
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +000093 *
cdalton55b24af2014-11-25 11:00:56 -080094 * @param pathRange Source paths to draw from
95 * @param indices Array of path indices to draw
96 * @param indexType Data type of the array elements in indexBuffer
97 * @param transformValues Array of transforms for the individual paths
98 * @param transformType Type of transforms in transformBuffer
99 * @param count Number of paths to draw
cdaltonb85a0aa2014-07-21 15:32:44 -0700100 * @param fill Fill type for drawing all the paths
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000101 */
egdaniel8dd688b2015-01-22 10:16:09 -0800102 void drawPaths(GrPipelineBuilder*,
joshualitt56995b52014-12-11 15:44:02 -0800103 const GrPathProcessor*,
joshualitt2e3b3e32014-12-09 13:31:14 -0800104 const GrPathRange* pathRange,
cdalton55b24af2014-11-25 11:00:56 -0800105 const void* indices,
106 PathIndexType indexType,
107 const float transformValues[],
108 PathTransformType transformType,
joshualitt9853cce2014-11-17 14:22:48 -0800109 int count,
joshualitt92e496f2014-10-31 13:56:50 -0700110 GrPathRendering::FillType fill);
cdaltonb85a0aa2014-07-21 15:32:44 -0700111
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000112 /**
bsalomon72e3ae42015-04-28 08:08:46 -0700113 * Helper function for drawing rects.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000114 *
bsalomon@google.comc7818882013-03-20 19:19:53 +0000115 * @param rect the rect to draw
bsalomon@google.comc7818882013-03-20 19:19:53 +0000116 * @param localRect optional rect that specifies local coords to map onto
117 * rect. If NULL then rect serves as the local coords.
joshualitt8fc6c2d2014-12-22 15:27:05 -0800118 * @param localMatrix Optional local matrix. The local coordinates are specified by localRect,
119 * or if it is NULL by rect. This matrix applies to the coordinate implied by
120 * that rectangle before it is input to GrCoordTransforms that read local
121 * coordinates
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000122 */
joshualitt4d8da812015-01-28 12:53:54 -0800123 void drawRect(GrPipelineBuilder* pipelineBuilder,
joshualitt2e3b3e32014-12-09 13:31:14 -0800124 GrColor color,
joshualitt8059eb92014-12-29 15:10:07 -0800125 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -0800126 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000127 const SkRect* localRect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000128 const SkMatrix* localMatrix) {
joshualitt4d8da812015-01-28 12:53:54 -0800129 this->onDrawRect(pipelineBuilder, color, viewMatrix, rect, localRect, localMatrix);
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000130 }
jvanverth@google.com39768252013-02-14 15:25:44 +0000131
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000132 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000133 * Helper for drawRect when the caller doesn't need separate local rects or matrices.
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000134 */
egdaniel8dd688b2015-01-22 10:16:09 -0800135 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM,
136 const SkRect& rect) {
joshualitt8059eb92014-12-29 15:10:07 -0800137 this->drawRect(ds, color, viewM, rect, NULL, NULL);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000138 }
egdaniel8dd688b2015-01-22 10:16:09 -0800139 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM,
joshualitt8059eb92014-12-29 15:10:07 -0800140 const SkIRect& irect) {
reed@google.com44699382013-10-31 17:28:30 +0000141 SkRect rect = SkRect::Make(irect);
joshualitt8059eb92014-12-29 15:10:07 -0800142 this->drawRect(ds, color, viewM, rect, NULL, NULL);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000143 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000144
bsalomon@google.com934c5702012-03-20 21:17:58 +0000145
146 /**
egdaniel8dd688b2015-01-22 10:16:09 -0800147 * Clear the passed in render target. Ignores the GrPipelineBuilder and clip. Clears the whole
148 * thing if rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire
149 * render target can be optionally cleared.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000150 */
joshualitt9853cce2014-11-17 14:22:48 -0800151 void clear(const SkIRect* rect,
152 GrColor color,
153 bool canIgnoreRect,
bsalomon63b21962014-11-05 07:05:34 -0800154 GrRenderTarget* renderTarget);
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000155
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000156 /**
bsalomon89c62982014-11-03 12:08:42 -0800157 * Discards the contents render target.
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000158 **/
bsalomon89c62982014-11-03 12:08:42 -0800159 virtual void discard(GrRenderTarget*) = 0;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000160
161 /**
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000162 * Called at start and end of gpu trace marking
163 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start
164 * and end of a code block respectively
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000165 */
egdaniel3eee3832014-06-18 13:09:11 -0700166 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
167 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
168
169 /**
170 * Takes the current active set of markers and stores them for later use. Any current marker
171 * in the active set is removed from the active set and the targets remove function is called.
172 * These functions do not work as a stack so you cannot call save a second time before calling
173 * restore. Also, it is assumed that when restore is called the current active set of markers
174 * is empty. When the stored markers are added back into the active set, the targets add marker
175 * is called.
176 */
177 void saveActiveTraceMarkers();
178 void restoreActiveTraceMarkers();
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000179
180 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000181 * Copies a pixel rectangle from one surface to another. This call may finalize
182 * reserved vertex/index data (as though a draw call was made). The src pixels
183 * copied are specified by srcRect. They are copied to a rect of the same
184 * size in dst with top left at dstPoint. If the src rect is clipped by the
185 * src bounds then pixel values in the dst rect corresponding to area clipped
186 * by the src rect are not overwritten. This method can fail and return false
187 * depending on the type of surface, configs, etc, and the backend-specific
188 * limitations. If rect is clipped out entirely by the src or dst bounds then
189 * true is returned since there is no actual copy necessary to succeed.
190 */
bsalomonf90a02b2014-11-26 12:28:00 -0800191 bool copySurface(GrSurface* dst,
192 GrSurface* src,
193 const SkIRect& srcRect,
194 const SkIPoint& dstPoint);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000195 /**
bsalomonf90a02b2014-11-26 12:28:00 -0800196 * Function that determines whether a copySurface call would succeed without actually
bsalomon@google.com116ad842013-04-09 15:38:19 +0000197 * performing the copy.
198 */
bsalomonf90a02b2014-11-26 12:28:00 -0800199 bool canCopySurface(const GrSurface* dst,
200 const GrSurface* src,
201 const SkIRect& srcRect,
202 const SkIPoint& dstPoint);
bsalomon@google.comeb851172013-04-15 13:51:00 +0000203
204 /**
robertphillips@google.comff175842012-05-14 19:31:39 +0000205 * Release any resources that are cached but not currently in use. This
206 * is intended to give an application some recourse when resources are low.
207 */
208 virtual void purgeResources() {};
209
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000210 ///////////////////////////////////////////////////////////////////////////
211 // Draw execution tracking (for font atlases and other resources)
212 class DrawToken {
213 public:
214 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) :
215 fDrawTarget(drawTarget), fDrawID(drawID) {}
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000216
bsalomon49f085d2014-09-05 13:34:00 -0700217 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000218
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000219 private:
220 GrDrawTarget* fDrawTarget;
221 uint32_t fDrawID; // this may wrap, but we're doing direct comparison
222 // so that should be okay
223 };
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000224
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000225 virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); }
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000226
joshualitt3322fa42014-11-07 08:48:51 -0800227 /**
bsalomonb5238a72015-05-05 07:49:49 -0700228 * Used to communicate draw index vertex offsets and counts toto GPUs / subclasses
joshualitt3322fa42014-11-07 08:48:51 -0800229 */
230 class DrawInfo {
231 public:
bsalomonb5238a72015-05-05 07:49:49 -0700232 DrawInfo() {}
joshualitt3322fa42014-11-07 08:48:51 -0800233 DrawInfo(const DrawInfo& di) { (*this) = di; }
234 DrawInfo& operator =(const DrawInfo& di);
235
bsalomonb5238a72015-05-05 07:49:49 -0700236 void init(GrPrimitiveType primType, const GrVertexBuffer* vertexBuffer, int startVertex,
237 int vertexCount) {
238 SkASSERT(vertexBuffer);
239 SkASSERT(vertexCount);
240 SkASSERT(startVertex >= 0);
241 fPrimitiveType = primType;
242 fVertexBuffer.reset(SkRef(vertexBuffer));
243 fIndexBuffer.reset(NULL);
244 fStartVertex = startVertex;
245 fStartIndex = 0;
246 fVertexCount = vertexCount;
247 fIndexCount = 0;
248 fInstanceCount = 0;
249 fVerticesPerInstance = 0;
250 fIndicesPerInstance = 0;
251 }
252
253 void initIndexed(GrPrimitiveType primType,
254 const GrVertexBuffer* vertexBuffer,
255 const GrIndexBuffer* indexBuffer,
256 int startVertex,
257 int startIndex,
258 int vertexCount,
259 int indexCount) {
260 SkASSERT(indexBuffer);
261 SkASSERT(vertexBuffer);
262 SkASSERT(indexCount);
263 SkASSERT(vertexCount);
264 SkASSERT(startIndex >= 0);
265 SkASSERT(startVertex >= 0);
266 fPrimitiveType = primType;
267 fVertexBuffer.reset(SkRef(vertexBuffer));
268 fIndexBuffer.reset(SkRef(indexBuffer));
269 fStartVertex = startVertex;
270 fStartIndex = startIndex;
271 fVertexCount = vertexCount;
272 fIndexCount = indexCount;
273 fInstanceCount = 0;
274 fVerticesPerInstance = 0;
275 fIndicesPerInstance = 0;
276 }
277
278 void initInstanced(GrPrimitiveType primType,
279 const GrVertexBuffer* vertexBuffer,
280 const GrIndexBuffer* indexBuffer,
281 int startVertex,
282 int verticesPerInstance,
283 int indicesPerInstance,
284 int instanceCount) {
285 SkASSERT(vertexBuffer);
286 SkASSERT(indexBuffer);
287 SkASSERT(instanceCount);
288 SkASSERT(verticesPerInstance);
289 SkASSERT(indicesPerInstance);
290 SkASSERT(startVertex >= 0);
291 fPrimitiveType = primType;
292 fVertexBuffer.reset(SkRef(vertexBuffer));
293 fIndexBuffer.reset(SkRef(indexBuffer));
294 fStartVertex = startVertex;
295 fStartIndex = 0;
296 fVerticesPerInstance = verticesPerInstance;
297 fIndicesPerInstance = indicesPerInstance;
298 fInstanceCount = instanceCount;
299 fVertexCount = instanceCount * fVerticesPerInstance;
300 fIndexCount = instanceCount * fIndicesPerInstance;
301 }
302
303 /** Variation of the above that may be used when the total number of instances may exceed
304 the number of instances supported by the index buffer. To be used with
305 nextInstances() to draw in max-sized batches.*/
306 void initInstanced(GrPrimitiveType primType,
307 const GrVertexBuffer* vertexBuffer,
308 const GrIndexBuffer* indexBuffer,
309 int startVertex,
310 int verticesPerInstance,
311 int indicesPerInstance,
312 int* instancesRemaining,
313 int maxInstancesPerDraw) {
314 int instanceCount = SkTMin(*instancesRemaining, maxInstancesPerDraw);
315 *instancesRemaining -= instanceCount;
316 this->initInstanced(primType, vertexBuffer, indexBuffer, startVertex,
317 verticesPerInstance, indicesPerInstance, instanceCount);
318 }
319
joshualitt3322fa42014-11-07 08:48:51 -0800320 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
321 int startVertex() const { return fStartVertex; }
322 int startIndex() const { return fStartIndex; }
323 int vertexCount() const { return fVertexCount; }
324 int indexCount() const { return fIndexCount; }
bsalomonb5238a72015-05-05 07:49:49 -0700325
326 /** These return 0 if initInstanced was not used to initialize the DrawInfo. */
joshualitt3322fa42014-11-07 08:48:51 -0800327 int verticesPerInstance() const { return fVerticesPerInstance; }
328 int indicesPerInstance() const { return fIndicesPerInstance; }
329 int instanceCount() const { return fInstanceCount; }
330
331 bool isIndexed() const { return fIndexCount > 0; }
joshualitt3322fa42014-11-07 08:48:51 -0800332 bool isInstanced() const { return fInstanceCount > 0; }
joshualitt3322fa42014-11-07 08:48:51 -0800333
bsalomonb5238a72015-05-05 07:49:49 -0700334 /** Called after using this draw info to draw the next set of instances.
335 The vertex offset is advanced while the index buffer is reused at the same
336 position. instancesRemaining is number of instances that remain, maxInstances is
337 the most number of instances that can be used with the index buffer. If there
338 are no instances remaining, the DrawInfo is unmodified and false is returned.*/
339 bool nextInstances(int* instancesRemaining, int maxInstances) {
340 SkASSERT(this->isInstanced());
341 if (!*instancesRemaining) {
342 return false;
343 }
344 fStartVertex += fVertexCount;
345 fInstanceCount = SkTMin(*instancesRemaining, maxInstances);
346 fVertexCount = fInstanceCount * fVerticesPerInstance;
347 fIndexCount = fInstanceCount * fIndicesPerInstance;
348 *instancesRemaining -= fInstanceCount;
349 return true;
bsalomon72e3ae42015-04-28 08:08:46 -0700350 }
bsalomonb5238a72015-05-05 07:49:49 -0700351
joshualitt7eb8c7b2014-11-18 14:24:27 -0800352 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
353 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); }
joshualitt3322fa42014-11-07 08:48:51 -0800354
joshualitt3322fa42014-11-07 08:48:51 -0800355 private:
joshualitt3322fa42014-11-07 08:48:51 -0800356 friend class GrDrawTarget;
357
358 GrPrimitiveType fPrimitiveType;
359
360 int fStartVertex;
361 int fStartIndex;
362 int fVertexCount;
363 int fIndexCount;
364
365 int fInstanceCount;
366 int fVerticesPerInstance;
367 int fIndicesPerInstance;
368
joshualitt7eb8c7b2014-11-18 14:24:27 -0800369 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer;
370 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer;
joshualitt3322fa42014-11-07 08:48:51 -0800371 };
joshualitt2c93efe2014-11-06 12:57:13 -0800372
373 bool programUnitTest(int maxStages);
374
reed@google.comac10a2d2010-12-22 21:39:39 +0000375protected:
joshualitte46760e2015-05-05 08:41:50 -0700376 friend class GrCommandBuilder; // for PipelineInfo
robertphillipsdad77942015-03-03 09:28:16 -0800377 friend class GrTargetCommands; // for PipelineInfo
378
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000379 GrContext* getContext() { return fContext; }
380 const GrContext* getContext() const { return fContext; }
381
bsalomona73239a2015-04-28 13:35:17 -0700382 GrGpu* getGpu() {
383 SkASSERT(fContext && fContext->getGpu());
384 return fContext->getGpu();
385 }
386 const GrGpu* getGpu() const {
387 SkASSERT(fContext && fContext->getGpu());
388 return fContext->getGpu();
389 }
390
391 GrVertexBufferAllocPool* getVertexAllocPool() { return fVertexPool; }
392 GrIndexBufferAllocPool* getIndexAllocPool() { return fIndexPool; }
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000393
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000394 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; }
395
joshualitt65171342014-10-09 07:25:36 -0700396 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
397 // but couldn't be made. Otherwise, returns true. This method needs to be protected because it
398 // needs to be accessed by GLPrograms to setup a correct drawstate
bsalomon50785a32015-02-06 07:02:37 -0800399 bool setupDstReadIfNecessary(const GrPipelineBuilder&,
egdaniele36914c2015-02-13 09:00:33 -0800400 const GrProcOptInfo& colorPOI,
401 const GrProcOptInfo& coveragePOI,
joshualitt9853cce2014-11-17 14:22:48 -0800402 GrDeviceCoordTexture* dstCopy,
403 const SkRect* drawBounds);
joshualitt65171342014-10-09 07:25:36 -0700404
egdaniele36914c2015-02-13 09:00:33 -0800405 struct PipelineInfo {
406 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor,
joshualitt44701df2015-02-23 14:44:57 -0800407 const GrPrimitiveProcessor* primProc,
408 const SkRect* devBounds, GrDrawTarget* target);
egdaniele36914c2015-02-13 09:00:33 -0800409
410 PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor,
joshualitt44701df2015-02-23 14:44:57 -0800411 const GrBatch* batch, const SkRect* devBounds,
412 GrDrawTarget* target);
egdaniele36914c2015-02-13 09:00:33 -0800413
414 bool willBlendWithDst(const GrPrimitiveProcessor* primProc) const {
415 return fPipelineBuilder->willBlendWithDst(primProc);
416 }
417 private:
418 friend class GrDrawTarget;
419
420 bool mustSkipDraw() const { return (NULL == fPipelineBuilder); }
421
422 GrPipelineBuilder* fPipelineBuilder;
423 GrScissorState* fScissor;
424 GrProcOptInfo fColorPOI;
425 GrProcOptInfo fCoveragePOI;
426 GrDeviceCoordTexture fDstCopy;
427 };
428
429 void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline);
430
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000431private:
bsalomona73239a2015-04-28 13:35:17 -0700432 virtual void onReset() = 0;
bsalomonf90a02b2014-11-26 12:28:00 -0800433
bsalomona73239a2015-04-28 13:35:17 -0700434 virtual void onFlush() = 0;
bsalomonf90a02b2014-11-26 12:28:00 -0800435
egdaniele36914c2015-02-13 09:00:33 -0800436 virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0;
joshualitt5478d422014-11-14 16:00:38 -0800437 // TODO copy in order drawbuffer onDrawRect to here
egdaniel8dd688b2015-01-22 10:16:09 -0800438 virtual void onDrawRect(GrPipelineBuilder*,
joshualitt2e3b3e32014-12-09 13:31:14 -0800439 GrColor color,
joshualitt8059eb92014-12-29 15:10:07 -0800440 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -0800441 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000442 const SkRect* localRect,
joshualitt5478d422014-11-14 16:00:38 -0800443 const SkMatrix* localMatrix) = 0;
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000444
egdaniel8dd688b2015-01-22 10:16:09 -0800445 virtual void onStencilPath(const GrPipelineBuilder&,
joshualitt56995b52014-12-11 15:44:02 -0800446 const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800447 const GrPath*,
bsalomon3e791242014-12-17 13:43:13 -0800448 const GrScissorState&,
joshualitt2c93efe2014-11-06 12:57:13 -0800449 const GrStencilSettings&) = 0;
egdaniele36914c2015-02-13 09:00:33 -0800450 virtual void onDrawPath(const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800451 const GrPath*,
joshualitt2c93efe2014-11-06 12:57:13 -0800452 const GrStencilSettings&,
egdaniele36914c2015-02-13 09:00:33 -0800453 const PipelineInfo&) = 0;
454 virtual void onDrawPaths(const GrPathProcessor*,
joshualitt9853cce2014-11-17 14:22:48 -0800455 const GrPathRange*,
cdalton55b24af2014-11-25 11:00:56 -0800456 const void* indices,
457 PathIndexType,
458 const float transformValues[],
joshualitt2c93efe2014-11-06 12:57:13 -0800459 PathTransformType,
cdalton55b24af2014-11-25 11:00:56 -0800460 int count,
joshualitt2c93efe2014-11-06 12:57:13 -0800461 const GrStencilSettings&,
egdaniele36914c2015-02-13 09:00:33 -0800462 const PipelineInfo&) = 0;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000463
bsalomon63b21962014-11-05 07:05:34 -0800464 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
465 GrRenderTarget* renderTarget) = 0;
466
bsalomona73239a2015-04-28 13:35:17 -0700467 /** The subclass's copy surface implementation. It should assume that any clipping has already
468 been performed on the rect and point and that the GrGpu supports the copy. */
469 virtual void onCopySurface(GrSurface* dst,
bsalomonf90a02b2014-11-26 12:28:00 -0800470 GrSurface* src,
471 const SkIRect& srcRect,
472 const SkIPoint& dstPoint) = 0;
473
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000474 // Check to see if this set of draw commands has been sent out
475 virtual bool isIssued(uint32_t drawID) { return true; }
joshualitt9853cce2014-11-17 14:22:48 -0800476 void getPathStencilSettingsForFilltype(GrPathRendering::FillType,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700477 const GrStencilAttachment*,
joshualitt9853cce2014-11-17 14:22:48 -0800478 GrStencilSettings*);
joshualitta7024152014-11-03 14:16:35 -0800479 virtual GrClipMaskManager* clipMaskManager() = 0;
egdaniel8dd688b2015-01-22 10:16:09 -0800480 virtual bool setupClip(GrPipelineBuilder*,
bsalomon6be6f7c2015-02-26 13:05:21 -0800481 GrPipelineBuilder::AutoRestoreFragmentProcessors*,
482 GrPipelineBuilder::AutoRestoreStencil*,
483 GrScissorState*,
joshualitt8059eb92014-12-29 15:10:07 -0800484 const SkRect* devBounds) = 0;
skia.committer@gmail.com74758112013-08-17 07:01:54 +0000485
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000486 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget.
487 GrContext* fContext;
bsalomona73239a2015-04-28 13:35:17 -0700488 SkAutoTUnref<const GrDrawTargetCaps> fCaps;
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000489 // To keep track that we always have at least as many debug marker adds as removes
490 int fGpuTraceMarkerCount;
491 GrTraceMarkerSet fActiveTraceMarkers;
egdaniel3eee3832014-06-18 13:09:11 -0700492 GrTraceMarkerSet fStoredTraceMarkers;
bsalomona73239a2015-04-28 13:35:17 -0700493 GrVertexBufferAllocPool* fVertexPool;
494 GrIndexBufferAllocPool* fIndexPool;
495 bool fFlushing;
reed@google.comfa35e3d2012-06-26 20:16:17 +0000496
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000497 typedef SkRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000498};
499
joshualitt329bf482014-10-29 12:31:28 -0700500/*
501 * This class is JUST for clip mask manager. Everyone else should just use draw target above.
502 */
joshualitt6db519c2014-10-29 08:48:18 -0700503class GrClipTarget : public GrDrawTarget {
504public:
bsalomona73239a2015-04-28 13:35:17 -0700505 GrClipTarget(GrContext* context,
506 GrVertexBufferAllocPool* vpool,
507 GrIndexBufferAllocPool* ipool)
508 : INHERITED(context, vpool, ipool) {
joshualitt329bf482014-10-29 12:31:28 -0700509 fClipMaskManager.setClipTarget(this);
510 }
511
512 /* Clip mask manager needs access to the context.
513 * TODO we only need a very small subset of context in the CMM.
514 */
515 GrContext* getContext() { return INHERITED::getContext(); }
516 const GrContext* getContext() const { return INHERITED::getContext(); }
517
joshualitt6db519c2014-10-29 08:48:18 -0700518 /**
519 * Clip Mask Manager(and no one else) needs to clear private stencil bits.
520 * ClipTarget subclass sets clip bit in the stencil buffer. The subclass
521 * is free to clear the remaining bits to zero if masked clears are more
522 * expensive than clearing all bits.
523 */
524 virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0;
525
joshualitt3bdd7dc2014-10-31 08:27:39 -0700526 /**
527 * Release any resources that are cached but not currently in use. This
528 * is intended to give an application some recourse when resources are low.
529 */
mtklein36352bf2015-03-25 18:17:31 -0700530 void purgeResources() override {
joshualitt3bdd7dc2014-10-31 08:27:39 -0700531 // The clip mask manager can rebuild all its clip masks so just
532 // get rid of them all.
533 fClipMaskManager.purgeResources();
534 };
535
joshualitt329bf482014-10-29 12:31:28 -0700536protected:
537 GrClipMaskManager fClipMaskManager;
538
joshualitt6db519c2014-10-29 08:48:18 -0700539private:
mtklein36352bf2015-03-25 18:17:31 -0700540 GrClipMaskManager* clipMaskManager() override { return &fClipMaskManager; }
joshualitt329bf482014-10-29 12:31:28 -0700541
egdaniel8dd688b2015-01-22 10:16:09 -0800542 virtual bool setupClip(GrPipelineBuilder*,
bsalomon6be6f7c2015-02-26 13:05:21 -0800543 GrPipelineBuilder::AutoRestoreFragmentProcessors*,
544 GrPipelineBuilder::AutoRestoreStencil*,
joshualitt8059eb92014-12-29 15:10:07 -0800545 GrScissorState* scissorState,
mtklein36352bf2015-03-25 18:17:31 -0700546 const SkRect* devBounds) override;
joshualitt2c93efe2014-11-06 12:57:13 -0800547
joshualitt6db519c2014-10-29 08:48:18 -0700548 typedef GrDrawTarget INHERITED;
549};
550
reed@google.comac10a2d2010-12-22 21:39:39 +0000551#endif