Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] add example of testing entity with "real" HAL instead of mocking. #47631

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
../../../flutter/impeller/display_list/dl_unittests.cc
../../../flutter/impeller/display_list/skia_conversions_unittests.cc
../../../flutter/impeller/docs
../../../flutter/impeller/entity/contents/checkerboard_contents_unittests.cc
../../../flutter/impeller/entity/contents/filters/inputs/filter_input_unittests.cc
../../../flutter/impeller/entity/entity_unittests.cc
../../../flutter/impeller/entity/geometry/geometry_unittests.cc
Expand Down
1 change: 1 addition & 0 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ impeller_component("entity_unittests") {
testonly = true

sources = [
"contents/checkerboard_contents_unittests.cc",
"contents/filters/inputs/filter_input_unittests.cc",
"entity_playground.cc",
"entity_playground.h",
Expand Down
1 change: 0 additions & 1 deletion impeller/entity/contents/checkerboard_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#pragma once

#include "flutter/fml/macros.h"
#include "impeller/entity/contents/contents.h"

namespace impeller {
Expand Down
50 changes: 50 additions & 0 deletions impeller/entity/contents/checkerboard_contents_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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 <memory>
#include <optional>

#include "gtest/gtest.h"

#include "impeller/entity/contents/checkerboard_contents.h"
#include "impeller/entity/contents/contents.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/entity_playground.h"
#include "impeller/renderer/render_target.h"

namespace impeller {
namespace testing {

using EntityTest = EntityPlayground;
INSTANTIATE_PLAYGROUND_SUITE(EntityTest);

#ifdef IMPELLER_DEBUG
TEST(EntityTest, HasNulloptCoverage) {
auto contents = std::make_shared<CheckerboardContents>();

Entity entity;
ASSERT_EQ(contents->GetCoverage(entity), std::nullopt);
}

TEST_P(EntityTest, RendersWithoutError) {
auto contents = std::make_shared<CheckerboardContents>();
contents->SetColor(Color::Aqua());
contents->SetSquareSize(10);

auto content_context = GetContentContext();
auto buffer = content_context->GetContext()->CreateCommandBuffer();
auto render_target = RenderTarget::CreateOffscreenMSAA(
*content_context->GetContext(),
*GetContentContext()->GetRenderTargetCache(), {100, 100});
auto render_pass = buffer->CreateRenderPass(render_target);
Entity entity;

ASSERT_TRUE(render_pass->GetCommands().empty());
ASSERT_TRUE(contents->Render(*content_context, entity, *render_pass));
ASSERT_FALSE(render_pass->GetCommands().empty());
}
#endif // IMPELLER_DEBUG

} // namespace testing
} // namespace impeller
10 changes: 7 additions & 3 deletions impeller/entity/entity_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ bool EntityPlayground::OpenPlaygroundHere(EntityPass& entity_pass) {
return Playground::OpenPlaygroundHere(callback);
}

std::shared_ptr<ContentContext> EntityPlayground::GetContentContext() const {
return std::make_shared<ContentContext>(GetContext(), typographer_context_);
}

bool EntityPlayground::OpenPlaygroundHere(Entity entity) {
if (!switches_.enable_playground) {
return true;
}

ContentContext content_context(GetContext(), typographer_context_);
if (!content_context.IsValid()) {
auto content_context = GetContentContext();
if (!content_context->IsValid()) {
return false;
}
SinglePassCallback callback = [&](RenderPass& pass) -> bool {
return entity.Render(content_context, pass);
return entity.Render(*content_context, pass);
};
return Playground::OpenPlaygroundHere(callback);
}
Expand Down
2 changes: 2 additions & 0 deletions impeller/entity/entity_playground.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class EntityPlayground : public PlaygroundTest {

bool OpenPlaygroundHere(EntityPlaygroundCallback callback);

std::shared_ptr<ContentContext> GetContentContext() const;

private:
std::shared_ptr<TypographerContext> typographer_context_;

Expand Down
10 changes: 0 additions & 10 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <algorithm>
#include <cstring>
#include <memory>
#include <optional>
#include <unordered_map>
#include <utility>
#include <vector>

#include "flutter/testing/testing.h"
#include "fml/logging.h"
#include "fml/time/time_point.h"
#include "gtest/gtest.h"
#include "impeller/core/texture_descriptor.h"
#include "impeller/entity/contents/atlas_contents.h"
#include "impeller/entity/contents/clip_contents.h"
#include "impeller/entity/contents/conical_gradient_contents.h"
#include "impeller/entity/contents/contents.h"
#include "impeller/entity/contents/filters/blend_filter_contents.h"
#include "impeller/entity/contents/filters/color_filter_contents.h"
#include "impeller/entity/contents/filters/filter_contents.h"
#include "impeller/entity/contents/filters/inputs/filter_input.h"
Expand All @@ -28,11 +23,9 @@
#include "impeller/entity/contents/runtime_effect_contents.h"
#include "impeller/entity/contents/solid_color_contents.h"
#include "impeller/entity/contents/solid_rrect_blur_contents.h"
#include "impeller/entity/contents/sweep_gradient_contents.h"
#include "impeller/entity/contents/text_contents.h"
#include "impeller/entity/contents/texture_contents.h"
#include "impeller/entity/contents/tiled_texture_contents.h"
#include "impeller/entity/contents/vertices_contents.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/entity_pass.h"
#include "impeller/entity/entity_pass_delegate.h"
Expand All @@ -50,11 +43,8 @@
#include "impeller/renderer/command.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/vertex_buffer_builder.h"
#include "impeller/runtime_stage/runtime_stage.h"
#include "impeller/tessellator/tessellator.h"
#include "impeller/typographer/backends/skia/text_frame_skia.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
#include "include/core/SkBlendMode.h"
#include "third_party/imgui/imgui.h"
#include "third_party/skia/include/core/SkTextBlob.h"

Expand Down