Chromium Code Reviews| 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 SK_DEFINE_INST_COUNT(GrTexture) | 18 SK_DEFINE_INST_COUNT(GrTexture) |
| 19 | 19 |
| 20 GrTexture::~GrTexture() { | |
|
bsalomon
2013/04/09 13:38:27
This was added to the original change.
| |
| 21 if (NULL != fRenderTarget.get()) { | |
| 22 fRenderTarget.get()->owningTextureDestroyed(); | |
| 23 } | |
| 24 } | |
| 25 | |
| 20 /** | 26 /** |
| 21 * This method allows us to interrupt the normal deletion process and place | 27 * This method allows us to interrupt the normal deletion process and place |
| 22 * textures back in the texture cache when their ref count goes to zero. | 28 * textures back in the texture cache when their ref count goes to zero. |
| 23 */ | 29 */ |
| 24 void GrTexture::internal_dispose() const { | 30 void GrTexture::internal_dispose() const { |
| 25 | 31 |
| 26 if (this->isSetFlag((GrTextureFlags) kReturnToCache_FlagBit) && | 32 if (this->isSetFlag((GrTextureFlags) kReturnToCache_FlagBit) && |
| 27 NULL != this->INHERITED::getContext()) { | 33 NULL != this->INHERITED::getContext()) { |
| 28 GrTexture* nonConstThis = const_cast<GrTexture *>(this); | 34 GrTexture* nonConstThis = const_cast<GrTexture *>(this); |
| 29 this->fRefCnt = 1; // restore ref count to initial setting | 35 this->fRefCnt = 1; // restore ref count to initial setting |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 60 GrContext* context = this->getContext(); | 66 GrContext* context = this->getContext(); |
| 61 if (NULL == context) { | 67 if (NULL == context) { |
| 62 return; | 68 return; |
| 63 } | 69 } |
| 64 context->writeTexturePixels(this, | 70 context->writeTexturePixels(this, |
| 65 left, top, width, height, | 71 left, top, width, height, |
| 66 config, buffer, rowBytes, | 72 config, buffer, rowBytes, |
| 67 pixelOpsFlags); | 73 pixelOpsFlags); |
| 68 } | 74 } |
| 69 | 75 |
| 70 void GrTexture::releaseRenderTarget() { | |
| 71 if (NULL != fRenderTarget) { | |
| 72 GrAssert(fRenderTarget->asTexture() == this); | |
| 73 GrAssert(fDesc.fFlags & kRenderTarget_GrTextureFlagBit); | |
| 74 | |
| 75 fRenderTarget->onTextureReleaseRenderTarget(); | |
| 76 fRenderTarget->unref(); | |
| 77 fRenderTarget = NULL; | |
| 78 | |
| 79 fDesc.fFlags = fDesc.fFlags & | |
| 80 ~(kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit); | |
| 81 fDesc.fSampleCnt = 0; | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 void GrTexture::onRelease() { | 76 void GrTexture::onRelease() { |
| 86 GrAssert(!this->isSetFlag((GrTextureFlags) kReturnToCache_FlagBit)); | 77 GrAssert(!this->isSetFlag((GrTextureFlags) kReturnToCache_FlagBit)); |
| 87 this->releaseRenderTarget(); | |
| 88 | |
| 89 INHERITED::onRelease(); | 78 INHERITED::onRelease(); |
| 90 } | 79 } |
| 91 | 80 |
| 92 void GrTexture::onAbandon() { | 81 void GrTexture::onAbandon() { |
| 93 if (NULL != fRenderTarget) { | 82 if (NULL != fRenderTarget.get()) { |
| 94 fRenderTarget->abandon(); | 83 fRenderTarget->abandon(); |
| 95 } | 84 } |
| 96 | |
| 97 INHERITED::onAbandon(); | 85 INHERITED::onAbandon(); |
| 98 } | 86 } |
| 99 | 87 |
| 100 void GrTexture::validateDesc() const { | 88 void GrTexture::validateDesc() const { |
| 101 if (NULL != this->asRenderTarget()) { | 89 if (NULL != this->asRenderTarget()) { |
| 102 // This texture has a render target | 90 // This texture has a render target |
| 103 GrAssert(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); | 91 GrAssert(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); |
| 104 | 92 |
| 105 if (NULL != this->asRenderTarget()->getStencilBuffer()) { | 93 if (NULL != this->asRenderTarget()->getStencilBuffer()) { |
| 106 GrAssert(0 != (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); | 94 GrAssert(0 != (fDesc.fFlags & kNoStencil_GrTextureFlagBit)); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 return GrResourceKey(cacheID, texture_resource_type(), 0); | 182 return GrResourceKey(cacheID, texture_resource_type(), 0); |
| 195 } | 183 } |
| 196 | 184 |
| 197 bool GrTexture::NeedsResizing(const GrResourceKey& key) { | 185 bool GrTexture::NeedsResizing(const GrResourceKey& key) { |
| 198 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); | 186 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); |
| 199 } | 187 } |
| 200 | 188 |
| 201 bool GrTexture::NeedsFiltering(const GrResourceKey& key) { | 189 bool GrTexture::NeedsFiltering(const GrResourceKey& key) { |
| 202 return SkToBool(key.getResourceFlags() & kFilter_TextureFlag); | 190 return SkToBool(key.getResourceFlags() & kFilter_TextureFlag); |
| 203 } | 191 } |
| OLD | NEW |