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

Commit 539eb9a

Browse files
author
George Wright
committed
Refactor ShellTest to allow for different ShellTestPlatformViews backed
by different rendering APIs (OpenGL, Vulkan). Stub out a Vulkan implementation of ShellTestPlatformView.
1 parent 2ce15cf commit 539eb9a

12 files changed

+314
-121
lines changed

shell/common/BUILD.gn

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ if (current_toolchain == host_toolchain) {
166166
"pipeline_unittests.cc",
167167
"shell_test.cc",
168168
"shell_test.h",
169+
"shell_test_platform_view.cc",
170+
"shell_test_platform_view.h",
171+
"shell_test_platform_view_gl.cc",
172+
"shell_test_platform_view_gl.h",
173+
"shell_test_platform_view_vulkan.cc",
174+
"shell_test_platform_view_vulkan.h",
169175
"shell_unittests.cc",
170176
"vsync_waiters_test.cc",
171177
"vsync_waiters_test.h",
@@ -195,4 +201,4 @@ if (current_toolchain == host_toolchain) {
195201
"$flutter_root/testing:testing_lib",
196202
]
197203
}
198-
}
204+
}

shell/common/animator_unittests.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "flutter/shell/common/animator.h"
1212
#include "flutter/shell/common/shell_test.h"
13+
#include "flutter/shell/common/shell_test_platform_view.h"
1314
#include "flutter/testing/testing.h"
1415
#include "gtest/gtest.h"
1516

