mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Refactor ShellTest to allow for different ShellTestPlatformViews (#15972)
This paves the way for us to have shell_unittests backed by different rendering APIs (e.g. OpenGL, Vulkan, Metal).
This commit is contained in:
parent
f43097215c
commit
abdf4bde63
@ -570,6 +570,10 @@ FILE: ../../../flutter/shell/common/shell_io_manager.cc
|
||||
FILE: ../../../flutter/shell/common/shell_io_manager.h
|
||||
FILE: ../../../flutter/shell/common/shell_test.cc
|
||||
FILE: ../../../flutter/shell/common/shell_test.h
|
||||
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_unittests.cc
|
||||
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc
|
||||
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.h
|
||||
|
||||
@ -166,6 +166,10 @@ if (current_toolchain == host_toolchain) {
|
||||
"pipeline_unittests.cc",
|
||||
"shell_test.cc",
|
||||
"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",
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include "flutter/shell/common/animator.h"
|
||||
#include "flutter/shell/common/shell_test.h"
|
||||
#include "flutter/shell/common/shell_test_platform_view.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -51,9 +52,9 @@ TEST_F(ShellTest, VSyncTargetTime) {
|
||||
shell = Shell::Create(
|
||||
task_runners, settings,
|
||||
[vsync_clock, &create_vsync_waiter](Shell& shell) {
|
||||
return std::make_unique<ShellTestPlatformView>(
|
||||
shell, shell.GetTaskRunners(), vsync_clock,
|
||||
std::move(create_vsync_waiter));
|
||||
return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(),
|
||||
vsync_clock,
|
||||
std::move(create_vsync_waiter));
|
||||
},
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#define FML_USED_ON_EMBEDDER
|
||||
|
||||
#include "flutter/shell/common/shell_test.h"
|
||||
#include "flutter/shell/common/shell_test_platform_view.h"
|
||||
|
||||
#include "flutter/flow/layers/layer_tree.h"
|
||||
#include "flutter/flow/layers/transform_layer.h"
|
||||
@ -12,7 +13,6 @@
|
||||
#include "flutter/fml/mapping.h"
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
#include "flutter/shell/common/vsync_waiter_fallback.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_gl.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
|
||||
namespace flutter {
|
||||
@ -272,9 +272,9 @@ std::unique_ptr<Shell> ShellTest::CreateShell(Settings settings,
|
||||
return Shell::Create(
|
||||
task_runners, settings,
|
||||
[vsync_clock, &create_vsync_waiter](Shell& shell) {
|
||||
return std::make_unique<ShellTestPlatformView>(
|
||||
shell, shell.GetTaskRunners(), vsync_clock,
|
||||
std::move(create_vsync_waiter));
|
||||
return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(),
|
||||
vsync_clock,
|
||||
std::move(create_vsync_waiter));
|
||||
},
|
||||
[](Shell& shell) {
|
||||
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
|
||||
@ -301,70 +301,5 @@ void ShellTest::AddNativeCallback(std::string name,
|
||||
native_resolver_->AddNativeCallback(std::move(name), callback);
|
||||
}
|
||||
|
||||
ShellTestPlatformView::ShellTestPlatformView(
|
||||
PlatformView::Delegate& delegate,
|
||||
TaskRunners task_runners,
|
||||
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
|
||||
CreateVsyncWaiter create_vsync_waiter)
|
||||
: PlatformView(delegate, std::move(task_runners)),
|
||||
gl_surface_(SkISize::Make(800, 600)),
|
||||
create_vsync_waiter_(std::move(create_vsync_waiter)),
|
||||
vsync_clock_(vsync_clock) {}
|
||||
|
||||
ShellTestPlatformView::~ShellTestPlatformView() = default;
|
||||
|
||||
std::unique_ptr<VsyncWaiter> ShellTestPlatformView::CreateVSyncWaiter() {
|
||||
return create_vsync_waiter_();
|
||||
}
|
||||
|
||||
void ShellTestPlatformView::SimulateVSync() {
|
||||
vsync_clock_->SimulateVSync();
|
||||
}
|
||||
|
||||
// |PlatformView|
|
||||
std::unique_ptr<Surface> ShellTestPlatformView::CreateRenderingSurface() {
|
||||
return std::make_unique<GPUSurfaceGL>(this, true);
|
||||
}
|
||||
|
||||
// |PlatformView|
|
||||
PointerDataDispatcherMaker ShellTestPlatformView::GetDispatcherMaker() {
|
||||
return [](DefaultPointerDataDispatcher::Delegate& delegate) {
|
||||
return std::make_unique<SmoothPointerDataDispatcher>(delegate);
|
||||
};
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool ShellTestPlatformView::GLContextMakeCurrent() {
|
||||
return gl_surface_.MakeCurrent();
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool ShellTestPlatformView::GLContextClearCurrent() {
|
||||
return gl_surface_.ClearCurrent();
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool ShellTestPlatformView::GLContextPresent() {
|
||||
return gl_surface_.Present();
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
intptr_t ShellTestPlatformView::GLContextFBO() const {
|
||||
return gl_surface_.GetFramebuffer();
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
GPUSurfaceGLDelegate::GLProcResolver ShellTestPlatformView::GetGLProcResolver()
|
||||
const {
|
||||
return [surface = &gl_surface_](const char* name) -> void* {
|
||||
return surface->GetProcAddress(name);
|
||||
};
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
ExternalViewEmbedder* ShellTestPlatformView::GetExternalViewEmbedder() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
@ -9,15 +9,14 @@
|
||||
|
||||
#include "flutter/common/settings.h"
|
||||
#include "flutter/flow/layers/container_layer.h"
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/lib/ui/window/platform_message.h"
|
||||
#include "flutter/shell/common/run_configuration.h"
|
||||
#include "flutter/shell/common/shell.h"
|
||||
#include "flutter/shell/common/thread_host.h"
|
||||
#include "flutter/shell/common/vsync_waiters_test.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
|
||||
#include "flutter/testing/test_dart_native_resolver.h"
|
||||
#include "flutter/testing/test_gl_surface.h"
|
||||
#include "flutter/testing/thread_test.h"
|
||||
|
||||
namespace flutter {
|
||||
@ -89,54 +88,6 @@ class ShellTest : public ThreadTest {
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShellTest);
|
||||
};
|
||||
|
||||
class ShellTestPlatformView : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
public:
|
||||
ShellTestPlatformView(PlatformView::Delegate& delegate,
|
||||
TaskRunners task_runners,
|
||||
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
|
||||
CreateVsyncWaiter create_vsync_waiter);
|
||||
|
||||
~ShellTestPlatformView() override;
|
||||
|
||||
void SimulateVSync();
|
||||
|
||||
private:
|
||||
TestGLSurface gl_surface_;
|
||||
|
||||
CreateVsyncWaiter create_vsync_waiter_;
|
||||
|
||||
std::shared_ptr<ShellTestVsyncClock> vsync_clock_;
|
||||
|
||||
// |PlatformView|
|
||||
std::unique_ptr<Surface> CreateRenderingSurface() override;
|
||||
|
||||
// |PlatformView|
|
||||
std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
|
||||
|
||||
// |PlatformView|
|
||||
PointerDataDispatcherMaker GetDispatcherMaker() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextMakeCurrent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextClearCurrent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextPresent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
intptr_t GLContextFBO() const override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
GLProcResolver GetGLProcResolver() const override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
ExternalViewEmbedder* GetExternalViewEmbedder() override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView);
|
||||
};
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
|
||||
21
shell/common/shell_test_platform_view.cc
Normal file
21
shell/common/shell_test_platform_view.cc
Normal file
@ -0,0 +1,21 @@
|
||||
// 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.h"
|
||||
#include "flutter/shell/common/shell_test_platform_view_gl.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
35
shell/common/shell_test_platform_view.h
Normal file
35
shell/common/shell_test_platform_view.h
Normal file
@ -0,0 +1,35 @@
|
||||
// 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_H_
|
||||
#define FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_H_
|
||||
|
||||
#include "flutter/shell/common/platform_view.h"
|
||||
#include "flutter/shell/common/vsync_waiters_test.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
class ShellTestPlatformView : public PlatformView {
|
||||
public:
|
||||
static std::unique_ptr<ShellTestPlatformView> Create(
|
||||
PlatformView::Delegate& delegate,
|
||||
TaskRunners task_runners,
|
||||
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
|
||||
CreateVsyncWaiter create_vsync_waiter);
|
||||
|
||||
virtual void SimulateVSync() = 0;
|
||||
|
||||
protected:
|
||||
ShellTestPlatformView(PlatformView::Delegate& delegate,
|
||||
TaskRunners task_runners)
|
||||
: PlatformView(delegate, task_runners) {}
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView);
|
||||
};
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_GL_H_
|
||||
77
shell/common/shell_test_platform_view_gl.cc
Normal file
77
shell/common/shell_test_platform_view_gl.cc
Normal file
@ -0,0 +1,77 @@
|
||||
// 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_gl.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_gl.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
ShellTestPlatformViewGL::ShellTestPlatformViewGL(
|
||||
PlatformView::Delegate& delegate,
|
||||
TaskRunners task_runners,
|
||||
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
|
||||
CreateVsyncWaiter create_vsync_waiter)
|
||||
: ShellTestPlatformView(delegate, std::move(task_runners)),
|
||||
gl_surface_(SkISize::Make(800, 600)),
|
||||
create_vsync_waiter_(std::move(create_vsync_waiter)),
|
||||
vsync_clock_(vsync_clock) {}
|
||||
|
||||
ShellTestPlatformViewGL::~ShellTestPlatformViewGL() = default;
|
||||
|
||||
std::unique_ptr<VsyncWaiter> ShellTestPlatformViewGL::CreateVSyncWaiter() {
|
||||
return create_vsync_waiter_();
|
||||
}
|
||||
|
||||
void ShellTestPlatformViewGL::SimulateVSync() {
|
||||
vsync_clock_->SimulateVSync();
|
||||
}
|
||||
|
||||
// |PlatformView|
|
||||
std::unique_ptr<Surface> ShellTestPlatformViewGL::CreateRenderingSurface() {
|
||||
return std::make_unique<GPUSurfaceGL>(this, true);
|
||||
}
|
||||
|
||||
// |PlatformView|
|
||||
PointerDataDispatcherMaker ShellTestPlatformViewGL::GetDispatcherMaker() {
|
||||
return [](DefaultPointerDataDispatcher::Delegate& delegate) {
|
||||
return std::make_unique<SmoothPointerDataDispatcher>(delegate);
|
||||
};
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool ShellTestPlatformViewGL::GLContextMakeCurrent() {
|
||||
return gl_surface_.MakeCurrent();
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool ShellTestPlatformViewGL::GLContextClearCurrent() {
|
||||
return gl_surface_.ClearCurrent();
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool ShellTestPlatformViewGL::GLContextPresent() {
|
||||
return gl_surface_.Present();
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
intptr_t ShellTestPlatformViewGL::GLContextFBO() const {
|
||||
return gl_surface_.GetFramebuffer();
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
GPUSurfaceGLDelegate::GLProcResolver
|
||||
ShellTestPlatformViewGL::GetGLProcResolver() const {
|
||||
return [surface = &gl_surface_](const char* name) -> void* {
|
||||
return surface->GetProcAddress(name);
|
||||
};
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
ExternalViewEmbedder* ShellTestPlatformViewGL::GetExternalViewEmbedder() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
67
shell/common/shell_test_platform_view_gl.h
Normal file
67
shell/common/shell_test_platform_view_gl.h
Normal file
@ -0,0 +1,67 @@
|
||||
// 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_GL_H_
|
||||
#define FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_GL_H_
|
||||
|
||||
#include "flutter/shell/common/shell_test_platform_view.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
|
||||
#include "flutter/testing/test_gl_surface.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
class ShellTestPlatformViewGL : public ShellTestPlatformView,
|
||||
public GPUSurfaceGLDelegate {
|
||||
public:
|
||||
ShellTestPlatformViewGL(PlatformView::Delegate& delegate,
|
||||
TaskRunners task_runners,
|
||||
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
|
||||
CreateVsyncWaiter create_vsync_waiter);
|
||||
|
||||
virtual ~ShellTestPlatformViewGL() override;
|
||||
|
||||
virtual void SimulateVSync() override;
|
||||
|
||||
private:
|
||||
TestGLSurface gl_surface_;
|
||||
|
||||
CreateVsyncWaiter create_vsync_waiter_;
|
||||
|
||||
std::shared_ptr<ShellTestVsyncClock> vsync_clock_;
|
||||
|
||||
// |PlatformView|
|
||||
std::unique_ptr<Surface> CreateRenderingSurface() override;
|
||||
|
||||
// |PlatformView|
|
||||
std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
|
||||
|
||||
// |PlatformView|
|
||||
PointerDataDispatcherMaker GetDispatcherMaker() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextMakeCurrent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextClearCurrent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextPresent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
intptr_t GLContextFBO() const override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
GLProcResolver GetGLProcResolver() const override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
ExternalViewEmbedder* GetExternalViewEmbedder() override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformViewGL);
|
||||
};
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_GL_H_
|
||||
@ -22,6 +22,7 @@
|
||||
#include "flutter/shell/common/platform_view.h"
|
||||
#include "flutter/shell/common/rasterizer.h"
|
||||
#include "flutter/shell/common/shell_test.h"
|
||||
#include "flutter/shell/common/shell_test_platform_view.h"
|
||||
#include "flutter/shell/common/switches.h"
|
||||
#include "flutter/shell/common/thread_host.h"
|
||||
#include "flutter/shell/common/vsync_waiter_fallback.h"
|
||||
@ -129,7 +130,7 @@ TEST_F(ShellTest,
|
||||
// This is unused in the platform view as we are not using the simulated
|
||||
// vsync mechanism. We should have better DI in the tests.
|
||||
const auto vsync_clock = std::make_shared<ShellTestVsyncClock>();
|
||||
return std::make_unique<ShellTestPlatformView>(
|
||||
return ShellTestPlatformView::Create(
|
||||
shell, shell.GetTaskRunners(), vsync_clock,
|
||||
[task_runners = shell.GetTaskRunners()]() {
|
||||
return static_cast<std::unique_ptr<VsyncWaiter>>(
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
#include "flutter/fml/make_copyable.h"
|
||||
#include "flutter/fml/mapping.h"
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_gl.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user