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" |
11 #include "GrDrawTargetCaps.h" | 11 #include "GrDrawTargetCaps.h" |
12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
13 #include "GrRenderTarget.h" | 13 #include "GrRenderTarget.h" |
14 #include "GrResourceCache.h" | 14 #include "GrResourceCache.h" |
15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
16 #include "GrTexturePriv.h" | 16 #include "GrTexturePriv.h" |
17 | 17 |
18 GrTexture::~GrTexture() { | 18 GrTexture::~GrTexture() { |
19 if (fRenderTarget.get()) { | 19 if (fRenderTarget.get()) { |
20 fRenderTarget.get()->owningTextureDestroyed(); | 20 fRenderTarget.get()->owningTextureDestroyed(); |
21 } | 21 } |
22 } | 22 } |
23 | 23 |
| 24 /** |
| 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. |
| 27 */ |
| 28 void GrTexture::internal_dispose() const { |
| 29 if (this->texturePriv().isSetFlag((GrTextureFlags) GrTexture::kReturnToCache
_FlagBit) && |
| 30 this->INHERITED::getContext()) { |
| 31 GrTexture* nonConstThis = const_cast<GrTexture *>(this); |
| 32 this->ref(); // restore ref count to initial setting |
| 33 |
| 34 nonConstThis->texturePriv().resetFlag((GrTextureFlags) kReturnToCache_Fl
agBit); |
| 35 nonConstThis->INHERITED::getContext()->addExistingTextureToCache(nonCons
tThis); |
| 36 |
| 37 // Note: "this" texture might be freed inside addExistingTextureToCache |
| 38 // if it is purged. |
| 39 return; |
| 40 } |
| 41 |
| 42 this->INHERITED::internal_dispose(); |
| 43 } |
| 44 |
24 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { | 45 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { |
25 if (mipMapsDirty) { | 46 if (mipMapsDirty) { |
26 if (kValid_MipMapsStatus == fMipMapsStatus) { | 47 if (kValid_MipMapsStatus == fMipMapsStatus) { |
27 fMipMapsStatus = kAllocated_MipMapsStatus; | 48 fMipMapsStatus = kAllocated_MipMapsStatus; |
28 } | 49 } |
29 } else { | 50 } else { |
30 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; | 51 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; |
31 fMipMapsStatus = kValid_MipMapsStatus; | 52 fMipMapsStatus = kValid_MipMapsStatus; |
32 if (sizeChanged) { | 53 if (sizeChanged) { |
33 // This must not be called until after changing fMipMapsStatus. | 54 // This must not be called until after changing fMipMapsStatus. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 GrContext* context = this->getContext(); | 95 GrContext* context = this->getContext(); |
75 if (NULL == context) { | 96 if (NULL == context) { |
76 return; | 97 return; |
77 } | 98 } |
78 context->writeTexturePixels(this, | 99 context->writeTexturePixels(this, |
79 left, top, width, height, | 100 left, top, width, height, |
80 config, buffer, rowBytes, | 101 config, buffer, rowBytes, |
81 pixelOpsFlags); | 102 pixelOpsFlags); |
82 } | 103 } |
83 | 104 |
| 105 void GrTexture::abandonReleaseCommon() { |
| 106 // In debug builds the resource cache tracks removed/exclusive textures and
has an unref'ed ptr. |
| 107 // After abandon() or release() the resource cache will be unreachable (getC
ontext() == NULL). |
| 108 // So we readd the texture to the cache here so that it is removed from the
exclusive list and |
| 109 // there is no longer an unref'ed ptr to the texture in the cache. |
| 110 if (this->texturePriv().isSetFlag((GrTextureFlags)kReturnToCache_FlagBit)) { |
| 111 SkASSERT(!this->wasDestroyed()); |
| 112 this->ref(); // restores the ref the resource cache gave up when it mar
ked this exclusive. |
| 113 this->texturePriv().resetFlag((GrTextureFlags) kReturnToCache_FlagBit); |
| 114 this->getContext()->addExistingTextureToCache(this); |
| 115 } |
| 116 } |
| 117 |
84 void GrTexture::onRelease() { | 118 void GrTexture::onRelease() { |
| 119 this->abandonReleaseCommon(); |
85 SkASSERT(!this->texturePriv().isSetFlag((GrTextureFlags) kReturnToCache_Flag
Bit)); | 120 SkASSERT(!this->texturePriv().isSetFlag((GrTextureFlags) kReturnToCache_Flag
Bit)); |
86 INHERITED::onRelease(); | 121 INHERITED::onRelease(); |
87 } | 122 } |
88 | 123 |
89 void GrTexture::onAbandon() { | 124 void GrTexture::onAbandon() { |
| 125 this->abandonReleaseCommon(); |
90 if (fRenderTarget.get()) { | 126 if (fRenderTarget.get()) { |
91 fRenderTarget->abandon(); | 127 fRenderTarget->abandon(); |
92 } | 128 } |
93 INHERITED::onAbandon(); | 129 INHERITED::onAbandon(); |
94 } | 130 } |
95 | 131 |
96 void GrTexture::validateDesc() const { | 132 void GrTexture::validateDesc() const { |
97 if (this->asRenderTarget()) { | 133 if (this->asRenderTarget()) { |
98 // This texture has a render target | 134 // This texture has a render target |
99 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); | 135 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return GrResourceKey(cacheID, texture_resource_type(), 0); | 244 return GrResourceKey(cacheID, texture_resource_type(), 0); |
209 } | 245 } |
210 | 246 |
211 bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) { | 247 bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) { |
212 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); | 248 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); |
213 } | 249 } |
214 | 250 |
215 bool GrTexturePriv::NeedsBilerp(const GrResourceKey& key) { | 251 bool GrTexturePriv::NeedsBilerp(const GrResourceKey& key) { |
216 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); | 252 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); |
217 } | 253 } |
OLD | NEW |