| 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
|
|
|