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

Side by Side Diff: ui/gfx/icc_profile.cc

Issue 2660393002: Use gfx::ColorSpace instead of SkColorSpace in Blink (Closed)
Patch Set: Rebase (again) Created 3 years, 10 months 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 unified diff | Download patch
« no previous file with comments | « ui/gfx/icc_profile.h ('k') | ui/gfx/icc_profile_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return ICCProfile(); 137 return ICCProfile();
138 } 138 }
139 139
140 // gfx::ColorTransform assumes that this will return an empty profile for any 140 // gfx::ColorTransform assumes that this will return an empty profile for any
141 // color space that was not constructed from an ICC profile. 141 // color space that was not constructed from an ICC profile.
142 // TODO(ccameron): Fix this assumption. 142 // TODO(ccameron): Fix this assumption.
143 // return FromData(data->data(), data->size()); 143 // return FromData(data->data(), data->size());
144 return ICCProfile(); 144 return ICCProfile();
145 } 145 }
146 146
147 ICCProfile ICCProfile::FromSkColorSpace(sk_sp<SkColorSpace> color_space) {
148 ICCProfile icc_profile;
149
150 Cache& cache = g_cache.Get();
151 base::AutoLock lock(cache.lock);
152
153 // Linearly search the cached ICC profiles to find one with the same data.
154 // If it exists, re-use its id and touch it in the cache.
155 for (auto iter = cache.id_to_icc_profile_mru.begin();
156 iter != cache.id_to_icc_profile_mru.end(); ++iter) {
157 sk_sp<SkColorSpace> iter_color_space =
158 iter->second.color_space_.ToSkColorSpace();
159 if (SkColorSpace::Equals(color_space.get(), iter_color_space.get())) {
160 icc_profile = iter->second;
161 cache.id_to_icc_profile_mru.Get(icc_profile.id_);
162 return icc_profile;
163 }
164 }
165
166 // TODO(ccameron): Support constructing ICC profiles from arbitrary
167 // SkColorSpace objects.
168 DLOG(ERROR) << "Failed to find ICC profile matching SkColorSpace.";
169 return icc_profile;
170 }
171
172 const std::vector<char>& ICCProfile::GetData() const { 147 const std::vector<char>& ICCProfile::GetData() const {
173 return data_; 148 return data_;
174 } 149 }
175 150
176 const ColorSpace& ICCProfile::GetColorSpace() const { 151 const ColorSpace& ICCProfile::GetColorSpace() const {
177 // Move this ICC profile to the most recently used end of the cache, 152 // Move this ICC profile to the most recently used end of the cache,
178 // inserting if needed. 153 // inserting if needed.
179 if (id_) { 154 if (id_) {
180 Cache& cache = g_cache.Get(); 155 Cache& cache = g_cache.Get();
181 base::AutoLock lock(cache.lock); 156 base::AutoLock lock(cache.lock);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 cache.id_to_icc_profile_mru.Put(id_, *this); 228 cache.id_to_icc_profile_mru.Put(id_, *this);
254 } 229 }
255 } 230 }
256 231
257 // static 232 // static
258 bool ICCProfile::IsValidProfileLength(size_t length) { 233 bool ICCProfile::IsValidProfileLength(size_t length) {
259 return length >= kMinProfileLength && length <= kMaxProfileLength; 234 return length >= kMinProfileLength && length <= kMaxProfileLength;
260 } 235 }
261 236
262 } // namespace gfx 237 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/icc_profile.h ('k') | ui/gfx/icc_profile_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698