Adjust start and end points of arcs based on CTM
authorBrian Osman <brianosman@google.com>
Wed, 17 May 2017 15:43:11 +0000 (11:43 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 17 May 2017 16:08:06 +0000 (16:08 +0000)
GPU was effectively ignoring rotation and scale when drawing arcs. Found
this with a new GM I'll be adding. Hoping to land that separately.

Bug: skia:
Change-Id: I14d36ceaa478193c1a75fb2d06704e7d51f46d02
Reviewed-on: https://skia-review.googlesource.com/17218
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
src/gpu/ops/GrOvalOpFactory.cpp

index 5110ccfb40d2962698a5f527a63691ccca63bbc7..623ec7ab7f58cda86d72ee5d5b53f15e2665884a 100644 (file)
@@ -703,6 +703,18 @@ public:
             startPoint.fY = SkScalarSinCos(arcParams->fStartAngleRadians, &startPoint.fX);
             SkScalar endAngle = arcParams->fStartAngleRadians + arcParams->fSweepAngleRadians;
             stopPoint.fY = SkScalarSinCos(endAngle, &stopPoint.fX);
+
+            // Adjust the start and end points based on the view matrix (to handle rotated arcs)
+            startPoint = viewMatrix.mapVector(startPoint.fX, startPoint.fY);
+            stopPoint = viewMatrix.mapVector(stopPoint.fX, stopPoint.fY);
+            startPoint.normalize();
+            stopPoint.normalize();
+
+            // If the matrix included scale (on one axis) we need to swap our start and end points
+            if ((viewMatrix.getScaleX() < 0) != (viewMatrix.getScaleY() < 0)) {
+                SkTSwap(startPoint, stopPoint);
+            }
+
             // Like a fill without useCenter, butt-cap stroke can be implemented by clipping against
             // radial lines. However, in both cases we have to be careful about the half-circle.
             // case. In that case the two radial lines are equal and so that edge gets clipped