OLD | NEW |
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 #include "GrInOrderDrawBuffer.h" | 8 #include "GrInOrderDrawBuffer.h" |
9 | 9 |
10 #include "GrDefaultGeoProcFactory.h" | 10 #include "GrDefaultGeoProcFactory.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 /** We always use per-vertex colors so that rects can be batched across color ch
anges. Sometimes we | 55 /** We always use per-vertex colors so that rects can be batched across color ch
anges. Sometimes we |
56 have explicit local coords and sometimes not. We *could* always provide expl
icit local coords | 56 have explicit local coords and sometimes not. We *could* always provide expl
icit local coords |
57 and just duplicate the positions when the caller hasn't provided a local coo
rd rect, but we | 57 and just duplicate the positions when the caller hasn't provided a local coo
rd rect, but we |
58 haven't seen a use case which frequently switches between local rect and no
local rect draws. | 58 haven't seen a use case which frequently switches between local rect and no
local rect draws. |
59 | 59 |
60 The color param is used to determine whether the opaque hint can be set on t
he draw state. | 60 The color param is used to determine whether the opaque hint can be set on t
he draw state. |
61 The caller must populate the vertex colors itself. | 61 The caller must populate the vertex colors itself. |
62 | 62 |
63 The vertex attrib order is always pos, color, [local coords]. | 63 The vertex attrib order is always pos, color, [local coords]. |
64 */ | 64 */ |
65 static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G
rColor color) { | 65 static const GrGeometryProcessor* create_rect_gp(GrDrawState* drawState, |
| 66 bool hasLocalCoords, |
| 67 GrColor color) { |
66 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | | 68 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
67 GrDefaultGeoProcFactory::kColor_GPType; | 69 GrDefaultGeoProcFactory::kColor_GPType; |
68 flags |= hasLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; | 70 flags |= hasLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; |
69 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(color, flags
))->unref(); | 71 return GrDefaultGeoProcFactory::Create(color, flags, GrColorIsOpaque(color))
; |
70 if (0xFF == GrColorUnpackA(color)) { | |
71 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | |
72 } | |
73 } | 72 } |
74 | 73 |
75 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin
gs) { | 74 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin
gs) { |
76 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa
ce; | 75 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa
ce; |
77 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); | 76 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); |
78 if (isWinding) { | 77 if (isWinding) { |
79 // Double check that it is in fact winding. | 78 // Double check that it is in fact winding. |
80 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); | 79 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); |
81 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); | 80 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); |
82 SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); | 81 SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); |
(...skipping 26 matching lines...) Expand all Loading... |
109 | 108 |
110 static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTr
aceCmdBit); } | 109 static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTr
aceCmdBit); } |
111 | 110 |
112 void GrInOrderDrawBuffer::onDrawRect(GrDrawState* ds, | 111 void GrInOrderDrawBuffer::onDrawRect(GrDrawState* ds, |
113 GrColor color, | 112 GrColor color, |
114 const SkRect& rect, | 113 const SkRect& rect, |
115 const SkRect* localRect, | 114 const SkRect* localRect, |
116 const SkMatrix* localMatrix) { | 115 const SkMatrix* localMatrix) { |
117 GrDrawState::AutoRestoreEffects are(ds); | 116 GrDrawState::AutoRestoreEffects are(ds); |
118 | 117 |
119 set_vertex_attributes(ds, SkToBool(localRect), color); | 118 SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(ds, SkToBool(local
Rect), color)); |
120 | 119 |
121 size_t vstride = ds->getGeometryProcessor()->getVertexStride(); | 120 size_t vstride = gp->getVertexStride(); |
122 SkASSERT(vstride == sizeof(SkPoint) + sizeof(GrColor) + (SkToBool(localRect)
? sizeof(SkPoint) : | 121 SkASSERT(vstride == sizeof(SkPoint) + sizeof(GrColor) + (SkToBool(localRect)
? sizeof(SkPoint) : |
123
0)); | 122
0)); |
124 AutoReleaseGeometry geo(this, 4, vstride, 0); | 123 AutoReleaseGeometry geo(this, 4, vstride, 0); |
125 if (!geo.succeeded()) { | 124 if (!geo.succeeded()) { |
126 SkDebugf("Failed to get space for vertices!\n"); | 125 SkDebugf("Failed to get space for vertices!\n"); |
127 return; | 126 return; |
128 } | 127 } |
129 | 128 |
130 // Go to device coords to allow batching across matrix changes | 129 // Go to device coords to allow batching across matrix changes |
131 SkMatrix matrix = ds->getViewMatrix(); | 130 SkMatrix matrix = ds->getViewMatrix(); |
(...skipping 26 matching lines...) Expand all Loading... |
158 } | 157 } |
159 | 158 |
160 static const int kColorOffset = sizeof(SkPoint); | 159 static const int kColorOffset = sizeof(SkPoint); |
161 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + k
ColorOffset); | 160 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + k
ColorOffset); |
162 for (int i = 0; i < 4; ++i) { | 161 for (int i = 0; i < 4; ++i) { |
163 *vertColor = color; | 162 *vertColor = color; |
164 vertColor = (GrColor*) ((intptr_t) vertColor + vstride); | 163 vertColor = (GrColor*) ((intptr_t) vertColor + vstride); |
165 } | 164 } |
166 | 165 |
167 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer()); | 166 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer()); |
168 this->drawIndexedInstances(ds, kTriangles_GrPrimitiveType, 1, 4, 6, &devBoun
ds); | 167 this->drawIndexedInstances(ds, gp, kTriangles_GrPrimitiveType, 1, 4, 6, &dev
Bounds); |
169 } | 168 } |
170 | 169 |
171 int GrInOrderDrawBuffer::concatInstancedDraw(const GrDrawState& ds, const DrawIn
fo& info) { | 170 int GrInOrderDrawBuffer::concatInstancedDraw(const GrDrawState& ds, const DrawIn
fo& info) { |
172 SkASSERT(!fCmdBuffer.empty()); | 171 SkASSERT(!fCmdBuffer.empty()); |
173 SkASSERT(info.isInstanced()); | 172 SkASSERT(info.isInstanced()); |
174 | 173 |
175 const GeometrySrcState& geomSrc = this->getGeomSrc(); | 174 const GeometrySrcState& geomSrc = this->getGeomSrc(); |
176 | 175 |
177 // we only attempt to concat the case when reserved verts are used with a cl
ient-specified index | 176 // we only attempt to concat the case when reserved verts are used with a cl
ient-specified index |
178 // buffer. To make this work with client-specified VBs we'd need to know if
the VB was updated | 177 // buffer. To make this work with client-specified VBs we'd need to know if
the VB was updated |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } else { | 213 } else { |
215 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); | 214 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); |
216 draw->fType = add_trace_bit(draw->fType); | 215 draw->fType = add_trace_bit(draw->fType); |
217 } | 216 } |
218 } | 217 } |
219 | 218 |
220 return instancesToConcat; | 219 return instancesToConcat; |
221 } | 220 } |
222 | 221 |
223 void GrInOrderDrawBuffer::onDraw(const GrDrawState& ds, | 222 void GrInOrderDrawBuffer::onDraw(const GrDrawState& ds, |
| 223 const GrGeometryProcessor* gp, |
224 const DrawInfo& info, | 224 const DrawInfo& info, |
225 const ScissorState& scissorState, | 225 const ScissorState& scissorState, |
226 const GrDeviceCoordTexture* dstCopy) { | 226 const GrDeviceCoordTexture* dstCopy) { |
227 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); | 227 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); |
228 | 228 |
229 const GrGeometryProcessor* gp = ds.getGeometryProcessor(); | 229 if (!this->recordStateAndShouldDraw(ds, gp, NULL, |
230 if (!this->recordStateAndShouldDraw(ds, gp->getColor(), gp->getCoverage(), | |
231 GrGpu::PrimTypeToDrawType(info.primitive
Type()), | 230 GrGpu::PrimTypeToDrawType(info.primitive
Type()), |
232 scissorState, dstCopy)) { | 231 scissorState, dstCopy)) { |
233 return; | 232 return; |
234 } | 233 } |
235 | 234 |
236 Draw* draw; | 235 Draw* draw; |
237 if (info.isInstanced()) { | 236 if (info.isInstanced()) { |
238 int instancesConcated = this->concatInstancedDraw(ds, info); | 237 int instancesConcated = this->concatInstancedDraw(ds, info); |
239 if (info.instanceCount() > instancesConcated) { | 238 if (info.instanceCount() > instancesConcated) { |
240 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); | 239 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
241 draw->fInfo.adjustInstanceCount(-instancesConcated); | 240 draw->fInfo.adjustInstanceCount(-instancesConcated); |
242 } else { | 241 } else { |
243 return; | 242 return; |
244 } | 243 } |
245 } else { | 244 } else { |
246 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); | 245 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
247 } | 246 } |
248 this->recordTraceMarkersIfNecessary(); | 247 this->recordTraceMarkersIfNecessary(); |
249 } | 248 } |
250 | 249 |
251 void GrInOrderDrawBuffer::onStencilPath(const GrDrawState& ds, | 250 void GrInOrderDrawBuffer::onStencilPath(const GrDrawState& ds, |
| 251 const GrPathProcessor* pathProc, |
252 const GrPath* path, | 252 const GrPath* path, |
253 const GrClipMaskManager::ScissorState& s
cissorState, | 253 const GrClipMaskManager::ScissorState& s
cissorState, |
254 const GrStencilSettings& stencilSettings
) { | 254 const GrStencilSettings& stencilSettings
) { |
255 // Only compare the subset of GrDrawState relevant to path stenciling? | 255 // Only compare the subset of GrDrawState relevant to path stenciling? |
256 if (!this->recordStateAndShouldDraw(ds, GrColor_WHITE, 0xff, GrGpu::kStencil
Path_DrawType, | 256 if (!this->recordStateAndShouldDraw(ds, NULL, pathProc, GrGpu::kStencilPath_
DrawType, |
257 scissorState, NULL)) { | 257 scissorState, NULL)) { |
258 return; | 258 return; |
259 } | 259 } |
260 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, (path)); | 260 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, (path)); |
261 sp->fStencilSettings = stencilSettings; | 261 sp->fStencilSettings = stencilSettings; |
262 this->recordTraceMarkersIfNecessary(); | 262 this->recordTraceMarkersIfNecessary(); |
263 } | 263 } |
264 | 264 |
265 void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds, | 265 void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds, |
266 GrColor color, | 266 const GrPathProcessor* pathProc, |
267 const GrPath* path, | 267 const GrPath* path, |
268 const GrClipMaskManager::ScissorState& scis
sorState, | 268 const GrClipMaskManager::ScissorState& scis
sorState, |
269 const GrStencilSettings& stencilSettings, | 269 const GrStencilSettings& stencilSettings, |
270 const GrDeviceCoordTexture* dstCopy) { | 270 const GrDeviceCoordTexture* dstCopy) { |
271 // TODO: Only compare the subset of GrDrawState relevant to path covering? | 271 // TODO: Only compare the subset of GrDrawState relevant to path covering? |
272 if (!this->recordStateAndShouldDraw(ds, color, 0xff, GrGpu::kDrawPath_DrawTy
pe, scissorState, | 272 if (!this->recordStateAndShouldDraw(ds, NULL, pathProc, GrGpu::kDrawPath_Dra
wType, |
273 dstCopy)) { | 273 scissorState, dstCopy)) { |
274 return; | 274 return; |
275 } | 275 } |
276 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); | 276 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); |
277 dp->fStencilSettings = stencilSettings; | 277 dp->fStencilSettings = stencilSettings; |
278 this->recordTraceMarkersIfNecessary(); | 278 this->recordTraceMarkersIfNecessary(); |
279 } | 279 } |
280 | 280 |
281 void GrInOrderDrawBuffer::onDrawPaths(const GrDrawState& ds, | 281 void GrInOrderDrawBuffer::onDrawPaths(const GrDrawState& ds, |
282 GrColor color, | 282 const GrPathProcessor* pathProc, |
283 const GrPathRange* pathRange, | 283 const GrPathRange* pathRange, |
284 const void* indices, | 284 const void* indices, |
285 PathIndexType indexType, | 285 PathIndexType indexType, |
286 const float transformValues[], | 286 const float transformValues[], |
287 PathTransformType transformType, | 287 PathTransformType transformType, |
288 int count, | 288 int count, |
289 const GrClipMaskManager::ScissorState& sci
ssorState, | 289 const GrClipMaskManager::ScissorState& sci
ssorState, |
290 const GrStencilSettings& stencilSettings, | 290 const GrStencilSettings& stencilSettings, |
291 const GrDeviceCoordTexture* dstCopy) { | 291 const GrDeviceCoordTexture* dstCopy) { |
292 SkASSERT(pathRange); | 292 SkASSERT(pathRange); |
293 SkASSERT(indices); | 293 SkASSERT(indices); |
294 SkASSERT(transformValues); | 294 SkASSERT(transformValues); |
295 | 295 |
296 if (!this->recordStateAndShouldDraw(ds, color, 0xff, GrGpu::kDrawPath_DrawTy
pe, scissorState, | 296 if (!this->recordStateAndShouldDraw(ds, NULL, pathProc, GrGpu::kDrawPath_Dra
wType, scissorState, |
297 dstCopy)) { | 297 dstCopy)) { |
298 return; | 298 return; |
299 } | 299 } |
300 | 300 |
301 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); | 301 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); |
302 if (int misalign = fPathIndexBuffer.count() % indexBytes) { | 302 if (int misalign = fPathIndexBuffer.count() % indexBytes) { |
303 // Add padding to the index buffer so the indices are aligned properly. | 303 // Add padding to the index buffer so the indices are aligned properly. |
304 fPathIndexBuffer.append(indexBytes - misalign); | 304 fPathIndexBuffer.append(indexBytes - misalign); |
305 } | 305 } |
306 | 306 |
(...skipping 10 matching lines...) Expand all Loading... |
317 // and the combined calls may also cancel each other's winding numbers i
n some | 317 // and the combined calls may also cancel each other's winding numbers i
n some |
318 // places. For now the winding numbers are only an issue if the fill is
even/odd, | 318 // places. For now the winding numbers are only an issue if the fill is
even/odd, |
319 // because DrawPaths is currently only used for glyphs, and glyphs in th
e same | 319 // because DrawPaths is currently only used for glyphs, and glyphs in th
e same |
320 // font tend to all wind in the same direction. | 320 // font tend to all wind in the same direction. |
321 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); | 321 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); |
322 if (pathRange == previous->pathRange() && | 322 if (pathRange == previous->pathRange() && |
323 indexType == previous->fIndexType && | 323 indexType == previous->fIndexType && |
324 transformType == previous->fTransformType && | 324 transformType == previous->fTransformType && |
325 stencilSettings == previous->fStencilSettings && | 325 stencilSettings == previous->fStencilSettings && |
326 path_fill_type_is_winding(stencilSettings) && | 326 path_fill_type_is_winding(stencilSettings) && |
327 !ds.willBlendWithDst(color, GrColor_WHITE)) { | 327 !ds.willBlendWithDst(pathProc)) { |
328 // Fold this DrawPaths call into the one previous. | 328 // Fold this DrawPaths call into the one previous. |
329 previous->fCount += count; | 329 previous->fCount += count; |
330 return; | 330 return; |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange))
; | 334 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange))
; |
335 dp->fIndicesLocation = savedIndices - fPathIndexBuffer.begin(); | 335 dp->fIndicesLocation = savedIndices - fPathIndexBuffer.begin(); |
336 dp->fIndexType = indexType; | 336 dp->fIndexType = indexType; |
337 dp->fTransformsLocation = savedTransforms - fPathTransformBuffer.begin(); | 337 dp->fTransformsLocation = savedTransforms - fPathTransformBuffer.begin(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst
, src)); | 483 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst
, src)); |
484 cs->fSrcRect = srcRect; | 484 cs->fSrcRect = srcRect; |
485 cs->fDstPoint = dstPoint; | 485 cs->fDstPoint = dstPoint; |
486 this->recordTraceMarkersIfNecessary(); | 486 this->recordTraceMarkersIfNecessary(); |
487 return true; | 487 return true; |
488 } | 488 } |
489 return false; | 489 return false; |
490 } | 490 } |
491 | 491 |
492 bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, | 492 bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, |
493 GrColor color, | 493 const GrGeometryProcessor* gp
, |
494 uint8_t coverage, | 494 const GrPathProcessor* pathPr
oc, |
495 GrGpu::DrawType drawType, | 495 GrGpu::DrawType drawType, |
496 const GrClipMaskManager::Scis
sorState& scissor, | 496 const GrClipMaskManager::Scis
sorState& scissor, |
497 const GrDeviceCoordTexture* d
stCopy) { | 497 const GrDeviceCoordTexture* d
stCopy) { |
498 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, | 498 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, |
499 (ds, color, coverage, *this->getGpu(
)->caps(), scissor, | 499 (ds, gp, pathProc, *this->getGpu()->
caps(), scissor, |
500 dstCopy, drawType)); | 500 dstCopy, drawType)); |
501 if (ss->fState.mustSkip()) { | 501 if (ss->fState.mustSkip()) { |
502 fCmdBuffer.pop_back(); | 502 fCmdBuffer.pop_back(); |
503 return false; | 503 return false; |
504 } | 504 } |
505 if (fPrevState && *fPrevState == ss->fState) { | 505 if (fPrevState && *fPrevState == ss->fState) { |
506 fCmdBuffer.pop_back(); | 506 fCmdBuffer.pop_back(); |
507 } else { | 507 } else { |
508 fPrevState = &ss->fState; | 508 fPrevState = &ss->fState; |
509 this->recordTraceMarkersIfNecessary(); | 509 this->recordTraceMarkersIfNecessary(); |
510 } | 510 } |
511 return true; | 511 return true; |
512 } | 512 } |
513 | 513 |
514 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { | 514 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
515 SkASSERT(!fCmdBuffer.empty()); | 515 SkASSERT(!fCmdBuffer.empty()); |
516 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); | 516 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); |
517 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); | 517 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
518 if (activeTraceMarkers.count() > 0) { | 518 if (activeTraceMarkers.count() > 0) { |
519 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); | 519 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); |
520 fGpuCmdMarkers.push_back(activeTraceMarkers); | 520 fGpuCmdMarkers.push_back(activeTraceMarkers); |
521 } | 521 } |
522 } | 522 } |
OLD | NEW |