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

Commit 82b3b8b

Browse files
committed
Refactor Shell unit-tests to allow runtime selection of client rendering API.
Adds support for Metal rasterizers in the unit-test harness.
1 parent 07429c1 commit 82b3b8b

22 files changed

+588
-173
lines changed

shell/common/BUILD.gn

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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_root/shell/config.gni")
56
import("$flutter_root/shell/gpu/gpu.gni")
67
import("$flutter_root/testing/testing.gni")
78

@@ -158,17 +159,30 @@ if (current_toolchain == host_toolchain) {
158159
}
159160

160161
shell_host_executable("shell_unittests") {
162+
defines = []
163+
164+
if (shell_enable_metal) {
165+
defines += [ "SHELL_ENABLE_METAL" ]
166+
}
167+
161168
sources = [
162-
"animator_unittests.cc",
163-
"canvas_spy_unittests.cc",
164-
"input_events_unittests.cc",
165-
"persistent_cache_unittests.cc",
166-
"pipeline_unittests.cc",
167-
"shell_test.cc",
168-
"shell_test.h",
169-
"shell_unittests.cc",
170-
"vsync_waiters_test.cc",
171-
"vsync_waiters_test.h",
169+
"tests/canvas_spy_unittests.cc",
170+
"tests/input_events_unittests.cc",
171+
"tests/persistent_cache_unittests.cc",
172+
"tests/pipeline_unittests.cc",
173+
"tests/shell_test.cc",
174+
"tests/shell_test.h",
175+
"tests/shell_test_platform_view.cc",
176+
"tests/shell_test_platform_view.h",
177+
"tests/shell_test_surface.cc",
178+
"tests/shell_test_surface.h",
179+
"tests/shell_test_surface_gl.cc",
180+
"tests/shell_test_surface_gl.h",
181+
"tests/shell_test_surface_metal.cc",
182+
"tests/shell_test_surface_metal.h",
183+
"tests/shell_test_vsync_waiter.cc",
184+
"tests/shell_test_vsync_waiter.h",
185+
"tests/shell_unittests.cc",
172186
]
173187

174188
deps = [
@@ -180,8 +194,25 @@ if (current_toolchain == host_toolchain) {
180194
"$flutter_root/lib/ui:ui",
181195
"$flutter_root/shell",
182196
"$flutter_root/testing:dart",
197+
"$flutter_root/testing:metal",
183198
"$flutter_root/testing:opengl",
184199
]
200+
201+
libs = []
202+
203+
if (shell_enable_metal) {
204+
sources += [
205+
"tests/shell_test_surface_metal_impl.h",
206+
"tests/shell_test_surface_metal_impl.mm",
207+
]
208+
209+
deps += [ "//flutter/shell/gpu:gpu_surface_metal" ]
210+
211+
libs += [
212+
"Foundation.framework",
213+
"QuartzCore.framework",
214+
]
215+
}
185216
}
186217

187218
shell_host_executable("shell_benchmarks") {

shell/common/canvas_spy_unittests.cc renamed to shell/common/tests/canvas_spy_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "canvas_spy.h"
5+
#include "flutter/shell/common/canvas_spy.h"
66
#include "gtest/gtest.h"
77
#include "third_party/skia/include/core/SkPictureRecorder.h"
88
#include "third_party/skia/include/core/SkSurface.h"

shell/common/input_events_unittests.cc renamed to shell/common/tests/input_events_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "flutter/shell/common/shell_test.h"
5+
#include "flutter/shell/common/tests/shell_test.h"
66
#include "flutter/testing/testing.h"
77

88
namespace flutter {

shell/common/persistent_cache_unittests.cc renamed to shell/common/tests/persistent_cache_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "flutter/fml/file.h"
1313
#include "flutter/fml/unique_fd.h"
1414
#include "flutter/shell/common/persistent_cache.h"
15-
#include "flutter/shell/common/shell_test.h"
1615
#include "flutter/shell/common/switches.h"
16+
#include "flutter/shell/common/tests/shell_test.h"
1717
#include "flutter/testing/testing.h"
1818
#include "include/core/SkPicture.h"
1919

File renamed without changes.

shell/common/shell_test.cc renamed to shell/common/tests/shell_test.cc

Lines changed: 55 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44

55
#define FML_USED_ON_EMBEDDER
66

7-
#include "flutter/shell/common/shell_test.h"
7+
#include "flutter/shell/common/tests/shell_test.h"
88

9-
#include "flutter/flow/layers/layer_tree.h"
109
#include "flutter/flow/layers/transform_layer.h"
11-
#include "flutter/fml/make_copyable.h"
12-
#include "flutter/fml/mapping.h"
13-
#include "flutter/runtime/dart_vm.h"
10+
#include "flutter/shell/common/tests/shell_test_platform_view.h"
1411
#include "flutter/shell/common/vsync_waiter_fallback.h"
15-
#include "flutter/shell/gpu/gpu_surface_gl.h"
16-
#include "flutter/testing/testing.h"
1712

1813
namespace flutter {
1914
namespace testing {
@@ -250,35 +245,66 @@ TaskRunners ShellTest::GetTaskRunnersForFixture() {
250245
};
251246
}
252247

248+
static std::unique_ptr<Shell> CreateTestShell(
249+
Settings settings,
250+
TaskRunners task_runners,
251+
bool simulate_vsync,
252+
ShellTestSurface::ClientRenderingAPI api) {
253+
auto vsync_clock = std::make_shared<ShellTestVsyncClock>();
254+
CreateVsyncWaiter on_create_vsync_waiter = [&]() {
255+
std::unique_ptr<VsyncWaiter> waiter;
256+
if (simulate_vsync) {
257+
waiter =
258+
std::make_unique<ShellTestVsyncWaiter>(task_runners, vsync_clock);
259+
} else {
260+
waiter = std::make_unique<VsyncWaiterFallback>(task_runners);
261+
}
262+
return waiter;
263+
};
264+
265+
Shell::CreateCallback<PlatformView> on_create_platform_view =
266+
[&](Shell& shell) {
267+
return std::make_unique<ShellTestPlatformView>(
268+
shell, shell.GetTaskRunners(), vsync_clock, on_create_vsync_waiter,
269+
api);
270+
};
271+
272+
Shell::CreateCallback<Rasterizer> on_create_rasterizer = [](Shell& shell) {
273+
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
274+
};
275+
276+
return Shell::Create(task_runners, //
277+
settings, //
278+
on_create_platform_view, //
279+
on_create_rasterizer //
280+
);
281+
}
282+
283+
std::unique_ptr<Shell> ShellTest::CreateShell(
284+
Settings settings,
285+
ShellTestSurface::ClientRenderingAPI api) {
286+
return CreateTestShell(settings, GetTaskRunnersForFixture(), false, api);
287+
}
288+
253289
std::unique_ptr<Shell> ShellTest::CreateShell(Settings settings,
254290
bool simulate_vsync) {
255-
return CreateShell(std::move(settings), GetTaskRunnersForFixture(),
256-
simulate_vsync);
291+
return CreateTestShell(
292+
settings, //
293+
GetTaskRunnersForFixture(), //
294+
simulate_vsync, //
295+
ShellTestSurface::ClientRenderingAPI::kClientRenderingAPIOpenGL //
296+
);
257297
}
258298

259299
std::unique_ptr<Shell> ShellTest::CreateShell(Settings settings,
260300
TaskRunners task_runners,
261301
bool simulate_vsync) {
262-
const auto vsync_clock = std::make_shared<ShellTestVsyncClock>();
263-
CreateVsyncWaiter create_vsync_waiter = [&]() {
264-
if (simulate_vsync) {
265-
return static_cast<std::unique_ptr<VsyncWaiter>>(
266-
std::make_unique<ShellTestVsyncWaiter>(task_runners, vsync_clock));
267-
} else {
268-
return static_cast<std::unique_ptr<VsyncWaiter>>(
269-
std::make_unique<VsyncWaiterFallback>(task_runners));
270-
}
271-
};
272-
return Shell::Create(
273-
task_runners, settings,
274-
[vsync_clock, &create_vsync_waiter](Shell& shell) {
275-
return std::make_unique<ShellTestPlatformView>(
276-
shell, shell.GetTaskRunners(), vsync_clock,
277-
std::move(create_vsync_waiter));
278-
},
279-
[](Shell& shell) {
280-
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
281-
});
302+
return CreateTestShell(
303+
settings, //
304+
task_runners, //
305+
simulate_vsync, //
306+
ShellTestSurface::ClientRenderingAPI::kClientRenderingAPIOpenGL //
307+
);
282308
}
283309

284310
void ShellTest::DestroyShell(std::unique_ptr<Shell> shell) {
@@ -301,70 +327,5 @@ void ShellTest::AddNativeCallback(std::string name,
301327
native_resolver_->AddNativeCallback(std::move(name), callback);
302328
}
303329

304-
ShellTestPlatformView::ShellTestPlatformView(
305-
PlatformView::Delegate& delegate,
306-
TaskRunners task_runners,
307-
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
308-
CreateVsyncWaiter create_vsync_waiter)
309-
: PlatformView(delegate, std::move(task_runners)),
310-
gl_surface_(SkISize::Make(800, 600)),
311-
create_vsync_waiter_(std::move(create_vsync_waiter)),
312-
vsync_clock_(vsync_clock) {}
313-
314-
ShellTestPlatformView::~ShellTestPlatformView() = default;
315-
316-
std::unique_ptr<VsyncWaiter> ShellTestPlatformView::CreateVSyncWaiter() {
317-
return create_vsync_waiter_();
318-
}
319-
320-
void ShellTestPlatformView::SimulateVSync() {
321-
vsync_clock_->SimulateVSync();
322-
}
323-
324-
// |PlatformView|
325-
std::unique_ptr<Surface> ShellTestPlatformView::CreateRenderingSurface() {
326-
return std::make_unique<GPUSurfaceGL>(this, true);
327-
}
328-
329-
// |PlatformView|
330-
PointerDataDispatcherMaker ShellTestPlatformView::GetDispatcherMaker() {
331-
return [](DefaultPointerDataDispatcher::Delegate& delegate) {
332-
return std::make_unique<SmoothPointerDataDispatcher>(delegate);
333-
};
334-
}
335-
336-
// |GPUSurfaceGLDelegate|
337-
bool ShellTestPlatformView::GLContextMakeCurrent() {
338-
return gl_surface_.MakeCurrent();
339-
}
340-
341-
// |GPUSurfaceGLDelegate|
342-
bool ShellTestPlatformView::GLContextClearCurrent() {
343-
return gl_surface_.ClearCurrent();
344-
}
345-
346-
// |GPUSurfaceGLDelegate|
347-
bool ShellTestPlatformView::GLContextPresent() {
348-
return gl_surface_.Present();
349-
}
350-
351-
// |GPUSurfaceGLDelegate|
352-
intptr_t ShellTestPlatformView::GLContextFBO() const {
353-
return gl_surface_.GetFramebuffer();
354-
}
355-
356-
// |GPUSurfaceGLDelegate|
357-
GPUSurfaceGLDelegate::GLProcResolver ShellTestPlatformView::GetGLProcResolver()
358-
const {
359-
return [surface = &gl_surface_](const char* name) -> void* {
360-
return surface->GetProcAddress(name);
361-
};
362-
}
363-
364-
// |GPUSurfaceGLDelegate|
365-
ExternalViewEmbedder* ShellTestPlatformView::GetExternalViewEmbedder() {
366-
return nullptr;
367-
}
368-
369330
} // namespace testing
370331
} // namespace flutter

0 commit comments

Comments
 (0)