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(); |
bsalomon
2015/10/28 16:40:44
Can we add a TODO and bug here that the desc and s
cblume
2015/11/09 22:43:02
Done.
| |
29 } | 30 } |
30 } | 31 } |
31 } | 32 } |
32 | 33 |
33 size_t GrTexture::onGpuMemorySize() const { | 34 size_t GrTexture::onGpuMemorySize() const { |
34 size_t textureSize; | 35 size_t textureSize; |
35 | 36 |
36 if (GrPixelConfigIsCompressed(fDesc.fConfig)) { | 37 if (GrPixelConfigIsCompressed(fDesc.fConfig)) { |
37 textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fD esc.fHeight); | 38 textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fD esc.fHeight); |
38 } else { | 39 } else { |
(...skipping 36 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) { | |
bsalomon
2015/10/28 16:40:44
Shouldn't fMipMapsStatus start as kValid *if* the
cblume
2015/11/09 21:26:32
Done.
| |
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 GrSurfaceOrigin origin = resolve_origin(desc); | 106 GrSurfaceOrigin origin = resolve_origin(desc); |
102 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; | 107 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; |
103 | 108 |
104 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6)); | 109 // make sure desc.fConfig fits in 5 bits |
110 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5); | |
111 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5)); | |
105 SkASSERT(desc.fSampleCnt < (1 << 8)); | 112 SkASSERT(desc.fSampleCnt < (1 << 8)); |
106 SkASSERT(flags < (1 << 10)); | 113 SkASSERT(flags < (1 << 10)); |
107 SkASSERT(static_cast<int>(origin) < (1 << 8)); | 114 SkASSERT(static_cast<int>(origin) < (1 << 8)); |
108 | 115 |
109 GrScratchKey::Builder builder(key, kType, 3); | 116 GrScratchKey::Builder builder(key, kType, 3); |
110 builder[0] = desc.fWidth; | 117 builder[0] = desc.fWidth; |
111 builder[1] = desc.fHeight; | 118 builder[1] = desc.fHeight; |
112 builder[2] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin << 24); | 119 builder[2] = desc.fConfig | desc.fIsMipMapped << 5 | (desc.fSampleCnt << 6) | (flags << 14) |
120 | (origin << 24); | |
113 } | 121 } |
OLD | NEW |