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

Side by Side Diff: include/core/SkRefCnt.h

Issue 741793002: Add SkNVRefCnt, prune down SkPicture's size (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: notes Created 6 years, 1 month 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
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 SkRefCnt_DEFINED 10 #ifndef SkRefCnt_DEFINED
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 private: 239 private:
240 T* fObj; 240 T* fObj;
241 }; 241 };
242 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i t's templated. :( 242 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i t's templated. :(
243 243
244 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { 244 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> {
245 public: 245 public:
246 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} 246 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {}
247 }; 247 };
248 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) 248 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref)
249 249
tomhudson 2014/11/19 18:59:06 Can we put something like a short version of the C
mtklein 2014/11/19 19:19:14 Done.
250 template <typename Derived>
251 class SkNVRefCnt : SkNoncopyable {
252 public:
253 SkNVRefCnt() : fRefCnt(1) {}
254
255 // Implementation is pretty much the same as SkRefCntBase. All required barr iers are the same:
256 // - unique() needs acquire when it returns true, and no barrier if it ret urns false;
257 // - ref() doesn't need any barrier;
258 // - unref() needs a release barrier, and an acquire if it's going to call delete.
259
260 bool unique() const { return 1 == sk_acquire_load(&fRefCnt); }
261 void ref() const { sk_atomic_inc(&fRefCnt); }
262 void unref() const { if (1 == sk_atomic_dec(&fRefCnt)) { SkDELETE((const De rived*)this); } }
263 private:
264 mutable int32_t fRefCnt;
265 };
266
250 #endif 267 #endif
OLDNEW
« include/core/SkPicture.h ('K') | « include/core/SkPicture.h ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698