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" |
| 19 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 21 | #include "SkClipStack.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 22 | #include "SkTemplates.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 23 | #include "SkTypes.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 24 | |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 25 | class GrGpu; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 26 | class GrIndexBufferAllocPool; |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 27 | class GrVertexBufferAllocPool; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 29 | /** |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 30 | * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual |
| 31 | * playback into a GrGpu. In theory one draw buffer could playback into another. When index or |
| 32 | * vertex buffers are used as geometry sources it is the callers the draw buffer only holds |
| 33 | * references to the buffers. It is the callers responsibility to ensure that the data is still |
| 34 | * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's |
| 35 | * responsibility to ensure that all referenced textures, buffers, and render-targets are associated |
| 36 | * in the GrGpu object that the buffer is played back into. The buffer requires VB and IB pools to |
| 37 | * store geometry. |
skia.committer@gmail.com | 07d3a65 | 2013-04-10 07:01:15 +0000 | [diff] [blame] | 38 | */ |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 39 | class GrInOrderDrawBuffer : public GrDrawTarget { |
| 40 | public: |
| 41 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 42 | /** |
| 43 | * Creates a GrInOrderDrawBuffer |
| 44 | * |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 45 | * @param gpu the gpu object that this draw buffer flushes to. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 46 | * @param vertexPool pool where vertices for queued draws will be saved when |
| 47 | * the vertex source is either reserved or array. |
| 48 | * @param indexPool pool where indices for queued draws will be saved when |
| 49 | * the index source is either reserved or array. |
| 50 | */ |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 51 | GrInOrderDrawBuffer(GrGpu* gpu, |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 52 | GrVertexBufferAllocPool* vertexPool, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 53 | GrIndexBufferAllocPool* indexPool); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 54 | |
| 55 | virtual ~GrInOrderDrawBuffer(); |
| 56 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 57 | /** |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 58 | * Empties the draw buffer of any queued up draws. This must not be called while inside an |
| 59 | * unbalanced pushGeometrySource(). The current draw state and clip are preserved. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 60 | */ |
| 61 | void reset(); |
| 62 | |
| 63 | /** |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 64 | * This plays the queued up draws to its GrGpu target. It also resets this object (i.e. flushing |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 65 | * is destructive). This buffer must not have an active reserved vertex or index source. Any |
| 66 | * reserved geometry on the target will be finalized because it's geometry source will be pushed |
| 67 | * before flushing and popped afterwards. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 68 | */ |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 69 | void flush(); |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 70 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 71 | // tracking for draws |
| 72 | virtual DrawToken getCurrentDrawToken() { return DrawToken(this, fDrawID); } |
| 73 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 74 | // overrides from GrDrawTarget |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 75 | virtual bool geometryHints(int* vertexCount, |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 76 | int* indexCount) const SK_OVERRIDE; |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 77 | virtual void clear(const SkIRect* rect, |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 78 | GrColor color, |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 79 | bool canIgnoreRect, |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 80 | GrRenderTarget* renderTarget) SK_OVERRIDE; |
| 81 | |
| 82 | virtual void discard(GrRenderTarget*) SK_OVERRIDE; |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 83 | |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 84 | virtual void initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) SK_OVERRIDE; |
| 85 | |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 86 | protected: |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 87 | virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE; |
| 88 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 89 | private: |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 90 | enum Cmd { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 91 | kDraw_Cmd = 1, |
| 92 | kStencilPath_Cmd = 2, |
| 93 | kSetState_Cmd = 3, |
| 94 | kSetClip_Cmd = 4, |
| 95 | kClear_Cmd = 5, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 96 | kCopySurface_Cmd = 6, |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 97 | kDrawPath_Cmd = 7, |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 98 | kDrawPaths_Cmd = 8, |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 101 | class Draw : public DrawInfo { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 102 | public: |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 103 | Draw(const DrawInfo& info, const GrVertexBuffer* vb, const GrIndexBuffer* ib) |
| 104 | : DrawInfo(info) |
bsalomon | 45725db | 2014-09-19 11:48:02 -0700 | [diff] [blame] | 105 | , fVertexBuffer(vb) |
| 106 | , fIndexBuffer(ib) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 107 | |
| 108 | const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } |
| 109 | const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
| 110 | |
| 111 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame^] | 112 | GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; |
| 113 | GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 116 | struct StencilPath : public ::SkNoncopyable { |
bsalomon | 45725db | 2014-09-19 11:48:02 -0700 | [diff] [blame] | 117 | StencilPath(const GrPath* path) : fPath(path) {} |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 118 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 119 | const GrPath* path() const { return fPath.get(); } |
| 120 | |
| 121 | SkPath::FillType fFill; |
| 122 | |
| 123 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame^] | 124 | GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 127 | struct DrawPath : public ::SkNoncopyable { |
bsalomon | 45725db | 2014-09-19 11:48:02 -0700 | [diff] [blame] | 128 | DrawPath(const GrPath* path) : fPath(path) {} |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 129 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 130 | const GrPath* path() const { return fPath.get(); } |
| 131 | |
| 132 | SkPath::FillType fFill; |
| 133 | GrDeviceCoordTexture fDstCopy; |
| 134 | |
| 135 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame^] | 136 | GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 139 | struct DrawPaths : public ::SkNoncopyable { |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 140 | DrawPaths(const GrPathRange* pathRange) |
bsalomon | 45725db | 2014-09-19 11:48:02 -0700 | [diff] [blame] | 141 | : fPathRange(pathRange) {} |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 142 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 143 | ~DrawPaths() { |
| 144 | if (fTransforms) { |
| 145 | SkDELETE_ARRAY(fTransforms); |
| 146 | } |
| 147 | if (fIndices) { |
| 148 | SkDELETE_ARRAY(fIndices); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | const GrPathRange* pathRange() const { return fPathRange.get(); } |
| 153 | |
| 154 | uint32_t* fIndices; |
| 155 | size_t fCount; |
| 156 | float* fTransforms; |
| 157 | PathTransformType fTransformsType; |
| 158 | SkPath::FillType fFill; |
| 159 | GrDeviceCoordTexture fDstCopy; |
| 160 | |
| 161 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame^] | 162 | GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 165 | // This is also used to record a discard by setting the color to GrColor_ILLEGAL |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 166 | struct Clear : public ::SkNoncopyable { |
bsalomon | 45725db | 2014-09-19 11:48:02 -0700 | [diff] [blame] | 167 | Clear(GrRenderTarget* rt) : fRenderTarget(rt) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 168 | ~Clear() { } |
| 169 | GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 170 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 171 | SkIRect fRect; |
| 172 | GrColor fColor; |
| 173 | bool fCanIgnoreRect; |
| 174 | |
| 175 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame^] | 176 | GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 179 | struct CopySurface : public ::SkNoncopyable { |
bsalomon | 45725db | 2014-09-19 11:48:02 -0700 | [diff] [blame] | 180 | CopySurface(GrSurface* dst, GrSurface* src) : fDst(dst), fSrc(src) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 181 | |
| 182 | GrSurface* dst() const { return fDst.get(); } |
| 183 | GrSurface* src() const { return fSrc.get(); } |
| 184 | |
| 185 | SkIPoint fDstPoint; |
| 186 | SkIRect fSrcRect; |
| 187 | |
| 188 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame^] | 189 | GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
| 190 | GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 191 | }; |
| 192 | |
bsalomon | f0480b1 | 2014-07-02 12:11:24 -0700 | [diff] [blame] | 193 | struct Clip : public ::SkNoncopyable { |
| 194 | SkClipStack fStack; |
| 195 | SkIPoint fOrigin; |
| 196 | }; |
| 197 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 198 | // overrides from GrDrawTarget |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 199 | virtual void onDraw(const DrawInfo&) SK_OVERRIDE; |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 200 | virtual void onDrawRect(const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 201 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 202 | const SkMatrix* localMatrix) SK_OVERRIDE; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 203 | |
| 204 | virtual void onStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |
| 205 | virtual void onDrawPath(const GrPath*, SkPath::FillType, |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 206 | const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 207 | virtual void onDrawPaths(const GrPathRange*, |
| 208 | const uint32_t indices[], int count, |
| 209 | const float transforms[], PathTransformType, |
| 210 | SkPath::FillType, const GrDeviceCoordTexture*) SK_OVERRIDE; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 211 | |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 212 | virtual bool onReserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 213 | int vertexCount, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 214 | void** vertices) SK_OVERRIDE; |
| 215 | virtual bool onReserveIndexSpace(int indexCount, |
| 216 | void** indices) SK_OVERRIDE; |
| 217 | virtual void releaseReservedVertexSpace() SK_OVERRIDE; |
| 218 | virtual void releaseReservedIndexSpace() SK_OVERRIDE; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 219 | virtual void onSetVertexSourceToArray(const void* vertexArray, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 220 | int vertexCount) SK_OVERRIDE; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 221 | virtual void onSetIndexSourceToArray(const void* indexArray, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 222 | int indexCount) SK_OVERRIDE; |
| 223 | virtual void releaseVertexArray() SK_OVERRIDE; |
| 224 | virtual void releaseIndexArray() SK_OVERRIDE; |
| 225 | virtual void geometrySourceWillPush() SK_OVERRIDE; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 226 | virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE; |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 227 | virtual void willReserveVertexAndIndexSpace(int vertexCount, |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 228 | int indexCount) SK_OVERRIDE; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 229 | virtual bool onCopySurface(GrSurface* dst, |
| 230 | GrSurface* src, |
| 231 | const SkIRect& srcRect, |
| 232 | const SkIPoint& dstPoint) SK_OVERRIDE; |
| 233 | virtual bool onCanCopySurface(GrSurface* dst, |
| 234 | GrSurface* src, |
| 235 | const SkIRect& srcRect, |
| 236 | const SkIPoint& dstPoint) SK_OVERRIDE; |
| 237 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 238 | bool quickInsideClip(const SkRect& devBounds); |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 239 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 240 | virtual void didAddGpuTraceMarker() SK_OVERRIDE {} |
| 241 | virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 242 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 243 | // Attempts to concat instances from info onto the previous draw. info must represent an |
| 244 | // instanced draw. The caller must have already recorded a new draw state and clip if necessary. |
| 245 | int concatInstancedDraw(const DrawInfo& info); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 246 | |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 247 | // Determines whether the current draw operation requieres a new drawstate and if so records it. |
| 248 | void recordStateIfNecessary(); |
| 249 | // We lazily record clip changes in order to skip clips that have no effect. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 250 | bool needsNewClip() const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 251 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 252 | // these functions record a command |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 253 | void recordState(); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 254 | void recordClip(); |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 255 | Draw* recordDraw(const DrawInfo&, const GrVertexBuffer*, const GrIndexBuffer*); |
| 256 | StencilPath* recordStencilPath(const GrPath*); |
| 257 | DrawPath* recordDrawPath(const GrPath*); |
| 258 | DrawPaths* recordDrawPaths(const GrPathRange*); |
| 259 | Clear* recordClear(GrRenderTarget*); |
| 260 | CopySurface* recordCopySurface(GrSurface* dst, GrSurface* src); |
| 261 | |
| 262 | virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
| 263 | void addToCmdBuffer(uint8_t cmd); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 264 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 265 | // TODO: Use a single allocator for commands and records |
bsalomon@google.com | 4b90c62 | 2011-09-28 17:52:15 +0000 | [diff] [blame] | 266 | enum { |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 267 | kCmdPreallocCnt = 32, |
bsalomon | bce3d6d | 2014-07-02 07:54:42 -0700 | [diff] [blame] | 268 | kDrawPreallocCnt = 16, |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 269 | kStencilPathPreallocCnt = 8, |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 270 | kDrawPathPreallocCnt = 8, |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 271 | kDrawPathsPreallocCnt = 8, |
bsalomon@google.com | 4b90c62 | 2011-09-28 17:52:15 +0000 | [diff] [blame] | 272 | kStatePreallocCnt = 8, |
| 273 | kClipPreallocCnt = 8, |
bsalomon | bce3d6d | 2014-07-02 07:54:42 -0700 | [diff] [blame] | 274 | kClearPreallocCnt = 8, |
bsalomon@google.com | 4b90c62 | 2011-09-28 17:52:15 +0000 | [diff] [blame] | 275 | kGeoPoolStatePreAllocCnt = 4, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 276 | kCopySurfacePreallocCnt = 4, |
bsalomon@google.com | 4b90c62 | 2011-09-28 17:52:15 +0000 | [diff] [blame] | 277 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 278 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 279 | typedef GrTAllocator<Draw> DrawAllocator; |
| 280 | typedef GrTAllocator<StencilPath> StencilPathAllocator; |
| 281 | typedef GrTAllocator<DrawPath> DrawPathAllocator; |
| 282 | typedef GrTAllocator<DrawPaths> DrawPathsAllocator; |
| 283 | typedef GrTAllocator<GrDrawState> StateAllocator; |
| 284 | typedef GrTAllocator<Clear> ClearAllocator; |
| 285 | typedef GrTAllocator<CopySurface> CopySurfaceAllocator; |
| 286 | typedef GrTAllocator<Clip> ClipAllocator; |
bsalomon | bce3d6d | 2014-07-02 07:54:42 -0700 | [diff] [blame] | 287 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 288 | GrSTAllocator<kDrawPreallocCnt, Draw> fDraws; |
| 289 | GrSTAllocator<kStencilPathPreallocCnt, StencilPath> fStencilPaths; |
| 290 | GrSTAllocator<kDrawPathPreallocCnt, DrawPath> fDrawPath; |
| 291 | GrSTAllocator<kDrawPathsPreallocCnt, DrawPaths> fDrawPaths; |
| 292 | GrSTAllocator<kStatePreallocCnt, GrDrawState> fStates; |
| 293 | GrSTAllocator<kClearPreallocCnt, Clear> fClears; |
| 294 | GrSTAllocator<kCopySurfacePreallocCnt, CopySurface> fCopySurfaces; |
| 295 | GrSTAllocator<kClipPreallocCnt, Clip> fClips; |
bsalomon | bce3d6d | 2014-07-02 07:54:42 -0700 | [diff] [blame] | 296 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 297 | SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
| 298 | SkSTArray<kCmdPreallocCnt, uint8_t, true> fCmds; |
| 299 | GrDrawTarget* fDstGpu; |
| 300 | bool fClipSet; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 301 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 302 | enum ClipProxyState { |
| 303 | kUnknown_ClipProxyState, |
| 304 | kValid_ClipProxyState, |
| 305 | kInvalid_ClipProxyState |
| 306 | }; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 307 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 308 | ClipProxyState fClipProxyState; |
| 309 | SkRect fClipProxy; |
| 310 | GrVertexBufferAllocPool& fVertexPool; |
| 311 | GrIndexBufferAllocPool& fIndexPool; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 312 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 313 | struct GeometryPoolState { |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 314 | const GrVertexBuffer* fPoolVertexBuffer; |
| 315 | int fPoolStartVertex; |
| 316 | const GrIndexBuffer* fPoolIndexBuffer; |
| 317 | int fPoolStartIndex; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 318 | // caller may conservatively over reserve vertices / indices. |
| 319 | // we release unused space back to allocator if possible |
| 320 | // can only do this if there isn't an intervening pushGeometrySource() |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 321 | size_t fUsedPoolVertexBytes; |
| 322 | size_t fUsedPoolIndexBytes; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 323 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 324 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 325 | typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateStack; |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 326 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 327 | GeoPoolStateStack fGeoPoolStateStack; |
| 328 | bool fFlushing; |
| 329 | uint32_t fDrawID; |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 330 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 331 | typedef GrDrawTarget INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | #endif |