OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrInOrderDrawBuffer.h" | 10 #include "GrInOrderDrawBuffer.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + v
ertexSize); | 70 point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + v
ertexSize); |
71 bounds->growToInclude(point->fX, point->fY); | 71 bounds->growToInclude(point->fX, point->fY); |
72 } | 72 } |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 void GrInOrderDrawBuffer::drawRect(const GrRect& rect, | 76 void GrInOrderDrawBuffer::drawRect(const GrRect& rect, |
77 const SkMatrix* matrix, | 77 const SkMatrix* matrix, |
78 const GrRect* localRect, | 78 const GrRect* localRect, |
79 const SkMatrix* localMatrix) { | 79 const SkMatrix* localMatrix) { |
80 | |
81 GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings; | |
82 GrDrawState::AutoColorRestore acr; | 80 GrDrawState::AutoColorRestore acr; |
83 | 81 |
84 GrDrawState* drawState = this->drawState(); | 82 GrDrawState* drawState = this->drawState(); |
85 | 83 |
86 GrColor color = drawState->getColor(); | 84 GrColor color = drawState->getColor(); |
87 GrVertexAttribArray<3> attribs; | 85 GrVertexAttribArray<3> attribs; |
88 size_t currentOffset = 0; | |
89 int colorOffset = -1, localOffset = -1; | |
90 | 86 |
91 // set position attrib | 87 // set position attrib |
92 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count(
)); | 88 static const GrVertexAttrib kPosAttrib = |
93 GrVertexAttrib currAttrib = {kVec2f_GrVertexAttribType, currentOffset}; | 89 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; |
94 attribs.push_back(currAttrib); | 90 attribs.push_back(kPosAttrib); |
95 currentOffset += sizeof(GrPoint); | 91 |
| 92 size_t currentOffset = sizeof(GrPoint); |
| 93 int colorOffset = -1; |
| 94 int localOffset = -1; |
96 | 95 |
97 // Using per-vertex colors allows batching across colors. (A lot of rects in
a row differing | 96 // Using per-vertex colors allows batching across colors. (A lot of rects in
a row differing |
98 // only in color is a common occurrence in tables). However, having per-vert
ex colors disables | 97 // only in color is a common occurrence in tables). However, having per-vert
ex colors disables |
99 // blending optimizations because we don't know if the color will be solid o
r not. These | 98 // blending optimizations because we don't know if the color will be solid o
r not. These |
100 // optimizations help determine whether coverage and color can be blended co
rrectly when | 99 // optimizations help determine whether coverage and color can be blended co
rrectly when |
101 // dual-source blending isn't available. This comes into play when there is
coverage. If colors | 100 // dual-source blending isn't available. This comes into play when there is
coverage. If colors |
102 // were a stage it could take a hint that every vertex's color will be opaqu
e. | 101 // were a stage it could take a hint that every vertex's color will be opaqu
e. |
103 if (this->caps()->dualSourceBlendingSupport() || | 102 if (this->caps()->dualSourceBlendingSupport() || drawState->hasSolidCoverage
()) { |
104 drawState->hasSolidCoverage(drawState->getAttribBindings())) { | |
105 bindings |= GrDrawState::kColor_AttribBindingsBit; | |
106 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count
()); | |
107 currAttrib.set(kVec4ub_GrVertexAttribType, currentOffset); | |
108 attribs.push_back(currAttrib); | |
109 colorOffset = currentOffset; | 103 colorOffset = currentOffset; |
| 104 GrVertexAttrib colorAttrib = |
| 105 {kVec4ub_GrVertexAttribType, colorOffset, kColor_GrVertexAttribBindi
ng}; |
| 106 attribs.push_back(colorAttrib); |
110 currentOffset += sizeof(GrColor); | 107 currentOffset += sizeof(GrColor); |
111 // We set the draw state's color to white here. This is done so that any
batching performed | 108 // We set the draw state's color to white here. This is done so that any
batching performed |
112 // in our subclass's onDraw() won't get a false from GrDrawState::op== d
ue to a color | 109 // in our subclass's onDraw() won't get a false from GrDrawState::op== d
ue to a color |
113 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should
skip comparing the | 110 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should
skip comparing the |
114 // constant color in its op== when the kColor layout bit is set and then
we can remove this. | 111 // constant color in its op== when the kColor layout bit is set and then
we can remove this. |
115 acr.set(drawState, 0xFFFFFFFF); | 112 acr.set(drawState, 0xFFFFFFFF); |
116 } | 113 } |
117 | 114 |
118 if (NULL != localRect) { | 115 if (NULL != localRect) { |
119 bindings |= GrDrawState::kLocalCoords_AttribBindingsBit; | |
120 drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs
.count()); | |
121 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset); | |
122 attribs.push_back(currAttrib); | |
123 localOffset = currentOffset; | 116 localOffset = currentOffset; |
| 117 GrVertexAttrib localCoordAttrib = |
| 118 {kVec2f_GrVertexAttribType, localOffset, kLocalCoord_GrVertexAttribB
inding}; |
| 119 attribs.push_back(localCoordAttrib); |
124 currentOffset += sizeof(GrPoint); | 120 currentOffset += sizeof(GrPoint); |
125 } | 121 } |
126 | 122 |
127 drawState->setVertexAttribs(attribs.begin(), attribs.count()); | 123 drawState->setVertexAttribs(attribs.begin(), attribs.count()); |
128 drawState->setAttribBindings(bindings); | |
129 AutoReleaseGeometry geo(this, 4, 0); | 124 AutoReleaseGeometry geo(this, 4, 0); |
130 if (!geo.succeeded()) { | 125 if (!geo.succeeded()) { |
131 GrPrintf("Failed to get space for vertices!\n"); | 126 GrPrintf("Failed to get space for vertices!\n"); |
132 return; | 127 return; |
133 } | 128 } |
134 | 129 |
135 // Go to device coords to allow batching across matrix changes | 130 // Go to device coords to allow batching across matrix changes |
136 SkMatrix combinedMatrix; | 131 SkMatrix combinedMatrix; |
137 if (NULL != matrix) { | 132 if (NULL != matrix) { |
138 combinedMatrix = *matrix; | 133 combinedMatrix = *matrix; |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { | 754 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { |
760 fCmds.push_back(kClear_Cmd); | 755 fCmds.push_back(kClear_Cmd); |
761 return &fClears.push_back(); | 756 return &fClears.push_back(); |
762 } | 757 } |
763 | 758 |
764 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { | 759 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
765 INHERITED::clipWillBeSet(newClipData); | 760 INHERITED::clipWillBeSet(newClipData); |
766 fClipSet = true; | 761 fClipSet = true; |
767 fClipProxyState = kUnknown_ClipProxyState; | 762 fClipProxyState = kUnknown_ClipProxyState; |
768 } | 763 } |
OLD | NEW |