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

Unified Diff: src/core/SkBitmapProcState.cpp

Issue 2472003004: Avoid matrix inverse in SkBitmapProcInfo::init for translate-only cases (Closed)
Patch Set: simplified matrix type test Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmapProcState.cpp
diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp
index f04379cf20d035112533937fce5d77d03faf2778..26ee82e28fe954b840926dc2917a21367389583e 100644
--- a/src/core/SkBitmapProcState.cpp
+++ b/src/core/SkBitmapProcState.cpp
@@ -62,9 +62,9 @@ SkBitmapProcInfo::~SkBitmapProcInfo() {
///////////////////////////////////////////////////////////////////////////////
-// true iff the matrix contains, at most, scale and translate elements
+// true iff the matrix has a scale and no more than an optional translate.
static bool matrix_only_scale_translate(const SkMatrix& m) {
- return m.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask);
+ return (m.getType() & ~SkMatrix::kTranslate_Mask) == SkMatrix::kScale_Mask;
}
/**
@@ -74,44 +74,32 @@ static bool matrix_only_scale_translate(const SkMatrix& m) {
static bool just_trans_clamp(const SkMatrix& matrix, const SkPixmap& pixmap) {
SkASSERT(matrix_only_scale_translate(matrix));
- if (matrix.getType() & SkMatrix::kScale_Mask) {
- SkRect dst;
- SkRect src = SkRect::Make(pixmap.bounds());
-
- // Can't call mapRect(), since that will fix up inverted rectangles,
- // e.g. when scale is negative, and we don't want to return true for
- // those.
- matrix.mapPoints(SkTCast<SkPoint*>(&dst),
- SkTCast<const SkPoint*>(&src),
- 2);
-
- // Now round all 4 edges to device space, and then compare the device
- // width/height to the original. Note: we must map all 4 and subtract
- // rather than map the "width" and compare, since we care about the
- // phase (in pixel space) that any translate in the matrix might impart.
- SkIRect idst;
- dst.round(&idst);
- return idst.width() == pixmap.width() && idst.height() == pixmap.height();
- }
- // if we got here, we're either kTranslate_Mask or identity
- return true;
+ SkRect dst;
+ SkRect src = SkRect::Make(pixmap.bounds());
+
+ // Can't call mapRect(), since that will fix up inverted rectangles,
+ // e.g. when scale is negative, and we don't want to return true for
+ // those.
+ matrix.mapPoints(SkTCast<SkPoint*>(&dst),
+ SkTCast<const SkPoint*>(&src),
+ 2);
+
+ // Now round all 4 edges to device space, and then compare the device
+ // width/height to the original. Note: we must map all 4 and subtract
+ // rather than map the "width" and compare, since we care about the
+ // phase (in pixel space) that any translate in the matrix might impart.
+ SkIRect idst;
+ dst.round(&idst);
+ return idst.width() == pixmap.width() && idst.height() == pixmap.height();
}
static bool just_trans_general(const SkMatrix& matrix) {
SkASSERT(matrix_only_scale_translate(matrix));
- if (matrix.getType() & SkMatrix::kScale_Mask) {
- const SkScalar tol = SK_Scalar1 / 32768;
+ const SkScalar tol = SK_Scalar1 / 32768;
- if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleX] - SK_Scalar1, tol)) {
- return false;
- }
- if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleY] - SK_Scalar1, tol)) {
- return false;
- }
- }
- // if we got here, treat us as either kTranslate_Mask or identity
- return true;
+ return SkScalarNearlyZero(matrix[SkMatrix::kMScaleX] - SK_Scalar1, tol)
+ && SkScalarNearlyZero(matrix[SkMatrix::kMScaleY] - SK_Scalar1, tol);
}
static bool valid_for_filtering(unsigned dimension) {
« 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