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

Unified Diff: ui/gfx/color_profile_win.cc

Issue 312723003: ui/gfx/color_profile: implement GetDisplayColorProfile on win (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor code name changes. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/gfx/color_profile_win_unittest.cc » ('j') | ui/gfx/color_profile_win_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/color_profile_win.cc
diff --git a/ui/gfx/color_profile_win.cc b/ui/gfx/color_profile_win.cc
index 67f1b7016ce65f76bbfd67760027a9c5defb04e8..a22c3d96a18a2fc1efc98401cea5d27679b10caa 100644
--- a/ui/gfx/color_profile_win.cc
+++ b/ui/gfx/color_profile_win.cc
@@ -55,12 +55,48 @@ class ColorProfileCache {
DISALLOW_COPY_AND_ASSIGN(ColorProfileCache);
};
+base::LazyInstance<ColorProfileCache>::Leaky g_color_profile_cache =
+ LAZY_INSTANCE_INITIALIZER;
+
+inline ColorProfileCache& GetColorProfileCache() {
+ return g_color_profile_cache.Get();
+}
+
bool GetDisplayColorProfile(const gfx::Rect& bounds,
std::vector<char>* profile) {
- if (bounds.IsEmpty())
+ DCHECK(profile->empty());
+
+ RECT rect = bounds.ToRECT();
+ HMONITOR handle = ::MonitorFromRect(&rect, MONITOR_DEFAULTTONULL);
+ if (bounds.IsEmpty() || !handle)
return false;
- // TODO(noel): implement.
- return false;
+
+ MONITORINFOEX monitor;
+ monitor.cbSize = sizeof(MONITORINFOEX);
+ CHECK(::GetMonitorInfo(handle, &monitor));
+ if (GetColorProfileCache().Find(monitor.szDevice, profile))
+ return true;
+
+ HDC hdc = ::CreateDC(monitor.szDevice, NULL, NULL, NULL);
+ DWORD path_length = MAX_PATH;
+ WCHAR path[MAX_PATH + 1];
+ BOOL result = ::GetICMProfile(hdc, &path_length, path);
+ ::DeleteDC(hdc);
+ if (!result)
+ return false;
+
+ base::FilePath file_name = base::FilePath(path).BaseName();
+ if (file_name != base::FilePath(L"sRGB Color Space Profile.icm")) {
+ std::string data;
+ if (base::ReadFileToString(base::FilePath(path), &data))
+ profile->assign(data.data(), data.data() + data.size());
+ size_t length = profile->size();
+ if (gfx::InvalidColorProfileLength(length))
+ profile->clear();
+ }
+
+ GetColorProfileCache().Insert(monitor.szDevice, *profile);
+ return true;
}
void ReadColorProfile(std::vector<char>* profile) {
« no previous file with comments | « no previous file | ui/gfx/color_profile_win_unittest.cc » ('j') | ui/gfx/color_profile_win_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698