aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkYUVPlanesCache.cpp
diff options
context:
space:
mode:
authorGravatar sugoi <sugoi@chromium.org>2015-01-19 10:10:27 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-19 10:10:27 -0800
commit692135f9689d4dcb5ba91ff8f4899e268c0bfe11 (patch)
tree73d0911ff57b27e75df7c5a1da554b959a2e6ca1 /src/core/SkYUVPlanesCache.cpp
parent89499d76b9616a455dfe8257cef9e4489938ea22 (diff)
YUV planes cache
- Added new classes to contain YUV planes of memory, along with the associated data. - Used these classes in load_yuv_texture() to enable YUV planes caching - Added a unit test for the new cache BUG=450021 Review URL: https://codereview.chromium.org/851273003
Diffstat (limited to 'src/core/SkYUVPlanesCache.cpp')
-rw-r--r--src/core/SkYUVPlanesCache.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/core/SkYUVPlanesCache.cpp b/src/core/SkYUVPlanesCache.cpp
new file mode 100644
index 0000000000..69885fe46a
--- /dev/null
+++ b/src/core/SkYUVPlanesCache.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkYUVPlanesCache.h"
+#include "SkResourceCache.h"
+
+#define CHECK_LOCAL(localCache, localName, globalName, ...) \
+ ((localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::globalName(__VA_ARGS__))
+
+namespace {
+static unsigned gYUVPlanesKeyNamespaceLabel;
+
+struct YUVValue {
+ SkYUVPlanesCache::Info fInfo;
+ SkCachedData* fData;
+};
+
+struct YUVPlanesKey : public SkResourceCache::Key {
+ YUVPlanesKey(uint32_t genID)
+ : fGenID(genID)
+ {
+ this->init(&gYUVPlanesKeyNamespaceLabel, sizeof(genID));
+ }
+
+ uint32_t fGenID;
+};
+
+struct YUVPlanesRec : public SkResourceCache::Rec {
+ YUVPlanesRec(YUVPlanesKey key, SkCachedData* data, SkYUVPlanesCache::Info* info)
+ : fKey(key)
+ {
+ fValue.fData = data;
+ fValue.fInfo = *info;
+ fValue.fData->attachToCacheAndRef();
+ }
+ ~YUVPlanesRec() {
+ fValue.fData->detachFromCacheAndUnref();
+ }
+
+ YUVPlanesKey fKey;
+ YUVValue fValue;
+
+ const Key& getKey() const SK_OVERRIDE { return fKey; }
+ size_t bytesUsed() const SK_OVERRIDE { return sizeof(*this) + fValue.fData->size(); }
+
+ static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextData) {
+ const YUVPlanesRec& rec = static_cast<const YUVPlanesRec&>(baseRec);
+ YUVValue* result = static_cast<YUVValue*>(contextData);
+
+ SkCachedData* tmpData = rec.fValue.fData;
+ tmpData->ref();
+ if (NULL == tmpData->data()) {
+ tmpData->unref();
+ return false;
+ }
+ result->fData = tmpData;
+ result->fInfo = rec.fValue.fInfo;
+ return true;
+ }
+};
+} // namespace
+
+SkCachedData* SkYUVPlanesCache::FindAndRef(uint32_t genID, Info* info,
+ SkResourceCache* localCache) {
+ YUVValue result;
+ YUVPlanesKey key(genID);
+ if (!CHECK_LOCAL(localCache, find, Find, key, YUVPlanesRec::Visitor, &result)) {
+ return NULL;
+ }
+
+ *info = result.fInfo;
+ return result.fData;
+}
+
+void SkYUVPlanesCache::Add(uint32_t genID, SkCachedData* data, Info* info,
+ SkResourceCache* localCache) {
+ YUVPlanesKey key(genID);
+ return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(YUVPlanesRec, (key, data, info)));
+}