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 2011 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 GrInOrderDrawBuffer_DEFINED |
| 9 | #define GrInOrderDrawBuffer_DEFINED |
| 10 | |
| 11 | #include "GrDrawTarget.h" |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 12 | #include "GrGpu.h" |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 13 | #include "GrIndexBuffer.h" |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 14 | #include "GrOptDrawState.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 15 | #include "GrPath.h" |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 16 | #include "GrPathRange.h" |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 17 | #include "GrRenderTarget.h" |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 18 | #include "GrSurface.h" |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 19 | #include "GrTRecorder.h" |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 20 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 22 | #include "SkClipStack.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 23 | #include "SkTemplates.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 24 | #include "SkTypes.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 25 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 26 | class GrIndexBufferAllocPool; |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 27 | class GrVertexBufferAllocPool; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 29 | /** |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 30 | * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual |
| 31 | * playback into a GrGpu. In theory one draw buffer could playback into another. When index or |
| 32 | * vertex buffers are used as geometry sources it is the callers the draw buffer only holds |
| 33 | * references to the buffers. It is the callers responsibility to ensure that the data is still |
| 34 | * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's |
| 35 | * responsibility to ensure that all referenced textures, buffers, and render-targets are associated |
| 36 | * in the GrGpu object that the buffer is played back into. The buffer requires VB and IB pools to |
| 37 | * store geometry. |
skia.committer@gmail.com | 07d3a65 | 2013-04-10 07:01:15 +0000 | [diff] [blame] | 38 | */ |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 39 | class GrInOrderDrawBuffer : public GrClipTarget { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | public: |
| 41 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 42 | /** |
| 43 | * Creates a GrInOrderDrawBuffer |
| 44 | * |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 45 | * @param gpu the gpu object that this draw buffer flushes to. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 46 | * @param vertexPool pool where vertices for queued draws will be saved when |
| 47 | * the vertex source is either reserved or array. |
| 48 | * @param indexPool pool where indices for queued draws will be saved when |
| 49 | * the index source is either reserved or array. |
| 50 | */ |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 51 | GrInOrderDrawBuffer(GrGpu* gpu, |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 52 | GrVertexBufferAllocPool* vertexPool, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 53 | GrIndexBufferAllocPool* indexPool); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 54 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 55 | ~GrInOrderDrawBuffer() SK_OVERRIDE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 56 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 57 | /** |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 58 | * Empties the draw buffer of any queued up draws. This must not be called while inside an |
| 59 | * unbalanced pushGeometrySource(). The current draw state and clip are preserved. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 60 | */ |
| 61 | void reset(); |
| 62 | |
| 63 | /** |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 64 | * This plays the queued up draws to its GrGpu target. It also resets this object (i.e. flushing |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 65 | * is destructive). This buffer must not have an active reserved vertex or index source. Any |
| 66 | * reserved geometry on the target will be finalized because it's geometry source will be pushed |
| 67 | * before flushing and popped afterwards. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 68 | */ |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 69 | void flush(); |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 70 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 71 | // tracking for draws |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 72 | DrawToken getCurrentDrawToken() { return DrawToken(this, fDrawID); } |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 73 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 74 | // overrides from GrDrawTarget |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 75 | bool geometryHints(size_t vertexStride, |
| 76 | int* vertexCount, |
| 77 | int* indexCount) const SK_OVERRIDE; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 78 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 79 | void clearStencilClip(const SkIRect& rect, |
| 80 | bool insideClip, |
| 81 | GrRenderTarget* renderTarget) SK_OVERRIDE; |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 82 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 83 | void discard(GrRenderTarget*) SK_OVERRIDE; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 84 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 85 | private: |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 86 | typedef GrClipMaskManager::ScissorState ScissorState; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 87 | enum { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 88 | kDraw_Cmd = 1, |
| 89 | kStencilPath_Cmd = 2, |
| 90 | kSetState_Cmd = 3, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 91 | kClear_Cmd = 4, |
| 92 | kCopySurface_Cmd = 5, |
| 93 | kDrawPath_Cmd = 6, |
| 94 | kDrawPaths_Cmd = 7, |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 97 | struct Cmd : ::SkNoncopyable { |
| 98 | Cmd(uint8_t type) : fType(type) {} |
| 99 | virtual ~Cmd() {} |
| 100 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 101 | virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) = 0; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 102 | |
| 103 | uint8_t fType; |
| 104 | }; |
| 105 | |
| 106 | struct Draw : public Cmd { |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 107 | Draw(const DrawInfo& info) : Cmd(kDraw_Cmd), fInfo(info) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 108 | |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 109 | void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 110 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 111 | DrawInfo fInfo; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 114 | struct StencilPath : public Cmd { |
| 115 | StencilPath(const GrPath* path) : Cmd(kStencilPath_Cmd), fPath(path) {} |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 116 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 117 | const GrPath* path() const { return fPath.get(); } |
| 118 | |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 119 | void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 120 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 121 | GrStencilSettings fStencilSettings; |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 122 | |
| 123 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 124 | GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 127 | struct DrawPath : public Cmd { |
| 128 | DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 129 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 130 | const GrPath* path() const { return fPath.get(); } |
| 131 | |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 132 | void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 133 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 134 | GrStencilSettings fStencilSettings; |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 135 | |
| 136 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 137 | GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 140 | struct DrawPaths : public Cmd { |
| 141 | DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRange(pathRange) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 142 | |
| 143 | const GrPathRange* pathRange() const { return fPathRange.get(); } |
| 144 | |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 145 | void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 146 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 147 | int fIndicesLocation; |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 148 | PathIndexType fIndexType; |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 149 | int fTransformsLocation; |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 150 | PathTransformType fTransformType; |
| 151 | int fCount; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 152 | GrStencilSettings fStencilSettings; |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 153 | |
| 154 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 155 | GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 158 | // This is also used to record a discard by setting the color to GrColor_ILLEGAL |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 159 | struct Clear : public Cmd { |
| 160 | Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} |
| 161 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 162 | GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 163 | |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 164 | void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 165 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 166 | SkIRect fRect; |
| 167 | GrColor fColor; |
| 168 | bool fCanIgnoreRect; |
| 169 | |
| 170 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 171 | GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 174 | // This command is ONLY used by the clip mask manager to clear the stencil clip bits |
| 175 | struct ClearStencilClip : public Cmd { |
| 176 | ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} |
| 177 | |
| 178 | GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
| 179 | |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 180 | void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 181 | |
| 182 | SkIRect fRect; |
| 183 | bool fInsideClip; |
| 184 | |
| 185 | private: |
| 186 | GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
| 187 | }; |
| 188 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 189 | struct CopySurface : public Cmd { |
| 190 | CopySurface(GrSurface* dst, GrSurface* src) : Cmd(kCopySurface_Cmd), fDst(dst), fSrc(src) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 191 | |
| 192 | GrSurface* dst() const { return fDst.get(); } |
| 193 | GrSurface* src() const { return fSrc.get(); } |
| 194 | |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 195 | void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 196 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 197 | SkIPoint fDstPoint; |
| 198 | SkIRect fSrcRect; |
| 199 | |
| 200 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 201 | GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
| 202 | GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 203 | }; |
| 204 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 205 | struct SetState : public Cmd { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 206 | SetState(const GrDrawState& drawState, GrGpu* gpu, const ScissorState& scissor, |
| 207 | const GrDeviceCoordTexture* dstCopy, GrGpu::DrawType drawType) |
| 208 | : Cmd(kSetState_Cmd) |
| 209 | , fState(drawState, gpu, scissor, dstCopy, drawType) {} |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 210 | |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 211 | void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 212 | |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 213 | const GrOptDrawState fState; |
| 214 | GrGpu::DrawType fDrawType; |
bsalomon | f0480b1 | 2014-07-02 12:11:24 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 217 | typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double. |
| 218 | typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
| 219 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 220 | // overrides from GrDrawTarget |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 221 | void onDraw(const GrDrawState&, |
| 222 | const DrawInfo&, |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 223 | const ScissorState&, |
| 224 | const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 225 | void onDrawRect(GrDrawState*, |
| 226 | const SkRect& rect, |
| 227 | const SkRect* localRect, |
| 228 | const SkMatrix* localMatrix) SK_OVERRIDE; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 229 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 230 | void onStencilPath(const GrDrawState&, |
| 231 | const GrPath*, |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 232 | const ScissorState&, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 233 | const GrStencilSettings&) SK_OVERRIDE; |
| 234 | void onDrawPath(const GrDrawState&, |
| 235 | const GrPath*, |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 236 | const ScissorState&, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 237 | const GrStencilSettings&, |
| 238 | const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
| 239 | void onDrawPaths(const GrDrawState&, |
| 240 | const GrPathRange*, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 241 | const void* indices, |
| 242 | PathIndexType, |
| 243 | const float transformValues[], |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 244 | PathTransformType, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 245 | int count, |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 246 | const ScissorState&, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 247 | const GrStencilSettings&, |
| 248 | const GrDeviceCoordTexture*) SK_OVERRIDE; |
| 249 | void onClear(const SkIRect* rect, |
| 250 | GrColor color, |
| 251 | bool canIgnoreRect, |
| 252 | GrRenderTarget* renderTarget) SK_OVERRIDE; |
| 253 | void setDrawBuffers(DrawInfo*) SK_OVERRIDE; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 254 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 255 | bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) SK_OVERRIDE; |
| 256 | bool onReserveIndexSpace(int indexCount, void** indices) SK_OVERRIDE; |
| 257 | void releaseReservedVertexSpace() SK_OVERRIDE; |
| 258 | void releaseReservedIndexSpace() SK_OVERRIDE; |
| 259 | void geometrySourceWillPush() SK_OVERRIDE; |
| 260 | void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE; |
| 261 | void willReserveVertexAndIndexSpace(int vertexCount, |
| 262 | size_t vertexStride, |
| 263 | int indexCount) SK_OVERRIDE; |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 264 | bool onCopySurface(GrSurface* dst, |
| 265 | GrSurface* src, |
| 266 | const SkIRect& srcRect, |
| 267 | const SkIPoint& dstPoint) SK_OVERRIDE; |
| 268 | bool onCanCopySurface(const GrSurface* dst, |
| 269 | const GrSurface* src, |
| 270 | const SkIRect& srcRect, |
| 271 | const SkIPoint& dstPoint) SK_OVERRIDE; |
| 272 | bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) SK_OVERRIDE; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 273 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 274 | // Attempts to concat instances from info onto the previous draw. info must represent an |
| 275 | // instanced draw. The caller must have already recorded a new draw state and clip if necessary. |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 276 | int concatInstancedDraw(const GrDrawState&, const DrawInfo&); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 277 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 278 | // Determines whether the current draw operation requires a new GrOptDrawState and if so |
| 279 | // records it. If the draw can be skipped false is returned and no new GrOptDrawState is |
| 280 | // recorded. |
| 281 | bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(const GrDrawState&, |
| 282 | GrGpu::DrawType, |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 283 | const GrClipMaskManager::ScissorState&, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 284 | const GrDeviceCoordTexture*); |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 285 | // We lazily record clip changes in order to skip clips that have no effect. |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 286 | void recordClipIfNecessary(); |
| 287 | // Records any trace markers for a command after adding it to the buffer. |
| 288 | void recordTraceMarkersIfNecessary(); |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 289 | |
| 290 | virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 291 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 292 | // TODO: Use a single allocator for commands and records |
bsalomon@google.com | 4b90c62 | 2011-09-28 17:52:15 +0000 | [diff] [blame] | 293 | enum { |
cdalton | c4650ee | 2014-11-07 12:51:18 -0800 | [diff] [blame] | 294 | kCmdBufferInitialSizeInBytes = 8 * 1024, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 295 | kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's |
| 296 | kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 297 | kGeoPoolStatePreAllocCnt = 4, |
bsalomon@google.com | 4b90c62 | 2011-09-28 17:52:15 +0000 | [diff] [blame] | 298 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 299 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 300 | struct GeometryPoolState { |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 301 | const GrVertexBuffer* fPoolVertexBuffer; |
| 302 | int fPoolStartVertex; |
| 303 | const GrIndexBuffer* fPoolIndexBuffer; |
| 304 | int fPoolStartIndex; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 305 | // caller may conservatively over reserve vertices / indices. |
| 306 | // we release unused space back to allocator if possible |
| 307 | // can only do this if there isn't an intervening pushGeometrySource() |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 308 | size_t fUsedPoolVertexBytes; |
| 309 | size_t fUsedPoolIndexBytes; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 310 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 311 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 312 | typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateStack; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 313 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 314 | CmdBuffer fCmdBuffer; |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 315 | const GrOptDrawState* fPrevState; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 316 | SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
| 317 | GrGpu* fDstGpu; |
| 318 | GrVertexBufferAllocPool& fVertexPool; |
| 319 | GrIndexBufferAllocPool& fIndexPool; |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 320 | SkTDArray<char> fPathIndexBuffer; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 321 | SkTDArray<float> fPathTransformBuffer; |
| 322 | GeoPoolStateStack fGeoPoolStateStack; |
| 323 | bool fFlushing; |
| 324 | uint32_t fDrawID; |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 325 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 326 | typedef GrClipTarget INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | #endif |