diff options
Diffstat (limited to 'src/gpu/GrAARectRenderer.cpp')
-rw-r--r-- | src/gpu/GrAARectRenderer.cpp | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp index d23c4b4496..741b83d080 100644 --- a/src/gpu/GrAARectRenderer.cpp +++ b/src/gpu/GrAARectRenderer.cpp @@ -13,14 +13,15 @@ SK_DEFINE_INST_COUNT(GrAARectRenderer) namespace { -static GrVertexLayout aa_rect_layout(bool useCoverage) { - GrVertexLayout layout = 0; +static void aa_rect_attributes(bool useCoverage, GrAttribBindings* bindings, + GrDrawState::AttribIndex* index) { if (useCoverage) { - layout |= GrDrawState::kCoverage_VertexLayoutBit; + *bindings = GrDrawState::kCoverage_AttribBindingsBit; + *index = GrDrawState::kCoverage_AttribIndex; } else { - layout |= GrDrawState::kColor_VertexLayoutBit; + *bindings = GrDrawState::kColor_AttribBindingsBit; + *index = GrDrawState::kColor_AttribIndex; } - return layout; } static void set_inset_fan(GrPoint* pts, size_t stride, @@ -29,6 +30,12 @@ static void set_inset_fan(GrPoint* pts, size_t stride, r.fRight - dx, r.fBottom - dy, stride); } +// position + color/coverage +static const GrVertexAttrib kVertexAttribs[] = { + GrVertexAttrib(kVec2f_GrVertexAttribType, 0), + GrVertexAttrib(kVec4ub_GrVertexAttribType, sizeof(GrPoint)) +}; + }; void GrAARectRenderer::reset() { @@ -125,8 +132,15 @@ void GrAARectRenderer::fillAARect(GrGpu* gpu, GrDrawTarget* target, const GrRect& devRect, bool useVertexCoverage) { - GrVertexLayout layout = aa_rect_layout(useVertexCoverage); - target->drawState()->setVertexLayout(layout); + GrDrawState* drawState = target->drawState(); + + GrAttribBindings bindings; + GrDrawState::AttribIndex attribIndex; + aa_rect_attributes(useVertexCoverage, &bindings, &attribIndex); + drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs)); + drawState->setAttribBindings(bindings); + drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); + drawState->setAttribIndex(attribIndex, 1); GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); if (!geo.succeeded()) { @@ -141,7 +155,8 @@ void GrAARectRenderer::fillAARect(GrGpu* gpu, } intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); - size_t vsize = target->getDrawState().getVertexSize(); + size_t vsize = drawState->getVertexSize(); + GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize); GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); @@ -177,6 +192,8 @@ void GrAARectRenderer::strokeAARect(GrGpu* gpu, const GrRect& devRect, const GrVec& devStrokeSize, bool useVertexCoverage) { + GrDrawState* drawState = target->drawState(); + const SkScalar& dx = devStrokeSize.fX; const SkScalar& dy = devStrokeSize.fY; const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf); @@ -195,8 +212,14 @@ void GrAARectRenderer::strokeAARect(GrGpu* gpu, this->fillAARect(gpu, target, r, useVertexCoverage); return; } - GrVertexLayout layout = aa_rect_layout(useVertexCoverage); - target->drawState()->setVertexLayout(layout); + + GrAttribBindings bindings; + GrDrawState::AttribIndex attribIndex; + aa_rect_attributes(useVertexCoverage, &bindings, &attribIndex); + drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs)); + drawState->setAttribBindings(bindings); + drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); + drawState->setAttribIndex(attribIndex, 1); GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); if (!geo.succeeded()) { @@ -210,7 +233,8 @@ void GrAARectRenderer::strokeAARect(GrGpu* gpu, } intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); - size_t vsize = target->getDrawState().getVertexSize(); + size_t vsize = drawState->getVertexSize(); + GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize); // We create vertices for four nested rectangles. There are two ramps from 0 to full // coverage, one on the exterior of the stroke and the other on the interior. |