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_profile.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 ReadBestMonitorColorProfile(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 profileData; | |
30 if (!base::ReadFileToString(base::FilePath(path), &profileData)) | |
31 return; | |
32 size_t length = profileData.size(); | |
33 if (!ColorProfile::IsValidProfileLength(length)) | |
34 return; | |
35 profile->assign(profileData.data(), profileData.data() + length); | |
36 } | |
37 | |
38 base::LazyInstance<base::Lock> g_best_color_profile_lock = | |
39 LAZY_INSTANCE_INITIALIZER; | |
40 base::LazyInstance<gfx::ColorProfile> g_best_color_profile = | |
41 LAZY_INSTANCE_INITIALIZER; | |
42 bool g_has_initialized_best_color_profile = false; | |
43 | |
44 } // namespace | |
45 | |
46 // static | |
47 ColorProfile ColorProfile::GetFromBestMonitor() { | |
48 base::AutoLock lock(g_best_color_profile_lock.Get()); | |
49 return g_best_color_profile.Get(); | |
50 } | |
51 | |
52 // static | |
53 bool ColorProfile::CachedProfilesNeedUpdate() { | |
54 base::AutoLock lock(g_best_color_profile_lock.Get()); | |
55 return !g_has_initialized_best_color_profile; | |
56 } | |
57 | |
58 // static | |
59 void ColorProfile::UpdateCachedProfilesOnBackgroundThread() { | |
60 std::vector<char> profile; | |
61 ReadBestMonitorColorProfile(&profile); | |
62 | |
63 base::AutoLock lock(g_best_color_profile_lock.Get()); | |
64 g_best_color_profile.Get().profile_ = profile; | |
65 g_has_initialized_best_color_profile = true; | |
66 } | |
67 | |
68 } // namespace gfx | |
OLD | NEW |