Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: src/core/SkBitmapProcState.cpp

Issue 394003003: Set maximum output size for scaled-image-cache images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkGraphics.h ('k') | src/core/SkScaledImageCache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkBitmapProcState.h" 8 #include "SkBitmapProcState.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkFilterProc.h" 10 #include "SkFilterProc.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // forgets the ID, so it won't call Unlock 120 // forgets the ID, so it won't call Unlock
121 void release() { 121 void release() {
122 fIDPtr = NULL; 122 fIDPtr = NULL;
123 } 123 }
124 124
125 private: 125 private:
126 SkScaledImageCache::ID** fIDPtr; 126 SkScaledImageCache::ID** fIDPtr;
127 }; 127 };
128 #define AutoScaledCacheUnlocker(...) SK_REQUIRE_LOCAL_VAR(AutoScaledCacheUnlocke r) 128 #define AutoScaledCacheUnlocker(...) SK_REQUIRE_LOCAL_VAR(AutoScaledCacheUnlocke r)
129 129
130 // 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.
132 static inline bool cache_size_okay(const SkBitmap& bm, const SkMatrix& invMat) {
133 size_t maximumAllocation
134 = SkScaledImageCache::GetSingleAllocationByteLimit();
135 if (0 == maximumAllocation) {
136 return true;
137 }
138 // float matrixScaleFactor = 1.0 / (invMat.scaleX * invMat.scaleY);
139 // return ((origBitmapSize * matrixScaleFactor) < maximumAllocationSize);
140 // Skip the division step:
141 return bm.info().getSafeSize(bm.info().minRowBytes())
142 < (maximumAllocation * invMat.getScaleX() * invMat.getScaleY());
143 }
144
130 // TODO -- we may want to pass the clip into this function so we only scale 145 // TODO -- we may want to pass the clip into this function so we only scale
131 // the portion of the image that we're going to need. This will complicate 146 // the portion of the image that we're going to need. This will complicate
132 // the interface to the cache, but might be well worth it. 147 // the interface to the cache, but might be well worth it.
133 148
134 bool SkBitmapProcState::possiblyScaleImage() { 149 bool SkBitmapProcState::possiblyScaleImage() {
135 AutoScaledCacheUnlocker unlocker(&fScaledCacheID); 150 AutoScaledCacheUnlocker unlocker(&fScaledCacheID);
136 151
137 SkASSERT(NULL == fBitmap); 152 SkASSERT(NULL == fBitmap);
138 SkASSERT(NULL == fScaledCacheID); 153 SkASSERT(NULL == fScaledCacheID);
139 154
140 if (fFilterLevel <= SkPaint::kLow_FilterLevel) { 155 if (fFilterLevel <= SkPaint::kLow_FilterLevel) {
141 return false; 156 return false;
142 } 157 }
143
144 // Check to see if the transformation matrix is simple, and if we're 158 // Check to see if the transformation matrix is simple, and if we're
145 // doing high quality scaling. If so, do the bitmap scale here and 159 // doing high quality scaling. If so, do the bitmap scale here and
146 // remove the scaling component from the matrix. 160 // remove the scaling component from the matrix.
147 161
148 if (SkPaint::kHigh_FilterLevel == fFilterLevel && 162 if (SkPaint::kHigh_FilterLevel == fFilterLevel &&
149 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma sk) && 163 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma sk) &&
150 kN32_SkColorType == fOrigBitmap.colorType()) { 164 kN32_SkColorType == fOrigBitmap.colorType() &&
165 cache_size_okay(fOrigBitmap, fInvMatrix)) {
151 166
152 SkScalar invScaleX = fInvMatrix.getScaleX(); 167 SkScalar invScaleX = fInvMatrix.getScaleX();
153 SkScalar invScaleY = fInvMatrix.getScaleY(); 168 SkScalar invScaleY = fInvMatrix.getScaleY();
154 169
155 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, 170 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap,
156 invScaleX, invScaleY, 171 invScaleX, invScaleY,
157 &fScaledBitmap); 172 &fScaledBitmap);
158 if (fScaledCacheID) { 173 if (fScaledCacheID) {
159 fScaledBitmap.lockPixels(); 174 fScaledBitmap.lockPixels();
160 if (!fScaledBitmap.getPixels()) { 175 if (!fScaledBitmap.getPixels()) {
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 } else { 1055 } else {
1041 size >>= 2; 1056 size >>= 2;
1042 } 1057 }
1043 1058
1044 if (fFilterLevel != SkPaint::kNone_FilterLevel) { 1059 if (fFilterLevel != SkPaint::kNone_FilterLevel) {
1045 size >>= 1; 1060 size >>= 1;
1046 } 1061 }
1047 1062
1048 return size; 1063 return size;
1049 } 1064 }
OLDNEW
« no previous file with comments | « include/core/SkGraphics.h ('k') | src/core/SkScaledImageCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698