aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-02-20 12:35:32 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-20 12:35:32 -0800
commit2aa1f7e6799501974532d35c1f6c3a0447121b95 (patch)
treebd4ad170d9a5205cf1e93fb5d19665eb3d6cb900 /src
parente5524cd52d56f9b70d9b4a83bd73a3fa75d56509 (diff)
Port GrGLCaps over to use SkTHash.
I've written some new hashtable interfaces that should be easier to use, and I've been trying to roll them out bit by bit, hopefully replacing SkTDynamicHash, SkTMultiMap, SkTHashCache, etc. This turns the cache in GrGLCaps::readPixelsSupported() into an SkTHashMap, mapping the format key to a bool. Functionally, it's the same. BUG=skia: Review URL: https://codereview.chromium.org/948473002
Diffstat (limited to 'src')
-rw-r--r--src/core/SkTHash.h12
-rw-r--r--src/core/SkTHashCache.h77
-rw-r--r--src/gpu/gl/GrGLCaps.cpp19
-rw-r--r--src/gpu/gl/GrGLCaps.h48
4 files changed, 31 insertions, 125 deletions
diff --git a/src/core/SkTHash.h b/src/core/SkTHash.h
index c7917ac668..b47f8fa766 100644
--- a/src/core/SkTHash.h
+++ b/src/core/SkTHash.h
@@ -18,6 +18,12 @@ class SkTHashTable : SkNoncopyable {
public:
SkTHashTable() : fCount(0), fCapacity(0) {}
+ // Clear the table.
+ void reset() {
+ this->~SkTHashTable();
+ SkNEW_PLACEMENT(this, SkTHashTable);
+ }
+
// How many entries are in the table?
int count() const { return fCount; }
@@ -144,6 +150,9 @@ class SkTHashMap : SkNoncopyable {
public:
SkTHashMap() {}
+ // Clear the map.
+ void reset() { fTable.reset(); }
+
// How many key/value pairs are in the table?
int count() const { return fTable.count(); }
@@ -187,6 +196,9 @@ class SkTHashSet : SkNoncopyable {
public:
SkTHashSet() {}
+ // Clear the set.
+ void reset() { fTable.reset(); }
+
// How many items are in the set?
int count() const { return fTable.count(); }
diff --git a/src/core/SkTHashCache.h b/src/core/SkTHashCache.h
deleted file mode 100644
index cfee9722f2..0000000000
--- a/src/core/SkTHashCache.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 SkTHASHCACHE_DEFINED
-#define SkTHASHCACHE_DEFINED
-
-#include "SkTypes.h"
-#include "SkTDynamicHash.h"
-
-template <typename T,
-typename Key,
-typename Traits = T,
-int kGrowPercent = 75 >
-class SkTHashCache : public SkNoncopyable {
-public:
-
- SkTHashCache() {
- this->reset();
- }
-
- ~SkTHashCache() {
- this->clear();
- }
-
- T* find(const Key& key) const {
- return fDict->find(key);
- }
-
- /**
- * If element already in cache, return immediately the cached value
- */
- T& add(const T& add) {
- Key key = Traits::GetKey(add);
- if (T* val = this->find(key)) {
- return *val;
- }
-
- T* element = SkNEW_ARGS(T, (add));
-
- fDict->add(element);
-
- return *element;
- }
-
- int size() const {
- return fDict->count();
- }
-
- void reset() {
- this->clear();
-
- fDict.reset(SkNEW(DictType));
- }
-
-private:
- typedef SkTDynamicHash<T, Key, Traits, kGrowPercent> DictType;
-
- void clear() {
- if (fDict.get()) {
- typename DictType::Iter it(fDict.get());
-
- while (!it.done()) {
- SkDELETE(&(*it));
- ++it;
- }
- }
- }
-
- SkAutoTDelete<DictType> fDict;
-};
-
-#endif /* SkHASHCACHE_DEFINED */
-
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 1f50f8d1e1..9911d53f43 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -749,20 +749,13 @@ bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
GrGLenum format,
GrGLenum type,
GrGLenum currFboFormat) const {
-
- ReadPixelsSupportedFormats::Key key = {format, type, currFboFormat};
-
- ReadPixelsSupportedFormats* cachedValue = fReadPixelsSupportedCache.find(key);
-
- if (NULL == cachedValue) {
- bool value = doReadPixelsSupported(intf, format, type);
- ReadPixelsSupportedFormats newValue(key, value);
- fReadPixelsSupportedCache.add(newValue);
-
- return newValue.value();
+ ReadPixelsSupportedFormat key = {format, type, currFboFormat};
+ if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
+ return *supported;
}
-
- return cachedValue->value();
+ bool supported = this->doReadPixelsSupported(intf, format, type);
+ fReadPixelsSupportedCache.set(key, supported);
+ return supported;
}
void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 527cd33ee3..1b77ed0e32 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -12,7 +12,7 @@
#include "GrDrawTargetCaps.h"
#include "GrGLStencilBuffer.h"
#include "SkChecksum.h"
-#include "SkTHashCache.h"
+#include "SkTHash.h"
#include "SkTArray.h"
class GrGLContextInfo;
@@ -393,45 +393,23 @@ private:
const char* fFBFetchColorName;
const char* fFBFetchExtensionString;
- class ReadPixelsSupportedFormats {
- public:
- struct Key {
- GrGLenum fFormat;
- GrGLenum fType;
- GrGLenum fFboFormat;
-
- bool operator==(const Key& rhs) const {
- return fFormat == rhs.fFormat
- && fType == rhs.fType
- && fFboFormat == rhs.fFboFormat;
- }
-
- uint32_t getHash() const {
- return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), sizeof(*this));
- }
- };
-
- ReadPixelsSupportedFormats(Key key, bool value) : fKey(key), fValue(value) {
- }
-
- static const Key& GetKey(const ReadPixelsSupportedFormats& element) {
- return element.fKey;
- }
+ struct ReadPixelsSupportedFormat {
+ GrGLenum fFormat;
+ GrGLenum fType;
+ GrGLenum fFboFormat;
- static uint32_t Hash(const Key& key) {
- return key.getHash();
+ bool operator==(const ReadPixelsSupportedFormat& rhs) const {
+ return fFormat == rhs.fFormat
+ && fType == rhs.fType
+ && fFboFormat == rhs.fFboFormat;
}
-
- bool value() const {
- return fValue;
+ static uint32_t Hash(const ReadPixelsSupportedFormat& r) {
+ return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&r), sizeof(r));
}
- private:
- Key fKey;
- bool fValue;
};
- mutable SkTHashCache<ReadPixelsSupportedFormats,
- ReadPixelsSupportedFormats::Key> fReadPixelsSupportedCache;
+ mutable SkTHashMap<ReadPixelsSupportedFormat, bool, ReadPixelsSupportedFormat::Hash>
+ fReadPixelsSupportedCache;
typedef GrDrawTargetCaps INHERITED;
};