Skip to content

Commit

Permalink
Add PlatformScreen interface in Ozone.
Browse files Browse the repository at this point in the history
Added OzonePlatform::CreateScreen(), which returns in instance of the
new PlatformScren interface. Also added aura::SceenOzone that implements
display::Screen on top of PlatformScreen.

Bug: 850650
Change-Id: I3481dda921f564f0c117d9c8a0e8ce060254f4c3
Reviewed-on: https://chromium-review.googlesource.com/1162354
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Robert Kroeger <rjkroege@chromium.org>
Reviewed-by: Michael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582792}
  • Loading branch information
SergeyUlanov authored and Commit Bot committed Aug 14, 2018
1 parent 9fc51b5 commit 9885115
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 21 deletions.
21 changes: 6 additions & 15 deletions content/shell/browser/shell_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "content/public/browser/web_contents.h"
#include "content/shell/browser/shell_platform_data_aura.h"
#include "ui/aura/env.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"

Expand All @@ -16,8 +15,6 @@ namespace content {
// static
void Shell::PlatformInitialize(const gfx::Size& default_window_size) {
CHECK(!platform_);
aura::TestScreen* screen = aura::TestScreen::Create(gfx::Size());
display::Screen::SetScreenInstance(screen);
platform_ = new ShellPlatformDataAura(default_window_size);
}

Expand All @@ -26,17 +23,13 @@ void Shell::PlatformExit() {
platform_ = nullptr;
}

void Shell::PlatformCleanUp() {
}
void Shell::PlatformCleanUp() {}

void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) {
}
void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) {}

void Shell::PlatformSetAddressBarURL(const GURL& url) {
}
void Shell::PlatformSetAddressBarURL(const GURL& url) {}

void Shell::PlatformSetIsLoading(bool loading) {
}
void Shell::PlatformSetIsLoading(bool loading) {}

void Shell::PlatformCreateWindow(int width, int height) {
CHECK(platform_);
Expand All @@ -56,14 +49,12 @@ void Shell::PlatformSetContents() {
content->Show();
}

void Shell::PlatformResizeSubViews() {
}
void Shell::PlatformResizeSubViews() {}

void Shell::Close() {
delete this;
}

void Shell::PlatformSetTitle(const base::string16& title) {
}
void Shell::PlatformSetTitle(const base::string16& title) {}

} // namespace content
31 changes: 30 additions & 1 deletion content/shell/browser/shell_platform_data_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ui/aura/env.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/test/test_focus_client.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_window_parenting_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
Expand All @@ -26,6 +27,10 @@
#include "base/fuchsia/component_context.h"
#endif

#if defined(USE_OZONE)
#include "ui/aura/screen_ozone.h"
#endif

namespace content {

namespace {
Expand Down Expand Up @@ -78,6 +83,27 @@ ShellPlatformDataAura* Shell::platform_ = nullptr;
ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) {
CHECK(aura::Env::GetInstance());

// Setup global display::Screen singleton.
if (!display::Screen::GetScreen()) {
#if defined(USE_OZONE)
auto platform_screen = ui::OzonePlatform::GetInstance()->CreateScreen();
if (platform_screen)
screen_ = std::make_unique<aura::ScreenOzone>(std::move(platform_screen));
#endif // defined(USE_OZONE)

// Use aura::TestScreen for Ozone platforms that don't provide
// PlatformScreen.
// TODO(https://crbug.com/872339): Implement PlatformScreen for all
// platforms and remove this code.
if (!screen_) {
// Some layout tests expect to be able to resize the window, so the screen
// must be larger than the window.
screen_.reset(
aura::TestScreen::Create(gfx::ScaleToCeiledSize(initial_size, 2.0)));
}
display::Screen::SetScreenInstance(screen_.get());
}

ui::PlatformWindowInitProperties properties;
properties.bounds = gfx::Rect(initial_size);

Expand Down Expand Up @@ -113,7 +139,10 @@ ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) {
new aura::test::TestWindowParentingClient(host_->window()));
}

ShellPlatformDataAura::~ShellPlatformDataAura() = default;
ShellPlatformDataAura::~ShellPlatformDataAura() {
if (screen_)
display::Screen::SetScreenInstance(nullptr);
}

