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

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

Issue 19789016: add mipmaps to scaledimagecache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkMipMap.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 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkMipMap.h" 8 #include "SkMipMap.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 185
186 for (int i = 0; i < countLevels; ++i) { 186 for (int i = 0; i < countLevels; ++i) {
187 width >>= 1; 187 width >>= 1;
188 height >>= 1; 188 height >>= 1;
189 rowBytes = SkToU32(SkBitmap::ComputeRowBytes(config, width)); 189 rowBytes = SkToU32(SkBitmap::ComputeRowBytes(config, width));
190 190
191 levels[i].fPixels = addr; 191 levels[i].fPixels = addr;
192 levels[i].fWidth = width; 192 levels[i].fWidth = width;
193 levels[i].fHeight = height; 193 levels[i].fHeight = height;
194 levels[i].fRowBytes = rowBytes; 194 levels[i].fRowBytes = rowBytes;
195 levels[i].fScale = (float)width / src.width();
195 196
196 SkBitmap dstBM; 197 SkBitmap dstBM;
197 dstBM.setConfig(config, width, height, rowBytes); 198 dstBM.setConfig(config, width, height, rowBytes);
198 dstBM.setPixels(addr); 199 dstBM.setPixels(addr);
199 200
200 srcBM.lockPixels(); 201 srcBM.lockPixels();
201 for (int y = 0; y < height; y++) { 202 for (int y = 0; y < height; y++) {
202 for (int x = 0; x < width; x++) { 203 for (int x = 0; x < width; x++) {
203 proc(&dstBM, x, y, srcBM); 204 proc(&dstBM, x, y, srcBM);
204 } 205 }
205 } 206 }
206 srcBM.unlockPixels(); 207 srcBM.unlockPixels();
207 208
208 srcBM = dstBM; 209 srcBM = dstBM;
209 addr += height * rowBytes; 210 addr += height * rowBytes;
210 } 211 }
211 SkASSERT(addr == baseAddr + size); 212 SkASSERT(addr == baseAddr + size);
212 213
213 return SkNEW_ARGS(SkMipMap, (levels, countLevels)); 214 return SkNEW_ARGS(SkMipMap, (levels, countLevels, size));
215 }
216
217 ///////////////////////////////////////////////////////////////////////////////
218
219 //static int gCounter;
220
221 SkMipMap::SkMipMap(Level* levels, int count, size_t size)
222 : fSize(size), fLevels(levels), fCount(count) {
223 SkASSERT(levels);
224 SkASSERT(count > 0);
225 // SkDebugf("mips %d\n", ++gCounter);
226 }
227
228 SkMipMap::~SkMipMap() {
229 sk_free(fLevels);
230 // SkDebugf("mips %d\n", --gCounter);
214 } 231 }
215 232
216 static SkFixed compute_level(SkScalar scale) { 233 static SkFixed compute_level(SkScalar scale) {
217 SkFixed s = SkAbs32(SkScalarToFixed(SkScalarInvert(scale))); 234 SkFixed s = SkAbs32(SkScalarToFixed(SkScalarInvert(scale)));
218 235
219 if (s < SK_Fixed1) { 236 if (s < SK_Fixed1) {
220 return 0; 237 return 0;
221 } 238 }
222 int clz = SkCLZ(s); 239 int clz = SkCLZ(s);
223 SkASSERT(clz >= 1 && clz <= 15); 240 SkASSERT(clz >= 1 && clz <= 15);
(...skipping 12 matching lines...) Expand all
236 } 253 }
237 254
238 if (level > fCount) { 255 if (level > fCount) {
239 level = fCount; 256 level = fCount;
240 } 257 }
241 if (levelPtr) { 258 if (levelPtr) {
242 *levelPtr = fLevels[level - 1]; 259 *levelPtr = fLevels[level - 1];
243 } 260 }
244 return true; 261 return true;
245 } 262 }
OLDNEW
« no previous file with comments | « src/core/SkMipMap.h ('k') | src/core/SkScaledImageCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698