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 "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
11 #include "SkFilterProc.h" | 11 #include "SkFilterProc.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkShader.h" // for tilemodes | 13 #include "SkShader.h" // for tilemodes |
14 #include "SkUtilsArm.h" | 14 #include "SkUtilsArm.h" |
15 #include "SkBitmapScaler.h" | 15 #include "SkBitmapScaler.h" |
16 #include "SkMipMap.h" | 16 #include "SkMipMap.h" |
17 #include "SkPixelRef.h" | 17 #include "SkPixelRef.h" |
18 #include "SkImageEncoder.h" | 18 #include "SkImageEncoder.h" |
| 19 #include "SkResourceCache.h" |
19 | 20 |
20 #if !SK_ARM_NEON_IS_NONE | 21 #if !SK_ARM_NEON_IS_NONE |
21 // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp | 22 // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp |
22 extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[]; | 23 extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[]; |
23 extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[]; | 24 extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[]; |
24 extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, i
nt, uint16_t*); | 25 extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, i
nt, uint16_t*); |
25 extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, i
nt, int, uint16_t*, int); | 26 extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, i
nt, int, uint16_t*, int); |
26 extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint16_t*, int); | 27 extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint16_t*, int); |
27 extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint3
2_t*, int, SkPMColor*); | 28 extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint3
2_t*, int, SkPMColor*); |
28 extern void SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint32_t*, int); | 29 extern void SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint32_t*, int); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 101 |
101 v1.fX = mat.getScaleX(); | 102 v1.fX = mat.getScaleX(); |
102 v1.fY = mat.getSkewY(); | 103 v1.fY = mat.getSkewY(); |
103 | 104 |
104 v2.fX = mat.getSkewX(); | 105 v2.fX = mat.getSkewX(); |
105 v2.fY = mat.getScaleY(); | 106 v2.fY = mat.getScaleY(); |
106 | 107 |
107 return SkMaxScalar(v1.lengthSqd(), v2.lengthSqd()); | 108 return SkMaxScalar(v1.lengthSqd(), v2.lengthSqd()); |
108 } | 109 } |
109 | 110 |
110 class AutoScaledCacheUnlocker { | |
111 public: | |
112 AutoScaledCacheUnlocker(SkScaledImageCache::ID* idPtr) : fIDPtr(idPtr) {} | |
113 ~AutoScaledCacheUnlocker() { | |
114 if (fIDPtr && *fIDPtr) { | |
115 SkScaledImageCache::Unlock(*fIDPtr); | |
116 *fIDPtr = NULL; | |
117 } | |
118 } | |
119 | |
120 // forgets the ID, so it won't call Unlock | |
121 void release() { | |
122 fIDPtr = NULL; | |
123 } | |
124 | |
125 private: | |
126 SkScaledImageCache::ID* fIDPtr; | |
127 }; | |
128 #define AutoScaledCacheUnlocker(...) SK_REQUIRE_LOCAL_VAR(AutoScaledCacheUnlocke
r) | |
129 | |
130 // Check to see that the size of the bitmap that would be produced by | 111 // Check to see that the size of the bitmap that would be produced by |
131 // scaling by the given inverted matrix is less than the maximum allowed. | 112 // scaling by the given inverted matrix is less than the maximum allowed. |
132 static inline bool cache_size_okay(const SkBitmap& bm, const SkMatrix& invMat) { | 113 static inline bool cache_size_okay(const SkBitmap& bm, const SkMatrix& invMat) { |
133 size_t maximumAllocation | 114 size_t maximumAllocation = SkResourceCache::GetSingleAllocationByteLimit(); |
134 = SkScaledImageCache::GetSingleAllocationByteLimit(); | |
135 if (0 == maximumAllocation) { | 115 if (0 == maximumAllocation) { |
136 return true; | 116 return true; |
137 } | 117 } |
138 // float matrixScaleFactor = 1.0 / (invMat.scaleX * invMat.scaleY); | 118 // float matrixScaleFactor = 1.0 / (invMat.scaleX * invMat.scaleY); |
139 // return ((origBitmapSize * matrixScaleFactor) < maximumAllocationSize); | 119 // return ((origBitmapSize * matrixScaleFactor) < maximumAllocationSize); |
140 // Skip the division step: | 120 // Skip the division step: |
141 return bm.info().getSafeSize(bm.info().minRowBytes()) | 121 return bm.info().getSafeSize(bm.info().minRowBytes()) |
142 < (maximumAllocation * invMat.getScaleX() * invMat.getScaleY()); | 122 < (maximumAllocation * invMat.getScaleX() * invMat.getScaleY()); |
143 } | 123 } |
144 | 124 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 float dest_width = fOrigBitmap.width() / invScaleX; | 164 float dest_width = fOrigBitmap.width() / invScaleX; |
185 float dest_height = fOrigBitmap.height() / invScaleY; | 165 float dest_height = fOrigBitmap.height() / invScaleY; |
186 | 166 |
187 // All the criteria are met; let's make a new bitmap. | 167 // All the criteria are met; let's make a new bitmap. |
188 | 168 |
189 if (!SkBitmapScaler::Resize(&fScaledBitmap, | 169 if (!SkBitmapScaler::Resize(&fScaledBitmap, |
190 fOrigBitmap, | 170 fOrigBitmap, |
191 SkBitmapScaler::RESIZE_BEST, | 171 SkBitmapScaler::RESIZE_BEST, |
192 dest_width, | 172 dest_width, |
193 dest_height, | 173 dest_height, |
194 SkScaledImageCache::GetAllocator())) { | 174 SkResourceCache::GetAllocator())) { |
195 // we failed to create fScaledBitmap, so just return and let | 175 // we failed to create fScaledBitmap, so just return and let |
196 // the scanline proc handle it. | 176 // the scanline proc handle it. |
197 return false; | 177 return false; |
198 | 178 |
199 } | 179 } |
200 | 180 |
201 SkASSERT(NULL != fScaledBitmap.getPixels()); | 181 SkASSERT(NULL != fScaledBitmap.getPixels()); |
202 SkBitmapCache::Add(fOrigBitmap, invScaleX, invScaleY, fScaledBitmap)
; | 182 SkBitmapCache::Add(fOrigBitmap, invScaleX, invScaleY, fScaledBitmap)
; |
203 } | 183 } |
204 | 184 |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 } else { | 987 } else { |
1008 size >>= 2; | 988 size >>= 2; |
1009 } | 989 } |
1010 | 990 |
1011 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 991 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
1012 size >>= 1; | 992 size >>= 1; |
1013 } | 993 } |
1014 | 994 |
1015 return size; | 995 return size; |
1016 } | 996 } |
OLD | NEW |