| Index: ui/gfx/win/display_info.cc
|
| diff --git a/ui/gfx/win/display_info.cc b/ui/gfx/win/display_info.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9876dc996bb6362413104abac4364b56a99688e2
|
| --- /dev/null
|
| +++ b/ui/gfx/win/display_info.cc
|
| @@ -0,0 +1,88 @@
|
| +// Copyright 2016 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/win/display_info.h"
|
| +
|
| +#include "base/hash.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +
|
| +namespace {
|
| +
|
| +gfx::Display::Rotation GetRotationForDevice(const wchar_t* device_name) {
|
| + DEVMODE mode;
|
| + ::ZeroMemory(&mode, sizeof(mode));
|
| + mode.dmSize = sizeof(DEVMODE);
|
| + mode.dmDriverExtra = 0;
|
| + if (::EnumDisplaySettings(device_name, ENUM_CURRENT_SETTINGS, &mode)) {
|
| + switch (mode.dmDisplayOrientation) {
|
| + case DMDO_DEFAULT:
|
| + return gfx::Display::ROTATE_0;
|
| + case DMDO_90:
|
| + return gfx::Display::ROTATE_90;
|
| + case DMDO_180:
|
| + return gfx::Display::ROTATE_180;
|
| + case DMDO_270:
|
| + return gfx::Display::ROTATE_270;
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| + }
|
| + return gfx::Display::ROTATE_0;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +namespace gfx {
|
| +namespace win {
|
| +
|
| +int64_t DisplayInfo::HashDeviceName(const wchar_t* device_name) {
|
| + return static_cast<int64_t>(base::Hash(base::WideToUTF8(device_name)));
|
| +}
|
| +
|
| +DisplayInfo::DisplayInfo(HMONITOR monitor, float device_scale_factor)
|
| + : device_scale_factor_(device_scale_factor){
|
| + MONITORINFOEX monitor_info;
|
| + ::ZeroMemory(&monitor_info, sizeof(monitor_info));
|
| + monitor_info.cbSize = sizeof(monitor_info);
|
| + ::GetMonitorInfo(monitor, &monitor_info);
|
| + InitializeFromMonitorInfo(monitor_info);
|
| +}
|
| +
|
| +DisplayInfo::DisplayInfo(const MONITORINFOEX& monitor_info,
|
| + gfx::Display::Rotation rotation,
|
| + float device_scale_factor)
|
| + : rotation_(rotation),
|
| + device_scale_factor_(device_scale_factor) {
|
| + InitializeFromMonitorInfo(monitor_info);
|
| +}
|
| +
|
| +int64_t DisplayInfo::id() const {
|
| + return id_;
|
| +}
|
| +
|
| +gfx::Display::Rotation DisplayInfo::rotation() const {
|
| + return rotation_;
|
| +}
|
| +
|
| +const gfx::Rect& DisplayInfo::screen_rect() const {
|
| + return screen_rect_;
|
| +}
|
| +
|
| +const gfx::Rect& DisplayInfo::screen_work_rect() const {
|
| + return screen_work_rect_;
|
| +}
|
| +
|
| +float DisplayInfo::device_scale_factor() const {
|
| + return device_scale_factor_;
|
| +}
|
| +
|
| +void DisplayInfo::InitializeFromMonitorInfo(const MONITORINFOEX& monitor_info) {
|
| + id_ = HashDeviceName(monitor_info.szDevice);
|
| + screen_rect_ = gfx::Rect(monitor_info.rcMonitor);
|
| + screen_work_rect_ = gfx::Rect(monitor_info.rcWork);
|
| + rotation_ = GetRotationForDevice(monitor_info.szDevice);
|
| +}
|
| +
|
| +} // namespace win
|
| +} // namespace gfx
|
|
|