Skip to content

Commit

Permalink
Start wiring up the entity playground.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 2747332 commit 97455db
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 4 deletions.
6 changes: 5 additions & 1 deletion impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions impeller/entity/contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "impeller/entity/contents.h"

#include <memory>

#include "flutter/fml/logging.h"
#include "impeller/entity/content_renderer.h"
#include "impeller/entity/entity.h"
Expand Down Expand Up @@ -151,6 +153,12 @@ bool SolidColorContents::Render(const ContentRenderer& renderer,
return true;
}

std::unique_ptr<SolidColorContents> SolidColorContents::Make(Color color) {
auto contents = std::make_unique<SolidColorContents>();
contents->SetColor(color);
return contents;
}

/*******************************************************************************
******* SolidStrokeContents
******************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions impeller/entity/contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class SolidColorContents final : public Contents {

~SolidColorContents() override;

static std::unique_ptr<SolidColorContents> Make(Color color);

void SetColor(Color color);

const Color& GetColor() const;
Expand Down
28 changes: 28 additions & 0 deletions impeller/entity/entity_playground.cc
Original file line number Diff line number Diff line change
@@ -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<EntityRenderer>(GetContext());
if (!renderer_) {
return false;
}
}
Renderer::RenderCallback callback = [&](const Surface& surface,
RenderPass& pass) -> bool {
std::vector<Entity> entities = {entity};
return renderer_->RenderEntities(surface, pass, entities);
};
return Playground::OpenPlaygroundHere(callback);
}

} // namespace impeller
28 changes: 28 additions & 0 deletions impeller/entity/entity_playground.h
Original file line number Diff line number Diff line change
@@ -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<EntityRenderer> renderer_;

FML_DISALLOW_COPY_AND_ASSIGN(EntityPlayground);
};

} // namespace impeller
5 changes: 4 additions & 1 deletion impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions impeller/playground/playground.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions impeller/renderer/pipeline_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -82,7 +86,9 @@ struct PipelineBuilder {
auto vertex_descriptor = std::make_shared<VertexDescriptor>();
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));
Expand Down

0 comments on commit 97455db

Please sign in to comment.