Skip to content

Commit

Permalink
Send default dsf to remote shell client.
Browse files Browse the repository at this point in the history
Instead of having hard coded scale information on client
side and send it back to wayland, which is basically the
same information, the server sends the default dsf to client.

Bug:64734914
Test: added unit test. Tested on 2x/1.25x devices with ARC++ side changes.

(cherry picked from commit b61a264)

Reviewed-on: https://chromium-review.googlesource.com/646026
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: David Reveman <reveman@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#499225}
Change-Id: I61654e5d218676c12f53986a00755145771f697b
Reviewed-on: https://chromium-review.googlesource.com/663421
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/branch-heads/3202@{crosswalk-project#172}
Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
  • Loading branch information
mitoshima committed Sep 12, 2017
1 parent 1a436a9 commit 62166df
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 55 deletions.
2 changes: 2 additions & 0 deletions ash/test/ash_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ void AshTestHelper::TearDown() {

command_line_.reset();

display::Display::ResetForceDeviceScaleFactorForTesting();

// WindowManager owns the CaptureController for mus/mash.
CHECK(config_ != Config::CLASSIC || !::wm::CaptureController::Get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ArcAccessibilityHelperBridgeTest : public testing::Test {
void AddPostTargetHandler(ui::EventHandler* handler) override {}
void RemovePostTargetHandler(ui::EventHandler* handler) override {}
bool IsTabletModeWindowManagerEnabled() const override { return false; }
double GetDefaultDeviceScaleFactor() const override { return 1.0; }

DISALLOW_COPY_AND_ASSIGN(FakeWMHelper);
};
Expand Down
12 changes: 9 additions & 3 deletions components/exo/display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ std::unique_ptr<ShellSurface> Display::CreatePopupShellSurface(

std::unique_ptr<ShellSurface> Display::CreateRemoteShellSurface(
Surface* surface,
int container) {
int container,
bool scale_by_defult_device_scale_factor) {
TRACE_EVENT2("exo", "Display::CreateRemoteShellSurface", "surface",
surface->AsTracedValue(), "container", container);

Expand All @@ -195,9 +196,14 @@ std::unique_ptr<ShellSurface> Display::CreateRemoteShellSurface(
// Remote shell surfaces in system modal container cannot be minimized.
bool can_minimize = container != ash::kShellWindowId_SystemModalContainer;

return base::MakeUnique<ShellSurface>(
std::unique_ptr<ShellSurface> shell_surface(base::MakeUnique<ShellSurface>(
surface, nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(),
true /* activatable */, can_minimize, container);
true /* activatable */, can_minimize, container));
if (scale_by_defult_device_scale_factor) {
shell_surface->SetScale(
WMHelper::GetInstance()->GetDefaultDeviceScaleFactor());
}
return shell_surface;
}

std::unique_ptr<SubSurface> Display::CreateSubSurface(Surface* surface,
Expand Down
3 changes: 2 additions & 1 deletion components/exo/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class Display {
// Creates a remote shell surface for an existing surface using |container|.
std::unique_ptr<ShellSurface> CreateRemoteShellSurface(
Surface* surface,
int container);
int container,
bool scale_by_default_device_scale_factor);

// Creates a sub-surface for an existing surface. The sub-surface will be
// a child of |parent|.
Expand Down
8 changes: 5 additions & 3 deletions components/exo/display_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ TEST_F(DisplayTest, CreateRemoteShellSurface) {
// Create a remote shell surface for surface1.
std::unique_ptr<ShellSurface> shell_surface1 =
display->CreateRemoteShellSurface(
surface1.get(), ash::kShellWindowId_SystemModalContainer);
surface1.get(), ash::kShellWindowId_SystemModalContainer,
true /* scale_by_default_scale_factor */);
EXPECT_TRUE(shell_surface1);

// Create a remote shell surface for surface2.
std::unique_ptr<ShellSurface> shell_surface2 =
display->CreateRemoteShellSurface(surface2.get(),
ash::kShellWindowId_DefaultContainer);
display->CreateRemoteShellSurface(
surface2.get(), ash::kShellWindowId_DefaultContainer,
false /* scale_by_default_scale_factor */);
EXPECT_TRUE(shell_surface2);
}

Expand Down
74 changes: 66 additions & 8 deletions components/exo/shell_surface_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/display/display.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/widget/widget.h"
Expand Down Expand Up @@ -85,9 +86,13 @@ class ShellSurfaceBoundsModeTest
}

std::unique_ptr<ShellSurface> CreateDefaultShellSurface(Surface* surface) {
return base::MakeUnique<ShellSurface>(surface, nullptr, GetParam(),
gfx::Point(), true, false,
ash::kShellWindowId_DefaultContainer);
if (IsClientBoundsMode()) {
return Display().CreateRemoteShellSurface(
surface, ash::kShellWindowId_DefaultContainer,
true /* scale_by_default_scale_factor */);
} else {
return Display().CreateShellSurface(surface);
}
}

private:
Expand Down Expand Up @@ -376,20 +381,73 @@ TEST_F(ShellSurfaceTest, SetGeometry) {
shell_surface->host_window()->bounds().ToString());
}

TEST_F(ShellSurfaceTest, SetScale) {
TEST_P(ShellSurfaceBoundsModeTest, DefaultDeviceScaleFactorForcedScaleFactor) {
double scale = 1.5;
display::Display::SetForceDeviceScaleFactor(scale);

int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::Display::SetInternalDisplayId(display_id);

gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
std::unique_ptr<ShellSurface> shell_surface(
CreateDefaultShellSurface(surface.get()));
surface->Attach(buffer.get());
surface->Commit();
gfx::Transform transform;
if (IsClientBoundsMode())
transform.Scale(1.0 / scale, 1.0 / scale);

EXPECT_EQ(
transform.ToString(),
shell_surface->host_window()->layer()->GetTargetTransform().ToString());
}

TEST_P(ShellSurfaceBoundsModeTest, DefaultDeviceScaleFactorFromDisplayManager) {
int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::Display::SetInternalDisplayId(display_id);
gfx::Size size(1920, 1080);

display::DisplayManager* display_manager =
ash::Shell::Get()->display_manager();

double scale = 1.25;
scoped_refptr<display::ManagedDisplayMode> mode(
new display::ManagedDisplayMode(size, 60.f, false /* overscan */,
true /*native*/, 1.0, scale));
mode->set_is_default(true);

display::ManagedDisplayInfo::ManagedDisplayModeList mode_list;
mode_list.push_back(mode);

display::ManagedDisplayInfo native_display_info(display_id, "test", false);
native_display_info.SetManagedDisplayModes(mode_list);

native_display_info.SetBounds(gfx::Rect(size));
native_display_info.set_device_scale_factor(scale);

std::vector<display::ManagedDisplayInfo> display_info_list;
display_info_list.push_back(native_display_info);

display_manager->OnNativeDisplaysChanged(display_info_list);
display_manager->UpdateInternalManagedDisplayModeListForTest();

gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(
CreateDefaultShellSurface(surface.get()));

double scale = 1.5;
shell_surface->SetScale(scale);
surface->Attach(buffer.get());
surface->Commit();

gfx::Transform transform;
transform.Scale(1.0 / scale, 1.0 / scale);
if (IsClientBoundsMode())
transform.Scale(1.0 / scale, 1.0 / scale);

EXPECT_EQ(
transform.ToString(),
shell_surface->host_window()->layer()->GetTargetTransform().ToString());
Expand Down
27 changes: 22 additions & 5 deletions components/exo/wayland/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,17 @@ class WaylandRemoteShell : public WMHelper::TabletModeObserver,
? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET
: ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;

if (wl_resource_get_version(remote_shell_resource_) >= 8) {
float scale_factor =
WMHelper::GetInstance()->GetDefaultDeviceScaleFactor();
// Send using 16.16 fixed point.
const int kDecimalBits = 16;
int32_t fixed_scale =
static_cast<int32_t>(scale_factor * (1 << kDecimalBits));
zcr_remote_shell_v1_send_default_device_scale_factor(
remote_shell_resource_, fixed_scale);
}

SendDisplayMetrics();
SendActivated(helper->GetActiveWindow(), nullptr);
}
Expand All @@ -2294,9 +2305,12 @@ class WaylandRemoteShell : public WMHelper::TabletModeObserver,
return wl_resource_get_version(remote_shell_resource_) >= 5;
}

std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface,
int container) {
return display_->CreateRemoteShellSurface(surface, container);
std::unique_ptr<ShellSurface> CreateShellSurface(
Surface* surface,
int container,
bool scale_by_default_device_scale_factor) {
return display_->CreateRemoteShellSurface(
surface, container, scale_by_default_device_scale_factor);
}

std::unique_ptr<NotificationSurface> CreateNotificationSurface(
Expand Down Expand Up @@ -2541,8 +2555,11 @@ void remote_shell_get_remote_surface(wl_client* client,
wl_resource* surface,
uint32_t container) {
WaylandRemoteShell* shell = GetUserDataAs<WaylandRemoteShell>(resource);
bool scale_by_default_scale_factor = wl_resource_get_version(resource) >= 8;

std::unique_ptr<ShellSurface> shell_surface = shell->CreateShellSurface(
GetUserDataAs<Surface>(surface), RemoteSurfaceContainer(container));
GetUserDataAs<Surface>(surface), RemoteSurfaceContainer(container),
scale_by_default_scale_factor);
if (!shell_surface) {
wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V1_ERROR_ROLE,
"surface has already been assigned a role");
Expand Down Expand Up @@ -2602,7 +2619,7 @@ const struct zcr_remote_shell_v1_interface remote_shell_implementation = {
remote_shell_destroy, remote_shell_get_remote_surface,
remote_shell_get_notification_surface};

const uint32_t remote_shell_version = 7;
const uint32_t remote_shell_version = 8;

void bind_remote_shell(wl_client* client,
void* data,
Expand Down
1 change: 1 addition & 0 deletions components/exo/wm_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class WMHelper : public aura::client::DragDropDelegate {
virtual void AddPostTargetHandler(ui::EventHandler* handler) = 0;
virtual void RemovePostTargetHandler(ui::EventHandler* handler) = 0;
virtual bool IsTabletModeWindowManagerEnabled() const = 0;
virtual double GetDefaultDeviceScaleFactor() const = 0;

// Overridden from aura::client::DragDropDelegate:
void OnDragEntered(const ui::DropTargetEvent& event) override;
Expand Down
20 changes: 20 additions & 0 deletions components/exo/wm_helper_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ bool WMHelperAsh::IsTabletModeWindowManagerEnabled() const {
->IsTabletModeWindowManagerEnabled();
}

double WMHelperAsh::GetDefaultDeviceScaleFactor() const {
if (!display::Display::HasInternalDisplay())
return 1.0;

if (display::Display::HasForceDeviceScaleFactor())
return display::Display::GetForcedDeviceScaleFactor();

display::DisplayManager* display_manager =
ash::Shell::Get()->display_manager();
const display::ManagedDisplayInfo& display_info =
display_manager->GetDisplayInfo(display::Display::InternalDisplayId());
for (auto& mode : display_info.display_modes()) {
if (mode->is_default())
return mode->device_scale_factor();
}

NOTREACHED();
return 1.0f;
}

void WMHelperAsh::OnWindowActivated(
wm::ActivationChangeObserver::ActivationReason reason,
aura::Window* gained_active,
Expand Down
1 change: 1 addition & 0 deletions components/exo/wm_helper_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class WMHelperAsh : public WMHelper,
void AddPostTargetHandler(ui::EventHandler* handler) override;
void RemovePostTargetHandler(ui::EventHandler* handler) override;
bool IsTabletModeWindowManagerEnabled() const override;
double GetDefaultDeviceScaleFactor() const override;

// Overridden from wm::ActivationChangeObserver:
void OnWindowActivated(wm::ActivationChangeObserver::ActivationReason reason,
Expand Down
5 changes: 5 additions & 0 deletions components/exo/wm_helper_mus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ bool WMHelperMus::IsTabletModeWindowManagerEnabled() const {
return false;
}

double WMHelperMus::GetDefaultDeviceScaleFactor() const {
NOTIMPLEMENTED();
return 1.0;
}

void WMHelperMus::OnActiveFocusClientChanged(
aura::client::FocusClient* focus_client,
aura::Window* focus_client_root) {
Expand Down
1 change: 1 addition & 0 deletions components/exo/wm_helper_mus.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class WMHelperMus : public WMHelper,
void AddPostTargetHandler(ui::EventHandler* handler) override;
void RemovePostTargetHandler(ui::EventHandler* handler) override;
bool IsTabletModeWindowManagerEnabled() const override;
double GetDefaultDeviceScaleFactor() const override;

// Overridden from aura::FocusSynchronizerObserver:
void OnActiveFocusClientChanged(aura::client::FocusClient* focus_client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@ struct zcr_remote_shell_v1_listener {
void (*configure)(void *data,
struct zcr_remote_shell_v1 *zcr_remote_shell_v1,
uint32_t layout_mode);
/**
* initialize scale configuration
*
* Sends the default device scale factor.
* @param scale DP to pixels ratio, in 16.16 fixed point format
* @since 8
*/
void (*default_device_scale_factor)(void *data,
struct zcr_remote_shell_v1 *zcr_remote_shell_v1,
int32_t scale);
};

/**
Expand Down Expand Up @@ -326,6 +336,10 @@ zcr_remote_shell_v1_add_listener(struct zcr_remote_shell_v1 *zcr_remote_shell_v1
* @ingroup iface_zcr_remote_shell_v1
*/
#define ZCR_REMOTE_SHELL_V1_CONFIGURE_SINCE_VERSION 5
/**
* @ingroup iface_zcr_remote_shell_v1
*/
#define ZCR_REMOTE_SHELL_V1_DEFAULT_DEVICE_SCALE_FACTOR_SINCE_VERSION 8

/**
* @ingroup iface_zcr_remote_shell_v1
Expand Down Expand Up @@ -471,14 +485,14 @@ enum zcr_remote_surface_v1_orientation {
* The type of the window.
*/
enum zcr_remote_surface_v1_window_type {
/**
* normal app window
*/
ZCR_REMOTE_SURFACE_V1_WINDOW_TYPE_NORMAL = 1,
/**
* window is treated as systemui
*/
ZCR_REMOTE_SURFACE_V1_WINDOW_TYPE_SYSTEM_UI = 2,
/**
* normal app window
*/
ZCR_REMOTE_SURFACE_V1_WINDOW_TYPE_NORMAL = 1,
/**
* window is treated as systemui
*/
ZCR_REMOTE_SURFACE_V1_WINDOW_TYPE_SYSTEM_UI = 2,
};
#endif /* ZCR_REMOTE_SURFACE_V1_WINDOW_TYPE_ENUM */

Expand Down Expand Up @@ -1144,11 +1158,11 @@ zcr_remote_surface_v1_set_orientation(struct zcr_remote_surface_v1 *zcr_remote_s
* Set the type of window. This is only a hint to the compositor and the
* compositor is free to ignore it.
*/
static inline void zcr_remote_surface_v1_set_window_type(
struct zcr_remote_surface_v1* zcr_remote_surface_v1,
uint32_t type) {
wl_proxy_marshal((struct wl_proxy*)zcr_remote_surface_v1,
ZCR_REMOTE_SURFACE_V1_SET_WINDOW_TYPE, type);
static inline void
zcr_remote_surface_v1_set_window_type(struct zcr_remote_surface_v1 *zcr_remote_surface_v1, uint32_t type)
{
wl_proxy_marshal((struct wl_proxy *) zcr_remote_surface_v1,
ZCR_REMOTE_SURFACE_V1_SET_WINDOW_TYPE, type);
}

#define ZCR_NOTIFICATION_SURFACE_V1_DESTROY 0
Expand Down
Loading

0 comments on commit 62166df

Please sign in to comment.