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

Side by Side Diff: src/gpu/GrGpuResourceCacheAccess.h

Issue 703303003: Add GrGpuResource::CacheAccess (Closed) Base URL: https://skia.googlesource.com/skia.git@nohash
Patch Set: fix warning 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
« no previous file with comments | « src/gpu/GrGpuResource.cpp ('k') | src/gpu/GrResourceCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #ifndef GrGpuResourceCacheAccess_DEFINED
10 #define GrGpuResourceCacheAccess_DEFINED
11
12 #include "GrGpuResource.h"
13
14 /**
15 * This class allows code internal to Skia privileged access to manage the cache keys of a
16 * GrGpuResource object.
17 */
18 class GrGpuResource::CacheAccess {
19 public:
20 /**
21 * Sets a content key for the resource. If the resource was previously cache d as scratch it will
22 * be converted to a content resource. Currently this may only be called onc e per resource. It
23 * fails if there is already a resource with the same content key. TODO: mak e this supplant the
24 * resource that currently is using the content key, allow resources' conten t keys to change,
25 * and allow removal of a content key to convert a resource back to scratch.
26 */
27 bool setContentKey(const GrResourceKey& contentKey) {
28 return fResource->setContentKey(contentKey);
29 }
30
31 /**
32 * Used by legacy cache to attach a cache entry. This is to be removed soon.
33 */
34 void setCacheEntry(GrResourceCacheEntry* cacheEntry) {
35 // GrResourceCache never changes the cacheEntry once one has been added.
36 SkASSERT(NULL == cacheEntry || NULL == fResource->fCacheEntry);
37 fResource->fCacheEntry = cacheEntry;
38 }
39
40 /**
41 * Is the resource in the legacy cache? This is to be removed soon.
42 */
43 bool isInCache() const { return SkToBool(fResource->fCacheEntry); }
44
45 /**
46 * Returns the cache entry for the legacy cache. This is to be removed soon.
47 */
48 GrResourceCacheEntry* getCacheEntry() const { return fResource->fCacheEntry; }
49
50 /**
51 * Is the resource currently cached as scratch? This means it has a valid sc ratch key and does
52 * not have a content key.
53 */
54 bool isScratch() const {
55 SkASSERT(fResource->fScratchKey.isScratch());
56 return NULL == this->getContentKey() && !fResource->fScratchKey.isNullSc ratch();
57 }
58
59 /**
60 * If this resource can be used as a scratch resource this returns a valid s cratch key.
61 * Otherwise it returns a key for which isNullScratch is true. The resource may currently be
62 * used as content resource rather than scratch. Check isScratch().
63 */
64 const GrResourceKey& getScratchKey() const { return fResource->fScratchKey; }
65
66 /**
67 * If the resource is currently cached by a content key, the key is returned , otherwise NULL.
68 */
69 const GrResourceKey* getContentKey() const {
70 if (fResource->fContentKeySet) {
71 return &fResource->fContentKey;
72 }
73 return NULL;
74 }
75
76 private:
77 CacheAccess(GrGpuResource* resource) : fResource(resource) { }
78 CacheAccess(const CacheAccess& that) : fResource(that.fResource) { }
79 CacheAccess& operator=(const CacheAccess&); // unimpl
80
81 // No taking addresses of this type.
82 const CacheAccess* operator&() const;
83 CacheAccess* operator&();
84
85 GrGpuResource* fResource;
86
87 friend class GrGpuResource; // to construct/copy this type.
88 };
89
90 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc ess(this); }
91
92 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const {
93 return CacheAccess(const_cast<GrGpuResource*>(this));
94 }
95
96 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrGpuResource.cpp ('k') | src/gpu/GrResourceCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698