| 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 "GrTexture.h" | 10 #include "GrTexture.h" |
| 11 | 11 |
| 12 #include "GrContext.h" | 12 #include "GrContext.h" |
| 13 #include "GrDrawTargetCaps.h" | 13 #include "GrDrawTargetCaps.h" |
| 14 #include "GrGpu.h" | 14 #include "GrGpu.h" |
| 15 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
| 16 #include "GrResourceCache.h" | 16 #include "GrResourceCache.h" |
| 17 | 17 |
| 18 GrTexture::~GrTexture() { | 18 GrTexture::~GrTexture() { |
| 19 if (NULL != fRenderTarget.get()) { | 19 if (fRenderTarget.get()) { |
| 20 fRenderTarget.get()->owningTextureDestroyed(); | 20 fRenderTarget.get()->owningTextureDestroyed(); |
| 21 } | 21 } |
| 22 } | 22 } |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * This method allows us to interrupt the normal deletion process and place | 25 * This method allows us to interrupt the normal deletion process and place |
| 26 * textures back in the texture cache when their ref count goes to zero. | 26 * textures back in the texture cache when their ref count goes to zero. |
| 27 */ | 27 */ |
| 28 void GrTexture::internal_dispose() const { | 28 void GrTexture::internal_dispose() const { |
| 29 if (this->impl()->isSetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_F
lagBit) && | 29 if (this->impl()->isSetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_F
lagBit) && |
| 30 NULL != this->INHERITED::getContext()) { | 30 this->INHERITED::getContext()) { |
| 31 GrTexture* nonConstThis = const_cast<GrTexture *>(this); | 31 GrTexture* nonConstThis = const_cast<GrTexture *>(this); |
| 32 this->ref(); // restore ref count to initial setting | 32 this->ref(); // restore ref count to initial setting |
| 33 | 33 |
| 34 nonConstThis->impl()->resetFlag((GrTextureFlags) GrTextureImpl::kReturnT
oCache_FlagBit); | 34 nonConstThis->impl()->resetFlag((GrTextureFlags) GrTextureImpl::kReturnT
oCache_FlagBit); |
| 35 nonConstThis->INHERITED::getContext()->addExistingTextureToCache(nonCons
tThis); | 35 nonConstThis->INHERITED::getContext()->addExistingTextureToCache(nonCons
tThis); |
| 36 | 36 |
| 37 // Note: "this" texture might be freed inside addExistingTextureToCache | 37 // Note: "this" texture might be freed inside addExistingTextureToCache |
| 38 // if it is purged. | 38 // if it is purged. |
| 39 return; | 39 return; |
| 40 } | 40 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 void GrTexture::onRelease() { | 118 void GrTexture::onRelease() { |
| 119 this->abandonReleaseCommon(); | 119 this->abandonReleaseCommon(); |
| 120 SkASSERT(!this->impl()->isSetFlag((GrTextureFlags) GrTextureImpl::kReturnToC
ache_FlagBit)); | 120 SkASSERT(!this->impl()->isSetFlag((GrTextureFlags) GrTextureImpl::kReturnToC
ache_FlagBit)); |
| 121 INHERITED::onRelease(); | 121 INHERITED::onRelease(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void GrTexture::onAbandon() { | 124 void GrTexture::onAbandon() { |
| 125 this->abandonReleaseCommon(); | 125 this->abandonReleaseCommon(); |
| 126 if (NULL != fRenderTarget.get()) { | 126 if (fRenderTarget.get()) { |
| 127 fRenderTarget->abandon(); | 127 fRenderTarget->abandon(); |
| 128 } | 128 } |
| 129 INHERITED::onAbandon(); | 129 INHERITED::onAbandon(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void GrTexture::validateDesc() const { | 132 void GrTexture::validateDesc() const { |
| 133 if (NULL != this->asRenderTarget()) { | 133 if (this->asRenderTarget()) { |
| 134 // This texture has a render target | 134 // This texture has a render target |
| 135 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); | 135 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); |
| 136 | 136 |
| 137 if (NULL != this->asRenderTarget()->getStencilBuffer()) { | 137 if (this->asRenderTarget()->getStencilBuffer()) { |
| 138 SkASSERT(0 != (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); | 138 SkASSERT(0 != (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); |
| 139 } else { | 139 } else { |
| 140 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); | 140 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); |
| 141 } | 141 } |
| 142 | 142 |
| 143 SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numSamples()); | 143 SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numSamples()); |
| 144 } else { | 144 } else { |
| 145 SkASSERT(0 == (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); | 145 SkASSERT(0 == (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); |
| 146 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); | 146 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); |
| 147 SkASSERT(0 == fDesc.fSampleCnt); | 147 SkASSERT(0 == fDesc.fSampleCnt); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 163 * stretched texture should be bilerped. | 163 * stretched texture should be bilerped. |
| 164 */ | 164 */ |
| 165 kBilerp_TextureFlag = 0x2, | 165 kBilerp_TextureFlag = 0x2, |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 namespace { | 168 namespace { |
| 169 GrResourceKey::ResourceFlags get_texture_flags(const GrGpu* gpu, | 169 GrResourceKey::ResourceFlags get_texture_flags(const GrGpu* gpu, |
| 170 const GrTextureParams* params, | 170 const GrTextureParams* params, |
| 171 const GrTextureDesc& desc) { | 171 const GrTextureDesc& desc) { |
| 172 GrResourceKey::ResourceFlags flags = 0; | 172 GrResourceKey::ResourceFlags flags = 0; |
| 173 bool tiled = NULL != params && params->isTiled(); | 173 bool tiled = params && params->isTiled(); |
| 174 if (tiled && !gpu->caps()->npotTextureTileSupport()) { | 174 if (tiled && !gpu->caps()->npotTextureTileSupport()) { |
| 175 if (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight)) { | 175 if (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight)) { |
| 176 flags |= kStretchToPOT_TextureFlag; | 176 flags |= kStretchToPOT_TextureFlag; |
| 177 switch(params->filterMode()) { | 177 switch(params->filterMode()) { |
| 178 case GrTextureParams::kNone_FilterMode: | 178 case GrTextureParams::kNone_FilterMode: |
| 179 break; | 179 break; |
| 180 case GrTextureParams::kBilerp_FilterMode: | 180 case GrTextureParams::kBilerp_FilterMode: |
| 181 case GrTextureParams::kMipMap_FilterMode: | 181 case GrTextureParams::kMipMap_FilterMode: |
| 182 flags |= kBilerp_TextureFlag; | 182 flags |= kBilerp_TextureFlag; |
| 183 break; | 183 break; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 return GrResourceKey(cacheID, texture_resource_type(), 0); | 240 return GrResourceKey(cacheID, texture_resource_type(), 0); |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool GrTextureImpl::NeedsResizing(const GrResourceKey& key) { | 243 bool GrTextureImpl::NeedsResizing(const GrResourceKey& key) { |
| 244 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); | 244 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); |
| 245 } | 245 } |
| 246 | 246 |
| 247 bool GrTextureImpl::NeedsBilerp(const GrResourceKey& key) { | 247 bool GrTextureImpl::NeedsBilerp(const GrResourceKey& key) { |
| 248 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); | 248 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); |
| 249 } | 249 } |
| OLD | NEW |