From 8ab251bc4ce7755aa803998e470aa7b722e0b5a6 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 10 Jul 2019 11:46:45 -0700 Subject: [PATCH 1/2] Make all shell unit tests use the OpenGL rasterizer. The software backend was used earlier. --- shell/common/BUILD.gn | 3 ++- shell/common/shell_test.cc | 37 ++++++++++++++++++++++++++----------- shell/common/shell_test.h | 25 ++++++++++++++++++------- testing/test_gl_surface.cc | 4 ++-- testing/test_gl_surface.h | 4 ++-- 5 files changed, 50 insertions(+), 23 deletions(-) diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index e8375080feae3..47bef75a27a88 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -142,7 +142,7 @@ template("shell_host_executable") { shell_gpu_configuration("shell_unittests_gpu_configuration") { enable_software = true enable_vulkan = false - enable_gl = false + enable_gl = true enable_metal = false } @@ -165,6 +165,7 @@ shell_host_executable("shell_unittests") { "$flutter_root/flow", "$flutter_root/shell", "$flutter_root/testing:dart", + "$flutter_root/testing:opengl", ] } diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index 9afd64ad165f3..f34e04fdb3130 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -11,6 +11,7 @@ #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 { @@ -200,21 +201,35 @@ ShellTestPlatformView::~ShellTestPlatformView() = default; // |PlatformView| std::unique_ptr ShellTestPlatformView::CreateRenderingSurface() { - return std::make_unique(this); + return std::make_unique(this); } -// |GPUSurfaceSoftwareDelegate| -sk_sp ShellTestPlatformView::AcquireBackingStore( - const SkISize& size) { - SkImageInfo image_info = SkImageInfo::MakeN32Premul( - size.width(), size.height(), SkColorSpace::MakeSRGB()); - return SkSurface::MakeRaster(image_info); +// |GPUSurfaceGLDelegate| +bool ShellTestPlatformView::GLContextMakeCurrent() { + return gl_surface_.MakeCurrent(); } -// |GPUSurfaceSoftwareDelegate| -bool ShellTestPlatformView::PresentBackingStore( - sk_sp backing_store) { - return true; +// |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); + }; } } // namespace testing diff --git a/shell/common/shell_test.h b/shell/common/shell_test.h index 2a839b821e6e1..4a69e7e516e3a 100644 --- a/shell/common/shell_test.h +++ b/shell/common/shell_test.h @@ -12,8 +12,9 @@ #include "flutter/shell/common/run_configuration.h" #include "flutter/shell/common/shell.h" #include "flutter/shell/common/thread_host.h" -#include "flutter/shell/gpu/gpu_surface_software.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 { @@ -66,8 +67,7 @@ class ShellTest : public ThreadTest { void SetSnapshotsAndAssets(Settings& settings); }; -class ShellTestPlatformView : public PlatformView, - public GPUSurfaceSoftwareDelegate { +class ShellTestPlatformView : public PlatformView, public GPUSurfaceGLDelegate { public: ShellTestPlatformView(PlatformView::Delegate& delegate, TaskRunners task_runners); @@ -75,14 +75,25 @@ class ShellTestPlatformView : public PlatformView, ~ShellTestPlatformView() override; private: + TestGLSurface gl_surface_; + // |PlatformView| std::unique_ptr CreateRenderingSurface() override; - // |GPUSurfaceSoftwareDelegate| - virtual sk_sp AcquireBackingStore(const SkISize& size) override; + // |GPUSurfaceGLDelegate| + bool GLContextMakeCurrent() override; + + // |GPUSurfaceGLDelegate| + bool GLContextClearCurrent() override; + + // |GPUSurfaceGLDelegate| + bool GLContextPresent() override; + + // |GPUSurfaceGLDelegate| + intptr_t GLContextFBO() const override; - // |GPUSurfaceSoftwareDelegate| - virtual bool PresentBackingStore(sk_sp backing_store) override; + // |GPUSurfaceGLDelegate| + GLProcResolver GetGLProcResolver() const override; FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView); }; diff --git a/testing/test_gl_surface.cc b/testing/test_gl_surface.cc index ec8394078cef9..44a92badbc51a 100644 --- a/testing/test_gl_surface.cc +++ b/testing/test_gl_surface.cc @@ -203,7 +203,7 @@ bool TestGLSurface::Present() { return result == EGL_TRUE; } -uint32_t TestGLSurface::GetFramebuffer() { +uint32_t TestGLSurface::GetFramebuffer() const { // Return FBO0 return 0; } @@ -220,7 +220,7 @@ bool TestGLSurface::MakeResourceCurrent() { return result == EGL_TRUE; } -void* TestGLSurface::GetProcAddress(const char* name) { +void* TestGLSurface::GetProcAddress(const char* name) const { if (name == nullptr) { return nullptr; } diff --git a/testing/test_gl_surface.h b/testing/test_gl_surface.h index 3357ce56fe1bc..0351552660af3 100644 --- a/testing/test_gl_surface.h +++ b/testing/test_gl_surface.h @@ -25,11 +25,11 @@ class TestGLSurface { bool Present(); - uint32_t GetFramebuffer(); + uint32_t GetFramebuffer() const; bool MakeResourceCurrent(); - void* GetProcAddress(const char* name); + void* GetProcAddress(const char* name) const; sk_sp CreateContext(); From 964c2e0aa42dd78991b264fafb55f40f00b1c336 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 10 Jul 2019 12:10:28 -0700 Subject: [PATCH 2/2] PR --- shell/common/BUILD.gn | 72 ++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index 47bef75a27a88..135bf43ae1799 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -139,44 +139,46 @@ template("shell_host_executable") { } } -shell_gpu_configuration("shell_unittests_gpu_configuration") { - enable_software = true - enable_vulkan = false - enable_gl = true - enable_metal = false -} +if (current_toolchain == host_toolchain) { + shell_gpu_configuration("shell_unittests_gpu_configuration") { + enable_software = true + enable_vulkan = false + enable_gl = true + enable_metal = false + } -test_fixtures("shell_unittests_fixtures") { - dart_main = "fixtures/shell_test.dart" -} + test_fixtures("shell_unittests_fixtures") { + dart_main = "fixtures/shell_test.dart" + } -shell_host_executable("shell_unittests") { - sources = [ - "pipeline_unittests.cc", - "shell_test.cc", - "shell_test.h", - "shell_unittests.cc", - ] + shell_host_executable("shell_unittests") { + sources = [ + "pipeline_unittests.cc", + "shell_test.cc", + "shell_test.h", + "shell_unittests.cc", + ] - deps = [ - ":shell_unittests_fixtures", - ":shell_unittests_gpu_configuration", - "$flutter_root/common", - "$flutter_root/flow", - "$flutter_root/shell", - "$flutter_root/testing:dart", - "$flutter_root/testing:opengl", - ] -} + deps = [ + ":shell_unittests_fixtures", + ":shell_unittests_gpu_configuration", + "$flutter_root/common", + "$flutter_root/flow", + "$flutter_root/shell", + "$flutter_root/testing:dart", + "$flutter_root/testing:opengl", + ] + } -shell_host_executable("shell_benchmarks") { - sources = [ - "shell_benchmarks.cc", - ] + shell_host_executable("shell_benchmarks") { + sources = [ + "shell_benchmarks.cc", + ] - deps = [ - ":shell_unittests_fixtures", - "$flutter_root/benchmarking", - "$flutter_root/testing:testing_lib", - ] + deps = [ + ":shell_unittests_fixtures", + "$flutter_root/benchmarking", + "$flutter_root/testing:testing_lib", + ] + } }