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

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

Issue 856783004: Revert of use log2(scale) to compute mip level (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 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/SkScalar.h ('k') | no next file » | 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 srcBM = dstBM; 218 srcBM = dstBM;
219 addr += height * rowBytes; 219 addr += height * rowBytes;
220 } 220 }
221 SkASSERT(addr == baseAddr + size); 221 SkASSERT(addr == baseAddr + size);
222 222
223 return mipmap; 223 return mipmap;
224 } 224 }
225 225
226 /////////////////////////////////////////////////////////////////////////////// 226 ///////////////////////////////////////////////////////////////////////////////
227 227
228 #ifdef SK_SUPPORT_LEGACY_MIPLEVELCHOICE 228 //static int gCounter;
229
229 static SkFixed compute_level(SkScalar scale) { 230 static SkFixed compute_level(SkScalar scale) {
230 SkScalar inv = SkScalarAbs(SkScalarInvert(scale)); 231 SkScalar inv = SkScalarAbs(SkScalarInvert(scale));
231 if (inv > 32767) { // Watch out for SkFixed overflow. 232 if (inv > 32767) { // Watch out for SkFixed overflow.
232 inv = 32767; 233 inv = 32767;
233 } 234 }
234 SkFixed s = SkScalarToFixed(inv); 235 SkFixed s = SkScalarToFixed(inv);
235 236
236 if (s < SK_Fixed1) { 237 if (s < SK_Fixed1) {
237 return 0; 238 return 0;
238 } 239 }
239 int clz = SkCLZ(s); 240 int clz = SkCLZ(s);
240 SkASSERT(clz >= 1 && clz <= 15); 241 SkASSERT(clz >= 1 && clz <= 15);
241 return SkIntToFixed(15 - clz) + ((unsigned)(s << (clz + 1)) >> 16); 242 return SkIntToFixed(15 - clz) + ((unsigned)(s << (clz + 1)) >> 16);
242 } 243 }
243 #endif
244 244
245 bool SkMipMap::extractLevel(SkScalar scale, Level* levelPtr) const { 245 bool SkMipMap::extractLevel(SkScalar scale, Level* levelPtr) const {
246 if (NULL == fLevels) { 246 if (NULL == fLevels) {
247 return false; 247 return false;
248 } 248 }
249 249
250 if (scale >= SK_Scalar1 || scale <= 0 || !SkScalarIsFinite(scale)) { 250 if (scale >= SK_Scalar1) {
251 return false; 251 return false;
252 } 252 }
253 253
254 #ifdef SK_SUPPORT_LEGACY_MIPLEVELCHOICE
255 int level = compute_level(scale) >> 16; 254 int level = compute_level(scale) >> 16;
256 #else
257 SkScalar L = -SkScalarLog2(scale);
258 if (!SkScalarIsFinite(L)) {
259 return false;
260 }
261 SkASSERT(L >= 0);
262 int level = SkScalarRoundToInt(L);
263 // SkDebugf("mipmap scale=%g L=%g level=%d\n", scale, L, level);
264 #endif
265
266 SkASSERT(level >= 0); 255 SkASSERT(level >= 0);
267 if (level <= 0) { 256 if (level <= 0) {
268 return false; 257 return false;
269 } 258 }
270 259
271 if (level > fCount) { 260 if (level > fCount) {
272 level = fCount; 261 level = fCount;
273 } 262 }
274 if (levelPtr) { 263 if (levelPtr) {
275 *levelPtr = fLevels[level - 1]; 264 *levelPtr = fLevels[level - 1];
276 } 265 }
277 return true; 266 return true;
278 } 267 }
OLDNEW
« no previous file with comments | « include/core/SkScalar.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698