| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } else { | 44 } else { |
| 45 textureSize = (size_t) fDesc.fWidth * fDesc.fHeight * GrBytesPerPixel(fD
esc.fConfig); | 45 textureSize = (size_t) fDesc.fWidth * fDesc.fHeight * GrBytesPerPixel(fD
esc.fConfig); |
| 46 } | 46 } |
| 47 | 47 |
| 48 if (this->texturePriv().hasMipMaps()) { | 48 if (this->texturePriv().hasMipMaps()) { |
| 49 // We don't have to worry about the mipmaps being a different size than | 49 // We don't have to worry about the mipmaps being a different size than |
| 50 // we'd expect because we never change fDesc.fWidth/fHeight. | 50 // we'd expect because we never change fDesc.fWidth/fHeight. |
| 51 textureSize += textureSize/3; | 51 textureSize += textureSize/3; |
| 52 } | 52 } |
| 53 | 53 |
| 54 SkASSERT(!SkToBool(fDesc.fFlags & kRenderTarget_GrSurfaceFlag)); | |
| 55 SkASSERT(textureSize <= WorseCaseSize(fDesc)); | 54 SkASSERT(textureSize <= WorseCaseSize(fDesc)); |
| 56 | 55 |
| 57 return textureSize; | 56 return textureSize; |
| 58 } | 57 } |
| 59 | 58 |
| 60 void GrTexture::validateDesc() const { | 59 void GrTexture::validateDesc() const { |
| 61 if (this->asRenderTarget()) { | 60 if (this->asRenderTarget()) { |
| 62 // This texture has a render target | 61 // This texture has a render target |
| 63 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrSurfaceFlag)); | 62 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrSurfaceFlag)); |
| 64 SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numColorSamples()); | 63 SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numColorSamples()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 80 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrSurfaceFlag); | 79 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 81 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 80 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
| 82 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; | 81 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; |
| 83 } else { | 82 } else { |
| 84 return desc.fOrigin; | 83 return desc.fOrigin; |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 } | 86 } |
| 88 | 87 |
| 89 ////////////////////////////////////////////////////////////////////////////// | 88 ////////////////////////////////////////////////////////////////////////////// |
| 90 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc, | 89 GrTexture::GrTexture(GrGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, |
| 91 GrSLType samplerType, bool wasMipMapDataProvided) | 90 GrSLType samplerType, bool wasMipMapDataProvided) |
| 92 : INHERITED(gpu, lifeCycle, desc) | 91 : INHERITED(gpu, budgeted, desc) |
| 93 , fSamplerType(samplerType) { | 92 , fSamplerType(samplerType) { |
| 94 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig) && | |
| 95 !desc.fTextureStorageAllocator.fAllocateTextureStorage) { | |
| 96 GrScratchKey key; | |
| 97 GrTexturePriv::ComputeScratchKey(desc, &key); | |
| 98 this->setScratchKey(key); | |
| 99 } | |
| 100 | |
| 101 if (wasMipMapDataProvided) { | 93 if (wasMipMapDataProvided) { |
| 102 fMipMapsStatus = kValid_MipMapsStatus; | 94 fMipMapsStatus = kValid_MipMapsStatus; |
| 103 fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeigh
t); | 95 fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeigh
t); |
| 104 } else { | 96 } else { |
| 105 fMipMapsStatus = kNotAllocated_MipMapsStatus; | 97 fMipMapsStatus = kNotAllocated_MipMapsStatus; |
| 106 fMaxMipMapLevel = 0; | 98 fMaxMipMapLevel = 0; |
| 107 } | 99 } |
| 108 } | 100 } |
| 109 | 101 |
| 102 void GrTexture::initScratchKeyIfNeeded() { |
| 103 if (!this->refsWrappedResources() && !GrPixelConfigIsCompressed(fDesc.fConfi
g) && |
| 104 !fDesc.fTextureStorageAllocator.fAllocateTextureStorage) { |
| 105 GrScratchKey key; |
| 106 GrTexturePriv::ComputeScratchKey(fDesc, &key); |
| 107 this->setScratchKey(key); |
| 108 } |
| 109 } |
| 110 |
| 110 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { | 111 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { |
| 111 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); | 112 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); |
| 112 | 113 |
| 113 GrSurfaceOrigin origin = resolve_origin(desc); | 114 GrSurfaceOrigin origin = resolve_origin(desc); |
| 114 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; | 115 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; |
| 115 | 116 |
| 116 // make sure desc.fConfig fits in 5 bits | 117 // make sure desc.fConfig fits in 5 bits |
| 117 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); | 118 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); |
| 118 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); | 119 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); |
| 119 SkASSERT(desc.fSampleCnt < (1 << 8)); | 120 SkASSERT(desc.fSampleCnt < (1 << 8)); |
| 120 SkASSERT(flags < (1 << 10)); | 121 SkASSERT(flags < (1 << 10)); |
| 121 SkASSERT(static_cast<int>(origin) < (1 << 8)); | 122 SkASSERT(static_cast<int>(origin) < (1 << 8)); |
| 122 | 123 |
| 123 GrScratchKey::Builder builder(key, kType, 3); | 124 GrScratchKey::Builder builder(key, kType, 3); |
| 124 builder[0] = desc.fWidth; | 125 builder[0] = desc.fWidth; |
| 125 builder[1] = desc.fHeight; | 126 builder[1] = desc.fHeight; |
| 126 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6
) | (flags << 14) | 127 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6
) | (flags << 14) |
| 127 | (origin << 24); | 128 | (origin << 24); |
| 128 } | 129 } |
| OLD | NEW |