Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: tests/RefCntTest.cpp

Issue 1769093002: add virtual ~Effect() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: undo comment Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698