Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 58b2b52

Browse files
author
George Wright
committed
Enable shell_unittests on Fuchsia with Vulkan dependencies.
This also adds a dependency on SwiftShader's Vulkan frontend.
1 parent 7fea936 commit 58b2b52

17 files changed

+330
-86
lines changed

BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ if (is_fuchsia) {
135135
deps = [
136136
"//flutter/flow:flow_tests",
137137
"//flutter/fml:fml_tests",
138+
"//flutter/shell/common:shell_tests",
138139
"//flutter/shell/platform/fuchsia/flutter:flutter_runner_scenic_tests",
139140
"//flutter/shell/platform/fuchsia/flutter:flutter_runner_tests",
140141
]

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ FILE: ../../../flutter/shell/common/shell_test_platform_view.cc
578578
FILE: ../../../flutter/shell/common/shell_test_platform_view.h
579579
FILE: ../../../flutter/shell/common/shell_test_platform_view_gl.cc
580580
FILE: ../../../flutter/shell/common/shell_test_platform_view_gl.h
581+
FILE: ../../../flutter/shell/common/shell_test_platform_view_vulkan.cc
582+
FILE: ../../../flutter/shell/common/shell_test_platform_view_vulkan.h
581583
FILE: ../../../flutter/shell/common/shell_unittests.cc
582584
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc
583585
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.h

shell/common/BUILD.gn

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,30 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5+
import("//flutter/common/config.gni")
56
import("//flutter/shell/gpu/gpu.gni")
67
import("//flutter/testing/testing.gni")
78

9+
if (is_fuchsia) {
10+
import("//build/fuchsia/sdk.gni")
11+
import("//flutter/tools/fuchsia/fuchsia_archive.gni")
12+
}
13+
14+
config("vulkan_config") {
15+
if (using_fuchsia_sdk) {
16+
include_dirs = [ "$fuchsia_sdk_root/vulkan/include" ]
17+
} else if (is_fuchsia) {
18+
include_dirs =
19+
[ "//third_party/vulkan_loader_and_validation_layers/include" ]
20+
} else {
21+
include_dirs = [ "//third_party/vulkan/src" ]
22+
}
23+
24+
if (is_fuchsia) {
25+
defines = [ "VK_USE_PLATFORM_FUCHSIA=1" ]
26+
}
27+
}
28+
829
# Template to generate a dart embedder resource.cc file.
930
# Required invoker inputs:
1031
# String output (name of output file)
@@ -143,12 +164,19 @@ template("shell_host_executable") {
143164
}
144165
}
145166

