| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrOvalRenderer.h" | 8 #include "GrOvalRenderer.h" |
| 9 | 9 |
| 10 #include "effects/GrCircleEdgeEffect.h" | 10 #include "effects/GrCircleEdgeEffect.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); | 78 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); |
| 79 SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); | 79 SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); |
| 80 | 80 |
| 81 GrDrawState::AutoDeviceCoordDraw adcd(drawState); | 81 GrDrawState::AutoDeviceCoordDraw adcd(drawState); |
| 82 if (!adcd.succeeded()) { | 82 if (!adcd.succeeded()) { |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // position + edge | 86 // position + edge |
| 87 static const GrVertexAttrib kVertexAttribs[] = { | 87 static const GrVertexAttrib kVertexAttribs[] = { |
| 88 {kVec2f_GrVertexAttribType, 0}, | 88 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 89 {kVec4f_GrVertexAttribType, sizeof(GrPoint)} | 89 {kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindi
ng} |
| 90 }; | 90 }; |
| 91 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs)); | 91 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs)); |
| 92 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); | |
| 93 GrAssert(sizeof(CircleVertex) == drawState->getVertexSize()); | 92 GrAssert(sizeof(CircleVertex) == drawState->getVertexSize()); |
| 94 | 93 |
| 95 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); | 94 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 96 if (!geo.succeeded()) { | 95 if (!geo.succeeded()) { |
| 97 GrPrintf("Failed to get space for vertices!\n"); | 96 GrPrintf("Failed to get space for vertices!\n"); |
| 98 return; | 97 return; |
| 99 } | 98 } |
| 100 | 99 |
| 101 CircleVertex* verts = reinterpret_cast<CircleVertex*>(geo.vertices()); | 100 CircleVertex* verts = reinterpret_cast<CircleVertex*>(geo.vertices()); |
| 102 | 101 |
| 103 SkStrokeRec::Style style = stroke.getStyle(); | 102 SkStrokeRec::Style style = stroke.getStyle(); |
| 104 bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairl
ine_Style == style); | 103 bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairl
ine_Style == style); |
| 105 enum { | 104 enum { |
| 106 // the edge effects share this stage with glyph rendering | 105 // the edge effects share this stage with glyph rendering |
| 107 // (kGlyphMaskStage in GrTextContext) && SW path rendering | 106 // (kGlyphMaskStage in GrTextContext) && SW path rendering |
| 108 // (kPathMaskStage in GrSWMaskHelper) | 107 // (kPathMaskStage in GrSWMaskHelper) |
| 109 kEdgeEffectStage = GrPaint::kTotalStages, | 108 kEdgeEffectStage = GrPaint::kTotalStages, |
| 110 }; | 109 }; |
| 111 drawState->setAttribBindings(GrDrawState::kDefault_AttribBindings); | |
| 112 | 110 |
| 113 GrEffectRef* effect = GrCircleEdgeEffect::Create(isStroked); | 111 GrEffectRef* effect = GrCircleEdgeEffect::Create(isStroked); |
| 114 static const int kCircleEdgeAttrIndex = 1; | 112 static const int kCircleEdgeAttrIndex = 1; |
| 115 drawState->setEffect(kEdgeEffectStage, effect, kCircleEdgeAttrIndex)->unref(
); | 113 drawState->setEffect(kEdgeEffectStage, effect, kCircleEdgeAttrIndex)->unref(
); |
| 116 | 114 |
| 117 SkScalar innerRadius = 0.0f; | 115 SkScalar innerRadius = 0.0f; |
| 118 SkScalar outerRadius = radius; | 116 SkScalar outerRadius = radius; |
| 119 SkScalar halfWidth = 0; | 117 SkScalar halfWidth = 0; |
| 120 if (style != SkStrokeRec::kFill_Style) { | 118 if (style != SkStrokeRec::kFill_Style) { |
| 121 if (SkScalarNearlyZero(strokeWidth)) { | 119 if (SkScalarNearlyZero(strokeWidth)) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 SkRect xformedRect; | 171 SkRect xformedRect; |
| 174 vm.mapRect(&xformedRect, ellipse); | 172 vm.mapRect(&xformedRect, ellipse); |
| 175 | 173 |
| 176 GrDrawState::AutoDeviceCoordDraw adcd(drawState); | 174 GrDrawState::AutoDeviceCoordDraw adcd(drawState); |
| 177 if (!adcd.succeeded()) { | 175 if (!adcd.succeeded()) { |
| 178 return; | 176 return; |
| 179 } | 177 } |
| 180 | 178 |
| 181 // position + edge | 179 // position + edge |
| 182 static const GrVertexAttrib kVertexAttribs[] = { | 180 static const GrVertexAttrib kVertexAttribs[] = { |
| 183 {kVec2f_GrVertexAttribType, 0}, | 181 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 184 {kVec2f_GrVertexAttribType, sizeof(GrPoint)}, | 182 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindi
ng}, |
| 185 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint)} | 183 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBin
ding} |
| 186 }; | 184 }; |
| 187 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs)); | 185 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs)); |
| 188 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); | |
| 189 GrAssert(sizeof(EllipseVertex) == drawState->getVertexSize()); | 186 GrAssert(sizeof(EllipseVertex) == drawState->getVertexSize()); |
| 190 | 187 |
| 191 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); | 188 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 192 if (!geo.succeeded()) { | 189 if (!geo.succeeded()) { |
| 193 GrPrintf("Failed to get space for vertices!\n"); | 190 GrPrintf("Failed to get space for vertices!\n"); |
| 194 return; | 191 return; |
| 195 } | 192 } |
| 196 | 193 |
| 197 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); | 194 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); |
| 198 | 195 |
| 199 SkStrokeRec::Style style = stroke.getStyle(); | 196 SkStrokeRec::Style style = stroke.getStyle(); |
| 200 bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairl
ine_Style == style); | 197 bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairl
ine_Style == style); |
| 201 enum { | 198 enum { |
| 202 // the edge effects share this stage with glyph rendering | 199 // the edge effects share this stage with glyph rendering |
| 203 // (kGlyphMaskStage in GrTextContext) && SW path rendering | 200 // (kGlyphMaskStage in GrTextContext) && SW path rendering |
| 204 // (kPathMaskStage in GrSWMaskHelper) | 201 // (kPathMaskStage in GrSWMaskHelper) |
| 205 kEdgeEffectStage = GrPaint::kTotalStages, | 202 kEdgeEffectStage = GrPaint::kTotalStages, |
| 206 }; | 203 }; |
| 207 drawState->setAttribBindings(GrDrawState::kDefault_AttribBindings); | |
| 208 | 204 |
| 209 GrEffectRef* effect = GrEllipseEdgeEffect::Create(isStroked); | 205 GrEffectRef* effect = GrEllipseEdgeEffect::Create(isStroked); |
| 210 static const int kEllipseCenterAttrIndex = 1; | 206 static const int kEllipseCenterAttrIndex = 1; |
| 211 static const int kEllipseEdgeAttrIndex = 2; | 207 static const int kEllipseEdgeAttrIndex = 2; |
| 212 drawState->setEffect(kEdgeEffectStage, effect, | 208 drawState->setEffect(kEdgeEffectStage, effect, |
| 213 kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref(
); | 209 kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref(
); |
| 214 | 210 |
| 215 SkScalar xRadius = SkScalarHalf(xformedRect.width()); | 211 SkScalar xRadius = SkScalarHalf(xformedRect.width()); |
| 216 SkScalar yRadius = SkScalarHalf(xformedRect.height()); | 212 SkScalar yRadius = SkScalarHalf(xformedRect.height()); |
| 217 SkScalar innerXRadius = 0.0f; | 213 SkScalar innerXRadius = 0.0f; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 T += center.fY - SK_ScalarHalf; | 261 T += center.fY - SK_ScalarHalf; |
| 266 B += center.fY + SK_ScalarHalf; | 262 B += center.fY + SK_ScalarHalf; |
| 267 | 263 |
| 268 verts[0].fPos = SkPoint::Make(L, T); | 264 verts[0].fPos = SkPoint::Make(L, T); |
| 269 verts[1].fPos = SkPoint::Make(R, T); | 265 verts[1].fPos = SkPoint::Make(R, T); |
| 270 verts[2].fPos = SkPoint::Make(L, B); | 266 verts[2].fPos = SkPoint::Make(L, B); |
| 271 verts[3].fPos = SkPoint::Make(R, B); | 267 verts[3].fPos = SkPoint::Make(R, B); |
| 272 | 268 |
| 273 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4); | 269 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4); |
| 274 } | 270 } |
| OLD | NEW |