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

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

Issue 14328009: Vertex Attrib configurations now handled as pointers vs. SkSTArrays (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Added "extern const" & removed comment 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
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 GrContext* context, 135 GrContext* context,
136 const GrDrawTargetCaps&, 136 const GrDrawTargetCaps&,
137 GrTexture* textures[]) { 137 GrTexture* textures[]) {
138 return GrRectEffect::Create(); 138 return GrRectEffect::Create();
139 } 139 }
140 140
141 /////////////////////////////////////////////////////////////////////////////// 141 ///////////////////////////////////////////////////////////////////////////////
142 142
143 namespace { 143 namespace {
144 144
145 static void aa_rect_attributes(bool useCoverage, const GrVertexAttrib** attribs, int* count) { 145 extern const GrVertexAttrib gAARectCoverageAttribs[] = {
146 static const GrVertexAttrib kCoverageAttribs[] = { 146 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin g},
147 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, 147 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kCoverage_GrVertexAttribBindin g},
148 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kCoverage_GrVertexAttribBi nding}, 148 };
149 }; 149
150 static const GrVertexAttrib kColorAttribs[] = { 150 extern const GrVertexAttrib gAARectColorAttribs[] = {
151 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, 151 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin g},
152 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBindi ng}, 152 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBinding},
153 }; 153 };
154 *attribs = useCoverage ? kCoverageAttribs : kColorAttribs; 154
155 *count = 2; 155 static void set_aa_rect_vertex_attributes(GrDrawState* drawState, bool useCovera ge) {
156 if (useCoverage) {
157 drawState->setVertexAttribs<gAARectCoverageAttribs>(SK_ARRAY_COUNT(gAARe ctCoverageAttribs));
158 } else {
159 drawState->setVertexAttribs<gAARectColorAttribs>(SK_ARRAY_COUNT(gAARectC olorAttribs));
160 }
156 } 161 }
157 162
158 static void set_inset_fan(GrPoint* pts, size_t stride, 163 static void set_inset_fan(GrPoint* pts, size_t stride,
159 const GrRect& r, SkScalar dx, SkScalar dy) { 164 const GrRect& r, SkScalar dx, SkScalar dy) {
160 pts->setRectFan(r.fLeft + dx, r.fTop + dy, 165 pts->setRectFan(r.fLeft + dx, r.fTop + dy,
161 r.fRight - dx, r.fBottom - dy, stride); 166 r.fRight - dx, r.fBottom - dy, stride);
162 } 167 }
163 168
164 }; 169 };
165 170
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 257 }
253 return fAAStrokeRectIndexBuffer; 258 return fAAStrokeRectIndexBuffer;
254 } 259 }
255 260
256 void GrAARectRenderer::fillAARect(GrGpu* gpu, 261 void GrAARectRenderer::fillAARect(GrGpu* gpu,
257 GrDrawTarget* target, 262 GrDrawTarget* target,
258 const GrRect& devRect, 263 const GrRect& devRect,
259 bool useVertexCoverage) { 264 bool useVertexCoverage) {
260 GrDrawState* drawState = target->drawState(); 265 GrDrawState* drawState = target->drawState();
261 266
262 const GrVertexAttrib* attribs; 267 set_aa_rect_vertex_attributes(drawState, useVertexCoverage);
263 int attribCount;
264 aa_rect_attributes(useVertexCoverage, &attribs, &attribCount);
265 drawState->setVertexAttribs(attribs, attribCount);
266 268
267 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); 269 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0);
268 if (!geo.succeeded()) { 270 if (!geo.succeeded()) {
269 GrPrintf("Failed to get space for vertices!\n"); 271 GrPrintf("Failed to get space for vertices!\n");
270 return; 272 return;
271 } 273 }
272 274
273 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu); 275 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu);
274 if (NULL == indexBuffer) { 276 if (NULL == indexBuffer) {
275 GrPrintf("Failed to create index buffer!\n"); 277 GrPrintf("Failed to create index buffer!\n");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 target->resetIndexSource(); 312 target->resetIndexSource();
311 } 313 }
312 314
313 struct RectVertex { 315 struct RectVertex {
314 GrPoint fPos; 316 GrPoint fPos;
315 GrPoint fCenter; 317 GrPoint fCenter;
316 GrPoint fDir; 318 GrPoint fDir;
317 GrPoint fWidthHeight; 319 GrPoint fWidthHeight;
318 }; 320 };
319 321
322 namespace {
323
324 extern const GrVertexAttrib gAARectVertexAttribs[] = {
325 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind ing },
326 { kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindin g },
327 { kVec2f_GrVertexAttribType, 3*sizeof(GrPoint), kEffect_GrVertexAttribBindin g }
328 };
329
330 };
320 331
321 void GrAARectRenderer::shaderFillAARect(GrGpu* gpu, 332 void GrAARectRenderer::shaderFillAARect(GrGpu* gpu,
322 GrDrawTarget* target, 333 GrDrawTarget* target,
323 const GrRect& rect, 334 const GrRect& rect,
324 const SkMatrix& combinedMatrix, 335 const SkMatrix& combinedMatrix,
325 const GrRect& devRect, 336 const GrRect& devRect,
326 bool useVertexCoverage) { 337 bool useVertexCoverage) {
327 GrDrawState* drawState = target->drawState(); 338 GrDrawState* drawState = target->drawState();
328 339
329 SkPoint center = SkPoint::Make(rect.centerX(), rect.centerY()); 340 SkPoint center = SkPoint::Make(rect.centerX(), rect.centerY());
330 combinedMatrix.mapPoints(&center, 1); 341 combinedMatrix.mapPoints(&center, 1);
331 342
332 // compute transformed (0, 1) vector 343 // compute transformed (0, 1) vector
333 SkVector dir = { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix: :kMScaleY] }; 344 SkVector dir = { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix: :kMScaleY] };
334 dir.normalize(); 345 dir.normalize();
335 346
336 // compute transformed (width, 0) and (0, height) vectors 347 // compute transformed (width, 0) and (0, height) vectors
337 SkVector vec[2] = { 348 SkVector vec[2] = {
338 { combinedMatrix[SkMatrix::kMScaleX] * rect.width(), 349 { combinedMatrix[SkMatrix::kMScaleX] * rect.width(),
339 combinedMatrix[SkMatrix::kMSkewY] * rect.width() }, 350 combinedMatrix[SkMatrix::kMSkewY] * rect.width() },
340 { combinedMatrix[SkMatrix::kMSkewX] * rect.height(), 351 { combinedMatrix[SkMatrix::kMSkewX] * rect.height(),
341 combinedMatrix[SkMatrix::kMScaleY] * rect.height() } 352 combinedMatrix[SkMatrix::kMScaleY] * rect.height() }
342 }; 353 };
343 354
344 SkScalar newWidth = vec[0].length() / 2.0f + 0.5f; 355 SkScalar newWidth = vec[0].length() / 2.0f + 0.5f;
345 SkScalar newHeight = vec[1].length() / 2.0f + 0.5f; 356 SkScalar newHeight = vec[1].length() / 2.0f + 0.5f;
346 357
347 static const GrVertexAttrib kVertexAttribs[] = { 358 drawState->setVertexAttribs<gAARectVertexAttribs>(SK_ARRAY_COUNT(gAARectVert exAttribs));
348 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
349 { kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBind ing },
350 { kVec2f_GrVertexAttribType, 3*sizeof(GrPoint), kEffect_GrVertexAttribBi nding }
351 };
352 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
353 GrAssert(sizeof(RectVertex) == drawState->getVertexSize()); 359 GrAssert(sizeof(RectVertex) == drawState->getVertexSize());
354 360
355 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); 361 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
356 if (!geo.succeeded()) { 362 if (!geo.succeeded()) {
357 GrPrintf("Failed to get space for vertices!\n"); 363 GrPrintf("Failed to get space for vertices!\n");
358 return; 364 return;
359 } 365 }
360 366
361 RectVertex* verts = reinterpret_cast<RectVertex*>(geo.vertices()); 367 RectVertex* verts = reinterpret_cast<RectVertex*>(geo.vertices());
362 368
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 spare = GrMin(w, h); 421 spare = GrMin(w, h);
416 } 422 }
417 423
418 if (spare <= 0) { 424 if (spare <= 0) {
419 GrRect r(devRect); 425 GrRect r(devRect);
420 r.inset(-rx, -ry); 426 r.inset(-rx, -ry);
421 this->fillAARect(gpu, target, r, useVertexCoverage); 427 this->fillAARect(gpu, target, r, useVertexCoverage);
422 return; 428 return;
423 } 429 }
424 430
425 const GrVertexAttrib* attribs; 431 set_aa_rect_vertex_attributes(drawState, useVertexCoverage);
426 int attribCount;
427 aa_rect_attributes(useVertexCoverage, &attribs, &attribCount);
428 drawState->setVertexAttribs(attribs, attribCount);
429 432
430 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); 433 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0);
431 if (!geo.succeeded()) { 434 if (!geo.succeeded()) {
432 GrPrintf("Failed to get space for vertices!\n"); 435 GrPrintf("Failed to get space for vertices!\n");
433 return; 436 return;
434 } 437 }
435 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(gpu); 438 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(gpu);
436 if (NULL == indexBuffer) { 439 if (NULL == indexBuffer) {
437 GrPrintf("Failed to create index buffer!\n"); 440 GrPrintf("Failed to create index buffer!\n");
438 return; 441 return;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 // The innermost rect has full coverage 483 // The innermost rect has full coverage
481 verts += 8 * vsize; 484 verts += 8 * vsize;
482 for (int i = 0; i < 4; ++i) { 485 for (int i = 0; i < 4; ++i) {
483 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; 486 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
484 } 487 }
485 488
486 target->setIndexSourceToBuffer(indexBuffer); 489 target->setIndexSourceToBuffer(indexBuffer);
487 target->drawIndexed(kTriangles_GrPrimitiveType, 490 target->drawIndexed(kTriangles_GrPrimitiveType,
488 0, 0, 16, aaStrokeRectIndexCount()); 491 0, 0, 16, aaStrokeRectIndexCount());
489 } 492 }
OLDNEW
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698