146-
if (current_toolchain == host_toolchain) {
167+
if (enable_unittests) {
168+
declare_args() {
169+
test_enable_vulkan = is_fuchsia
170+
test_enable_gl = !is_fuchsia
171+
test_enable_software = true
172+
test_enable_metal = false
173+
}
174+
147175
shell_gpu_configuration("shell_unittests_gpu_configuration") {
148-
enable_software = true
149-
enable_vulkan = false
150-
enable_gl = true
151-
enable_metal = false
176+
enable_software = test_enable_software
177+
enable_vulkan = test_enable_vulkan
178+
enable_gl = test_enable_gl
179+
enable_metal = test_enable_metal
152180
}
153181

154182
test_fixtures("shell_unittests_fixtures") {
@@ -168,8 +196,6 @@ if (current_toolchain == host_toolchain) {
168196
"shell_test.h",
169197
"shell_test_platform_view.cc",
170198
"shell_test_platform_view.h",
171-
"shell_test_platform_view_gl.cc",
172-
"shell_test_platform_view_gl.h",
173199
"shell_unittests.cc",
174200
"vsync_waiters_test.cc",
175201
"vsync_waiters_test.h",
@@ -184,8 +210,63 @@ if (current_toolchain == host_toolchain) {
184210
"//flutter/lib/ui:ui",
185211
"//flutter/shell",
186212
"//flutter/testing:dart",
187-
"//flutter/testing:opengl",
188213
]
214+
215+
if (!defined(defines)) {
216+
defines = []
217+
}
218+
219+
# SwiftShader only supports x86/x64_64
220+
if (target_cpu == "x86" || target_cpu == "x64") {
221+
if (test_enable_gl) {
222+
sources += [
223+
"shell_test_platform_view_gl.cc",
224+
"shell_test_platform_view_gl.h",
225+
]
226+
227+
deps += [ "//flutter/testing:opengl" ]
228+
229+
defines += [ "SHELL_ENABLE_GL" ]
230+
}
231+
232+
if (test_enable_vulkan) {
233+
sources += [
234+
"shell_test_platform_view_vulkan.cc",
235+
"shell_test_platform_view_vulkan.h",
236+
]
237+
238+
deps += [
239+
"//flutter/testing:vulkan",
240+
"//flutter/vulkan",
241+
]
242+
243+
defines += [ "SHELL_ENABLE_VULKAN" ]
244+
}
245+
}
246+
}
247+
248+
if (is_fuchsia) {
249+
fuchsia_test_archive("shell_tests") {
250+
deps = [
251+
":shell_unittests",
252+
":shell_unittests_fixtures",
253+
]
254+
255+
binary = "shell_unittests"
256+
257+
# Right now we need to manually specify all the fixtures that are
258+
# declared in the test_fixtures() call above.
259+
resources = [
260+
{
261+
path = "$target_gen_dir/assets/kernel_blob.bin"
262+
dest = "assets/kernel_blob.bin"
263+
},
264+
{
265+
path = "$target_gen_dir/assets/shelltest_screenshot.png"
266+
dest = "assets/shelltest_screenshot.png"
267+
},
268+
]
269+
}
189270
}
190271

191272
shell_host_executable("shell_benchmarks") {

shell/common/animator_unittests.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ TEST_F(ShellTest, VSyncTargetTime) {
5252
shell = Shell::Create(
5353
task_runners, settings,
5454
[vsync_clock, &create_vsync_waiter](Shell& shell) {
55-
return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(),
56-
vsync_clock,
57-
std::move(create_vsync_waiter));
55+
return ShellTestPlatformView::Create(
56+
shell, shell.GetTaskRunners(), vsync_clock,
57+
std::move(create_vsync_waiter),
58+
ShellTestPlatformView::BackendType::kDefaultBackend);
5859
},
5960
[](Shell& shell) {
6061
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());

shell/common/shell_test.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,10 @@ std::unique_ptr<Shell> ShellTest::CreateShell(Settings settings,
254254
return Shell::Create(
255255
task_runners, settings,
256256
[vsync_clock, &create_vsync_waiter](Shell& shell) {
257-
return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(),
258-
vsync_clock,
259-
std::move(create_vsync_waiter));
257+
return ShellTestPlatformView::Create(
258+
shell, shell.GetTaskRunners(), vsync_clock,
259+
std::move(create_vsync_waiter),
260+
ShellTestPlatformView::BackendType::kDefaultBackend);
260261
},
261262
[](Shell& shell) {
262263
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());

shell/common/shell_test_platform_view.cc

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
// found in the LICENSE file.
44

55
#include "flutter/shell/common/shell_test_platform_view.h"
6+
7+
#ifdef SHELL_ENABLE_GL
68
#include "flutter/shell/common/shell_test_platform_view_gl.h"
9+
#endif // SHELL_ENABLE_GL
10+
#ifdef SHELL_ENABLE_VULKAN
11+
#include "flutter/shell/common/shell_test_platform_view_vulkan.h"
12+
#endif // SHELL_ENABLE_VULKAN
713

814
namespace flutter {
915
namespace testing {
@@ -12,9 +18,25 @@ std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
1218
PlatformView::Delegate& delegate,
1319
TaskRunners task_runners,
1420
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
15-
CreateVsyncWaiter create_vsync_waiter) {
16-
return std::make_unique<ShellTestPlatformViewGL>(
17-
delegate, task_runners, vsync_clock, create_vsync_waiter);
21+
CreateVsyncWaiter create_vsync_waiter,
22+
BackendType backend) {
23+
// TODO(gw280): Make this fully runtime configurable
24+
switch (backend) {
25+
case BackendType::kDefaultBackend:
26+
#ifdef SHELL_ENABLE_GL
27+
case BackendType::kGLBackend:
28+
return std::make_unique<ShellTestPlatformViewGL>(
29+
delegate, task_runners, vsync_clock, create_vsync_waiter);
30+
#endif // SHELL_ENABLE_GL
31+
#ifdef SHELL_ENABLE_VULKAN
32+
case BackendType::kVulkanBackend:
33+
return std::make_unique<ShellTestPlatformViewVulkan>(
34+
delegate, task_runners, vsync_clock, create_vsync_waiter);
35+
#endif // SHELL_ENABLE_VULKAN
36+
default:
37+
FML_LOG(FATAL) << "No backends supported for ShellTestPlatformView";
38+
return nullptr;
39+
}
1840
}
1941

2042
} // namespace testing

shell/common/shell_test_platform_view.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ namespace testing {
1313

1414
class ShellTestPlatformView : public PlatformView {
1515
public:
16+
enum class BackendType {
17+
kGLBackend,
18+
kVulkanBackend,
19+
kDefaultBackend,
20+
};
21+
1622
static std::unique_ptr<ShellTestPlatformView> Create(
1723
PlatformView::Delegate& delegate,
1824
TaskRunners task_runners,
1925
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
20-
CreateVsyncWaiter create_vsync_waiter);
26+
CreateVsyncWaiter create_vsync_waiter,
27+
BackendType backend);
2128

2229
virtual void SimulateVSync() = 0;
2330

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/shell/common/shell_test_platform_view_vulkan.h"
6+
#include "flutter/shell/gpu/gpu_surface_vulkan.h"
7+
8+
namespace flutter {
9+
namespace testing {
10+
11+
ShellTestPlatformViewVulkan::ShellTestPlatformViewVulkan(
12+
PlatformView::Delegate& delegate,
13+
TaskRunners task_runners,
14+
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
15+
CreateVsyncWaiter create_vsync_waiter)
16+
: ShellTestPlatformView(delegate, std::move(task_runners)),
17+
create_vsync_waiter_(std::move(create_vsync_waiter)),
18+
vsync_clock_(vsync_clock),
19+
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {}
20+
21+
ShellTestPlatformViewVulkan::~ShellTestPlatformViewVulkan() = default;
22+
23+
std::unique_ptr<VsyncWaiter> ShellTestPlatformViewVulkan::CreateVSyncWaiter() {
24+
return create_vsync_waiter_();
25+
}
26+
27+
void ShellTestPlatformViewVulkan::SimulateVSync() {
28+
vsync_clock_->SimulateVSync();
29+
}
30+
31+
// |PlatformView|
32+
std::unique_ptr<Surface> ShellTestPlatformViewVulkan::CreateRenderingSurface() {
33+
return std::make_unique<GPUSurfaceVulkan>(this, nullptr, true);
34+
}
35+
36+
// |PlatformView|
37+
PointerDataDispatcherMaker ShellTestPlatformViewVulkan::GetDispatcherMaker() {
38+
return [](DefaultPointerDataDispatcher::Delegate& delegate) {
39+
return std::make_unique<SmoothPointerDataDispatcher>(delegate);
40+
};
41+
}
42+
43+
// |GPUSurfaceVulkanDelegate|
44+
fml::RefPtr<vulkan::VulkanProcTable> ShellTestPlatformViewVulkan::vk() {
45+
return proc_table_;
46+
}
47+
48+
} // namespace testing
49+
} // namespace flutter
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_
6+
#define FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_
7+
8+
#include "flutter/shell/common/shell_test_platform_view.h"
9+
#include "flutter/shell/gpu/gpu_surface_vulkan_delegate.h"
10+
11+
namespace flutter {
12+
namespace testing {
13+
14+
class ShellTestPlatformViewVulkan : public ShellTestPlatformView,
15+
public GPUSurfaceVulkanDelegate {
16+
public:
17+
ShellTestPlatformViewVulkan(PlatformView::Delegate& delegate,
18+
TaskRunners task_runners,
19+
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
20+
CreateVsyncWaiter create_vsync_waiter);
21+
22+
~ShellTestPlatformViewVulkan() override;
23+
24+
void SimulateVSync() override;
25+
26+
private:
27+
CreateVsyncWaiter create_vsync_waiter_;
28+
29+
std::shared_ptr<ShellTestVsyncClock> vsync_clock_;
30+
31+
fml::RefPtr<vulkan::VulkanProcTable> proc_table_;
32+
33+
// |PlatformView|
34+
std::unique_ptr<Surface> CreateRenderingSurface() override;
35+
36+
// |PlatformView|
37+
std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
38+
39+
// |PlatformView|
40+
PointerDataDispatcherMaker GetDispatcherMaker() override;
41+
42+
// |GPUSurfaceVulkanDelegate|
43+
fml::RefPtr<vulkan::VulkanProcTable> vk() override;
44+
45+
FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformViewVulkan);
46+
};
47+
48+
} // namespace testing
49+
} // namespace flutter
50+
51+
#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_

shell/common/shell_unittests.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ TEST_F(ShellTest,
135135
[task_runners = shell.GetTaskRunners()]() {
136136
return static_cast<std::unique_ptr<VsyncWaiter>>(
137137
std::make_unique<VsyncWaiterFallback>(task_runners));
138-
});
138+
},
139+
ShellTestPlatformView::BackendType::kDefaultBackend);
139140
},
140141
[](Shell& shell) {
141142
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());

shell/platform/fuchsia/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import("//flutter/tools/fuchsia/dart.gni")
88
import("//flutter/tools/fuchsia/fuchsia_host_bundle.gni")
99

1010
if (using_fuchsia_sdk) {
11-
testonly = true
12-
1311
product_suffix = ""
1412
is_product = false
1513

0 commit comments

Comments
 (0)