| 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 "SkFloatingPoint.h" |
| 17 | 18 |
| 18 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { | 19 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { |
| 19 if (mipMapsDirty) { | 20 if (mipMapsDirty) { |
| 20 if (kValid_MipMapsStatus == fMipMapsStatus) { | 21 if (kValid_MipMapsStatus == fMipMapsStatus) { |
| 21 fMipMapsStatus = kAllocated_MipMapsStatus; | 22 fMipMapsStatus = kAllocated_MipMapsStatus; |
| 22 } | 23 } |
| 23 } else { | 24 } else { |
| 24 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; | 25 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; |
| 25 fMipMapsStatus = kValid_MipMapsStatus; | 26 fMipMapsStatus = kValid_MipMapsStatus; |
| 26 if (sizeChanged) { | 27 if (sizeChanged) { |
| 27 // This must not be called until after changing fMipMapsStatus. | 28 // This must not be called until after changing fMipMapsStatus. |
| 28 this->didChangeGpuMemorySize(); | 29 this->didChangeGpuMemorySize(); |
| 29 } | 30 } |
| 30 } | 31 } |
| 31 } | 32 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 76 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
| 76 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; | 77 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; |
| 77 } else { | 78 } else { |
| 78 return desc.fOrigin; | 79 return desc.fOrigin; |
| 79 } | 80 } |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 | 83 |
| 83 ////////////////////////////////////////////////////////////////////////////// | 84 ////////////////////////////////////////////////////////////////////////////// |
| 84 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc) | 85 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc) |
| 85 : INHERITED(gpu, lifeCycle, desc) | 86 : INHERITED(gpu, lifeCycle, desc) { |
| 86 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { | |
| 87 | 87 |
| 88 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) { | 88 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) { |
| 89 GrScratchKey key; | 89 GrScratchKey key; |
| 90 GrTexturePriv::ComputeScratchKey(desc, &key); | 90 GrTexturePriv::ComputeScratchKey(desc, &key); |
| 91 this->setScratchKey(key); | 91 this->setScratchKey(key); |
| 92 } | 92 } |
| 93 // only make sense if alloc size is pow2 | 93 // only make sense if alloc size is pow2 |
| 94 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); | 94 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); |
| 95 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); | 95 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); |
| 96 if (desc.fIsMipMapped) { |
| 97 fMipMapsStatus = kAllocated_MipMapsStatus; |
| 98 } else { |
| 99 fMipMapsStatus = kNotAllocated_MipMapsStatus; |
| 100 } |
| 96 } | 101 } |
| 97 | 102 |
| 98 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { | 103 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k
ey) { |
| 99 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); | 104 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour
ceType(); |
| 100 | 105 |
| 101 GrScratchKey::Builder builder(key, kType, 2); | |
| 102 | |
| 103 GrSurfaceOrigin origin = resolve_origin(desc); | 106 GrSurfaceOrigin origin = resolve_origin(desc); |
| 104 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; | 107 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; |
| 105 | 108 |
| 106 SkASSERT(desc.fWidth <= SK_MaxU16); | 109 // make sure desc.fConfig fits in 5 bits |
| 107 SkASSERT(desc.fHeight <= SK_MaxU16); | 110 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); |
| 108 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6)); | 111 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); |
| 109 SkASSERT(desc.fSampleCnt < (1 << 8)); | 112 SkASSERT(desc.fSampleCnt < (1 << 8)); |
| 110 SkASSERT(flags < (1 << 10)); | 113 SkASSERT(flags < (1 << 10)); |
| 111 SkASSERT(static_cast<int>(origin) < (1 << 8)); | 114 SkASSERT(static_cast<int>(origin) < (1 << 8)); |
| 112 | 115 |
| 113 builder[0] = desc.fWidth | (desc.fHeight << 16); | 116 GrScratchKey::Builder builder(key, kType, 3); |
| 114 builder[1] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin
<< 24); | 117 builder[0] = desc.fWidth; |
| 118 builder[1] = desc.fHeight; |
| 119 builder[2] = desc.fConfig | desc.fIsMipMapped << 5 | (desc.fSampleCnt << 6)
| (flags << 14) |
| 120 | (origin << 24); |
| 115 } | 121 } |
| OLD | NEW |