Skip to content

Commit

Permalink
Auto-update the screen instance from various Screen subclasses.
Browse files Browse the repository at this point in the history
This includes:
* DesktopScreenWin
* DesktopScreenX11
* ScreenOzone
* TestDesktopScreenX11
* TestScreenWin

Ideally, eventually all subclasses can do this, but this is a start.

Bug: none
Change-Id: I6b74298a5d4ab9bdefd592d984d29756fd111906
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2126255
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Reviewed-by: Devlin <rdevlin.cronin@chromium.org>
Reviewed-by: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#769800}
  • Loading branch information
pkasting authored and Commit Bot committed May 18, 2020
1 parent 94612c8 commit 5bac1a0
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 28 deletions.
7 changes: 1 addition & 6 deletions chrome/browser/ui/views/test/view_event_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,14 @@ ViewEventTestBase::ViewEventTestBase() {
// tests.
DCHECK(!display::Screen::GetScreen());
#if defined(USE_X11)
display::Screen::SetScreenInstance(
views::test::TestDesktopScreenX11::GetInstance());
views::test::TestDesktopScreenX11::GetInstance();
#else
screen_.reset(views::CreateDesktopScreen());
display::Screen::SetScreenInstance(screen_.get());
#endif
#endif
}

ViewEventTestBase::~ViewEventTestBase() {
#if defined(USE_AURA) && !defined(OS_CHROMEOS)
display::Screen::SetScreenInstance(nullptr);
#endif
TestingBrowserProcess::DeleteInstance();
}

Expand Down
12 changes: 2 additions & 10 deletions content/shell/browser/shell_platform_data_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#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 Down Expand Up @@ -82,10 +81,8 @@ ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) {

#if defined(USE_OZONE)
// Setup global display::Screen singleton.
if (!display::Screen::GetScreen()) {
if (!display::Screen::GetScreen())
screen_ = std::make_unique<aura::ScreenOzone>();
display::Screen::SetScreenInstance(screen_.get());
}
#endif // defined(USE_OZONE)

ui::PlatformWindowInitProperties properties;
Expand Down Expand Up @@ -116,12 +113,7 @@ ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) {
std::make_unique<aura::test::TestWindowParentingClient>(host_->window());
}

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

