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 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 11 | #include "GrFlushToGpuDrawTarget.h" |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 12 | |
| 13 | #include "GrBatch.h" |
| 14 | #include "GrBatchTarget.h" |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 15 | #include "SkChunkAlloc.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 16 | #include "GrPipeline.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 17 | #include "GrPath.h" |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 18 | #include "GrTRecorder.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 20 | /** |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 21 | * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual |
| 22 | * playback into a GrGpu. In theory one draw buffer could playback into another. When index or |
| 23 | * vertex buffers are used as geometry sources it is the callers the draw buffer only holds |
| 24 | * references to the buffers. It is the callers responsibility to ensure that the data is still |
| 25 | * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's |
| 26 | * responsibility to ensure that all referenced textures, buffers, and render-targets are associated |
| 27 | * in the GrGpu object that the buffer is played back into. The buffer requires VB and IB pools to |
| 28 | * store geometry. |
skia.committer@gmail.com | 07d3a65 | 2013-04-10 07:01:15 +0000 | [diff] [blame] | 29 | */ |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 30 | class GrInOrderDrawBuffer : public GrFlushToGpuDrawTarget { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 31 | public: |
| 32 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 33 | /** |
| 34 | * Creates a GrInOrderDrawBuffer |
| 35 | * |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 36 | * @param gpu the gpu object that this draw buffer flushes to. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 37 | * @param vertexPool pool where vertices for queued draws will be saved when |
| 38 | * the vertex source is either reserved or array. |
| 39 | * @param indexPool pool where indices for queued draws will be saved when |
| 40 | * the index source is either reserved or array. |
| 41 | */ |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 42 | GrInOrderDrawBuffer(GrGpu* gpu, |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 43 | GrVertexBufferAllocPool* vertexPool, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 44 | GrIndexBufferAllocPool* indexPool); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 45 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 46 | ~GrInOrderDrawBuffer() SK_OVERRIDE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 48 | // tracking for draws |
tfarina | 912ed6e | 2014-12-14 15:20:10 -0800 | [diff] [blame] | 49 | DrawToken getCurrentDrawToken() SK_OVERRIDE { return DrawToken(this, fDrawID); } |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 50 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 51 | void clearStencilClip(const SkIRect& rect, |
| 52 | bool insideClip, |
| 53 | GrRenderTarget* renderTarget) SK_OVERRIDE; |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 54 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 55 | void discard(GrRenderTarget*) SK_OVERRIDE; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 56 | |
robertphillips | 54fac8b | 2015-02-16 09:35:50 -0800 | [diff] [blame] | 57 | protected: |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 58 | void willReserveVertexAndIndexSpace(int vertexCount, |
| 59 | size_t vertexStride, |
| 60 | int indexCount); |
| 61 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 62 | private: |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 63 | typedef GrGpu::DrawArgs DrawArgs; |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 64 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 65 | struct SetState; |
| 66 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 67 | struct Cmd : ::SkNoncopyable { |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 68 | enum { |
| 69 | kDraw_Cmd = 1, |
| 70 | kStencilPath_Cmd = 2, |
| 71 | kSetState_Cmd = 3, |
| 72 | kClear_Cmd = 4, |
| 73 | kCopySurface_Cmd = 5, |
| 74 | kDrawPath_Cmd = 6, |
| 75 | kDrawPaths_Cmd = 7, |
| 76 | kDrawBatch_Cmd = 8, |
| 77 | }; |
| 78 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 79 | Cmd(uint8_t type) : fType(type) {} |
| 80 | virtual ~Cmd() {} |
| 81 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 82 | virtual void execute(GrGpu*, const SetState*) = 0; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 83 | |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 84 | uint8_t type() const { return fType & kCmdMask; } |
| 85 | |
| 86 | bool isTraced() const { return SkToBool(fType & kTraceCmdBit); } |
| 87 | void makeTraced() { fType |= kTraceCmdBit; } |
| 88 | |
| 89 | private: |
| 90 | static const int kCmdMask = 0x7F; |
| 91 | static const int kTraceCmdBit = 0x80; |
| 92 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 93 | uint8_t fType; |
| 94 | }; |
| 95 | |
| 96 | struct Draw : public Cmd { |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 97 | Draw(const DrawInfo& info) : Cmd(kDraw_Cmd), fInfo(info) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 98 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 99 | void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 100 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 101 | DrawInfo fInfo; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 104 | struct StencilPath : public Cmd { |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 105 | StencilPath(const GrPath* path, GrRenderTarget* rt) |
| 106 | : Cmd(kStencilPath_Cmd) |
| 107 | , fRenderTarget(rt) |
| 108 | , fPath(path) {} |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 109 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 110 | const GrPath* path() const { return fPath.get(); } |
| 111 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 112 | void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 113 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 114 | SkMatrix fViewMatrix; |
| 115 | bool fUseHWAA; |
| 116 | GrStencilSettings fStencil; |
| 117 | GrScissorState fScissor; |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 118 | private: |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 119 | GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
| 120 | GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 123 | struct DrawPath : public Cmd { |
| 124 | DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 125 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 126 | const GrPath* path() const { return fPath.get(); } |
| 127 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 128 | void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 129 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 130 | GrStencilSettings fStencilSettings; |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 131 | |
| 132 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 133 | GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 136 | struct DrawPaths : public Cmd { |
| 137 | DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRange(pathRange) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 138 | |
| 139 | const GrPathRange* pathRange() const { return fPathRange.get(); } |
| 140 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 141 | void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 142 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 143 | char* fIndices; |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 144 | PathIndexType fIndexType; |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 145 | float* fTransforms; |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 146 | PathTransformType fTransformType; |
| 147 | int fCount; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 148 | GrStencilSettings fStencilSettings; |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 149 | |
| 150 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 151 | GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 154 | // 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] | 155 | struct Clear : public Cmd { |
| 156 | Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} |
| 157 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 158 | GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 159 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 160 | void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 161 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 162 | SkIRect fRect; |
| 163 | GrColor fColor; |
| 164 | bool fCanIgnoreRect; |
| 165 | |
| 166 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 167 | GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 170 | // This command is ONLY used by the clip mask manager to clear the stencil clip bits |
| 171 | struct ClearStencilClip : public Cmd { |
| 172 | ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} |
| 173 | |
| 174 | GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
| 175 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 176 | void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 177 | |
| 178 | SkIRect fRect; |
| 179 | bool fInsideClip; |
| 180 | |
| 181 | private: |
| 182 | GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
| 183 | }; |
| 184 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 185 | struct CopySurface : public Cmd { |
| 186 | CopySurface(GrSurface* dst, GrSurface* src) : Cmd(kCopySurface_Cmd), fDst(dst), fSrc(src) {} |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 187 | |
| 188 | GrSurface* dst() const { return fDst.get(); } |
| 189 | GrSurface* src() const { return fSrc.get(); } |
| 190 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 191 | void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 192 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 193 | SkIPoint fDstPoint; |
| 194 | SkIRect fSrcRect; |
| 195 | |
| 196 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 197 | GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
| 198 | GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 199 | }; |
| 200 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 201 | // TODO: rename to SetPipeline once pp, batch tracker, and desc are removed |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 202 | struct SetState : public Cmd { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 203 | // TODO get rid of the prim proc parameter when we use batch everywhere |
| 204 | SetState(const GrPrimitiveProcessor* primProc = NULL) |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 205 | : Cmd(kSetState_Cmd) |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 206 | , fPrimitiveProcessor(primProc) {} |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 207 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 208 | ~SetState() { reinterpret_cast<GrPipeline*>(fPipeline.get())->~GrPipeline(); } |
| 209 | |
| 210 | // This function is only for getting the location in memory where we will create our |
| 211 | // pipeline object. |
| 212 | GrPipeline* pipelineLocation() { return reinterpret_cast<GrPipeline*>(fPipeline.get()); } |
| 213 | |
| 214 | const GrPipeline* getPipeline() const { |
| 215 | return reinterpret_cast<const GrPipeline*>(fPipeline.get()); |
| 216 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 217 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 218 | void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 219 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 220 | typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimitiveProcessor; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 221 | ProgramPrimitiveProcessor fPrimitiveProcessor; |
| 222 | SkAlignedSStorage<sizeof(GrPipeline)> fPipeline; |
| 223 | GrProgramDesc fDesc; |
| 224 | GrBatchTracker fBatchTracker; |
bsalomon | f0480b1 | 2014-07-02 12:11:24 -0700 | [diff] [blame] | 225 | }; |
| 226 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 227 | struct DrawBatch : public Cmd { |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 228 | DrawBatch(GrBatch* batch, GrBatchTarget* batchTarget) |
| 229 | : Cmd(kDrawBatch_Cmd) |
| 230 | , fBatch(SkRef(batch)) |
| 231 | , fBatchTarget(batchTarget) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 232 | SkASSERT(!batch->isUsed()); |
| 233 | } |
| 234 | |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 235 | void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 236 | |
| 237 | // TODO it wouldn't be too hard to let batches allocate in the cmd buffer |
| 238 | SkAutoTUnref<GrBatch> fBatch; |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 239 | |
| 240 | private: |
| 241 | GrBatchTarget* fBatchTarget; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 242 | }; |
| 243 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 244 | typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double. |
| 245 | typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
| 246 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 247 | void onReset() SK_OVERRIDE; |
| 248 | void onFlush() SK_OVERRIDE; |
| 249 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 250 | // overrides from GrDrawTarget |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 251 | void onDraw(const GrGeometryProcessor*, const DrawInfo&, const PipelineInfo&) SK_OVERRIDE; |
| 252 | void onDrawBatch(GrBatch*, const PipelineInfo&) SK_OVERRIDE; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 253 | void onDrawRect(GrPipelineBuilder*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 254 | GrColor, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 255 | const SkMatrix& viewMatrix, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 256 | const SkRect& rect, |
| 257 | const SkRect* localRect, |
| 258 | const SkMatrix* localMatrix) SK_OVERRIDE; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 259 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 260 | void onStencilPath(const GrPipelineBuilder&, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 261 | const GrPathProcessor*, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 262 | const GrPath*, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 263 | const GrScissorState&, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 264 | const GrStencilSettings&) SK_OVERRIDE; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 265 | void onDrawPath(const GrPathProcessor*, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 266 | const GrPath*, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 267 | const GrStencilSettings&, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 268 | const PipelineInfo&) SK_OVERRIDE; |
| 269 | void onDrawPaths(const GrPathProcessor*, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 270 | const GrPathRange*, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 271 | const void* indices, |
| 272 | PathIndexType, |
| 273 | const float transformValues[], |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 274 | PathTransformType, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 275 | int count, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 276 | const GrStencilSettings&, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 277 | const PipelineInfo&) SK_OVERRIDE; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 278 | void onClear(const SkIRect* rect, |
| 279 | GrColor color, |
| 280 | bool canIgnoreRect, |
| 281 | GrRenderTarget* renderTarget) SK_OVERRIDE; |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 282 | bool onCopySurface(GrSurface* dst, |
| 283 | GrSurface* src, |
| 284 | const SkIRect& srcRect, |
| 285 | const SkIPoint& dstPoint) SK_OVERRIDE; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 286 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 287 | // Attempts to concat instances from info onto the previous draw. info must represent an |
| 288 | // instanced draw. The caller must have already recorded a new draw state and clip if necessary. |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 289 | int concatInstancedDraw(const DrawInfo&); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 290 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 291 | // Determines whether the current draw operation requires a new GrPipeline and if so |
| 292 | // records it. If the draw can be skipped false is returned and no new GrPipeline is |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 293 | // recorded. |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 294 | // TODO delete the primproc variant when we have batches everywhere |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 295 | bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(const GrPrimitiveProcessor*, |
| 296 | const PipelineInfo&); |
| 297 | bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrBatch*, const PipelineInfo&); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 298 | |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 299 | // 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] | 300 | void recordClipIfNecessary(); |
| 301 | // Records any trace markers for a command after adding it to the buffer. |
| 302 | void recordTraceMarkersIfNecessary(); |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 303 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 304 | bool isIssued(uint32_t drawID) SK_OVERRIDE { return drawID != fDrawID; } |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 305 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 306 | GrBatchTarget* getBatchTarget() { return &fBatchTarget; } |
| 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 | c4650ee | 2014-11-07 12:51:18 -0800 | [diff] [blame] | 310 | kCmdBufferInitialSizeInBytes = 8 * 1024, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 311 | kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's |
| 312 | kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms |
bsalomon@google.com | 4b90c62 | 2011-09-28 17:52:15 +0000 | [diff] [blame] | 313 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 314 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 315 | CmdBuffer fCmdBuffer; |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 316 | SetState* fPrevState; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 317 | SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 318 | SkChunkAlloc fPathIndexBuffer; |
| 319 | SkChunkAlloc fPathTransformBuffer; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 320 | uint32_t fDrawID; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 321 | GrBatchTarget fBatchTarget; |
| 322 | // TODO hack until batch is everywhere |
| 323 | DrawBatch* fDrawBatch; |
| 324 | |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame] | 325 | // This will go away when everything uses batch. However, in the short term anything which |
| 326 | // might be put into the GrInOrderDrawBuffer needs to make sure it closes the last batch |
| 327 | void closeBatch() { |
| 328 | if (fDrawBatch) { |
| 329 | fBatchTarget.resetNumberOfDraws(); |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 330 | fDrawBatch->execute(this->getGpu(), fPrevState); |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame] | 331 | fDrawBatch->fBatch->setNumberOfDraws(fBatchTarget.numberOfDraws()); |
| 332 | fDrawBatch = NULL; |
| 333 | } |
| 334 | } |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 335 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 336 | typedef GrFlushToGpuDrawTarget INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | #endif |