Commit ce17019a authored by noel@chromium.org's avatar noel@chromium.org

gfx/ui/color_profile: implement GetDisplayColorProfile on win

Add a global device color profile cache and use it to extract the
color profile associated with screen display devices.

TEST=ui_unittests.exe --gtest_filter="ColorProfileTest*"
BUG=368694

Review URL: https://codereview.chromium.org/312723003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276589 0039d316-1c4b-4281-b951-d872f2087c98
parent 19d63df7
......@@ -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) {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/color_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
bool TestColorProfileUsingScreenBounds(const gfx::Rect& bounds) {
std::vector<char> color_profile;
return gfx::GetDisplayColorProfile(bounds, &color_profile);
}
TEST(ColorProfileTest, GetDisplayColorProfile) {
const gfx::Rect in_screen_bounds(10, 10, 100, 100);
EXPECT_TRUE(TestColorProfileUsingScreenBounds(in_screen_bounds));
}
TEST(ColorProfileTest, GetDisplayColorProfileForOffScreenBounds) {
const gfx::Rect off_screen_bounds(-100, -100, 10, 10);
EXPECT_FALSE(TestColorProfileUsingScreenBounds(off_screen_bounds));
}
TEST(ColorProfileTest, GetDisplayColorProfileForEmptyBounds) {
const gfx::Rect empty_screen_bounds(10, 10, 0, 0);
EXPECT_TRUE(empty_screen_bounds.IsEmpty());
EXPECT_FALSE(TestColorProfileUsingScreenBounds(empty_screen_bounds));
}
} // namespace
......@@ -110,6 +110,7 @@
'sources': [
'base/dragdrop/os_exchange_data_win_unittest.cc',
'base/win/hwnd_subclass_unittest.cc',
'gfx/color_profile_win_unittest.cc',
'gfx/font_fallback_win_unittest.cc',
'gfx/icon_util_unittest.cc',
'gfx/icon_util_unittests.rc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment