Commit db7d6b05 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

ozone/headless: Add HeadlessScreen impl

This CL adds a simple HeadlessScreen implementation and removes
usage of NativeDisplayDelegate.

Bug: 891613
Change-Id: I522b500ad32358f4ec7db95e4b58b0774b4cc807
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1782558
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693636}
parent 0ff216ba
...@@ -82,26 +82,13 @@ ShellPlatformDataAura* Shell::platform_ = nullptr; ...@@ -82,26 +82,13 @@ ShellPlatformDataAura* Shell::platform_ = nullptr;
ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) { ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) {
CHECK(aura::Env::GetInstance()); CHECK(aura::Env::GetInstance());
#if defined(USE_OZONE)
// Setup global display::Screen singleton. // Setup global display::Screen singleton.
if (!display::Screen::GetScreen()) { if (!display::Screen::GetScreen()) {
#if defined(USE_OZONE) screen_ = std::make_unique<aura::ScreenOzone>();
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 web 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()); display::Screen::SetScreenInstance(screen_.get());
} }
#endif // defined(USE_OZONE)
ui::PlatformWindowInitProperties properties; ui::PlatformWindowInitProperties properties;
properties.bounds = gfx::Rect(initial_size); properties.bounds = gfx::Rect(initial_size);
......
...@@ -33,15 +33,7 @@ WebEngineBrowserMainParts::~WebEngineBrowserMainParts() { ...@@ -33,15 +33,7 @@ WebEngineBrowserMainParts::~WebEngineBrowserMainParts() {
void WebEngineBrowserMainParts::PreMainMessageLoopRun() { void WebEngineBrowserMainParts::PreMainMessageLoopRun() {
DCHECK(!screen_); DCHECK(!screen_);
auto platform_screen = ui::OzonePlatform::GetInstance()->CreateScreen(); screen_ = std::make_unique<aura::ScreenOzone>();
if (platform_screen) {
screen_ = std::make_unique<aura::ScreenOzone>(std::move(platform_screen));
} else {
// Use dummy display::Screen for Ozone platforms that don't provide
// PlatformScreen.
screen_ = std::make_unique<WebEngineScreen>();
}
display::Screen::SetScreenInstance(screen_.get()); display::Screen::SetScreenInstance(screen_.get());
// If Vulkan is not enabled then disable hardware acceleration. Otherwise gpu // If Vulkan is not enabled then disable hardware acceleration. Otherwise gpu
......
...@@ -9,11 +9,19 @@ ...@@ -9,11 +9,19 @@
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/platform_screen.h"
namespace aura { namespace aura {
ScreenOzone::ScreenOzone(std::unique_ptr<ui::PlatformScreen> platform_screen) ScreenOzone::ScreenOzone() {
: platform_screen_(std::move(platform_screen)) {} platform_screen_ = ui::OzonePlatform::GetInstance()->CreateScreen();
if (!platform_screen_) {
NOTREACHED()
<< "PlatformScreen is not implemented for this ozone platform.";
}
}
ScreenOzone::~ScreenOzone() = default; ScreenOzone::~ScreenOzone() = default;
gfx::Point ScreenOzone::GetCursorScreenPoint() { gfx::Point ScreenOzone::GetCursorScreenPoint() {
......
...@@ -10,7 +10,10 @@ ...@@ -10,7 +10,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "ui/aura/aura_export.h" #include "ui/aura/aura_export.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/ozone/public/platform_screen.h"
namespace ui {
class PlatformScreen;
}
namespace aura { namespace aura {
...@@ -18,7 +21,7 @@ namespace aura { ...@@ -18,7 +21,7 @@ namespace aura {
// Ozone. // Ozone.
class AURA_EXPORT ScreenOzone : public display::Screen { class AURA_EXPORT ScreenOzone : public display::Screen {
public: public:
explicit ScreenOzone(std::unique_ptr<ui::PlatformScreen> platform_screen); ScreenOzone();
~ScreenOzone() override; ~ScreenOzone() override;
// display::Screen interface. // display::Screen interface.
...@@ -49,4 +52,4 @@ class AURA_EXPORT ScreenOzone : public display::Screen { ...@@ -49,4 +52,4 @@ class AURA_EXPORT ScreenOzone : public display::Screen {
} // namespace aura } // namespace aura
#endif // UI_AURA_SCREEN_OZONE_H_ #endif // UI_AURA_SCREEN_OZONE_H_
\ No newline at end of file
...@@ -8,8 +8,8 @@ source_set("headless") { ...@@ -8,8 +8,8 @@ source_set("headless") {
sources = [ sources = [
"client_native_pixmap_factory_headless.cc", "client_native_pixmap_factory_headless.cc",
"client_native_pixmap_factory_headless.h", "client_native_pixmap_factory_headless.h",
"headless_native_display_delegate.cc", "headless_screen.cc",
"headless_native_display_delegate.h", "headless_screen.h",
"headless_surface_factory.cc", "headless_surface_factory.cc",
"headless_surface_factory.h", "headless_surface_factory.h",
"headless_window.cc", "headless_window.cc",
......
// 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/ozone/platform/headless/headless_native_display_delegate.h"
#include <memory>
#include <utility>
#include "ui/display/types/display_snapshot.h"
#include "ui/display/types/native_display_observer.h"
namespace ui {
namespace {
constexpr gfx::Size kDefaultWindowSize(800, 600);
constexpr int default_refresh = 60;
} // namespace
HeadlessNativeDisplayDelegate::HeadlessNativeDisplayDelegate() = default;
HeadlessNativeDisplayDelegate::~HeadlessNativeDisplayDelegate() = default;
void HeadlessNativeDisplayDelegate::Initialize() {
// This shouldn't be called twice.
DCHECK(!current_snapshot_);
if (next_display_id_ == std::numeric_limits<int64_t>::max()) {
LOG(FATAL) << "Exceeded display id limit";
return;
}
display::DisplaySnapshot::DisplayModeList modes;
std::unique_ptr<display::DisplayMode> display_mode =
std::make_unique<display::DisplayMode>(kDefaultWindowSize, false,
default_refresh);
modes.push_back(std::move(display_mode));
const display::DisplayMode* mode = modes.back().get();
current_snapshot_ = std::make_unique<display::DisplaySnapshot>(
next_display_id(), gfx::Point(0, 0), kDefaultWindowSize,
display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NONE, false,
false, false, false, gfx::ColorSpace(), 8u /* bits_per_channel*/, "",
base::FilePath(), std::move(modes), display::PanelOrientation::kNormal,
std::vector<uint8_t>(), mode, mode, 0, 0, gfx::Size());
for (display::NativeDisplayObserver& observer : observers_)
observer.OnConfigurationChanged();
}
void HeadlessNativeDisplayDelegate::TakeDisplayControl(
display::DisplayControlCallback callback) {
NOTREACHED();
}
void HeadlessNativeDisplayDelegate::RelinquishDisplayControl(
display::DisplayControlCallback callback) {
NOTREACHED();
}
void HeadlessNativeDisplayDelegate::GetDisplays(
display::GetDisplaysCallback callback) {
std::vector<display::DisplaySnapshot*> snapshot;
snapshot.push_back(current_snapshot_.get());
std::move(callback).Run(snapshot);
}
void HeadlessNativeDisplayDelegate::Configure(
const display::DisplaySnapshot& output,
const display::DisplayMode* mode,
const gfx::Point& origin,
display::ConfigureCallback callback) {
NOTIMPLEMENTED();
// It should call |callback| after configuration.
// Even if we don't have implementation, it calls |callback| to finish the
// logic.
std::move(callback).Run(true);
}
void HeadlessNativeDisplayDelegate::GetHDCPState(
const display::DisplaySnapshot& output,
display::GetHDCPStateCallback callback) {
NOTREACHED();
}
void HeadlessNativeDisplayDelegate::SetHDCPState(
const display::DisplaySnapshot& output,
display::HDCPState state,
display::SetHDCPStateCallback callback) {
NOTREACHED();
}
bool HeadlessNativeDisplayDelegate::SetColorMatrix(
int64_t display_id,
const std::vector<float>& color_matrix) {
NOTREACHED();
return false;
}
bool HeadlessNativeDisplayDelegate::SetGammaCorrection(
int64_t display_id,
const std::vector<display::GammaRampRGBEntry>& degamma_lut,
const std::vector<display::GammaRampRGBEntry>& gamma_lut) {
NOTREACHED();
return false;
}
void HeadlessNativeDisplayDelegate::AddObserver(
display::NativeDisplayObserver* observer) {
observers_.AddObserver(observer);
}
void HeadlessNativeDisplayDelegate::RemoveObserver(
display::NativeDisplayObserver* observer) {
observers_.RemoveObserver(observer);
}
display::FakeDisplayController*
HeadlessNativeDisplayDelegate::GetFakeDisplayController() {
return nullptr;
}
} // namespace ui
// 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_OZONE_PLATFORM_HEADLESS_HEADLESS_NATIVE_DISPLAY_DELEGATE_H_
#define UI_OZONE_PLATFORM_HEADLESS_HEADLESS_NATIVE_DISPLAY_DELEGATE_H_
#include <memory>
#include "base/observer_list.h"
#include "ui/display/types/native_display_delegate.h"
namespace display {
class DisplayMode;
class DisplaySnapshot;
} // namespace display
namespace ui {
class HeadlessNativeDisplayDelegate : public display::NativeDisplayDelegate {
public:
HeadlessNativeDisplayDelegate();
~HeadlessNativeDisplayDelegate() override;
// display::NativeDisplayDelegate overrides:
void Initialize() override;
void TakeDisplayControl(display::DisplayControlCallback callback) override;
void RelinquishDisplayControl(
display::DisplayControlCallback callback) override;
void GetDisplays(display::GetDisplaysCallback callback) override;
void Configure(const display::DisplaySnapshot& output,
const display::DisplayMode* mode,
const gfx::Point& origin,
display::ConfigureCallback callback) override;
void GetHDCPState(const display::DisplaySnapshot& output,
display::GetHDCPStateCallback callback) override;
void SetHDCPState(const display::DisplaySnapshot& output,
display::HDCPState state,
display::SetHDCPStateCallback callback) override;
bool SetColorMatrix(int64_t display_id,
const std::vector<float>& color_matrix) override;
bool SetGammaCorrection(
int64_t display_id,
const std::vector<display::GammaRampRGBEntry>& degamma_lut,
const std::vector<display::GammaRampRGBEntry>& gamma_lut) override;
void AddObserver(display::NativeDisplayObserver* observer) override;
void RemoveObserver(display::NativeDisplayObserver* observer) override;
display::FakeDisplayController* GetFakeDisplayController() override;
private:
int64_t next_display_id() { return next_display_id_++; }
std::unique_ptr<display::DisplaySnapshot> current_snapshot_;
base::ObserverList<display::NativeDisplayObserver>::Unchecked observers_;
// The next available display id.
int64_t next_display_id_ = 0;
DISALLOW_COPY_AND_ASSIGN(HeadlessNativeDisplayDelegate);
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_HEADLESS_HEADLESS_NATIVE_DISPLAY_DELEGATE_H_
// Copyright 2019 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/ozone/platform/headless/headless_screen.h"
namespace ui {
namespace {
constexpr gfx::Size kDefaultWindowSize(800, 600);
} // namespace
HeadlessScreen::HeadlessScreen() {
DCHECK_LE(next_display_id_, std::numeric_limits<int64_t>::max());
display::Display display(next_display_id_++);
display.SetScaleAndBounds(1.0f,
gfx::Rect(gfx::Point(0, 0), kDefaultWindowSize));
display_list_.AddDisplay(display, display::DisplayList::Type::PRIMARY);
}
HeadlessScreen::~HeadlessScreen() = default;
const std::vector<display::Display>& HeadlessScreen::GetAllDisplays() const {
return display_list_.displays();
}
display::Display HeadlessScreen::GetPrimaryDisplay() const {
auto iter = display_list_.GetPrimaryDisplayIterator();
DCHECK(iter != display_list_.displays().end());
return *iter;
}
display::Display HeadlessScreen::GetDisplayForAcceleratedWidget(
gfx::AcceleratedWidget widget) const {
return GetPrimaryDisplay();
}
gfx::Point HeadlessScreen::GetCursorScreenPoint() const {
return gfx::Point();
}
gfx::AcceleratedWidget HeadlessScreen::GetAcceleratedWidgetAtScreenPoint(
const gfx::Point& point) const {
return gfx::kNullAcceleratedWidget;
}
display::Display HeadlessScreen::GetDisplayNearestPoint(
const gfx::Point& point) const {
return GetPrimaryDisplay();
}
display::Display HeadlessScreen::GetDisplayMatching(
const gfx::Rect& match_rect) const {
return GetPrimaryDisplay();
}
void HeadlessScreen::AddObserver(display::DisplayObserver* observer) {
display_list_.AddObserver(observer);
}
void HeadlessScreen::RemoveObserver(display::DisplayObserver* observer) {
display_list_.RemoveObserver(observer);
}
} // namespace ui
// Copyright 2019 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_OZONE_PLATFORM_HEADLESS_HEADLESS_SCREEN_H_
#define UI_OZONE_PLATFORM_HEADLESS_HEADLESS_SCREEN_H_
#include <vector>
#include "base/macros.h"
#include "base/observer_list.h"
#include "ui/display/display_list.h"
#include "ui/gfx/geometry/point.h"
#include "ui/ozone/public/platform_screen.h"
namespace ui {
class HeadlessScreen : public PlatformScreen {
public:
HeadlessScreen();
~HeadlessScreen() override;
// Overridden from ui::PlatformScreen:
const std::vector<display::Display>& GetAllDisplays() const override;
display::Display GetPrimaryDisplay() const override;
display::Display GetDisplayForAcceleratedWidget(
gfx::AcceleratedWidget widget) const override;
gfx::Point GetCursorScreenPoint() const override;
gfx::AcceleratedWidget GetAcceleratedWidgetAtScreenPoint(
const gfx::Point& point) const override;
display::Display GetDisplayNearestPoint(
const gfx::Point& point) const override;
display::Display GetDisplayMatching(
const gfx::Rect& match_rect) const override;
void AddObserver(display::DisplayObserver* observer) override;
void RemoveObserver(display::DisplayObserver* observer) override;
private:
// The next available display id.
int64_t next_display_id_ = 0;
display::DisplayList display_list_;
base::ObserverList<display::DisplayObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(HeadlessScreen);
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_HEADLESS_HEADLESS_SCREEN_H_
...@@ -12,11 +12,12 @@ ...@@ -12,11 +12,12 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
#include "ui/base/ime/input_method_minimal.h" #include "ui/base/ime/input_method_minimal.h"
#include "ui/display/types/native_display_delegate.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
#include "ui/events/platform/platform_event_source.h" #include "ui/events/platform/platform_event_source.h"
#include "ui/ozone/common/stub_overlay_manager.h" #include "ui/ozone/common/stub_overlay_manager.h"
#include "ui/ozone/platform/headless/headless_native_display_delegate.h" #include "ui/ozone/platform/headless/headless_screen.h"
#include "ui/ozone/platform/headless/headless_surface_factory.h" #include "ui/ozone/platform/headless/headless_surface_factory.h"
#include "ui/ozone/platform/headless/headless_window.h" #include "ui/ozone/platform/headless/headless_window.h"
#include "ui/ozone/platform/headless/headless_window_manager.h" #include "ui/ozone/platform/headless/headless_window_manager.h"
...@@ -82,7 +83,10 @@ class OzonePlatformHeadless : public OzonePlatform { ...@@ -82,7 +83,10 @@ class OzonePlatformHeadless : public OzonePlatform {
} }
std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate() std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate()
override { override {
return std::make_unique<HeadlessNativeDisplayDelegate>(); return nullptr;
}
std::unique_ptr<PlatformScreen> CreateScreen() override {
return std::make_unique<HeadlessScreen>();
} }
std::unique_ptr<InputMethod> CreateInputMethod( std::unique_ptr<InputMethod> CreateInputMethod(
internal::InputMethodDelegate* delegate) override { internal::InputMethodDelegate* delegate) override {
......
...@@ -598,10 +598,6 @@ jumbo_component("views") { ...@@ -598,10 +598,6 @@ jumbo_component("views") {
] ]
} }
if (use_ozone) {
deps += [ "//ui/ozone" ]
}
if (use_x11) { if (use_x11) {
configs += [ configs += [
"//build/config/linux:x11", "//build/config/linux:x11",
...@@ -752,7 +748,6 @@ jumbo_component("views") { ...@@ -752,7 +748,6 @@ jumbo_component("views") {
"widget/desktop_aura/desktop_drag_drop_client_ozone.cc", "widget/desktop_aura/desktop_drag_drop_client_ozone.cc",
"widget/desktop_aura/desktop_drag_drop_client_ozone.h", "widget/desktop_aura/desktop_drag_drop_client_ozone.h",
"widget/desktop_aura/desktop_screen_ozone.cc", "widget/desktop_aura/desktop_screen_ozone.cc",
"widget/desktop_aura/desktop_screen_ozone.h",
] ]
} }
if (is_linux) { if (is_linux) {
......
...@@ -2,71 +2,13 @@ ...@@ -2,71 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/views/widget/desktop_aura/desktop_screen_ozone.h"
#include "base/bind.h"
#include "ui/aura/screen_ozone.h" #include "ui/aura/screen_ozone.h"
#include "ui/display/display.h"
#include "ui/display/types/display_constants.h"
#include "ui/display/types/display_snapshot.h"
#include "ui/display/types/native_display_delegate.h"
#include "ui/gfx/geometry/dip_util.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h"
namespace views { namespace views {
DesktopScreenOzone::DesktopScreenOzone()
: delegate_(
ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate()) {
delegate_->AddObserver(this);
delegate_->Initialize();
}
DesktopScreenOzone::~DesktopScreenOzone() = default;
void DesktopScreenOzone::OnHostDisplaysReady(
const std::vector<display::DisplaySnapshot*>& displays) {
DCHECK(!displays.empty());
// TODO(msisov): Add support for multiple displays.
display::DisplaySnapshot* display_snapshot = displays.front();
DCHECK(display_snapshot);
float device_scale_factor = 1.f;
if (display::Display::HasForceDeviceScaleFactor())
device_scale_factor = display::Display::GetForcedDeviceScaleFactor();
gfx::Size scaled_size = gfx::ConvertSizeToDIP(
device_scale_factor, display_snapshot->current_mode()->size());
display::Display display(display_snapshot->display_id());
display.set_bounds(gfx::Rect(scaled_size));
display.set_work_area(display.bounds());
display.set_device_scale_factor(device_scale_factor);
ProcessDisplayChanged(display, true /* is_primary */);
}
void DesktopScreenOzone::OnConfigurationChanged() {
delegate_->GetDisplays(base::BindOnce(
&DesktopScreenOzone::OnHostDisplaysReady, base::Unretained(this)));
}
void DesktopScreenOzone::OnDisplaySnapshotsInvalidated() {}
//////////////////////////////////////////////////////////////////////////////
display::Screen* CreateDesktopScreen() { display::Screen* CreateDesktopScreen() {
auto platform_screen = ui::OzonePlatform::GetInstance()->CreateScreen(); return new aura::ScreenOzone();
if (!platform_screen) {
// TODO: At the moment, only the Ozone/Headless uses this patch. Fix it:
// https://crbug.com/891613
LOG(ERROR) << "PlatformScreen is not implemented for this ozone platform. "
"Falling back to old DesktopScreenOzone implementation. See "
"https://crbug.com/872339 for details";
return new DesktopScreenOzone;
}
return new aura::ScreenOzone(std::move(platform_screen));
} }
} // namespace views } // namespace views
// 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_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_OZONE_H_
#define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_OZONE_H_
#include "ui/display/screen_base.h"
#include "ui/display/types/native_display_observer.h"
namespace display {
class NativeDisplayDelegate;
class DisplaySnapshot;
} // namespace display
namespace views {
class DesktopScreenOzone : public display::ScreenBase,
public display::NativeDisplayObserver {
public:
DesktopScreenOzone();
~DesktopScreenOzone() override;
private:
void OnHostDisplaysReady(
const std::vector<display::DisplaySnapshot*>& displays);
// display::NativeDisplayDelegate:
void OnConfigurationChanged() override;
void OnDisplaySnapshotsInvalidated() override;
std::unique_ptr<display::NativeDisplayDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(DesktopScreenOzone);
};
} // namespace views
#endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_OZONE_H_
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