OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrContext_DEFINED | 8 #ifndef GrContext_DEFINED |
9 #define GrContext_DEFINED | 9 #define GrContext_DEFINED |
10 | 10 |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 * we do set the returnToCache flag. In this way the texture remains | 1114 * we do set the returnToCache flag. In this way the texture remains |
1115 * "locked" in the texture cache until it is freed and recycled in | 1115 * "locked" in the texture cache until it is freed and recycled in |
1116 * GrTexture::internal_dispose. In reality, the texture has been removed | 1116 * GrTexture::internal_dispose. In reality, the texture has been removed |
1117 * from the cache (because this is in AutoScratchTexture) and by not | 1117 * from the cache (because this is in AutoScratchTexture) and by not |
1118 * calling unlockScratchTexture we simply don't re-add it. It will be | 1118 * calling unlockScratchTexture we simply don't re-add it. It will be |
1119 * reattached in GrTexture::internal_dispose. | 1119 * reattached in GrTexture::internal_dispose. |
1120 * | 1120 * |
1121 * Note that the caller is assumed to accept and manage the ref to the | 1121 * Note that the caller is assumed to accept and manage the ref to the |
1122 * returned texture. | 1122 * returned texture. |
1123 */ | 1123 */ |
1124 GrTexture* detach(); | 1124 GrTexture* detach() { |
| 1125 if (NULL == fTexture) { |
| 1126 return NULL; |
| 1127 } |
| 1128 GrTexture* texture = fTexture; |
| 1129 fTexture = NULL; |
| 1130 |
| 1131 // This GrAutoScratchTexture has a ref from lockAndRefScratchTexture, wh
ich we give up now. |
| 1132 // The cache also has a ref which we are lending to the caller of detach
(). When the caller |
| 1133 // lets go of the ref and the ref count goes to 0 internal_dispose will
see this flag is |
| 1134 // set and re-ref the texture, thereby restoring the cache's ref. |
| 1135 SkASSERT(!texture->unique()); |
| 1136 texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_
FlagBit); |
| 1137 texture->unref(); |
| 1138 SkASSERT(texture->getCacheEntry()); |
| 1139 |
| 1140 return texture; |
| 1141 } |
1125 | 1142 |
1126 GrTexture* set(GrContext* context, | 1143 GrTexture* set(GrContext* context, |
1127 const GrTextureDesc& desc, | 1144 const GrTextureDesc& desc, |
1128 GrContext::ScratchTexMatch match = GrContext::kApprox_Scratch
TexMatch) { | 1145 GrContext::ScratchTexMatch match = GrContext::kApprox_Scratch
TexMatch) { |
1129 this->reset(); | 1146 this->reset(); |
1130 | 1147 |
1131 fContext = context; | 1148 fContext = context; |
1132 if (fContext) { | 1149 if (fContext) { |
1133 fTexture = fContext->lockAndRefScratchTexture(desc, match); | 1150 fTexture = fContext->lockAndRefScratchTexture(desc, match); |
1134 if (NULL == fTexture) { | 1151 if (NULL == fTexture) { |
1135 fContext = NULL; | 1152 fContext = NULL; |
1136 } | 1153 } |
1137 return fTexture; | 1154 return fTexture; |
1138 } else { | 1155 } else { |
1139 return NULL; | 1156 return NULL; |
1140 } | 1157 } |
1141 } | 1158 } |
1142 | 1159 |
1143 GrTexture* texture() { return fTexture; } | 1160 GrTexture* texture() { return fTexture; } |
1144 | 1161 |
1145 private: | 1162 private: |
1146 GrContext* fContext; | 1163 GrContext* fContext; |
1147 GrTexture* fTexture; | 1164 GrTexture* fTexture; |
1148 }; | 1165 }; |
1149 | 1166 |
1150 #endif | 1167 #endif |
OLD | NEW |