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

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

Issue 709133003: Snap optdrawstate in inorder draw buffer and pass into gpu (Closed) Base URL: https://skia.googlesource.com/skia.git@remove_friends
Patch Set: Created 6 years, 1 month 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/GrGpu.cpp ('k') | src/gpu/GrInOrderDrawBuffer.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 2011 Google Inc. 2 * Copyright 2011 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 GrInOrderDrawBuffer_DEFINED 8 #ifndef GrInOrderDrawBuffer_DEFINED
9 #define GrInOrderDrawBuffer_DEFINED 9 #define GrInOrderDrawBuffer_DEFINED
10 10
11 #include "GrDrawTarget.h" 11 #include "GrDrawTarget.h"
12 #include "GrAllocPool.h" 12 #include "GrAllocPool.h"
13 #include "GrAllocator.h" 13 #include "GrAllocator.h"
14 #include "GrGpu.h"
14 #include "GrIndexBuffer.h" 15 #include "GrIndexBuffer.h"
15 #include "GrRenderTarget.h" 16 #include "GrRenderTarget.h"
16 #include "GrPath.h" 17 #include "GrPath.h"
17 #include "GrPathRange.h" 18 #include "GrPathRange.h"
18 #include "GrSurface.h" 19 #include "GrSurface.h"
19 #include "GrTRecorder.h" 20 #include "GrTRecorder.h"
20 #include "GrVertexBuffer.h" 21 #include "GrVertexBuffer.h"
21 22
22 #include "SkClipStack.h" 23 #include "SkClipStack.h"
23 #include "SkTemplates.h" 24 #include "SkTemplates.h"
24 #include "SkTypes.h" 25 #include "SkTypes.h"
25 26
26 class GrGpu;
27 class GrIndexBufferAllocPool; 27 class GrIndexBufferAllocPool;
28 class GrVertexBufferAllocPool; 28 class GrVertexBufferAllocPool;
29 29
30 /** 30 /**
31 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual 31 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual
32 * playback into a GrGpu. In theory one draw buffer could playback into another. When index or 32 * playback into a GrGpu. In theory one draw buffer could playback into another. When index or
33 * vertex buffers are used as geometry sources it is the callers the draw buffer only holds 33 * vertex buffers are used as geometry sources it is the callers the draw buffer only holds
34 * references to the buffers. It is the callers responsibility to ensure that th e data is still 34 * references to the buffers. It is the callers responsibility to ensure that th e data is still
35 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's 35 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's
36 * responsibility to ensure that all referenced textures, buffers, and render-ta rgets are associated 36 * responsibility to ensure that all referenced textures, buffers, and render-ta rgets are associated
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 kClear_Cmd = 4, 103 kClear_Cmd = 4,
104 kCopySurface_Cmd = 5, 104 kCopySurface_Cmd = 5,
105 kDrawPath_Cmd = 6, 105 kDrawPath_Cmd = 6,
106 kDrawPaths_Cmd = 7, 106 kDrawPaths_Cmd = 7,
107 }; 107 };
108 108
109 struct Cmd : ::SkNoncopyable { 109 struct Cmd : ::SkNoncopyable {
110 Cmd(uint8_t type) : fType(type) {} 110 Cmd(uint8_t type) : fType(type) {}
111 virtual ~Cmd() {} 111 virtual ~Cmd() {}
112 112
113 virtual void execute(GrGpu*) = 0; 113 virtual void execute(GrGpu*, const GrOptDrawState*) = 0;
114 114
115 uint8_t fType; 115 uint8_t fType;
116 }; 116 };
117 117
118 struct Draw : public Cmd { 118 struct Draw : public Cmd {
119 Draw(const DrawInfo& info, 119 Draw(const DrawInfo& info,
120 const ScissorState& scissorState, 120 const ScissorState& scissorState,
121 const GrVertexBuffer* vb, 121 const GrVertexBuffer* vb,
122 const GrIndexBuffer* ib) 122 const GrIndexBuffer* ib)
123 : Cmd(kDraw_Cmd) 123 : Cmd(kDraw_Cmd)
124 , fInfo(info) 124 , fInfo(info)
125 , fScissorState(scissorState) 125 , fScissorState(scissorState)
126 , fVertexBuffer(vb) 126 , fVertexBuffer(vb)
127 , fIndexBuffer(ib) {} 127 , fIndexBuffer(ib) {}
128 128
129 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } 129 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
130 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } 130 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); }
131 131
132 virtual void execute(GrGpu*); 132 virtual void execute(GrGpu*, const GrOptDrawState*);
133 133
134 DrawInfo fInfo; 134 DrawInfo fInfo;
135 ScissorState fScissorState; 135 ScissorState fScissorState;
136 136
137 private: 137 private:
138 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuff er; 138 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuff er;
139 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffe r; 139 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffe r;
140 }; 140 };
141 141
142 struct StencilPath : public Cmd { 142 struct StencilPath : public Cmd {
143 StencilPath(const GrPath* path) : Cmd(kStencilPath_Cmd), fPath(path) {} 143 StencilPath(const GrPath* path) : Cmd(kStencilPath_Cmd), fPath(path) {}
144 144
145 const GrPath* path() const { return fPath.get(); } 145 const GrPath* path() const { return fPath.get(); }
146 146
147 virtual void execute(GrGpu*); 147 virtual void execute(GrGpu*, const GrOptDrawState*);
148 148
149 ScissorState fScissorState; 149 ScissorState fScissorState;
150 GrStencilSettings fStencilSettings; 150 GrStencilSettings fStencilSettings;
151 151
152 private: 152 private:
153 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; 153 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath;
154 }; 154 };
155 155
156 struct DrawPath : public Cmd { 156 struct DrawPath : public Cmd {
157 DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} 157 DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {}
158 158
159 const GrPath* path() const { return fPath.get(); } 159 const GrPath* path() const { return fPath.get(); }
160 160
161 virtual void execute(GrGpu*); 161 virtual void execute(GrGpu*, const GrOptDrawState*);
162 162
163 GrDeviceCoordTexture fDstCopy; 163 GrDeviceCoordTexture fDstCopy;
164 ScissorState fScissorState; 164 ScissorState fScissorState;
165 GrStencilSettings fStencilSettings; 165 GrStencilSettings fStencilSettings;
166 166
167 private: 167 private:
168 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; 168 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath;
169 }; 169 };
170 170
171 struct DrawPaths : public Cmd { 171 struct DrawPaths : public Cmd {
172 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRang e(pathRange) {} 172 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRang e(pathRange) {}
173 173
174 const GrPathRange* pathRange() const { return fPathRange.get(); } 174 const GrPathRange* pathRange() const { return fPathRange.get(); }
175 uint32_t* indices() { return reinterpret_cast<uint32_t*>(CmdBuffer::GetD ataForItem(this)); } 175 uint32_t* indices() { return reinterpret_cast<uint32_t*>(CmdBuffer::GetD ataForItem(this)); }
176 float* transforms() { return reinterpret_cast<float*>(&this->indices()[f Count]); } 176 float* transforms() { return reinterpret_cast<float*>(&this->indices()[f Count]); }
177 177
178 virtual void execute(GrGpu*); 178 virtual void execute(GrGpu*, const GrOptDrawState*);
179 179
180 size_t fCount; 180 size_t fCount;
181 PathTransformType fTransformsType; 181 PathTransformType fTransformsType;
182 GrDeviceCoordTexture fDstCopy; 182 GrDeviceCoordTexture fDstCopy;
183 ScissorState fScissorState; 183 ScissorState fScissorState;
184 GrStencilSettings fStencilSettings; 184 GrStencilSettings fStencilSettings;
185 185
186 private: 186 private:
187 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; 187 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange;
188 }; 188 };
189 189
190 // This is also used to record a discard by setting the color to GrColor_ILL EGAL 190 // This is also used to record a discard by setting the color to GrColor_ILL EGAL
191 struct Clear : public Cmd { 191 struct Clear : public Cmd {
192 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} 192 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {}
193 193
194 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } 194 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
195 195
196 virtual void execute(GrGpu*); 196 virtual void execute(GrGpu*, const GrOptDrawState*);
197 197
198 SkIRect fRect; 198 SkIRect fRect;
199 GrColor fColor; 199 GrColor fColor;
200 bool fCanIgnoreRect; 200 bool fCanIgnoreRect;
201 201
202 private: 202 private:
203 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; 203 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
204 }; 204 };
205 205
206 // This command is ONLY used by the clip mask manager to clear the stencil c lip bits 206 // This command is ONLY used by the clip mask manager to clear the stencil c lip bits
207 struct ClearStencilClip : public Cmd { 207 struct ClearStencilClip : public Cmd {
208 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt ) {} 208 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt ) {}
209 209
210 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } 210 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
211 211
212 virtual void execute(GrGpu*); 212 virtual void execute(GrGpu*, const GrOptDrawState*);
213 213
214 SkIRect fRect; 214 SkIRect fRect;
215 bool fInsideClip; 215 bool fInsideClip;
216 216
217 private: 217 private:
218 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; 218 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
219 }; 219 };
220 220
221 struct CopySurface : public Cmd { 221 struct CopySurface : public Cmd {
222 CopySurface(GrSurface* dst, GrSurface* src) : Cmd(kCopySurface_Cmd), fDs t(dst), fSrc(src) {} 222 CopySurface(GrSurface* dst, GrSurface* src) : Cmd(kCopySurface_Cmd), fDs t(dst), fSrc(src) {}
223 223
224 GrSurface* dst() const { return fDst.get(); } 224 GrSurface* dst() const { return fDst.get(); }
225 GrSurface* src() const { return fSrc.get(); } 225 GrSurface* src() const { return fSrc.get(); }
226 226
227 virtual void execute(GrGpu*); 227 virtual void execute(GrGpu*, const GrOptDrawState*);
228 228
229 SkIPoint fDstPoint; 229 SkIPoint fDstPoint;
230 SkIRect fSrcRect; 230 SkIRect fSrcRect;
231 231
232 private: 232 private:
233 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; 233 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst;
234 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; 234 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc;
235 }; 235 };
236 236
237 struct SetState : public Cmd { 237 struct SetState : public Cmd {
238 SetState(const GrDrawState& state) : Cmd(kSetState_Cmd), fState(state) { } 238 SetState(const GrDrawState& state) : Cmd(kSetState_Cmd), fState(state) { }
239 239
240 virtual void execute(GrGpu*); 240 virtual void execute(GrGpu*, const GrOptDrawState*);
241 241
242 GrDrawState fState; 242 GrDrawState fState;
243 GrGpu::DrawType fDrawType;
244 GrDeviceCoordTexture fDstCopy;
243 }; 245 };
244 246
245 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double. 247 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double.
246 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; 248 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer;
247 249
248 // overrides from GrDrawTarget 250 // overrides from GrDrawTarget
249 virtual void onDraw(const DrawInfo&, const GrClipMaskManager::ScissorState&) SK_OVERRIDE; 251 virtual void onDraw(const DrawInfo&, const GrClipMaskManager::ScissorState&) SK_OVERRIDE;
250 virtual void onDrawRect(const SkRect& rect, 252 virtual void onDrawRect(const SkRect& rect,
251 const SkRect* localRect, 253 const SkRect* localRect,
252 const SkMatrix* localMatrix) SK_OVERRIDE; 254 const SkMatrix* localMatrix) SK_OVERRIDE;
(...skipping 28 matching lines...) Expand all
281 virtual void geometrySourceWillPush() SK_OVERRIDE; 283 virtual void geometrySourceWillPush() SK_OVERRIDE;
282 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK _OVERRIDE; 284 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK _OVERRIDE;
283 virtual void willReserveVertexAndIndexSpace(int vertexCount, 285 virtual void willReserveVertexAndIndexSpace(int vertexCount,
284 int indexCount) SK_OVERRIDE; 286 int indexCount) SK_OVERRIDE;
285 287
286 // Attempts to concat instances from info onto the previous draw. info must represent an 288 // Attempts to concat instances from info onto the previous draw. info must represent an
287 // instanced draw. The caller must have already recorded a new draw state an d clip if necessary. 289 // instanced draw. The caller must have already recorded a new draw state an d clip if necessary.
288 int concatInstancedDraw(const DrawInfo& info, const GrClipMaskManager::Sciss orState&); 290 int concatInstancedDraw(const DrawInfo& info, const GrClipMaskManager::Sciss orState&);
289 291
290 // Determines whether the current draw operation requieres a new drawstate a nd if so records it. 292 // Determines whether the current draw operation requieres a new drawstate a nd if so records it.
291 void recordStateIfNecessary(); 293 void recordStateIfNecessary(GrGpu::DrawType, const GrDeviceCoordTexture*);
292 // We lazily record clip changes in order to skip clips that have no effect. 294 // We lazily record clip changes in order to skip clips that have no effect.
293 void recordClipIfNecessary(); 295 void recordClipIfNecessary();
294 // Records any trace markers for a command after adding it to the buffer. 296 // Records any trace markers for a command after adding it to the buffer.
295 void recordTraceMarkersIfNecessary(); 297 void recordTraceMarkersIfNecessary();
296 298
297 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } 299 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; }
298 300
299 // TODO: Use a single allocator for commands and records 301 // TODO: Use a single allocator for commands and records
300 enum { 302 enum {
301 kCmdBufferInitialSizeInBytes = 8 * 1024, 303 kCmdBufferInitialSizeInBytes = 8 * 1024,
(...skipping 22 matching lines...) Expand all
324 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS tack; 326 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS tack;
325 327
326 GeoPoolStateStack fGeoPoolStateStack; 328 GeoPoolStateStack fGeoPoolStateStack;
327 bool fFlushing; 329 bool fFlushing;
328 uint32_t fDrawID; 330 uint32_t fDrawID;
329 331
330 typedef GrClipTarget INHERITED; 332 typedef GrClipTarget INHERITED;
331 }; 333 };
332 334
333 #endif 335 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.cpp ('k') | src/gpu/GrInOrderDrawBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698