Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: src/gpu/GrOvalRenderer.cpp

Issue 13296005: Revise attribute binding interface (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 SkRect xformedRect; 174 SkRect xformedRect;
177 vm.mapRect(&xformedRect, ellipse); 175 vm.mapRect(&xformedRect, ellipse);
178 176
179 GrDrawState::AutoDeviceCoordDraw adcd(drawState); 177 GrDrawState::AutoDeviceCoordDraw adcd(drawState);
180 if (!adcd.succeeded()) { 178 if (!adcd.succeeded()) {
181 return; 179 return;
182 } 180 }
183 181
184 // position + edge 182 // position + edge
185 static const GrVertexAttrib kVertexAttribs[] = { 183 static const GrVertexAttrib kVertexAttribs[] = {
186 {kVec2f_GrVertexAttribType, 0}, 184 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
187 {kVec2f_GrVertexAttribType, sizeof(GrPoint)}, 185 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindi ng},
188 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint)} 186 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBin ding}
189 }; 187 };
190 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs)); 188 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
191 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
192 GrAssert(sizeof(EllipseVertex) == drawState->getVertexSize()); 189 GrAssert(sizeof(EllipseVertex) == drawState->getVertexSize());
193 190
194 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); 191 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
195 if (!geo.succeeded()) { 192 if (!geo.succeeded()) {
196 GrPrintf("Failed to get space for vertices!\n"); 193 GrPrintf("Failed to get space for vertices!\n");
197 return; 194 return;
198 } 195 }
199 196
200 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); 197 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices());
201 198
202 SkStrokeRec::Style style = stroke.getStyle(); 199 SkStrokeRec::Style style = stroke.getStyle();
203 bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairl ine_Style == style); 200 bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairl ine_Style == style);
204 enum { 201 enum {
205 // the edge effects share this stage with glyph rendering 202 // the edge effects share this stage with glyph rendering
206 // (kGlyphMaskStage in GrTextContext) && SW path rendering 203 // (kGlyphMaskStage in GrTextContext) && SW path rendering
207 // (kPathMaskStage in GrSWMaskHelper) 204 // (kPathMaskStage in GrSWMaskHelper)
208 kEdgeEffectStage = GrPaint::kTotalStages, 205 kEdgeEffectStage = GrPaint::kTotalStages,
209 }; 206 };
210 drawState->setAttribBindings(GrDrawState::kDefault_AttribBindings);
211 207
212 GrEffectRef* effect = GrEllipseEdgeEffect::Create(isStroked); 208 GrEffectRef* effect = GrEllipseEdgeEffect::Create(isStroked);
213 static const int kEllipseCenterAttrIndex = 1; 209 static const int kEllipseCenterAttrIndex = 1;
214 static const int kEllipseEdgeAttrIndex = 2; 210 static const int kEllipseEdgeAttrIndex = 2;
215 drawState->setEffect(kEdgeEffectStage, effect, 211 drawState->setEffect(kEdgeEffectStage, effect,
216 kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref( ); 212 kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref( );
217 213
218 SkScalar xRadius = SkScalarHalf(xformedRect.width()); 214 SkScalar xRadius = SkScalarHalf(xformedRect.width());
219 SkScalar yRadius = SkScalarHalf(xformedRect.height()); 215 SkScalar yRadius = SkScalarHalf(xformedRect.height());
220 SkScalar innerXRadius = 0.0f; 216 SkScalar innerXRadius = 0.0f;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 T += center.fY - SK_ScalarHalf; 264 T += center.fY - SK_ScalarHalf;
269 B += center.fY + SK_ScalarHalf; 265 B += center.fY + SK_ScalarHalf;
270 266
271 verts[0].fPos = SkPoint::Make(L, T); 267 verts[0].fPos = SkPoint::Make(L, T);
272 verts[1].fPos = SkPoint::Make(R, T); 268 verts[1].fPos = SkPoint::Make(R, T);
273 verts[2].fPos = SkPoint::Make(L, B); 269 verts[2].fPos = SkPoint::Make(L, B);
274 verts[3].fPos = SkPoint::Make(R, B); 270 verts[3].fPos = SkPoint::Make(R, B);
275 271
276 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4); 272 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4);
277 } 273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698