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

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

Issue 13925015: Disable GPU acceleration for narrow ovals (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
« no previous file with comments | « include/gpu/GrOvalRenderer.h ('k') | no next file » | 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 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 "GrEffect.h" 10 #include "GrEffect.h"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 290
291 const SkMatrix& vm = context->getMatrix(); 291 const SkMatrix& vm = context->getMatrix();
292 292
293 // we can draw circles 293 // we can draw circles
294 if (SkScalarNearlyEqual(oval.width(), oval.height()) 294 if (SkScalarNearlyEqual(oval.width(), oval.height())
295 && circle_stays_circle(vm)) { 295 && circle_stays_circle(vm)) {
296 drawCircle(target, paint, oval, stroke); 296 drawCircle(target, paint, oval, stroke);
297 297
298 // and axis-aligned ellipses only 298 // and axis-aligned ellipses only
299 } else if (vm.rectStaysRect()) { 299 } else if (vm.rectStaysRect()) {
300 drawEllipse(target, paint, oval, stroke); 300 return drawEllipse(target, paint, oval, stroke);
301 301
302 } else { 302 } else {
303 return false; 303 return false;
304 } 304 }
305 305
306 return true; 306 return true;
307 } 307 }
308 308
309 void GrOvalRenderer::drawCircle(GrDrawTarget* target, 309 void GrOvalRenderer::drawCircle(GrDrawTarget* target,
310 const GrPaint& paint, 310 const GrPaint& paint,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 verts[2].fInnerRadius = innerRadius; 399 verts[2].fInnerRadius = innerRadius;
400 400
401 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); 401 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom);
402 verts[3].fOffset = SkPoint::Make(outerRadius, outerRadius); 402 verts[3].fOffset = SkPoint::Make(outerRadius, outerRadius);
403 verts[3].fOuterRadius = outerRadius; 403 verts[3].fOuterRadius = outerRadius;
404 verts[3].fInnerRadius = innerRadius; 404 verts[3].fInnerRadius = innerRadius;
405 405
406 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); 406 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds);
407 } 407 }
408 408
409 void GrOvalRenderer::drawEllipse(GrDrawTarget* target, 409 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target,
410 const GrPaint& paint, 410 const GrPaint& paint,
411 const GrRect& ellipse, 411 const GrRect& ellipse,
412 const SkStrokeRec& stroke) 412 const SkStrokeRec& stroke)
413 { 413 {
414 GrDrawState* drawState = target->drawState(); 414 GrDrawState* drawState = target->drawState();
415 #ifdef SK_DEBUG 415 #ifdef SK_DEBUG
416 { 416 {
417 // we should have checked for this previously 417 // we should have checked for this previously
418 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); 418 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect();
419 SkASSERT(paint.isAntiAlias() && isAxisAlignedEllipse); 419 SkASSERT(paint.isAntiAlias() && isAxisAlignedEllipse);
420 } 420 }
421 #endif 421 #endif
422 422
423 const SkMatrix& vm = drawState->getViewMatrix(); 423 const SkMatrix& vm = drawState->getViewMatrix();
424 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); 424 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY());
425 vm.mapPoints(&center, 1); 425 vm.mapPoints(&center, 1);
426 SkRect xformedRect; 426 SkRect xformedRect;
427 vm.mapRect(&xformedRect, ellipse); 427 vm.mapRect(&xformedRect, ellipse);
428 SkScalar xRadius = SkScalarHalf(xformedRect.width());
429 SkScalar yRadius = SkScalarHalf(xformedRect.height());
430 if (SkScalarDiv(xRadius, yRadius) > 2 || SkScalarDiv(yRadius, xRadius) > 2) {
431 return false;
432 }
428 433
429 GrDrawState::AutoDeviceCoordDraw adcd(drawState); 434 GrDrawState::AutoDeviceCoordDraw adcd(drawState);
430 if (!adcd.succeeded()) { 435 if (!adcd.succeeded()) {
431 return; 436 return false;
432 } 437 }
433 438
434 // position + edge 439 // position + edge
435 static const GrVertexAttrib kVertexAttribs[] = { 440 static const GrVertexAttrib kVertexAttribs[] = {
436 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, 441 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
437 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindi ng}, 442 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindi ng},
438 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBin ding} 443 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBin ding}
439 }; 444 };
440 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs)); 445 drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
441 GrAssert(sizeof(EllipseVertex) == drawState->getVertexSize()); 446 GrAssert(sizeof(EllipseVertex) == drawState->getVertexSize());
442 447
443 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); 448 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
444 if (!geo.succeeded()) { 449 if (!geo.succeeded()) {
445 GrPrintf("Failed to get space for vertices!\n"); 450 GrPrintf("Failed to get space for vertices!\n");
446 return; 451 return false;
447 } 452 }
448 453
449 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); 454 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices());
450 455
451 SkStrokeRec::Style style = stroke.getStyle(); 456 SkStrokeRec::Style style = stroke.getStyle();
452 bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairl ine_Style == style); 457 bool isStroked = (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairl ine_Style == style);
453 enum { 458 enum {
454 // the edge effects share this stage with glyph rendering 459 // the edge effects share this stage with glyph rendering
455 // (kGlyphMaskStage in GrTextContext) && SW path rendering 460 // (kGlyphMaskStage in GrTextContext) && SW path rendering
456 // (kPathMaskStage in GrSWMaskHelper) 461 // (kPathMaskStage in GrSWMaskHelper)
457 kEdgeEffectStage = GrPaint::kTotalStages, 462 kEdgeEffectStage = GrPaint::kTotalStages,
458 }; 463 };
459 464
460 GrEffectRef* effect = EllipseEdgeEffect::Create(isStroked); 465 GrEffectRef* effect = EllipseEdgeEffect::Create(isStroked);
461 static const int kEllipseCenterAttrIndex = 1; 466 static const int kEllipseCenterAttrIndex = 1;
462 static const int kEllipseEdgeAttrIndex = 2; 467 static const int kEllipseEdgeAttrIndex = 2;
463 drawState->setEffect(kEdgeEffectStage, effect, 468 drawState->setEffect(kEdgeEffectStage, effect,
464 kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref( ); 469 kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref( );
465 470
466 SkScalar xRadius = SkScalarHalf(xformedRect.width());
467 SkScalar yRadius = SkScalarHalf(xformedRect.height());
468 SkScalar innerXRadius = 0.0f; 471 SkScalar innerXRadius = 0.0f;
469 SkScalar innerRatio = 1.0f; 472 SkScalar innerRatio = 1.0f;
470 473
471 if (SkStrokeRec::kFill_Style != style) { 474 if (SkStrokeRec::kFill_Style != style) {
472 SkScalar strokeWidth = stroke.getWidth(); 475 SkScalar strokeWidth = stroke.getWidth();
473 476
474 // do (potentially) anisotropic mapping 477 // do (potentially) anisotropic mapping
475 SkVector scaledStroke; 478 SkVector scaledStroke;
476 scaledStroke.set(strokeWidth, strokeWidth); 479 scaledStroke.set(strokeWidth, strokeWidth);
477 vm.mapVectors(&scaledStroke, 1); 480 vm.mapVectors(&scaledStroke, 1);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 verts[2].fOuterOffset = SkPoint::Make(-xRadius, outerRatio*yRadius); 534 verts[2].fOuterOffset = SkPoint::Make(-xRadius, outerRatio*yRadius);
532 verts[2].fInnerOffset = SkPoint::Make(-xRadius, innerRatio*yRadius); 535 verts[2].fInnerOffset = SkPoint::Make(-xRadius, innerRatio*yRadius);
533 536
534 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); 537 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom);
535 verts[3].fOuterXRadius = xRadius; 538 verts[3].fOuterXRadius = xRadius;
536 verts[3].fInnerXRadius = innerXRadius; 539 verts[3].fInnerXRadius = innerXRadius;
537 verts[3].fOuterOffset = SkPoint::Make(xRadius, outerRatio*yRadius); 540 verts[3].fOuterOffset = SkPoint::Make(xRadius, outerRatio*yRadius);
538 verts[3].fInnerOffset = SkPoint::Make(xRadius, innerRatio*yRadius); 541 verts[3].fInnerOffset = SkPoint::Make(xRadius, innerRatio*yRadius);
539 542
540 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); 543 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds);
544
545 return true;
541 } 546 }
OLDNEW
« no previous file with comments | « include/gpu/GrOvalRenderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698