@@ -51,7 +52,7 @@ TEST_F(ShellTest, VSyncTargetTime) {
5152
shell = Shell::Create(
5253
task_runners, settings,
5354
[vsync_clock, &create_vsync_waiter](Shell& shell) {
54-
return std::make_unique<ShellTestPlatformView>(
55+
return ShellTestPlatformView::Create(
5556
shell, shell.GetTaskRunners(), vsync_clock,
5657
std::move(create_vsync_waiter));
5758
},

shell/common/shell_test.cc

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
#define FML_USED_ON_EMBEDDER
66

77
#include "flutter/shell/common/shell_test.h"
8+
#include "flutter/shell/common/shell_test_platform_view.h"
89

910
#include "flutter/flow/layers/layer_tree.h"
1011
#include "flutter/flow/layers/transform_layer.h"
1112
#include "flutter/fml/make_copyable.h"
1213
#include "flutter/fml/mapping.h"
1314
#include "flutter/runtime/dart_vm.h"
1415
#include "flutter/shell/common/vsync_waiter_fallback.h"
15-
#include "flutter/shell/gpu/gpu_surface_gl.h"
1616
#include "flutter/testing/testing.h"
1717

1818
namespace flutter {
@@ -272,7 +272,7 @@ std::unique_ptr<Shell> ShellTest::CreateShell(Settings settings,
272272
return Shell::Create(
273273
task_runners, settings,
274274
[vsync_clock, &create_vsync_waiter](Shell& shell) {
275-
return std::make_unique<ShellTestPlatformView>(
275+
return ShellTestPlatformView::Create(
276276
shell, shell.GetTaskRunners(), vsync_clock,
277277
std::move(create_vsync_waiter));
278278
},
@@ -301,70 +301,5 @@ void ShellTest::AddNativeCallback(std::string name,
301301
native_resolver_->AddNativeCallback(std::move(name), callback);
302302
}
303303

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-
369304
} // namespace testing
370305
} // namespace flutter

shell/common/shell_test.h

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99

1010
#include "flutter/common/settings.h"
1111
#include "flutter/flow/layers/container_layer.h"
12+
#include "flutter/fml/build_config.h"
1213
#include "flutter/fml/macros.h"
1314
#include "flutter/lib/ui/window/platform_message.h"
1415
#include "flutter/shell/common/run_configuration.h"
1516
#include "flutter/shell/common/shell.h"
1617
#include "flutter/shell/common/thread_host.h"
1718
#include "flutter/shell/common/vsync_waiters_test.h"
18-
#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
1919
#include "flutter/testing/test_dart_native_resolver.h"
20-
#include "flutter/testing/test_gl_surface.h"
2120
#include "flutter/testing/thread_test.h"
2221

2322
namespace flutter {
@@ -89,54 +88,6 @@ class ShellTest : public ThreadTest {
8988
FML_DISALLOW_COPY_AND_ASSIGN(ShellTest);
9089
};
9190

92-
class ShellTestPlatformView : public PlatformView, public GPUSurfaceGLDelegate {
93-
public:
94-
ShellTestPlatformView(PlatformView::Delegate& delegate,
95-
TaskRunners task_runners,
96-
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
97-
CreateVsyncWaiter create_vsync_waiter);
98-
99-
~ShellTestPlatformView() override;
100-
101-
void SimulateVSync();
102-
103-
private:
104-
TestGLSurface gl_surface_;
105-
106-
CreateVsyncWaiter create_vsync_waiter_;
107-
108-
std::shared_ptr<ShellTestVsyncClock> vsync_clock_;
109-
110-
// |PlatformView|
111-
std::unique_ptr<Surface> CreateRenderingSurface() override;
112-
113-
// |PlatformView|
114-
std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
115-
116-
// |PlatformView|
117-
PointerDataDispatcherMaker GetDispatcherMaker() override;
118-
119-
// |GPUSurfaceGLDelegate|
120-
bool GLContextMakeCurrent() override;
121-
122-
// |GPUSurfaceGLDelegate|
123-
bool GLContextClearCurrent() override;
124-
125-
// |GPUSurfaceGLDelegate|
126-
bool GLContextPresent() override;
127-
128-
// |GPUSurfaceGLDelegate|
129-
intptr_t GLContextFBO() const override;
130-
131-
// |GPUSurfaceGLDelegate|
132-
GLProcResolver GetGLProcResolver() const override;
133-
134-
// |GPUSurfaceGLDelegate|
135-
ExternalViewEmbedder* GetExternalViewEmbedder() override;
136-
137-
FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView);
138-
};
139-
14091
} // namespace testing
14192
} // namespace flutter
14293

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.h"
6+
7+
#if OS_FUCHSIA
8+
#include "flutter/shell/common/shell_test_platform_view_vulkan.h"
9+
#else
10+
#include "flutter/shell/common/shell_test_platform_view_gl.h"
11+
#endif
12+
13+
namespace flutter {
14+
namespace testing {
15+
16+
std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
17+
PlatformView::Delegate& delegate,
18+
TaskRunners task_runners,
19+
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
20+
CreateVsyncWaiter create_vsync_waiter)
21+
{
22+
#if OS_FUCHSIA
23+
return std::make_unique<ShellTestPlatformViewVulkan>(delegate,
24+
task_runners,
25+
vsync_clock,
26+
create_vsync_waiter);
27+
28+
#else
29+
return std::make_unique<ShellTestPlatformViewGL>(delegate,
30+
task_runners,
31+
vsync_clock,
32+
create_vsync_waiter);
33+
#endif
34+
}
35+
36+
37+
} // namespace testing
38+
} // namespace flutter
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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_H_
6+
#define FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_H_
7+
8+
#include "flutter/shell/common/platform_view.h"
9+
#include "flutter/shell/common/vsync_waiters_test.h"
10+
11+
namespace flutter {
12+
namespace testing {
13+
14+
class ShellTestPlatformView : public PlatformView {
15+
public:
16+
static std::unique_ptr<ShellTestPlatformView> Create(PlatformView::Delegate& delegate,
17+
TaskRunners task_runners,
18+
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
19+
CreateVsyncWaiter create_vsync_waiter);
20+
21+
virtual void SimulateVSync() = 0;
22+
23+
protected:
24+
ShellTestPlatformView(PlatformView::Delegate& delegate,
25+
TaskRunners task_runners) : PlatformView(delegate, task_runners) {}
26+
27+
FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView);
28+
};
29+
30+
} // namespace testing
31+
} // namespace flutter
32+
33+
#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_GL_H_
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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_gl.h"
6+
#include "flutter/shell/gpu/gpu_surface_gl.h"
7+
8+
namespace flutter {
9+
namespace testing {
10+
11+
ShellTestPlatformViewGL::ShellTestPlatformViewGL(
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+
gl_surface_(SkISize::Make(800, 600)),
18+
create_vsync_waiter_(std::move(create_vsync_waiter)),
19+
vsync_clock_(vsync_clock) {}
20+
21+
ShellTestPlatformViewGL::~ShellTestPlatformViewGL() = default;
22+
23+
std::unique_ptr<VsyncWaiter> ShellTestPlatformViewGL::CreateVSyncWaiter() {
24+
return create_vsync_waiter_();
25+
}
26+
27+
void ShellTestPlatformViewGL::SimulateVSync() {
28+
vsync_clock_->SimulateVSync();
29+
}
30+
31+
// |PlatformView|
32+
std::unique_ptr<Surface> ShellTestPlatformViewGL::CreateRenderingSurface() {
33+
return std::make_unique<GPUSurfaceGL>(this, true);
34+
}
35+
36+
// |PlatformView|
37+
PointerDataDispatcherMaker ShellTestPlatformViewGL::GetDispatcherMaker() {
38+
return [](DefaultPointerDataDispatcher::Delegate& delegate) {
39+
return std::make_unique<SmoothPointerDataDispatcher>(delegate);
40+
};
41+
}
42+
43+
// |GPUSurfaceGLDelegate|
44+
bool ShellTestPlatformViewGL::GLContextMakeCurrent() {
45+
return gl_surface_.MakeCurrent();
46+
}
47+
48+
// |GPUSurfaceGLDelegate|
49+
bool ShellTestPlatformViewGL::GLContextClearCurrent() {
50+
return gl_surface_.ClearCurrent();
51+
}
52+
53+
// |GPUSurfaceGLDelegate|
54+
bool ShellTestPlatformViewGL::GLContextPresent() {
55+
return gl_surface_.Present();
56+
}
57+
58+
// |GPUSurfaceGLDelegate|
59+
intptr_t ShellTestPlatformViewGL::GLContextFBO() const {
60+
return gl_surface_.GetFramebuffer();
61+
}
62+
63+
// |GPUSurfaceGLDelegate|
64+
GPUSurfaceGLDelegate::GLProcResolver ShellTestPlatformViewGL::GetGLProcResolver()
65+
const {
66+
return [surface = &gl_surface_](const char* name) -> void* {
67+
return surface->GetProcAddress(name);
68+
};
69+
}
70+
71+
// |GPUSurfaceGLDelegate|
72+
ExternalViewEmbedder* ShellTestPlatformViewGL::GetExternalViewEmbedder() {
73+
return nullptr;
74+
}
75+
76+
} // namespace testing
77+
} // namespace flutter

0 commit comments

Comments
 (0)