OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrTargetCommands_DEFINED | 8 #ifndef GrTargetCommands_DEFINED |
9 #define GrTargetCommands_DEFINED | 9 #define GrTargetCommands_DEFINED |
10 | 10 |
11 #include "GrBatchTarget.h" | |
12 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
13 #include "GrGpu.h" | |
14 #include "GrPath.h" | 12 #include "GrPath.h" |
15 #include "GrPendingProgramElement.h" | 13 #include "GrPendingProgramElement.h" |
| 14 #include "GrPrimitiveProcessor.h" |
16 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
17 #include "GrTRecorder.h" | 16 #include "GrTRecorder.h" |
18 #include "SkRect.h" | |
19 #include "SkTypes.h" | |
20 | 17 |
21 #include "batches/GrDrawBatch.h" | 18 #include "batches/GrDrawBatch.h" |
| 19 #include "SkRect.h" |
22 | 20 |
23 class GrBufferedDrawTarget; | 21 class GrResourceProvider; |
| 22 class GrBatchFlushState; |
24 | 23 |
25 // TODO: Convert all commands into GrBatch and remove this class. | 24 // TODO: Convert all commands into GrBatch and remove this class. |
26 class GrTargetCommands : ::SkNoncopyable { | 25 class GrTargetCommands : ::SkNoncopyable { |
27 public: | 26 public: |
28 GrTargetCommands(GrGpu* gpu) | 27 GrTargetCommands() : fCmdBuffer(kCmdBufferInitialSizeInBytes), fLastFlushTok
en(0) {} |
29 : fCmdBuffer(kCmdBufferInitialSizeInBytes) | |
30 , fBatchTarget(gpu) { | |
31 } | |
32 | 28 |
33 class Cmd : ::SkNoncopyable { | 29 class Cmd : ::SkNoncopyable { |
34 public: | 30 public: |
35 enum CmdType { | 31 enum CmdType { |
36 kStencilPath_CmdType = 1, | 32 kStencilPath_CmdType = 1, |
37 kClear_CmdType = 2, | 33 kClear_CmdType = 2, |
38 kClearStencil_CmdType = 3, | 34 kClearStencil_CmdType = 3, |
39 kCopySurface_CmdType = 4, | 35 kCopySurface_CmdType = 4, |
40 kDrawPath_CmdType = 5, | 36 kDrawPath_CmdType = 5, |
41 kDrawPaths_CmdType = 6, | 37 kDrawPaths_CmdType = 6, |
42 kDrawBatch_CmdType = 7, | 38 kDrawBatch_CmdType = 7, |
43 }; | 39 }; |
44 | 40 |
45 Cmd(CmdType type) | 41 Cmd(CmdType type) |
46 : fType(type) | 42 : fType(type) |
47 #if GR_BATCH_SPEW | 43 #if GR_BATCH_SPEW |
48 , fUniqueID(GenID(&gUniqueID)) | 44 , fUniqueID(GenID(&gUniqueID)) |
49 #endif | 45 #endif |
50 {} | 46 {} |
51 virtual ~Cmd() {} | 47 virtual ~Cmd() {} |
52 | 48 |
53 virtual void execute(GrGpu*) = 0; | 49 virtual void execute(GrBatchFlushState*) = 0; |
54 | 50 |
55 CmdType type() const { return fType; } | 51 CmdType type() const { return fType; } |
56 | 52 |
57 GrBATCH_SPEW(uint32_t uniqueID() const { return fUniqueID;} ) | 53 GrBATCH_SPEW(uint32_t uniqueID() const { return fUniqueID;} ) |
58 | 54 |
59 private: | 55 private: |
60 // TODO move this to a common header so it can be shared with GrBatch | 56 // TODO move this to a common header so it can be shared with GrBatch |
61 static uint32_t GenID(int32_t* idCounter) { | 57 static uint32_t GenID(int32_t* idCounter) { |
62 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; | 58 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; |
63 if (!id) { | 59 if (!id) { |
64 SkFAIL("This should never wrap\n"); | 60 SkFAIL("This should never wrap\n"); |
65 } | 61 } |
66 return id; | 62 return id; |
67 } | 63 } |
68 CmdType fType; | 64 CmdType fType; |
69 GrBATCH_SPEW(uint32_t fUniqueID); | 65 GrBATCH_SPEW(uint32_t fUniqueID); |
70 GrBATCH_SPEW(static int32_t gUniqueID;) | 66 GrBATCH_SPEW(static int32_t gUniqueID;) |
71 }; | 67 }; |
72 | 68 |
73 void reset(); | 69 void reset(); |
74 void flush(GrBufferedDrawTarget*); | 70 void flush(GrGpu*, GrResourceProvider*); |
75 | 71 |
76 private: | 72 private: |
77 friend class GrCommandBuilder; | 73 friend class GrCommandBuilder; |
78 friend class GrBufferedDrawTarget; // This goes away when State becomes just
a pipeline | 74 friend class GrBufferedDrawTarget; // This goes away when State becomes just
a pipeline |
79 friend class GrReorderCommandBuilder; | 75 friend class GrReorderCommandBuilder; |
80 | 76 |
81 typedef GrGpu::DrawArgs DrawArgs; | 77 typedef GrGpu::DrawArgs DrawArgs; |
82 | 78 |
83 // TODO: This can be just a pipeline once paths are in batch, and it should
live elsewhere | 79 // TODO: This can be just a pipeline once paths are in batch, and it should
live elsewhere |
84 struct StateForPathDraw : public SkNVRefCnt<StateForPathDraw> { | 80 struct StateForPathDraw : public SkNVRefCnt<StateForPathDraw> { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 friend SkNVRefCnt<StateForPathDraw>; | 121 friend SkNVRefCnt<StateForPathDraw>; |
126 | 122 |
127 struct StencilPath : public Cmd { | 123 struct StencilPath : public Cmd { |
128 StencilPath(const GrPath* path, GrRenderTarget* rt) | 124 StencilPath(const GrPath* path, GrRenderTarget* rt) |
129 : Cmd(kStencilPath_CmdType) | 125 : Cmd(kStencilPath_CmdType) |
130 , fRenderTarget(rt) | 126 , fRenderTarget(rt) |
131 , fPath(path) {} | 127 , fPath(path) {} |
132 | 128 |
133 const GrPath* path() const { return fPath.get(); } | 129 const GrPath* path() const { return fPath.get(); } |
134 | 130 |
135 void execute(GrGpu*) override; | 131 void execute(GrBatchFlushState*) override; |
136 | 132 |
137 SkMatrix fViewMatrix; | 133 SkMatrix fViewMatrix; |
138 bool fUseHWAA; | 134 bool fUseHWAA; |
139 GrStencilSettings fStencil; | 135 GrStencilSettings fStencil; |
140 GrScissorState fScissor; | 136 GrScissorState fScissor; |
141 private: | 137 private: |
142 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 138 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
143 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 139 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
144 }; | 140 }; |
145 | 141 |
146 struct DrawPath : public Cmd { | 142 struct DrawPath : public Cmd { |
147 DrawPath(StateForPathDraw* state, const GrPath* path) | 143 DrawPath(StateForPathDraw* state, const GrPath* path) |
148 : Cmd(kDrawPath_CmdType) | 144 : Cmd(kDrawPath_CmdType) |
149 , fState(SkRef(state)) | 145 , fState(SkRef(state)) |
150 , fPath(path) {} | 146 , fPath(path) {} |
151 | 147 |
152 const GrPath* path() const { return fPath.get(); } | 148 const GrPath* path() const { return fPath.get(); } |
153 | 149 |
154 void execute(GrGpu*) override; | 150 void execute(GrBatchFlushState*) override; |
155 | 151 |
156 SkAutoTUnref<StateForPathDraw> fState; | 152 SkAutoTUnref<StateForPathDraw> fState; |
157 GrStencilSettings fStencilSettings; | 153 GrStencilSettings fStencilSettings; |
158 private: | 154 private: |
159 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 155 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
160 }; | 156 }; |
161 | 157 |
162 struct DrawPaths : public Cmd { | 158 struct DrawPaths : public Cmd { |
163 DrawPaths(StateForPathDraw* state, const GrPathRange* pathRange) | 159 DrawPaths(StateForPathDraw* state, const GrPathRange* pathRange) |
164 : Cmd(kDrawPaths_CmdType) | 160 : Cmd(kDrawPaths_CmdType) |
165 , fState(SkRef(state)) | 161 , fState(SkRef(state)) |
166 , fPathRange(pathRange) {} | 162 , fPathRange(pathRange) {} |
167 | 163 |
168 const GrPathRange* pathRange() const { return fPathRange.get(); } | 164 const GrPathRange* pathRange() const { return fPathRange.get(); } |
169 | 165 |
170 void execute(GrGpu*) override; | 166 void execute(GrBatchFlushState*) override; |
171 | 167 |
172 SkAutoTUnref<StateForPathDraw> fState; | 168 SkAutoTUnref<StateForPathDraw> fState; |
173 char* fIndices; | 169 char* fIndices; |
174 GrDrawTarget::PathIndexType fIndexType; | 170 GrDrawTarget::PathIndexType fIndexType; |
175 float* fTransforms; | 171 float* fTransforms; |
176 GrDrawTarget::PathTransformType fTransformType; | 172 GrDrawTarget::PathTransformType fTransformType; |
177 int fCount; | 173 int fCount; |
178 GrStencilSettings fStencilSettings; | 174 GrStencilSettings fStencilSettings; |
179 | 175 |
180 private: | 176 private: |
181 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; | 177 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
182 }; | 178 }; |
183 | 179 |
184 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL | 180 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL |
185 struct Clear : public Cmd { | 181 struct Clear : public Cmd { |
186 Clear(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarget(rt) {} | 182 Clear(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarget(rt) {} |
187 | 183 |
188 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 184 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
189 | 185 |
190 void execute(GrGpu*) override; | 186 void execute(GrBatchFlushState*) override; |
191 | 187 |
192 SkIRect fRect; | 188 SkIRect fRect; |
193 GrColor fColor; | 189 GrColor fColor; |
194 | 190 |
195 private: | 191 private: |
196 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 192 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
197 }; | 193 }; |
198 | 194 |
199 // This command is ONLY used by the clip mask manager to clear the stencil c
lip bits | 195 // This command is ONLY used by the clip mask manager to clear the stencil c
lip bits |
200 struct ClearStencilClip : public Cmd { | 196 struct ClearStencilClip : public Cmd { |
201 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClearStencil_CmdType), fRend
erTarget(rt) {} | 197 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClearStencil_CmdType), fRend
erTarget(rt) {} |
202 | 198 |
203 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 199 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
204 | 200 |
205 void execute(GrGpu*) override; | 201 void execute(GrBatchFlushState*) override; |
206 | 202 |
207 SkIRect fRect; | 203 SkIRect fRect; |
208 bool fInsideClip; | 204 bool fInsideClip; |
209 | 205 |
210 private: | 206 private: |
211 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 207 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
212 }; | 208 }; |
213 | 209 |
214 struct CopySurface : public Cmd { | 210 struct CopySurface : public Cmd { |
215 CopySurface(GrSurface* dst, GrSurface* src) | 211 CopySurface(GrSurface* dst, GrSurface* src) |
216 : Cmd(kCopySurface_CmdType) | 212 : Cmd(kCopySurface_CmdType) |
217 , fDst(dst) | 213 , fDst(dst) |
218 , fSrc(src) { | 214 , fSrc(src) { |
219 } | 215 } |
220 | 216 |
221 GrSurface* dst() const { return fDst.get(); } | 217 GrSurface* dst() const { return fDst.get(); } |
222 GrSurface* src() const { return fSrc.get(); } | 218 GrSurface* src() const { return fSrc.get(); } |
223 | 219 |
224 void execute(GrGpu*) override; | 220 void execute(GrBatchFlushState*) override; |
225 | 221 |
226 SkIPoint fDstPoint; | 222 SkIPoint fDstPoint; |
227 SkIRect fSrcRect; | 223 SkIRect fSrcRect; |
228 | 224 |
229 private: | 225 private: |
230 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; | 226 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
231 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; | 227 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
232 }; | 228 }; |
233 | 229 |
234 struct DrawBatch : public Cmd { | 230 struct DrawBatch : public Cmd { |
235 DrawBatch(GrDrawBatch* batch, GrBatchTarget* batchTarget) | 231 DrawBatch(GrDrawBatch* batch) |
236 : Cmd(kDrawBatch_CmdType) | 232 : Cmd(kDrawBatch_CmdType) |
237 , fBatch(SkRef(batch)) | 233 , fBatch(SkRef(batch)){ |
238 , fBatchTarget(batchTarget) { | |
239 SkASSERT(!batch->isUsed()); | 234 SkASSERT(!batch->isUsed()); |
240 } | 235 } |
241 | 236 |
242 GrDrawBatch* batch() { return fBatch; } | 237 GrDrawBatch* batch() { return fBatch; } |
243 void execute(GrGpu*) override; | 238 void execute(GrBatchFlushState*) override; |
244 | 239 |
245 private: | 240 private: |
246 SkAutoTUnref<GrDrawBatch> fBatch; | 241 SkAutoTUnref<GrDrawBatch> fBatch; |
247 GrBatchTarget* fBatchTarget; | |
248 }; | 242 }; |
249 | 243 |
250 static const int kCmdBufferInitialSizeInBytes = 8 * 1024; | 244 static const int kCmdBufferInitialSizeInBytes = 8 * 1024; |
251 | 245 |
252 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. | 246 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. |
253 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; | 247 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
254 | 248 |
255 CmdBuffer* cmdBuffer() { return &fCmdBuffer; } | 249 CmdBuffer* cmdBuffer() { return &fCmdBuffer; } |
256 GrBatchTarget* batchTarget() { return &fBatchTarget; } | |
257 | 250 |
| 251 GrBatchToken fLastFlushToken; |
258 CmdBuffer fCmdBuffer; | 252 CmdBuffer fCmdBuffer; |
259 GrBatchTarget fBatchTarget; | |
260 }; | 253 }; |
261 | 254 |
262 #endif | 255 #endif |
263 | |
OLD | NEW |