Commit a657075b authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: makes cursor configuration apply in mus/mash

The cursor config controls the scale (additional factor influencing
how fast the cursor moves) and rotation of the cursor in ozone. Ash
was applying this, but in mus/mash we need the window-server to apply
it. This patch makes mus automatically apply the scale.

BUG=701068
TEST=covered by test

Change-Id: Ibb4fb3d4584bc23bd17e9f1b527857e27f0b6564
Reviewed-on: https://chromium-review.googlesource.com/572326Reviewed-by: default avatarElliot Glaysher <erg@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487164}
parent ada1507d
......@@ -47,6 +47,7 @@ include_rules = [
"+chromeos/system",
# Ozone does not run in process in mus/mash.
"-ui/events/ozone",
"-ui/ozone",
]
......
......@@ -59,10 +59,6 @@
#undef RootWindow
#endif // defined(USE_X11)
#if defined(USE_OZONE)
#include "ui/events/ozone/chromeos/cursor_controller.h"
#endif
namespace ash {
namespace {
......@@ -73,11 +69,6 @@ namespace {
// This is initialized in the constructor, and then in CreatePrimaryHost().
int64_t primary_display_id = -1;
#if defined(USE_OZONE)
// Add 20% more cursor motion on non-integrated displays.
const float kCursorMultiplierForExternalDisplays = 1.2f;
#endif
display::DisplayManager* GetDisplayManager() {
return Shell::Get()->display_manager();
}
......@@ -122,14 +113,7 @@ void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host,
ui::SetIntProperty(xwindow, kScaleFactorProp, kCARDINAL,
100 * display.device_scale_factor());
#elif defined(USE_OZONE)
// Scale all motion on High-DPI displays.
float scale = display.device_scale_factor();
if (!display.IsInternal())
scale *= kCursorMultiplierForExternalDisplays;
ui::CursorController::GetInstance()->SetCursorConfigForWindow(
host->GetAcceleratedWidget(), info.GetActiveRotation(), scale);
ash_host->SetCursorConfig(display, info.GetActiveRotation());
#endif
std::unique_ptr<RootWindowTransformer> transformer(
CreateRootWindowTransformerForDisplay(host->window(), display));
......@@ -143,16 +127,14 @@ void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host,
mode->refresh_rate()));
}
// Just movnig the display requires the full redraw.
// Just moving the display requires the full redraw.
// chrome-os-partner:33558.
host->compositor()->ScheduleFullRedraw();
}
void ClearDisplayPropertiesOnHost(AshWindowTreeHost* ash_host) {
#if defined(USE_OZONE)
aura::WindowTreeHost* host = ash_host->AsWindowTreeHost();
ui::CursorController::GetInstance()->ClearCursorConfigForWindow(
host->GetAcceleratedWidget());
ash_host->ClearCursorConfig();
#endif
}
......
......@@ -13,5 +13,8 @@ specific_include_rules = {
"ash_window_tree_host_platform.cc": [
"+ash/shell.h",
"+ash/shell_delegate.h",
# AshWindowTreeHostPlatform is only used in classic ash, so it can use
# ozone.
"+ui/events/ozone/chromeos/cursor_controller.h",
],
}
......@@ -8,6 +8,7 @@
#include <memory>
#include "ash/ash_export.h"
#include "ui/display/display.h"
namespace aura {
class WindowTreeHost;
......@@ -56,6 +57,12 @@ class ASH_EXPORT AshWindowTreeHost {
virtual void RegisterMirroringHost(AshWindowTreeHost* mirroring_ash_host) {}
#if defined(USE_OZONE)
virtual void SetCursorConfig(const display::Display& display,
display::Display::Rotation rotation) = 0;
virtual void ClearCursorConfig() = 0;
#endif
protected:
// Translates the native mouse location into screen coordinates.
void TranslateLocatedEvent(ui::LocatedEvent* event);
......
......@@ -21,6 +21,8 @@
#if defined(USE_OZONE)
#include "services/ui/public/cpp/input_devices/input_device_controller_client.h"
#include "services/ui/public/interfaces/window_manager.mojom.h"
#include "ui/events/ozone/chromeos/cursor_controller.h"
#endif
namespace ash {
......@@ -54,6 +56,26 @@ void AshWindowTreeHostPlatform::UnConfineCursor() {
NOTIMPLEMENTED();
}
#if defined(USE_OZONE)
void AshWindowTreeHostPlatform::SetCursorConfig(
const display::Display& display,
display::Display::Rotation rotation) {
// Scale all motion on High-DPI displays.
float scale = display.device_scale_factor();
if (!display.IsInternal())
scale *= ui::mojom::kCursorMultiplierForExternalDisplays;
ui::CursorController::GetInstance()->SetCursorConfigForWindow(
GetAcceleratedWidget(), rotation, scale);
}
void AshWindowTreeHostPlatform::ClearCursorConfig() {
ui::CursorController::GetInstance()->ClearCursorConfigForWindow(
GetAcceleratedWidget());
}
#endif
void AshWindowTreeHostPlatform::SetRootWindowTransformer(
std::unique_ptr<RootWindowTransformer> transformer) {
transformer_helper_.SetRootWindowTransformer(std::move(transformer));
......
......@@ -33,6 +33,13 @@ class ASH_EXPORT AshWindowTreeHostPlatform
gfx::Insets GetHostInsets() const override;
aura::WindowTreeHost* AsWindowTreeHost() override;
void PrepareForShutdown() override;
#if defined(USE_OZONE)
void SetCursorConfig(const display::Display& display,
display::Display::Rotation rotation) override;
void ClearCursorConfig() override;
#endif
// aura::WindowTreeHostPlatform:
void SetRootTransform(const gfx::Transform& transform) override;
gfx::Transform GetRootTransform() const override;
gfx::Transform GetInverseRootTransform() const override;
......
......@@ -74,6 +74,16 @@ void AshWindowTreeHostMus::RegisterMirroringHost(
NOTIMPLEMENTED();
}
void AshWindowTreeHostMus::SetCursorConfig(
const display::Display& display,
display::Display::Rotation rotation) {
// Nothing to do here, mus takes care of this.
}
void AshWindowTreeHostMus::ClearCursorConfig() {
// Nothing to do here, mus takes care of this.
}
void AshWindowTreeHostMus::SetRootTransform(const gfx::Transform& transform) {
transformer_helper_->SetTransform(transform);
}
......
......@@ -29,6 +29,11 @@ class AshWindowTreeHostMus : public AshWindowTreeHost,
aura::WindowTreeHost* AsWindowTreeHost() override;
void PrepareForShutdown() override;
void RegisterMirroringHost(AshWindowTreeHost* mirroring_ash_host) override;
#if defined(USE_OZONE)
void SetCursorConfig(const display::Display& display,
display::Display::Rotation rotation) override;
void ClearCursorConfig() override;
#endif
// aura::WindowTreeHostMus:
void SetRootTransform(const gfx::Transform& transform) override;
......
......@@ -72,3 +72,7 @@ struct WmViewportMetrics {
float device_scale_factor;
float ui_scale_factor;
};
// Scale factor applied to cursor movement on external displays.
// TODO(sky): remove this once classic ash is removed.
const float kCursorMultiplierForExternalDisplays = 1.2;
......@@ -161,10 +161,13 @@ static_library("lib") {
]
if (use_ozone) {
public_deps += [ "//ui/ozone:ozone" ]
public_deps += [ "//ui/ozone" ]
}
if (is_chromeos) {
public_deps += [ "//ui/chromeos/events" ]
if (use_ozone) {
public_deps += [ "//ui/events/ozone:events_ozone" ]
}
}
# ui service should not depend on below components.
......
......@@ -74,6 +74,7 @@ void Display::Init(const display::ViewportMetrics& metrics,
platform_display_ = PlatformDisplay::Create(
root_.get(), metrics, window_server_->GetThreadedImageCursorsFactory());
platform_display_->Init(this);
UpdateCursorConfig();
}
int64_t Display::GetId() const {
......@@ -83,6 +84,8 @@ int64_t Display::GetId() const {
void Display::SetDisplay(const display::Display& display) {
display_ = display;
UpdateCursorConfig();
}
const display::Display& Display::GetDisplay() {
......@@ -275,6 +278,16 @@ void Display::CreateRootWindow(const gfx::Size& size) {
focus_controller_->AddObserver(this);
}
void Display::UpdateCursorConfig() {
float scale = display_.device_scale_factor();
if (!display_.IsInternal())
scale *= ui::mojom::kCursorMultiplierForExternalDisplays;
if (platform_display_)
platform_display_->SetCursorConfig(display_.rotation(), scale);
}
ServerWindow* Display::GetRootWindow() {
return root_.get();
}
......
......@@ -76,8 +76,7 @@ class Display : public PlatformDisplayDelegate,
// display::Display ID. In external mode this hasn't been defined yet.
int64_t GetId() const;
// Sets the display::Display corresponding to this ws::Display. This is only
// valid in internal window mode.
// Sets the display::Display corresponding to this ws::Display.
void SetDisplay(const display::Display& display);
// PlatformDisplayDelegate:
......@@ -189,6 +188,9 @@ class Display : public PlatformDisplayDelegate,
// pixels.
void CreateRootWindow(const gfx::Size& size);
// Applyes the cursor scale and rotation to the PlatformDisplay.
void UpdateCursorConfig();
// PlatformDisplayDelegate:
ServerWindow* GetRootWindow() override;
EventSink* GetEventSink() override;
......
......@@ -13,6 +13,7 @@
#include "base/strings/string16.h"
#include "services/ui/display/viewport_metrics.h"
#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
#include "ui/display/display.h"
#include "ui/events/event_source.h"
#include "ui/gfx/native_widget_types.h"
......@@ -68,6 +69,9 @@ class PlatformDisplay : public ui::EventSource {
virtual FrameGenerator* GetFrameGenerator() = 0;
virtual void SetCursorConfig(display::Display::Rotation rotation,
float scale) = 0;
// Overrides factory for testing. Default (NULL) value indicates regular
// (non-test) environment.
static void set_factory_for_testing(PlatformDisplayFactory* factory) {
......
......@@ -7,6 +7,7 @@
#include <utility>
#include "base/memory/ptr_util.h"
#include "build/build_config.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "services/ui/display/screen_manager.h"
#include "services/ui/public/interfaces/cursor/cursor_struct_traits.h"
......@@ -25,6 +26,7 @@
#elif defined(OS_ANDROID)
#include "ui/platform_window/android/platform_window_android.h"
#elif defined(USE_OZONE)
#include "ui/events/ozone/chromeos/cursor_controller.h"
#include "ui/ozone/public/cursor_factory_ozone.h"
#include "ui/ozone/public/ozone_platform.h"
#endif
......@@ -42,6 +44,11 @@ PlatformDisplayDefault::PlatformDisplayDefault(
widget_(gfx::kNullAcceleratedWidget) {}
PlatformDisplayDefault::~PlatformDisplayDefault() {
#if defined(USE_OZONE) && defined(OS_CHROMEOS)
ui::CursorController::GetInstance()->ClearCursorConfigForWindow(
GetAcceleratedWidget());
#endif
// Don't notify the delegate from the destructor.
delegate_ = nullptr;
......@@ -191,6 +198,15 @@ gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const {
return widget_;
}
void PlatformDisplayDefault::SetCursorConfig(
display::Display::Rotation rotation,
float scale) {
#if defined(USE_OZONE) && defined(OS_CHROMEOS)
ui::CursorController::GetInstance()->SetCursorConfigForWindow(
GetAcceleratedWidget(), rotation, scale);
#endif
}
void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) {
// We only care if the window size has changed.
if (new_bounds.size() == metrics_.bounds_in_pixels.size())
......
......@@ -52,6 +52,8 @@ class PlatformDisplayDefault : public PlatformDisplay,
void UpdateViewportMetrics(const display::ViewportMetrics& metrics) override;
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
FrameGenerator* GetFrameGenerator() override;
void SetCursorConfig(display::Display::Rotation rotation,
float scale) override;
private:
// ui::PlatformWindowDelegate:
......
......@@ -31,46 +31,6 @@ namespace ws {
namespace test {
namespace {
// -----------------------------------------------------------------------------
// Empty implementation of PlatformDisplay.
class TestPlatformDisplay : public PlatformDisplay {
public:
explicit TestPlatformDisplay(const display::ViewportMetrics& metrics,
ui::CursorData* cursor_storage)
: metrics_(metrics), cursor_storage_(cursor_storage) {}
~TestPlatformDisplay() override {}
// PlatformDisplay:
void Init(PlatformDisplayDelegate* delegate) override {
delegate->OnAcceleratedWidgetAvailable();
}
void SetViewportSize(const gfx::Size& size) override {}
void SetTitle(const base::string16& title) override {}
void SetCapture() override {}
void ReleaseCapture() override {}
void SetCursor(const ui::CursorData& cursor) override {
*cursor_storage_ = cursor;
}
void SetCursorSize(const ui::CursorSize& cursor_size) override {}
void MoveCursorTo(const gfx::Point& window_pixel_location) override {}
void UpdateTextInputState(const ui::TextInputState& state) override {}
void SetImeVisibility(bool visible) override {}
void UpdateViewportMetrics(const display::ViewportMetrics& metrics) override {
metrics_ = metrics;
}
gfx::AcceleratedWidget GetAcceleratedWidget() const override {
return gfx::kNullAcceleratedWidget;
}
FrameGenerator* GetFrameGenerator() override { return nullptr; }
EventSink* GetEventSink() override { return nullptr; }
private:
display::ViewportMetrics metrics_;
ui::CursorData* cursor_storage_;
DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay);
};
ClientWindowId NextUnusedClientWindowId(WindowTree* tree) {
ClientWindowId client_id;
for (ClientSpecificId id = 1;; ++id) {
......@@ -720,6 +680,49 @@ void TestDisplayManagerObserver::OnDisplaysChanged(
observer_calls_ += "OnDisplaysChanged " + DisplayIdsToString(displays);
}
// -----------------------------------------------------------------------------
TestPlatformDisplay::TestPlatformDisplay(
const display::ViewportMetrics& metrics,
ui::CursorData* cursor_storage)
: metrics_(metrics), cursor_storage_(cursor_storage) {}
TestPlatformDisplay::~TestPlatformDisplay() = default;
// PlatformDisplay:
void TestPlatformDisplay::Init(PlatformDisplayDelegate* delegate) {
delegate->OnAcceleratedWidgetAvailable();
}
void TestPlatformDisplay::SetViewportSize(const gfx::Size& size) {}
void TestPlatformDisplay::SetTitle(const base::string16& title) {}
void TestPlatformDisplay::SetCapture() {}
void TestPlatformDisplay::ReleaseCapture() {}
void TestPlatformDisplay::SetCursor(const ui::CursorData& cursor) {
*cursor_storage_ = cursor;
}
void TestPlatformDisplay::SetCursorSize(const ui::CursorSize& cursor_size) {}
void TestPlatformDisplay::MoveCursorTo(
const gfx::Point& window_pixel_location) {}
void TestPlatformDisplay::UpdateTextInputState(
const ui::TextInputState& state) {}
void TestPlatformDisplay::SetImeVisibility(bool visible) {}
void TestPlatformDisplay::UpdateViewportMetrics(
const display::ViewportMetrics& metrics) {
metrics_ = metrics;
}
gfx::AcceleratedWidget TestPlatformDisplay::GetAcceleratedWidget() const {
return gfx::kNullAcceleratedWidget;
}
FrameGenerator* TestPlatformDisplay::GetFrameGenerator() {
return nullptr;
}
EventSink* TestPlatformDisplay::GetEventSink() {
return nullptr;
}
void TestPlatformDisplay::SetCursorConfig(display::Display::Rotation rotation,
float scale) {
cursor_scale_ = scale;
}
// -----------------------------------------------------------------------------
void AddWindowManager(WindowServer* window_server,
......
......@@ -726,6 +726,47 @@ class TestDisplayManagerObserver : public mojom::DisplayManagerObserver {
DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerObserver);
};
// -----------------------------------------------------------------------------
// Empty implementation of PlatformDisplay.
class TestPlatformDisplay : public PlatformDisplay {
public:
TestPlatformDisplay(const display::ViewportMetrics& metrics,
ui::CursorData* cursor_storage);
~TestPlatformDisplay() override;
display::Display::Rotation cursor_rotation() const {
return cursor_rotation_;
}
float cursor_scale() const { return cursor_scale_; }
// PlatformDisplay:
void Init(PlatformDisplayDelegate* delegate) override;
void SetViewportSize(const gfx::Size& size) override;
void SetTitle(const base::string16& title) override;
void SetCapture() override;
void ReleaseCapture() override;
void SetCursor(const ui::CursorData& cursor) override;
void SetCursorSize(const ui::CursorSize& cursor_size) override;
void MoveCursorTo(const gfx::Point& window_pixel_location) override;
void UpdateTextInputState(const ui::TextInputState& state) override;
void SetImeVisibility(bool visible) override;
void UpdateViewportMetrics(const display::ViewportMetrics& metrics) override;
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
FrameGenerator* GetFrameGenerator() override;
EventSink* GetEventSink() override;
void SetCursorConfig(display::Display::Rotation rotation,
float scale) override;
private:
display::ViewportMetrics metrics_;
ui::CursorData* cursor_storage_;
display::Display::Rotation cursor_rotation_ =
display::Display::Rotation::ROTATE_0;
float cursor_scale_ = 1.0f;
DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay);
};
// -----------------------------------------------------------------------------
// Adds a new WM to |window_server| for |user_id|. Creates
......
......@@ -17,6 +17,7 @@
#include "services/ui/common/task_runner_test_base.h"
#include "services/ui/common/types.h"
#include "services/ui/common/util.h"
#include "services/ui/public/interfaces/window_manager_constants.mojom.h"
#include "services/ui/public/interfaces/window_tree.mojom.h"
#include "services/ui/ws/default_access_policy.h"
#include "services/ui/ws/display_manager.h"
......@@ -1760,12 +1761,16 @@ TEST_F(WindowTreeManualDisplayTest,
EXPECT_TRUE(display_manager_observer.GetAndClearObserverCalls().empty());
// Add a new display.
display::Display display1 = MakeDisplay(0, 0, 1024, 768, 1.0f);
// The value for the scale factor doesn't matter, just choosing something
// other than 1 to ensure values other than 1 correctly take.
const float kDisplay1ScaleFactor = 2.25;
display::Display display1 =
MakeDisplay(0, 0, 1024, 768, kDisplay1ScaleFactor);
const int64_t display_id1 = 101;
display1.set_id(display_id1);
mojom::WmViewportMetrics metrics1;
metrics1.bounds_in_pixels = display1.bounds();
metrics1.device_scale_factor = 1.5;
metrics1.device_scale_factor = kDisplay1ScaleFactor;
metrics1.ui_scale_factor = 2.5;
const bool is_primary_display = true;
ASSERT_TRUE(WindowTreeTestApi(window_manager_tree)
......@@ -1784,6 +1789,12 @@ TEST_F(WindowTreeManualDisplayTest,
RunUntilIdle();
EXPECT_EQ("OnDisplaysChanged " + std::to_string(display_id1),
display_manager_observer.GetAndClearObserverCalls());
PlatformDisplay* platform_display1 =
display_manager->GetDisplayById(display_id1)->platform_display();
ASSERT_TRUE(platform_display1);
EXPECT_EQ(
kDisplay1ScaleFactor * ui::mojom::kCursorMultiplierForExternalDisplays,
static_cast<TestPlatformDisplay*>(platform_display1)->cursor_scale());
// Create a window for the windowmanager and set it as the root.
ClientWindowId display_root_id2 =
......
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