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

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

Issue 14017012: Fix non-uniform scale for stroked ellipses (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 | « no previous file | 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // do any matrix crunching before we reset the draw state for device coords
423 const SkMatrix& vm = drawState->getViewMatrix(); 424 const SkMatrix& vm = drawState->getViewMatrix();
424 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); 425 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY());
425 vm.mapPoints(&center, 1); 426 vm.mapPoints(&center, 1);
426 SkRect xformedRect; 427 SkScalar ellipseXRadius = SkScalarHalf(ellipse.width());
427 vm.mapRect(&xformedRect, ellipse); 428 SkScalar ellipseYRadius = SkScalarHalf(ellipse.height());
428 SkScalar xRadius = SkScalarHalf(xformedRect.width()); 429 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*ellipseXRadius +
429 SkScalar yRadius = SkScalarHalf(xformedRect.height()); 430 vm[SkMatrix::kMSkewY]*ellipseYRadius);
431 SkScalar yRadius = SkScalarAbs(vm[SkMatrix::kMSkewX]*ellipseXRadius +
432 vm[SkMatrix::kMScaleY]*ellipseYRadius);
430 if (SkScalarDiv(xRadius, yRadius) > 2 || SkScalarDiv(yRadius, xRadius) > 2) { 433 if (SkScalarDiv(xRadius, yRadius) > 2 || SkScalarDiv(yRadius, xRadius) > 2) {
431 return false; 434 return false;
432 } 435 }
433 436
437 // do (potentially) anisotropic mapping of stroke
438 SkVector scaledStroke;
439 SkScalar strokeWidth = stroke.getWidth();
440 scaledStroke.fX = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMScaleX] + vm[SkMat rix::kMSkewY]));
441 scaledStroke.fY = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMSkewX] + vm[SkMatr ix::kMScaleY]));
442
434 GrDrawState::AutoDeviceCoordDraw adcd(drawState); 443 GrDrawState::AutoDeviceCoordDraw adcd(drawState);
435 if (!adcd.succeeded()) { 444 if (!adcd.succeeded()) {
436 return false; 445 return false;
437 } 446 }
438 447
439 // position + edge 448 // position + edge
440 static const GrVertexAttrib kVertexAttribs[] = { 449 static const GrVertexAttrib kVertexAttribs[] = {
441 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, 450 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
442 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindi ng}, 451 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindi ng},
443 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBin ding} 452 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBin ding}
(...skipping 21 matching lines...) Expand all
465 GrEffectRef* effect = EllipseEdgeEffect::Create(isStroked); 474 GrEffectRef* effect = EllipseEdgeEffect::Create(isStroked);
466 static const int kEllipseCenterAttrIndex = 1; 475 static const int kEllipseCenterAttrIndex = 1;
467 static const int kEllipseEdgeAttrIndex = 2; 476 static const int kEllipseEdgeAttrIndex = 2;
468 drawState->setEffect(kEdgeEffectStage, effect, 477 drawState->setEffect(kEdgeEffectStage, effect,
469 kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref( ); 478 kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref( );
470 479
471 SkScalar innerXRadius = 0.0f; 480 SkScalar innerXRadius = 0.0f;
472 SkScalar innerRatio = 1.0f; 481 SkScalar innerRatio = 1.0f;
473 482
474 if (SkStrokeRec::kFill_Style != style) { 483 if (SkStrokeRec::kFill_Style != style) {
475 SkScalar strokeWidth = stroke.getWidth();
476 484
477 // do (potentially) anisotropic mapping
478 SkVector scaledStroke;
479 scaledStroke.set(strokeWidth, strokeWidth);
480 vm.mapVectors(&scaledStroke, 1);
481 485
482 if (SkScalarNearlyZero(scaledStroke.length())) { 486 if (SkScalarNearlyZero(scaledStroke.length())) {
483 scaledStroke.set(SK_ScalarHalf, SK_ScalarHalf); 487 scaledStroke.set(SK_ScalarHalf, SK_ScalarHalf);
484 } else { 488 } else {
485 scaledStroke.scale(0.5f); 489 scaledStroke.scale(0.5f);
486 } 490 }
487 491
488 // this is legit only if scale & translation (which should be the case a t the moment) 492 // this is legit only if scale & translation (which should be the case a t the moment)
489 if (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairline_Style == style) { 493 if (SkStrokeRec::kStroke_Style == style || SkStrokeRec::kHairline_Style == style) {
490 SkScalar innerYRadius = SkMaxScalar(0, yRadius - scaledStroke.fY); 494 SkScalar innerYRadius = SkMaxScalar(0, yRadius - scaledStroke.fY);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); 541 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom);
538 verts[3].fOuterXRadius = xRadius; 542 verts[3].fOuterXRadius = xRadius;
539 verts[3].fInnerXRadius = innerXRadius; 543 verts[3].fInnerXRadius = innerXRadius;
540 verts[3].fOuterOffset = SkPoint::Make(xRadius, outerRatio*yRadius); 544 verts[3].fOuterOffset = SkPoint::Make(xRadius, outerRatio*yRadius);
541 verts[3].fInnerOffset = SkPoint::Make(xRadius, innerRatio*yRadius); 545 verts[3].fInnerOffset = SkPoint::Make(xRadius, innerRatio*yRadius);
542 546
543 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); 547 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds);
544 548
545 return true; 549 return true;
546 } 550 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698