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 | |
45 void GrTexturePriv::dirtyMipMaps(bool mipMapsDirty) { | 24 void GrTexturePriv::dirtyMipMaps(bool mipMapsDirty) { |
46 if (mipMapsDirty) { | 25 if (mipMapsDirty) { |
47 if (GrTexture::kValid_MipMapsStatus == fTexture->fMipMapsStatus) { | 26 if (GrTexture::kValid_MipMapsStatus == fTexture->fMipMapsStatus) { |
48 fTexture-> fMipMapsStatus = GrTexture::kAllocated_MipMapsStatus; | 27 fTexture-> fMipMapsStatus = GrTexture::kAllocated_MipMapsStatus; |
49 } | 28 } |
50 } else { | 29 } else { |
51 const bool sizeChanged = GrTexture::kNotAllocated_MipMapsStatus == fText
ure->fMipMapsStatus; | 30 const bool sizeChanged = GrTexture::kNotAllocated_MipMapsStatus == fText
ure->fMipMapsStatus; |
52 fTexture->fMipMapsStatus = GrTexture::kValid_MipMapsStatus; | 31 fTexture->fMipMapsStatus = GrTexture::kValid_MipMapsStatus; |
53 if (sizeChanged) { | 32 if (sizeChanged) { |
54 // This must not be called until after changing fMipMapsStatus. | 33 // This must not be called until after changing fMipMapsStatus. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 GrContext* context = this->getContext(); | 74 GrContext* context = this->getContext(); |
96 if (NULL == context) { | 75 if (NULL == context) { |
97 return; | 76 return; |
98 } | 77 } |
99 context->writeTexturePixels(this, | 78 context->writeTexturePixels(this, |
100 left, top, width, height, | 79 left, top, width, height, |
101 config, buffer, rowBytes, | 80 config, buffer, rowBytes, |
102 pixelOpsFlags); | 81 pixelOpsFlags); |
103 } | 82 } |
104 | 83 |
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 | |
118 void GrTexture::onRelease() { | 84 void GrTexture::onRelease() { |
119 this->abandonReleaseCommon(); | |
120 SkASSERT(!this->texturePriv().isSetFlag((GrTextureFlags) kReturnToCache_Flag
Bit)); | 85 SkASSERT(!this->texturePriv().isSetFlag((GrTextureFlags) kReturnToCache_Flag
Bit)); |
121 INHERITED::onRelease(); | 86 INHERITED::onRelease(); |
122 } | 87 } |
123 | 88 |
124 void GrTexture::onAbandon() { | 89 void GrTexture::onAbandon() { |
125 this->abandonReleaseCommon(); | |
126 if (fRenderTarget.get()) { | 90 if (fRenderTarget.get()) { |
127 fRenderTarget->abandon(); | 91 fRenderTarget->abandon(); |
128 } | 92 } |
129 INHERITED::onAbandon(); | 93 INHERITED::onAbandon(); |
130 } | 94 } |
131 | 95 |
132 void GrTexture::validateDesc() const { | 96 void GrTexture::validateDesc() const { |
133 if (this->asRenderTarget()) { | 97 if (this->asRenderTarget()) { |
134 // This texture has a render target | 98 // This texture has a render target |
135 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); | 99 SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 return GrResourceKey(cacheID, texture_resource_type(), 0); | 208 return GrResourceKey(cacheID, texture_resource_type(), 0); |
245 } | 209 } |
246 | 210 |
247 bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) { | 211 bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) { |
248 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); | 212 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag); |
249 } | 213 } |
250 | 214 |
251 bool GrTexturePriv::NeedsBilerp(const GrResourceKey& key) { | 215 bool GrTexturePriv::NeedsBilerp(const GrResourceKey& key) { |
252 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); | 216 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag); |
253 } | 217 } |
OLD | NEW |