Revert "Add storage on the surface for its last render task"
This reverts commit ca5b36c474476c20805fd643a1abd1081b469be5.
Reason for revert: This may be blocking the Chrome roll
Original change's description:
> Add storage on the surface for its last render task
>
> Let's land this and see if it gets us back to baseline on the
> lastRenderTask regression from the bug. If it doesn't, we'll revert it
> since the extra complexity won't have been worth it.
>
> Bug: skia:10372
> Change-Id: I9d5ae93435b833d575afdc7f219dc8e7c453c92b
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297836
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Adlai Holler <adlai@google.com>
TBR=robertphillips@google.com,adlai@google.com
Change-Id: Id418d042d1123d946cd99b7b1ba438211cb628ec
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:10372
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299763
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrHashMapWithCache.h b/src/gpu/GrHashMapWithCache.h
new file mode 100644
index 0000000..8a24ecc
--- /dev/null
+++ b/src/gpu/GrHashMapWithCache.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrHashMapWithCache_DEFINED
+#define GrHashMapWithCache_DEFINED
+
+#include "include/private/SkChecksum.h"
+#include "include/private/SkNoncopyable.h"
+#include "include/private/SkTHash.h"
+
+// Cheaper than SkGoodHash and good enough for UniqueID tables.
+struct GrCheapHash {
+ uint32_t operator()(uint32_t val) {
+ return SkChecksum::CheapMix(val);
+ }
+};
+
+/** A hash map that caches the most recently accessed entry.
+ The API is a subset of SkHashMap, and you must provide a
+ sentinel key that will never be present, such as SK_InvalidUniqueID.
+
+ KeyTraits must have:
+ - static K GetInvalidKey()
+*/
+template <typename K, typename V, typename KeyTraits, typename HashT = SkGoodHash>
+class GrHashMapWithCache : public SkNoncopyable {
+public:
+ // How many key/value pairs are in the table?
+ int count() const { return fMap.count(); }
+
+ // Approximately how many bytes of memory do we use beyond sizeof(*this)?
+ size_t approxBytesUsed() const { return fMap.approxBytesUsed(); }
+
+ // N.B. The pointers returned by set() and find() are valid only until the next call to set().
+
+ // If there is key/value entry in the table with this key, return a pointer to the value.
+ // If not, return null.
+ const V* find(const K& key) const {
+ if (key != fLastKey) {
+ fLastKey = key;
+ fLastValue = fMap.find(key);
+ }
+ return fLastValue;
+ }
+
+ // Set key to val in the map, replacing any previous value with the same key.
+ // We copy both key and val, and return a pointer to the value copy now in the map.
+ const V* set(K key, V val) {
+ if (fLastValue && key == fLastKey) {
+ *fLastValue = std::move(val);
+ } else {
+ fLastKey = key;
+ fLastValue = fMap.set(std::move(key), std::move(val));
+ }
+ return fLastValue;
+ }
+
+ // Remove the key/value entry in the table with this key.
+ void remove(K key) {
+ // Match SkTHashMap requirement. The caller can find() if they're unsure.
+ SkASSERT(fMap.find(fLastKey));
+ fLastKey = std::move(key);
+ fLastValue = nullptr;
+ fMap.remove(fLastKey);
+ }
+
+ // Clear the map.
+ void reset() {
+ fLastKey = KeyTraits::GetInvalidKey();
+ fLastValue = nullptr;
+ fMap.reset();
+ }
+
+private:
+ SkTHashMap<K, V, HashT> fMap;
+ mutable K fLastKey = KeyTraits::GetInvalidKey();
+ mutable V* fLastValue = nullptr;
+};
+
+#endif