summaryrefslogtreecommitdiffstats
path: root/win8/metro_driver
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-29 21:34:01 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-29 21:34:01 +0000
commitc8a79464e743d8ca9f9315c553637d7a4eef704b (patch)
treeab67faeca5514bdc25a80a239e895226165ce2ed /win8/metro_driver
parent4be968e96a8c37345a714b248cf18f128a8c6036 (diff)
downloadchromium_src-c8a79464e743d8ca9f9315c553637d7a4eef704b.zip
chromium_src-c8a79464e743d8ca9f9315c553637d7a4eef704b.tar.gz
chromium_src-c8a79464e743d8ca9f9315c553637d7a4eef704b.tar.bz2
Use the win32 device scale factor in Chrome ASH on Windows.
The WinRT interfaces seem to be giving us the wrong values in metro mode. On Windows 8 the IDisplayProperties interface always gives us 100% for the scale factor and a dpi of 96. On 8.1 it reports incorrect scale factors which cause the content to be displayed shrunk. Fix is to use the win32 scale factor in ASH and convert the input coordinates to DIP correctly before passing them to chrome. We also convert the width and height of the window to pixels using the win32 scale factor before initializing the direct3d swap chain. BUG=376529 R=cpu Review URL: https://codereview.chromium.org/300003002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'win8/metro_driver')
-rw-r--r--win8/metro_driver/chrome_app_view_ash.cc52
-rw-r--r--win8/metro_driver/chrome_app_view_ash.h7
-rw-r--r--win8/metro_driver/direct3d_helper.cc20
-rw-r--r--win8/metro_driver/metro_driver.gyp1
4 files changed, 57 insertions, 23 deletions
diff --git a/win8/metro_driver/chrome_app_view_ash.cc b/win8/metro_driver/chrome_app_view_ash.cc
index 49d517e..c104a15 100644
--- a/win8/metro_driver/chrome_app_view_ash.cc
+++ b/win8/metro_driver/chrome_app_view_ash.cc
@@ -23,6 +23,8 @@
#include "ipc/ipc_channel_proxy.h"
#include "ipc/ipc_sender.h"
#include "ui/events/gestures/gesture_sequence.h"
+#include "ui/gfx/geometry/point_conversions.h"
+#include "ui/gfx/win/dpi.h"
#include "ui/metro_viewer/metro_viewer_messages.h"
#include "win8/metro_driver/file_picker_ash.h"
#include "win8/metro_driver/ime/ime_popup_monitor.h"
@@ -362,7 +364,7 @@ bool LaunchChromeBrowserProcess(const wchar_t* additional_parameters,
// This class helps decoding the pointer properties of an event.
class ChromeAppViewAsh::PointerInfoHandler {
public:
- PointerInfoHandler()
+ PointerInfoHandler(float metro_dpi_scale, float win32_dpi_scale)
: x_(0),
y_(0),
wheel_delta_(0),
@@ -370,7 +372,9 @@ class ChromeAppViewAsh::PointerInfoHandler {
timestamp_(0),
pointer_id_(0),
mouse_down_flags_(0),
- is_horizontal_wheel_(0) {}
+ is_horizontal_wheel_(0),
+ metro_dpi_scale_(metro_dpi_scale),
+ win32_dpi_scale_(win32_dpi_scale) {}
HRESULT Init(winui::Core::IPointerEventArgs* args) {
HRESULT hr = args->get_CurrentPoint(&pointer_point_);
@@ -398,8 +402,18 @@ class ChromeAppViewAsh::PointerInfoHandler {
is_horizontal_wheel_ = 0;
properties->get_IsHorizontalMouseWheel(&is_horizontal_wheel_);
- x_ = point.X;
- y_ = point.Y;
+ // The input coordinates are in DIP based on the metro scale factor.
+ // We want to convert it to DIP based on the win32 scale factor.
+ // We scale the point by the metro scale factor and then scale down
+ // via the win32 scale factor which achieves the needful.
+ gfx::Point dip_point_metro(point.X, point.Y);
+ gfx::Point scaled_point_metro =
+ gfx::ToCeiledPoint(gfx::ScalePoint(dip_point_metro, metro_dpi_scale_));
+ gfx::Point dip_point_win32 =
+ gfx::ToCeiledPoint(gfx::ScalePoint(scaled_point_metro,
+ 1.0 / win32_dpi_scale_));
+ x_ = dip_point_win32.x();
+ y_ = dip_point_win32.y();
pointer_point_->get_Timestamp(&timestamp_);
pointer_point_->get_PointerId(&pointer_id_);
@@ -502,6 +516,12 @@ class ChromeAppViewAsh::PointerInfoHandler {
// Set to true for a horizontal wheel message.
boolean is_horizontal_wheel_;
+ // The metro device scale factor as reported by the winrt interfaces.
+ float metro_dpi_scale_;
+ // The win32 dpi scale which is queried via GetDeviceCaps. Please refer to
+ // ui/gfx/win/dpi.cc for more information.
+ float win32_dpi_scale_;
+
DISALLOW_COPY_AND_ASSIGN(PointerInfoHandler);
};
@@ -509,7 +529,8 @@ ChromeAppViewAsh::ChromeAppViewAsh()
: mouse_down_flags_(ui::EF_NONE),
ui_channel_(nullptr),
core_window_hwnd_(NULL),
- scale_(0) {
+ metro_dpi_scale_(0),
+ win32_dpi_scale_(0) {
DVLOG(1) << __FUNCTION__;
globals.previous_state =
winapp::Activation::ApplicationExecutionState_NotRunning;
@@ -629,8 +650,15 @@ ChromeAppViewAsh::SetWindow(winui::Core::ICoreWindow* window) {
direct3d_helper_.Initialize(window);
DVLOG(1) << "Initialized Direct3D.";
- scale_ = GetModernUIScale();
- DVLOG(1) << "Scale is " << scale_;
+ // On Windows 8+ the WinRT interface IDisplayProperties which we use to get
+ // device scale factor does not return the correct values in metro mode.
+ // To workaround this we retrieve the device scale factor via the win32 way
+ // and scale input coordinates accordingly to pass them in DIP to chrome.
+ // TODO(ananta). Investigate and fix.
+ metro_dpi_scale_ = GetModernUIScale();
+ win32_dpi_scale_ = gfx::GetDPIScale();
+ DVLOG(1) << "Metro Scale is " << metro_dpi_scale_;
+ DVLOG(1) << "Win32 Scale is " << win32_dpi_scale_;
return S_OK;
}
@@ -675,7 +703,7 @@ ChromeAppViewAsh::Run() {
// Upon receipt of the MetroViewerHostMsg_SetTargetSurface message the
// browser will use D3D from the browser process to present to our Window.
ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface(
- gfx::NativeViewId(core_window_hwnd_), scale_));
+ gfx::NativeViewId(core_window_hwnd_), win32_dpi_scale_));
DVLOG(1) << "ICoreWindow sent " << core_window_hwnd_;
// Send an initial size message so that the Ash root window host gets sized
@@ -1047,7 +1075,7 @@ HRESULT ChromeAppViewAsh::OnActivate(
HRESULT ChromeAppViewAsh::OnPointerMoved(winui::Core::ICoreWindow* sender,
winui::Core::IPointerEventArgs* args) {
- PointerInfoHandler pointer;
+ PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
HRESULT hr = pointer.Init(args);
if (FAILED(hr))
return hr;
@@ -1077,7 +1105,7 @@ HRESULT ChromeAppViewAsh::OnPointerMoved(winui::Core::ICoreWindow* sender,
HRESULT ChromeAppViewAsh::OnPointerPressed(
winui::Core::ICoreWindow* sender,
winui::Core::IPointerEventArgs* args) {
- PointerInfoHandler pointer;
+ PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
HRESULT hr = pointer.Init(args);
if (FAILED(hr))
return hr;
@@ -1100,7 +1128,7 @@ HRESULT ChromeAppViewAsh::OnPointerPressed(
HRESULT ChromeAppViewAsh::OnPointerReleased(
winui::Core::ICoreWindow* sender,
winui::Core::IPointerEventArgs* args) {
- PointerInfoHandler pointer;
+ PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
HRESULT hr = pointer.Init(args);
if (FAILED(hr))
return hr;
@@ -1125,7 +1153,7 @@ HRESULT ChromeAppViewAsh::OnPointerReleased(
HRESULT ChromeAppViewAsh::OnWheel(
winui::Core::ICoreWindow* sender,
winui::Core::IPointerEventArgs* args) {
- PointerInfoHandler pointer;
+ PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
HRESULT hr = pointer.Init(args);
if (FAILED(hr))
return hr;
diff --git a/win8/metro_driver/chrome_app_view_ash.h b/win8/metro_driver/chrome_app_view_ash.h
index 174836d..102d010 100644
--- a/win8/metro_driver/chrome_app_view_ash.h
+++ b/win8/metro_driver/chrome_app_view_ash.h
@@ -233,8 +233,11 @@ class ChromeAppViewAsh
scoped_ptr<metro_driver::InputSource> input_source_;
scoped_ptr<metro_driver::TextService> text_service_;
- // The device scale factor.
- float scale_;
+ // The metro device scale factor as reported by the winrt interfaces.
+ float metro_dpi_scale_;
+ // The win32 dpi scale which is queried via GetDeviceCaps. Please refer to
+ // ui/gfx/win/dpi.cc for more information.
+ float win32_dpi_scale_;
};
#endif // WIN8_METRO_DRIVER_CHROME_APP_VIEW_ASH_H_
diff --git a/win8/metro_driver/direct3d_helper.cc b/win8/metro_driver/direct3d_helper.cc
index d0c30cf..b4da8cd 100644
--- a/win8/metro_driver/direct3d_helper.cc
+++ b/win8/metro_driver/direct3d_helper.cc
@@ -3,16 +3,16 @@
// found in the LICENSE file.
#include "stdafx.h"
-#include "win8/metro_driver/direct3d_helper.h"
-#include "win8/metro_driver/winrt_utils.h"
-
-#include "base/logging.h"
-#include "base/win/windows_version.h"
-
#include <corewindow.h>
#include <windows.applicationmodel.core.h>
#include <windows.graphics.display.h>
+#include "win8/metro_driver/direct3d_helper.h"
+#include "base/logging.h"
+#include "base/win/windows_version.h"
+#include "ui/gfx/win/dpi.h"
+#include "win8/metro_driver/winrt_utils.h"
+
namespace {
void CheckIfFailed(HRESULT hr) {
@@ -21,6 +21,10 @@ void CheckIfFailed(HRESULT hr) {
DVLOG(0) << "Direct3D call failed, hr = " << hr;
}
+// TODO(ananta)
+// This function does not return the correct value as the IDisplayProperties
+// interface does not work correctly in Windows 8 in metro mode. Needs
+// more investigation.
float GetLogicalDpi() {
mswr::ComPtr<wingfx::Display::IDisplayPropertiesStatics> display_properties;
CheckIfFailed(winrt_utils::CreateActivationFactory(
@@ -32,9 +36,7 @@ float GetLogicalDpi() {
}
float ConvertDipsToPixels(float dips) {
- static const float dips_per_inch = 96.f;
- float logical_dpi = GetLogicalDpi();
- return floor(dips * logical_dpi / dips_per_inch + 0.5f);
+ return floor(dips * gfx::GetDPIScale() + 0.5f);
}
}
diff --git a/win8/metro_driver/metro_driver.gyp b/win8/metro_driver/metro_driver.gyp
index 5c12c04..905139f 100644
--- a/win8/metro_driver/metro_driver.gyp
+++ b/win8/metro_driver/metro_driver.gyp
@@ -74,6 +74,7 @@
'../../sandbox/sandbox.gyp:sandbox',
'../../ui/metro_viewer/metro_viewer.gyp:metro_viewer_messages',
'../../ui/gfx/gfx.gyp:gfx',
+ '../../ui/gfx/gfx.gyp:gfx_geometry',
'../../url/url.gyp:url_lib',
'metro_driver_version_resources',
],