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" |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 14 | #include "GrIndexBuffer.h" |
| 15 | #include "GrRenderTarget.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 16 | #include "GrPath.h" |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 17 | #include "GrPathRange.h" |
| 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 | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 26 | class GrGpu; |
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 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 89 | virtual void clear(const SkIRect* rect, |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 90 | GrColor color, |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 91 | bool canIgnoreRect, |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 92 | GrRenderTarget* renderTarget) SK_OVERRIDE; |
| 93 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 94 | virtual void clearStencilClip(const SkIRect& rect, |
| 95 | bool insideClip, |
| 96 | GrRenderTarget* renderTarget) SK_OVERRIDE; |
| 97 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 98 | virtual void discard(GrRenderTarget*) SK_OVERRIDE; |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 99 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 100 | virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) SK_OVERRIDE; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 101 | |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 102 | protected: |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 103 | virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE; |
| 104 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 105 | private: |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 106 | enum { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 107 | kDraw_Cmd = 1, |
| 108 | kStencilPath_Cmd = 2, |
| 109 | kSetState_Cmd = 3, |
| 110 | kSetClip_Cmd = 4, |
| 111 | kClear_Cmd = 5, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 112 | kCopySurface_Cmd = 6, |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 113 | kDrawPath_Cmd = 7, |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 114 | kDrawPaths_Cmd = 8, |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 117 | struct Cmd : ::SkNoncopyable { |
| 118 | Cmd(uint8_t type) : fType(type) {} |
| 119 | virtual ~Cmd() {} |
| 120 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 121 | virtual void execute(GrClipTarget*) = 0; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 122 | |
| 123 | uint8_t fType; |
| 124 | }; |
| 125 | |
| 126 | struct Draw : public Cmd { |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 127 | Draw(const DrawInfo& info, const GrVertexBuffer* vb, const GrIndexBuffer* ib) |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 128 | : Cmd(kDraw_Cmd) |
| 129 | , fInfo(info) |
bsalomon | 45725db | 2014-09-19 11:48:02 -0700 | [diff] [blame] | 130 | , fVertexBuffer(vb) |
| 131 | , fIndexBuffer(ib) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 132 | |
| 133 | const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } |
| 134 | const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
| 135 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 136 | virtual void execute(GrClipTarget*); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 137 | |
| 138 | DrawInfo fInfo; |
| 139 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 140 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 141 | GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; |
| 142 | GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 145 | struct StencilPath : public Cmd { |
| 146 | StencilPath(const GrPath* path) : Cmd(kStencilPath_Cmd), fPath(path) {} |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 147 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 148 | const GrPath* path() const { return fPath.get(); } |
| 149 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 150 | virtual void execute(GrClipTarget*); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 151 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 152 | GrPathRendering::FillType fFill; |
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 GrPath, kRead_GrIOType> fPath; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 158 | struct DrawPath : public Cmd { |
| 159 | DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 160 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 161 | const GrPath* path() const { return fPath.get(); } |
| 162 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 163 | virtual void execute(GrClipTarget*); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 164 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 165 | GrPathRendering::FillType fFill; |
| 166 | GrDeviceCoordTexture fDstCopy; |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 167 | |
| 168 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 169 | GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 170 | }; |
| 171 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 172 | struct DrawPaths : public Cmd { |
| 173 | DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRange(pathRange) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 174 | |
| 175 | const GrPathRange* pathRange() const { return fPathRange.get(); } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 176 | uint32_t* indices() { return reinterpret_cast<uint32_t*>(CmdBuffer::GetDataForItem(this)); } |
| 177 | float* transforms() { return reinterpret_cast<float*>(&this->indices()[fCount]); } |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 178 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 179 | virtual void execute(GrClipTarget*); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 180 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 181 | size_t fCount; |
| 182 | PathTransformType fTransformsType; |
| 183 | GrPathRendering::FillType fFill; |
| 184 | GrDeviceCoordTexture fDstCopy; |
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 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 196 | virtual void execute(GrClipTarget*); |
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 | |
| 212 | virtual void execute(GrClipTarget*); |
| 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 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 227 | virtual void execute(GrClipTarget*); |
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 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 240 | virtual void execute(GrClipTarget*); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 241 | |
| 242 | GrDrawState fState; |
bsalomon | f0480b1 | 2014-07-02 12:11:24 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 245 | struct SetClip : public Cmd { |
| 246 | SetClip(const GrClipData* clipData) |
| 247 | : Cmd(kSetClip_Cmd), |
| 248 | fStackStorage(*clipData->fClipStack) { |
| 249 | fClipData.fClipStack = &fStackStorage; |
| 250 | fClipData.fOrigin = clipData->fOrigin; |
| 251 | } |
| 252 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 253 | virtual void execute(GrClipTarget*); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 254 | |
| 255 | GrClipData fClipData; |
| 256 | |
| 257 | private: |
| 258 | SkClipStack fStackStorage; |
| 259 | }; |
| 260 | |
| 261 | typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double. |
| 262 | typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
| 263 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 264 | // overrides from GrDrawTarget |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 265 | virtual void onDraw(const DrawInfo&) SK_OVERRIDE; |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 266 | virtual void onDrawRect(const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 267 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 268 | const SkMatrix* localMatrix) SK_OVERRIDE; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 269 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 270 | virtual void onStencilPath(const GrPath*, GrPathRendering::FillType) SK_OVERRIDE; |
| 271 | virtual void onDrawPath(const GrPath*, GrPathRendering::FillType, |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 272 | const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 273 | virtual void onDrawPaths(const GrPathRange*, |
| 274 | const uint32_t indices[], int count, |
| 275 | const float transforms[], PathTransformType, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 276 | GrPathRendering::FillType, const GrDeviceCoordTexture*) SK_OVERRIDE; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 277 | |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 278 | virtual bool onReserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 279 | int vertexCount, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 280 | void** vertices) SK_OVERRIDE; |
| 281 | virtual bool onReserveIndexSpace(int indexCount, |
| 282 | void** indices) SK_OVERRIDE; |
| 283 | virtual void releaseReservedVertexSpace() SK_OVERRIDE; |
| 284 | virtual void releaseReservedIndexSpace() SK_OVERRIDE; |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 285 | virtual void geometrySourceWillPush() SK_OVERRIDE; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 286 | virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE; |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 287 | virtual void willReserveVertexAndIndexSpace(int vertexCount, |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 288 | int indexCount) SK_OVERRIDE; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 289 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 290 | bool quickInsideClip(const SkRect& devBounds); |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 291 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 292 | virtual void didAddGpuTraceMarker() SK_OVERRIDE {} |
| 293 | virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 294 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 295 | // Attempts to concat instances from info onto the previous draw. info must represent an |
| 296 | // instanced draw. The caller must have already recorded a new draw state and clip if necessary. |
| 297 | int concatInstancedDraw(const DrawInfo& info); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 298 | |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 299 | // Determines whether the current draw operation requieres a new drawstate and if so records it. |
| 300 | void recordStateIfNecessary(); |
| 301 | // 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] | 302 | void recordClipIfNecessary(); |
| 303 | // Records any trace markers for a command after adding it to the buffer. |
| 304 | void recordTraceMarkersIfNecessary(); |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 305 | |
| 306 | virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 307 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 308 | // TODO: Use a single allocator for commands and records |
bsalomon@google.com | 4b90c62 | 2011-09-28 17:52:15 +0000 | [diff] [blame] | 309 | enum { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 310 | kCmdBufferInitialSizeInBytes = 64 * 1024, |
| 311 | kGeoPoolStatePreAllocCnt = 4, |
bsalomon@google.com | 4b90c62 | 2011-09-28 17:52:15 +0000 | [diff] [blame] | 312 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 313 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 314 | CmdBuffer fCmdBuffer; |
| 315 | GrDrawState* fLastState; |
| 316 | GrClipData* fLastClip; |
bsalomon | bce3d6d | 2014-07-02 07:54:42 -0700 | [diff] [blame] | 317 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 318 | SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 319 | GrClipTarget* fDstGpu; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 320 | bool fClipSet; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 321 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 322 | enum ClipProxyState { |
| 323 | kUnknown_ClipProxyState, |
| 324 | kValid_ClipProxyState, |
| 325 | kInvalid_ClipProxyState |
| 326 | }; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 327 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 328 | ClipProxyState fClipProxyState; |
| 329 | SkRect fClipProxy; |
| 330 | GrVertexBufferAllocPool& fVertexPool; |
| 331 | GrIndexBufferAllocPool& fIndexPool; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 332 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 333 | struct GeometryPoolState { |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 334 | const GrVertexBuffer* fPoolVertexBuffer; |
| 335 | int fPoolStartVertex; |
| 336 | const GrIndexBuffer* fPoolIndexBuffer; |
| 337 | int fPoolStartIndex; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 338 | // caller may conservatively over reserve vertices / indices. |
| 339 | // we release unused space back to allocator if possible |
| 340 | // can only do this if there isn't an intervening pushGeometrySource() |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 341 | size_t fUsedPoolVertexBytes; |
| 342 | size_t fUsedPoolIndexBytes; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 343 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 344 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 345 | typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateStack; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 346 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 347 | GeoPoolStateStack fGeoPoolStateStack; |
| 348 | bool fFlushing; |
| 349 | uint32_t fDrawID; |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 350 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 351 | typedef GrClipTarget INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 352 | }; |
| 353 | |
| 354 | #endif |