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

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

Issue 2556723003: Merge color options into ColorBehavior (Closed)
Patch Set: Feedback Created 4 years 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/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

Powered by Google App Engine
This is Rietveld 408576698