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

Unified Diff: third_party/WebKit/Source/platform/graphics/ColorSpaceFilterCache.cpp

Issue 1331533002: [poc] curve-filter Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix CanvasRenderingContext2D::createPattern crash for #40 Created 4 years, 11 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: third_party/WebKit/Source/platform/graphics/ColorSpaceFilterCache.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/ColorSpaceFilterCache.cpp b/third_party/WebKit/Source/platform/graphics/ColorSpaceFilterCache.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ff85c4fdcd58c5a231463ec591427a650d2a51e2
--- /dev/null
+++ b/third_party/WebKit/Source/platform/graphics/ColorSpaceFilterCache.cpp
@@ -0,0 +1,121 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/graphics/ColorSpaceFilterCache.h"
+
+#include "platform/graphics/ColorSpaceProfile.h"
+#include "third_party/skia/include/core/SkColorFilter.h"
+#include "wtf/HashMap.h"
+#include "wtf/MainThread.h"
+#include "wtf/text/StringHash.h"
+#include "wtf/text/WTFString.h"
+
+namespace blink {
+
+#if USE(QCMSLIB)
+
+class ColorTransformCache {
+public:
+ void set(ColorSpaceProfile* source, ColorSpaceProfile* target, SkColorFilter* transform)
+ {
+ set(transformCacheKey(source, target), transform);
+ }
+
+ PassRefPtr<SkColorFilter> find(ColorSpaceProfile* source, ColorSpaceProfile* target) const
+ {
+ return find(transformCacheKey(source, target));
+ }
+
+ void prune(ColorSpaceProfile* target)
+ {
+ const size_t cachePruneMinimum = 3; // FIXME: provide a larger prune limit?
+
+ if (!target || m_colorTransforms.size() < cachePruneMinimum)
+ return;
+
+ prune(transformTargetDescription(target));
+ }
+
+private:
+ static String transformCacheKey(ColorSpaceProfile* source, ColorSpaceProfile* target)
+ {
+ return qcms_profile_get_description(source->profile()) + transformTargetDescription(target);
+ }
+
+ static String transformTargetDescription(ColorSpaceProfile* target)
+ {
+ return String(" -> ") + qcms_profile_get_description(target->profile());
+ }
+
+ void set(const String& key, SkColorFilter* transform)
+ {
+ m_colorTransforms.set(key, transform);
+ }
+
+ PassRefPtr<SkColorFilter> find(const String& key) const
+ {
+ HashMap<String, RefPtr<SkColorFilter>>::const_iterator it = m_colorTransforms.find(key);
+ return it != m_colorTransforms.end() ? it->value : nullptr;
+ }
+
+ void prune(const String& target)
+ {
+ Vector<String> removeKeys;
+
+ for (const auto& key : m_colorTransforms.keys()) {
+ SkColorFilter* transform = m_colorTransforms.get(key);
+ fprintf(stderr, " transform cache %s\n", String(key).latin1().data());
+ if (transform->unique() || key.endsWith(target))
+ removeKeys.append(key);
+ }
+
+ for (unsigned i = 0; i < removeKeys.size(); ++i)
+ fprintf(stderr, " prune %s\n", removeKeys[i].latin1().data());
+
+ m_colorTransforms.removeAll(removeKeys);
+ }
+
+ HashMap<String, RefPtr<SkColorFilter>> m_colorTransforms;
+};
+
+static ColorTransformCache& colorTransformCache()
+{
+ DEFINE_STATIC_LOCAL(ColorTransformCache, cache, ());
+ RELEASE_ASSERT(isMainThread());
+ return cache;
+}
+
+PassRefPtr<SkColorFilter> findColorTransform(ColorSpaceProfile* source, ColorSpaceProfile* target)
+{
+ return colorTransformCache().find(source, target);
+}
+
+void cacheColorTransform(ColorSpaceProfile* source, ColorSpaceProfile* target, SkColorFilter* filter)
+{
+ colorTransformCache().set(source, target, filter);
+}
+
+void pruneColorTransform(ColorSpaceProfile* target)
+{
+ colorTransformCache().prune(target);
+}
+
+#else
+
+PassRefPtr<SkColorFilter> findColorTransform(ColorSpaceProfile*, ColorSpaceProfile*)
+{
+ return nullptr;
+}
+
+void cacheColorTransform(ColorSpaceProfile*, ColorSpaceProfile*, SkColorFilter*)
+{
+}
+
+void pruneColorTransform(ColorSpaceProfile*)
+{
+}
+
+#endif // USE(QCMSLIB)
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698