Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Enable shell_unittests on Fuchsia with Vulkan dependencies. (flutter#…
Browse files Browse the repository at this point in the history
…16376)

This also adds a dependency on SwiftShader's Vulkan frontend.
  • Loading branch information
George Wright authored Feb 6, 2020
1 parent de7022b commit d2aab27
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 86 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ if (is_fuchsia) {
"//flutter/flow:flow_tests",
"//flutter/fml:fml_tests",
"//flutter/runtime:runtime_tests",
"//flutter/shell/common:shell_tests",
"//flutter/shell/platform/fuchsia/flutter:flutter_runner_scenic_tests",
"//flutter/shell/platform/fuchsia/flutter:flutter_runner_tests",
]
Expand Down
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ FILE: ../../../flutter/shell/common/shell_test_platform_view.cc
FILE: ../../../flutter/shell/common/shell_test_platform_view.h
FILE: ../../../flutter/shell/common/shell_test_platform_view_gl.cc
FILE: ../../../flutter/shell/common/shell_test_platform_view_gl.h
FILE: ../../../flutter/shell/common/shell_test_platform_view_vulkan.cc
FILE: ../../../flutter/shell/common/shell_test_platform_view_vulkan.h
FILE: ../../../flutter/shell/common/shell_unittests.cc
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.h
Expand Down
98 changes: 90 additions & 8 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,30 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//flutter/common/config.gni")
import("//flutter/shell/gpu/gpu.gni")
import("//flutter/testing/testing.gni")

if (is_fuchsia) {
import("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/fuchsia_archive.gni")
}

config("vulkan_config") {
if (using_fuchsia_sdk) {
include_dirs = [ "$fuchsia_sdk_root/vulkan/include" ]
} else if (is_fuchsia) {
include_dirs =
[ "//third_party/vulkan_loader_and_validation_layers/include" ]
} else {
include_dirs = [ "//third_party/vulkan/src" ]
}

if (is_fuchsia) {
defines = [ "VK_USE_PLATFORM_FUCHSIA=1" ]
}
}

# Template to generate a dart embedder resource.cc file.
# Required invoker inputs:
# String output (name of output file)
Expand Down Expand Up @@ -143,12 +164,19 @@ template("shell_host_executable") {
}
}

