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" |
11 #include "GrGpu.h" | 11 #include "GrGpu.h" |
12 #include "GrResourceKey.h" | 12 #include "GrResourceKey.h" |
13 #include "GrRenderTarget.h" | 13 #include "GrRenderTarget.h" |
14 #include "GrRenderTargetPriv.h" | 14 #include "GrRenderTargetPriv.h" |
15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
16 #include "GrTexturePriv.h" | 16 #include "GrTexturePriv.h" |
| 17 #include "GrTypes.h" |
| 18 #include "SkMath.h" |
| 19 #include "SkMipMap.h" |
| 20 #include "SkTypes.h" |
17 | 21 |
18 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { | 22 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { |
19 if (mipMapsDirty) { | 23 if (mipMapsDirty) { |
20 if (kValid_MipMapsStatus == fMipMapsStatus) { | 24 if (kValid_MipMapsStatus == fMipMapsStatus) { |
21 fMipMapsStatus = kAllocated_MipMapsStatus; | 25 fMipMapsStatus = kAllocated_MipMapsStatus; |
22 } | 26 } |
23 } else { | 27 } else { |
24 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; | 28 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; |
25 fMipMapsStatus = kValid_MipMapsStatus; | 29 fMipMapsStatus = kValid_MipMapsStatus; |
26 if (sizeChanged) { | 30 if (sizeChanged) { |
27 // This must not be called until after changing fMipMapsStatus. | 31 // This must not be called until after changing fMipMapsStatus. |
28 this->didChangeGpuMemorySize(); | 32 this->didChangeGpuMemorySize(); |
| 33 // TODO(http://skbug.com/4548) - The desc and scratch key should be |
| 34 // updated to reflect the newly-allocated mipmaps. |
29 } | 35 } |
30 } | 36 } |
31 } | 37 } |
32 | 38 |
33 size_t GrTexture::onGpuMemorySize() const { | 39 size_t GrTexture::onGpuMemorySize() const { |
34 size_t textureSize; | 40 size_t textureSize; |
35 | 41 |
36 if (GrPixelConfigIsCompressed(fDesc.fConfig)) { | 42 if (GrPixelConfigIsCompressed(fDesc.fConfig)) { |
37 textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fD
esc.fHeight); | 43 textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fD
esc.fHeight); |
38 } else { | 44 } else { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrSurfaceFlag); | 80 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrSurfaceFlag); |
75 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 81 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
76 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; | 82 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; |
77 } else { | 83 } else { |
78 return desc.fOrigin; | 84 return desc.fOrigin; |
79 } | 85 } |
80 } | 86 } |
81 } | 87 } |
82 | 88 |
83 ////////////////////////////////////////////////////////////////////////////// | 89 ////////////////////////////////////////////////////////////////////////////// |
84 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc) | 90 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc, |
85 : INHERITED(gpu, lifeCycle, desc) | 91 bool wasMipMapDataProvided) |
86 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { | 92 : INHERITED(gpu, lifeCycle, desc) { |
87 | |
88 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig) && | 93 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig) && |
89 !desc.fTextureStorageAllocator.fAllocateTextureStorage) { | 94 !desc.fTextureStorageAllocator.fAllocateTextureStorage) { |
90 GrScratchKey key; | 95 GrScratchKey key; |
91 GrTexturePriv::ComputeScratchKey(desc, &key); | 96 GrTexturePriv::ComputeScratchKey(desc, &key); |
92 this->setScratchKey(key); | 97 this->setScratchKey(key); |
93 } | 98 } |
| 99 |
| 100 if (wasMipMapDataProvided) { |
| 101 fMipMapsStatus = kValid_MipMapsStatus; |
| 102 fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeigh
t); |
| 103 } else { |
| 104 fMipMapsStatus = kNotAllocated_MipMapsStatus; |
| 105 fMaxMipMapLevel = 0; |
| 106 } |
94 } | 107 } |
95 | 108 |
96 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { | 109 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { |
97 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); | 110 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); |
98 | 111 |
99 GrSurfaceOrigin origin = resolve_origin(desc); | 112 GrSurfaceOrigin origin = resolve_origin(desc); |
100 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; | 113 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; |
101 | 114 |
102 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6)); | 115 // make sure desc.fConfig fits in 5 bits |
| 116 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); |
| 117 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); |
103 SkASSERT(desc.fSampleCnt < (1 << 8)); | 118 SkASSERT(desc.fSampleCnt < (1 << 8)); |
104 SkASSERT(flags < (1 << 10)); | 119 SkASSERT(flags < (1 << 10)); |
105 SkASSERT(static_cast<int>(origin) < (1 << 8)); | 120 SkASSERT(static_cast<int>(origin) < (1 << 8)); |
106 | 121 |
107 GrScratchKey::Builder builder(key, kType, 3); | 122 GrScratchKey::Builder builder(key, kType, 3); |
108 builder[0] = desc.fWidth; | 123 builder[0] = desc.fWidth; |
109 builder[1] = desc.fHeight; | 124 builder[1] = desc.fHeight; |
110 builder[2] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin
<< 24); | 125 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6
) | (flags << 14) |
| 126 | (origin << 24); |
111 } | 127 } |
OLD | NEW |