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

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

Issue 293393008: gfx/ui/color_profile: add color profile cache on win (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/color_profile.h" 5 #include "ui/gfx/color_profile.h"
6 6
7 #include <map>
7 #include <windows.h> 8 #include <windows.h>
8 9
9 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/lazy_instance.h"
12 #include "base/synchronization/lock.h"
10 13
11 namespace gfx { 14 namespace gfx {
12 15
16 typedef std::map<std::wstring, std::vector<char> > ColorProfileMap;
17
18 base::LazyInstance<ColorProfileMap>::Leaky g_color_profile_map =
sky 2014/05/28 15:31:21 Seems like you only want ColorProfileCache as the
19 LAZY_INSTANCE_INITIALIZER;
20 base::LazyInstance<base::Lock>::Leaky g_color_profile_map_lock;
sky 2014/05/28 15:31:21 These are not globals, remove the g_.
21
22 struct ColorProfileCache {
sky 2014/05/28 15:31:21 Make this a class (see https://engdoc.corp.google.
23 ColorProfileCache() {}
24
25 bool find(std::wstring device, std::vector<char>* profile) {
26 base::AutoLock lock(g_color_profile_map_lock.Get());
27
28 ColorProfileMap* cache = g_color_profile_map.Pointer();
29 ColorProfileMap::const_iterator it = cache->find(device);
30 if (it == cache->end())
31 return false;
32
33 const char* data = it->second.data();
sky 2014/05/28 15:31:21 *profile = it->second; ?
34 profile->assign(data, data + it->second.size());
35 return true;
36 }
37
38 void insert(std::wstring device, const std::vector<char>& profile) {
sky 2014/05/28 15:31:21 const std::wstring&
39 base::AutoLock lock(g_color_profile_map_lock.Get());
40
41 ColorProfileMap* cache = g_color_profile_map.Pointer();
42 (*cache)[device] = profile;
43 }
44
45 bool erase(std::wstring device) {
sky 2014/05/28 15:31:21 const std::wstring&
46 base::AutoLock lock(g_color_profile_map_lock.Get());
47
48 ColorProfileMap* cache = g_color_profile_map.Pointer();
49 ColorProfileMap::iterator it = cache->find(device);
50 if (it == cache->end())
51 return false;
52
53 cache->erase(device);
54 return true;
55 }
56
57 void clear() {
58 base::AutoLock lock(g_color_profile_map_lock.Get());
59
60 ColorProfileMap* cache = g_color_profile_map.Pointer();
61 cache->clear();
62 }
63 };
64
13 bool GetDisplayColorProfile(const gfx::Rect& bounds, 65 bool GetDisplayColorProfile(const gfx::Rect& bounds,
14 std::vector<char>* profile) { 66 std::vector<char>* profile) {
15 if (bounds.IsEmpty()) 67 if (bounds.IsEmpty())
16 return false; 68 return false;
17 // TODO(noel): implement. 69 // TODO(noel): implement.
18 return false; 70 return false;
19 } 71 }
20 72
21 void ReadColorProfile(std::vector<char>* profile) { 73 void ReadColorProfile(std::vector<char>* profile) {
22 // TODO: support multiple monitors. 74 // TODO: support multiple monitors.
23 HDC screen_dc = GetDC(NULL); 75 HDC screen_dc = GetDC(NULL);
24 DWORD path_len = MAX_PATH; 76 DWORD path_len = MAX_PATH;
25 WCHAR path[MAX_PATH + 1]; 77 WCHAR path[MAX_PATH + 1];
26 78
27 BOOL result = GetICMProfile(screen_dc, &path_len, path); 79 BOOL result = GetICMProfile(screen_dc, &path_len, path);
28 ReleaseDC(NULL, screen_dc); 80 ReleaseDC(NULL, screen_dc);
29 if (!result) 81 if (!result)
30 return; 82 return;
31 std::string profileData; 83 std::string profileData;
32 if (!base::ReadFileToString(base::FilePath(path), &profileData)) 84 if (!base::ReadFileToString(base::FilePath(path), &profileData))
33 return; 85 return;
34 size_t length = profileData.size(); 86 size_t length = profileData.size();
35 if (gfx::InvalidColorProfileLength(length)) 87 if (gfx::InvalidColorProfileLength(length))
36 return; 88 return;
37 profile->assign(profileData.data(), profileData.data() + length); 89 profile->assign(profileData.data(), profileData.data() + length);
38 } 90 }
39 91
40 } // namespace gfx 92 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698