Commit f4382a4e authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

vulkan_tests: support ozone platform

Tested with --ozone-platform=x11.

Bug: 1065499
Change-Id: I57299267c6c496f77a2004ca6017bc2c0c8dabf1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2126248
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: default avatarVasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Auto-Submit: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754681}
parent ab73cc04
......@@ -41,6 +41,7 @@ constexpr SkColor kOutputColor = SK_ColorRED;
class SkiaOutputSurfaceImplTest : public testing::TestWithParam<bool> {
public:
SkiaOutputSurfaceImplTest();
~SkiaOutputSurfaceImplTest() override;
bool CreateNativeWindow() const { return GetParam(); }
......@@ -62,6 +63,7 @@ class SkiaOutputSurfaceImplTest : public testing::TestWithParam<bool> {
void UnblockMainThread();
protected:
gfx::AcceleratedWidget accelerated_widget_ = gfx::kNullAcceleratedWidget;
gl::DisableNullDrawGLBindings enable_pixel_output_;
std::unique_ptr<SkiaOutputSurface> output_surface_;
cc::FakeOutputSurfaceClient output_surface_client_;
......@@ -74,11 +76,24 @@ SkiaOutputSurfaceImplTest::SkiaOutputSurfaceImplTest()
SetUpSkiaOutputSurfaceImpl();
}
SkiaOutputSurfaceImplTest::~SkiaOutputSurfaceImplTest() {
output_surface_.reset();
if (accelerated_widget_ != gfx::kNullAcceleratedWidget) {
#if BUILDFLAG(ENABLE_VULKAN) && defined(USE_X11)
gpu::DestroyNativeWindow(accelerated_widget_);
#else
// TODO(backer): Support other platforms.
NOTREACHED();
#endif
}
}
void SkiaOutputSurfaceImplTest::SetUpSkiaOutputSurfaceImpl() {
gpu::SurfaceHandle surface_handle_ = gpu::kNullSurfaceHandle;
gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle;
if (CreateNativeWindow()) {
#if BUILDFLAG(ENABLE_VULKAN) && defined(USE_X11)
surface_handle_ = gpu::CreateNativeWindow(kSurfaceRect);
accelerated_widget_ = gpu::CreateNativeWindow(kSurfaceRect);
surface_handle = accelerated_widget_;
#else
// TODO(backer): Support other platforms.
NOTREACHED();
......@@ -89,7 +104,7 @@ void SkiaOutputSurfaceImplTest::SetUpSkiaOutputSurfaceImpl() {
settings.use_skia_renderer = true;
output_surface_ = SkiaOutputSurfaceImpl::Create(
std::make_unique<SkiaOutputSurfaceDependencyImpl>(GetGpuService(),
surface_handle_),
surface_handle),
settings);
output_surface_->BindToClient(&output_surface_client_);
}
......
......@@ -100,8 +100,12 @@ viz_source_set("test_suite") {
":test_support",
"//base",
"//base/test:test_support",
"//ui/events/platform",
"//ui/gl:test_support",
]
if (use_x11) {
deps += [ "//ui/events/platform/x11" ]
}
}
viz_source_set("unit_tests") {
......
......@@ -31,6 +31,7 @@ include_rules = [
"+third_party/khronos/GLES2/gl2.h",
"+third_party/khronos/GLES2/gl2ext.h",
"+third_party/skia/include",
"+ui/events",
"+ui/gl",
"+ui/latency",
]
......
......@@ -6,6 +6,7 @@
#include "base/threading/thread_id_name_manager.h"
#include "components/viz/test/paths.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gl/test/gl_surface_test_support.h"
namespace viz {
......@@ -20,6 +21,7 @@ void VizTestSuite::Initialize() {
// Must be initialized after time outs are initialized in by the TestSuite.
task_environment_ = std::make_unique<base::test::TaskEnvironment>(
base::test::TaskEnvironment::MainThreadType::UI);
platform_event_source_ = ui::PlatformEventSource::CreateDefault();
gl::GLSurfaceTestSupport::InitializeOneOff();
Paths::RegisterPathProvider();
......@@ -30,6 +32,8 @@ void VizTestSuite::Initialize() {
}
void VizTestSuite::Shutdown() {
platform_event_source_.reset();
task_environment_.reset();
base::TestSuite::Shutdown();
}
......
......@@ -12,6 +12,10 @@
#include "base/test/test_discardable_memory_allocator.h"
#include "base/test/test_suite.h"
namespace ui {
class PlatformEventSource;
} // namespace ui
namespace viz {
class VizTestSuite : public base::TestSuite {
......@@ -26,6 +30,8 @@ class VizTestSuite : public base::TestSuite {
private:
std::unique_ptr<base::test::TaskEnvironment> task_environment_;
std::unique_ptr<ui::PlatformEventSource> platform_event_source_;
base::TestDiscardableMemoryAllocator discardable_memory_allocator_;
DISALLOW_COPY_AND_ASSIGN(VizTestSuite);
......
......@@ -121,19 +121,39 @@ if (enable_vulkan) {
"//ui/gfx",
"//ui/gfx:native_widget_types",
]
if (use_x11) {
sources += [ "tests/native_window_x11.cc" ]
deps += [ "//ui/gfx/x" ]
configs += [ "//build/config/linux:x11" ]
if (use_x11 && !use_ozone) {
sources += [ "tests/native_window.cc" ]
deps += [
"//ui/platform_window",
"//ui/platform_window/x11",
]
}
if (is_win) {
sources += [ "tests/native_window_win.cc" ]
}
if (use_ozone) {
sources += [ "tests/native_window.cc" ]
deps += [
"//ui/ozone",
"//ui/platform_window",
]
}
if (is_android) {
sources += [ "tests/native_window_android.cc" ]
deps += [
"//ui/android:ui_java",
"//ui/gl",
]
}
}
# TODO(penghuang): support more platforms
# https://crbug.com/1065499
if (is_android || use_x11 || is_win) {
if (is_android || use_x11 || is_win || use_ozone) {
test("vulkan_tests") {
sources = [
"tests/basic_vulkan_test.cc",
......@@ -161,11 +181,8 @@ if (enable_vulkan) {
deps += [ "//ui/events/platform/x11" ]
}
if (is_android) {
deps += [
"//ui/android:ui_java",
"//ui/gl",
]
if (use_ozone) {
deps += [ "//ui/ozone" ]
}
}
}
......
include_rules = [
"+ui/events/platform",
"+ui/platform_window",
]
......@@ -8,13 +8,8 @@
#include "gpu/vulkan/init/vulkan_factory.h"
#include "gpu/vulkan/tests/native_window.h"
#include "gpu/vulkan/vulkan_surface.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/geometry/rect.h"
#if defined(OS_ANDROID)
#include <android/native_window_jni.h>
#endif
namespace gpu {
BasicVulkanTest::BasicVulkanTest() {}
......@@ -22,21 +17,13 @@ BasicVulkanTest::BasicVulkanTest() {}
BasicVulkanTest::~BasicVulkanTest() {}
void BasicVulkanTest::SetUp() {
platform_event_source_ = ui::PlatformEventSource::CreateDefault();
#if defined(USE_X11) || defined(OS_WIN)
#if defined(USE_X11) || defined(OS_WIN) || defined(OS_ANDROID) || \
defined(USE_OZONE)
bool use_swiftshader =
base::CommandLine::ForCurrentProcess()->HasSwitch("use-swiftshader");
const gfx::Rect kDefaultBounds(10, 10, 100, 100);
window_ = CreateNativeWindow(kDefaultBounds);
#elif defined(OS_ANDROID)
// Vulkan swiftshader is not supported on Android.
bool use_swiftshader = false;
// TODO(penghuang): Not depend on gl.
uint texture = 0;
surface_texture_ = gl::SurfaceTexture::Create(texture);
window_ = surface_texture_->CreateSurface();
ASSERT_TRUE(window_ != gfx::kNullAcceleratedWidget);
#endif
vulkan_implementation_ = CreateVulkanImplementation(use_swiftshader);
ASSERT_TRUE(vulkan_implementation_);
ASSERT_TRUE(vulkan_implementation_->InitializeVulkanInstance());
......@@ -45,18 +32,21 @@ void BasicVulkanTest::SetUp() {
VulkanDeviceQueue::GRAPHICS_QUEUE_FLAG |
VulkanDeviceQueue::PRESENTATION_SUPPORT_QUEUE_FLAG);
ASSERT_TRUE(device_queue_);
#else
#error Unsupported platform
#endif
}
void BasicVulkanTest::TearDown() {
#if defined(USE_X11) || defined(OS_WIN)
#if defined(USE_X11) || defined(OS_WIN) || defined(OS_ANDROID) || \
defined(USE_OZONE)
DestroyNativeWindow(window_);
#elif defined(OS_ANDROID)
ANativeWindow_release(window_);
#endif
window_ = gfx::kNullAcceleratedWidget;
device_queue_->Destroy();
vulkan_implementation_.reset();
platform_event_source_.reset();
#else
#error Unsupported platform
#endif
}
std::unique_ptr<VulkanSurface> BasicVulkanTest::CreateViewSurface(
......
......@@ -5,21 +5,13 @@
#ifndef GPU_VULKAN_TESTS_BASIC_VULKAN_TEST_H_
#define GPU_VULKAN_TESTS_BASIC_VULKAN_TEST_H_
#include "base/memory/ref_counted.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "gpu/vulkan/vulkan_device_queue.h"
#include "gpu/vulkan/vulkan_implementation.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/native_widget_types.h"
#if defined(OS_ANDROID)
#include "ui/gl/android/surface_texture.h"
#endif
namespace ui {
class PlatformEventSource;
}
namespace gpu {
class BasicVulkanTest : public testing::Test {
......@@ -41,14 +33,9 @@ class BasicVulkanTest : public testing::Test {
gfx::AcceleratedWidget window);
private:
std::unique_ptr<ui::PlatformEventSource> platform_event_source_;
std::unique_ptr<VulkanImplementation> vulkan_implementation_;
std::unique_ptr<VulkanDeviceQueue> device_queue_;
gfx::AcceleratedWidget window_ = gfx::kNullAcceleratedWidget;
#if defined(OS_ANDROID)
scoped_refptr<gl::SurfaceTexture> surface_texture_;
#endif
};
} // namespace gpu
......
// 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 "gpu/vulkan/tests/native_window.h"
#include "base/containers/flat_map.h"
#include "ui/platform_window/platform_window_delegate.h"
#include "ui/platform_window/platform_window_init_properties.h"
#if defined(USE_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif
#if defined(USE_X11)
#include "ui/platform_window/x11/x11_window.h" // nogncheck
#endif
namespace gpu {
namespace {
class Window : public ui::PlatformWindowDelegate {
public:
Window() = default;
~Window() override = default;
void Initialize(const gfx::Rect& bounds) {
DCHECK(!platform_window_);
#if defined(USE_OZONE)
ui::PlatformWindowInitProperties props(bounds);
platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
this, std::move(props));
#elif defined(USE_X11)
ui::PlatformWindowInitProperties props(bounds);
auto x11_window = std::make_unique<ui::X11Window>(this);
x11_window->Initialize(std::move(props));
platform_window_ = std::move(x11_window);
#else
NOTIMPLEMENTED();
return;
#endif
platform_window_->Show();
}
gfx::AcceleratedWidget widget() const { return widget_; }
private:
// ui::PlatformWindowDelegate:
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override {
widget_ = widget;
}
void OnBoundsChanged(const gfx::Rect& new_bounds) override {}
void OnDamageRect(const gfx::Rect& damaged_region) override {}
void DispatchEvent(ui::Event* event) override {}
void OnCloseRequest() override {}
void OnClosed() override {}
void OnWindowStateChanged(ui::PlatformWindowState new_state) override {}
void OnLostCapture() override {}
void OnAcceleratedWidgetDestroyed() override {}
void OnActivationChanged(bool active) override {}
void OnMouseEnter() override {}
std::unique_ptr<ui::PlatformWindow> platform_window_;
gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
};
base::flat_map<gfx::AcceleratedWidget, std::unique_ptr<Window>> g_windows_;
} // namespace
gfx::AcceleratedWidget CreateNativeWindow(const gfx::Rect& bounds) {
auto window = std::make_unique<Window>();
window->Initialize(bounds);
gfx::AcceleratedWidget widget = window->widget();
if (widget != gfx::kNullAcceleratedWidget)
g_windows_[widget] = std::move(window);
return widget;
}
void DestroyNativeWindow(gfx::AcceleratedWidget window) {
auto it = g_windows_.find(window);
DCHECK(it != g_windows_.end());
g_windows_.erase(it);
}
} // namespace gpu
// 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 "gpu/vulkan/tests/native_window.h"
#include <android/native_window_jni.h>
#include "ui/gl/android/surface_texture.h"
namespace gpu {
scoped_refptr<gl::SurfaceTexture> g_surface_texture;
gfx::AcceleratedWidget g_widget = gfx::kNullAcceleratedWidget;
gfx::AcceleratedWidget CreateNativeWindow(const gfx::Rect& bounds) {
DCHECK(!g_surface_texture);
DCHECK(g_widget == gfx::kNullAcceleratedWidget);
// TODO(penghuang): Not depend on gl.
uint texture = 0;
g_surface_texture = gl::SurfaceTexture::Create(texture);
g_widget = g_surface_texture->CreateSurface();
return g_widget;
}
void DestroyNativeWindow(gfx::AcceleratedWidget window) {
DCHECK_EQ(g_widget, window);
ANativeWindow_release(window);
g_widget = gfx::kNullAcceleratedWidget;
g_surface_texture = nullptr;
}
} // namespace gpu
// Copyright (c) 2016 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 "gpu/vulkan/tests/native_window.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_types.h"
namespace gpu {
gfx::AcceleratedWidget CreateNativeWindow(const gfx::Rect& bounds) {
XDisplay* display = gfx::GetXDisplay();
XSetWindowAttributes swa;
swa.event_mask = StructureNotifyMask | ExposureMask;
swa.override_redirect = x11::True;
XID window = XCreateWindow(
display, XRootWindow(display, DefaultScreen(display)), // parent
bounds.x(), bounds.y(), bounds.width(), bounds.height(),
0, // border width
CopyFromParent, // depth
InputOutput,
CopyFromParent, // visual
CWEventMask | CWOverrideRedirect, &swa);
XMapWindow(display, window);
while (1) {
XEvent event;
XNextEvent(display, &event);
if (event.type == MapNotify && event.xmap.window == window)
break;
}
return window;
}
void DestroyNativeWindow(gfx::AcceleratedWidget window) {
XDestroyWindow(gfx::GetXDisplay(), window);
}
} // namespace gpu
......@@ -5,21 +5,54 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/task_environment.h"
#include "base/test/test_suite.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/events/platform/platform_event_source.h"
#if defined(USE_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace {
int RunHelper(base::TestSuite* testSuite) {
return testSuite->Run();
}
class VulkanTestSuite : public base::TestSuite {
public:
VulkanTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
protected:
void Initialize() override {
base::TestSuite::Initialize();
task_environment_ = std::make_unique<base::test::TaskEnvironment>(
base::test::TaskEnvironment::MainThreadType::UI);
platform_event_source_ = ui::PlatformEventSource::CreateDefault();
#if defined(USE_OZONE)
// Make Ozone run in single-process mode.
ui::OzonePlatform::InitParams params;
params.single_process = true;
params.using_mojo = true;
// This initialization must be done after TaskEnvironment has
// initialized the UI thread.
ui::OzonePlatform::InitializeForUI(params);
ui::OzonePlatform::InitializeForGPU(params);
#endif
}
private:
std::unique_ptr<ui::PlatformEventSource> platform_event_source_;
std::unique_ptr<base::test::TaskEnvironment> task_environment_;
};
} // namespace
int main(int argc, char** argv) {
base::TestSuite test_suite(argc, argv);
VulkanTestSuite test_suite(argc, argv);
base::CommandLine::Init(argc, argv);
testing::InitGoogleMock(&argc, argv);
return base::LaunchUnitTestsSerially(
argc, argv, base::BindOnce(&RunHelper, base::Unretained(&test_suite)));
argc, argv,
base::BindOnce(&VulkanTestSuite::Run, base::Unretained(&test_suite)));
}
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