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