[Impeller] add example of testing entity with "real" HAL instead of mocking. (flutter/engine#47631)
As a response to my comments in https://github.com/flutter/engine/pull/47621
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -268,6 +268,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",
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/entity/contents/contents.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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_;
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user