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/containers/mru_cache.h" | 9 #include "base/containers/mru_cache.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 Cache& cache = g_cache.Get(); | 69 Cache& cache = g_cache.Get(); |
70 base::AutoLock lock(cache.lock); | 70 base::AutoLock lock(cache.lock); |
71 | 71 |
72 // Linearly search the cached ICC profiles to find one with the same data. | 72 // Linearly search the cached ICC profiles to find one with the same data. |
73 // If it exists, re-use its id and touch it in the cache. | 73 // If it exists, re-use its id and touch it in the cache. |
74 for (auto iter = cache.id_to_icc_profile_mru.begin(); | 74 for (auto iter = cache.id_to_icc_profile_mru.begin(); |
75 iter != cache.id_to_icc_profile_mru.end(); ++iter) { | 75 iter != cache.id_to_icc_profile_mru.end(); ++iter) { |
76 if (icc_profile.data_ == iter->second.data_) { | 76 if (icc_profile.data_ == iter->second.data_) { |
77 icc_profile.id_ = iter->second.id_; | 77 icc_profile = iter->second; |
78 cache.id_to_icc_profile_mru.Get(icc_profile.id_); | 78 cache.id_to_icc_profile_mru.Get(icc_profile.id_); |
79 return icc_profile; | 79 return icc_profile; |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 // Create a new cached id and add it to the cache. | 83 // Create a new cached id and add it to the cache. |
84 icc_profile.id_ = cache.next_unused_id++; | 84 icc_profile.id_ = cache.next_unused_id++; |
| 85 icc_profile.color_space_ = |
| 86 ColorSpace(ColorSpace::PrimaryID::CUSTOM, ColorSpace::TransferID::CUSTOM, |
| 87 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); |
| 88 icc_profile.color_space_.icc_profile_id_ = icc_profile.id_; |
| 89 icc_profile.color_space_.sk_color_space_ = SkColorSpace::MakeICC(data, size); |
85 cache.id_to_icc_profile_mru.Put(icc_profile.id_, icc_profile); | 90 cache.id_to_icc_profile_mru.Put(icc_profile.id_, icc_profile); |
86 return icc_profile; | 91 return icc_profile; |
87 } | 92 } |
88 | 93 |
89 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(USE_X11) | 94 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(USE_X11) |
90 // static | 95 // static |
91 ICCProfile ICCProfile::FromBestMonitor() { | 96 ICCProfile ICCProfile::FromBestMonitor() { |
92 return ICCProfile(); | 97 return ICCProfile(); |
93 } | 98 } |
94 #endif | 99 #endif |
(...skipping 16 matching lines...) Expand all Loading... |
111 } | 116 } |
112 | 117 |
113 // TODO(ccameron): Support constructing ICC profiles from arbitrary ColorSpace | 118 // TODO(ccameron): Support constructing ICC profiles from arbitrary ColorSpace |
114 // objects. | 119 // objects. |
115 ICCProfile icc_profile; | 120 ICCProfile icc_profile; |
116 icc_profile.type_ = gfx::ICCProfile::Type::FROM_COLOR_SPACE; | 121 icc_profile.type_ = gfx::ICCProfile::Type::FROM_COLOR_SPACE; |
117 icc_profile.color_space_ = color_space; | 122 icc_profile.color_space_ = color_space; |
118 return icc_profile; | 123 return icc_profile; |
119 } | 124 } |
120 | 125 |
| 126 ICCProfile ICCProfile::FromSkColorSpace(sk_sp<SkColorSpace> color_space) { |
| 127 ICCProfile icc_profile; |
| 128 |
| 129 Cache& cache = g_cache.Get(); |
| 130 base::AutoLock lock(cache.lock); |
| 131 |
| 132 // Linearly search the cached ICC profiles to find one with the same data. |
| 133 // If it exists, re-use its id and touch it in the cache. |
| 134 for (auto iter = cache.id_to_icc_profile_mru.begin(); |
| 135 iter != cache.id_to_icc_profile_mru.end(); ++iter) { |
| 136 sk_sp<SkColorSpace> iter_color_space = |
| 137 iter->second.color_space_.ToSkColorSpace(); |
| 138 if (SkColorSpace::Equals(color_space.get(), iter_color_space.get())) { |
| 139 icc_profile = iter->second; |
| 140 cache.id_to_icc_profile_mru.Get(icc_profile.id_); |
| 141 return icc_profile; |
| 142 } |
| 143 } |
| 144 |
| 145 // TODO(ccameron): Support constructing ICC profiles from arbitrary |
| 146 // SkColorSpace objects. |
| 147 return icc_profile; |
| 148 } |
| 149 |
121 const std::vector<char>& ICCProfile::GetData() const { | 150 const std::vector<char>& ICCProfile::GetData() const { |
122 return data_; | 151 return data_; |
123 } | 152 } |
124 | 153 |
125 ColorSpace ICCProfile::GetColorSpace() const { | 154 ColorSpace ICCProfile::GetColorSpace() const { |
126 if (type_ == Type::INVALID) | 155 if (type_ == Type::INVALID) |
127 return gfx::ColorSpace(); | 156 return gfx::ColorSpace(); |
128 if (type_ == Type::FROM_COLOR_SPACE) | 157 if (type_ == Type::FROM_COLOR_SPACE) |
129 return color_space_; | 158 return color_space_; |
130 | 159 |
131 ColorSpace color_space(ColorSpace::PrimaryID::CUSTOM, | 160 ColorSpace color_space = color_space_; |
132 ColorSpace::TransferID::CUSTOM, | |
133 ColorSpace::MatrixID::RGB, ColorSpace::RangeID::FULL); | |
134 color_space.icc_profile_id_ = id_; | |
135 | 161 |
136 // Move this ICC profile to the most recently used end of the cache. | 162 // Move this ICC profile to the most recently used end of the cache. |
137 { | 163 { |
138 Cache& cache = g_cache.Get(); | 164 Cache& cache = g_cache.Get(); |
139 base::AutoLock lock(cache.lock); | 165 base::AutoLock lock(cache.lock); |
140 | 166 |
141 auto found = cache.id_to_icc_profile_mru.Get(id_); | 167 auto found = cache.id_to_icc_profile_mru.Get(id_); |
142 if (found == cache.id_to_icc_profile_mru.end()) | 168 if (found == cache.id_to_icc_profile_mru.end()) |
143 cache.id_to_icc_profile_mru.Put(id_, *this); | 169 cache.id_to_icc_profile_mru.Put(id_, *this); |
144 } | 170 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 214 |
189 return color_space; | 215 return color_space; |
190 } | 216 } |
191 | 217 |
192 // static | 218 // static |
193 bool ICCProfile::IsValidProfileLength(size_t length) { | 219 bool ICCProfile::IsValidProfileLength(size_t length) { |
194 return length >= kMinProfileLength && length <= kMaxProfileLength; | 220 return length >= kMinProfileLength && length <= kMaxProfileLength; |
195 } | 221 } |
196 | 222 |
197 } // namespace gfx | 223 } // namespace gfx |
OLD | NEW |