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 | 9 |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 void GrTexture::onAbandon() { | 61 void GrTexture::onAbandon() { |
62 if (fRenderTarget.get()) { | 62 if (fRenderTarget.get()) { |
63 fRenderTarget->abandon(); | 63 fRenderTarget->abandon(); |
64 } | 64 } |
65 INHERITED::onAbandon(); | 65 INHERITED::onAbandon(); |
66 } | 66 } |
67 | 67 |
68 void GrTexture::validateDesc() const { | 68 void GrTexture::validateDesc() const { |
69 if (this->asRenderTarget()) { | 69 if (this->asRenderTarget()) { |
70 // This texture has a render target | 70 // This texture has a render target |
71 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); | 71 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrSurfaceFlag)); |
72 | 72 |
73 if (this->asRenderTarget()->getStencilBuffer()) { | 73 if (this->asRenderTarget()->getStencilBuffer()) { |
74 SkASSERT(0 != (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); | 74 SkASSERT(0 != (fDesc.fFlags & kNoStencil_GrSurfaceFlag)); |
75 } else { | 75 } else { |
76 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); | 76 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrSurfaceFlag)); |
77 } | 77 } |
78 | 78 |
79 SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numSamples()); | 79 SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numSamples()); |
80 } else { | 80 } else { |
81 SkASSERT(0 == (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); | 81 SkASSERT(0 == (fDesc.fFlags & kRenderTarget_GrSurfaceFlag)); |
82 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); | 82 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrSurfaceFlag)); |
83 SkASSERT(0 == fDesc.fSampleCnt); | 83 SkASSERT(0 == fDesc.fSampleCnt); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 ////////////////////////////////////////////////////////////////////////////// | 87 ////////////////////////////////////////////////////////////////////////////// |
88 | 88 |
89 // These flags need to fit in a GrResourceKey::ResourceFlags so they can be fold
ed into the texture | 89 // These flags need to fit in a GrResourceKey::ResourceFlags so they can be fold
ed into the texture |
90 // key | 90 // key |
91 enum TextureFlags { | 91 enum TextureFlags { |
92 /** | 92 /** |
93 * The kStretchToPOT bit is set when the texture is NPOT and is being repeat
ed but the | 93 * The kStretchToPOT bit is set when the texture is NPOT and is being repeat
ed but the |
94 * hardware doesn't support that feature. | 94 * hardware doesn't support that feature. |
95 */ | 95 */ |
96 kStretchToPOT_TextureFlag = 0x1, | 96 kStretchToPOT_TextureFlag = 0x1, |
97 /** | 97 /** |
98 * The kBilerp bit can only be set when the kStretchToPOT flag is set and in
dicates whether the | 98 * The kBilerp bit can only be set when the kStretchToPOT flag is set and in
dicates whether the |
99 * stretched texture should be bilerped. | 99 * stretched texture should be bilerped. |
100 */ | 100 */ |
101 kBilerp_TextureFlag = 0x2, | 101 kBilerp_TextureFlag = 0x2, |
102 }; | 102 }; |
103 | 103 |
104 namespace { | 104 namespace { |
105 GrResourceKey::ResourceFlags get_texture_flags(const GrGpu* gpu, | 105 GrResourceKey::ResourceFlags get_texture_flags(const GrGpu* gpu, |
106 const GrTextureParams* params, | 106 const GrTextureParams* params, |
107 const GrTextureDesc& desc) { | 107 const GrSurfaceDesc& desc) { |
108 GrResourceKey::ResourceFlags flags = 0; | 108 GrResourceKey::ResourceFlags flags = 0; |
109 bool tiled = params && params->isTiled(); | 109 bool tiled = params && params->isTiled(); |
110 if (tiled && !gpu->caps()->npotTextureTileSupport()) { | 110 if (tiled && !gpu->caps()->npotTextureTileSupport()) { |
111 if (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight)) { | 111 if (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight)) { |
112 flags |= kStretchToPOT_TextureFlag; | 112 flags |= kStretchToPOT_TextureFlag; |
113 switch(params->filterMode()) { | 113 switch(params->filterMode()) { |
114 case GrTextureParams::kNone_FilterMode: | 114 case GrTextureParams::kNone_FilterMode: |
115 break; | 115 break; |
116 case GrTextureParams::kBilerp_FilterMode: | 116 case GrTextureParams::kBilerp_FilterMode: |
117 case GrTextureParams::kMipMap_FilterMode: | 117 case GrTextureParams::kMipMap_FilterMode: |
118 flags |= kBilerp_TextureFlag; | 118 flags |= kBilerp_TextureFlag; |
119 break; | 119 break; |
120 } | 120 } |
121 } | 121 } |
122 } | 122 } |
123 return flags; | 123 return flags; |
124 } | 124 } |
125 | 125 |
126 // FIXME: This should be refactored with the code in gl/GrGpuGL.cpp. | 126 // FIXME: This should be refactored with the code in gl/GrGpuGL.cpp. |
127 GrSurfaceOrigin resolve_origin(const GrTextureDesc& desc) { | 127 GrSurfaceOrigin resolve_origin(const GrSurfaceDesc& desc) { |
128 // By default, GrRenderTargets are GL's normal orientation so that they | 128 // By default, GrRenderTargets are GL's normal orientation so that they |
129 // can be drawn to by the outside world without the client having | 129 // can be drawn to by the outside world without the client having |
130 // to render upside down. | 130 // to render upside down. |
131 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrTextureFlagBit); | 131 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrSurfaceFlag); |
132 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 132 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
133 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; | 133 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; |
134 } else { | 134 } else { |
135 return desc.fOrigin; | 135 return desc.fOrigin; |
136 } | 136 } |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 ////////////////////////////////////////////////////////////////////////////// | 140 ////////////////////////////////////////////////////////////////////////////// |
141 GrTexture::GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) | 141 GrTexture::GrTexture(GrGpu* gpu, bool isWrapped, const GrSurfaceDesc& desc) |
142 : INHERITED(gpu, isWrapped, desc) | 142 : INHERITED(gpu, isWrapped, desc) |
143 , fRenderTarget(NULL) | 143 , fRenderTarget(NULL) |
144 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { | 144 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { |
145 this->setScratchKey(GrTexturePriv::ComputeScratchKey(desc)); | 145 this->setScratchKey(GrTexturePriv::ComputeScratchKey(desc)); |
146 // only make sense if alloc size is pow2 | 146 // only make sense if alloc size is pow2 |
147 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); | 147 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); |
148 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); | 148 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); |
149 } | 149 } |
150 | 150 |
151 GrResourceKey GrTexturePriv::ComputeKey(const GrGpu* gpu, | 151 GrResourceKey GrTexturePriv::ComputeKey(const GrGpu* gpu, |
152 const GrTextureParams* params, | 152 const GrTextureParams* params, |
153 const GrTextureDesc& desc, | 153 const GrSurfaceDesc& desc, |
154 const GrCacheID& cacheID) { | 154 const GrCacheID& cacheID) { |
155 GrResourceKey::ResourceFlags flags = get_texture_flags(gpu, params, desc); | 155 GrResourceKey::ResourceFlags flags = get_texture_flags(gpu, params, desc); |
156 return GrResourceKey(cacheID, ResourceType(), flags); | 156 return GrResourceKey(cacheID, ResourceType(), flags); |
157 } | 157 } |
158 | 158 |
159 GrResourceKey GrTexturePriv::ComputeScratchKey(const GrTextureDesc& desc) { | 159 GrResourceKey GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc) { |
160 GrCacheID::Key idKey; | 160 GrCacheID::Key idKey; |
161 // Instead of a client-provided key of the texture contents we create a key
from the | 161 // Instead of a client-provided key of the texture contents we create a key
from the |
162 // descriptor. | 162 // descriptor. |
163 GR_STATIC_ASSERT(sizeof(idKey) >= 16); | 163 GR_STATIC_ASSERT(sizeof(idKey) >= 16); |
164 SkASSERT(desc.fHeight < (1 << 16)); | 164 SkASSERT(desc.fHeight < (1 << 16)); |
165 SkASSERT(desc.fWidth < (1 << 16)); | 165 SkASSERT(desc.fWidth < (1 << 16)); |
166 idKey.fData32[0] = (desc.fWidth) | (desc.fHeight << 16); | 166 idKey.fData32[0] = (desc.fWidth) | (desc.fHeight << 16); |
167 idKey.fData32[1] = desc.fConfig | desc.fSampleCnt << 16; | 167 idKey.fData32[1] = desc.fConfig | desc.fSampleCnt << 16; |
168 idKey.fData32[2] = desc.fFlags; | 168 idKey.fData32[2] = desc.fFlags; |
169 idKey.fData32[3] = resolve_origin(desc); // Only needs 2 bits actually | 169 idKey.fData32[3] = resolve_origin(desc); // Only needs 2 bits actually |
170 static const int kPadSize = sizeof(idKey) - 16; | 170 static const int kPadSize = sizeof(idKey) - 16; |
171 GR_STATIC_ASSERT(kPadSize >= 0); | 171 GR_STATIC_ASSERT(kPadSize >= 0); |
172 memset(idKey.fData8 + 16, 0, kPadSize); | 172 memset(idKey.fData8 + 16, 0, kPadSize); |
173 | 173 |
174 GrCacheID cacheID(GrResourceKey::ScratchDomain(), idKey); | 174 GrCacheID cacheID(GrResourceKey::ScratchDomain(), idKey); |
175 return GrResourceKey(cacheID, ResourceType(), 0); | 175 return GrResourceKey(cacheID, ResourceType(), 0); |
176 } | 176 } |
177 | 177 |
178 bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) { | 178 bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) { |
179 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); | 179 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); |
180 } | 180 } |
181 | 181 |
182 bool GrTexturePriv::NeedsBilerp(const GrResourceKey& key) { | 182 bool GrTexturePriv::NeedsBilerp(const GrResourceKey& key) { |
183 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); | 183 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); |
184 } | 184 } |
OLD | NEW |