OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "SkRefCnt.h" | 8 #include "SkRefCnt.h" |
9 #include "SkThreadUtils.h" | 9 #include "SkThreadUtils.h" |
10 #include "SkTypes.h" | 10 #include "SkTypes.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 REPORTER_ASSERT(reporter, gUnrefCounter == unref); \ | 92 REPORTER_ASSERT(reporter, gUnrefCounter == unref); \ |
93 REPORTER_ASSERT(reporter, gNewCounter == make); \ | 93 REPORTER_ASSERT(reporter, gNewCounter == make); \ |
94 REPORTER_ASSERT(reporter, gDeleteCounter == kill); | 94 REPORTER_ASSERT(reporter, gDeleteCounter == kill); |
95 | 95 |
96 | 96 |
97 class Effect { | 97 class Effect { |
98 public: | 98 public: |
99 Effect() : fRefCnt(1) { | 99 Effect() : fRefCnt(1) { |
100 gNewCounter += 1; | 100 gNewCounter += 1; |
101 } | 101 } |
| 102 virtual ~Effect() {} |
102 | 103 |
103 int fRefCnt; | 104 int fRefCnt; |
104 | 105 |
105 void ref() { | 106 void ref() { |
106 gRefCounter += 1; | 107 gRefCounter += 1; |
107 fRefCnt += 1; | 108 fRefCnt += 1; |
108 } | 109 } |
109 void unref() { | 110 void unref() { |
110 gUnrefCounter += 1; | 111 gUnrefCounter += 1; |
111 | 112 |
(...skipping 16 matching lines...) Expand all Loading... |
128 sk_sp<Effect> fEffect; | 129 sk_sp<Effect> fEffect; |
129 | 130 |
130 const sk_sp<Effect>& get() const { return fEffect; } | 131 const sk_sp<Effect>& get() const { return fEffect; } |
131 | 132 |
132 void set(sk_sp<Effect> value) { | 133 void set(sk_sp<Effect> value) { |
133 fEffect = std::move(value); | 134 fEffect = std::move(value); |
134 } | 135 } |
135 }; | 136 }; |
136 | 137 |
137 struct EffectImpl : public Effect { | 138 struct EffectImpl : public Effect { |
| 139 ~EffectImpl() override {} |
| 140 |
138 static sk_sp<EffectImpl> Create() { | 141 static sk_sp<EffectImpl> Create() { |
139 return sk_sp<EffectImpl>(new EffectImpl); | 142 return sk_sp<EffectImpl>(new EffectImpl); |
140 } | 143 } |
141 int fValue; | 144 int fValue; |
142 }; | 145 }; |
143 static sk_sp<Effect> make_effect() { | 146 static sk_sp<Effect> make_effect() { |
144 auto foo = EffectImpl::Create(); | 147 auto foo = EffectImpl::Create(); |
145 foo->fValue = 42; | 148 foo->fValue = 42; |
146 return std::move(foo); | 149 return std::move(foo); |
147 } | 150 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 sp.reset(rc); | 304 sp.reset(rc); |
302 // We have transfered our ownership over to sp | 305 // We have transfered our ownership over to sp |
303 REPORTER_ASSERT(r, rc->unique()); | 306 REPORTER_ASSERT(r, rc->unique()); |
304 | 307 |
305 rc->ref(); // now "rc" is also an owner | 308 rc->ref(); // now "rc" is also an owner |
306 REPORTER_ASSERT(r, !rc->unique()); | 309 REPORTER_ASSERT(r, !rc->unique()); |
307 | 310 |
308 sp.reset(rc); // this should transfer our ownership over to sp | 311 sp.reset(rc); // this should transfer our ownership over to sp |
309 REPORTER_ASSERT(r, rc->unique()); | 312 REPORTER_ASSERT(r, rc->unique()); |
310 } | 313 } |
OLD | NEW |