[Impeller] Don't make playgrounds implicitly be test fixtures. (flutter/engine#34957)

This commit is contained in:
Chinmay Garde
2022-07-27 17:39:04 -07:00
committed by GitHub
parent 1b6c21d5c1
commit 06e5813871
21 changed files with 154 additions and 76 deletions

2
DEPS
View File

@@ -102,7 +102,7 @@ allowed_hosts = [
]
deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'fd6e9d332eed84b2a9d2a0f790c24089bbc0a093',
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'cd444824e34d8f735a351f680776bc0479f20677',
# Fuchsia compatibility
#

View File

@@ -41,7 +41,7 @@ impeller_component("aiks_unittests") {
deps = [
":aiks",
"../geometry:geometry_unittests",
"../playground",
"../playground:playground_test",
"//flutter/testing",
]
}

View File

@@ -7,11 +7,11 @@
#include "flutter/fml/macros.h"
#include "impeller/aiks/aiks_context.h"
#include "impeller/aiks/picture.h"
#include "impeller/playground/playground.h"
#include "impeller/playground/playground_test.h"
namespace impeller {
class AiksPlayground : public Playground {
class AiksPlayground : public PlaygroundTest {
public:
using AiksPlaygroundCallback =
std::function<bool(AiksContext& renderer, RenderTarget& render_target)>;

View File

@@ -31,6 +31,6 @@ impeller_component("display_list_unittests") {
deps = [
":display_list",
"../playground",
"../playground:playground_test",
]
}

View File

@@ -7,12 +7,12 @@
#include "flutter/display_list/display_list.h"
#include "flutter/display_list/display_list_builder.h"
#include "flutter/fml/macros.h"
#include "impeller/playground/playground.h"
#include "impeller/playground/playground_test.h"
#include "third_party/skia/include/core/SkFont.h"
namespace impeller {
class DisplayListPlayground : public Playground {
class DisplayListPlayground : public PlaygroundTest {
public:
using DisplayListPlaygroundCallback =
std::function<sk_sp<flutter::DisplayList>()>;

View File

@@ -8,12 +8,6 @@
#include "display_list/display_list_image_filter.h"
#include "display_list/display_list_paint.h"
#include "display_list/display_list_tile_mode.h"
#include "gtest/gtest.h"
#include "third_party/imgui/imgui.h"
#include "third_party/skia/include/core/SkClipOp.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPathBuilder.h"
#include "flutter/display_list/display_list_builder.h"
#include "flutter/display_list/display_list_mask_filter.h"
#include "flutter/display_list/types.h"
@@ -22,6 +16,10 @@
#include "impeller/display_list/display_list_playground.h"
#include "impeller/geometry/point.h"
#include "impeller/playground/widgets.h"
#include "third_party/imgui/imgui.h"
#include "third_party/skia/include/core/SkClipOp.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPathBuilder.h"
namespace impeller {
namespace testing {

View File

@@ -121,6 +121,6 @@ impeller_component("entity_unittests") {
deps = [
":entity",
"../geometry:geometry_unittests",
"../playground",
"../playground:playground_test",
]
}

View File

@@ -7,11 +7,11 @@
#include "flutter/fml/macros.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/entity.h"
#include "impeller/playground/playground.h"
#include "impeller/playground/playground_test.h"
namespace impeller {
class EntityPlayground : public Playground {
class EntityPlayground : public PlaygroundTest {
public:
using EntityPlaygroundCallback =
std::function<bool(ContentContext& context, RenderPass& pass)>;

View File

@@ -6,8 +6,6 @@ import("//flutter/impeller/tools/impeller.gni")
import("//flutter/testing/testing.gni")
impeller_component("playground") {
testonly = true
sources = [
"playground.cc",
"playground.h",
@@ -45,7 +43,7 @@ impeller_component("playground") {
"../fixtures:shader_fixtures",
"../renderer",
"imgui:imgui_impeller_backend",
"//flutter/testing",
"//flutter/fml",
"//third_party/glfw",
"//third_party/imgui:imgui_glfw",
]
@@ -60,6 +58,20 @@ impeller_component("playground") {
}
}
impeller_component("playground_test") {
testonly = true
sources = [
"playground_test.cc",
"playground_test.h",
]
public_deps = [
":playground",
"//flutter/testing",
]
}
config("playground_config") {
if (impeller_enable_playground) {
defines = [ "IMPELLER_ENABLE_PLAYGROUND" ]

View File

@@ -12,9 +12,7 @@ impeller_shaders("imgui_shaders") {
]
}
source_set("imgui_impeller_backend") {
testonly = true
impeller_component("imgui_impeller_backend") {
public_deps = [
":imgui_shaders",
"//third_party/imgui",

View File

@@ -14,7 +14,6 @@
#include "third_party/glfw/include/GLFW/glfw3.h"
#include "flutter/fml/paths.h"
#include "flutter/testing/testing.h"
#include "impeller/base/validation.h"
#include "impeller/image/compressed_image.h"
#include "impeller/playground/imgui/imgui_impl_impeller.h"
@@ -76,15 +75,11 @@ Playground::Playground()
Playground::~Playground() = default;
PlaygroundBackend Playground::GetBackend() const {
return GetParam();
}
std::shared_ptr<Context> Playground::GetContext() const {
return renderer_ ? renderer_->GetContext() : nullptr;
}
static constexpr bool PlatformSupportsBackend(PlaygroundBackend backend) {
bool Playground::SupportsBackend(PlaygroundBackend backend) {
switch (backend) {
case PlaygroundBackend::kMetal:
#if IMPELLER_ENABLE_METAL
@@ -108,12 +103,10 @@ static constexpr bool PlatformSupportsBackend(PlaygroundBackend backend) {
FML_UNREACHABLE();
}
void Playground::SetUp() {
if (!PlatformSupportsBackend(GetBackend())) {
GTEST_SKIP_("This backend is disabled or isn't supported on this platform");
}
void Playground::SetupWindow(PlaygroundBackend backend) {
FML_CHECK(SupportsBackend(backend));
impl_ = PlaygroundImpl::Create(GetParam());
impl_ = PlaygroundImpl::Create(backend);
if (!impl_) {
return;
}
@@ -128,7 +121,7 @@ void Playground::SetUp() {
renderer_ = std::move(renderer);
}
void Playground::TearDown() {
void Playground::TeardownWindow() {
renderer_.reset();
impl_.reset();
}
@@ -143,13 +136,6 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
}
}
static std::string GetWindowTitle(const std::string& test_name) {
std::stringstream stream;
stream << "Impeller Playground for '" << test_name
<< "' (Press ESC or 'q' to quit)";
return stream.str();
}
Point Playground::GetCursorPosition() const {
return cursor_position_;
}
@@ -190,8 +176,7 @@ bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) {
if (!window) {
return false;
}
::glfwSetWindowTitle(
window, GetWindowTitle(flutter::testing::GetCurrentTestName()).c_str());
::glfwSetWindowTitle(window, GetWindowTitle().c_str());
::glfwSetWindowUserPointer(window, this);
::glfwSetWindowSizeCallback(
window, [](GLFWwindow* window, int width, int height) -> void {
@@ -309,12 +294,12 @@ bool Playground::OpenPlaygroundHere(SinglePassCallback pass_callback) {
std::optional<DecompressedImage> Playground::LoadFixtureImageRGBA(
const char* fixture_name) const {
if (!renderer_) {
if (!renderer_ || fixture_name == nullptr) {
return std::nullopt;
}
auto compressed_image = CompressedImage::Create(
flutter::testing::OpenFixtureAsMapping(fixture_name));
auto compressed_image =
CompressedImage::Create(OpenAssetAsMapping(fixture_name));
if (!compressed_image) {
VALIDATION_LOG << "Could not create compressed image.";
return std::nullopt;

View File

@@ -8,7 +8,6 @@
#include "flutter/fml/closure.h"
#include "flutter/fml/macros.h"
#include "gtest/gtest.h"
#include "impeller/geometry/point.h"
#include "impeller/renderer/renderer.h"
#include "impeller/renderer/texture.h"
@@ -25,21 +24,19 @@ enum class PlaygroundBackend {
std::string PlaygroundBackendToString(PlaygroundBackend backend);
class Playground : public ::testing::TestWithParam<PlaygroundBackend> {
class Playground {
public:
using SinglePassCallback = std::function<bool(RenderPass& pass)>;
Playground();
explicit Playground();
~Playground();
virtual ~Playground();
static constexpr bool is_enabled() { return is_enabled_; }
void SetUp() override;
void SetupWindow(PlaygroundBackend backend);
void TearDown() override;
PlaygroundBackend GetBackend() const;
void TeardownWindow();
Point GetCursorPosition() const;
@@ -63,6 +60,13 @@ class Playground : public ::testing::TestWithParam<PlaygroundBackend> {
std::shared_ptr<Texture> CreateTextureCubeForFixture(
std::array<const char*, 6> fixture_names) const;
static bool SupportsBackend(PlaygroundBackend backend);
virtual std::unique_ptr<fml::Mapping> OpenAssetAsMapping(
std::string asset_name) const = 0;
virtual std::string GetWindowTitle() const = 0;
private:
#if IMPELLER_ENABLE_PLAYGROUND
static const bool is_enabled_ = true;
@@ -84,14 +88,4 @@ class Playground : public ::testing::TestWithParam<PlaygroundBackend> {
FML_DISALLOW_COPY_AND_ASSIGN(Playground);
};
#define INSTANTIATE_PLAYGROUND_SUITE(playground) \
INSTANTIATE_TEST_SUITE_P( \
Play, playground, \
::testing::Values(PlaygroundBackend::kMetal, \
PlaygroundBackend::kOpenGLES, \
PlaygroundBackend::kVulkan), \
[](const ::testing::TestParamInfo<Playground::ParamType>& info) { \
return PlaygroundBackendToString(info.param); \
});
} // namespace impeller

View File

@@ -0,0 +1,44 @@
// 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 "impeller/playground/playground_test.h"
namespace impeller {
PlaygroundTest::PlaygroundTest() = default;
PlaygroundTest::~PlaygroundTest() = default;
void PlaygroundTest::SetUp() {
if (!Playground::SupportsBackend(GetParam())) {
GTEST_SKIP_("Playground doesn't support this backend type.");
return;
}
SetupWindow(GetParam());
}
void PlaygroundTest::TearDown() {
TeardownWindow();
}
// |Playground|
std::unique_ptr<fml::Mapping> PlaygroundTest::OpenAssetAsMapping(
std::string asset_name) const {
return flutter::testing::OpenFixtureAsMapping(asset_name);
}
static std::string FormatWindowTitle(const std::string& test_name) {
std::stringstream stream;
stream << "Impeller Playground for '" << test_name
<< "' (Press ESC or 'q' to quit)";
return stream.str();
}
// |Playground|
std::string PlaygroundTest::GetWindowTitle() const {
return FormatWindowTitle(flutter::testing::GetCurrentTestName());
}
} // namespace impeller

View File

@@ -0,0 +1,47 @@
// 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.
#pragma once
#include <memory>
#include "flutter/fml/macros.h"
#include "flutter/testing/testing.h"
#include "impeller/playground/playground.h"
namespace impeller {
class PlaygroundTest : public Playground,
public ::testing::TestWithParam<PlaygroundBackend> {
public:
PlaygroundTest();
virtual ~PlaygroundTest();
void SetUp() override;
void TearDown() override;
// |Playground|
std::unique_ptr<fml::Mapping> OpenAssetAsMapping(
std::string asset_name) const override;
// |Playground|
std::string GetWindowTitle() const override;
private:
FML_DISALLOW_COPY_AND_ASSIGN(PlaygroundTest);
};
#define INSTANTIATE_PLAYGROUND_SUITE(playground) \
INSTANTIATE_TEST_SUITE_P( \
Play, playground, \
::testing::Values(PlaygroundBackend::kMetal, \
PlaygroundBackend::kOpenGLES, \
PlaygroundBackend::kVulkan), \
[](const ::testing::TestParamInfo<PlaygroundTest::ParamType>& info) { \
return PlaygroundBackendToString(info.param); \
});
} // namespace impeller

View File

@@ -98,7 +98,7 @@ impeller_component("renderer_unittests") {
deps = [
":renderer",
"../fixtures",
"../playground",
"../playground:playground_test",
"//flutter/testing:testing_lib",
]
}

View File

@@ -20,7 +20,7 @@
#include "impeller/geometry/path_builder.h"
#include "impeller/image/compressed_image.h"
#include "impeller/image/decompressed_image.h"
#include "impeller/playground/playground.h"
#include "impeller/playground/playground_test.h"
#include "impeller/renderer/command.h"
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/formats.h"
@@ -38,7 +38,7 @@
namespace impeller {
namespace testing {
using RendererTest = Playground;
using RendererTest = PlaygroundTest;
INSTANTIATE_PLAYGROUND_SUITE(RendererTest);
TEST_P(RendererTest, CanCreateBoxPrimitive) {
@@ -384,7 +384,7 @@ TEST_P(RendererTest, CanRenderToTexture) {
#if IMPELLER_ENABLE_METAL
TEST_P(RendererTest, CanRenderInstanced) {
if (GetBackend() != PlaygroundBackend::kMetal) {
if (GetParam() != PlaygroundBackend::kMetal) {
GTEST_SKIP_("Instancing is only supported on Metal.");
}
using VS = InstancedDrawVertexShader;

View File

@@ -39,7 +39,7 @@ impeller_component("runtime_stage_unittests") {
]
deps = [
":runtime_stage",
"../playground",
"../playground:playground_test",
"//flutter/testing",
]
}

View File

@@ -5,12 +5,12 @@
#pragma once
#include "flutter/fml/macros.h"
#include "impeller/playground/playground.h"
#include "impeller/playground/playground_test.h"
#include "impeller/runtime_stage/runtime_stage.h"
namespace impeller {
class RuntimeStagePlayground : public Playground {
class RuntimeStagePlayground : public PlaygroundTest {
public:
RuntimeStagePlayground();

View File

@@ -186,7 +186,7 @@ TEST(RuntimeStageTest, CanReadUniforms) {
}
TEST_P(RuntimeStageTest, CanRegisterStage) {
if (GetBackend() != PlaygroundBackend::kMetal) {
if (GetParam() != PlaygroundBackend::kMetal) {
GTEST_SKIP_("Skipped: https://github.com/flutter/flutter/issues/105538");
}
auto fixture =
@@ -212,7 +212,7 @@ TEST_P(RuntimeStageTest, CanRegisterStage) {
}
TEST_P(RuntimeStageTest, CanCreatePipelineFromRuntimeStage) {
if (GetBackend() != PlaygroundBackend::kMetal) {
if (GetParam() != PlaygroundBackend::kMetal) {
GTEST_SKIP_("Skipped: https://github.com/flutter/flutter/issues/105538");
}
auto stage = CreateStageFromFixture("ink_sparkle.frag.iplr");

View File

@@ -49,6 +49,6 @@ impeller_component("typographer_unittests") {
deps = [
":typographer",
"../playground",
"../playground:playground_test",
]
}

View File

@@ -3,7 +3,7 @@
// found in the LICENSE file.
#include "flutter/testing/testing.h"
#include "impeller/playground/playground.h"
#include "impeller/playground/playground_test.h"
#include "impeller/typographer/backends/skia/text_frame_skia.h"
#include "impeller/typographer/backends/skia/text_render_context_skia.h"
#include "third_party/skia/include/core/SkTextBlob.h"
@@ -11,7 +11,7 @@
namespace impeller {
namespace testing {
using TypographerTest = Playground;
using TypographerTest = PlaygroundTest;
INSTANTIATE_PLAYGROUND_SUITE(TypographerTest);
TEST_P(TypographerTest, CanConvertTextBlob) {