| 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 "ui/gfx/icc_profile.h" | 5 #include "ui/gfx/icc_profile.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/command_line.h" |
| 9 #include "base/containers/mru_cache.h" | 10 #include "base/containers/mru_cache.h" |
| 10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 11 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 12 #include "third_party/skia/include/core/SkColorSpaceXform.h" | 13 #include "third_party/skia/include/core/SkColorSpaceXform.h" |
| 13 #include "third_party/skia/include/core/SkICC.h" | 14 #include "third_party/skia/include/core/SkICC.h" |
| 14 #include "ui/gfx/skia_color_space_util.h" | 15 #include "ui/gfx/skia_color_space_util.h" |
| 16 #include "ui/gfx/switches.h" |
| 15 | 17 |
| 16 namespace gfx { | 18 namespace gfx { |
| 17 | 19 |
| 18 const uint64_t ICCProfile::test_id_adobe_rgb_ = 1; | 20 const uint64_t ICCProfile::test_id_adobe_rgb_ = 1; |
| 19 const uint64_t ICCProfile::test_id_color_spin_ = 2; | 21 const uint64_t ICCProfile::test_id_color_spin_ = 2; |
| 20 const uint64_t ICCProfile::test_id_generic_rgb_ = 3; | 22 const uint64_t ICCProfile::test_id_generic_rgb_ = 3; |
| 21 const uint64_t ICCProfile::test_id_srgb_ = 4; | 23 const uint64_t ICCProfile::test_id_srgb_ = 4; |
| 22 const uint64_t ICCProfile::test_id_no_analytic_tr_fn_ = 5; | 24 const uint64_t ICCProfile::test_id_no_analytic_tr_fn_ = 5; |
| 23 const uint64_t ICCProfile::test_id_a2b_only_ = 6; | 25 const uint64_t ICCProfile::test_id_a2b_only_ = 6; |
| 24 const uint64_t ICCProfile::test_id_overshoot_ = 7; | 26 const uint64_t ICCProfile::test_id_overshoot_ = 7; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 icc_profile.id_ = new_profile_id; | 100 icc_profile.id_ = new_profile_id; |
| 99 icc_profile.data_.insert(icc_profile.data_.begin(), data_as_char, | 101 icc_profile.data_.insert(icc_profile.data_.begin(), data_as_char, |
| 100 data_as_char + size); | 102 data_as_char + size); |
| 101 icc_profile.ComputeColorSpaceAndCache(); | 103 icc_profile.ComputeColorSpaceAndCache(); |
| 102 return icc_profile; | 104 return icc_profile; |
| 103 } | 105 } |
| 104 | 106 |
| 105 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(USE_X11) | 107 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(USE_X11) |
| 106 // static | 108 // static |
| 107 ICCProfile ICCProfile::FromBestMonitor() { | 109 ICCProfile ICCProfile::FromBestMonitor() { |
| 110 if (HasForcedProfile()) |
| 111 return GetForcedProfile(); |
| 108 return ICCProfile(); | 112 return ICCProfile(); |
| 109 } | 113 } |
| 110 #endif | 114 #endif |
| 111 | 115 |
| 112 // static | 116 // static |
| 117 bool ICCProfile::HasForcedProfile() { |
| 118 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 119 switches::kForceColorProfile); |
| 120 } |
| 121 |
| 122 // static |
| 123 ICCProfile ICCProfile::GetForcedProfile() { |
| 124 DCHECK(HasForcedProfile()); |
| 125 ICCProfile icc_profile; |
| 126 std::string value = |
| 127 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 128 switches::kForceColorProfile); |
| 129 if (value == "srgb") { |
| 130 ColorSpace::CreateSRGB().GetICCProfile(&icc_profile); |
| 131 } else if (value == "generic-rgb") { |
| 132 ColorSpace generic_rgb_color_space(ColorSpace::PrimaryID::APPLE_GENERIC_RGB, |
| 133 ColorSpace::TransferID::GAMMA18); |
| 134 generic_rgb_color_space.GetICCProfile(&icc_profile); |
| 135 } else { |
| 136 LOG(ERROR) << "Invalid forced color profile"; |
| 137 } |
| 138 return icc_profile; |
| 139 } |
| 140 |
| 141 // static |
| 113 const std::vector<char>& ICCProfile::GetData() const { | 142 const std::vector<char>& ICCProfile::GetData() const { |
| 114 return data_; | 143 return data_; |
| 115 } | 144 } |
| 116 | 145 |
| 117 const ColorSpace& ICCProfile::GetColorSpace() const { | 146 const ColorSpace& ICCProfile::GetColorSpace() const { |
| 118 // Move this ICC profile to the most recently used end of the cache, | 147 // Move this ICC profile to the most recently used end of the cache, |
| 119 // inserting if needed. | 148 // inserting if needed. |
| 120 if (id_) { | 149 if (id_) { |
| 121 Cache& cache = g_cache.Get(); | 150 Cache& cache = g_cache.Get(); |
| 122 base::AutoLock lock(cache.lock); | 151 base::AutoLock lock(cache.lock); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 279 |
| 251 // Add to the cache. | 280 // Add to the cache. |
| 252 { | 281 { |
| 253 Cache& cache = g_cache.Get(); | 282 Cache& cache = g_cache.Get(); |
| 254 base::AutoLock lock(cache.lock); | 283 base::AutoLock lock(cache.lock); |
| 255 cache.id_to_icc_profile_mru.Put(id_, *this); | 284 cache.id_to_icc_profile_mru.Put(id_, *this); |
| 256 } | 285 } |
| 257 } | 286 } |
| 258 | 287 |
| 259 } // namespace gfx | 288 } // namespace gfx |
| OLD | NEW |