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 "GrBatch.h" | 11 #include "GrBatch.h" |
12 #include "GrBatchTarget.h" | 12 #include "GrBatchTarget.h" |
13 #include "GrDrawTarget.h" | 13 #include "GrDrawTarget.h" |
14 #include "GrGpu.h" | 14 #include "GrGpu.h" |
15 #include "GrPath.h" | 15 #include "GrPath.h" |
16 #include "GrPendingProgramElement.h" | 16 #include "GrPendingProgramElement.h" |
17 #include "GrRenderTarget.h" | 17 #include "GrRenderTarget.h" |
18 #include "GrTRecorder.h" | 18 #include "GrTRecorder.h" |
19 #include "SkRect.h" | 19 #include "SkRect.h" |
20 #include "SkTypes.h" | 20 #include "SkTypes.h" |
21 | 21 |
22 class GrInOrderDrawBuffer; | 22 class GrInOrderDrawBuffer; |
23 class GrVertexBufferAllocPool; | 23 class GrVertexBufferAllocPool; |
24 class GrIndexBufferAllocPool; | 24 class GrIndexBufferAllocPool; |
25 | 25 |
26 class GrTargetCommands : ::SkNoncopyable { | 26 class GrTargetCommands : ::SkNoncopyable { |
| 27 struct State; |
27 struct SetState; | 28 struct SetState; |
28 | 29 |
29 public: | 30 public: |
30 GrTargetCommands(GrGpu* gpu, | 31 GrTargetCommands(GrGpu* gpu, |
31 GrVertexBufferAllocPool* vertexPool, | 32 GrVertexBufferAllocPool* vertexPool, |
32 GrIndexBufferAllocPool* indexPool) | 33 GrIndexBufferAllocPool* indexPool) |
33 : fCmdBuffer(kCmdBufferInitialSizeInBytes) | 34 : fCmdBuffer(kCmdBufferInitialSizeInBytes) |
34 , fPrevState(NULL) | |
35 , fBatchTarget(gpu, vertexPool, indexPool) { | 35 , fBatchTarget(gpu, vertexPool, indexPool) { |
36 } | 36 } |
37 | 37 |
38 class Cmd : ::SkNoncopyable { | 38 class Cmd : ::SkNoncopyable { |
39 public: | 39 public: |
40 enum CmdType { | 40 enum CmdType { |
41 kStencilPath_CmdType = 1, | 41 kStencilPath_CmdType = 1, |
42 kSetState_CmdType = 2, | 42 kSetState_CmdType = 2, |
43 kClear_CmdType = 3, | 43 kClear_CmdType = 3, |
44 kCopySurface_CmdType = 4, | 44 kCopySurface_CmdType = 4, |
45 kDrawPath_CmdType = 5, | 45 kDrawPath_CmdType = 5, |
46 kDrawPaths_CmdType = 6, | 46 kDrawPaths_CmdType = 6, |
47 kDrawBatch_CmdType = 7, | 47 kDrawBatch_CmdType = 7, |
48 kXferBarrier_CmdType = 8, | 48 kXferBarrier_CmdType = 8, |
49 }; | 49 }; |
50 | 50 |
51 Cmd(CmdType type) : fMarkerID(-1), fType(type) {} | 51 Cmd(CmdType type) : fMarkerID(-1), fType(type) {} |
52 virtual ~Cmd() {} | 52 virtual ~Cmd() {} |
53 | 53 |
54 virtual void execute(GrGpu*, const SetState*) = 0; | 54 virtual void execute(GrGpu*) = 0; |
55 | 55 |
56 CmdType type() const { return fType; } | 56 CmdType type() const { return fType; } |
57 | 57 |
58 // trace markers | 58 // trace markers |
59 bool isTraced() const { return -1 != fMarkerID; } | 59 bool isTraced() const { return -1 != fMarkerID; } |
60 void setMarkerID(int markerID) { SkASSERT(-1 == fMarkerID); fMarkerID =
markerID; } | 60 void setMarkerID(int markerID) { SkASSERT(-1 == fMarkerID); fMarkerID =
markerID; } |
61 int markerID() const { return fMarkerID; } | 61 int markerID() const { return fMarkerID; } |
62 | 62 |
63 private: | 63 private: |
64 int fMarkerID; | 64 int fMarkerID; |
65 CmdType fType; | 65 CmdType fType; |
66 }; | 66 }; |
67 | 67 |
68 void reset(); | 68 void reset(); |
69 void flush(GrInOrderDrawBuffer*); | 69 void flush(GrInOrderDrawBuffer*); |
70 | 70 |
71 Cmd* recordClearStencilClip(GrInOrderDrawBuffer*, | 71 Cmd* recordClearStencilClip(const SkIRect& rect, |
72 const SkIRect& rect, | |
73 bool insideClip, | 72 bool insideClip, |
74 GrRenderTarget* renderTarget); | 73 GrRenderTarget* renderTarget); |
75 | 74 |
76 Cmd* recordDiscard(GrInOrderDrawBuffer*, GrRenderTarget*); | 75 Cmd* recordDiscard(GrRenderTarget*); |
77 | 76 Cmd* recordDrawBatch(State*, GrBatch*); |
78 Cmd* recordDraw(GrInOrderDrawBuffer*, | 77 Cmd* recordStencilPath(const GrPipelineBuilder&, |
79 const GrGeometryProcessor*, | |
80 const GrDrawTarget::DrawInfo&, | |
81 const GrDrawTarget::PipelineInfo&); | |
82 Cmd* recordDrawBatch(GrInOrderDrawBuffer*, | |
83 GrBatch*, | |
84 const GrDrawTarget::PipelineInfo&); | |
85 Cmd* recordStencilPath(GrInOrderDrawBuffer*, | |
86 const GrPipelineBuilder&, | |
87 const GrPathProcessor*, | 78 const GrPathProcessor*, |
88 const GrPath*, | 79 const GrPath*, |
89 const GrScissorState&, | 80 const GrScissorState&, |
90 const GrStencilSettings&); | 81 const GrStencilSettings&); |
91 Cmd* recordDrawPath(GrInOrderDrawBuffer*, | 82 Cmd* recordDrawPath(State*, |
92 const GrPathProcessor*, | 83 const GrPathProcessor*, |
93 const GrPath*, | 84 const GrPath*, |
94 const GrStencilSettings&, | 85 const GrStencilSettings&); |
95 const GrDrawTarget::PipelineInfo&); | 86 Cmd* recordDrawPaths(State*, |
96 Cmd* recordDrawPaths(GrInOrderDrawBuffer*, | 87 GrInOrderDrawBuffer*, |
97 const GrPathProcessor*, | 88 const GrPathProcessor*, |
98 const GrPathRange*, | 89 const GrPathRange*, |
99 const void*, | 90 const void*, |
100 GrDrawTarget::PathIndexType, | 91 GrDrawTarget::PathIndexType, |
101 const float transformValues[], | 92 const float transformValues[], |
102 GrDrawTarget::PathTransformType , | 93 GrDrawTarget::PathTransformType , |
103 int, | 94 int, |
104 const GrStencilSettings&, | 95 const GrStencilSettings&, |
105 const GrDrawTarget::PipelineInfo&); | 96 const GrDrawTarget::PipelineInfo&); |
106 Cmd* recordClear(GrInOrderDrawBuffer*, | 97 Cmd* recordClear(const SkIRect* rect, |
107 const SkIRect* rect, | |
108 GrColor, | 98 GrColor, |
109 bool canIgnoreRect, | 99 bool canIgnoreRect, |
110 GrRenderTarget*); | 100 GrRenderTarget*); |
111 Cmd* recordCopySurface(GrSurface* dst, | 101 Cmd* recordCopySurface(GrSurface* dst, |
112 GrSurface* src, | 102 GrSurface* src, |
113 const SkIRect& srcRect, | 103 const SkIRect& srcRect, |
114 const SkIPoint& dstPoint); | 104 const SkIPoint& dstPoint); |
115 | 105 |
116 private: | 106 private: |
117 friend class GrInOrderDrawBuffer; | 107 friend class GrInOrderDrawBuffer; |
118 | 108 |
119 typedef GrGpu::DrawArgs DrawArgs; | 109 typedef GrGpu::DrawArgs DrawArgs; |
120 | 110 |
121 // Attempts to concat instances from info onto the previous draw. info must
represent an | 111 void recordXferBarrierIfNecessary(const GrPipeline&, GrInOrderDrawBuffer*); |
122 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. | |
123 int concatInstancedDraw(GrInOrderDrawBuffer*, const GrDrawTarget::DrawInfo&)
; | |
124 | 112 |
125 bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrInOrderDrawBuffer*, | 113 // TODO: This can be just a pipeline once paths are in batch, and it should
live elsewhere |
126 const GrPrimitiveProce
ssor*, | 114 struct State : public SkNVRefCnt<State> { |
127 const GrDrawTarget::Pi
pelineInfo&); | 115 // TODO get rid of the prim proc parameter when we use batch everywhere |
128 bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrInOrderDrawBuffer*, | 116 State(const GrPrimitiveProcessor* primProc = NULL) |
129 GrBatch*, | 117 : fPrimitiveProcessor(primProc) |
130 const GrDrawTarget::Pi
pelineInfo&); | 118 , fCompiled(false) {} |
131 | 119 |
132 void recordXferBarrierIfNecessary(GrInOrderDrawBuffer*, const GrDrawTarget::
PipelineInfo&); | 120 ~State() { reinterpret_cast<GrPipeline*>(fPipeline.get())->~GrPipeline()
; } |
| 121 |
| 122 // This function is only for getting the location in memory where we wil
l create our |
| 123 // pipeline object. |
| 124 GrPipeline* pipelineLocation() { return reinterpret_cast<GrPipeline*>(fP
ipeline.get()); } |
| 125 |
| 126 const GrPipeline* getPipeline() const { |
| 127 return reinterpret_cast<const GrPipeline*>(fPipeline.get()); |
| 128 } |
| 129 GrRenderTarget* getRenderTarget() const { |
| 130 return this->getPipeline()->getRenderTarget(); |
| 131 } |
| 132 const GrXferProcessor* getXferProcessor() const { |
| 133 return this->getPipeline()->getXferProcessor(); |
| 134 } |
| 135 |
| 136 void operator delete(void* p) {} |
| 137 void* operator new(size_t) { |
| 138 SkFAIL("All States are created by placement new."); |
| 139 return sk_malloc_throw(0); |
| 140 } |
| 141 |
| 142 void* operator new(size_t, void* p) { return p; } |
| 143 void operator delete(void* target, void* placement) { |
| 144 ::operator delete(target, placement); |
| 145 } |
| 146 |
| 147 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; |
| 148 ProgramPrimitiveProcessor fPrimitiveProcessor; |
| 149 SkAlignedSStorage<sizeof(GrPipeline)> fPipeline; |
| 150 GrProgramDesc fDesc; |
| 151 GrBatchTracker fBatchTracker; |
| 152 bool fCompiled; |
| 153 }; |
| 154 // TODO remove this when State is just a pipeline |
| 155 friend SkNVRefCnt<State>; |
133 | 156 |
134 struct StencilPath : public Cmd { | 157 struct StencilPath : public Cmd { |
135 StencilPath(const GrPath* path, GrRenderTarget* rt) | 158 StencilPath(const GrPath* path, GrRenderTarget* rt) |
136 : Cmd(kStencilPath_CmdType) | 159 : Cmd(kStencilPath_CmdType) |
137 , fRenderTarget(rt) | 160 , fRenderTarget(rt) |
138 , fPath(path) {} | 161 , fPath(path) {} |
139 | 162 |
140 const GrPath* path() const { return fPath.get(); } | 163 const GrPath* path() const { return fPath.get(); } |
141 | 164 |
142 void execute(GrGpu*, const SetState*) override; | 165 void execute(GrGpu*) override; |
143 | 166 |
144 SkMatrix fViewMatrix; | 167 SkMatrix fViewMatrix; |
145 bool fUseHWAA; | 168 bool fUseHWAA; |
146 GrStencilSettings fStencil; | 169 GrStencilSettings fStencil; |
147 GrScissorState fScissor; | 170 GrScissorState fScissor; |
148 private: | 171 private: |
149 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 172 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
150 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 173 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
151 }; | 174 }; |
152 | 175 |
153 struct DrawPath : public Cmd { | 176 struct DrawPath : public Cmd { |
154 DrawPath(const GrPath* path) : Cmd(kDrawPath_CmdType), fPath(path) {} | 177 DrawPath(State* state, const GrPath* path) |
| 178 : Cmd(kDrawPath_CmdType) |
| 179 , fState(SkRef(state)) |
| 180 , fPath(path) {} |
155 | 181 |
156 const GrPath* path() const { return fPath.get(); } | 182 const GrPath* path() const { return fPath.get(); } |
157 | 183 |
158 void execute(GrGpu*, const SetState*) override; | 184 void execute(GrGpu*) override; |
159 | 185 |
| 186 SkAutoTUnref<State> fState; |
160 GrStencilSettings fStencilSettings; | 187 GrStencilSettings fStencilSettings; |
161 | |
162 private: | 188 private: |
163 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 189 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
164 }; | 190 }; |
165 | 191 |
166 struct DrawPaths : public Cmd { | 192 struct DrawPaths : public Cmd { |
167 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_CmdType), fPath
Range(pathRange) {} | 193 DrawPaths(State* state, const GrPathRange* pathRange) |
| 194 : Cmd(kDrawPaths_CmdType) |
| 195 , fState(SkRef(state)) |
| 196 , fPathRange(pathRange) {} |
168 | 197 |
169 const GrPathRange* pathRange() const { return fPathRange.get(); } | 198 const GrPathRange* pathRange() const { return fPathRange.get(); } |
170 | 199 |
171 void execute(GrGpu*, const SetState*) override; | 200 void execute(GrGpu*) override; |
172 | 201 |
| 202 SkAutoTUnref<State> fState; |
173 char* fIndices; | 203 char* fIndices; |
174 GrDrawTarget::PathIndexType fIndexType; | 204 GrDrawTarget::PathIndexType fIndexType; |
175 float* fTransforms; | 205 float* fTransforms; |
176 GrDrawTarget::PathTransformType fTransformType; | 206 GrDrawTarget::PathTransformType fTransformType; |
177 int fCount; | 207 int fCount; |
178 GrStencilSettings fStencilSettings; | 208 GrStencilSettings fStencilSettings; |
179 | 209 |
180 private: | 210 private: |
181 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; | 211 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
182 }; | 212 }; |
183 | 213 |
184 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL | 214 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL |
185 struct Clear : public Cmd { | 215 struct Clear : public Cmd { |
186 Clear(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarget(rt) {} | 216 Clear(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarget(rt) {} |
187 | 217 |
188 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 218 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
189 | 219 |
190 void execute(GrGpu*, const SetState*) override; | 220 void execute(GrGpu*) override; |
191 | 221 |
192 SkIRect fRect; | 222 SkIRect fRect; |
193 GrColor fColor; | 223 GrColor fColor; |
194 bool fCanIgnoreRect; | 224 bool fCanIgnoreRect; |
195 | 225 |
196 private: | 226 private: |
197 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 227 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
198 }; | 228 }; |
199 | 229 |
200 // This command is ONLY used by the clip mask manager to clear the stencil c
lip bits | 230 // This command is ONLY used by the clip mask manager to clear the stencil c
lip bits |
201 struct ClearStencilClip : public Cmd { | 231 struct ClearStencilClip : public Cmd { |
202 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarge
t(rt) {} | 232 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarge
t(rt) {} |
203 | 233 |
204 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 234 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
205 | 235 |
206 void execute(GrGpu*, const SetState*) override; | 236 void execute(GrGpu*) override; |
207 | 237 |
208 SkIRect fRect; | 238 SkIRect fRect; |
209 bool fInsideClip; | 239 bool fInsideClip; |
210 | 240 |
211 private: | 241 private: |
212 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 242 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
213 }; | 243 }; |
214 | 244 |
215 struct CopySurface : public Cmd { | 245 struct CopySurface : public Cmd { |
216 CopySurface(GrSurface* dst, GrSurface* src) | 246 CopySurface(GrSurface* dst, GrSurface* src) |
217 : Cmd(kCopySurface_CmdType) | 247 : Cmd(kCopySurface_CmdType) |
218 , fDst(dst) | 248 , fDst(dst) |
219 , fSrc(src) { | 249 , fSrc(src) { |
220 } | 250 } |
221 | 251 |
222 GrSurface* dst() const { return fDst.get(); } | 252 GrSurface* dst() const { return fDst.get(); } |
223 GrSurface* src() const { return fSrc.get(); } | 253 GrSurface* src() const { return fSrc.get(); } |
224 | 254 |
225 void execute(GrGpu*, const SetState*) override; | 255 void execute(GrGpu*) override; |
226 | 256 |
227 SkIPoint fDstPoint; | 257 SkIPoint fDstPoint; |
228 SkIRect fSrcRect; | 258 SkIRect fSrcRect; |
229 | 259 |
230 private: | 260 private: |
231 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; | 261 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
232 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; | 262 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
233 }; | 263 }; |
234 | 264 |
235 // TODO: rename to SetPipeline once pp, batch tracker, and desc are removed | |
236 struct SetState : public Cmd { | |
237 // TODO get rid of the prim proc parameter when we use batch everywhere | |
238 SetState(const GrPrimitiveProcessor* primProc = NULL) | |
239 : Cmd(kSetState_CmdType) | |
240 , fPrimitiveProcessor(primProc) {} | |
241 | |
242 ~SetState() { reinterpret_cast<GrPipeline*>(fPipeline.get())->~GrPipelin
e(); } | |
243 | |
244 // This function is only for getting the location in memory where we wil
l create our | |
245 // pipeline object. | |
246 GrPipeline* pipelineLocation() { return reinterpret_cast<GrPipeline*>(fP
ipeline.get()); } | |
247 | |
248 const GrPipeline* getPipeline() const { | |
249 return reinterpret_cast<const GrPipeline*>(fPipeline.get()); | |
250 } | |
251 GrRenderTarget* getRenderTarget() const { | |
252 return this->getPipeline()->getRenderTarget(); | |
253 } | |
254 const GrXferProcessor* getXferProcessor() const { | |
255 return this->getPipeline()->getXferProcessor(); | |
256 } | |
257 | |
258 void execute(GrGpu*, const SetState*) override; | |
259 | |
260 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; | |
261 ProgramPrimitiveProcessor fPrimitiveProcessor; | |
262 SkAlignedSStorage<sizeof(GrPipeline)> fPipeline; | |
263 GrProgramDesc fDesc; | |
264 GrBatchTracker fBatchTracker; | |
265 }; | |
266 | |
267 struct DrawBatch : public Cmd { | 265 struct DrawBatch : public Cmd { |
268 DrawBatch(GrBatch* batch, GrBatchTarget* batchTarget) | 266 DrawBatch(State* state, GrBatch* batch, GrBatchTarget* batchTarget) |
269 : Cmd(kDrawBatch_CmdType) | 267 : Cmd(kDrawBatch_CmdType) |
| 268 , fState(SkRef(state)) |
270 , fBatch(SkRef(batch)) | 269 , fBatch(SkRef(batch)) |
271 , fBatchTarget(batchTarget) { | 270 , fBatchTarget(batchTarget) { |
272 SkASSERT(!batch->isUsed()); | 271 SkASSERT(!batch->isUsed()); |
273 } | 272 } |
274 | 273 |
275 void execute(GrGpu*, const SetState*) override; | 274 void execute(GrGpu*) override; |
276 | 275 |
277 // TODO it wouldn't be too hard to let batches allocate in the cmd buffe
r | 276 SkAutoTUnref<State> fState; |
278 SkAutoTUnref<GrBatch> fBatch; | 277 SkAutoTUnref<GrBatch> fBatch; |
279 | 278 |
280 private: | 279 private: |
281 GrBatchTarget* fBatchTarget; | 280 GrBatchTarget* fBatchTarget; |
282 }; | 281 }; |
283 | 282 |
284 struct XferBarrier : public Cmd { | 283 struct XferBarrier : public Cmd { |
285 XferBarrier() : Cmd(kXferBarrier_CmdType) {} | 284 XferBarrier() : Cmd(kXferBarrier_CmdType) {} |
286 | 285 |
287 void execute(GrGpu*, const SetState*) override; | 286 void execute(GrGpu*) override; |
288 | 287 |
289 GrXferBarrierType fBarrierType; | 288 GrXferBarrierType fBarrierType; |
290 }; | 289 }; |
291 | 290 |
292 static const int kCmdBufferInitialSizeInBytes = 8 * 1024; | 291 static const int kCmdBufferInitialSizeInBytes = 8 * 1024; |
293 | 292 |
294 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. | 293 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. |
295 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; | 294 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
296 | 295 |
297 CmdBuffer fCmdBuffer; | 296 CmdBuffer fCmdBuffer; |
298 SetState* fPrevState; | 297 GrBatchTarget fBatchTarget; |
299 GrBatchTarget fBatchTarget; | |
300 }; | 298 }; |
301 | 299 |
302 #endif | 300 #endif |
303 | 301 |
OLD | NEW |