diff options
author | piotaixr <piotaixr@chromium.org> | 2014-10-02 10:57:53 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-02 10:57:53 -0700 |
commit | e4b231428e8c14cbc82d20cfb12eb08fc45f8df6 (patch) | |
tree | 0987b023b75e85bc01e8d2814fe2183ac2c38c07 /tests | |
parent | cf99b00980b6c9c557e71abf1a7c9f9b21217262 (diff) |
Caching the result of readPixelsSupported
The call was calling GR_GL_GetIntegerv 2 times for each readPixels
and thus was causing a loss of performance
(resubmit of issue 344793008)
Benchmark url: http://packages.gkny.fr/tst/index.html
BUG=skia:2681
Committed: https://skia.googlesource.com/skia/+/753a2964afe5661ce9b2a8ca77ca9d0aabd3173c
Committed: https://skia.googlesource.com/skia/+/8339371f1ec3c57a0741932fd96bff32c53d4e54
Review URL: https://codereview.chromium.org/364193004
Diffstat (limited to 'tests')
-rw-r--r-- | tests/THashCache.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/THashCache.cpp b/tests/THashCache.cpp new file mode 100644 index 0000000000..7797431553 --- /dev/null +++ b/tests/THashCache.cpp @@ -0,0 +1,91 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "Test.h" +#include "SkTHashCache.h" + + +// Tests the SkTHashCache<T> class template. + +struct Tint { + uint32_t value; + + bool operator==(const Tint& rhs) const { + return value == rhs.value; + } +}; + +class Element { +public: + + bool operator==(const Element& rhs) const { + return value == rhs.value && key == rhs.key; + } + + static const Tint& GetKey(const Element& element) { + return element.key; + } + + static uint32_t Hash(const Tint& key) { + return key.value; + } + + Element(Tint key, int value) : key(key), value(value) { + } + + Tint key; + int value; +}; + +typedef SkTHashCache<Element, Tint> CacheType; + +DEF_TEST(THashCache, reporter) { + Tint k11 = {11}; + Element e11(k11, 22); + + e11.value = e11.value; + Element e11Collision(k11, 0); + // Element e42(4, 2); + + //Some tests for the class Element + REPORTER_ASSERT(reporter, Element::GetKey(e11) == k11); + REPORTER_ASSERT(reporter, Element::Hash(k11) == 11); + + CacheType cache; + + // Is the cahce correctly initialized ? + REPORTER_ASSERT(reporter, 0 == cache.size()); + REPORTER_ASSERT(reporter, NULL == cache.find(k11)); + + Element& e11_c = cache.add(e11); + e11_c.value = e11_c.value; + + // Tests for simple insertion, verifying that the returned element + // has the same values as the original one + REPORTER_ASSERT(reporter, 1 == cache.size()); + REPORTER_ASSERT(reporter, NULL != cache.find(k11)); + REPORTER_ASSERT(reporter, e11_c == e11); + + Element& e11Collision_c = cache.add(e11Collision); + // Verifying that, in case of collision, the element alerady in the cache is not removed + REPORTER_ASSERT(reporter, e11Collision_c == e11); + REPORTER_ASSERT(reporter, 1 == cache.size()); + + Tint k42 = {42}; + Element e42(k42, 2); + cache.add(e42); + // Can we add more than one element? + REPORTER_ASSERT(reporter, NULL != cache.find(k11)); + REPORTER_ASSERT(reporter, NULL != cache.find(k42)); + REPORTER_ASSERT(reporter, 2 == cache.size()); + + cache.reset(); + // Does clear do its job? + REPORTER_ASSERT(reporter, 0 == cache.size()); + REPORTER_ASSERT(reporter, NULL == cache.find(k11)); + REPORTER_ASSERT(reporter, NULL == cache.find(k42)); +} |