reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #ifndef GrDrawTarget_DEFINED |
| 9 | #define GrDrawTarget_DEFINED |
| 10 | |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 11 | #include "GrClip.h" |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 12 | #include "GrClipMaskManager.h" |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 14 | #include "GrPathProcessor.h" |
| 15 | #include "GrPrimitiveProcessor.h" |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 16 | #include "GrIndexBuffer.h" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 17 | #include "GrPathRendering.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 18 | #include "GrPipelineBuilder.h" |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 19 | #include "GrTraceMarker.h" |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 20 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 22 | #include "SkClipStack.h" |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 23 | #include "SkMatrix.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 24 | #include "SkPath.h" |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 25 | #include "SkStrokeRec.h" |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 26 | #include "SkTArray.h" |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 27 | #include "SkTLazy.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 28 | #include "SkTypes.h" |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 29 | #include "SkXfermode.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 30 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 31 | class GrBatch; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 32 | class GrClip; |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 33 | class GrDrawTargetCaps; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 34 | class GrPath; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 35 | class GrPathRange; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 36 | class GrPipeline; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 37 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 38 | class GrDrawTarget : public SkRefCnt { |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 39 | public: |
| 40 | SK_DECLARE_INST_COUNT(GrDrawTarget) |
| 41 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 42 | typedef GrPathRange::PathIndexType PathIndexType; |
| 43 | typedef GrPathRendering::PathTransformType PathTransformType; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 44 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 45 | /////////////////////////////////////////////////////////////////////////// |
| 46 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 47 | // The context may not be fully constructed and should not be used during GrDrawTarget |
| 48 | // construction. |
| 49 | GrDrawTarget(GrContext* context); |
bsalomon | 72e3ae4 | 2015-04-28 08:08:46 -0700 | [diff] [blame^] | 50 | virtual ~GrDrawTarget() {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | |
| 52 | /** |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 53 | * Gets the capabilities of the draw target. |
| 54 | */ |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 55 | const GrDrawTargetCaps* caps() const { return fCaps.get(); } |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 56 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 57 | // TODO devbounds should live on the batch |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 58 | void drawBatch(GrPipelineBuilder*, GrBatch*, const SkRect* devBounds = NULL); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 59 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 60 | /** |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 61 | * Draws path into the stencil buffer. The fill must be either even/odd or |
| 62 | * winding (not inverse or hairline). It will respect the HW antialias flag |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 63 | * on the GrPipelineBuilder (if possible in the 3D API). Note, we will never have an inverse |
| 64 | * fill with stencil path |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 65 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 66 | void stencilPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*, |
| 67 | GrPathRendering::FillType); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 68 | |
| 69 | /** |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 70 | * Draws a path. Fill must not be a hairline. It will respect the HW |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 71 | * antialias flag on the GrPipelineBuilder (if possible in the 3D API). |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 72 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 73 | void drawPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*, |
| 74 | GrPathRendering::FillType); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 75 | |
| 76 | /** |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 77 | * Draws the aggregate path from combining multiple. Note that this will not |
| 78 | * always be equivalent to back-to-back calls to drawPath(). It will respect |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 79 | * the HW antialias flag on the GrPipelineBuilder (if possible in the 3D API). |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 80 | * |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 81 | * @param pathRange Source paths to draw from |
| 82 | * @param indices Array of path indices to draw |
| 83 | * @param indexType Data type of the array elements in indexBuffer |
| 84 | * @param transformValues Array of transforms for the individual paths |
| 85 | * @param transformType Type of transforms in transformBuffer |
| 86 | * @param count Number of paths to draw |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 87 | * @param fill Fill type for drawing all the paths |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 88 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 89 | void drawPaths(GrPipelineBuilder*, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 90 | const GrPathProcessor*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 91 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 92 | const void* indices, |
| 93 | PathIndexType indexType, |
| 94 | const float transformValues[], |
| 95 | PathTransformType transformType, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 96 | int count, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 97 | GrPathRendering::FillType fill); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 98 | |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 99 | /** |
bsalomon | 72e3ae4 | 2015-04-28 08:08:46 -0700 | [diff] [blame^] | 100 | * Helper function for drawing rects. |
skia.committer@gmail.com | 044679e | 2013-02-15 07:16:57 +0000 | [diff] [blame] | 101 | * |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 102 | * @param rect the rect to draw |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 103 | * @param localRect optional rect that specifies local coords to map onto |
| 104 | * rect. If NULL then rect serves as the local coords. |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 105 | * @param localMatrix Optional local matrix. The local coordinates are specified by localRect, |
| 106 | * or if it is NULL by rect. This matrix applies to the coordinate implied by |
| 107 | * that rectangle before it is input to GrCoordTransforms that read local |
| 108 | * coordinates |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 109 | */ |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 110 | void drawRect(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 111 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 112 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 113 | const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 114 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 115 | const SkMatrix* localMatrix) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 116 | this->onDrawRect(pipelineBuilder, color, viewMatrix, rect, localRect, localMatrix); |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 117 | } |
jvanverth@google.com | 3976825 | 2013-02-14 15:25:44 +0000 | [diff] [blame] | 118 | |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 119 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 120 | * Helper for drawRect when the caller doesn't need separate local rects or matrices. |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 121 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 122 | void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM, |
| 123 | const SkRect& rect) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 124 | this->drawRect(ds, color, viewM, rect, NULL, NULL); |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 125 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 126 | void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& viewM, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 127 | const SkIRect& irect) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 128 | SkRect rect = SkRect::Make(irect); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 129 | this->drawRect(ds, color, viewM, rect, NULL, NULL); |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 130 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 131 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 132 | |
| 133 | /** |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 134 | * Clear the passed in render target. Ignores the GrPipelineBuilder and clip. Clears the whole |
| 135 | * thing if rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire |
| 136 | * render target can be optionally cleared. |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 137 | */ |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 138 | void clear(const SkIRect* rect, |
| 139 | GrColor color, |
| 140 | bool canIgnoreRect, |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 141 | GrRenderTarget* renderTarget); |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 142 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 143 | /** |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 144 | * Discards the contents render target. |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 145 | **/ |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 146 | virtual void discard(GrRenderTarget*) = 0; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 147 | |
| 148 | /** |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 149 | * Called at start and end of gpu trace marking |
| 150 | * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start |
| 151 | * and end of a code block respectively |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 152 | */ |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 153 | void addGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 154 | void removeGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 155 | |
| 156 | /** |
| 157 | * Takes the current active set of markers and stores them for later use. Any current marker |
| 158 | * in the active set is removed from the active set and the targets remove function is called. |
| 159 | * These functions do not work as a stack so you cannot call save a second time before calling |
| 160 | * restore. Also, it is assumed that when restore is called the current active set of markers |
| 161 | * is empty. When the stored markers are added back into the active set, the targets add marker |
| 162 | * is called. |
| 163 | */ |
| 164 | void saveActiveTraceMarkers(); |
| 165 | void restoreActiveTraceMarkers(); |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 166 | |
| 167 | /** |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 168 | * Copies a pixel rectangle from one surface to another. This call may finalize |
| 169 | * reserved vertex/index data (as though a draw call was made). The src pixels |
| 170 | * copied are specified by srcRect. They are copied to a rect of the same |
| 171 | * size in dst with top left at dstPoint. If the src rect is clipped by the |
| 172 | * src bounds then pixel values in the dst rect corresponding to area clipped |
| 173 | * by the src rect are not overwritten. This method can fail and return false |
| 174 | * depending on the type of surface, configs, etc, and the backend-specific |
| 175 | * limitations. If rect is clipped out entirely by the src or dst bounds then |
| 176 | * true is returned since there is no actual copy necessary to succeed. |
| 177 | */ |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 178 | bool copySurface(GrSurface* dst, |
| 179 | GrSurface* src, |
| 180 | const SkIRect& srcRect, |
| 181 | const SkIPoint& dstPoint); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 182 | /** |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 183 | * Function that determines whether a copySurface call would succeed without actually |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 184 | * performing the copy. |
| 185 | */ |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 186 | bool canCopySurface(const GrSurface* dst, |
| 187 | const GrSurface* src, |
| 188 | const SkIRect& srcRect, |
| 189 | const SkIPoint& dstPoint); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 190 | |
| 191 | /** |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 192 | * Release any resources that are cached but not currently in use. This |
| 193 | * is intended to give an application some recourse when resources are low. |
| 194 | */ |
| 195 | virtual void purgeResources() {}; |
| 196 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 197 | /////////////////////////////////////////////////////////////////////////// |
| 198 | // Draw execution tracking (for font atlases and other resources) |
| 199 | class DrawToken { |
| 200 | public: |
| 201 | DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : |
| 202 | fDrawTarget(drawTarget), fDrawID(drawID) {} |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 203 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 204 | bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID); } |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 205 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 206 | private: |
| 207 | GrDrawTarget* fDrawTarget; |
| 208 | uint32_t fDrawID; // this may wrap, but we're doing direct comparison |
| 209 | // so that should be okay |
| 210 | }; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 211 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 212 | virtual DrawToken getCurrentDrawToken() { return DrawToken(this, 0); } |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 213 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 214 | /** |
| 215 | * Used to communicate draws to GPUs / subclasses |
| 216 | */ |
| 217 | class DrawInfo { |
| 218 | public: |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 219 | DrawInfo() { fDevBounds = NULL; } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 220 | DrawInfo(const DrawInfo& di) { (*this) = di; } |
| 221 | DrawInfo& operator =(const DrawInfo& di); |
| 222 | |
| 223 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
| 224 | int startVertex() const { return fStartVertex; } |
| 225 | int startIndex() const { return fStartIndex; } |
| 226 | int vertexCount() const { return fVertexCount; } |
| 227 | int indexCount() const { return fIndexCount; } |
| 228 | int verticesPerInstance() const { return fVerticesPerInstance; } |
| 229 | int indicesPerInstance() const { return fIndicesPerInstance; } |
| 230 | int instanceCount() const { return fInstanceCount; } |
| 231 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 232 | void setPrimitiveType(GrPrimitiveType type) { fPrimitiveType = type; } |
| 233 | void setStartVertex(int startVertex) { fStartVertex = startVertex; } |
| 234 | void setStartIndex(int startIndex) { fStartIndex = startIndex; } |
| 235 | void setVertexCount(int vertexCount) { fVertexCount = vertexCount; } |
| 236 | void setIndexCount(int indexCount) { fIndexCount = indexCount; } |
| 237 | void setVerticesPerInstance(int verticesPerI) { fVerticesPerInstance = verticesPerI; } |
| 238 | void setIndicesPerInstance(int indicesPerI) { fIndicesPerInstance = indicesPerI; } |
| 239 | void setInstanceCount(int instanceCount) { fInstanceCount = instanceCount; } |
| 240 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 241 | bool isIndexed() const { return fIndexCount > 0; } |
| 242 | #ifdef SK_DEBUG |
| 243 | bool isInstanced() const; // this version is longer because of asserts |
| 244 | #else |
| 245 | bool isInstanced() const { return fInstanceCount > 0; } |
| 246 | #endif |
| 247 | |
| 248 | // adds or remove instances |
| 249 | void adjustInstanceCount(int instanceOffset); |
| 250 | // shifts the start vertex |
bsalomon | 72e3ae4 | 2015-04-28 08:08:46 -0700 | [diff] [blame^] | 251 | void adjustStartVertex(int vertexOffset) { |
| 252 | fStartVertex += vertexOffset; |
| 253 | SkASSERT(fStartVertex >= 0); |
| 254 | } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 255 | // shifts the start index |
bsalomon | 72e3ae4 | 2015-04-28 08:08:46 -0700 | [diff] [blame^] | 256 | void adjustStartIndex(int indexOffset) { |
| 257 | SkASSERT(this->isIndexed()); |
| 258 | fStartIndex += indexOffset; |
| 259 | SkASSERT(fStartIndex >= 0); |
| 260 | } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 261 | void setDevBounds(const SkRect& bounds) { |
| 262 | fDevBoundsStorage = bounds; |
| 263 | fDevBounds = &fDevBoundsStorage; |
| 264 | } |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 265 | const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } |
| 266 | const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
| 267 | void setVertexBuffer(const GrVertexBuffer* vb) { |
| 268 | fVertexBuffer.reset(vb); |
| 269 | } |
| 270 | void setIndexBuffer(const GrIndexBuffer* ib) { |
| 271 | fIndexBuffer.reset(ib); |
| 272 | } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 273 | const SkRect* getDevBounds() const { return fDevBounds; } |
| 274 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 275 | private: |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 276 | friend class GrDrawTarget; |
| 277 | |
| 278 | GrPrimitiveType fPrimitiveType; |
| 279 | |
| 280 | int fStartVertex; |
| 281 | int fStartIndex; |
| 282 | int fVertexCount; |
| 283 | int fIndexCount; |
| 284 | |
| 285 | int fInstanceCount; |
| 286 | int fVerticesPerInstance; |
| 287 | int fIndicesPerInstance; |
| 288 | |
| 289 | SkRect fDevBoundsStorage; |
| 290 | SkRect* fDevBounds; |
| 291 | |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 292 | GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; |
| 293 | GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 294 | }; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 295 | |
| 296 | bool programUnitTest(int maxStages); |
| 297 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 298 | protected: |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 299 | friend class GrTargetCommands; // for PipelineInfo |
| 300 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 301 | GrContext* getContext() { return fContext; } |
| 302 | const GrContext* getContext() const { return fContext; } |
| 303 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 304 | // Subclass must initialize this in its constructor. |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 305 | SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 306 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 307 | const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; } |
| 308 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 309 | // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required |
| 310 | // but couldn't be made. Otherwise, returns true. This method needs to be protected because it |
| 311 | // needs to be accessed by GLPrograms to setup a correct drawstate |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 312 | bool setupDstReadIfNecessary(const GrPipelineBuilder&, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 313 | const GrProcOptInfo& colorPOI, |
| 314 | const GrProcOptInfo& coveragePOI, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 315 | GrDeviceCoordTexture* dstCopy, |
| 316 | const SkRect* drawBounds); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 317 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 318 | struct PipelineInfo { |
| 319 | PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor, |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 320 | const GrPrimitiveProcessor* primProc, |
| 321 | const SkRect* devBounds, GrDrawTarget* target); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 322 | |
| 323 | PipelineInfo(GrPipelineBuilder* pipelineBuilder, GrScissorState* scissor, |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 324 | const GrBatch* batch, const SkRect* devBounds, |
| 325 | GrDrawTarget* target); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 326 | |
| 327 | bool willBlendWithDst(const GrPrimitiveProcessor* primProc) const { |
| 328 | return fPipelineBuilder->willBlendWithDst(primProc); |
| 329 | } |
| 330 | private: |
| 331 | friend class GrDrawTarget; |
| 332 | |
| 333 | bool mustSkipDraw() const { return (NULL == fPipelineBuilder); } |
| 334 | |
| 335 | GrPipelineBuilder* fPipelineBuilder; |
| 336 | GrScissorState* fScissor; |
| 337 | GrProcOptInfo fColorPOI; |
| 338 | GrProcOptInfo fCoveragePOI; |
| 339 | GrDeviceCoordTexture fDstCopy; |
| 340 | }; |
| 341 | |
| 342 | void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline); |
| 343 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 344 | private: |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 345 | /** |
| 346 | * This will be called before allocating a texture as a dst for copySurface. This function |
| 347 | * populates the dstDesc's config, flags, and origin so as to maximize efficiency and guarantee |
| 348 | * success of the copySurface call. |
| 349 | */ |
| 350 | void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) { |
| 351 | if (!this->onInitCopySurfaceDstDesc(src, dstDesc)) { |
| 352 | dstDesc->fOrigin = kDefault_GrSurfaceOrigin; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 353 | dstDesc->fFlags = kRenderTarget_GrSurfaceFlag; |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 354 | dstDesc->fConfig = src->config(); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /** Internal implementation of canCopySurface. */ |
| 359 | bool internalCanCopySurface(const GrSurface* dst, |
| 360 | const GrSurface* src, |
| 361 | const SkIRect& clippedSrcRect, |
| 362 | const SkIPoint& clippedDstRect); |
| 363 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 364 | virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0; |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 365 | // TODO copy in order drawbuffer onDrawRect to here |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 366 | virtual void onDrawRect(GrPipelineBuilder*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 367 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 368 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 369 | const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 370 | const SkRect* localRect, |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 371 | const SkMatrix* localMatrix) = 0; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 372 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 373 | virtual void onStencilPath(const GrPipelineBuilder&, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 374 | const GrPathProcessor*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 375 | const GrPath*, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 376 | const GrScissorState&, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 377 | const GrStencilSettings&) = 0; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 378 | virtual void onDrawPath(const GrPathProcessor*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 379 | const GrPath*, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 380 | const GrStencilSettings&, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 381 | const PipelineInfo&) = 0; |
| 382 | virtual void onDrawPaths(const GrPathProcessor*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 383 | const GrPathRange*, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 384 | const void* indices, |
| 385 | PathIndexType, |
| 386 | const float transformValues[], |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 387 | PathTransformType, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 388 | int count, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 389 | const GrStencilSettings&, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 390 | const PipelineInfo&) = 0; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 391 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 392 | virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect, |
| 393 | GrRenderTarget* renderTarget) = 0; |
| 394 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 395 | /** The subclass will get a chance to copy the surface for falling back to the default |
| 396 | implementation, which simply draws a rectangle (and fails if dst isn't a render target). It |
| 397 | should assume that any clipping has already been performed on the rect and point. It won't |
| 398 | be called if the copy can be skipped. */ |
| 399 | virtual bool onCopySurface(GrSurface* dst, |
| 400 | GrSurface* src, |
| 401 | const SkIRect& srcRect, |
| 402 | const SkIPoint& dstPoint) = 0; |
| 403 | |
| 404 | /** Indicates whether onCopySurface would succeed. It should assume that any clipping has |
| 405 | already been performed on the rect and point. It won't be called if the copy can be |
| 406 | skipped. */ |
| 407 | virtual bool onCanCopySurface(const GrSurface* dst, |
| 408 | const GrSurface* src, |
| 409 | const SkIRect& srcRect, |
| 410 | const SkIPoint& dstPoint) = 0; |
| 411 | /** |
| 412 | * This will be called before allocating a texture to be a dst for onCopySurface. Only the |
| 413 | * dstDesc's config, flags, and origin need be set by the function. If the subclass cannot |
| 414 | * create a surface that would succeed its implementation of onCopySurface, it should return |
| 415 | * false. The base class will fall back to creating a render target to draw into using the src. |
| 416 | */ |
| 417 | virtual bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) = 0; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 418 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 419 | // Check to see if this set of draw commands has been sent out |
| 420 | virtual bool isIssued(uint32_t drawID) { return true; } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 421 | void getPathStencilSettingsForFilltype(GrPathRendering::FillType, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 422 | const GrStencilAttachment*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 423 | GrStencilSettings*); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 424 | virtual GrClipMaskManager* clipMaskManager() = 0; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 425 | virtual bool setupClip(GrPipelineBuilder*, |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 426 | GrPipelineBuilder::AutoRestoreFragmentProcessors*, |
| 427 | GrPipelineBuilder::AutoRestoreStencil*, |
| 428 | GrScissorState*, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 429 | const SkRect* devBounds) = 0; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 430 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 431 | // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget. |
| 432 | GrContext* fContext; |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 433 | // To keep track that we always have at least as many debug marker adds as removes |
| 434 | int fGpuTraceMarkerCount; |
| 435 | GrTraceMarkerSet fActiveTraceMarkers; |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 436 | GrTraceMarkerSet fStoredTraceMarkers; |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 437 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 438 | typedef SkRefCnt INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 439 | }; |
| 440 | |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 441 | /* |
| 442 | * This class is JUST for clip mask manager. Everyone else should just use draw target above. |
| 443 | */ |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 444 | class GrClipTarget : public GrDrawTarget { |
| 445 | public: |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 446 | GrClipTarget(GrContext* context) : INHERITED(context) { |
| 447 | fClipMaskManager.setClipTarget(this); |
| 448 | } |
| 449 | |
| 450 | /* Clip mask manager needs access to the context. |
| 451 | * TODO we only need a very small subset of context in the CMM. |
| 452 | */ |
| 453 | GrContext* getContext() { return INHERITED::getContext(); } |
| 454 | const GrContext* getContext() const { return INHERITED::getContext(); } |
| 455 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 456 | /** |
| 457 | * Clip Mask Manager(and no one else) needs to clear private stencil bits. |
| 458 | * ClipTarget subclass sets clip bit in the stencil buffer. The subclass |
| 459 | * is free to clear the remaining bits to zero if masked clears are more |
| 460 | * expensive than clearing all bits. |
| 461 | */ |
| 462 | virtual void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* = NULL) = 0; |
| 463 | |
joshualitt | 3bdd7dc | 2014-10-31 08:27:39 -0700 | [diff] [blame] | 464 | /** |
| 465 | * Release any resources that are cached but not currently in use. This |
| 466 | * is intended to give an application some recourse when resources are low. |
| 467 | */ |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 468 | void purgeResources() override { |
joshualitt | 3bdd7dc | 2014-10-31 08:27:39 -0700 | [diff] [blame] | 469 | // The clip mask manager can rebuild all its clip masks so just |
| 470 | // get rid of them all. |
| 471 | fClipMaskManager.purgeResources(); |
| 472 | }; |
| 473 | |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 474 | protected: |
| 475 | GrClipMaskManager fClipMaskManager; |
| 476 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 477 | private: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 478 | GrClipMaskManager* clipMaskManager() override { return &fClipMaskManager; } |
joshualitt | 329bf48 | 2014-10-29 12:31:28 -0700 | [diff] [blame] | 479 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 480 | virtual bool setupClip(GrPipelineBuilder*, |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 481 | GrPipelineBuilder::AutoRestoreFragmentProcessors*, |
| 482 | GrPipelineBuilder::AutoRestoreStencil*, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 483 | GrScissorState* scissorState, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 484 | const SkRect* devBounds) override; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 485 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 486 | typedef GrDrawTarget INHERITED; |
| 487 | }; |
| 488 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 489 | #endif |