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 "GrDrawTargetCaps.h" | 10 #include "GrDrawTargetCaps.h" |
11 #include "GrGpu.h" | 11 #include "GrGpu.h" |
| 12 #include "GrResourceKey.h" |
12 #include "GrTexture.h" | 13 #include "GrTexture.h" |
13 #include "GrTexturePriv.h" | 14 #include "GrTexturePriv.h" |
14 | 15 |
15 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { | 16 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { |
16 if (mipMapsDirty) { | 17 if (mipMapsDirty) { |
17 if (kValid_MipMapsStatus == fMipMapsStatus) { | 18 if (kValid_MipMapsStatus == fMipMapsStatus) { |
18 fMipMapsStatus = kAllocated_MipMapsStatus; | 19 fMipMapsStatus = kAllocated_MipMapsStatus; |
19 } | 20 } |
20 } else { | 21 } else { |
21 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; | 22 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 116 } |
116 } | 117 } |
117 } | 118 } |
118 | 119 |
119 ////////////////////////////////////////////////////////////////////////////// | 120 ////////////////////////////////////////////////////////////////////////////// |
120 GrTexture::GrTexture(GrGpu* gpu, bool isWrapped, const GrSurfaceDesc& desc) | 121 GrTexture::GrTexture(GrGpu* gpu, bool isWrapped, const GrSurfaceDesc& desc) |
121 : INHERITED(gpu, isWrapped, desc) | 122 : INHERITED(gpu, isWrapped, desc) |
122 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { | 123 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { |
123 | 124 |
124 if (!isWrapped) { | 125 if (!isWrapped) { |
125 this->setScratchKey(GrTexturePriv::ComputeScratchKey(desc)); | 126 GrScratchKey key; |
| 127 GrTexturePriv::ComputeScratchKey(desc, &key); |
| 128 this->setScratchKey(key); |
126 } | 129 } |
127 // only make sense if alloc size is pow2 | 130 // only make sense if alloc size is pow2 |
128 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); | 131 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); |
129 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); | 132 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); |
130 } | 133 } |
131 | 134 |
132 GrResourceKey GrTexturePriv::ComputeKey(const GrGpu* gpu, | 135 GrResourceKey GrTexturePriv::ComputeKey(const GrGpu* gpu, |
133 const GrTextureParams* params, | 136 const GrTextureParams* params, |
134 const GrSurfaceDesc& desc, | 137 const GrSurfaceDesc& desc, |
135 const GrCacheID& cacheID) { | 138 const GrCacheID& cacheID) { |
136 GrResourceKey::ResourceFlags flags = get_texture_flags(gpu, params, desc); | 139 GrResourceKey::ResourceFlags flags = get_texture_flags(gpu, params, desc); |
137 return GrResourceKey(cacheID, ResourceType(), flags); | 140 return GrResourceKey(cacheID, flags); |
138 } | 141 } |
139 | 142 |
140 GrResourceKey GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc) { | 143 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { |
141 GrCacheID::Key idKey; | 144 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); |
142 // Instead of a client-provided key of the texture contents we create a key
from the | |
143 // descriptor. | |
144 GR_STATIC_ASSERT(sizeof(idKey) >= 16); | |
145 SkASSERT(desc.fHeight < (1 << 16)); | |
146 SkASSERT(desc.fWidth < (1 << 16)); | |
147 idKey.fData32[0] = (desc.fWidth) | (desc.fHeight << 16); | |
148 idKey.fData32[1] = desc.fConfig | desc.fSampleCnt << 16; | |
149 idKey.fData32[2] = desc.fFlags; | |
150 idKey.fData32[3] = resolve_origin(desc); // Only needs 2 bits actually | |
151 static const int kPadSize = sizeof(idKey) - 16; | |
152 GR_STATIC_ASSERT(kPadSize >= 0); | |
153 memset(idKey.fData8 + 16, 0, kPadSize); | |
154 | 145 |
155 GrCacheID cacheID(GrResourceKey::ScratchDomain(), idKey); | 146 GrScratchKey::Builder builder(key, kType, 2); |
156 return GrResourceKey(cacheID, ResourceType(), 0); | 147 |
| 148 GrSurfaceOrigin origin = resolve_origin(desc); |
| 149 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; |
| 150 |
| 151 SkASSERT(desc.fWidth <= SK_MaxU16); |
| 152 SkASSERT(desc.fHeight <= SK_MaxU16); |
| 153 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6)); |
| 154 SkASSERT(desc.fSampleCnt < (1 << 8)); |
| 155 SkASSERT(flags < (1 << 10)); |
| 156 SkASSERT(static_cast<int>(origin) < (1 << 8)); |
| 157 |
| 158 builder[0] = desc.fWidth | (desc.fHeight << 16); |
| 159 builder[1] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin
<< 24); |
157 } | 160 } |
158 | 161 |
159 bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) { | 162 bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) { |
160 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); | 163 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); |
161 } | 164 } |
162 | 165 |
163 bool GrTexturePriv::NeedsBilerp(const GrResourceKey& key) { | 166 bool GrTexturePriv::NeedsBilerp(const GrResourceKey& key) { |
164 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); | 167 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); |
165 } | 168 } |
OLD | NEW |