Skip to content

Commit 97455db

Browse files
chinmaygardednfield
authored andcommitted
Start wiring up the entity playground.
1 parent 2747332 commit 97455db

File tree

8 files changed

+85
-4
lines changed

8 files changed

+85
-4
lines changed

impeller/entity/BUILD.gn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ impeller_component("entity") {
3838
impeller_component("entity_unittests") {
3939
testonly = true
4040

41-
sources = [ "entity_unittests.cc" ]
41+
sources = [
42+
"entity_playground.cc",
43+
"entity_playground.h",
44+
"entity_unittests.cc",
45+
]
4246

4347
deps = [
4448
":entity",

impeller/entity/contents.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "impeller/entity/contents.h"
66

7+
#include <memory>
8+
79
#include "flutter/fml/logging.h"
810
#include "impeller/entity/content_renderer.h"
911
#include "impeller/entity/entity.h"
@@ -151,6 +153,12 @@ bool SolidColorContents::Render(const ContentRenderer& renderer,
151153
return true;
152154
}
153155

156+
std::unique_ptr<SolidColorContents> SolidColorContents::Make(Color color) {
157+
auto contents = std::make_unique<SolidColorContents>();
158+
contents->SetColor(color);
159+
return contents;
160+
}
161+
154162
/*******************************************************************************
155163
******* SolidStrokeContents
156164
******************************************************************************/

impeller/entity/contents.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class SolidColorContents final : public Contents {
6464

6565
~SolidColorContents() override;
6666

67+
static std::unique_ptr<SolidColorContents> Make(Color color);
68+
6769
void SetColor(Color color);
6870

6971
const Color& GetColor() const;

impeller/entity/entity_playground.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "impeller/entity/entity_playground.h"
6+
7+
namespace impeller {
8+
9+
EntityPlayground::EntityPlayground() = default;
10+
11+
EntityPlayground::~EntityPlayground() = default;
12+
13+
bool EntityPlayground::OpenPlaygroundHere(Entity entity) {
14+
if (!renderer_) {
15+
renderer_ = std::make_unique<EntityRenderer>(GetContext());
16+
if (!renderer_) {
17+
return false;
18+
}
19+
}
20+
Renderer::RenderCallback callback = [&](const Surface& surface,
21+
RenderPass& pass) -> bool {
22+
std::vector<Entity> entities = {entity};
23+
return renderer_->RenderEntities(surface, pass, entities);
24+
};
25+
return Playground::OpenPlaygroundHere(callback);
26+
}
27+
28+
} // namespace impeller

impeller/entity/entity_playground.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#pragma once
6+
7+
#include "flutter/fml/macros.h"
8+
#include "impeller/entity/entity.h"
9+
#include "impeller/entity/entity_renderer.h"
10+
#include "impeller/playground/playground.h"
11+
12+
namespace impeller {
13+
14+
class EntityPlayground : public Playground {
15+
public:
16+
EntityPlayground();
17+
18+
~EntityPlayground();
19+
20+
bool OpenPlaygroundHere(Entity entity);
21+
22+
private:
23+
std::unique_ptr<EntityRenderer> renderer_;
24+
25+
FML_DISALLOW_COPY_AND_ASSIGN(EntityPlayground);
26+
};
27+
28+
} // namespace impeller

impeller/entity/entity_unittests.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
#include "flutter/testing/testing.h"
66
#include "impeller/entity/entity.h"
7+
#include "impeller/entity/entity_playground.h"
78
#include "impeller/geometry/path_builder.h"
89
#include "impeller/playground/playground.h"
910

1011
namespace impeller {
1112
namespace testing {
1213

13-
using EntityTest = Playground;
14+
using EntityTest = EntityPlayground;
1415

1516
TEST_F(EntityTest, CanCreateEntity) {
1617
Entity entity;
@@ -20,6 +21,8 @@ TEST_F(EntityTest, CanCreateEntity) {
2021
TEST_F(EntityTest, CanDrawRect) {
2122
Entity entity;
2223
entity.SetPath(PathBuilder{}.AddRect({100, 100, 100, 100}).CreatePath());
24+
entity.SetContents(SolidColorContents::Make(Color::Red()));
25+
ASSERT_TRUE(OpenPlaygroundHere(entity));
2326
}
2427

2528
} // namespace testing

impeller/playground/playground.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#pragma once
6+
57
#include "flutter/fml/closure.h"
68
#include "flutter/fml/macros.h"
79
#include "gtest/gtest.h"

impeller/renderer/pipeline_builder.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ struct PipelineBuilder {
6969
FragmentShader::kEntrypointName, ShaderStage::kFragment);
7070

7171
if (!vertex_function || !fragment_function) {
72-
FML_LOG(ERROR) << "Could not resolve pipeline entrypoint(s).";
72+
FML_LOG(ERROR) << "Could not resolve pipeline entrypoint(s) '"
73+
<< VertexShader::kEntrypointName << "' and '"
74+
<< FragmentShader::kEntrypointName
75+
<< "' for pipline named '" << VertexShader::kLabel
76+
<< "'.";
7377
return false;
7478
}
7579

@@ -82,7 +86,9 @@ struct PipelineBuilder {
8286
auto vertex_descriptor = std::make_shared<VertexDescriptor>();
8387
if (!vertex_descriptor->SetStageInputs(
8488
VertexShader::kAllShaderStageInputs)) {
85-
FML_LOG(ERROR) << "Could not configure vertex descriptor.";
89+
FML_LOG(ERROR)
90+
<< "Could not configure vertex descriptor for pipeline named '"
91+
<< VertexShader::kLabel << "'.";
8692
return false;
8793
}
8894
desc.SetVertexDescriptor(std::move(vertex_descriptor));

0 commit comments

Comments
 (0)