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) { | 21 void GrTexture::dirtyMipMaps(bool mipMapsDirty, bool sRGBCorrect) { |
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; |
29 if (sizeChanged) { | 30 if (sizeChanged) { |
30 // This must not be called until after changing fMipMapsStatus. | 31 // This must not be called until after changing fMipMapsStatus. |
31 this->didChangeGpuMemorySize(); | 32 this->didChangeGpuMemorySize(); |
32 // TODO(http://skbug.com/4548) - The desc and scratch key should be | 33 // TODO(http://skbug.com/4548) - The desc and scratch key should be |
33 // updated to reflect the newly-allocated mipmaps. | 34 // updated to reflect the newly-allocated mipmaps. |
34 } | 35 } |
35 } | 36 } |
36 } | 37 } |
37 | 38 |
38 size_t GrTexture::onGpuMemorySize() const { | 39 size_t GrTexture::onGpuMemorySize() const { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 87 } |
87 | 88 |
88 ////////////////////////////////////////////////////////////////////////////// | 89 ////////////////////////////////////////////////////////////////////////////// |
89 GrTexture::GrTexture(GrGpu* gpu, const GrSurfaceDesc& desc, GrSLType samplerType
, | 90 GrTexture::GrTexture(GrGpu* gpu, const GrSurfaceDesc& desc, GrSLType samplerType
, |
90 bool wasMipMapDataProvided) | 91 bool wasMipMapDataProvided) |
91 : INHERITED(gpu, desc) | 92 : INHERITED(gpu, desc) |
92 , fSamplerType(samplerType) { | 93 , fSamplerType(samplerType) { |
93 if (wasMipMapDataProvided) { | 94 if (wasMipMapDataProvided) { |
94 fMipMapsStatus = kValid_MipMapsStatus; | 95 fMipMapsStatus = kValid_MipMapsStatus; |
95 fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeigh
t); | 96 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; |
96 } else { | 99 } else { |
97 fMipMapsStatus = kNotAllocated_MipMapsStatus; | 100 fMipMapsStatus = kNotAllocated_MipMapsStatus; |
98 fMaxMipMapLevel = 0; | 101 fMaxMipMapLevel = 0; |
| 102 fMipMapsAreSRGBCorrect = false; |
99 } | 103 } |
100 } | 104 } |
101 | 105 |
102 void GrTexture::computeScratchKey(GrScratchKey* key) const { | 106 void GrTexture::computeScratchKey(GrScratchKey* key) const { |
103 if (!GrPixelConfigIsCompressed(fDesc.fConfig)) { | 107 if (!GrPixelConfigIsCompressed(fDesc.fConfig)) { |
104 GrTexturePriv::ComputeScratchKey(fDesc, key); | 108 GrTexturePriv::ComputeScratchKey(fDesc, key); |
105 } | 109 } |
106 } | 110 } |
107 | 111 |
108 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { | 112 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { |
109 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); | 113 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); |
110 | 114 |
111 GrSurfaceOrigin origin = resolve_origin(desc); | 115 GrSurfaceOrigin origin = resolve_origin(desc); |
112 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; | 116 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; |
113 | 117 |
114 // make sure desc.fConfig fits in 5 bits | 118 // make sure desc.fConfig fits in 5 bits |
115 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); | 119 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); |
116 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); | 120 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); |
117 SkASSERT(desc.fSampleCnt < (1 << 8)); | 121 SkASSERT(desc.fSampleCnt < (1 << 8)); |
118 SkASSERT(flags < (1 << 10)); | 122 SkASSERT(flags < (1 << 10)); |
119 SkASSERT(static_cast<int>(origin) < (1 << 8)); | 123 SkASSERT(static_cast<int>(origin) < (1 << 8)); |
120 | 124 |
121 GrScratchKey::Builder builder(key, kType, 3); | 125 GrScratchKey::Builder builder(key, kType, 3); |
122 builder[0] = desc.fWidth; | 126 builder[0] = desc.fWidth; |
123 builder[1] = desc.fHeight; | 127 builder[1] = desc.fHeight; |
124 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6
) | (flags << 14) | 128 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6
) | (flags << 14) |
125 | (origin << 24); | 129 | (origin << 24); |
126 } | 130 } |
OLD | NEW |