Start wiring up the entity playground.
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
@@ -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
|
||||
******************************************************************************/
|
||||
|
||||
@@ -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;
|
||||
|
||||
28
engine/src/flutter/impeller/entity/entity_playground.cc
Normal file
28
engine/src/flutter/impeller/entity/entity_playground.cc
Normal file
@@ -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
engine/src/flutter/impeller/entity/entity_playground.h
Normal file
28
engine/src/flutter/impeller/entity/entity_playground.h
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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<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));
|
||||
|
||||
Reference in New Issue
Block a user