| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrContext.h" | 8 #include "GrContext.h" |
| 9 #include "GrCaps.h" | 9 #include "GrCaps.h" |
| 10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
| 11 #include "GrResourceKey.h" | 11 #include "GrResourceKey.h" |
| 12 #include "GrRenderTarget.h" | 12 #include "GrRenderTarget.h" |
| 13 #include "GrRenderTargetPriv.h" | 13 #include "GrRenderTargetPriv.h" |
| 14 #include "GrTexture.h" | 14 #include "GrTexture.h" |
| 15 #include "GrTexturePriv.h" | 15 #include "GrTexturePriv.h" |
| 16 #include "GrTypes.h" | 16 #include "GrTypes.h" |
| 17 #include "SkMath.h" | 17 #include "SkMath.h" |
| 18 #include "SkMipMap.h" | 18 #include "SkMipMap.h" |
| 19 #include "SkTypes.h" | 19 #include "SkTypes.h" |
| 20 | 20 |
| 21 void GrTexture::dirtyMipMaps(bool mipMapsDirty, bool sRGBCorrect) { | 21 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { |
| 22 if (mipMapsDirty) { | 22 if (mipMapsDirty) { |
| 23 if (kValid_MipMapsStatus == fMipMapsStatus) { | 23 if (kValid_MipMapsStatus == fMipMapsStatus) { |
| 24 fMipMapsStatus = kAllocated_MipMapsStatus; | 24 fMipMapsStatus = kAllocated_MipMapsStatus; |
| 25 } | 25 } |
| 26 } else { | 26 } else { |
| 27 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; | 27 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; |
| 28 fMipMapsStatus = kValid_MipMapsStatus; | 28 fMipMapsStatus = kValid_MipMapsStatus; |
| 29 fMipMapsAreSRGBCorrect = sRGBCorrect; | |
| 30 if (sizeChanged) { | 29 if (sizeChanged) { |
| 31 // This must not be called until after changing fMipMapsStatus. | 30 // This must not be called until after changing fMipMapsStatus. |
| 32 this->didChangeGpuMemorySize(); | 31 this->didChangeGpuMemorySize(); |
| 33 // TODO(http://skbug.com/4548) - The desc and scratch key should be | 32 // TODO(http://skbug.com/4548) - The desc and scratch key should be |
| 34 // updated to reflect the newly-allocated mipmaps. | 33 // updated to reflect the newly-allocated mipmaps. |
| 35 } | 34 } |
| 36 } | 35 } |
| 37 } | 36 } |
| 38 | 37 |
| 39 size_t GrTexture::onGpuMemorySize() const { | 38 size_t GrTexture::onGpuMemorySize() const { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, const GrSurfaceDesc& desc, GrSLType samplerType
, | 89 GrTexture::GrTexture(GrGpu* gpu, const GrSurfaceDesc& desc, GrSLType samplerType
, |
| 91 bool wasMipMapDataProvided) | 90 bool wasMipMapDataProvided) |
| 92 : INHERITED(gpu, desc) | 91 : INHERITED(gpu, desc) |
| 93 , fSamplerType(samplerType) { | 92 , fSamplerType(samplerType) |
| 93 // Gamma treatment is explicitly set after creation via GrTexturePriv |
| 94 , fGammaTreatment(SkSourceGammaTreatment::kIgnore) { |
| 94 if (wasMipMapDataProvided) { | 95 if (wasMipMapDataProvided) { |
| 95 fMipMapsStatus = kValid_MipMapsStatus; | 96 fMipMapsStatus = kValid_MipMapsStatus; |
| 96 fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeigh
t); | 97 fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeigh
t); |
| 97 // At the moment, the CPU code for generating mipmaps doesn't account fo
r sRGB: | |
| 98 fMipMapsAreSRGBCorrect = false; | |
| 99 } else { | 98 } else { |
| 100 fMipMapsStatus = kNotAllocated_MipMapsStatus; | 99 fMipMapsStatus = kNotAllocated_MipMapsStatus; |
| 101 fMaxMipMapLevel = 0; | 100 fMaxMipMapLevel = 0; |
| 102 fMipMapsAreSRGBCorrect = false; | |
| 103 } | 101 } |
| 104 } | 102 } |
| 105 | 103 |
| 106 void GrTexture::computeScratchKey(GrScratchKey* key) const { | 104 void GrTexture::computeScratchKey(GrScratchKey* key) const { |
| 107 if (!GrPixelConfigIsCompressed(fDesc.fConfig)) { | 105 if (!GrPixelConfigIsCompressed(fDesc.fConfig)) { |
| 108 GrTexturePriv::ComputeScratchKey(fDesc, key); | 106 GrTexturePriv::ComputeScratchKey(fDesc, key); |
| 109 } | 107 } |
| 110 } | 108 } |
| 111 | 109 |
| 112 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { | 110 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { |
| 113 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); | 111 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); |
| 114 | 112 |
| 115 GrSurfaceOrigin origin = resolve_origin(desc); | 113 GrSurfaceOrigin origin = resolve_origin(desc); |
| 116 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; | 114 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; |
| 117 | 115 |
| 118 // make sure desc.fConfig fits in 5 bits | 116 // make sure desc.fConfig fits in 5 bits |
| 119 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); | 117 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); |
| 120 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); | 118 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); |
| 121 SkASSERT(desc.fSampleCnt < (1 << 8)); | 119 SkASSERT(desc.fSampleCnt < (1 << 8)); |
| 122 SkASSERT(flags < (1 << 10)); | 120 SkASSERT(flags < (1 << 10)); |
| 123 SkASSERT(static_cast<int>(origin) < (1 << 8)); | 121 SkASSERT(static_cast<int>(origin) < (1 << 8)); |
| 124 | 122 |
| 125 GrScratchKey::Builder builder(key, kType, 3); | 123 GrScratchKey::Builder builder(key, kType, 3); |
| 126 builder[0] = desc.fWidth; | 124 builder[0] = desc.fWidth; |
| 127 builder[1] = desc.fHeight; | 125 builder[1] = desc.fHeight; |
| 128 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6
) | (flags << 14) | 126 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6
) | (flags << 14) |
| 129 | (origin << 24); | 127 | (origin << 24); |
| 130 } | 128 } |
| OLD | NEW |