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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 public: | 28 public: |
29 GrTargetCommands(GrGpu* gpu, | 29 GrTargetCommands(GrGpu* gpu, |
30 GrVertexBufferAllocPool* vertexPool, | 30 GrVertexBufferAllocPool* vertexPool, |
31 GrIndexBufferAllocPool* indexPool) | 31 GrIndexBufferAllocPool* indexPool) |
32 : fCmdBuffer(kCmdBufferInitialSizeInBytes) | 32 : fCmdBuffer(kCmdBufferInitialSizeInBytes) |
33 , fPrevState(NULL) | 33 , fPrevState(NULL) |
34 , fBatchTarget(gpu, vertexPool, indexPool) | 34 , fBatchTarget(gpu, vertexPool, indexPool) |
35 , fDrawBatch(NULL) { | 35 , fDrawBatch(NULL) { |
36 } | 36 } |
37 | 37 |
38 struct Cmd : ::SkNoncopyable { | 38 class Cmd : ::SkNoncopyable { |
39 enum { | 39 public: |
40 kDraw_Cmd = 1, | 40 enum CmdType { |
41 kStencilPath_Cmd = 2, | 41 kDraw_CmdType = 1, |
42 kSetState_Cmd = 3, | 42 kStencilPath_CmdType = 2, |
43 kClear_Cmd = 4, | 43 kSetState_CmdType = 3, |
44 kCopySurface_Cmd = 5, | 44 kClear_CmdType = 4, |
45 kDrawPath_Cmd = 6, | 45 kCopySurface_CmdType = 5, |
46 kDrawPaths_Cmd = 7, | 46 kDrawPath_CmdType = 6, |
47 kDrawBatch_Cmd = 8, | 47 kDrawPaths_CmdType = 7, |
| 48 kDrawBatch_CmdType = 8, |
48 }; | 49 }; |
49 | 50 |
50 Cmd(uint8_t type) : fType(type) {} | 51 Cmd(CmdType type) : fMarkerID(-1), fType(type) {} |
51 virtual ~Cmd() {} | 52 virtual ~Cmd() {} |
52 | 53 |
53 virtual void execute(GrGpu*, const SetState*) = 0; | 54 virtual void execute(GrGpu*, const SetState*) = 0; |
54 | 55 |
55 uint8_t type() const { return fType & kCmdMask; } | 56 CmdType type() const { return fType; } |
56 | 57 |
57 bool isTraced() const { return SkToBool(fType & kTraceCmdBit); } | 58 // trace markers |
58 void makeTraced() { fType |= kTraceCmdBit; } | 59 bool isTraced() const { return -1 != fMarkerID; } |
| 60 void setMarkerID(int markerID) { SkASSERT(-1 == fMarkerID); fMarkerID =
markerID; } |
| 61 int markerID() const { return fMarkerID; } |
59 | 62 |
60 private: | 63 private: |
61 static const int kCmdMask = 0x7F; | 64 int fMarkerID; |
62 static const int kTraceCmdBit = 0x80; | 65 CmdType fType; |
63 | |
64 uint8_t fType; | |
65 }; | 66 }; |
66 | 67 |
67 void reset(); | 68 void reset(); |
68 void flush(GrInOrderDrawBuffer*); | 69 void flush(GrInOrderDrawBuffer*); |
69 | 70 |
70 Cmd* recordClearStencilClip(GrInOrderDrawBuffer*, | 71 Cmd* recordClearStencilClip(GrInOrderDrawBuffer*, |
71 const SkIRect& rect, | 72 const SkIRect& rect, |
72 bool insideClip, | 73 bool insideClip, |
73 GrRenderTarget* renderTarget); | 74 GrRenderTarget* renderTarget); |
74 | 75 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 int concatInstancedDraw(GrInOrderDrawBuffer*, const GrDrawTarget::DrawInfo&)
; | 136 int concatInstancedDraw(GrInOrderDrawBuffer*, const GrDrawTarget::DrawInfo&)
; |
136 | 137 |
137 bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrInOrderDrawBuffer*, | 138 bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrInOrderDrawBuffer*, |
138 const GrPrimitiveProce
ssor*, | 139 const GrPrimitiveProce
ssor*, |
139 const GrDrawTarget::Pi
pelineInfo&); | 140 const GrDrawTarget::Pi
pelineInfo&); |
140 bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrInOrderDrawBuffer*, | 141 bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrInOrderDrawBuffer*, |
141 GrBatch*, | 142 GrBatch*, |
142 const GrDrawTarget::Pi
pelineInfo&); | 143 const GrDrawTarget::Pi
pelineInfo&); |
143 | 144 |
144 struct Draw : public Cmd { | 145 struct Draw : public Cmd { |
145 Draw(const GrDrawTarget::DrawInfo& info) : Cmd(kDraw_Cmd), fInfo(info) {
} | 146 Draw(const GrDrawTarget::DrawInfo& info) : Cmd(kDraw_CmdType), fInfo(inf
o) {} |
146 | 147 |
147 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | 148 void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
148 | 149 |
149 GrDrawTarget::DrawInfo fInfo; | 150 GrDrawTarget::DrawInfo fInfo; |
150 }; | 151 }; |
151 | 152 |
152 struct StencilPath : public Cmd { | 153 struct StencilPath : public Cmd { |
153 StencilPath(const GrPath* path, GrRenderTarget* rt) | 154 StencilPath(const GrPath* path, GrRenderTarget* rt) |
154 : Cmd(kStencilPath_Cmd) | 155 : Cmd(kStencilPath_CmdType) |
155 , fRenderTarget(rt) | 156 , fRenderTarget(rt) |
156 , fPath(path) {} | 157 , fPath(path) {} |
157 | 158 |
158 const GrPath* path() const { return fPath.get(); } | 159 const GrPath* path() const { return fPath.get(); } |
159 | 160 |
160 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | 161 void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
161 | 162 |
162 SkMatrix fViewMatrix; | 163 SkMatrix fViewMatrix; |
163 bool fUseHWAA; | 164 bool fUseHWAA; |
164 GrStencilSettings fStencil; | 165 GrStencilSettings fStencil; |
165 GrScissorState fScissor; | 166 GrScissorState fScissor; |
166 private: | 167 private: |
167 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 168 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
168 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 169 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
169 }; | 170 }; |
170 | 171 |
171 struct DrawPath : public Cmd { | 172 struct DrawPath : public Cmd { |
172 DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} | 173 DrawPath(const GrPath* path) : Cmd(kDrawPath_CmdType), fPath(path) {} |
173 | 174 |
174 const GrPath* path() const { return fPath.get(); } | 175 const GrPath* path() const { return fPath.get(); } |
175 | 176 |
176 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | 177 void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
177 | 178 |
178 GrStencilSettings fStencilSettings; | 179 GrStencilSettings fStencilSettings; |
179 | 180 |
180 private: | 181 private: |
181 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 182 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
182 }; | 183 }; |
183 | 184 |
184 struct DrawPaths : public Cmd { | 185 struct DrawPaths : public Cmd { |
185 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRang
e(pathRange) {} | 186 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_CmdType), fPath
Range(pathRange) {} |
186 | 187 |
187 const GrPathRange* pathRange() const { return fPathRange.get(); } | 188 const GrPathRange* pathRange() const { return fPathRange.get(); } |
188 | 189 |
189 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | 190 void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
190 | 191 |
191 char* fIndices; | 192 char* fIndices; |
192 GrDrawTarget::PathIndexType fIndexType; | 193 GrDrawTarget::PathIndexType fIndexType; |
193 float* fTransforms; | 194 float* fTransforms; |
194 GrDrawTarget::PathTransformType fTransformType; | 195 GrDrawTarget::PathTransformType fTransformType; |
195 int fCount; | 196 int fCount; |
196 GrStencilSettings fStencilSettings; | 197 GrStencilSettings fStencilSettings; |
197 | 198 |
198 private: | 199 private: |
199 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; | 200 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
200 }; | 201 }; |
201 | 202 |
202 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL | 203 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL |
203 struct Clear : public Cmd { | 204 struct Clear : public Cmd { |
204 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} | 205 Clear(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarget(rt) {} |
205 | 206 |
206 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 207 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
207 | 208 |
208 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | 209 void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
209 | 210 |
210 SkIRect fRect; | 211 SkIRect fRect; |
211 GrColor fColor; | 212 GrColor fColor; |
212 bool fCanIgnoreRect; | 213 bool fCanIgnoreRect; |
213 | 214 |
214 private: | 215 private: |
215 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 216 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
216 }; | 217 }; |
217 | 218 |
218 // This command is ONLY used by the clip mask manager to clear the stencil c
lip bits | 219 // This command is ONLY used by the clip mask manager to clear the stencil c
lip bits |
219 struct ClearStencilClip : public Cmd { | 220 struct ClearStencilClip : public Cmd { |
220 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt
) {} | 221 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarge
t(rt) {} |
221 | 222 |
222 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 223 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
223 | 224 |
224 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | 225 void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
225 | 226 |
226 SkIRect fRect; | 227 SkIRect fRect; |
227 bool fInsideClip; | 228 bool fInsideClip; |
228 | 229 |
229 private: | 230 private: |
230 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 231 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
231 }; | 232 }; |
232 | 233 |
233 struct CopySurface : public Cmd { | 234 struct CopySurface : public Cmd { |
234 CopySurface(GrSurface* dst, GrSurface* src) : Cmd(kCopySurface_Cmd), fDs
t(dst), fSrc(src) {} | 235 CopySurface(GrSurface* dst, GrSurface* src) |
| 236 : Cmd(kCopySurface_CmdType) |
| 237 , fDst(dst) |
| 238 , fSrc(src) { |
| 239 } |
235 | 240 |
236 GrSurface* dst() const { return fDst.get(); } | 241 GrSurface* dst() const { return fDst.get(); } |
237 GrSurface* src() const { return fSrc.get(); } | 242 GrSurface* src() const { return fSrc.get(); } |
238 | 243 |
239 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | 244 void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
240 | 245 |
241 SkIPoint fDstPoint; | 246 SkIPoint fDstPoint; |
242 SkIRect fSrcRect; | 247 SkIRect fSrcRect; |
243 | 248 |
244 private: | 249 private: |
245 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; | 250 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
246 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; | 251 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
247 }; | 252 }; |
248 | 253 |
249 // TODO: rename to SetPipeline once pp, batch tracker, and desc are removed | 254 // TODO: rename to SetPipeline once pp, batch tracker, and desc are removed |
250 struct SetState : public Cmd { | 255 struct SetState : public Cmd { |
251 // TODO get rid of the prim proc parameter when we use batch everywhere | 256 // TODO get rid of the prim proc parameter when we use batch everywhere |
252 SetState(const GrPrimitiveProcessor* primProc = NULL) | 257 SetState(const GrPrimitiveProcessor* primProc = NULL) |
253 : Cmd(kSetState_Cmd) | 258 : Cmd(kSetState_CmdType) |
254 , fPrimitiveProcessor(primProc) {} | 259 , fPrimitiveProcessor(primProc) {} |
255 | 260 |
256 ~SetState() { reinterpret_cast<GrPipeline*>(fPipeline.get())->~GrPipelin
e(); } | 261 ~SetState() { reinterpret_cast<GrPipeline*>(fPipeline.get())->~GrPipelin
e(); } |
257 | 262 |
258 // This function is only for getting the location in memory where we wil
l create our | 263 // This function is only for getting the location in memory where we wil
l create our |
259 // pipeline object. | 264 // pipeline object. |
260 GrPipeline* pipelineLocation() { return reinterpret_cast<GrPipeline*>(fP
ipeline.get()); } | 265 GrPipeline* pipelineLocation() { return reinterpret_cast<GrPipeline*>(fP
ipeline.get()); } |
261 | 266 |
262 const GrPipeline* getPipeline() const { | 267 const GrPipeline* getPipeline() const { |
263 return reinterpret_cast<const GrPipeline*>(fPipeline.get()); | 268 return reinterpret_cast<const GrPipeline*>(fPipeline.get()); |
264 } | 269 } |
265 | 270 |
266 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | 271 void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
267 | 272 |
268 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; | 273 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; |
269 ProgramPrimitiveProcessor fPrimitiveProcessor; | 274 ProgramPrimitiveProcessor fPrimitiveProcessor; |
270 SkAlignedSStorage<sizeof(GrPipeline)> fPipeline; | 275 SkAlignedSStorage<sizeof(GrPipeline)> fPipeline; |
271 GrProgramDesc fDesc; | 276 GrProgramDesc fDesc; |
272 GrBatchTracker fBatchTracker; | 277 GrBatchTracker fBatchTracker; |
273 }; | 278 }; |
274 | 279 |
275 struct DrawBatch : public Cmd { | 280 struct DrawBatch : public Cmd { |
276 DrawBatch(GrBatch* batch, GrBatchTarget* batchTarget) | 281 DrawBatch(GrBatch* batch, GrBatchTarget* batchTarget) |
277 : Cmd(kDrawBatch_Cmd) | 282 : Cmd(kDrawBatch_CmdType) |
278 , fBatch(SkRef(batch)) | 283 , fBatch(SkRef(batch)) |
279 , fBatchTarget(batchTarget) { | 284 , fBatchTarget(batchTarget) { |
280 SkASSERT(!batch->isUsed()); | 285 SkASSERT(!batch->isUsed()); |
281 } | 286 } |
282 | 287 |
283 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | 288 void execute(GrGpu*, const SetState*) SK_OVERRIDE; |
284 | 289 |
285 // TODO it wouldn't be too hard to let batches allocate in the cmd buffe
r | 290 // TODO it wouldn't be too hard to let batches allocate in the cmd buffe
r |
286 SkAutoTUnref<GrBatch> fBatch; | 291 SkAutoTUnref<GrBatch> fBatch; |
287 | 292 |
(...skipping 12 matching lines...) Expand all Loading... |
300 // TODO hack until batch is everywhere | 305 // TODO hack until batch is everywhere |
301 GrTargetCommands::DrawBatch* fDrawBatch; | 306 GrTargetCommands::DrawBatch* fDrawBatch; |
302 | 307 |
303 // This will go away when everything uses batch. However, in the short ter
m anything which | 308 // This will go away when everything uses batch. However, in the short ter
m anything which |
304 // might be put into the GrInOrderDrawBuffer needs to make sure it closes t
he last batch | 309 // might be put into the GrInOrderDrawBuffer needs to make sure it closes t
he last batch |
305 void closeBatch(); | 310 void closeBatch(); |
306 }; | 311 }; |
307 | 312 |
308 #endif | 313 #endif |
309 | 314 |
OLD | NEW |