| Index: src/gpu/GrTexture.cpp
|
| diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
|
| index 905455a9ec7030b1ac3d69019927888da320f637..9a80736c646d550ff4dd78d49874329f6c4fdfca 100644
|
| --- a/src/gpu/GrTexture.cpp
|
| +++ b/src/gpu/GrTexture.cpp
|
| @@ -14,11 +14,12 @@
|
| #include "GrRenderTargetPriv.h"
|
| #include "GrTexture.h"
|
| #include "GrTexturePriv.h"
|
| +#include "SkFloatingPoint.h"
|
|
|
| void GrTexture::dirtyMipMaps(bool mipMapsDirty) {
|
| if (mipMapsDirty) {
|
| if (kValid_MipMapsStatus == fMipMapsStatus) {
|
| - fMipMapsStatus = kAllocated_MipMapsStatus;
|
| + fMipMapsStatus = kAllocated_MipMapsStatus;
|
| }
|
| } else {
|
| const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus;
|
| @@ -26,6 +27,8 @@ void GrTexture::dirtyMipMaps(bool mipMapsDirty) {
|
| if (sizeChanged) {
|
| // This must not be called until after changing fMipMapsStatus.
|
| this->didChangeGpuMemorySize();
|
| + // TODO(http://skbug.com/4548) - The desc and scratch key should be
|
| + // updated to reflect the newly-allocated mipmaps.
|
| }
|
| }
|
| }
|
| @@ -83,8 +86,22 @@ GrSurfaceOrigin resolve_origin(const GrSurfaceDesc& desc) {
|
| //////////////////////////////////////////////////////////////////////////////
|
| GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc)
|
| : INHERITED(gpu, lifeCycle, desc)
|
| - , fMipMapsStatus(kNotAllocated_MipMapsStatus) {
|
| + , fMipMapsStatus(kNotAllocated_MipMapsStatus)
|
| + , fIsMaxMipMapLevelSpecified(false)
|
| + , fMaxMipMapLevel(0) {
|
| + if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) {
|
| + GrScratchKey key;
|
| + GrTexturePriv::ComputeScratchKey(desc, &key);
|
| + this->setScratchKey(key);
|
| + }
|
| + // only make sense if alloc size is pow2
|
| + fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
|
| + fShiftFixedY = 31 - SkCLZ(fDesc.fHeight);
|
| +}
|
|
|
| +GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc,
|
| + bool wasMipMapDataProvided)
|
| + : INHERITED(gpu, lifeCycle, desc) {
|
| if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) {
|
| GrScratchKey key;
|
| GrTexturePriv::ComputeScratchKey(desc, &key);
|
| @@ -93,6 +110,32 @@ GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc)
|
| // only make sense if alloc size is pow2
|
| fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
|
| fShiftFixedY = 31 - SkCLZ(fDesc.fHeight);
|
| +
|
| + if (wasMipMapDataProvided) {
|
| + fMipMapsStatus = kValid_MipMapsStatus;
|
| +
|
| + const uint32_t baseWidth = static_cast<uint32_t>(fDesc.fWidth);
|
| + const uint32_t baseHeight = static_cast<uint32_t>(fDesc.fHeight);
|
| +
|
| + // 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 uint32_t largestAxis = SkTMax(baseWidth, baseHeight);
|
| + const int leadingZeros = SkCLZ(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.
|
| + SkASSERT(significantBits >= 0);
|
| + fMaxMipMapLevel = significantBits;
|
| + fIsMaxMipMapLevelSpecified = true;
|
| + } else {
|
| + fMipMapsStatus = kNotAllocated_MipMapsStatus;
|
| + fMaxMipMapLevel = 0;
|
| + fIsMaxMipMapLevelSpecified = false;
|
| + }
|
| }
|
|
|
| void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* key) {
|
| @@ -101,7 +144,9 @@ void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
|
| GrSurfaceOrigin origin = resolve_origin(desc);
|
| uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag;
|
|
|
| - SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6));
|
| + // make sure desc.fConfig fits in 5 bits
|
| + SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5);
|
| + SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5));
|
| SkASSERT(desc.fSampleCnt < (1 << 8));
|
| SkASSERT(flags < (1 << 10));
|
| SkASSERT(static_cast<int>(origin) < (1 << 8));
|
| @@ -109,5 +154,6 @@ void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
|
| GrScratchKey::Builder builder(key, kType, 3);
|
| builder[0] = desc.fWidth;
|
| builder[1] = desc.fHeight;
|
| - builder[2] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin << 24);
|
| + builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6) | (flags << 14)
|
| + | (origin << 24);
|
| }
|
|
|