| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrAARectRenderer.h" | 8 #include "GrAARectRenderer.h" |
| 9 #include "GrRefCnt.h" | 9 #include "GrRefCnt.h" |
| 10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
| 11 | 11 |
| 12 SK_DEFINE_INST_COUNT(GrAARectRenderer) | 12 SK_DEFINE_INST_COUNT(GrAARectRenderer) |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 static void aa_rect_attributes(bool useCoverage, GrAttribBindings* bindings, | 16 static void aa_rect_attributes(bool useCoverage, const GrVertexAttrib** attribs,
int* count) { |
| 17 GrDrawState::AttribIndex* index) { | 17 static const GrVertexAttrib kCoverageAttribs[] = { |
| 18 if (useCoverage) { | 18 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 19 *bindings = GrDrawState::kCoverage_AttribBindingsBit; | 19 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kCoverage_GrVertexAttribBi
nding}, |
| 20 *index = GrDrawState::kCoverage_AttribIndex; | 20 }; |
| 21 } else { | 21 static const GrVertexAttrib kColorAttribs[] = { |
| 22 *bindings = GrDrawState::kColor_AttribBindingsBit; | 22 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 23 *index = GrDrawState::kColor_AttribIndex; | 23 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBindi
ng}, |
| 24 } | 24 }; |
| 25 *attribs = useCoverage ? kCoverageAttribs : kColorAttribs; |
| 26 *count = 2; |
| 25 } | 27 } |
| 26 | 28 |
| 27 static void set_inset_fan(GrPoint* pts, size_t stride, | 29 static void set_inset_fan(GrPoint* pts, size_t stride, |
| 28 const GrRect& r, SkScalar dx, SkScalar dy) { | 30 const GrRect& r, SkScalar dx, SkScalar dy) { |
| 29 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 31 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
| 30 r.fRight - dx, r.fBottom - dy, stride); | 32 r.fRight - dx, r.fBottom - dy, stride); |
| 31 } | 33 } |
| 32 | 34 |
| 33 }; | 35 }; |
| 34 | 36 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 123 } |
| 122 return fAAStrokeRectIndexBuffer; | 124 return fAAStrokeRectIndexBuffer; |
| 123 } | 125 } |
| 124 | 126 |
| 125 void GrAARectRenderer::fillAARect(GrGpu* gpu, | 127 void GrAARectRenderer::fillAARect(GrGpu* gpu, |
| 126 GrDrawTarget* target, | 128 GrDrawTarget* target, |
| 127 const GrRect& devRect, | 129 const GrRect& devRect, |
| 128 bool useVertexCoverage) { | 130 bool useVertexCoverage) { |
| 129 GrDrawState* drawState = target->drawState(); | 131 GrDrawState* drawState = target->drawState(); |
| 130 | 132 |
| 131 // position + color/coverage | 133 const GrVertexAttrib* attribs; |
| 132 static const GrVertexAttrib kVertexAttribs[] = { | 134 int attribCount; |
| 133 {kVec2f_GrVertexAttribType, 0}, | 135 aa_rect_attributes(useVertexCoverage, &attribs, &attribCount); |
| 134 {kVec4ub_GrVertexAttribType, sizeof(GrPoint)} | 136 drawState->setVertexAttribs(attribs, attribCount); |
| 135 }; | |
| 136 GrAttribBindings bindings; | |
| 137 GrDrawState::AttribIndex attribIndex; | |
| 138 aa_rect_attributes(useVertexCoverage, &bindings, &attribIndex); | |
| 139 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs)); | |
| 140 drawState->setAttribBindings(bindings); | |
| 141 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); | |
| 142 drawState->setAttribIndex(attribIndex, 1); | |
| 143 | 137 |
| 144 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); | 138 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); |
| 145 if (!geo.succeeded()) { | 139 if (!geo.succeeded()) { |
| 146 GrPrintf("Failed to get space for vertices!\n"); | 140 GrPrintf("Failed to get space for vertices!\n"); |
| 147 return; | 141 return; |
| 148 } | 142 } |
| 149 | 143 |
| 150 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu); | 144 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu); |
| 151 if (NULL == indexBuffer) { | 145 if (NULL == indexBuffer) { |
| 152 GrPrintf("Failed to create index buffer!\n"); | 146 GrPrintf("Failed to create index buffer!\n"); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 spare = GrMin(w, h); | 199 spare = GrMin(w, h); |
| 206 } | 200 } |
| 207 | 201 |
| 208 if (spare <= 0) { | 202 if (spare <= 0) { |
| 209 GrRect r(devRect); | 203 GrRect r(devRect); |
| 210 r.inset(-rx, -ry); | 204 r.inset(-rx, -ry); |
| 211 this->fillAARect(gpu, target, r, useVertexCoverage); | 205 this->fillAARect(gpu, target, r, useVertexCoverage); |
| 212 return; | 206 return; |
| 213 } | 207 } |
| 214 | 208 |
| 215 // position + color/coverage | 209 const GrVertexAttrib* attribs; |
| 216 static const GrVertexAttrib kVertexAttribs[] = { | 210 int attribCount; |
| 217 {kVec2f_GrVertexAttribType, 0}, | 211 aa_rect_attributes(useVertexCoverage, &attribs, &attribCount); |
| 218 {kVec4ub_GrVertexAttribType, sizeof(GrPoint)} | 212 drawState->setVertexAttribs(attribs, attribCount); |
| 219 }; | |
| 220 GrAttribBindings bindings; | |
| 221 GrDrawState::AttribIndex attribIndex; | |
| 222 aa_rect_attributes(useVertexCoverage, &bindings, &attribIndex); | |
| 223 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs)); | |
| 224 drawState->setAttribBindings(bindings); | |
| 225 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); | |
| 226 drawState->setAttribIndex(attribIndex, 1); | |
| 227 | 213 |
| 228 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); | 214 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); |
| 229 if (!geo.succeeded()) { | 215 if (!geo.succeeded()) { |
| 230 GrPrintf("Failed to get space for vertices!\n"); | 216 GrPrintf("Failed to get space for vertices!\n"); |
| 231 return; | 217 return; |
| 232 } | 218 } |
| 233 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(gpu); | 219 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(gpu); |
| 234 if (NULL == indexBuffer) { | 220 if (NULL == indexBuffer) { |
| 235 GrPrintf("Failed to create index buffer!\n"); | 221 GrPrintf("Failed to create index buffer!\n"); |
| 236 return; | 222 return; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 // The innermost rect has full coverage | 264 // The innermost rect has full coverage |
| 279 verts += 8 * vsize; | 265 verts += 8 * vsize; |
| 280 for (int i = 0; i < 4; ++i) { | 266 for (int i = 0; i < 4; ++i) { |
| 281 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; | 267 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; |
| 282 } | 268 } |
| 283 | 269 |
| 284 target->setIndexSourceToBuffer(indexBuffer); | 270 target->setIndexSourceToBuffer(indexBuffer); |
| 285 target->drawIndexed(kTriangles_GrPrimitiveType, | 271 target->drawIndexed(kTriangles_GrPrimitiveType, |
| 286 0, 0, 16, aaStrokeRectIndexCount()); | 272 0, 0, 16, aaStrokeRectIndexCount()); |
| 287 } | 273 } |
| OLD | NEW |