OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 |
| 9 #include "SkMath.h" |
| 10 #include "SkMipMapLevel.h" |
| 11 #include "SkTypes.h" |
| 12 |
| 13 SkMipMapLevel::SkMipMapLevel(const void* texelsOrOffset, size_t rowBytes, int wi
dth, int height) |
| 14 : fTexelsOrOffset(texelsOrOffset) |
| 15 , fRowBytes(rowBytes) |
| 16 , fWidth(width) |
| 17 , fHeight(height) |
| 18 { |
| 19 } |
| 20 |
| 21 SkMipMapLevel::SkMipMapLevel(SkMipMapLevel&& rhs) |
| 22 : fTexelsOrOffset(rhs.fTexelsOrOffset) |
| 23 , fRowBytes(rhs.fRowBytes) |
| 24 , fWidth(rhs.fWidth) |
| 25 , fHeight(rhs.fHeight) |
| 26 { |
| 27 rhs.fTexelsOrOffset = nullptr; |
| 28 rhs.fRowBytes = 0; |
| 29 rhs.fWidth = 0; |
| 30 rhs.fHeight = 0; |
| 31 } |
| 32 |
| 33 SkMipMapLevel& SkMipMapLevel::operator =(SkMipMapLevel&& rhs) { |
| 34 fTexelsOrOffset = rhs.fTexelsOrOffset; |
| 35 fRowBytes = rhs.fRowBytes; |
| 36 fWidth = rhs.fWidth; |
| 37 fHeight = rhs.fHeight; |
| 38 |
| 39 rhs.fTexelsOrOffset = nullptr; |
| 40 rhs.fRowBytes = 0; |
| 41 rhs.fWidth = 0; |
| 42 rhs.fHeight = 0; |
| 43 |
| 44 return *this; |
| 45 } |
| 46 |
| 47 int SkMipMapLevelCount(int baseWidth, int baseHeight) { |
| 48 // OpenGL's spec requires that each mipmap level have height/width equal to |
| 49 // max(1, floor(original_height / 2^i) |
| 50 // (or original_width) where i is the mipmap level. |
| 51 // Continue scaling down until both axes are size 1. |
| 52 |
| 53 const int largestAxis = SkTMax(baseWidth, baseHeight); |
| 54 if (largestAxis < 0) { |
| 55 return 0; |
| 56 } |
| 57 const int leadingZeros = SkCLZ(static_cast<uint32_t>(largestAxis)); |
| 58 // If the value 00011010 has 3 leading 0s then it has 5 significant bits |
| 59 // (the bits which are not leading zeros) |
| 60 const int significantBits = (sizeof(uint32_t) * 8) - leadingZeros; |
| 61 // This is making the assumption that the size of a byte is 8 bits |
| 62 // and that sizeof(uint32_t)'s implementation-defined behavior is 4. |
| 63 const int mipLevelCount = significantBits; |
| 64 |
| 65 return mipLevelCount; |
| 66 } |
OLD | NEW |