void ShellPlatformDataAura::ShowWindow() {
host_->Show();
Expand Down
6 changes: 6 additions & 0 deletions content/shell/browser/shell_platform_data_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class WindowParentingClient;
}
}

namespace display {
class Screen;
}

namespace gfx {
class Size;
}
Expand All @@ -35,6 +39,8 @@ class ShellPlatformDataAura {
aura::WindowTreeHost* host() { return host_.get(); }

private:
std::unique_ptr<display::Screen> screen_;

std::unique_ptr<aura::WindowTreeHost> host_;
std::unique_ptr<aura::client::FocusClient> focus_client_;
std::unique_ptr<aura::client::DefaultCaptureClient> capture_client_;
Expand Down
2 changes: 2 additions & 0 deletions ui/aura/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ jumbo_component("aura") {

if (use_ozone) {
deps += [ "//ui/ozone" ]
public += [ "screen_ozone.h" ]
sources += [ "screen_ozone.cc" ]
}

if (is_android) {
Expand Down
92 changes: 92 additions & 0 deletions ui/aura/screen_ozone.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright 2018 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/aura/screen_ozone.h"

#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"

namespace aura {

ScreenOzone::ScreenOzone(std::unique_ptr<ui::PlatformScreen> platform_screen)
: platform_screen_(std::move(platform_screen)) {}
ScreenOzone::~ScreenOzone() = default;

gfx::Point ScreenOzone::GetCursorScreenPoint() {
return platform_screen_->GetCursorScreenPoint();
}

bool ScreenOzone::IsWindowUnderCursor(gfx::NativeWindow window) {
return GetWindowAtScreenPoint(GetCursorScreenPoint()) == window;
}

gfx::NativeWindow ScreenOzone::GetWindowAtScreenPoint(const gfx::Point& point) {
auto widget = platform_screen_->GetAcceleratedWidgetAtScreenPoint(point);
if (!widget)
return nullptr;

aura::WindowTreeHost* host =
aura::WindowTreeHost::GetForAcceleratedWidget(widget);
return host ? host->window() : nullptr;
}

int ScreenOzone::GetNumDisplays() const {
return GetAllDisplays().size();
}

const std::vector<display::Display>& ScreenOzone::GetAllDisplays() const {
return platform_screen_->GetAllDisplays();
}

display::Display ScreenOzone::GetDisplayNearestWindow(
gfx::NativeWindow window) const {
gfx::AcceleratedWidget widget = GetAcceleratedWidgetForWindow(window);
if (!widget)
return GetPrimaryDisplay();

return platform_screen_->GetDisplayForAcceleratedWidget(widget);
}

display::Display ScreenOzone::GetDisplayNearestView(
gfx::NativeView view) const {
return GetDisplayNearestWindow(view);
}

display::Display ScreenOzone::GetDisplayNearestPoint(
const gfx::Point& point) const {
return platform_screen_->GetDisplayNearestPoint(point);
}

display::Display ScreenOzone::GetDisplayMatching(
const gfx::Rect& match_rect) const {
return platform_screen_->GetDisplayMatching(match_rect);
}

display::Display ScreenOzone::GetPrimaryDisplay() const {
return platform_screen_->GetPrimaryDisplay();
}

void ScreenOzone::AddObserver(display::DisplayObserver* observer) {
platform_screen_->AddObserver(observer);
}

void ScreenOzone::RemoveObserver(display::DisplayObserver* observer) {
platform_screen_->RemoveObserver(observer);
}

gfx::AcceleratedWidget ScreenOzone::GetAcceleratedWidgetForWindow(
aura::Window* window) const {
if (!window)
return gfx::kNullAcceleratedWidget;

aura::WindowTreeHost* host = window->GetHost();
if (!host)
return gfx::kNullAcceleratedWidget;

return host->GetAcceleratedWidget();
}

} // namespace aura
50 changes: 50 additions & 0 deletions ui/aura/screen_ozone.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2018 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.

#ifndef UI_AURA_SCREEN_OZONE_H_
#define UI_AURA_SCREEN_OZONE_H_

#include "base/macros.h"
#include "ui/aura/aura_export.h"
#include "ui/display/screen.h"
#include "ui/ozone/public/platform_screen.h"

namespace aura {

// display::Screen implementation on top of ui::PlatformScreen provided by
// Ozone.
class AURA_EXPORT ScreenOzone : public display::Screen {
public:
explicit ScreenOzone(std::unique_ptr<ui::PlatformScreen> platform_screen);
~ScreenOzone() override;

// display::Screen interface.
gfx::Point GetCursorScreenPoint() override;
bool IsWindowUnderCursor(gfx::NativeWindow window) override;
gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override;
int GetNumDisplays() const override;
const std::vector<display::Display>& GetAllDisplays() const override;
display::Display GetDisplayNearestWindow(
gfx::NativeWindow window) const override;
display::Display GetDisplayNearestView(gfx::NativeView view) const override;
display::Display GetDisplayNearestPoint(
const gfx::Point& point) const override;
display::Display GetDisplayMatching(
const gfx::Rect& match_rect) const override;
display::Display GetPrimaryDisplay() const override;
void AddObserver(display::DisplayObserver* observer) override;
void RemoveObserver(display::DisplayObserver* observer) override;

private:
gfx::AcceleratedWidget GetAcceleratedWidgetForWindow(
aura::Window* window) const;

std::unique_ptr<ui::PlatformScreen> platform_screen_;

DISALLOW_COPY_AND_ASSIGN(ScreenOzone);
};

} // namespace aura

#endif // UI_AURA_SCREEN_OZONE_H_
8 changes: 7 additions & 1 deletion ui/base/layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ float GetScaleFactorForNativeView(gfx::NativeView view) {
return 1.0f;
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestView(view);
DCHECK(display.is_valid());

// GetDisplayNearestView() may return null Display if the |view| is not shown
// on the screen and there is no primary display. In that case use scale
// factor 1.0.
if (!display.is_valid())
return 1.0f;

return display.device_scale_factor();
}

Expand Down
2 changes: 2 additions & 0 deletions ui/ozone/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jumbo_component("ozone_base") {
"public/overlay_surface_candidate.h",
"public/ozone_switches.cc",
"public/ozone_switches.h",
"public/platform_screen.h",
"public/surface_factory_ozone.cc",
"public/surface_factory_ozone.h",
"public/surface_ozone_canvas.h",
Expand All @@ -104,6 +105,7 @@ jumbo_component("ozone_base") {
"//gpu/vulkan:buildflags",
"//ipc",
"//skia",
"//ui/display",
"//ui/display/types",
"//ui/display/util",
"//ui/events",
Expand Down
6 changes: 6 additions & 0 deletions ui/ozone/public/ozone_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/trace_event/trace_event.h"
#include "ui/display/screen.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/ozone/platform_object.h"
#include "ui/ozone/platform_selection.h"
#include "ui/ozone/public/platform_screen.h"

namespace ui {

Expand Down Expand Up @@ -111,6 +113,10 @@ IPC::MessageFilter* OzonePlatform::GetGpuMessageFilter() {
return nullptr;
}

std::unique_ptr<PlatformScreen> OzonePlatform::CreateScreen() {
return nullptr;
}

const OzonePlatform::PlatformProperties&
OzonePlatform::GetPlatformProperties() {
return kDefaultPlatformProperties;
Expand Down
4 changes: 4 additions & 0 deletions ui/ozone/public/ozone_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

#include <memory>

#include "base/callback.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "services/service_manager/public/cpp/bind_source_info.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "ui/events/system_input_injector.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/ozone/ozone_export.h"

namespace display {
Expand All @@ -32,6 +34,7 @@ class CursorFactoryOzone;
class InputController;
class GpuPlatformSupportHost;
class OverlayManagerOzone;
class PlatformScreen;
class PlatformWindow;
class PlatformWindowDelegate;
class SurfaceFactoryOzone;
Expand Down Expand Up @@ -139,6 +142,7 @@ class OZONE_EXPORT OzonePlatform {
PlatformWindowInitProperties properties) = 0;
virtual std::unique_ptr<display::NativeDisplayDelegate>
CreateNativeDisplayDelegate() = 0;
virtual std::unique_ptr<PlatformScreen> CreateScreen();

// Returns a struct that contains configuration and requirements for the
// current platform implementation.
Expand Down
Loading

0 comments on commit 9885115

Please sign in to comment.