Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d5ccb5b

Browse files
author
Jonah Williams
authored
[Impeller] add example of testing entity with "real" HAL instead of mocking. (#47631)
As a response to my comments in #47621
1 parent b0d8663 commit d5ccb5b

File tree

7 files changed

+61
-14
lines changed

7 files changed

+61
-14
lines changed

ci/licenses_golden/excluded_files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
../../../flutter/impeller/display_list/dl_unittests.cc
135135
../../../flutter/impeller/display_list/skia_conversions_unittests.cc
136136
../../../flutter/impeller/docs
137+
../../../flutter/impeller/entity/contents/checkerboard_contents_unittests.cc
137138
../../../flutter/impeller/entity/contents/filters/inputs/filter_input_unittests.cc
138139
../../../flutter/impeller/entity/entity_unittests.cc
139140
../../../flutter/impeller/entity/geometry/geometry_unittests.cc

impeller/entity/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ impeller_component("entity_unittests") {
268268
testonly = true
269269

270270
sources = [
271+
"contents/checkerboard_contents_unittests.cc",
271272
"contents/filters/inputs/filter_input_unittests.cc",
272273
"entity_playground.cc",
273274
"entity_playground.h",

impeller/entity/contents/checkerboard_contents.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#pragma once
66

7-
#include "flutter/fml/macros.h"
87
#include "impeller/entity/contents/contents.h"
98

109
namespace impeller {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 <memory>
6+
#include <optional>
7+
8+
#include "gtest/gtest.h"
9+
10+
#include "impeller/entity/contents/checkerboard_contents.h"
11+
#include "impeller/entity/contents/contents.h"
12+
#include "impeller/entity/entity.h"
13+
#include "impeller/entity/entity_playground.h"
14+
#include "impeller/renderer/render_target.h"
15+
16+
namespace impeller {
17+
namespace testing {
18+
19+
using EntityTest = EntityPlayground;
20+
INSTANTIATE_PLAYGROUND_SUITE(EntityTest);
21+
22+
#ifdef IMPELLER_DEBUG
23+
TEST(EntityTest, HasNulloptCoverage) {
24+
auto contents = std::make_shared<CheckerboardContents>();
25+
26+
Entity entity;
27+
ASSERT_EQ(contents->GetCoverage(entity), std::nullopt);
28+
}
29+
30+
TEST_P(EntityTest, RendersWithoutError) {
31+
auto contents = std::make_shared<CheckerboardContents>();
32+
contents->SetColor(Color::Aqua());
33+
contents->SetSquareSize(10);
34+
35+
auto content_context = GetContentContext();
36+
auto buffer = content_context->GetContext()->CreateCommandBuffer();
37+
auto render_target = RenderTarget::CreateOffscreenMSAA(
38+
*content_context->GetContext(),
39+
*GetContentContext()->GetRenderTargetCache(), {100, 100});
40+
auto render_pass = buffer->CreateRenderPass(render_target);
41+
Entity entity;
42+
43+
ASSERT_TRUE(render_pass->GetCommands().empty());
44+
ASSERT_TRUE(contents->Render(*content_context, entity, *render_pass));
45+
ASSERT_FALSE(render_pass->GetCommands().empty());
46+
}
47+
#endif // IMPELLER_DEBUG
48+
49+
} // namespace testing
50+
} // namespace impeller

impeller/entity/entity_playground.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,21 @@ bool EntityPlayground::OpenPlaygroundHere(EntityPass& entity_pass) {
3636
return Playground::OpenPlaygroundHere(callback);
3737
}
3838

39+
std::shared_ptr<ContentContext> EntityPlayground::GetContentContext() const {
40+
return std::make_shared<ContentContext>(GetContext(), typographer_context_);
41+
}
42+
3943
bool EntityPlayground::OpenPlaygroundHere(Entity entity) {
4044
if (!switches_.enable_playground) {
4145
return true;
4246
}
4347

44-
ContentContext content_context(GetContext(), typographer_context_);
45-
if (!content_context.IsValid()) {
48+
auto content_context = GetContentContext();
49+
if (!content_context->IsValid()) {
4650
return false;
4751
}
4852
SinglePassCallback callback = [&](RenderPass& pass) -> bool {
49-
return entity.Render(content_context, pass);
53+
return entity.Render(*content_context, pass);
5054
};
5155
return Playground::OpenPlaygroundHere(callback);
5256
}

impeller/entity/entity_playground.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class EntityPlayground : public PlaygroundTest {
3232

3333
bool OpenPlaygroundHere(EntityPlaygroundCallback callback);
3434

35+
std::shared_ptr<ContentContext> GetContentContext() const;
36+
3537
private:
3638
std::shared_ptr<TypographerContext> typographer_context_;
3739

impeller/entity/entity_unittests.cc

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

5-
#include <algorithm>
65
#include <cstring>
76
#include <memory>
87
#include <optional>
9-
#include <unordered_map>
108
#include <utility>
119
#include <vector>
1210

13-
#include "flutter/testing/testing.h"
1411
#include "fml/logging.h"
15-
#include "fml/time/time_point.h"
1612
#include "gtest/gtest.h"
1713
#include "impeller/core/texture_descriptor.h"
1814
#include "impeller/entity/contents/atlas_contents.h"
1915
#include "impeller/entity/contents/clip_contents.h"
2016
#include "impeller/entity/contents/conical_gradient_contents.h"
2117
#include "impeller/entity/contents/contents.h"
22-
#include "impeller/entity/contents/filters/blend_filter_contents.h"
2318
#include "impeller/entity/contents/filters/color_filter_contents.h"
2419
#include "impeller/entity/contents/filters/filter_contents.h"
2520
#include "impeller/entity/contents/filters/inputs/filter_input.h"
@@ -28,11 +23,9 @@
2823
#include "impeller/entity/contents/runtime_effect_contents.h"
2924
#include "impeller/entity/contents/solid_color_contents.h"
3025
#include "impeller/entity/contents/solid_rrect_blur_contents.h"
31-
#include "impeller/entity/contents/sweep_gradient_contents.h"
3226
#include "impeller/entity/contents/text_contents.h"
3327
#include "impeller/entity/contents/texture_contents.h"
3428
#include "impeller/entity/contents/tiled_texture_contents.h"
35-
#include "impeller/entity/contents/vertices_contents.h"
3629
#include "impeller/entity/entity.h"
3730
#include "impeller/entity/entity_pass.h"
3831
#include "impeller/entity/entity_pass_delegate.h"
@@ -50,11 +43,8 @@
5043
#include "impeller/renderer/command.h"
5144
#include "impeller/renderer/render_pass.h"
5245
#include "impeller/renderer/vertex_buffer_builder.h"
53-
#include "impeller/runtime_stage/runtime_stage.h"
54-
#include "impeller/tessellator/tessellator.h"
5546
#include "impeller/typographer/backends/skia/text_frame_skia.h"
5647
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
57-
#include "include/core/SkBlendMode.h"
5848
#include "third_party/imgui/imgui.h"
5949
#include "third_party/skia/include/core/SkTextBlob.h"
6050

0 commit comments

Comments
 (0)