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

Side by Side Diff: src/core/SkCachedData.h

Issue 592843003: Add SkCachedData and use it for SkMipMap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: uses low-bit of refcnt to known when we're in the cache Created 6 years, 2 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkCachedData_DEFINED
9 #define SkCachedData_DEFINED
10
11 #include "SkTypes.h"
12
13 class SkDiscardableMemory;
14
15 class SkCachedData : ::SkNoncopyable {
16 public:
17 static SkCachedData* Create(size_t bytes, SkDiscardableMemory* = NULL);
18
19 virtual ~SkCachedData() {}
20
21 size_t size() const { return fSize; }
22 const void* data() const { return fData; }
23
24 void* writable_data() { return fData; }
25
26 void ref();
27 void unref();
28
29 int testing_only_getRefCnt() const { return fRefCnt >> 1; }
30 bool testing_only_isInCache() const { return fRefCnt & 1; }
31
32 protected:
33 SkCachedData(void* data, size_t size);
34
35 virtual void onLock() = 0; // called when owner count rises above 1
36 virtual void onUnlock() = 0; // called when owner count falls back to 1
37
38 void setData(void* data) { fData = data; }
39
40 private:
41 void* fData;
42 size_t fSize;
43 int32_t fRefCnt; // low-bit means we're owned by the cache
44
45 void lock() {
46 this->onLock();
47 }
48
49 void unlock() {
50 this->onUnlock();
51 fData = NULL; // signal that we're unlocked
52 }
53
54 public:
55 void ref_from_cache();
56 void unref_from_cache();
57 };
58
59 #endif
OLDNEW
« no previous file with comments | « gyp/tests.gypi ('k') | src/core/SkCachedData.cpp » ('j') | src/core/SkCachedData.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698