| Index: src/core/SkMipMapLevel.cpp
|
| diff --git a/src/core/SkMipMapLevel.cpp b/src/core/SkMipMapLevel.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4bb0195704ea441b62a2970b5e4b86e5e3dd09a5
|
| --- /dev/null
|
| +++ b/src/core/SkMipMapLevel.cpp
|
| @@ -0,0 +1,66 @@
|
| +/*
|
| + * Copyright 2015 Google Inc.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + */
|
| +
|
| +
|
| +#include "SkMath.h"
|
| +#include "SkMipMapLevel.h"
|
| +#include "SkTypes.h"
|
| +
|
| +SkMipMapLevel::SkMipMapLevel(const void* texelsOrOffset, size_t rowBytes, int width, int height)
|
| + : fTexelsOrOffset(texelsOrOffset)
|
| + , fRowBytes(rowBytes)
|
| + , fWidth(width)
|
| + , fHeight(height)
|
| +{
|
| +}
|
| +
|
| +SkMipMapLevel::SkMipMapLevel(SkMipMapLevel&& rhs)
|
| + : fTexelsOrOffset(rhs.fTexelsOrOffset)
|
| + , fRowBytes(rhs.fRowBytes)
|
| + , fWidth(rhs.fWidth)
|
| + , fHeight(rhs.fHeight)
|
| +{
|
| + rhs.fTexelsOrOffset = nullptr;
|
| + rhs.fRowBytes = 0;
|
| + rhs.fWidth = 0;
|
| + rhs.fHeight = 0;
|
| +}
|
| +
|
| +SkMipMapLevel& SkMipMapLevel::operator =(SkMipMapLevel&& rhs) {
|
| + fTexelsOrOffset = rhs.fTexelsOrOffset;
|
| + fRowBytes = rhs.fRowBytes;
|
| + fWidth = rhs.fWidth;
|
| + fHeight = rhs.fHeight;
|
| +
|
| + rhs.fTexelsOrOffset = nullptr;
|
| + rhs.fRowBytes = 0;
|
| + rhs.fWidth = 0;
|
| + rhs.fHeight = 0;
|
| +
|
| + return *this;
|
| +}
|
| +
|
| +int SkMipMapLevelCount(int baseWidth, int baseHeight) {
|
| + // OpenGL's spec requires that each mipmap level have height/width equal to
|
| + // max(1, floor(original_height / 2^i)
|
| + // (or original_width) where i is the mipmap level.
|
| + // Continue scaling down until both axes are size 1.
|
| +
|
| + const int largestAxis = SkTMax(baseWidth, baseHeight);
|
| + if (largestAxis < 0) {
|
| + return 0;
|
| + }
|
| + const int leadingZeros = SkCLZ(static_cast<uint32_t>(largestAxis));
|
| + // If the value 00011010 has 3 leading 0s then it has 5 significant bits
|
| + // (the bits which are not leading zeros)
|
| + const int significantBits = (sizeof(uint32_t) * 8) - leadingZeros;
|
| + // This is making the assumption that the size of a byte is 8 bits
|
| + // and that sizeof(uint32_t)'s implementation-defined behavior is 4.
|
| + const int mipLevelCount = significantBits;
|
| +
|
| + return mipLevelCount;
|
| +}
|
|
|