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

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: 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
Index: include/gpu/GrResourceKey.h
diff --git a/include/gpu/GrResourceKey.h b/include/gpu/GrResourceKey.h
new file mode 100644
index 0000000000000000000000000000000000000000..800cdcfa0d1b08847392df95091a8d5c58e2ddd0
--- /dev/null
+++ b/include/gpu/GrResourceKey.h
@@ -0,0 +1,119 @@
+
+/*
+ * 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 {
bsalomon 2014/08/27 18:14:33 This is lifted from GrResourceCache.h with the fol
+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);
+ };
+
robertphillips 2014/08/27 19:11:29 one line ?
bsalomon 2014/08/27 20:37:40 Done.
+ GrResourceKey(const GrResourceKey& src) {
+ fKey = src.fKey;
+ }
+
robertphillips 2014/08/27 19:11:29 one line ?
bsalomon 2014/08/27 20:37:39 Done.
+ GrResourceKey() {
+ fKey.reset();
+ }
+
+ void reset(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
+ this->init(id.getDomain(), id.getKey(), type, flags);
+ }
+
robertphillips 2014/08/27 19:11:30 one line ?
bsalomon 2014/08/27 20:37:40 Done.
+ 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.
bsalomon 2014/08/27 18:14:33 here
+ 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 {
bsalomon 2014/08/27 18:14:33 here
+ 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() {
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.
+ static const ResourceType type = GenerateResourceType();
+ return type;
+ }
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698