OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gfx/color_space.h" |
| 6 |
| 7 #include <windows.h> |
| 8 #include <stddef.h> |
| 9 #include <map> |
| 10 |
| 11 #include "base/files/file_util.h" |
| 12 #include "base/lazy_instance.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/synchronization/lock.h" |
| 15 |
| 16 namespace gfx { |
| 17 |
| 18 namespace { |
| 19 |
| 20 void ReadBestMonitorICCProfile(std::vector<char>* profile) { |
| 21 HDC screen_dc = GetDC(NULL); |
| 22 DWORD path_len = MAX_PATH; |
| 23 WCHAR path[MAX_PATH + 1]; |
| 24 |
| 25 BOOL result = GetICMProfile(screen_dc, &path_len, path); |
| 26 ReleaseDC(NULL, screen_dc); |
| 27 if (!result) |
| 28 return; |
| 29 std::string profile_data; |
| 30 if (!base::ReadFileToString(base::FilePath(path), &profile_data)) |
| 31 return; |
| 32 size_t length = profile_data.size(); |
| 33 if (!ColorSpace::IsValidProfileLength(length)) |
| 34 return; |
| 35 profile->assign(profile_data.data(), profile_data.data() + length); |
| 36 } |
| 37 |
| 38 base::LazyInstance<base::Lock> g_best_monitor_color_space_lock = |
| 39 LAZY_INSTANCE_INITIALIZER; |
| 40 base::LazyInstance<gfx::ColorSpace> g_best_monitor_color_space = |
| 41 LAZY_INSTANCE_INITIALIZER; |
| 42 bool g_has_initialized_best_monitor_color_space = false; |
| 43 |
| 44 } // namespace |
| 45 |
| 46 // static |
| 47 ColorSpace ColorSpace::FromBestMonitor() { |
| 48 base::AutoLock lock(g_best_monitor_color_space_lock.Get()); |
| 49 return g_best_monitor_color_space.Get(); |
| 50 } |
| 51 |
| 52 // static |
| 53 bool ColorSpace::CachedProfilesNeedUpdate() { |
| 54 base::AutoLock lock(g_best_monitor_color_space_lock.Get()); |
| 55 return !g_has_initialized_best_monitor_color_space; |
| 56 } |
| 57 |
| 58 // static |
| 59 void ColorSpace::UpdateCachedProfilesOnBackgroundThread() { |
| 60 std::vector<char> icc_profile; |
| 61 ReadBestMonitorICCProfile(&icc_profile); |
| 62 |
| 63 base::AutoLock lock(g_best_monitor_color_space_lock.Get()); |
| 64 g_best_monitor_color_space.Get().icc_profile_ = icc_profile; |
| 65 g_has_initialized_best_monitor_color_space = true; |
| 66 } |
| 67 |
| 68 } // namespace gfx |
OLD | NEW |