void ShellPlatformDataAura::ShowWindow() {
host_->Show();
Expand Down
6 changes: 5 additions & 1 deletion extensions/shell/browser/shell_desktop_controller_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,13 @@ void ShellDesktopControllerAura::InitWindowManager() {
if (!display::Screen::GetScreen()) {
#if defined(OS_CHROMEOS)
screen_ = std::make_unique<ShellScreen>(this, GetStartingWindowSize());
// TODO(pkasting): Make ShellScreen() call SetScreenInstance() as the
// classes in CreateDesktopScreen() do, and remove this.
display::Screen::SetScreenInstance(screen_.get());
#else
// TODO(crbug.com/756680): Refactor DesktopScreen out of views.
screen_.reset(views::CreateDesktopScreen());
#endif
display::Screen::SetScreenInstance(screen_.get());
}

focus_controller_ =
Expand Down Expand Up @@ -350,7 +352,9 @@ void ShellDesktopControllerAura::TearDownWindowManager() {
cursor_manager_.reset();
focus_controller_.reset();
if (screen_) {
#if defined(OS_CHROMEOS)
display::Screen::SetScreenInstance(nullptr);
#endif
screen_.reset();
}
root_window_event_filter_.reset();
Expand Down
5 changes: 3 additions & 2 deletions ui/aura/screen_ozone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/platform_screen.h"

Expand All @@ -22,7 +21,9 @@ ScreenOzone::ScreenOzone() {
}
}

ScreenOzone::~ScreenOzone() = default;
ScreenOzone::~ScreenOzone() {
display::Screen::SetScreenInstance(old_screen_);
}

gfx::Point ScreenOzone::GetCursorScreenPoint() {
return platform_screen_->GetCursorScreenPoint();
Expand Down
1 change: 1 addition & 0 deletions ui/aura/screen_ozone.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AURA_EXPORT ScreenOzone : public display::Screen {
gfx::AcceleratedWidget GetAcceleratedWidgetForWindow(
aura::Window* window) const;

display::Screen* const old_screen_ = display::Screen::SetScreenInstance(this);
std::unique_ptr<ui::PlatformScreen> platform_screen_;

DISALLOW_COPY_AND_ASSIGN(ScreenOzone);
Expand Down
7 changes: 3 additions & 4 deletions ui/display/win/screen_win_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TestScreenWin : public ScreenWin {
UpdateFromDisplayInfos(display_infos);
}

~TestScreenWin() override = default;
~TestScreenWin() override { Screen::SetScreenInstance(old_screen_); }

protected:
// win::ScreenWin:
Expand Down Expand Up @@ -122,6 +122,7 @@ class TestScreenWin : public ScreenWin {
return metric;
}

Screen* old_screen_ = Screen::SetScreenInstance(this);
std::vector<MONITORINFOEX> monitor_infos_;
std::unordered_map<HWND, gfx::Rect> hwnd_map_;

Expand All @@ -148,8 +149,7 @@ class TestScreenWinInitializer {
class TestScreenWinManager final : public TestScreenWinInitializer {
public:
TestScreenWinManager() = default;

~TestScreenWinManager() { Screen::SetScreenInstance(nullptr); }
~TestScreenWinManager() = default;

void AddMonitor(const gfx::Rect& pixel_bounds,
const gfx::Rect& pixel_work,
Expand All @@ -175,7 +175,6 @@ class TestScreenWinManager final : public TestScreenWinInitializer {
ASSERT_EQ(screen_win_, nullptr);
screen_win_ = std::make_unique<TestScreenWin>(display_infos_,
monitor_infos_, hwnd_map_);
Screen::SetScreenInstance(screen_win_.get());
}

ScreenWin* GetScreenWin() {
Expand Down
1 change: 0 additions & 1 deletion ui/views/examples/examples_main_proc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ ExamplesExitCode ExamplesMainProc(bool under_test) {
#if BUILDFLAG(ENABLE_DESKTOP_AURA)
std::unique_ptr<display::Screen> desktop_screen =
base::WrapUnique(views::CreateDesktopScreen());
display::Screen::SetScreenInstance(desktop_screen.get());
#endif

base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
Expand Down
2 changes: 1 addition & 1 deletion ui/views/widget/desktop_aura/desktop_screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void InstallDesktopScreenIfNecessary() {

// The screen may have already been set in test initialization.
if (!display::Screen::GetScreen())
display::Screen::SetScreenInstance(CreateDesktopScreen());
CreateDesktopScreen();
}

} // namespace views
4 changes: 3 additions & 1 deletion ui/views/widget/desktop_aura/desktop_screen_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace views {

DesktopScreenWin::DesktopScreenWin() = default;

DesktopScreenWin::~DesktopScreenWin() = default;
DesktopScreenWin::~DesktopScreenWin() {
display::Screen::SetScreenInstance(old_screen_);
}

HWND DesktopScreenWin::GetHWNDFromNativeWindow(gfx::NativeWindow window) const {
aura::WindowTreeHost* host = window->GetHost();
Expand Down
2 changes: 2 additions & 0 deletions ui/views/widget/desktop_aura/desktop_screen_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class VIEWS_EXPORT DesktopScreenWin : public display::win::ScreenWin {
// display::win::ScreenWin:
HWND GetHWNDFromNativeWindow(gfx::NativeWindow window) const override;
gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const override;

display::Screen* const old_screen_ = display::Screen::SetScreenInstance(this);
};

} // namespace views
Expand Down
4 changes: 3 additions & 1 deletion ui/views/widget/desktop_aura/desktop_screen_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ DesktopScreenX11::DesktopScreenX11() {
display_scale_factor_observer_.Add(LinuxUI::instance());
}

DesktopScreenX11::~DesktopScreenX11() = default;
DesktopScreenX11::~DesktopScreenX11() {
display::Screen::SetScreenInstance(old_screen_);
}

void DesktopScreenX11::Init() {
if (x11_display_manager_->IsXrandrAvailable() &&
Expand Down
1 change: 1 addition & 0 deletions ui/views/widget/desktop_aura/desktop_screen_x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class VIEWS_EXPORT DesktopScreenX11 : public display::Screen,
void OnXDisplayListUpdated() override;
float GetXDisplayScaleFactor() const override;

display::Screen* const old_screen_ = display::Screen::SetScreenInstance(this);
std::unique_ptr<ui::XDisplayManager> x11_display_manager_ =
std::make_unique<ui::XDisplayManager>(this);
ScopedObserver<LinuxUI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ViewsContentClientMainPartsDesktopAura::ViewsContentClientMainPartsDesktopAura(
void ViewsContentClientMainPartsDesktopAura::PreMainMessageLoopRun() {
ViewsContentClientMainPartsAura::PreMainMessageLoopRun();

display::Screen::SetScreenInstance(views::CreateDesktopScreen());
views::CreateDesktopScreen();

views_content_client()->OnPreMainMessageLoopRun(browser_context(), nullptr);
}
Expand Down

0 comments on commit 5bac1a0

Please sign in to comment.