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