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