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

Side by Side Diff: include/gpu/GrResourceKey.h

Issue 510053003: Make textures register with GrResourceCache2 as scratch. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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 /*
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 GrResourceKey_DEFINED
10 #define GrResourceKey_DEFINED
11
12 #include "GrTypes.h"
13 #include "GrBinHashKey.h"
14
15 class GrResourceKey {
bsalomon 2014/08/27 18:14:33 This is lifted from GrResourceCache.h with the fol
16 public:
17 static GrCacheID::Domain ScratchDomain() {
18 static const GrCacheID::Domain gDomain = GrCacheID::GenerateDomain();
19 return gDomain;
20 }
21
22 /** Uniquely identifies the GrGpuResource subclass in the key to avoid colli sions
23 across resource types. */
24 typedef uint8_t ResourceType;
25
26 /** Flags set by the GrGpuResource subclass. */
27 typedef uint8_t ResourceFlags;
28
29 /** Generate a unique ResourceType */
30 static ResourceType GenerateResourceType();
31
32 /** Creates a key for resource */
33 GrResourceKey(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
34 this->init(id.getDomain(), id.getKey(), type, flags);
35 };
36
robertphillips 2014/08/27 19:11:29 one line ?
bsalomon 2014/08/27 20:37:40 Done.
37 GrResourceKey(const GrResourceKey& src) {
38 fKey = src.fKey;
39 }
40
robertphillips 2014/08/27 19:11:29 one line ?
bsalomon 2014/08/27 20:37:39 Done.
41 GrResourceKey() {
42 fKey.reset();
43 }
44
45 void reset(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
46 this->init(id.getDomain(), id.getKey(), type, flags);
47 }
48
robertphillips 2014/08/27 19:11:30 one line ?
bsalomon 2014/08/27 20:37:40 Done.
49 uint32_t getHash() const {
50 return fKey.getHash();
51 }
52
53 bool isScratch() const {
54 return ScratchDomain() ==
55 *reinterpret_cast<const GrCacheID::Domain*>(fKey.getData() +
56 kCacheIDDomainOffset);
57 }
58
59 ResourceType getResourceType() const {
60 return *reinterpret_cast<const ResourceType*>(fKey.getData() +
61 kResourceTypeOffset);
62 }
63
64 ResourceFlags getResourceFlags() const {
65 return *reinterpret_cast<const ResourceFlags*>(fKey.getData() +
66 kResourceFlagsOffset);
67 }
68
69 bool operator==(const GrResourceKey& other) const { return fKey == other.fKe y; }
70
71 // A key indicating that the resource is not usable as a scratch resource.
bsalomon 2014/08/27 18:14:33 here
72 static GrResourceKey& NullScratchKey() {
73 static const GrCacheID::Key kBogusKey = {0};
74 static GrCacheID kBogusID(ScratchDomain(), kBogusKey);
75 static GrResourceKey kNullScratchKey(kBogusID, NoneResourceType(), 0);
76 return kNullScratchKey;
77 }
78
79 bool isNullScratch() const {
bsalomon 2014/08/27 18:14:33 here
80 return this->isScratch() && NoneResourceType() == this->getResourceType( );
81 }
82
83 private:
84 enum {
85 kCacheIDKeyOffset = 0,
86 kCacheIDDomainOffset = kCacheIDKeyOffset + sizeof(GrCacheID::Key),
87 kResourceTypeOffset = kCacheIDDomainOffset + sizeof(GrCacheID::Domain),
88 kResourceFlagsOffset = kResourceTypeOffset + sizeof(ResourceType),
89 kPadOffset = kResourceFlagsOffset + sizeof(ResourceFlags),
90 kKeySize = SkAlign4(kPadOffset),
91 kPadSize = kKeySize - kPadOffset
92 };
93
94 static ResourceType NoneResourceType() {
bsalomon 2014/08/27 18:14:33 here
robertphillips 2014/08/27 19:11:29 type -> gNoneResourceType ?
bsalomon 2014/08/27 20:37:39 Done.
95 static const ResourceType type = GenerateResourceType();
96 return type;
97 }
98
99 void init(const GrCacheID::Domain domain,
100 const GrCacheID::Key& key,
101 ResourceType type,
102 ResourceFlags flags) {
103 union {
104 uint8_t fKey8[kKeySize];
105 uint32_t fKey32[kKeySize / 4];
106 } keyData;
107
108 uint8_t* k = keyData.fKey8;
109 memcpy(k + kCacheIDKeyOffset, key.fData8, sizeof(GrCacheID::Key));
110 memcpy(k + kCacheIDDomainOffset, &domain, sizeof(GrCacheID::Domain));
111 memcpy(k + kResourceTypeOffset, &type, sizeof(ResourceType));
112 memcpy(k + kResourceFlagsOffset, &flags, sizeof(ResourceFlags));
113 memset(k + kPadOffset, 0, kPadSize);
114 fKey.setKeyData(keyData.fKey32);
115 }
116 GrBinHashKey<kKeySize> fKey;
117 };
118
119 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698