Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/graphics/ColorBehavior.h" | 5 #include "platform/graphics/ColorBehavior.h" |
| 6 | 6 |
| 7 #include "platform/graphics/BitmapImageMetrics.h" | 7 #include "platform/graphics/BitmapImageMetrics.h" |
| 8 #include "wtf/SpinLock.h" | 8 #include "wtf/SpinLock.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // The output device color space is global and shared across multiple threads. | 14 // The output device color space is global and shared across multiple threads. |
| 15 SpinLock gTargetColorSpaceLock; | 15 SpinLock gTargetColorSpaceLock; |
| 16 SkColorSpace* gTargetColorSpace = nullptr; | 16 SkColorSpace* gTargetColorSpace = nullptr; |
| 17 | 17 |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 void ColorBehavior::setGlobalTargetColorProfile( | 21 void ColorBehavior::setGlobalTargetColorSpace( |
| 22 const WebVector<char>& profile) { | 22 const sk_sp<SkColorSpace>& colorSpace) { |
| 23 if (profile.isEmpty()) | 23 if (!colorSpace) |
| 24 return; | 24 return; |
| 25 | 25 |
| 26 // Take a lock around initializing and accessing the global device color | 26 // Take a lock around initializing and accessing the global device color |
| 27 // profile. | 27 // profile. |
| 28 SpinLock::Guard guard(gTargetColorSpaceLock); | 28 SpinLock::Guard guard(gTargetColorSpaceLock); |
| 29 | 29 |
| 30 // Layout tests expect that only the first call will take effect. | 30 // Layout tests expect that only the first call will take effect. |
| 31 if (gTargetColorSpace) | 31 if (gTargetColorSpace) |
| 32 return; | 32 return; |
| 33 | 33 |
| 34 gTargetColorSpace = | 34 // Ensure that the color space object be leaked. |
|
jbroman
2016/12/28 17:08:20
nit: "is leaked"?
ccameron
2016/12/28 21:52:56
It was intended to be the subjunctive ... but I'm
jbroman
2016/12/29 00:09:28
Indicative sounds better to me, but after searchin
| |
| 35 SkColorSpace::MakeICC(profile.data(), profile.size()).release(); | 35 gTargetColorSpace = colorSpace.get(); |
| 36 SkSafeRef(gTargetColorSpace); | |
| 36 | 37 |
| 37 // UMA statistics. | 38 // UMA statistics. |
| 38 BitmapImageMetrics::countOutputGammaAndGamut(gTargetColorSpace); | 39 BitmapImageMetrics::countOutputGammaAndGamut(gTargetColorSpace); |
| 39 } | 40 } |
| 40 | 41 |
| 41 void ColorBehavior::setGlobalTargetColorSpaceForTesting( | 42 void ColorBehavior::setGlobalTargetColorSpaceForTesting( |
| 42 const sk_sp<SkColorSpace>& colorSpace) { | 43 const sk_sp<SkColorSpace>& colorSpace) { |
| 43 // Take a lock around initializing and accessing the global device color | 44 // Take a lock around initializing and accessing the global device color |
| 44 // profile. | 45 // profile. |
| 45 SpinLock::Guard guard(gTargetColorSpaceLock); | 46 SpinLock::Guard guard(gTargetColorSpaceLock); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 if (m_type != Type::TransformTo) | 83 if (m_type != Type::TransformTo) |
| 83 return true; | 84 return true; |
| 84 return SkColorSpace::Equals(m_target.get(), other.m_target.get()); | 85 return SkColorSpace::Equals(m_target.get(), other.m_target.get()); |
| 85 } | 86 } |
| 86 | 87 |
| 87 bool ColorBehavior::operator!=(const ColorBehavior& other) const { | 88 bool ColorBehavior::operator!=(const ColorBehavior& other) const { |
| 88 return !(*this == other); | 89 return !(*this == other); |
| 89 } | 90 } |
| 90 | 91 |
| 91 } // namespace blink | 92 } // namespace blink |
| OLD | NEW |