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

X11 and ozone: fix compositor_unittests

The use_x11 && use_ozone config breaks compositor_unittests.
Basically, we need to decide on runtime what test compositor host
we need to use - X11 or Ozone. This CL fixes that using the same
approach I used in other CLs. For example, https://crrev.com/c/2247719

-----

PS: Please note that this is a temp solution that will help to choose
between ozone and non-ozone X11 build. The switch that will be used
to choose the path is --enable-features=UseOzonePlatform. Once
non-Ozone X11 path is removed (hopefully by Q1 2021 depending on how
the finch trial goes), the wrapper will be removed.

Please also note that it's impossible to build use_x11 && use_ozone
without some hacks in PlatformCursor code. The changes to that are
on their way to upstream.

----

Bug: 1085700
Change-Id: Id5442da33def3cdf8f00deffc59e11d76dbf60a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335284Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Maksim Sisov (GMT+3) <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#796351}
parent 7d23c67d
......@@ -208,14 +208,26 @@ static_library("test_support") {
}
if (use_ozone) {
sources += [ "test/test_compositor_host_ozone.cc" ]
sources += [
"test/test_compositor_host_ozone.cc",
"test/test_compositor_host_ozone.h",
]
deps += [
"//ui/ozone",
"//ui/platform_window",
]
} else if (use_x11) {
sources += [ "test/test_compositor_host_x11.cc" ]
}
if (use_x11) {
sources += [
"test/test_compositor_host_x11.cc",
"test/test_compositor_host_x11.h",
]
}
if (is_linux) {
sources += [ "test/test_compositor_host_linux.cc" ]
}
}
......
// Copyright 2020 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/compositor/test/test_compositor_host.h"
#include "base/notreached.h"
#if defined(USE_OZONE)
#include "ui/base/ui_base_features.h"
#include "ui/compositor/test/test_compositor_host_ozone.h"
#endif
#if defined(USE_X11)
#include "ui/compositor/test/test_compositor_host_x11.h"
#endif
namespace ui {
// static
TestCompositorHost* TestCompositorHost::Create(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform())
return new TestCompositorHostOzone(bounds, context_factory);
#endif
#if defined(USE_X11)
return new TestCompositorHostX11(bounds, context_factory);
#endif
NOTREACHED();
return nullptr;
}
} // namespace ui
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/compositor/test/test_compositor_host.h"
#include "ui/compositor/test/test_compositor_host_ozone.h"
#include <memory>
......@@ -13,6 +13,7 @@
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "ui/compositor/compositor.h"
#include "ui/gfx/geometry/rect.h"
......@@ -24,11 +25,10 @@
namespace ui {
namespace {
// Stub implementation of PlatformWindowDelegate that stores the
// AcceleratedWidget.
class StubPlatformWindowDelegate : public PlatformWindowDelegate {
class TestCompositorHostOzone::StubPlatformWindowDelegate
: public PlatformWindowDelegate {
public:
StubPlatformWindowDelegate() {}
~StubPlatformWindowDelegate() override {}
......@@ -59,26 +59,6 @@ class StubPlatformWindowDelegate : public PlatformWindowDelegate {
DISALLOW_COPY_AND_ASSIGN(StubPlatformWindowDelegate);
};
class TestCompositorHostOzone : public TestCompositorHost {
public:
TestCompositorHostOzone(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
~TestCompositorHostOzone() override;
private:
// Overridden from TestCompositorHost:
void Show() override;
ui::Compositor* GetCompositor() override;
gfx::Rect bounds_;
ui::Compositor compositor_;
std::unique_ptr<PlatformWindow> window_;
StubPlatformWindowDelegate window_delegate_;
viz::ParentLocalSurfaceIdAllocator allocator_;
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostOzone);
};
TestCompositorHostOzone::TestCompositorHostOzone(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory)
......@@ -86,7 +66,8 @@ TestCompositorHostOzone::TestCompositorHostOzone(
compositor_(context_factory->AllocateFrameSinkId(),
context_factory,
base::ThreadTaskRunnerHandle::Get(),
false /* enable_pixel_canvas */) {}
false /* enable_pixel_canvas */),
window_delegate_(std::make_unique<StubPlatformWindowDelegate>()) {}
TestCompositorHostOzone::~TestCompositorHostOzone() {
// |window_| should be destroyed earlier than |window_delegate_| as it refers
......@@ -99,12 +80,12 @@ void TestCompositorHostOzone::Show() {
properties.bounds = bounds_;
// Create a PlatformWindow to get the AcceleratedWidget backing it.
window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
&window_delegate_, std::move(properties));
window_delegate_.get(), std::move(properties));
window_->Show();
DCHECK_NE(window_delegate_.widget(), gfx::kNullAcceleratedWidget);
DCHECK_NE(window_delegate_->widget(), gfx::kNullAcceleratedWidget);
allocator_.GenerateId();
compositor_.SetAcceleratedWidget(window_delegate_.widget());
compositor_.SetAcceleratedWidget(window_delegate_->widget());
compositor_.SetScaleAndSize(1.0f, bounds_.size(),
allocator_.GetCurrentLocalSurfaceIdAllocation());
compositor_.SetVisible(true);
......@@ -114,13 +95,16 @@ ui::Compositor* TestCompositorHostOzone::GetCompositor() {
return &compositor_;
}
} // namespace
// To avoid multiple definitions when use_x11 && use_ozone is true, disable this
// factory method for OS_LINUX as Linux has a factory method that decides what
// screen to use based on IsUsingOzonePlatform feature flag.
#if !defined(OS_LINUX)
// static
TestCompositorHost* TestCompositorHost::Create(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
return new TestCompositorHostOzone(bounds, context_factory);
}
#endif
} // namespace ui
// Copyright 2020 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_COMPOSITOR_TEST_TEST_COMPOSITOR_HOST_OZONE_H_
#define UI_COMPOSITOR_TEST_TEST_COMPOSITOR_HOST_OZONE_H_
#include "ui/compositor/test/test_compositor_host.h"
#include <memory>
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "ui/compositor/compositor.h"
#include "ui/gfx/geometry/rect.h"
namespace ui {
class PlatformWindow;
class TestCompositorHostOzone : public TestCompositorHost {
public:
TestCompositorHostOzone(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
TestCompositorHostOzone(const TestCompositorHostOzone&) = delete;
TestCompositorHostOzone& operator=(const TestCompositorHostOzone&) = delete;
~TestCompositorHostOzone() override;
private:
class StubPlatformWindowDelegate;
// Overridden from TestCompositorHost:
void Show() override;
ui::Compositor* GetCompositor() override;
gfx::Rect bounds_;
ui::Compositor compositor_;
std::unique_ptr<PlatformWindow> window_;
std::unique_ptr<StubPlatformWindowDelegate> window_delegate_;
viz::ParentLocalSurfaceIdAllocator allocator_;
};
} // namespace ui
#endif // UI_COMPOSITOR_TEST_TEST_COMPOSITOR_HOST_OZONE_H_
......@@ -2,50 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/compositor/test/test_compositor_host.h"
#include <memory>
#include "ui/compositor/test/test_compositor_host_x11.h"
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "ui/compositor/compositor.h"
#include "ui/events/x/x11_window_event_manager.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_types.h"
namespace ui {
class TestCompositorHostX11 : public TestCompositorHost {
public:
TestCompositorHostX11(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
~TestCompositorHostX11() override;
private:
// Overridden from TestCompositorHost:
void Show() override;
ui::Compositor* GetCompositor() override;
gfx::Rect bounds_;
ui::ContextFactory* context_factory_;
ui::Compositor compositor_;
x11::Window window_;
std::unique_ptr<XScopedEventSelector> window_events_;
viz::ParentLocalSurfaceIdAllocator allocator_;
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostX11);
};
TestCompositorHostX11::TestCompositorHostX11(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory)
......@@ -88,11 +55,4 @@ ui::Compositor* TestCompositorHostX11::GetCompositor() {
return &compositor_;
}
// static
TestCompositorHost* TestCompositorHost::Create(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
return new TestCompositorHostX11(bounds, context_factory);
}
} // namespace ui
// Copyright 2020 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_COMPOSITOR_TEST_TEST_COMPOSITOR_HOST_X11_H_
#define UI_COMPOSITOR_TEST_TEST_COMPOSITOR_HOST_X11_H_
#include <memory>
#include "base/time/time.h"
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/test/test_compositor_host.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_types.h"
namespace ui {
class XScopedEventSelector;
class TestCompositorHostX11 : public TestCompositorHost {
public:
TestCompositorHostX11(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);
TestCompositorHostX11(const TestCompositorHostX11&) = delete;
TestCompositorHostX11& operator=(const TestCompositorHostX11&) = delete;
~TestCompositorHostX11() override;
private:
// Overridden from TestCompositorHost:
void Show() override;
ui::Compositor* GetCompositor() override;
gfx::Rect bounds_;
ui::ContextFactory* context_factory_;
ui::Compositor compositor_;
x11::Window window_;
std::unique_ptr<XScopedEventSelector> window_events_;
viz::ParentLocalSurfaceIdAllocator allocator_;
};
} // namespace ui
#endif // UI_COMPOSITOR_TEST_TEST_COMPOSITOR_HOST_X11_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