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

Unified 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: add new h file to git repo Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/gpu/GrGpuResource.h ('k') | include/gpu/GrTexture.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/gpu/GrResourceKey.h
diff --git a/include/gpu/GrResourceKey.h b/include/gpu/GrResourceKey.h
new file mode 100644
index 0000000000000000000000000000000000000000..d3e82c8e580661709309a622b9cadfe887b56acf
--- /dev/null
+++ b/include/gpu/GrResourceKey.h
@@ -0,0 +1,113 @@
+
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrResourceKey_DEFINED
+#define GrResourceKey_DEFINED
+
+#include "GrTypes.h"
+#include "GrBinHashKey.h"
+
+class GrResourceKey {
+public:
+ static GrCacheID::Domain ScratchDomain() {
+ static const GrCacheID::Domain gDomain = GrCacheID::GenerateDomain();
+ return gDomain;
+ }
+
+ /** Uniquely identifies the GrGpuResource subclass in the key to avoid collisions
+ across resource types. */
+ typedef uint8_t ResourceType;
+
+ /** Flags set by the GrGpuResource subclass. */
+ typedef uint8_t ResourceFlags;
+
+ /** Generate a unique ResourceType */
+ static ResourceType GenerateResourceType();
+
+ /** Creates a key for resource */
+ GrResourceKey(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
+ this->init(id.getDomain(), id.getKey(), type, flags);
+ };
+
+ GrResourceKey(const GrResourceKey& src) { fKey = src.fKey; }
+
+ GrResourceKey() { fKey.reset(); }
+
+ void reset(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
+ this->init(id.getDomain(), id.getKey(), type, flags);
+ }
+
+ uint32_t getHash() const { return fKey.getHash(); }
+
+ bool isScratch() const {
+ return ScratchDomain() ==
+ *reinterpret_cast<const GrCacheID::Domain*>(fKey.getData() +
+ kCacheIDDomainOffset);
+ }
+
+ ResourceType getResourceType() const {
+ return *reinterpret_cast<const ResourceType*>(fKey.getData() +
+ kResourceTypeOffset);
+ }
+
+ ResourceFlags getResourceFlags() const {
+ return *reinterpret_cast<const ResourceFlags*>(fKey.getData() +
+ kResourceFlagsOffset);
+ }
+
+ bool operator==(const GrResourceKey& other) const { return fKey == other.fKey; }
+
+ // A key indicating that the resource is not usable as a scratch resource.
+ static GrResourceKey& NullScratchKey() {
+ static const GrCacheID::Key kBogusKey = { { {0} } };
+ static GrCacheID kBogusID(ScratchDomain(), kBogusKey);
+ static GrResourceKey kNullScratchKey(kBogusID, NoneResourceType(), 0);
+ return kNullScratchKey;
+ }
+
+ bool isNullScratch() const {
+ return this->isScratch() && NoneResourceType() == this->getResourceType();
+ }
+
+private:
+ enum {
+ kCacheIDKeyOffset = 0,
+ kCacheIDDomainOffset = kCacheIDKeyOffset + sizeof(GrCacheID::Key),
+ kResourceTypeOffset = kCacheIDDomainOffset + sizeof(GrCacheID::Domain),
+ kResourceFlagsOffset = kResourceTypeOffset + sizeof(ResourceType),
+ kPadOffset = kResourceFlagsOffset + sizeof(ResourceFlags),
+ kKeySize = SkAlign4(kPadOffset),
+ kPadSize = kKeySize - kPadOffset
+ };
+
+ static ResourceType NoneResourceType() {
+ static const ResourceType gNoneResourceType = GenerateResourceType();
+ return gNoneResourceType;
+ }
+
+ void init(const GrCacheID::Domain domain,
+ const GrCacheID::Key& key,
+ ResourceType type,
+ ResourceFlags flags) {
+ union {
+ uint8_t fKey8[kKeySize];
+ uint32_t fKey32[kKeySize / 4];
+ } keyData;
+
+ uint8_t* k = keyData.fKey8;
+ memcpy(k + kCacheIDKeyOffset, key.fData8, sizeof(GrCacheID::Key));
+ memcpy(k + kCacheIDDomainOffset, &domain, sizeof(GrCacheID::Domain));
+ memcpy(k + kResourceTypeOffset, &type, sizeof(ResourceType));
+ memcpy(k + kResourceFlagsOffset, &flags, sizeof(ResourceFlags));
+ memset(k + kPadOffset, 0, kPadSize);
+ fKey.setKeyData(keyData.fKey32);
+ }
+ GrBinHashKey<kKeySize> fKey;
+};
+
+#endif
« no previous file with comments | « include/gpu/GrGpuResource.h ('k') | include/gpu/GrTexture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698