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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 const GrPoint* point = static_cast<const GrPoint*>(vertices); | 66 const GrPoint* point = static_cast<const GrPoint*>(vertices); |
67 bounds->fLeft = bounds->fRight = point->fX; | 67 bounds->fLeft = bounds->fRight = point->fX; |
68 bounds->fTop = bounds->fBottom = point->fY; | 68 bounds->fTop = bounds->fBottom = point->fY; |
69 for (int i = 1; i < vertexCount; ++i) { | 69 for (int i = 1; i < vertexCount; ++i) { |
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::onDrawRect(const GrRect& rect, | |
77 const SkMatrix* matrix, | |
78 const GrRect* localRect, | |
79 const SkMatrix* localMatrix) { | |
80 GrDrawState::AutoColorRestore acr; | |
81 | 76 |
82 GrDrawState* drawState = this->drawState(); | 77 namespace { |
83 | 78 |
84 GrColor color = drawState->getColor(); | 79 extern const GrVertexAttrib kRectPosColorUVAttribs[] = { |
85 GrVertexAttribArray<3> attribs; | 80 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, |
| 81 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBinding}, |
| 82 {kVec2f_GrVertexAttribType, sizeof(GrPoint)+sizeof(GrColor), |
| 83 kLocalCoord_GrVertexAttribBind
ing}, |
| 84 }; |
86 | 85 |
87 // set position attrib | 86 extern const GrVertexAttrib kRectPosUVAttribs[] = { |
88 static const GrVertexAttrib kPosAttrib = | 87 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
89 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; | 88 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBindi
ng}, |
90 attribs.push_back(kPosAttrib); | 89 }; |
91 | 90 |
92 size_t currentOffset = sizeof(GrPoint); | 91 static void set_vertex_attributes(GrDrawState* drawState, |
93 int colorOffset = -1; | 92 bool hasColor, bool hasUVs, |
94 int localOffset = -1; | 93 int* colorOffset, int* localOffset) { |
| 94 *colorOffset = -1; |
| 95 *localOffset = -1; |
95 | 96 |
96 // Using per-vertex colors allows batching across colors. (A lot of rects in
a row differing | 97 // Using per-vertex colors allows batching across colors. (A lot of rects in
a row differing |
97 // only in color is a common occurrence in tables). However, having per-vert
ex colors disables | 98 // only in color is a common occurrence in tables). However, having per-vert
ex colors disables |
98 // blending optimizations because we don't know if the color will be solid o
r not. These | 99 // blending optimizations because we don't know if the color will be solid o
r not. These |
99 // optimizations help determine whether coverage and color can be blended co
rrectly when | 100 // optimizations help determine whether coverage and color can be blended co
rrectly when |
100 // dual-source blending isn't available. This comes into play when there is
coverage. If colors | 101 // dual-source blending isn't available. This comes into play when there is
coverage. If colors |
101 // were a stage it could take a hint that every vertex's color will be opaqu
e. | 102 // were a stage it could take a hint that every vertex's color will be opaqu
e. |
102 if (this->caps()->dualSourceBlendingSupport() || drawState->hasSolidCoverage
()) { | 103 if (hasColor && hasUVs) { |
103 colorOffset = currentOffset; | 104 *colorOffset = sizeof(GrPoint); |
104 GrVertexAttrib colorAttrib = | 105 *localOffset = sizeof(GrPoint) + sizeof(GrColor); |
105 {kVec4ub_GrVertexAttribType, currentOffset, kColor_GrVertexAttribBin
ding}; | 106 drawState->setVertexAttribs<kRectPosColorUVAttribs>(3); |
106 attribs.push_back(colorAttrib); | 107 } else if (hasColor) { |
107 currentOffset += sizeof(GrColor); | 108 *colorOffset = sizeof(GrPoint); |
| 109 drawState->setVertexAttribs<kRectPosColorUVAttribs>(2); |
| 110 } else if (hasUVs) { |
| 111 *localOffset = sizeof(GrPoint); |
| 112 drawState->setVertexAttribs<kRectPosUVAttribs>(2); |
| 113 } else { |
| 114 drawState->setVertexAttribs<kRectPosUVAttribs>(1); |
| 115 } |
| 116 } |
| 117 |
| 118 }; |
| 119 |
| 120 void GrInOrderDrawBuffer::onDrawRect(const GrRect& rect, |
| 121 const SkMatrix* matrix, |
| 122 const GrRect* localRect, |
| 123 const SkMatrix* localMatrix) { |
| 124 GrDrawState::AutoColorRestore acr; |
| 125 |
| 126 GrDrawState* drawState = this->drawState(); |
| 127 |
| 128 GrColor color = drawState->getColor(); |
| 129 |
| 130 int colorOffset, localOffset; |
| 131 set_vertex_attributes(drawState, |
| 132 this->caps()->dualSourceBlendingSupport() || drawState->hasSo
lidCoverage(), |
| 133 NULL != localRect, |
| 134 &colorOffset, &localOffset); |
| 135 if (colorOffset >= 0) { |
108 // We set the draw state's color to white here. This is done so that any
batching performed | 136 // We set the draw state's color to white here. This is done so that any
batching performed |
109 // in our subclass's onDraw() won't get a false from GrDrawState::op== d
ue to a color | 137 // in our subclass's onDraw() won't get a false from GrDrawState::op== d
ue to a color |
110 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should
skip comparing the | 138 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should
skip comparing the |
111 // constant color in its op== when the kColor layout bit is set and then
we can remove this. | 139 // constant color in its op== when the kColor layout bit is set and then
we can remove |
| 140 // this. |
112 acr.set(drawState, 0xFFFFFFFF); | 141 acr.set(drawState, 0xFFFFFFFF); |
113 } | 142 } |
114 | 143 |
115 if (NULL != localRect) { | |
116 localOffset = currentOffset; | |
117 GrVertexAttrib localCoordAttrib = | |
118 {kVec2f_GrVertexAttribType, currentOffset, kLocalCoord_GrVertexAttri
bBinding}; | |
119 attribs.push_back(localCoordAttrib); | |
120 currentOffset += sizeof(GrPoint); | |
121 } | |
122 | |
123 drawState->setVertexAttribs(attribs.begin(), attribs.count()); | |
124 AutoReleaseGeometry geo(this, 4, 0); | 144 AutoReleaseGeometry geo(this, 4, 0); |
125 if (!geo.succeeded()) { | 145 if (!geo.succeeded()) { |
126 GrPrintf("Failed to get space for vertices!\n"); | 146 GrPrintf("Failed to get space for vertices!\n"); |
127 return; | 147 return; |
128 } | 148 } |
129 | 149 |
130 // Go to device coords to allow batching across matrix changes | 150 // Go to device coords to allow batching across matrix changes |
131 SkMatrix combinedMatrix; | 151 SkMatrix combinedMatrix; |
132 if (NULL != matrix) { | 152 if (NULL != matrix) { |
133 combinedMatrix = *matrix; | 153 combinedMatrix = *matrix; |
134 } else { | 154 } else { |
135 combinedMatrix.reset(); | 155 combinedMatrix.reset(); |
136 } | 156 } |
137 combinedMatrix.postConcat(drawState->getViewMatrix()); | 157 combinedMatrix.postConcat(drawState->getViewMatrix()); |
138 // When the caller has provided an explicit source rect for a stage then we
don't want to | 158 // When the caller has provided an explicit source rect for a stage then we
don't want to |
139 // modify that stage's matrix. Otherwise if the effect is generating its sou
rce rect from | 159 // modify that stage's matrix. Otherwise if the effect is generating its sou
rce rect from |
140 // the vertex positions then we have to account for the view matrix change. | 160 // the vertex positions then we have to account for the view matrix change. |
141 GrDrawState::AutoDeviceCoordDraw adcd(drawState); | 161 GrDrawState::AutoDeviceCoordDraw adcd(drawState); |
142 if (!adcd.succeeded()) { | 162 if (!adcd.succeeded()) { |
143 return; | 163 return; |
144 } | 164 } |
145 | 165 |
146 size_t vsize = drawState->getVertexSize(); | 166 size_t vsize = drawState->getVertexSize(); |
147 GrAssert(vsize == currentOffset); | |
148 | 167 |
149 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom
, vsize); | 168 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom
, vsize); |
150 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4); | 169 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4); |
151 | 170 |
152 SkRect devBounds; | 171 SkRect devBounds; |
153 // since we already computed the dev verts, set the bounds hint. This will h
elp us avoid | 172 // since we already computed the dev verts, set the bounds hint. This will h
elp us avoid |
154 // unnecessary clipping in our onDraw(). | 173 // unnecessary clipping in our onDraw(). |
155 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds); | 174 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds); |
156 | 175 |
157 if (localOffset >= 0) { | 176 if (localOffset >= 0) { |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 fCmds.push_back(kCopySurface_Cmd); | 816 fCmds.push_back(kCopySurface_Cmd); |
798 return &fCopySurfaces.push_back(); | 817 return &fCopySurfaces.push_back(); |
799 } | 818 } |
800 | 819 |
801 | 820 |
802 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { | 821 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
803 INHERITED::clipWillBeSet(newClipData); | 822 INHERITED::clipWillBeSet(newClipData); |
804 fClipSet = true; | 823 fClipSet = true; |
805 fClipProxyState = kUnknown_ClipProxyState; | 824 fClipProxyState = kUnknown_ClipProxyState; |
806 } | 825 } |
OLD | NEW |