Ensure that the platform view is created and destroyed when running the shell unittests. (flutter/engine#6560)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("$flutter_root/testing/testing.gni")
|
||||
import("$flutter_root/shell/gpu/gpu.gni")
|
||||
|
||||
# Template to generate a dart embedder resource.cc file.
|
||||
# Required invoker inputs:
|
||||
@@ -107,8 +108,8 @@ source_set("common") {
|
||||
public_deps = [
|
||||
"$flutter_root/shell/version",
|
||||
"$flutter_root/third_party/txt",
|
||||
"//third_party/tonic",
|
||||
"//third_party/rapidjson",
|
||||
"//third_party/tonic",
|
||||
]
|
||||
|
||||
public_configs = [ "$flutter_root:config" ]
|
||||
@@ -139,12 +140,20 @@ template("shell_host_executable") {
|
||||
}
|
||||
}
|
||||
|
||||
shell_gpu_configuration("shell_unittests_gpu_configuration") {
|
||||
enable_software = true
|
||||
enable_vulkan = false
|
||||
enable_gl = false
|
||||
}
|
||||
|
||||
shell_host_executable("shell_unittests") {
|
||||
sources = [
|
||||
"shell_unittests.cc",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":shell_unittests_gpu_configuration",
|
||||
"$flutter_root/shell/",
|
||||
"$flutter_root/testing",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "flutter/shell/common/rasterizer.h"
|
||||
#include "flutter/shell/common/shell.h"
|
||||
#include "flutter/shell/common/thread_host.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_software.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define CURRENT_TEST_NAME \
|
||||
@@ -23,6 +24,64 @@
|
||||
|
||||
namespace shell {
|
||||
|
||||
class TestPlatformView : public PlatformView,
|
||||
public GPUSurfaceSoftwareDelegate {
|
||||
public:
|
||||
TestPlatformView(PlatformView::Delegate& delegate,
|
||||
blink::TaskRunners task_runners)
|
||||
: PlatformView(delegate, std::move(task_runners)) {}
|
||||
|
||||
private:
|
||||
// |PlatformView|
|
||||
std::unique_ptr<Surface> CreateRenderingSurface() override {
|
||||
return std::make_unique<GPUSurfaceSoftware>(this);
|
||||
}
|
||||
|
||||
// |GPUSurfaceSoftwareDelegate|
|
||||
virtual sk_sp<SkSurface> AcquireBackingStore(const SkISize& size) override {
|
||||
return SkSurface::MakeRasterN32Premul(size.width(), size.height());
|
||||
}
|
||||
|
||||
// |GPUSurfaceSoftwareDelegate|
|
||||
virtual bool PresentBackingStore(sk_sp<SkSurface> backing_store) override {
|
||||
return true;
|
||||
}
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(TestPlatformView);
|
||||
};
|
||||
|
||||
static bool ValidateShell(Shell* shell) {
|
||||
if (!shell) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!shell->IsSetup()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
fml::TaskRunner::RunNowOrPostTask(
|
||||
shell->GetTaskRunners().GetPlatformTaskRunner(), [shell, &latch]() {
|
||||
shell->GetPlatformView()->NotifyCreated();
|
||||
latch.Signal();
|
||||
});
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
{
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
fml::TaskRunner::RunNowOrPostTask(
|
||||
shell->GetTaskRunners().GetPlatformTaskRunner(), [shell, &latch]() {
|
||||
shell->GetPlatformView()->NotifyDestroyed();
|
||||
latch.Signal();
|
||||
});
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(ShellTest, InitializeWithInvalidThreads) {
|
||||
blink::Settings settings = {};
|
||||
settings.task_observer_add = [](intptr_t, fml::closure) {};
|
||||
@@ -31,7 +90,8 @@ TEST(ShellTest, InitializeWithInvalidThreads) {
|
||||
auto shell = Shell::Create(
|
||||
std::move(task_runners), settings,
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<PlatformView>(shell, shell.GetTaskRunners());
|
||||
return std::make_unique<TestPlatformView>(shell,
|
||||
shell.GetTaskRunners());
|
||||
},
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
|
||||
@@ -54,12 +114,13 @@ TEST(ShellTest, InitializeWithDifferentThreads) {
|
||||
auto shell = Shell::Create(
|
||||
std::move(task_runners), settings,
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<PlatformView>(shell, shell.GetTaskRunners());
|
||||
return std::make_unique<TestPlatformView>(shell,
|
||||
shell.GetTaskRunners());
|
||||
},
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
|
||||
});
|
||||
ASSERT_TRUE(shell);
|
||||
ASSERT_TRUE(ValidateShell(shell.get()));
|
||||
}
|
||||
|
||||
TEST(ShellTest, InitializeWithSingleThread) {
|
||||
@@ -74,12 +135,13 @@ TEST(ShellTest, InitializeWithSingleThread) {
|
||||
auto shell = Shell::Create(
|
||||
std::move(task_runners), settings,
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<PlatformView>(shell, shell.GetTaskRunners());
|
||||
return std::make_unique<TestPlatformView>(shell,
|
||||
shell.GetTaskRunners());
|
||||
},
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
|
||||
});
|
||||
ASSERT_TRUE(shell);
|
||||
ASSERT_TRUE(ValidateShell(shell.get()));
|
||||
}
|
||||
|
||||
TEST(ShellTest, InitializeWithSingleThreadWhichIsTheCallingThread) {
|
||||
@@ -93,12 +155,13 @@ TEST(ShellTest, InitializeWithSingleThreadWhichIsTheCallingThread) {
|
||||
auto shell = Shell::Create(
|
||||
std::move(task_runners), settings,
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<PlatformView>(shell, shell.GetTaskRunners());
|
||||
return std::make_unique<TestPlatformView>(shell,
|
||||
shell.GetTaskRunners());
|
||||
},
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
|
||||
});
|
||||
ASSERT_TRUE(shell);
|
||||
ASSERT_TRUE(ValidateShell(shell.get()));
|
||||
}
|
||||
|
||||
TEST(ShellTest, InitializeWithMultipleThreadButCallingThreadAsPlatformThread) {
|
||||
@@ -117,12 +180,41 @@ TEST(ShellTest, InitializeWithMultipleThreadButCallingThreadAsPlatformThread) {
|
||||
auto shell = Shell::Create(
|
||||
std::move(task_runners), settings,
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<PlatformView>(shell, shell.GetTaskRunners());
|
||||
return std::make_unique<TestPlatformView>(shell,
|
||||
shell.GetTaskRunners());
|
||||
},
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
|
||||
});
|
||||
ASSERT_TRUE(shell);
|
||||
ASSERT_TRUE(ValidateShell(shell.get()));
|
||||
}
|
||||
|
||||
// Reported in Bug: Engine deadlocks when gpu and platforms threads are the same
|
||||
// #21398 (https://github.com/flutter/flutter/issues/21398)
|
||||
TEST(ShellTest, DISABLED_InitializeWithGPUAndPlatformThreadsTheSame) {
|
||||
blink::Settings settings = {};
|
||||
settings.task_observer_add = [](intptr_t, fml::closure) {};
|
||||
settings.task_observer_remove = [](intptr_t) {};
|
||||
ThreadHost thread_host(
|
||||
"io.flutter.test." + CURRENT_TEST_NAME + ".",
|
||||
ThreadHost::Type::Platform | ThreadHost::Type::IO | ThreadHost::Type::UI);
|
||||
blink::TaskRunners task_runners(
|
||||
"test",
|
||||
thread_host.platform_thread->GetTaskRunner(), // platform
|
||||
thread_host.platform_thread->GetTaskRunner(), // gpu
|
||||
thread_host.ui_thread->GetTaskRunner(), // ui
|
||||
thread_host.io_thread->GetTaskRunner() // io
|
||||
);
|
||||
auto shell = Shell::Create(
|
||||
std::move(task_runners), settings,
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<TestPlatformView>(shell,
|
||||
shell.GetTaskRunners());
|
||||
},
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
|
||||
});
|
||||
ASSERT_TRUE(ValidateShell(shell.get()));
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
|
||||
46
engine/src/flutter/shell/gpu/BUILD.gn
Normal file
46
engine/src/flutter/shell/gpu/BUILD.gn
Normal file
@@ -0,0 +1,46 @@
|
||||
# Copyright 2018 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.
|
||||
|
||||
import("$flutter_root/shell/config.gni")
|
||||
|
||||
gpu_dir = "$flutter_root/shell/gpu"
|
||||
|
||||
gpu_common_deps = [
|
||||
"$flutter_root/common",
|
||||
"$flutter_root/flow",
|
||||
"$flutter_root/fml",
|
||||
"$flutter_root/shell/common",
|
||||
"$flutter_root/synchronization",
|
||||
"//third_party/skia",
|
||||
]
|
||||
|
||||
source_set("gpu_surface_software") {
|
||||
sources = [
|
||||
"$gpu_dir/gpu_surface_software.cc",
|
||||
"$gpu_dir/gpu_surface_software.h",
|
||||
]
|
||||
|
||||
deps = gpu_common_deps
|
||||
}
|
||||
|
||||
source_set("gpu_surface_gl") {
|
||||
sources = [
|
||||
"$gpu_dir/gpu_surface_gl.cc",
|
||||
"$gpu_dir/gpu_surface_gl.h",
|
||||
]
|
||||
|
||||
deps = gpu_common_deps + [ "//third_party/skia:gpu" ]
|
||||
}
|
||||
|
||||
source_set("gpu_surface_vulkan") {
|
||||
sources = [
|
||||
"$gpu_dir/gpu_surface_vulkan.cc",
|
||||
"$gpu_dir/gpu_surface_vulkan.h",
|
||||
]
|
||||
|
||||
deps = gpu_common_deps + [
|
||||
"//third_party/skia:gpu",
|
||||
"$flutter_root/vulkan",
|
||||
]
|
||||
}
|
||||
@@ -12,51 +12,19 @@ template("shell_gpu_configuration") {
|
||||
assert(defined(invoker.enable_gl),
|
||||
"Caller must declare if the Open GL backend must be enabled.")
|
||||
|
||||
source_set(target_name) {
|
||||
# vulkan_backend_enabled = shell_enable_vulkan
|
||||
# gl_backend_enabled = !is_fuchsia
|
||||
# software_backend_enabled = true
|
||||
|
||||
sources = []
|
||||
|
||||
gpu_dir = "$flutter_root/shell/gpu"
|
||||
group(target_name) {
|
||||
public_deps = []
|
||||
|
||||
if (invoker.enable_software) {
|
||||
sources += [
|
||||
"$gpu_dir/gpu_surface_software.cc",
|
||||
"$gpu_dir/gpu_surface_software.h",
|
||||
]
|
||||
public_deps += [ "$flutter_root/shell/gpu:gpu_surface_software" ]
|
||||
}
|
||||
|
||||
if (invoker.enable_gl) {
|
||||
sources += [
|
||||
"$gpu_dir/gpu_surface_gl.cc",
|
||||
"$gpu_dir/gpu_surface_gl.h",
|
||||
]
|
||||
public_deps += [ "$flutter_root/shell/gpu:gpu_surface_gl" ]
|
||||
}
|
||||
|
||||
if (invoker.enable_vulkan) {
|
||||
sources += [
|
||||
"$gpu_dir/gpu_surface_vulkan.cc",
|
||||
"$gpu_dir/gpu_surface_vulkan.h",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"$flutter_root/common",
|
||||
"$flutter_root/flow",
|
||||
"$flutter_root/fml",
|
||||
"$flutter_root/shell/common",
|
||||
"$flutter_root/synchronization",
|
||||
"//third_party/skia",
|
||||
]
|
||||
|
||||
if (invoker.enable_vulkan || invoker.enable_gl) {
|
||||
deps += [ "//third_party/skia:gpu" ]
|
||||
}
|
||||
|
||||
if (invoker.enable_vulkan) {
|
||||
deps += [ "$flutter_root/vulkan" ]
|
||||
public_deps += [ "$flutter_root/shell/gpu:gpu_surface_vulkan" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user