| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SK_REF_CNT_EXT_DEBUG_H_ | 5 #ifndef SK_REF_CNT_EXT_DEBUG_H_ |
| 6 #define SK_REF_CNT_EXT_DEBUG_H_ | 6 #define SK_REF_CNT_EXT_DEBUG_H_ |
| 7 | 7 |
| 8 #ifdef SK_REF_CNT_EXT_RELEASE_H_ | 8 #ifdef SK_REF_CNT_EXT_RELEASE_H_ |
| 9 #error Only one SkRefCnt should be used. | 9 #error Only one SkRefCnt should be used. |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 #include <atomic> | |
| 13 | |
| 14 // Alternate implementation of SkRefCnt for Chromium debug builds | 12 // Alternate implementation of SkRefCnt for Chromium debug builds |
| 15 class SK_API SkRefCnt : public SkRefCntBase { | 13 class SK_API SkRefCnt : public SkRefCntBase { |
| 16 public: | 14 public: |
| 17 SkRefCnt() : flags_(0) {} | 15 SkRefCnt() : flags_(0) {} |
| 18 void ref() const { SkASSERT(flags_.load() != AdoptionRequired_Flag); SkRefCntB
ase::ref(); } | 16 void ref() const { SkASSERT(flags_ != AdoptionRequired_Flag); SkRefCntBase::re
f(); } |
| 19 void adopted() const { flags_ |= Adopted_Flag; } | 17 void adopted() const { flags_ |= Adopted_Flag; } |
| 20 void requireAdoption() const { flags_ |= AdoptionRequired_Flag; } | 18 void requireAdoption() const { flags_ |= AdoptionRequired_Flag; } |
| 21 void deref() const { SkRefCntBase::unref(); } | 19 void deref() const { SkRefCntBase::unref(); } |
| 22 private: | 20 private: |
| 23 | |
| 24 enum { | 21 enum { |
| 25 Adopted_Flag = 0x1, | 22 Adopted_Flag = 0x1, |
| 26 AdoptionRequired_Flag = 0x2, | 23 AdoptionRequired_Flag = 0x2, |
| 27 }; | 24 }; |
| 28 | 25 |
| 29 mutable std::atomic<int> flags_; | 26 mutable int flags_; |
| 30 }; | 27 }; |
| 31 | 28 |
| 32 // Bootstrap for Blink's WTF::RefPtr | 29 // Bootstrap for Blink's WTF::RefPtr |
| 33 | 30 |
| 34 namespace WTF { | 31 namespace WTF { |
| 35 inline void adopted(const SkRefCnt* object) { | 32 inline void adopted(const SkRefCnt* object) { |
| 36 if (!object) | 33 if (!object) |
| 37 return; | 34 return; |
| 38 object->adopted(); | 35 object->adopted(); |
| 39 } | 36 } |
| 40 inline void requireAdoption(const SkRefCnt* object) { | 37 inline void requireAdoption(const SkRefCnt* object) { |
| 41 if (!object) | 38 if (!object) |
| 42 return; | 39 return; |
| 43 object->requireAdoption(); | 40 object->requireAdoption(); |
| 44 } | 41 } |
| 45 }; | 42 }; |
| 46 | 43 |
| 47 using WTF::adopted; | 44 using WTF::adopted; |
| 48 using WTF::requireAdoption; | 45 using WTF::requireAdoption; |
| 49 | 46 |
| 50 #endif | 47 #endif |
| 51 | 48 |
| OLD | NEW |