From 69125a9966fb31807982950a4a55571a39c68af1 Mon Sep 17 00:00:00 2001 From: George Wright Date: Wed, 8 Jan 2020 15:14:53 -0800 Subject: [PATCH 1/4] Refactor ShellTest to allow for different ShellTestPlatformViews backed by different rendering APIs (OpenGL, Vulkan). --- shell/common/BUILD.gn | 4 ++ shell/common/animator_unittests.cc | 7 +- shell/common/shell_test.cc | 73 ++----------------- shell/common/shell_test.h | 51 +------------- shell/common/shell_test_platform_view.cc | 32 +++++++++ shell/common/shell_test_platform_view.h | 35 ++++++++++ shell/common/shell_test_platform_view_gl.cc | 77 +++++++++++++++++++++ shell/common/shell_test_platform_view_gl.h | 67 ++++++++++++++++++ shell/common/shell_unittests.cc | 3 +- shell/common/vsync_waiters_test.cc | 1 - 10 files changed, 226 insertions(+), 124 deletions(-) create mode 100644 shell/common/shell_test_platform_view.cc create mode 100644 shell/common/shell_test_platform_view.h create mode 100644 shell/common/shell_test_platform_view_gl.cc create mode 100644 shell/common/shell_test_platform_view_gl.h diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index 373a657b9205d..3dc6e37f72341 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -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", diff --git a/shell/common/animator_unittests.cc b/shell/common/animator_unittests.cc index 12e3042317a16..0932c1ab56a0c 100644 --- a/shell/common/animator_unittests.cc +++ b/shell/common/animator_unittests.cc @@ -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( - 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(shell, shell.GetTaskRunners()); diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index 2557d8ca73bed..2a9e82320a21b 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -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 ShellTest::CreateShell(Settings settings, return Shell::Create( task_runners, settings, [vsync_clock, &create_vsync_waiter](Shell& shell) { - return std::make_unique( - 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(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 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 ShellTestPlatformView::CreateVSyncWaiter() { - return create_vsync_waiter_(); -} - -void ShellTestPlatformView::SimulateVSync() { - vsync_clock_->SimulateVSync(); -} - -// |PlatformView| -std::unique_ptr ShellTestPlatformView::CreateRenderingSurface() { - return std::make_unique(this, true); -} - -// |PlatformView| -PointerDataDispatcherMaker ShellTestPlatformView::GetDispatcherMaker() { - return [](DefaultPointerDataDispatcher::Delegate& delegate) { - return std::make_unique(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 diff --git a/shell/common/shell_test.h b/shell/common/shell_test.h index ddbbc94ae1899..12b59f38ae359 100644 --- a/shell/common/shell_test.h +++ b/shell/common/shell_test.h @@ -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 vsync_clock, - CreateVsyncWaiter create_vsync_waiter); - - ~ShellTestPlatformView() override; - - void SimulateVSync(); - - private: - TestGLSurface gl_surface_; - - CreateVsyncWaiter create_vsync_waiter_; - - std::shared_ptr vsync_clock_; - - // |PlatformView| - std::unique_ptr CreateRenderingSurface() override; - - // |PlatformView| - std::unique_ptr 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 diff --git a/shell/common/shell_test_platform_view.cc b/shell/common/shell_test_platform_view.cc new file mode 100644 index 0000000000000..7eaca2ccf8773 --- /dev/null +++ b/shell/common/shell_test_platform_view.cc @@ -0,0 +1,32 @@ +// 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" + +#if OS_FUCHSIA +#include "flutter/shell/common/shell_test_platform_view_vulkan.h" +#else +#include "flutter/shell/common/shell_test_platform_view_gl.h" +#endif + +namespace flutter { +namespace testing { + +std::unique_ptr ShellTestPlatformView::Create( + PlatformView::Delegate& delegate, + TaskRunners task_runners, + std::shared_ptr vsync_clock, + CreateVsyncWaiter create_vsync_waiter) { +#if OS_FUCHSIA + return std::make_unique( + delegate, task_runners, vsync_clock, create_vsync_waiter); + +#else + return std::make_unique( + delegate, task_runners, vsync_clock, create_vsync_waiter); +#endif +} + +} // namespace testing +} // namespace flutter diff --git a/shell/common/shell_test_platform_view.h b/shell/common/shell_test_platform_view.h new file mode 100644 index 0000000000000..c53a2b4473230 --- /dev/null +++ b/shell/common/shell_test_platform_view.h @@ -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 Create( + PlatformView::Delegate& delegate, + TaskRunners task_runners, + std::shared_ptr 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_ diff --git a/shell/common/shell_test_platform_view_gl.cc b/shell/common/shell_test_platform_view_gl.cc new file mode 100644 index 0000000000000..2bd597575e523 --- /dev/null +++ b/shell/common/shell_test_platform_view_gl.cc @@ -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 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 ShellTestPlatformViewGL::CreateVSyncWaiter() { + return create_vsync_waiter_(); +} + +void ShellTestPlatformViewGL::SimulateVSync() { + vsync_clock_->SimulateVSync(); +} + +// |PlatformView| +std::unique_ptr ShellTestPlatformViewGL::CreateRenderingSurface() { + return std::make_unique(this, true); +} + +// |PlatformView| +PointerDataDispatcherMaker ShellTestPlatformViewGL::GetDispatcherMaker() { + return [](DefaultPointerDataDispatcher::Delegate& delegate) { + return std::make_unique(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 diff --git a/shell/common/shell_test_platform_view_gl.h b/shell/common/shell_test_platform_view_gl.h new file mode 100644 index 0000000000000..03db7910873e0 --- /dev/null +++ b/shell/common/shell_test_platform_view_gl.h @@ -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 vsync_clock, + CreateVsyncWaiter create_vsync_waiter); + + virtual ~ShellTestPlatformViewGL() override; + + virtual void SimulateVSync() override; + + private: + TestGLSurface gl_surface_; + + CreateVsyncWaiter create_vsync_waiter_; + + std::shared_ptr vsync_clock_; + + // |PlatformView| + std::unique_ptr CreateRenderingSurface() override; + + // |PlatformView| + std::unique_ptr 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_ diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 02b0edf6e0760..d35851d2cc3b7 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -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(); - return std::make_unique( + return ShellTestPlatformView::Create( shell, shell.GetTaskRunners(), vsync_clock, [task_runners = shell.GetTaskRunners()]() { return static_cast>( diff --git a/shell/common/vsync_waiters_test.cc b/shell/common/vsync_waiters_test.cc index b5437d0199454..762f9f58c0cac 100644 --- a/shell/common/vsync_waiters_test.cc +++ b/shell/common/vsync_waiters_test.cc @@ -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 { From ac53575fe9f91c3de63e720a248cd144868a5d9a Mon Sep 17 00:00:00 2001 From: George Wright Date: Fri, 24 Jan 2020 12:22:18 -0800 Subject: [PATCH 2/4] remove fuchsia ifdef --- shell/common/shell_test_platform_view.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/shell/common/shell_test_platform_view.cc b/shell/common/shell_test_platform_view.cc index 7eaca2ccf8773..d773cf224bb93 100644 --- a/shell/common/shell_test_platform_view.cc +++ b/shell/common/shell_test_platform_view.cc @@ -3,12 +3,7 @@ // found in the LICENSE file. #include "flutter/shell/common/shell_test_platform_view.h" - -#if OS_FUCHSIA -#include "flutter/shell/common/shell_test_platform_view_vulkan.h" -#else #include "flutter/shell/common/shell_test_platform_view_gl.h" -#endif namespace flutter { namespace testing { From 9996737eab2d71599aba1d3673cbd8518657edac Mon Sep 17 00:00:00 2001 From: George Wright Date: Fri, 24 Jan 2020 12:23:36 -0800 Subject: [PATCH 3/4] update licences file --- ci/licenses_golden/licenses_flutter | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index b6d7374267808..bc0989b5991f9 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -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 From 7acb291d070ba37904f0aaf4810acce0f68e3cc9 Mon Sep 17 00:00:00 2001 From: George Wright Date: Fri, 24 Jan 2020 12:24:54 -0800 Subject: [PATCH 4/4] another fuchsia ifdef... --- shell/common/shell_test_platform_view.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/shell/common/shell_test_platform_view.cc b/shell/common/shell_test_platform_view.cc index d773cf224bb93..694ac3eddc615 100644 --- a/shell/common/shell_test_platform_view.cc +++ b/shell/common/shell_test_platform_view.cc @@ -13,14 +13,8 @@ std::unique_ptr ShellTestPlatformView::Create( TaskRunners task_runners, std::shared_ptr vsync_clock, CreateVsyncWaiter create_vsync_waiter) { -#if OS_FUCHSIA - return std::make_unique( - delegate, task_runners, vsync_clock, create_vsync_waiter); - -#else return std::make_unique( delegate, task_runners, vsync_clock, create_vsync_waiter); -#endif } } // namespace testing