if (current_toolchain == host_toolchain) {
if (enable_unittests) {
declare_args() {
test_enable_vulkan = is_fuchsia
test_enable_gl = !is_fuchsia
test_enable_software = true
test_enable_metal = false
}

shell_gpu_configuration("shell_unittests_gpu_configuration") {
enable_software = true
enable_vulkan = false
enable_gl = true
enable_metal = false
enable_software = test_enable_software
enable_vulkan = test_enable_vulkan
enable_gl = test_enable_gl
enable_metal = test_enable_metal
}

test_fixtures("shell_unittests_fixtures") {
Expand All @@ -168,8 +196,6 @@ if (current_toolchain == host_toolchain) {
"shell_test.h",
"shell_test_platform_view.cc",
"shell_test_platform_view.h",
"shell_test_platform_view_gl.cc",
"shell_test_platform_view_gl.h",
"shell_unittests.cc",
"vsync_waiters_test.cc",
"vsync_waiters_test.h",
Expand All @@ -184,8 +210,64 @@ if (current_toolchain == host_toolchain) {
"//flutter/lib/ui:ui",
"//flutter/shell",
"//flutter/testing:dart",
"//flutter/testing:opengl",
]

if (!defined(defines)) {
defines = []
}

# SwiftShader only supports x86/x64_64
if (target_cpu == "x86" || target_cpu == "x64") {
if (test_enable_gl) {
sources += [
"shell_test_platform_view_gl.cc",
"shell_test_platform_view_gl.h",
]

deps += [ "//flutter/testing:opengl" ]

defines += [ "SHELL_ENABLE_GL" ]
}

if (test_enable_vulkan) {
sources += [
"shell_test_platform_view_vulkan.cc",
"shell_test_platform_view_vulkan.h",
]

deps += [
"//flutter/testing:vulkan",
"//flutter/vulkan",
]

defines += [ "SHELL_ENABLE_VULKAN" ]
}
}
}

if (is_fuchsia) {
fuchsia_test_archive("shell_tests") {
deps = [
":shell_unittests",
":shell_unittests_fixtures",
]

binary = "shell_unittests"

# TODO(gw280): https://github.com/flutter/flutter/issues/50294
# Right now we need to manually specify all the fixtures that are
# declared in the test_fixtures() call above.
resources = [
{
path = "$target_gen_dir/assets/kernel_blob.bin"
dest = "assets/kernel_blob.bin"
},
{
path = "$target_gen_dir/assets/shelltest_screenshot.png"
dest = "assets/shelltest_screenshot.png"
},
]
}
}

shell_host_executable("shell_benchmarks") {
Expand Down
7 changes: 4 additions & 3 deletions shell/common/animator_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ TEST_F(ShellTest, VSyncTargetTime) {
shell = Shell::Create(
task_runners, settings,
[vsync_clock, &create_vsync_waiter](Shell& shell) {
return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(),
vsync_clock,
std::move(create_vsync_waiter));
return ShellTestPlatformView::Create(
shell, shell.GetTaskRunners(), vsync_clock,
std::move(create_vsync_waiter),
ShellTestPlatformView::BackendType::kDefaultBackend);
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
Expand Down
7 changes: 4 additions & 3 deletions shell/common/shell_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ std::unique_ptr<Shell> ShellTest::CreateShell(Settings settings,
return Shell::Create(
task_runners, settings,
[vsync_clock, &create_vsync_waiter](Shell& shell) {
return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(),
vsync_clock,
std::move(create_vsync_waiter));
return ShellTestPlatformView::Create(
shell, shell.GetTaskRunners(), vsync_clock,
std::move(create_vsync_waiter),
ShellTestPlatformView::BackendType::kDefaultBackend);
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
Expand Down
29 changes: 26 additions & 3 deletions shell/common/shell_test_platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
// found in the LICENSE file.

#include "flutter/shell/common/shell_test_platform_view.h"

#ifdef SHELL_ENABLE_GL
#include "flutter/shell/common/shell_test_platform_view_gl.h"
#endif // SHELL_ENABLE_GL
#ifdef SHELL_ENABLE_VULKAN
#include "flutter/shell/common/shell_test_platform_view_vulkan.h"
#endif // SHELL_ENABLE_VULKAN

namespace flutter {
namespace testing {
Expand All @@ -12,9 +18,26 @@ std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter) {
return std::make_unique<ShellTestPlatformViewGL>(
delegate, task_runners, vsync_clock, create_vsync_waiter);
CreateVsyncWaiter create_vsync_waiter,
BackendType backend) {
// TODO(gw280): https://github.com/flutter/flutter/issues/50298
// Make this fully runtime configurable
switch (backend) {
case BackendType::kDefaultBackend:
#ifdef SHELL_ENABLE_GL
case BackendType::kGLBackend:
return std::make_unique<ShellTestPlatformViewGL>(
delegate, task_runners, vsync_clock, create_vsync_waiter);
#endif // SHELL_ENABLE_GL
#ifdef SHELL_ENABLE_VULKAN
case BackendType::kVulkanBackend:
return std::make_unique<ShellTestPlatformViewVulkan>(
delegate, task_runners, vsync_clock, create_vsync_waiter);
#endif // SHELL_ENABLE_VULKAN
default:
FML_LOG(FATAL) << "No backends supported for ShellTestPlatformView";
return nullptr;
}
}

} // namespace testing
Expand Down
9 changes: 8 additions & 1 deletion shell/common/shell_test_platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ namespace testing {

class ShellTestPlatformView : public PlatformView {
public:
enum class BackendType {
kGLBackend,
kVulkanBackend,
kDefaultBackend,
};

static std::unique_ptr<ShellTestPlatformView> Create(
PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter);
CreateVsyncWaiter create_vsync_waiter,
BackendType backend);

virtual void SimulateVSync() = 0;

Expand Down
49 changes: 49 additions & 0 deletions shell/common/shell_test_platform_view_vulkan.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2013 The Flutter 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 "flutter/shell/common/shell_test_platform_view_vulkan.h"
#include "flutter/shell/gpu/gpu_surface_vulkan.h"

namespace flutter {
namespace testing {

ShellTestPlatformViewVulkan::ShellTestPlatformViewVulkan(
PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter)
: ShellTestPlatformView(delegate, std::move(task_runners)),
create_vsync_waiter_(std::move(create_vsync_waiter)),
vsync_clock_(vsync_clock),
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {}

ShellTestPlatformViewVulkan::~ShellTestPlatformViewVulkan() = default;

std::unique_ptr<VsyncWaiter> ShellTestPlatformViewVulkan::CreateVSyncWaiter() {
return create_vsync_waiter_();
}

void ShellTestPlatformViewVulkan::SimulateVSync() {
vsync_clock_->SimulateVSync();
}

// |PlatformView|
std::unique_ptr<Surface> ShellTestPlatformViewVulkan::CreateRenderingSurface() {
return std::make_unique<GPUSurfaceVulkan>(this, nullptr, true);
}

// |PlatformView|
PointerDataDispatcherMaker ShellTestPlatformViewVulkan::GetDispatcherMaker() {
return [](DefaultPointerDataDispatcher::Delegate& delegate) {
return std::make_unique<SmoothPointerDataDispatcher>(delegate);
};
}

// |GPUSurfaceVulkanDelegate|
fml::RefPtr<vulkan::VulkanProcTable> ShellTestPlatformViewVulkan::vk() {
return proc_table_;
}

} // namespace testing
} // namespace flutter
51 changes: 51 additions & 0 deletions shell/common/shell_test_platform_view_vulkan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2013 The Flutter 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 FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_
#define FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_

#include "flutter/shell/common/shell_test_platform_view.h"
#include "flutter/shell/gpu/gpu_surface_vulkan_delegate.h"

namespace flutter {
namespace testing {

class ShellTestPlatformViewVulkan : public ShellTestPlatformView,
public GPUSurfaceVulkanDelegate {
public:
ShellTestPlatformViewVulkan(PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter);

~ShellTestPlatformViewVulkan() override;

void SimulateVSync() override;

private:
CreateVsyncWaiter create_vsync_waiter_;

std::shared_ptr<ShellTestVsyncClock> vsync_clock_;

fml::RefPtr<vulkan::VulkanProcTable> proc_table_;

// |PlatformView|
std::unique_ptr<Surface> CreateRenderingSurface() override;

// |PlatformView|
std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;

// |PlatformView|
PointerDataDispatcherMaker GetDispatcherMaker() override;

// |GPUSurfaceVulkanDelegate|
fml::RefPtr<vulkan::VulkanProcTable> vk() override;

FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformViewVulkan);
};

} // namespace testing
} // namespace flutter

#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_
3 changes: 2 additions & 1 deletion shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ TEST_F(ShellTest,
[task_runners = shell.GetTaskRunners()]() {
return static_cast<std::unique_ptr<VsyncWaiter>>(
std::make_unique<VsyncWaiterFallback>(task_runners));
});
},
ShellTestPlatformView::BackendType::kDefaultBackend);
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
Expand Down
2 changes: 0 additions & 2 deletions shell/platform/fuchsia/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import("//flutter/tools/fuchsia/dart.gni")
import("//flutter/tools/fuchsia/fuchsia_host_bundle.gni")

if (using_fuchsia_sdk) {
testonly = true

product_suffix = ""
is_product = false

Expand Down
Loading

0 comments on commit d2aab27

Please sign in to comment.