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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkScalar invScaleSqr = invMat.getScaleX() * invMat.getScaleY(); | 68 SkScalar invScaleSqr = invMat.getScaleX() * invMat.getScaleY(); |
69 #ifndef SK_SUPPORT_LEGACY_NEG_SCALE_HQ | 69 return size < (maximumAllocation * SkScalarAbs(invScaleSqr)); |
70 invScaleSqr = SkScalarAbs(invScaleSqr); | |
71 #endif | |
72 return size < (maximumAllocation * invScaleSqr); | |
73 } | 70 } |
74 | 71 |
75 /* | 72 /* |
76 * 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 |
77 * using bilerp for any remaining transformations. | 74 * using bilerp for any remaining transformations. |
78 */ | 75 */ |
79 bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmapProvider& pr
ovider) { | 76 bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmapProvider& pr
ovider) { |
80 if (fQuality != kHigh_SkFilterQuality) { | 77 if (fQuality != kHigh_SkFilterQuality) { |
81 return false; | 78 return false; |
82 } | 79 } |
(...skipping 11 matching lines...) Expand all Loading... |
94 SkScalar invScaleX = fInvMatrix.getScaleX(); | 91 SkScalar invScaleX = fInvMatrix.getScaleX(); |
95 SkScalar invScaleY = fInvMatrix.getScaleY(); | 92 SkScalar invScaleY = fInvMatrix.getScaleY(); |
96 if (fInvMatrix.getType() & SkMatrix::kAffine_Mask) { | 93 if (fInvMatrix.getType() & SkMatrix::kAffine_Mask) { |
97 SkSize scale; | 94 SkSize scale; |
98 if (!fInvMatrix.decomposeScale(&scale)) { | 95 if (!fInvMatrix.decomposeScale(&scale)) { |
99 return false; | 96 return false; |
100 } | 97 } |
101 invScaleX = scale.width(); | 98 invScaleX = scale.width(); |
102 invScaleY = scale.height(); | 99 invScaleY = scale.height(); |
103 } | 100 } |
104 #ifndef SK_SUPPORT_LEGACY_NEG_SCALE_HQ | |
105 invScaleX = SkScalarAbs(invScaleX); | 101 invScaleX = SkScalarAbs(invScaleX); |
106 invScaleY = SkScalarAbs(invScaleY); | 102 invScaleY = SkScalarAbs(invScaleY); |
107 #endif | |
108 | 103 |
109 if (SkScalarNearlyEqual(invScaleX, 1) && SkScalarNearlyEqual(invScaleY, 1))
{ | 104 if (SkScalarNearlyEqual(invScaleX, 1) && SkScalarNearlyEqual(invScaleY, 1))
{ |
110 return false; // no need for HQ | 105 return false; // no need for HQ |
111 } | 106 } |
112 | 107 |
113 #ifndef SK_SUPPORT_LEGACY_HQ_DOWNSAMPLING | 108 #ifndef SK_SUPPORT_LEGACY_HQ_DOWNSAMPLING |
114 if (invScaleX > 1 || invScaleY > 1) { | 109 if (invScaleX > 1 || invScaleY > 1) { |
115 return false; // only use HQ when upsampling | 110 return false; // only use HQ when upsampling |
116 } | 111 } |
117 #endif | 112 #endif |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 fResultBitmap.getColorTable()); | 224 fResultBitmap.getColorTable()); |
230 } | 225 } |
231 | 226 |
232 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi
tmapProvider& bm, | 227 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi
tmapProvider& bm, |
233 const SkMa
trix& inverse, | 228 const SkMa
trix& inverse, |
234 SkFilterQu
ality quality, | 229 SkFilterQu
ality quality, |
235 void* stor
age, size_t size) { | 230 void* stor
age, size_t size) { |
236 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm,
inverse, quality); | 231 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm,
inverse, quality); |
237 } | 232 } |
238 | 233 |
OLD | NEW |