OLD | NEW |
---|---|
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" |
11 #include "SkMath.h" | |
11 #include "SkNx.h" | 12 #include "SkNx.h" |
13 #include "SkTypes.h" | |
12 | 14 |
13 // | 15 // |
14 // ColorTypeFilter is the "Type" we pass to some downsample template functions. | 16 // ColorTypeFilter is the "Type" we pass to some downsample template functions. |
15 // It controls how we expand a pixel into a large type, with space between each component, | 17 // It controls how we expand a pixel into a large type, with space between each component, |
16 // so we can then perform our simple filter (either box or triangle) and store t he intermediates | 18 // so we can then perform our simple filter (either box or triangle) and store t he intermediates |
17 // in the expanded type. | 19 // in the expanded type. |
18 // | 20 // |
19 | 21 |
20 struct ColorTypeFilter_8888 { | 22 struct ColorTypeFilter_8888 { |
21 typedef uint32_t Type; | 23 typedef uint32_t Type; |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 return nullptr; | 367 return nullptr; |
366 } | 368 } |
367 const SkPixmap& srcPixmap = srcUnlocker.pixmap(); | 369 const SkPixmap& srcPixmap = srcUnlocker.pixmap(); |
368 // Try to catch where we might have returned nullptr for src crbug.com/49281 8 | 370 // Try to catch where we might have returned nullptr for src crbug.com/49281 8 |
369 if (nullptr == srcPixmap.addr()) { | 371 if (nullptr == srcPixmap.addr()) { |
370 sk_throw(); | 372 sk_throw(); |
371 } | 373 } |
372 return Build(srcPixmap, fact); | 374 return Build(srcPixmap, fact); |
373 } | 375 } |
374 | 376 |
377 int SkMipMap::ComputeLevelCount(int baseWidth, int baseHeight) { | |
reed1
2016/01/28 02:06:03
Its a little odd that the Build code doesn't call
cblume
2016/02/01 09:31:07
I agree.
But when I was writing this I realized th
| |
378 // OpenGL's spec requires that each mipmap level have height/width equal to | |
379 // max(1, floor(original_height / 2^i) | |
380 // (or original_width) where i is the mipmap level. | |
381 // Continue scaling down until both axes are size 1. | |
382 // | |
383 // This means when it maintains isotropic space (both axes scaling down | |
384 // at the same rate) until one axis hits size 1. | |
385 // At that point, OpenGL continues to scale down into anisotropic space | |
386 // (where the scales are not the same between axes). | |
387 // | |
388 // Skia currently does not go into anisotropic space. | |
389 // Once an axis hits size 1 we stop. | |
390 // All this means is rather than use the largest axis we will use the | |
391 // smallest axis. | |
392 | |
393 const int smallestAxis = SkTMin(baseWidth, baseHeight); | |
394 if (smallestAxis < 2) { | |
395 // SkMipMap::Build requires a minimum size of 2. | |
396 return 0; | |
397 } | |
398 const int leadingZeros = SkCLZ(static_cast<uint32_t>(smallestAxis)); | |
399 // If the value 00011010 has 3 leading 0s then it has 5 significant bits | |
400 // (the bits which are not leading zeros) | |
401 const int significantBits = (sizeof(uint32_t) * 8) - leadingZeros; | |
402 // This is making the assumption that the size of a byte is 8 bits | |
403 // and that sizeof(uint32_t)'s implementation-defined behavior is 4. | |
404 const int mipLevelCount = significantBits; | |
405 | |
406 return mipLevelCount; | |
407 } | |
408 | |
409 int SkMipMap::countLevels() const { | |
410 return fCount; | |
411 } | |
412 | |
413 void SkMipMap::getLevel(int index, Level* levelPtr) const { | |
414 if (NULL == fLevels) { | |
415 return; | |
416 } | |
417 if (index < 0) { | |
418 return; | |
419 } | |
420 if (index > fCount - 1) { | |
421 return; | |
422 } | |
423 if (levelPtr) { | |
424 *levelPtr = fLevels[index]; | |
425 } | |
426 } | |
OLD | NEW |