Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: src/gpu/GrTargetCommands.h

Issue 1119353002: Revert of Move state management to GrInOrderDrawBuffer (Closed) Base URL: https://skia.googlesource.com/skia.git@batchownsbounds
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrInOrderDrawBuffer.cpp ('k') | src/gpu/GrTargetCommands.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
28 struct SetState; 27 struct SetState;
29 28
30 public: 29 public:
31 GrTargetCommands(GrGpu* gpu, 30 GrTargetCommands(GrGpu* gpu,
32 GrVertexBufferAllocPool* vertexPool, 31 GrVertexBufferAllocPool* vertexPool,
33 GrIndexBufferAllocPool* indexPool) 32 GrIndexBufferAllocPool* indexPool)
34 : fCmdBuffer(kCmdBufferInitialSizeInBytes) 33 : 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*) = 0; 54 virtual void execute(GrGpu*, const SetState*) = 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(const SkIRect& rect, 71 Cmd* recordClearStencilClip(GrInOrderDrawBuffer*,
72 const SkIRect& rect,
72 bool insideClip, 73 bool insideClip,
73 GrRenderTarget* renderTarget); 74 GrRenderTarget* renderTarget);
74 75
75 Cmd* recordDiscard(GrRenderTarget*); 76 Cmd* recordDiscard(GrInOrderDrawBuffer*, GrRenderTarget*);
76 Cmd* recordDrawBatch(State*, GrBatch*); 77
77 Cmd* recordStencilPath(const GrPipelineBuilder&, 78 Cmd* recordDraw(GrInOrderDrawBuffer*,
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&,
78 const GrPathProcessor*, 87 const GrPathProcessor*,
79 const GrPath*, 88 const GrPath*,
80 const GrScissorState&, 89 const GrScissorState&,
81 const GrStencilSettings&); 90 const GrStencilSettings&);
82 Cmd* recordDrawPath(State*, 91 Cmd* recordDrawPath(GrInOrderDrawBuffer*,
83 const GrPathProcessor*, 92 const GrPathProcessor*,
84 const GrPath*, 93 const GrPath*,
85 const GrStencilSettings&); 94 const GrStencilSettings&,
86 Cmd* recordDrawPaths(State*, 95 const GrDrawTarget::PipelineInfo&);
87 GrInOrderDrawBuffer*, 96 Cmd* recordDrawPaths(GrInOrderDrawBuffer*,
88 const GrPathProcessor*, 97 const GrPathProcessor*,
89 const GrPathRange*, 98 const GrPathRange*,
90 const void*, 99 const void*,
91 GrDrawTarget::PathIndexType, 100 GrDrawTarget::PathIndexType,
92 const float transformValues[], 101 const float transformValues[],
93 GrDrawTarget::PathTransformType , 102 GrDrawTarget::PathTransformType ,
94 int, 103 int,
95 const GrStencilSettings&, 104 const GrStencilSettings&,
96 const GrDrawTarget::PipelineInfo&); 105 const GrDrawTarget::PipelineInfo&);
97 Cmd* recordClear(const SkIRect* rect, 106 Cmd* recordClear(GrInOrderDrawBuffer*,
107 const SkIRect* rect,
98 GrColor, 108 GrColor,
99 bool canIgnoreRect, 109 bool canIgnoreRect,
100 GrRenderTarget*); 110 GrRenderTarget*);
101 Cmd* recordCopySurface(GrSurface* dst, 111 Cmd* recordCopySurface(GrSurface* dst,
102 GrSurface* src, 112 GrSurface* src,
103 const SkIRect& srcRect, 113 const SkIRect& srcRect,
104 const SkIPoint& dstPoint); 114 const SkIPoint& dstPoint);
105 115
106 private: 116 private:
107 friend class GrInOrderDrawBuffer; 117 friend class GrInOrderDrawBuffer;
108 118
109 typedef GrGpu::DrawArgs DrawArgs; 119 typedef GrGpu::DrawArgs DrawArgs;
110 120
111 void recordXferBarrierIfNecessary(const GrPipeline&, GrInOrderDrawBuffer*); 121 // Attempts to concat instances from info onto the previous draw. info must represent an
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&) ;
112 124
113 // TODO: This can be just a pipeline once paths are in batch, and it should live elsewhere 125 bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrInOrderDrawBuffer*,
114 struct State : public SkRefCnt { 126 const GrPrimitiveProce ssor*,
115 // TODO get rid of the prim proc parameter when we use batch everywhere 127 const GrDrawTarget::Pi pelineInfo&);
116 State(const GrPrimitiveProcessor* primProc = NULL) 128 bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrInOrderDrawBuffer*,
117 : fPrimitiveProcessor(primProc) 129 GrBatch*,
118 , fCompiled(false) {} 130 const GrDrawTarget::Pi pelineInfo&);
119 131
120 ~State() { reinterpret_cast<GrPipeline*>(fPipeline.get())->~GrPipeline() ; } 132 void recordXferBarrierIfNecessary(GrInOrderDrawBuffer*, const GrDrawTarget:: PipelineInfo&);
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 //SkDebugf("destruction\n");
138 }
139 void* operator new(size_t) {
140 SkFAIL("All States are created by placement new.");
141 return sk_malloc_throw(0);
142 }
143
144 void* operator new(size_t, void* p) { return p; }
145 void operator delete(void* target, void* placement) {
146 ::operator delete(target, placement);
147 }
148
149 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor;
150 ProgramPrimitiveProcessor fPrimitiveProcessor;
151 SkAlignedSStorage<sizeof(GrPipeline)> fPipeline;
152 GrProgramDesc fDesc;
153 GrBatchTracker fBatchTracker;
154 bool fCompiled;
155 };
156 133
157 struct StencilPath : public Cmd { 134 struct StencilPath : public Cmd {
158 StencilPath(const GrPath* path, GrRenderTarget* rt) 135 StencilPath(const GrPath* path, GrRenderTarget* rt)
159 : Cmd(kStencilPath_CmdType) 136 : Cmd(kStencilPath_CmdType)
160 , fRenderTarget(rt) 137 , fRenderTarget(rt)
161 , fPath(path) {} 138 , fPath(path) {}
162 139
163 const GrPath* path() const { return fPath.get(); } 140 const GrPath* path() const { return fPath.get(); }
164 141
165 void execute(GrGpu*) override; 142 void execute(GrGpu*, const SetState*) override;
166 143
167 SkMatrix fViewMatrix; 144 SkMatrix fViewMatrix;
168 bool fUseHWAA; 145 bool fUseHWAA;
169 GrStencilSettings fStencil; 146 GrStencilSettings fStencil;
170 GrScissorState fScissor; 147 GrScissorState fScissor;
171 private: 148 private:
172 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; 149 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
173 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; 150 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath;
174 }; 151 };
175 152
176 struct DrawPath : public Cmd { 153 struct DrawPath : public Cmd {
177 DrawPath(State* state, const GrPath* path) 154 DrawPath(const GrPath* path) : Cmd(kDrawPath_CmdType), fPath(path) {}
178 : Cmd(kDrawPath_CmdType)
179 , fState(SkRef(state))
180 , fPath(path) {}
181 155
182 const GrPath* path() const { return fPath.get(); } 156 const GrPath* path() const { return fPath.get(); }
183 157
184 void execute(GrGpu*) override; 158 void execute(GrGpu*, const SetState*) override;
185 159
186 SkAutoTUnref<State> fState;
187 GrStencilSettings fStencilSettings; 160 GrStencilSettings fStencilSettings;
161
188 private: 162 private:
189 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; 163 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath;
190 }; 164 };
191 165
192 struct DrawPaths : public Cmd { 166 struct DrawPaths : public Cmd {
193 DrawPaths(State* state, const GrPathRange* pathRange) 167 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_CmdType), fPath Range(pathRange) {}
194 : Cmd(kDrawPaths_CmdType)
195 , fState(SkRef(state))
196 , fPathRange(pathRange) {}
197 168
198 const GrPathRange* pathRange() const { return fPathRange.get(); } 169 const GrPathRange* pathRange() const { return fPathRange.get(); }
199 170
200 void execute(GrGpu*) override; 171 void execute(GrGpu*, const SetState*) override;
201 172
202 SkAutoTUnref<State> fState;
203 char* fIndices; 173 char* fIndices;
204 GrDrawTarget::PathIndexType fIndexType; 174 GrDrawTarget::PathIndexType fIndexType;
205 float* fTransforms; 175 float* fTransforms;
206 GrDrawTarget::PathTransformType fTransformType; 176 GrDrawTarget::PathTransformType fTransformType;
207 int fCount; 177 int fCount;
208 GrStencilSettings fStencilSettings; 178 GrStencilSettings fStencilSettings;
209 179
210 private: 180 private:
211 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; 181 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange;
212 }; 182 };
213 183
214 // This is also used to record a discard by setting the color to GrColor_ILL EGAL 184 // This is also used to record a discard by setting the color to GrColor_ILL EGAL
215 struct Clear : public Cmd { 185 struct Clear : public Cmd {
216 Clear(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarget(rt) {} 186 Clear(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarget(rt) {}
217 187
218 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } 188 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
219 189
220 void execute(GrGpu*) override; 190 void execute(GrGpu*, const SetState*) override;
221 191
222 SkIRect fRect; 192 SkIRect fRect;
223 GrColor fColor; 193 GrColor fColor;
224 bool fCanIgnoreRect; 194 bool fCanIgnoreRect;
225 195
226 private: 196 private:
227 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; 197 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
228 }; 198 };
229 199
230 // This command is ONLY used by the clip mask manager to clear the stencil c lip bits 200 // This command is ONLY used by the clip mask manager to clear the stencil c lip bits
231 struct ClearStencilClip : public Cmd { 201 struct ClearStencilClip : public Cmd {
232 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarge t(rt) {} 202 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarge t(rt) {}
233 203
234 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } 204 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
235 205
236 void execute(GrGpu*) override; 206 void execute(GrGpu*, const SetState*) override;
237 207
238 SkIRect fRect; 208 SkIRect fRect;
239 bool fInsideClip; 209 bool fInsideClip;
240 210
241 private: 211 private:
242 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; 212 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
243 }; 213 };
244 214
245 struct CopySurface : public Cmd { 215 struct CopySurface : public Cmd {
246 CopySurface(GrSurface* dst, GrSurface* src) 216 CopySurface(GrSurface* dst, GrSurface* src)
247 : Cmd(kCopySurface_CmdType) 217 : Cmd(kCopySurface_CmdType)
248 , fDst(dst) 218 , fDst(dst)
249 , fSrc(src) { 219 , fSrc(src) {
250 } 220 }
251 221
252 GrSurface* dst() const { return fDst.get(); } 222 GrSurface* dst() const { return fDst.get(); }
253 GrSurface* src() const { return fSrc.get(); } 223 GrSurface* src() const { return fSrc.get(); }
254 224
255 void execute(GrGpu*) override; 225 void execute(GrGpu*, const SetState*) override;
256 226
257 SkIPoint fDstPoint; 227 SkIPoint fDstPoint;
258 SkIRect fSrcRect; 228 SkIRect fSrcRect;
259 229
260 private: 230 private:
261 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; 231 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst;
262 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; 232 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc;
263 }; 233 };
264 234
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
265 struct DrawBatch : public Cmd { 267 struct DrawBatch : public Cmd {
266 DrawBatch(State* state, GrBatch* batch, GrBatchTarget* batchTarget) 268 DrawBatch(GrBatch* batch, GrBatchTarget* batchTarget)
267 : Cmd(kDrawBatch_CmdType) 269 : Cmd(kDrawBatch_CmdType)
268 , fState(SkRef(state))
269 , fBatch(SkRef(batch)) 270 , fBatch(SkRef(batch))
270 , fBatchTarget(batchTarget) { 271 , fBatchTarget(batchTarget) {
271 SkASSERT(!batch->isUsed()); 272 SkASSERT(!batch->isUsed());
272 } 273 }
273 274
274 void execute(GrGpu*) override; 275 void execute(GrGpu*, const SetState*) override;
275 276
276 SkAutoTUnref<State> fState; 277 // TODO it wouldn't be too hard to let batches allocate in the cmd buffe r
277 SkAutoTUnref<GrBatch> fBatch; 278 SkAutoTUnref<GrBatch> fBatch;
278 279
279 private: 280 private:
280 GrBatchTarget* fBatchTarget; 281 GrBatchTarget* fBatchTarget;
281 }; 282 };
282 283
283 struct XferBarrier : public Cmd { 284 struct XferBarrier : public Cmd {
284 XferBarrier() : Cmd(kXferBarrier_CmdType) {} 285 XferBarrier() : Cmd(kXferBarrier_CmdType) {}
285 286
286 void execute(GrGpu*) override; 287 void execute(GrGpu*, const SetState*) override;
287 288
288 GrXferBarrierType fBarrierType; 289 GrXferBarrierType fBarrierType;
289 }; 290 };
290 291
291 static const int kCmdBufferInitialSizeInBytes = 8 * 1024; 292 static const int kCmdBufferInitialSizeInBytes = 8 * 1024;
292 293
293 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double. 294 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double.
294 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; 295 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer;
295 296
296 CmdBuffer fCmdBuffer; 297 CmdBuffer fCmdBuffer;
297 GrBatchTarget fBatchTarget; 298 SetState* fPrevState;
299 GrBatchTarget fBatchTarget;
298 }; 300 };
299 301
300 #endif 302 #endif
301 303
OLDNEW
« no previous file with comments | « src/gpu/GrInOrderDrawBuffer.cpp ('k') | src/gpu/GrTargetCommands.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698