OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapController.h" | 9 #include "SkBitmapController.h" |
10 #include "SkBitmapProvider.h" | 10 #include "SkBitmapProvider.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 // scaling by the given inverted matrix is less than the maximum allowed. | 58 // scaling by the given inverted matrix is less than the maximum allowed. |
59 static inline bool cache_size_okay(const SkBitmapProvider& provider, const SkMat rix& invMat) { | 59 static inline bool cache_size_okay(const SkBitmapProvider& provider, const SkMat rix& invMat) { |
60 size_t maximumAllocation = SkResourceCache::GetEffectiveSingleAllocationByte Limit(); | 60 size_t maximumAllocation = SkResourceCache::GetEffectiveSingleAllocationByte Limit(); |
61 if (0 == maximumAllocation) { | 61 if (0 == maximumAllocation) { |
62 return true; | 62 return true; |
63 } | 63 } |
64 // float matrixScaleFactor = 1.0 / (invMat.scaleX * invMat.scaleY); | 64 // float matrixScaleFactor = 1.0 / (invMat.scaleX * invMat.scaleY); |
65 // return ((origBitmapSize * matrixScaleFactor) < maximumAllocationSize); | 65 // return ((origBitmapSize * matrixScaleFactor) < maximumAllocationSize); |
66 // Skip the division step: | 66 // Skip the division step: |
67 const size_t size = provider.info().getSafeSize(provider.info().minRowBytes( )); | 67 const size_t size = provider.info().getSafeSize(provider.info().minRowBytes( )); |
68 return size < (maximumAllocation * invMat.getScaleX() * invMat.getScaleY()); | 68 SkScalar invScaleSqr = SkScalarAbs(invMat.getScaleX() * invMat.getScaleY()); |
69 return size < (maximumAllocation * invScaleSqr); | |
69 } | 70 } |
70 | 71 |
71 /* | 72 /* |
72 * High quality is implemented by performing up-right scale-only filtering and then | 73 * High quality is implemented by performing up-right scale-only filtering and then |
73 * using bilerp for any remaining transformations. | 74 * using bilerp for any remaining transformations. |
74 */ | 75 */ |
75 bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmapProvider& pr ovider) { | 76 bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmapProvider& pr ovider) { |
76 if (fQuality != kHigh_SkFilterQuality) { | 77 if (fQuality != kHigh_SkFilterQuality) { |
77 return false; | 78 return false; |
78 } | 79 } |
(...skipping 11 matching lines...) Expand all Loading... | |
90 SkScalar invScaleX = fInvMatrix.getScaleX(); | 91 SkScalar invScaleX = fInvMatrix.getScaleX(); |
91 SkScalar invScaleY = fInvMatrix.getScaleY(); | 92 SkScalar invScaleY = fInvMatrix.getScaleY(); |
92 if (fInvMatrix.getType() & SkMatrix::kAffine_Mask) { | 93 if (fInvMatrix.getType() & SkMatrix::kAffine_Mask) { |
93 SkSize scale; | 94 SkSize scale; |
94 if (!fInvMatrix.decomposeScale(&scale)) { | 95 if (!fInvMatrix.decomposeScale(&scale)) { |
95 return false; | 96 return false; |
96 } | 97 } |
97 invScaleX = scale.width(); | 98 invScaleX = scale.width(); |
98 invScaleY = scale.height(); | 99 invScaleY = scale.height(); |
99 } | 100 } |
101 invScaleX = SkScalarAbs(invScaleX); | |
vmpstr
2016/02/04 00:59:04
This is the only bit that requires some thought fo
| |
102 invScaleY = SkScalarAbs(invScaleY); | |
103 | |
100 if (SkScalarNearlyEqual(invScaleX, 1) && SkScalarNearlyEqual(invScaleY, 1)) { | 104 if (SkScalarNearlyEqual(invScaleX, 1) && SkScalarNearlyEqual(invScaleY, 1)) { |
101 return false; // no need for HQ | 105 return false; // no need for HQ |
102 } | 106 } |
103 | 107 |
104 #ifndef SK_SUPPORT_LEGACY_HQ_DOWNSAMPLING | 108 #ifndef SK_SUPPORT_LEGACY_HQ_DOWNSAMPLING |
105 if (invScaleX > 1 || invScaleY > 1) { | 109 if (invScaleX > 1 || invScaleY > 1) { |
106 return false; // only use HQ when upsampling | 110 return false; // only use HQ when upsampling |
107 } | 111 } |
108 #endif | 112 #endif |
109 | 113 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 fResultBitmap.getColorTable()); | 224 fResultBitmap.getColorTable()); |
221 } | 225 } |
222 | 226 |
223 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi tmapProvider& bm, | 227 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi tmapProvider& bm, |
224 const SkMa trix& inverse, | 228 const SkMa trix& inverse, |
225 SkFilterQu ality quality, | 229 SkFilterQu ality quality, |
226 void* stor age, size_t size) { | 230 void* stor age, size_t size) { |
227 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality); | 231 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality); |
228 } | 232 } |
229 | 233 |
OLD | NEW |