Chromium Code Reviews| 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..81eb2e9fa76f8e4172360a5129bd6c37a7c1ccb6 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()); |
|
sky
2014/06/04 15:29:24
Can you add a DCHECK that this isn't on the UI thr
Noel Gordon
2014/06/05 04:20:03
Plan is to do that at the call-site in render_widg
|
| + |
| + RECT rect = bounds.ToRECT(); |
| + HMONITOR handle = ::MonitorFromRect(&rect, MONITOR_DEFAULTTONULL); |
| + if (bounds.IsEmpty() || !handle) |
| + 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); |
|
sky
2014/06/04 15:29:24
Use the scoper in scoped_hdc.h.
Noel Gordon
2014/06/05 04:20:03
It requires a HWND and works for a GetDC/ReleaseDC
|
| + DWORD profile_length = MAX_PATH; |
| + WCHAR profile_path[MAX_PATH + 1]; |
| + BOOL result = ::GetICMProfile(hdc, &profile_length, profile_path); |
| + ::DeleteDC(hdc); |
| + if (!result) |
| return false; |
| - // TODO(noel): implement. |
| - return false; |
| + |
| + base::FilePath base_name = base::FilePath(profile_path).BaseName(); |
| + if (base_name != base::FilePath(L"sRGB Color Space Profile.icm")) { |
| + std::string file; |
|
sky
2014/06/04 15:29:24
nit: file_data or maybe profile_data.
Noel Gordon
2014/06/05 04:20:03
I called it data.
|
| + if (base::ReadFileToString(base::FilePath(profile_path), &file)) |
| + profile->assign(file.data(), file.data() + file.size()); |
|
sky
2014/06/04 15:29:24
*profile = file;
Noel Gordon
2014/06/05 04:20:03
Need the vector->assign() here. STL is lame when
|
| + size_t length = profile->size(); |
| + if (gfx::InvalidColorProfileLength(length)) |
|
sky
2014/06/04 15:29:24
Do this before you set profile (if on 91).
Noel Gordon
2014/06/05 04:20:03
Think we test for valid profile length sometime af
|
| + profile->clear(); |
| + } |
| + |
| + GetColorProfileCache().Insert(monitor.szDevice, *profile); |
| + return true; |
| } |
| void ReadColorProfile(std::vector<char>* profile) { |