| 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 "GrBufferAllocPool.h" | 10 #include "GrBufferAllocPool.h" |
| 11 #include "GrDefaultGeoProcFactory.h" |
| 11 #include "GrDrawTargetCaps.h" | 12 #include "GrDrawTargetCaps.h" |
| 12 #include "GrGpu.h" | 13 #include "GrGpu.h" |
| 13 #include "GrOptDrawState.h" | 14 #include "GrOptDrawState.h" |
| 14 #include "GrTemplates.h" | 15 #include "GrTemplates.h" |
| 15 #include "GrTextStrike.h" | 16 #include "GrTextStrike.h" |
| 16 #include "GrTexture.h" | 17 #include "GrTexture.h" |
| 17 | 18 |
| 18 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, | 19 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, |
| 19 GrVertexBufferAllocPool* vertexPool, | 20 GrVertexBufferAllocPool* vertexPool, |
| 20 GrIndexBufferAllocPool* indexPool) | 21 GrIndexBufferAllocPool* indexPool) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 const SkPoint* point = static_cast<const SkPoint*>(vertices); | 68 const SkPoint* point = static_cast<const SkPoint*>(vertices); |
| 68 bounds->fLeft = bounds->fRight = point->fX; | 69 bounds->fLeft = bounds->fRight = point->fX; |
| 69 bounds->fTop = bounds->fBottom = point->fY; | 70 bounds->fTop = bounds->fBottom = point->fY; |
| 70 for (int i = 1; i < vertexCount; ++i) { | 71 for (int i = 1; i < vertexCount; ++i) { |
| 71 point = reinterpret_cast<SkPoint*>(reinterpret_cast<intptr_t>(point) + v
ertexSize); | 72 point = reinterpret_cast<SkPoint*>(reinterpret_cast<intptr_t>(point) + v
ertexSize); |
| 72 bounds->growToInclude(point->fX, point->fY); | 73 bounds->growToInclude(point->fX, point->fY); |
| 73 } | 74 } |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 | 77 |
| 77 | |
| 78 namespace { | |
| 79 | |
| 80 extern const GrVertexAttrib kRectAttribs[] = { | |
| 81 {kVec2f_GrVertexAttribType, 0, kPosition_GrVe
rtexAttribBinding}, | |
| 82 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVerte
xAttribBinding}, | |
| 83 {kVec2f_GrVertexAttribType, sizeof(SkPoint)+sizeof(GrColor), kLocalCoord_Gr
VertexAttribBinding}, | |
| 84 }; | |
| 85 } | |
| 86 | |
| 87 /** We always use per-vertex colors so that rects can be batched across color ch
anges. Sometimes we | 78 /** We always use per-vertex colors so that rects can be batched across color ch
anges. Sometimes we |
| 88 have explicit local coords and sometimes not. We *could* always provide expl
icit local coords | 79 have explicit local coords and sometimes not. We *could* always provide expl
icit local coords |
| 89 and just duplicate the positions when the caller hasn't provided a local coo
rd rect, but we | 80 and just duplicate the positions when the caller hasn't provided a local coo
rd rect, but we |
| 90 haven't seen a use case which frequently switches between local rect and no
local rect draws. | 81 haven't seen a use case which frequently switches between local rect and no
local rect draws. |
| 91 | 82 |
| 92 The color param is used to determine whether the opaque hint can be set on t
he draw state. | 83 The color param is used to determine whether the opaque hint can be set on t
he draw state. |
| 93 The caller must populate the vertex colors itself. | 84 The caller must populate the vertex colors itself. |
| 94 | 85 |
| 95 The vertex attrib order is always pos, color, [local coords]. | 86 The vertex attrib order is always pos, color, [local coords]. |
| 96 */ | 87 */ |
| 97 static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G
rColor color) { | 88 static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G
rColor color) { |
| 98 if (hasLocalCoords) { | 89 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
| 99 drawState->setVertexAttribs<kRectAttribs>(3, 2 * sizeof(SkPoint) + sizeo
f(SkColor)); | 90 GrDefaultGeoProcFactory::kColor_GPType; |
| 100 } else { | 91 flags |= hasLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; |
| 101 drawState->setVertexAttribs<kRectAttribs>(2, sizeof(SkPoint) + sizeof(Sk
Color)); | 92 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::CreateAndSetAttribs
(drawState, |
| 102 } | 93
flags))->unref(); |
| 103 if (0xFF == GrColorUnpackA(color)) { | 94 if (0xFF == GrColorUnpackA(color)) { |
| 104 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | 95 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
| 105 } | 96 } |
| 106 } | 97 } |
| 107 | 98 |
| 108 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin
gs) { | 99 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin
gs) { |
| 109 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa
ce; | 100 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa
ce; |
| 110 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); | 101 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); |
| 111 if (isWinding) { | 102 if (isWinding) { |
| 112 // Double check that it is in fact winding. | 103 // Double check that it is in fact winding. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 139 static inline uint8_t add_trace_bit(uint8_t cmd) { return cmd | kTraceCmdBit; } | 130 static inline uint8_t add_trace_bit(uint8_t cmd) { return cmd | kTraceCmdBit; } |
| 140 | 131 |
| 141 static inline uint8_t strip_trace_bit(uint8_t cmd) { return cmd & kCmdMask; } | 132 static inline uint8_t strip_trace_bit(uint8_t cmd) { return cmd & kCmdMask; } |
| 142 | 133 |
| 143 static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTr
aceCmdBit); } | 134 static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTr
aceCmdBit); } |
| 144 | 135 |
| 145 void GrInOrderDrawBuffer::onDrawRect(const SkRect& rect, | 136 void GrInOrderDrawBuffer::onDrawRect(const SkRect& rect, |
| 146 const SkRect* localRect, | 137 const SkRect* localRect, |
| 147 const SkMatrix* localMatrix) { | 138 const SkMatrix* localMatrix) { |
| 148 GrDrawState* drawState = this->drawState(); | 139 GrDrawState* drawState = this->drawState(); |
| 140 GrDrawState::AutoRestoreEffects are(drawState); |
| 149 | 141 |
| 150 GrColor color = drawState->getColor(); | 142 GrColor color = drawState->getColor(); |
| 151 | 143 |
| 152 set_vertex_attributes(drawState, SkToBool(localRect), color); | 144 set_vertex_attributes(drawState, SkToBool(localRect), color); |
| 153 | 145 |
| 154 AutoReleaseGeometry geo(this, 4, 0); | 146 AutoReleaseGeometry geo(this, 4, 0); |
| 155 if (!geo.succeeded()) { | 147 if (!geo.succeeded()) { |
| 156 SkDebugf("Failed to get space for vertices!\n"); | 148 SkDebugf("Failed to get space for vertices!\n"); |
| 157 return; | 149 return; |
| 158 } | 150 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); | 257 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); |
| 266 draw->fType = add_trace_bit(draw->fType); | 258 draw->fType = add_trace_bit(draw->fType); |
| 267 } | 259 } |
| 268 } | 260 } |
| 269 | 261 |
| 270 return instancesToConcat; | 262 return instancesToConcat; |
| 271 } | 263 } |
| 272 | 264 |
| 273 void GrInOrderDrawBuffer::onDraw(const DrawInfo& info, | 265 void GrInOrderDrawBuffer::onDraw(const DrawInfo& info, |
| 274 const GrClipMaskManager::ScissorState& scissorS
tate) { | 266 const GrClipMaskManager::ScissorState& scissorS
tate) { |
| 275 | |
| 276 GeometryPoolState& poolState = fGeoPoolStateStack.back(); | 267 GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 277 const GrDrawState& drawState = this->getDrawState(); | 268 const GrDrawState& drawState = this->getDrawState(); |
| 278 | 269 |
| 279 this->recordStateIfNecessary(GrGpu::PrimTypeToDrawType(info.primitiveType())
, | 270 this->recordStateIfNecessary(GrGpu::PrimTypeToDrawType(info.primitiveType())
, |
| 280 info.getDstCopy()); | 271 info.getDstCopy()); |
| 281 | 272 |
| 282 const GrVertexBuffer* vb; | 273 const GrVertexBuffer* vb; |
| 283 if (kBuffer_GeometrySrcType == this->getGeomSrc().fVertexSrc) { | 274 if (kBuffer_GeometrySrcType == this->getGeomSrc().fVertexSrc) { |
| 284 vb = this->getGeomSrc().fVertexBuffer; | 275 vb = this->getGeomSrc().fVertexBuffer; |
| 285 } else { | 276 } else { |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 | 796 |
| 806 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { | 797 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
| 807 SkASSERT(!fCmdBuffer.empty()); | 798 SkASSERT(!fCmdBuffer.empty()); |
| 808 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); | 799 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); |
| 809 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); | 800 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 810 if (activeTraceMarkers.count() > 0) { | 801 if (activeTraceMarkers.count() > 0) { |
| 811 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); | 802 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); |
| 812 fGpuCmdMarkers.push_back(activeTraceMarkers); | 803 fGpuCmdMarkers.push_back(activeTraceMarkers); |
| 813 } | 804 } |
| 814 } | 805 } |
| OLD | NEW |