From 97455db0f6551f7b70fd5559e108f0b00c3aef54 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Mon, 15 Nov 2021 13:02:21 -0800 Subject: [PATCH] Start wiring up the entity playground. --- impeller/entity/BUILD.gn | 6 +++++- impeller/entity/contents.cc | 8 ++++++++ impeller/entity/contents.h | 2 ++ impeller/entity/entity_playground.cc | 28 ++++++++++++++++++++++++++++ impeller/entity/entity_playground.h | 28 ++++++++++++++++++++++++++++ impeller/entity/entity_unittests.cc | 5 ++++- impeller/playground/playground.h | 2 ++ impeller/renderer/pipeline_builder.h | 10 ++++++++-- 8 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 impeller/entity/entity_playground.cc create mode 100644 impeller/entity/entity_playground.h diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index e4d368cc1ab97..0b35d51a7f6d9 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -38,7 +38,11 @@ impeller_component("entity") { impeller_component("entity_unittests") { testonly = true - sources = [ "entity_unittests.cc" ] + sources = [ + "entity_playground.cc", + "entity_playground.h", + "entity_unittests.cc", + ] deps = [ ":entity", diff --git a/impeller/entity/contents.cc b/impeller/entity/contents.cc index 7ce063119b669..3e27ea27bb1dc 100644 --- a/impeller/entity/contents.cc +++ b/impeller/entity/contents.cc @@ -4,6 +4,8 @@ #include "impeller/entity/contents.h" +#include + #include "flutter/fml/logging.h" #include "impeller/entity/content_renderer.h" #include "impeller/entity/entity.h" @@ -151,6 +153,12 @@ bool SolidColorContents::Render(const ContentRenderer& renderer, return true; } +std::unique_ptr SolidColorContents::Make(Color color) { + auto contents = std::make_unique(); + contents->SetColor(color); + return contents; +} + /******************************************************************************* ******* SolidStrokeContents ******************************************************************************/ diff --git a/impeller/entity/contents.h b/impeller/entity/contents.h index 2feedcfccf2f9..c4b8ac9c7540e 100644 --- a/impeller/entity/contents.h +++ b/impeller/entity/contents.h @@ -64,6 +64,8 @@ class SolidColorContents final : public Contents { ~SolidColorContents() override; + static std::unique_ptr Make(Color color); + void SetColor(Color color); const Color& GetColor() const; diff --git a/impeller/entity/entity_playground.cc b/impeller/entity/entity_playground.cc new file mode 100644 index 0000000000000..e643bd81488c7 --- /dev/null +++ b/impeller/entity/entity_playground.cc @@ -0,0 +1,28 @@ +// 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/entity/entity_playground.h" + +namespace impeller { + +EntityPlayground::EntityPlayground() = default; + +EntityPlayground::~EntityPlayground() = default; + +bool EntityPlayground::OpenPlaygroundHere(Entity entity) { + if (!renderer_) { + renderer_ = std::make_unique(GetContext()); + if (!renderer_) { + return false; + } + } + Renderer::RenderCallback callback = [&](const Surface& surface, + RenderPass& pass) -> bool { + std::vector entities = {entity}; + return renderer_->RenderEntities(surface, pass, entities); + }; + return Playground::OpenPlaygroundHere(callback); +} + +} // namespace impeller diff --git a/impeller/entity/entity_playground.h b/impeller/entity/entity_playground.h new file mode 100644 index 0000000000000..fdbc3c492a6c5 --- /dev/null +++ b/impeller/entity/entity_playground.h @@ -0,0 +1,28 @@ +// 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 "flutter/fml/macros.h" +#include "impeller/entity/entity.h" +#include "impeller/entity/entity_renderer.h" +#include "impeller/playground/playground.h" + +namespace impeller { + +class EntityPlayground : public Playground { + public: + EntityPlayground(); + + ~EntityPlayground(); + + bool OpenPlaygroundHere(Entity entity); + + private: + std::unique_ptr renderer_; + + FML_DISALLOW_COPY_AND_ASSIGN(EntityPlayground); +}; + +} // namespace impeller diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 9a82998fc295b..b589d979f726e 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -4,13 +4,14 @@ #include "flutter/testing/testing.h" #include "impeller/entity/entity.h" +#include "impeller/entity/entity_playground.h" #include "impeller/geometry/path_builder.h" #include "impeller/playground/playground.h" namespace impeller { namespace testing { -using EntityTest = Playground; +using EntityTest = EntityPlayground; TEST_F(EntityTest, CanCreateEntity) { Entity entity; @@ -20,6 +21,8 @@ TEST_F(EntityTest, CanCreateEntity) { TEST_F(EntityTest, CanDrawRect) { Entity entity; entity.SetPath(PathBuilder{}.AddRect({100, 100, 100, 100}).CreatePath()); + entity.SetContents(SolidColorContents::Make(Color::Red())); + ASSERT_TRUE(OpenPlaygroundHere(entity)); } } // namespace testing diff --git a/impeller/playground/playground.h b/impeller/playground/playground.h index 6e11998cda78b..1d35b1c9b07e8 100644 --- a/impeller/playground/playground.h +++ b/impeller/playground/playground.h @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#pragma once + #include "flutter/fml/closure.h" #include "flutter/fml/macros.h" #include "gtest/gtest.h" diff --git a/impeller/renderer/pipeline_builder.h b/impeller/renderer/pipeline_builder.h index 8cc488c512d7d..89a7833995ebe 100644 --- a/impeller/renderer/pipeline_builder.h +++ b/impeller/renderer/pipeline_builder.h @@ -69,7 +69,11 @@ struct PipelineBuilder { FragmentShader::kEntrypointName, ShaderStage::kFragment); if (!vertex_function || !fragment_function) { - FML_LOG(ERROR) << "Could not resolve pipeline entrypoint(s)."; + FML_LOG(ERROR) << "Could not resolve pipeline entrypoint(s) '" + << VertexShader::kEntrypointName << "' and '" + << FragmentShader::kEntrypointName + << "' for pipline named '" << VertexShader::kLabel + << "'."; return false; } @@ -82,7 +86,9 @@ struct PipelineBuilder { auto vertex_descriptor = std::make_shared(); if (!vertex_descriptor->SetStageInputs( VertexShader::kAllShaderStageInputs)) { - FML_LOG(ERROR) << "Could not configure vertex descriptor."; + FML_LOG(ERROR) + << "Could not configure vertex descriptor for pipeline named '" + << VertexShader::kLabel << "'."; return false; } desc.SetVertexDescriptor(std::move(vertex_descriptor));