aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkMatrix.cpp
diff options
context:
space:
mode:
authorGravatar jvanverth@google.com <jvanverth@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-22 13:34:01 +0000
committerGravatar jvanverth@google.com <jvanverth@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-22 13:34:01 +0000
commit46d3d39e65e0b3ea2ad7c91c176ccafb4df0fa24 (patch)
tree3ed0089389283fd2d9cfa8bea196b9363ee60a9d /src/core/SkMatrix.cpp
parent9d5f99bc309a7d733e33a149bef295ae3c8b3ac1 (diff)
Add GPU support for axis-aligned ovals:
- Add drawOval base function to SkDevice, and override in SkGpuDevice - Move isSimilarityMatrix to SkMatrix (renamed to isSimilarity) and fixed up unit test - Since both SkGpuDevice::drawOval() and GrContext::drawPath() can try to draw ovals, added GrContext::canDrawOval() and GrContext::internalDrawOval() to avoid duplicate code - Hooked in axis-aligned oval fill shader - Enabled GPU stroked circles - Added stroked circle bench test Review URL: https://codereview.appspot.com/7137050 git-svn-id: http://skia.googlecode.com/svn/trunk@7304 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkMatrix.cpp')
-rw-r--r--src/core/SkMatrix.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 532a53449b..eda8f14c07 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -170,6 +170,43 @@ bool operator==(const SkMatrix& a, const SkMatrix& b) {
///////////////////////////////////////////////////////////////////////////////
+bool SkMatrix::isSimilarity(SkScalar tol) const {
+ // if identity or translate matrix
+ TypeMask mask = this->getType();
+ if (mask <= kTranslate_Mask) {
+ return true;
+ }
+ if (mask & kPerspective_Mask) {
+ return false;
+ }
+
+ SkScalar mx = fMat[kMScaleX];
+ SkScalar my = fMat[kMScaleY];
+ // if no skew, can just compare scale factors
+ if (!(mask & kAffine_Mask)) {
+ return !SkScalarNearlyZero(mx) && SkScalarNearlyEqual(SkScalarAbs(mx), SkScalarAbs(my));
+ }
+ SkScalar sx = fMat[kMSkewX];
+ SkScalar sy = fMat[kMSkewY];
+
+ // degenerate matrix, non-similarity
+ if (SkScalarNearlyZero(mx) && SkScalarNearlyZero(my)
+ && SkScalarNearlyZero(sx) && SkScalarNearlyZero(sy)) {
+ return false;
+ }
+
+ // it has scales and skews, but it could also be rotation, check it out.
+ SkVector vec[2];
+ vec[0].set(mx, sx);
+ vec[1].set(sy, my);
+
+ return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) &&
+ SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(),
+ SkScalarSquare(tol));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
void SkMatrix::setTranslate(SkScalar dx, SkScalar dy) {
if (SkScalarToCompareType(dx) || SkScalarToCompareType(dy)) {
fMat[kMTransX] = dx;