| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBitmapCache.h" | 8 #include "SkBitmapCache.h" |
| 9 #include "SkBitmapController.h" | 9 #include "SkBitmapController.h" |
| 10 #include "SkBitmapProcState.h" | 10 #include "SkBitmapProcState.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 , fSrcGammaTreatment(treatment) | 55 , fSrcGammaTreatment(treatment) |
| 56 , fBMState(nullptr) | 56 , fBMState(nullptr) |
| 57 {} | 57 {} |
| 58 | 58 |
| 59 SkBitmapProcInfo::~SkBitmapProcInfo() { | 59 SkBitmapProcInfo::~SkBitmapProcInfo() { |
| 60 SkInPlaceDeleteCheck(fBMState, fBMStateStorage.get()); | 60 SkInPlaceDeleteCheck(fBMState, fBMStateStorage.get()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 /////////////////////////////////////////////////////////////////////////////// | 63 /////////////////////////////////////////////////////////////////////////////// |
| 64 | 64 |
| 65 // true iff the matrix contains, at most, scale and translate elements | 65 // true iff the matrix has a scale and no more than an optional translate. |
| 66 static bool matrix_only_scale_translate(const SkMatrix& m) { | 66 static bool matrix_only_scale_translate(const SkMatrix& m) { |
| 67 return m.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask); | 67 return (m.getType() & ~SkMatrix::kTranslate_Mask) == SkMatrix::kScale_Mask; |
| 68 } | 68 } |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * For the purposes of drawing bitmaps, if a matrix is "almost" translate | 71 * For the purposes of drawing bitmaps, if a matrix is "almost" translate |
| 72 * go ahead and treat it as if it were, so that subsequent code can go fast. | 72 * go ahead and treat it as if it were, so that subsequent code can go fast. |
| 73 */ | 73 */ |
| 74 static bool just_trans_clamp(const SkMatrix& matrix, const SkPixmap& pixmap) { | 74 static bool just_trans_clamp(const SkMatrix& matrix, const SkPixmap& pixmap) { |
| 75 SkASSERT(matrix_only_scale_translate(matrix)); | 75 SkASSERT(matrix_only_scale_translate(matrix)); |
| 76 | 76 |
| 77 if (matrix.getType() & SkMatrix::kScale_Mask) { | 77 SkRect dst; |
| 78 SkRect dst; | 78 SkRect src = SkRect::Make(pixmap.bounds()); |
| 79 SkRect src = SkRect::Make(pixmap.bounds()); | |
| 80 | 79 |
| 81 // Can't call mapRect(), since that will fix up inverted rectangles, | 80 // Can't call mapRect(), since that will fix up inverted rectangles, |
| 82 // e.g. when scale is negative, and we don't want to return true for | 81 // e.g. when scale is negative, and we don't want to return true for |
| 83 // those. | 82 // those. |
| 84 matrix.mapPoints(SkTCast<SkPoint*>(&dst), | 83 matrix.mapPoints(SkTCast<SkPoint*>(&dst), |
| 85 SkTCast<const SkPoint*>(&src), | 84 SkTCast<const SkPoint*>(&src), |
| 86 2); | 85 2); |
| 87 | 86 |
| 88 // Now round all 4 edges to device space, and then compare the device | 87 // Now round all 4 edges to device space, and then compare the device |
| 89 // width/height to the original. Note: we must map all 4 and subtract | 88 // width/height to the original. Note: we must map all 4 and subtract |
| 90 // rather than map the "width" and compare, since we care about the | 89 // rather than map the "width" and compare, since we care about the |
| 91 // phase (in pixel space) that any translate in the matrix might impart. | 90 // phase (in pixel space) that any translate in the matrix might impart. |
| 92 SkIRect idst; | 91 SkIRect idst; |
| 93 dst.round(&idst); | 92 dst.round(&idst); |
| 94 return idst.width() == pixmap.width() && idst.height() == pixmap.height(
); | 93 return idst.width() == pixmap.width() && idst.height() == pixmap.height(); |
| 95 } | |
| 96 // if we got here, we're either kTranslate_Mask or identity | |
| 97 return true; | |
| 98 } | 94 } |
| 99 | 95 |
| 100 static bool just_trans_general(const SkMatrix& matrix) { | 96 static bool just_trans_general(const SkMatrix& matrix) { |
| 101 SkASSERT(matrix_only_scale_translate(matrix)); | 97 SkASSERT(matrix_only_scale_translate(matrix)); |
| 102 | 98 |
| 103 if (matrix.getType() & SkMatrix::kScale_Mask) { | 99 const SkScalar tol = SK_Scalar1 / 32768; |
| 104 const SkScalar tol = SK_Scalar1 / 32768; | |
| 105 | 100 |
| 106 if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleX] - SK_Scalar1, tol)) { | 101 return SkScalarNearlyZero(matrix[SkMatrix::kMScaleX] - SK_Scalar1, tol) |
| 107 return false; | 102 && SkScalarNearlyZero(matrix[SkMatrix::kMScaleY] - SK_Scalar1, tol); |
| 108 } | |
| 109 if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleY] - SK_Scalar1, tol)) { | |
| 110 return false; | |
| 111 } | |
| 112 } | |
| 113 // if we got here, treat us as either kTranslate_Mask or identity | |
| 114 return true; | |
| 115 } | 103 } |
| 116 | 104 |
| 117 static bool valid_for_filtering(unsigned dimension) { | 105 static bool valid_for_filtering(unsigned dimension) { |
| 118 // for filtering, width and height must fit in 14bits, since we use steal | 106 // for filtering, width and height must fit in 14bits, since we use steal |
| 119 // 2 bits from each to store our 4bit subpixel data | 107 // 2 bits from each to store our 4bit subpixel data |
| 120 return (dimension & ~0x3FFF) == 0; | 108 return (dimension & ~0x3FFF) == 0; |
| 121 } | 109 } |
| 122 | 110 |
| 123 bool SkBitmapProcInfo::init(const SkMatrix& inv, const SkPaint& paint) { | 111 bool SkBitmapProcInfo::init(const SkMatrix& inv, const SkPaint& paint) { |
| 124 const int origW = fProvider.info().width(); | 112 const int origW = fProvider.info().width(); |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 *dst++ = src[index]; | 810 *dst++ = src[index]; |
| 823 fx += dx; | 811 fx += dx; |
| 824 } | 812 } |
| 825 } else { | 813 } else { |
| 826 for (int i = 0; i < count; ++i) { | 814 for (int i = 0; i < count; ++i) { |
| 827 dst[i] = src[SkClampMax(SkFractionalIntToInt(fx), maxX)]; | 815 dst[i] = src[SkClampMax(SkFractionalIntToInt(fx), maxX)]; |
| 828 fx += dx; | 816 fx += dx; |
| 829 } | 817 } |
| 830 } | 818 } |
| 831 } | 819 } |
| OLD | NEW |