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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const SkPoint* point = static_cast<const SkPoint*>(vertices); | 65 const SkPoint* point = static_cast<const SkPoint*>(vertices); |
65 bounds->fLeft = bounds->fRight = point->fX; | 66 bounds->fLeft = bounds->fRight = point->fX; |
66 bounds->fTop = bounds->fBottom = point->fY; | 67 bounds->fTop = bounds->fBottom = point->fY; |
67 for (int i = 1; i < vertexCount; ++i) { | 68 for (int i = 1; i < vertexCount; ++i) { |
68 point = reinterpret_cast<SkPoint*>(reinterpret_cast<intptr_t>(point) + v
ertexSize); | 69 point = reinterpret_cast<SkPoint*>(reinterpret_cast<intptr_t>(point) + v
ertexSize); |
69 bounds->growToInclude(point->fX, point->fY); | 70 bounds->growToInclude(point->fX, point->fY); |
70 } | 71 } |
71 } | 72 } |
72 } | 73 } |
73 | 74 |
74 | |
75 namespace { | |
76 | |
77 extern const GrVertexAttrib kRectAttribs[] = { | |
78 {kVec2f_GrVertexAttribType, 0, kPosition_GrVe
rtexAttribBinding}, | |
79 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVerte
xAttribBinding}, | |
80 {kVec2f_GrVertexAttribType, sizeof(SkPoint)+sizeof(GrColor), kLocalCoord_Gr
VertexAttribBinding}, | |
81 }; | |
82 } | |
83 | |
84 /** We always use per-vertex colors so that rects can be batched across color ch
anges. Sometimes we | 75 /** We always use per-vertex colors so that rects can be batched across color ch
anges. Sometimes we |
85 have explicit local coords and sometimes not. We *could* always provide expl
icit local coords | 76 have explicit local coords and sometimes not. We *could* always provide expl
icit local coords |
86 and just duplicate the positions when the caller hasn't provided a local coo
rd rect, but we | 77 and just duplicate the positions when the caller hasn't provided a local coo
rd rect, but we |
87 haven't seen a use case which frequently switches between local rect and no
local rect draws. | 78 haven't seen a use case which frequently switches between local rect and no
local rect draws. |
88 | 79 |
89 The color param is used to determine whether the opaque hint can be set on t
he draw state. | 80 The color param is used to determine whether the opaque hint can be set on t
he draw state. |
90 The caller must populate the vertex colors itself. | 81 The caller must populate the vertex colors itself. |
91 | 82 |
92 The vertex attrib order is always pos, color, [local coords]. | 83 The vertex attrib order is always pos, color, [local coords]. |
93 */ | 84 */ |
94 static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G
rColor color) { | 85 static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G
rColor color) { |
95 if (hasLocalCoords) { | 86 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
96 drawState->setVertexAttribs<kRectAttribs>(3, 2 * sizeof(SkPoint) + sizeo
f(SkColor)); | 87 GrDefaultGeoProcFactory::kColor_GPType; |
97 } else { | 88 flags |= hasLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; |
98 drawState->setVertexAttribs<kRectAttribs>(2, sizeof(SkPoint) + sizeof(Sk
Color)); | 89 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::CreateAndSetAttribs
(drawState, |
99 } | 90
flags))->unref(); |
100 if (0xFF == GrColorUnpackA(color)) { | 91 if (0xFF == GrColorUnpackA(color)) { |
101 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | 92 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
102 } | 93 } |
103 } | 94 } |
104 | 95 |
105 enum { | 96 enum { |
106 kTraceCmdBit = 0x80, | 97 kTraceCmdBit = 0x80, |
107 kCmdMask = 0x7f, | 98 kCmdMask = 0x7f, |
108 }; | 99 }; |
109 | 100 |
110 static inline uint8_t add_trace_bit(uint8_t cmd) { return cmd | kTraceCmdBit; } | 101 static inline uint8_t add_trace_bit(uint8_t cmd) { return cmd | kTraceCmdBit; } |
111 | 102 |
112 static inline uint8_t strip_trace_bit(uint8_t cmd) { return cmd & kCmdMask; } | 103 static inline uint8_t strip_trace_bit(uint8_t cmd) { return cmd & kCmdMask; } |
113 | 104 |
114 static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTr
aceCmdBit); } | 105 static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTr
aceCmdBit); } |
115 | 106 |
116 void GrInOrderDrawBuffer::onDrawRect(const SkRect& rect, | 107 void GrInOrderDrawBuffer::onDrawRect(const SkRect& rect, |
117 const SkRect* localRect, | 108 const SkRect* localRect, |
118 const SkMatrix* localMatrix) { | 109 const SkMatrix* localMatrix) { |
119 GrDrawState* drawState = this->drawState(); | 110 GrDrawState* drawState = this->drawState(); |
| 111 GrDrawState::AutoRestoreEffects are(drawState); |
120 | 112 |
121 GrColor color = drawState->getColor(); | 113 GrColor color = drawState->getColor(); |
122 | 114 |
123 set_vertex_attributes(drawState, SkToBool(localRect), color); | 115 set_vertex_attributes(drawState, SkToBool(localRect), color); |
124 | 116 |
125 AutoReleaseGeometry geo(this, 4, 0); | 117 AutoReleaseGeometry geo(this, 4, 0); |
126 if (!geo.succeeded()) { | 118 if (!geo.succeeded()) { |
127 SkDebugf("Failed to get space for vertices!\n"); | 119 SkDebugf("Failed to get space for vertices!\n"); |
128 return; | 120 return; |
129 } | 121 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); | 228 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); |
237 draw->fType = add_trace_bit(draw->fType); | 229 draw->fType = add_trace_bit(draw->fType); |
238 } | 230 } |
239 } | 231 } |
240 | 232 |
241 return instancesToConcat; | 233 return instancesToConcat; |
242 } | 234 } |
243 | 235 |
244 void GrInOrderDrawBuffer::onDraw(const DrawInfo& info, | 236 void GrInOrderDrawBuffer::onDraw(const DrawInfo& info, |
245 const GrClipMaskManager::ScissorState& scissorS
tate) { | 237 const GrClipMaskManager::ScissorState& scissorS
tate) { |
246 | |
247 GeometryPoolState& poolState = fGeoPoolStateStack.back(); | 238 GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
248 const GrDrawState& drawState = this->getDrawState(); | 239 const GrDrawState& drawState = this->getDrawState(); |
249 | 240 |
250 this->recordStateIfNecessary(GrGpu::PrimTypeToDrawType(info.primitiveType())
, | 241 this->recordStateIfNecessary(GrGpu::PrimTypeToDrawType(info.primitiveType())
, |
251 info.getDstCopy()); | 242 info.getDstCopy()); |
252 | 243 |
253 const GrVertexBuffer* vb; | 244 const GrVertexBuffer* vb; |
254 if (kBuffer_GeometrySrcType == this->getGeomSrc().fVertexSrc) { | 245 if (kBuffer_GeometrySrcType == this->getGeomSrc().fVertexSrc) { |
255 vb = this->getGeomSrc().fVertexBuffer; | 246 vb = this->getGeomSrc().fVertexBuffer; |
256 } else { | 247 } else { |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 739 |
749 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { | 740 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
750 SkASSERT(!fCmdBuffer.empty()); | 741 SkASSERT(!fCmdBuffer.empty()); |
751 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); | 742 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); |
752 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); | 743 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
753 if (activeTraceMarkers.count() > 0) { | 744 if (activeTraceMarkers.count() > 0) { |
754 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); | 745 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); |
755 fGpuCmdMarkers.push_back(activeTraceMarkers); | 746 fGpuCmdMarkers.push_back(activeTraceMarkers); |
756 } | 747 } |
757 } | 748 } |
OLD | NEW |