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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 174 } |
195 | 175 |
196 if (!SkBitmapCache::Find(fOrigBitmap, roundedDestWidth, roundedDestHeigh
t, &fScaledBitmap)) { | 176 if (!SkBitmapCache::Find(fOrigBitmap, roundedDestWidth, roundedDestHeigh
t, &fScaledBitmap)) { |
197 // All the criteria are met; let's make a new bitmap. | 177 // All the criteria are met; let's make a new bitmap. |
198 | 178 |
199 if (!SkBitmapScaler::Resize(&fScaledBitmap, | 179 if (!SkBitmapScaler::Resize(&fScaledBitmap, |
200 fOrigBitmap, | 180 fOrigBitmap, |
201 SkBitmapScaler::RESIZE_BEST, | 181 SkBitmapScaler::RESIZE_BEST, |
202 roundedDestWidth, | 182 roundedDestWidth, |
203 roundedDestHeight, | 183 roundedDestHeight, |
204 SkScaledImageCache::GetAllocator())) { | 184 SkResourceCache::GetAllocator())) { |
205 // we failed to create fScaledBitmap, so just return and let | 185 // we failed to create fScaledBitmap, so just return and let |
206 // the scanline proc handle it. | 186 // the scanline proc handle it. |
207 return false; | 187 return false; |
208 | 188 |
209 } | 189 } |
210 | 190 |
211 SkASSERT(NULL != fScaledBitmap.getPixels()); | 191 SkASSERT(NULL != fScaledBitmap.getPixels()); |
212 SkBitmapCache::Add(fOrigBitmap, roundedDestWidth, roundedDestHeight,
fScaledBitmap); | 192 SkBitmapCache::Add(fOrigBitmap, roundedDestWidth, roundedDestHeight,
fScaledBitmap); |
213 } | 193 } |
214 | 194 |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 } else { | 1007 } else { |
1028 size >>= 2; | 1008 size >>= 2; |
1029 } | 1009 } |
1030 | 1010 |
1031 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 1011 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
1032 size >>= 1; | 1012 size >>= 1; |
1033 } | 1013 } |
1034 | 1014 |
1035 return size; | 1015 return size; |
1036 } | 1016 } |
OLD | NEW |