OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 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 #ifndef GrContext_DEFINED | 10 #ifndef GrContext_DEFINED |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 * "locked" in the texture cache until it is freed and recycled in | 971 * "locked" in the texture cache until it is freed and recycled in |
972 * GrTexture::internal_dispose. In reality, the texture has been removed | 972 * GrTexture::internal_dispose. In reality, the texture has been removed |
973 * from the cache (because this is in AutoScratchTexture) and by not | 973 * from the cache (because this is in AutoScratchTexture) and by not |
974 * calling unlockScratchTexture we simply don't re-add it. It will be | 974 * calling unlockScratchTexture we simply don't re-add it. It will be |
975 * reattached in GrTexture::internal_dispose. | 975 * reattached in GrTexture::internal_dispose. |
976 * | 976 * |
977 * Note that the caller is assumed to accept and manage the ref to the | 977 * Note that the caller is assumed to accept and manage the ref to the |
978 * returned texture. | 978 * returned texture. |
979 */ | 979 */ |
980 GrTexture* detach() { | 980 GrTexture* detach() { |
| 981 if (NULL == fTexture) { |
| 982 return NULL; |
| 983 } |
981 GrTexture* texture = fTexture; | 984 GrTexture* texture = fTexture; |
982 fTexture = NULL; | 985 fTexture = NULL; |
983 | 986 |
984 // This GrAutoScratchTexture has a ref from lockAndRefScratchTexture, wh
ich we give up now. | 987 // This GrAutoScratchTexture has a ref from lockAndRefScratchTexture, wh
ich we give up now. |
985 // The cache also has a ref which we are lending to the caller of detach
(). When the caller | 988 // The cache also has a ref which we are lending to the caller of detach
(). When the caller |
986 // lets go of the ref and the ref count goes to 0 internal_dispose will
see this flag is | 989 // lets go of the ref and the ref count goes to 0 internal_dispose will
see this flag is |
987 // set and re-ref the texture, thereby restoring the cache's ref. | 990 // set and re-ref the texture, thereby restoring the cache's ref. |
988 GrAssert(texture->getRefCnt() > 1); | 991 GrAssert(texture->getRefCnt() > 1); |
989 texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit); | 992 texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit); |
990 texture->unref(); | 993 texture->unref(); |
(...skipping 20 matching lines...) Expand all Loading... |
1011 } | 1014 } |
1012 | 1015 |
1013 GrTexture* texture() { return fTexture; } | 1016 GrTexture* texture() { return fTexture; } |
1014 | 1017 |
1015 private: | 1018 private: |
1016 GrContext* fContext; | 1019 GrContext* fContext; |
1017 GrTexture* fTexture; | 1020 GrTexture* fTexture; |
1018 }; | 1021 }; |
1019 | 1022 |
1020 #endif | 1023 #endif |
OLD | NEW |