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

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/synchronization/lock.h"
10 12
11 namespace gfx { 13 namespace gfx {
12 14
15 class ColorProfileCache {
sky 2014/05/29 15:31:32 Add description.
16 public:
17 ColorProfileCache() {}
18
19 bool find(const std::wstring& device, std::vector<char>* profile) {
sky 2014/05/29 15:31:32 All your function names should be camelcase, eg Fi
20 base::AutoLock lock(lock_);
21 DeviceColorProfile::const_iterator it = cache_.find(device);
22 if (it == cache_.end())
23 return false;
24 *profile = it->second;
25 return true;
26 }
27
28 void insert(const std::wstring& device, const std::vector<char>& profile) {
29 base::AutoLock lock(lock_);
30 cache_[device] = profile;
31 }
32
33 bool erase(const std::wstring& device) {
34 base::AutoLock lock(lock_);
35 DeviceColorProfile::iterator it = cache_.find(device);
36 if (it == cache_.end())
37 return false;
38 cache_.erase(device);
39 return true;
40 }
41
42 void clear() {
43 base::AutoLock lock(lock_);
44 cache_.clear();
45 }
46
47 private:
48 typedef std::map<std::wstring, std::vector<char> > DeviceColorProfile;
49
50 DeviceColorProfile cache_;
51 base::Lock lock_;
52 };
sky 2014/05/29 15:31:32 DISALLOW_COPY_AND_ASSIGN.
53
13 bool GetDisplayColorProfile(const gfx::Rect& bounds, 54 bool GetDisplayColorProfile(const gfx::Rect& bounds,
14 std::vector<char>* profile) { 55 std::vector<char>* profile) {
15 if (bounds.IsEmpty()) 56 if (bounds.IsEmpty())
16 return false; 57 return false;
17 // TODO(noel): implement. 58 // TODO(noel): implement.
18 return false; 59 return false;
19 } 60 }
20 61
21 void ReadColorProfile(std::vector<char>* profile) { 62 void ReadColorProfile(std::vector<char>* profile) {
22 // TODO: support multiple monitors. 63 // TODO: support multiple monitors.
23 HDC screen_dc = GetDC(NULL); 64 HDC screen_dc = GetDC(NULL);
24 DWORD path_len = MAX_PATH; 65 DWORD path_len = MAX_PATH;
25 WCHAR path[MAX_PATH + 1]; 66 WCHAR path[MAX_PATH + 1];
26 67
27 BOOL result = GetICMProfile(screen_dc, &path_len, path); 68 BOOL result = GetICMProfile(screen_dc, &path_len, path);
28 ReleaseDC(NULL, screen_dc); 69 ReleaseDC(NULL, screen_dc);
29 if (!result) 70 if (!result)
30 return; 71 return;
31 std::string profileData; 72 std::string profileData;
32 if (!base::ReadFileToString(base::FilePath(path), &profileData)) 73 if (!base::ReadFileToString(base::FilePath(path), &profileData))
33 return; 74 return;
34 size_t length = profileData.size(); 75 size_t length = profileData.size();
35 if (gfx::InvalidColorProfileLength(length)) 76 if (gfx::InvalidColorProfileLength(length))
36 return; 77 return;
37 profile->assign(profileData.data(), profileData.data() + length); 78 profile->assign(profileData.data(), profileData.data() + length);
38 } 79 }
39 80
40 } // namespace gfx 81 } // 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