| Index: third_party/WebKit/Source/platform/graphics/ColorBehavior.cpp
|
| diff --git a/third_party/WebKit/Source/platform/graphics/ColorBehavior.cpp b/third_party/WebKit/Source/platform/graphics/ColorBehavior.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..781ccc1f6d606e921424e537d63332411d0afdf5
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/platform/graphics/ColorBehavior.cpp
|
| @@ -0,0 +1,69 @@
|
| +// Copyright 2016 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/ColorBehavior.h"
|
| +
|
| +#include "platform/graphics/BitmapImageMetrics.h"
|
| +#include "third_party/skia/include/core/SkColorSpace.h"
|
| +#include "wtf/SpinLock.h"
|
| +
|
| +namespace blink {
|
| +
|
| +namespace {
|
| +
|
| +// The output device color space is global and shared across multiple threads.
|
| +SpinLock gTargetColorSpaceLock;
|
| +SkColorSpace* gTargetColorSpace = nullptr;
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +void ColorBehavior::setGlobalTargetColorProfile(
|
| + const WebVector<char>& profile) {
|
| + if (profile.isEmpty())
|
| + return;
|
| +
|
| + // Take a lock around initializing and accessing the global device color
|
| + // profile.
|
| + SpinLock::Guard guard(gTargetColorSpaceLock);
|
| +
|
| + // Layout tests expect that only the first call will take effect.
|
| + if (gTargetColorSpace)
|
| + return;
|
| +
|
| + gTargetColorSpace =
|
| + SkColorSpace::MakeICC(profile.data(), profile.size()).release();
|
| +
|
| + // UMA statistics.
|
| + BitmapImageMetrics::countOutputGamma(gTargetColorSpace);
|
| +}
|
| +
|
| +// static
|
| +sk_sp<SkColorSpace> ColorBehavior::globalTargetColorSpace() {
|
| + // Take a lock around initializing and accessing the global device color
|
| + // profile.
|
| + SpinLock::Guard guard(gTargetColorSpaceLock);
|
| +
|
| + // Initialize the output device profile to sRGB if it has not yet been
|
| + // initialized.
|
| + if (!gTargetColorSpace) {
|
| + gTargetColorSpace =
|
| + SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).release();
|
| + }
|
| +
|
| + gTargetColorSpace->ref();
|
| + return sk_sp<SkColorSpace>(gTargetColorSpace);
|
| +}
|
| +
|
| +// static
|
| +ColorBehavior ColorBehavior::transformToGlobalTarget() {
|
| + return ColorBehavior(Type::TransformTo, globalTargetColorSpace());
|
| +}
|
| +
|
| +// static
|
| +ColorBehavior ColorBehavior::transformToTargetForTesting() {
|
| + return transformToGlobalTarget();
|
| +}
|
| +
|
| +} // namespace blink
|
|
|