| 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" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrSurfaceFlag); | 79 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 80 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 80 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
| 81 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; | 81 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; |
| 82 } else { | 82 } else { |
| 83 return desc.fOrigin; | 83 return desc.fOrigin; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 ////////////////////////////////////////////////////////////////////////////// | 88 ////////////////////////////////////////////////////////////////////////////// |
| 89 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc, | 89 GrTexture::GrTexture(GrGpu* gpu, const GrSurfaceDesc& desc, GrSLType samplerType
, |
| 90 GrSLType samplerType, bool wasMipMapDataProvided) | 90 bool wasMipMapDataProvided) |
| 91 : INHERITED(gpu, lifeCycle, desc) | 91 : INHERITED(gpu, desc) |
| 92 , fSamplerType(samplerType) { | 92 , fSamplerType(samplerType) { |
| 93 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) { | |
| 94 GrScratchKey key; | |
| 95 GrTexturePriv::ComputeScratchKey(desc, &key); | |
| 96 this->setScratchKey(key); | |
| 97 } | |
| 98 | |
| 99 if (wasMipMapDataProvided) { | 93 if (wasMipMapDataProvided) { |
| 100 fMipMapsStatus = kValid_MipMapsStatus; | 94 fMipMapsStatus = kValid_MipMapsStatus; |
| 101 fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeigh
t); | 95 fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeigh
t); |
| 102 } else { | 96 } else { |
| 103 fMipMapsStatus = kNotAllocated_MipMapsStatus; | 97 fMipMapsStatus = kNotAllocated_MipMapsStatus; |
| 104 fMaxMipMapLevel = 0; | 98 fMaxMipMapLevel = 0; |
| 105 } | 99 } |
| 106 } | 100 } |
| 107 | 101 |
| 102 void GrTexture::computeScratchKey(GrScratchKey* key) const { |
| 103 if (!GrPixelConfigIsCompressed(fDesc.fConfig)) { |
| 104 GrTexturePriv::ComputeScratchKey(fDesc, key); |
| 105 } |
| 106 } |
| 107 |
| 108 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { | 108 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { |
| 109 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); | 109 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); |
| 110 | 110 |
| 111 GrSurfaceOrigin origin = resolve_origin(desc); | 111 GrSurfaceOrigin origin = resolve_origin(desc); |
| 112 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; | 112 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; |
| 113 | 113 |
| 114 // make sure desc.fConfig fits in 5 bits | 114 // make sure desc.fConfig fits in 5 bits |
| 115 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); | 115 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); |
| 116 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); | 116 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); |
| 117 SkASSERT(desc.fSampleCnt < (1 << 8)); | 117 SkASSERT(desc.fSampleCnt < (1 << 8)); |
| 118 SkASSERT(flags < (1 << 10)); | 118 SkASSERT(flags < (1 << 10)); |
| 119 SkASSERT(static_cast<int>(origin) < (1 << 8)); | 119 SkASSERT(static_cast<int>(origin) < (1 << 8)); |
| 120 | 120 |
| 121 GrScratchKey::Builder builder(key, kType, 3); | 121 GrScratchKey::Builder builder(key, kType, 3); |
| 122 builder[0] = desc.fWidth; | 122 builder[0] = desc.fWidth; |
| 123 builder[1] = desc.fHeight; | 123 builder[1] = desc.fHeight; |
| 124 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6
) | (flags << 14) | 124 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6
) | (flags << 14) |
| 125 | (origin << 24); | 125 | (origin << 24); |
| 126 } | 126 } |
| OLD | NEW |