Commit 00d3a762 authored by ananta@chromium.org's avatar ananta@chromium.org

Send the device scale factor from Windows 8 ASH during initialization via the...

Send the device scale factor from Windows 8 ASH during initialization via the MetroViewerHostMsg_SetTargetSurface IPC message.

cpu, please review everything.
sky, please review the ash/chrome/ui portions.

I added a dependency on gfx in the metro_driver project for a subsequent change to send the correct device scale
factor on Windows 8 as the metro API does not appear to work correctly causing text, etc to appear very small on
high dpi monitors with scales above 125%.

BUG=371219
R=cpu,sky

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269993 0039d316-1c4b-4281-b951-d872f2087c98
parent dbd338c4
......@@ -115,7 +115,7 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
} else {
#if defined(OS_WIN)
if (gfx::IsHighDPIEnabled()) {
device_scale_factor = gfx::GetModernUIScale();
device_scale_factor = gfx::GetDPIScale();
}
#endif
}
......
......@@ -26,10 +26,12 @@ void TestMetroViewerProcessHost::OnChannelError() {
}
void TestMetroViewerProcessHost::OnSetTargetSurface(
gfx::NativeViewId target_surface) {
gfx::NativeViewId target_surface,
float device_scale) {
DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface;
HWND hwnd = reinterpret_cast<HWND>(target_surface);
aura::RemoteWindowTreeHostWin::Instance()->SetRemoteWindowHandle(hwnd);
aura::RemoteWindowTreeHostWin::Instance()->
InitializeRemoteWindowAndScaleFactor(hwnd, device_scale);
aura::RemoteWindowTreeHostWin::Instance()->Connected(this);
}
......
......@@ -23,7 +23,8 @@ class TestMetroViewerProcessHost : public win8::MetroViewerProcessHost {
private:
// win8::MetroViewerProcessHost implementation
virtual void OnChannelError() OVERRIDE;
virtual void OnSetTargetSurface(gfx::NativeViewId target_surface) OVERRIDE;
virtual void OnSetTargetSurface(gfx::NativeViewId target_surface,
float device_scale) OVERRIDE;
virtual void OnOpenURL(const base::string16& url) OVERRIDE;
virtual void OnHandleSearchRequest(
const base::string16& search_string) OVERRIDE;
......
......@@ -116,13 +116,15 @@ void ChromeMetroViewerProcessHost::OnChannelConnected(int32 /*peer_pid*/) {
}
void ChromeMetroViewerProcessHost::OnSetTargetSurface(
gfx::NativeViewId target_surface) {
gfx::NativeViewId target_surface,
float device_scale) {
HWND hwnd = reinterpret_cast<HWND>(target_surface);
// Make hwnd available as early as possible for proper InputMethod
// initialization.
ash::AshRemoteWindowTreeHostWin::Init();
aura::RemoteWindowTreeHostWin::Instance()->SetRemoteWindowHandle(hwnd);
aura::RemoteWindowTreeHostWin::Instance()->
InitializeRemoteWindowAndScaleFactor(hwnd, device_scale);
// Now start the Ash shell environment.
chrome::OpenAsh();
......@@ -158,7 +160,7 @@ void ChromeMetroViewerProcessHost::OnWindowSizeChanged(uint32 width,
uint32 height) {
std::vector<ash::DisplayInfo> info_list;
info_list.push_back(ash::DisplayInfo::CreateFromSpec(
base::StringPrintf("%dx%d*%f", width, height, gfx::GetModernUIScale())));
base::StringPrintf("%dx%d*%f", width, height, gfx::GetDPIScale())));
ash::Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
info_list);
aura::RemoteWindowTreeHostWin::Instance()->HandleWindowSizeChanged(width,
......
......@@ -16,7 +16,8 @@ class ChromeMetroViewerProcessHost : public win8::MetroViewerProcessHost {
virtual void OnChannelError() OVERRIDE;
// IPC::Listener implementation
virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
virtual void OnSetTargetSurface(gfx::NativeViewId target_surface) OVERRIDE;
virtual void OnSetTargetSurface(gfx::NativeViewId target_surface,
float device_scale) OVERRIDE;
virtual void OnOpenURL(const base::string16& url) OVERRIDE;
virtual void OnHandleSearchRequest(
const base::string16& search_string) OVERRIDE;
......
......@@ -183,8 +183,11 @@ bool RemoteWindowTreeHostWin::IsValid() {
return Instance()->remote_window_ != NULL;
}
void RemoteWindowTreeHostWin::SetRemoteWindowHandle(HWND remote_window) {
void RemoteWindowTreeHostWin::InitializeRemoteWindowAndScaleFactor(
HWND remote_window,
float device_scale) {
remote_window_ = remote_window;
gfx::InitDeviceScaleFactor(device_scale);
// Do not create compositor here, but in Connected() below.
// See http://crbug.com/330179 and http://crbug.com/334380.
}
......@@ -489,7 +492,7 @@ void RemoteWindowTreeHostWin::OnTextInputClientUpdated(
}
gfx::Point PointFromNativeEvent(int32 x, int32 y) {
static float scale_factor = gfx::GetModernUIScale();
static float scale_factor = gfx::GetDPIScale();
gfx::Point result( x * scale_factor, y * scale_factor);
return result;
}
......
......@@ -120,10 +120,13 @@ class AURA_EXPORT RemoteWindowTreeHostWin
// HWND. A return value of false typically indicates we're not in metro mode.
static bool IsValid();
// Sets the handle to the remote window. The |remote_window| is the actual
// window owned by the viewer process. Call this before Connected() for some
// customers like input method initialization which needs the handle.
void SetRemoteWindowHandle(HWND remote_window);
// Sets the handle to the remote window and the scale factor. The
// |remote_window| is the actual window owned by the viewer process. Call
// this before Connected() for some customers like input method
// initialization which needs the handle.
// |device_scale| indicates the Windows 8 dpi scale.
void InitializeRemoteWindowAndScaleFactor(HWND remote_window,
float device_scale);
// The |host| can be used when we need to send a message to it.
void Connected(IPC::Sender* host);
......
......@@ -13,15 +13,7 @@ namespace ui {
namespace win {
void InitDeviceScaleFactor() {
float scale = 1.0;
if (CommandLine::ForCurrentProcess()->HasSwitch("silent-launch")) {
if (gfx::IsHighDPIEnabled())
scale = gfx::GetModernUIScale();
}
else {
scale = gfx::GetDPIScale();
}
gfx::InitDeviceScaleFactor(scale);
gfx::InitDeviceScaleFactor(gfx::GetDPIScale());
}
} // namespace win
......
......@@ -38,29 +38,16 @@ BOOL IsProcessDPIAwareWrapper() {
float g_device_scale_factor = 0.0f;
float GetUnforcedDeviceScaleFactor() {
// If the global device scale factor is initialized use it. This is to ensure
// we use the same scale factor across all callsites. We don't use the
// GetDeviceScaleFactor function here because it fires a DCHECK if the
// g_device_scale_factor global is 0.
if (g_device_scale_factor)
return g_device_scale_factor;
return static_cast<float>(gfx::GetDPI().width()) /
static_cast<float>(kDefaultDPIX);
}
float GetModernUIScaleWrapper() {
float result = 1.0f;
// TODO(cpu) : Fix scale for Win7.
if (base::win::GetVersion() < base::win::VERSION_WIN8)
return result;
typedef float(WINAPI *GetModernUIScalePtr)(VOID);
HMODULE lib = LoadLibraryA("metro_driver.dll");
if (lib) {
GetModernUIScalePtr func =
reinterpret_cast<GetModernUIScalePtr>(
GetProcAddress(lib, "GetModernUIScale"));
if (func)
result = func();
FreeLibrary(lib);
}
return result;
}
// Duplicated from Win8.1 SDK ShellScalingApi.h
typedef enum PROCESS_DPI_AWARENESS {
PROCESS_DPI_UNAWARE = 0,
......@@ -126,10 +113,6 @@ DWORD ReadRegistryValue(HKEY root,
namespace gfx {
float GetModernUIScale() {
return GetModernUIScaleWrapper();
}
void InitDeviceScaleFactor(float scale) {
DCHECK_NE(0.0f, scale);
g_device_scale_factor = scale;
......
......@@ -22,14 +22,9 @@ GFX_EXPORT void InitDeviceScaleFactor(float scale);
GFX_EXPORT Size GetDPI();
// Gets the scale factor of the display. For example, if the display DPI is
// 96 then the scale factor is 1.0. Note that this is the "desktop" scale, which
// may be differnt than GetModernUIScale().
// 96 then the scale factor is 1.0.
GFX_EXPORT float GetDPIScale();
// Gets the scale factor of the modern (metro) UI display. Returns 1.0 for
// unscaled or "not running on win8+"
GFX_EXPORT float GetModernUIScale();
// Tests to see if the command line flag "--high-dpi-support" is set.
GFX_EXPORT bool IsHighDPIEnabled();
......
......@@ -33,8 +33,9 @@ IPC_STRUCT_END()
// Messages sent from the viewer to the browser:
// Inform the browser of the surface to target for compositing.
IPC_MESSAGE_CONTROL1(MetroViewerHostMsg_SetTargetSurface,
gfx::NativeViewId /* target hwnd */)
IPC_MESSAGE_CONTROL2(MetroViewerHostMsg_SetTargetSurface,
gfx::NativeViewId /* target hwnd */,
float /* device scale */)
// Informs the browser that the mouse moved.
IPC_MESSAGE_CONTROL3(MetroViewerHostMsg_MouseMoved,
int32, /* x-coordinate */
......
......@@ -74,6 +74,8 @@ struct Globals {
BreakpadExceptionHandler breakpad_exception_handler;
} globals;
extern float GetModernUIScale();
namespace {
enum KeyModifier {
......@@ -506,7 +508,8 @@ class ChromeAppViewAsh::PointerInfoHandler {
ChromeAppViewAsh::ChromeAppViewAsh()
: mouse_down_flags_(ui::EF_NONE),
ui_channel_(nullptr),
core_window_hwnd_(NULL) {
core_window_hwnd_(NULL),
scale_(0) {
DVLOG(1) << __FUNCTION__;
globals.previous_state =
winapp::Activation::ApplicationExecutionState_NotRunning;
......@@ -625,6 +628,9 @@ ChromeAppViewAsh::SetWindow(winui::Core::ICoreWindow* window) {
// we can now directly blit to it from the browser process.
direct3d_helper_.Initialize(window);
DVLOG(1) << "Initialized Direct3D.";
scale_ = GetModernUIScale();
DVLOG(1) << "Scale is " << scale_;
return S_OK;
}
......@@ -669,7 +675,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_)));
gfx::NativeViewId(core_window_hwnd_), scale_));
DVLOG(1) << "ICoreWindow sent " << core_window_hwnd_;
// Send an initial size message so that the Ash root window host gets sized
......
......@@ -232,6 +232,9 @@ class ChromeAppViewAsh
// For IME support.
scoped_ptr<metro_driver::InputSource> input_source_;
scoped_ptr<metro_driver::TextService> text_service_;
// The device scale factor.
float scale_;
};
#endif // WIN8_METRO_DRIVER_CHROME_APP_VIEW_ASH_H_
......@@ -9,15 +9,10 @@
#include <wrl\wrappers\corewrappers.h>
#include <windows.foundation.h>
#include <windows.graphics.display.h>
#include "base/win/scoped_com_initializer.h"
#include "ui/gfx/win/dpi.h"
#include "winrt_utils.h"
#pragma comment(lib, "runtimeobject.lib")
extern "C" {
__declspec(dllexport) float GetModernUIScale() {
base::win::ScopedCOMInitializer com_init;
float GetModernUIScale() {
Microsoft::WRL::ComPtr<
ABI::Windows::Graphics::Display::IDisplayPropertiesStatics>
display_properties;
......@@ -30,5 +25,3 @@ __declspec(dllexport) float GetModernUIScale() {
}
return 1.0f;
}
}
......@@ -73,6 +73,7 @@
'../../ipc/ipc.gyp:ipc',
'../../sandbox/sandbox.gyp:sandbox',
'../../ui/metro_viewer/metro_viewer.gyp:metro_viewer_messages',
'../../ui/gfx/gfx.gyp:gfx',
'../../url/url.gyp:url_lib',
'metro_driver_version_resources',
],
......
......@@ -64,7 +64,8 @@ class MetroViewerProcessHost : public IPC::Listener,
// Called over IPC by the viewer process to tell this host that it should be
// drawing to |target_surface|.
virtual void OnSetTargetSurface(gfx::NativeViewId target_surface) = 0;
virtual void OnSetTargetSurface(gfx::NativeViewId target_surface,
float device_scale) = 0;
// Called over IPC by the viewer process to request that the url passed in be
// opened.
......
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