Flutter Impeller
vertices_contents_unittests.cc
Go to the documentation of this file.
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 
12 #include "impeller/entity/contents/test/contents_test_helpers.h"
14 #include "impeller/entity/entity.h"
16 #include "impeller/entity/vertices.frag.h"
19 
20 namespace impeller {
21 namespace testing {
22 
23 using EntityTest = EntityPlayground;
24 
25 std::shared_ptr<VerticesGeometry> CreateColorVertices(
26  const std::vector<Point>& vertices,
27  const std::vector<Color>& colors) {
28  auto bounds = Rect::MakePointBounds(vertices.begin(), vertices.end());
29  std::vector<uint16_t> indices = {};
30  indices.reserve(vertices.size());
31  for (auto i = 0u; i < vertices.size(); i++) {
32  indices.emplace_back(i);
33  }
34  std::vector<Point> texture_coordinates = {};
35 
36  return std::make_shared<VerticesGeometry>(
37  vertices, indices, texture_coordinates, colors,
38  bounds.value_or(Rect::MakeLTRB(0, 0, 0, 0)),
40 }
41 
42 // Verifies that the destination blend fast path still sets an alpha value.
43 TEST_P(EntityTest, RendersDstPerColorWithAlpha) {
45 
46  auto contents = std::make_shared<VerticesContents>();
47  auto vertices = CreateColorVertices(
48  {{0, 0}, {100, 0}, {0, 100}, {100, 0}, {0, 100}, {100, 100}},
50  Color::Red()});
51  auto src_contents = SolidColorContents::Make(
52  PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 100, 100)).TakePath(),
53  Color::Red());
54 
55  contents->SetGeometry(vertices);
56  contents->SetAlpha(0.5);
57  contents->SetBlendMode(BlendMode::kDestination);
58  contents->SetSourceContents(std::move(src_contents));
59 
60  auto content_context = GetContentContext();
61  auto buffer = content_context->GetContext()->CreateCommandBuffer();
62  auto render_target = RenderTarget::CreateOffscreenMSAA(
63  *content_context->GetContext(),
64  *GetContentContext()->GetRenderTargetCache(), {100, 100});
65  auto render_pass = buffer->CreateRenderPass(render_target);
66  Entity entity;
67 
68  ASSERT_TRUE(render_pass->GetCommands().empty());
69  ASSERT_TRUE(contents->Render(*content_context, entity, *render_pass));
70 
71  const auto& cmd = render_pass->GetCommands()[0];
72  auto* frag_uniforms = GetFragInfo<FS>(cmd);
73 
74  ASSERT_EQ(frag_uniforms->alpha, 0.5);
75 }
76 
77 } // namespace testing
78 } // namespace impeller
contents.h
impeller::Color::Red
static constexpr Color Red()
Definition: color.h:264
entity.h
solid_color_contents.h
impeller::BlendMode::kDestination
@ kDestination
impeller::PathBuilder
Definition: path_builder.h:14
impeller::RenderPipelineT::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:93
impeller::PathBuilder::AddRect
PathBuilder & AddRect(Rect rect)
Definition: path_builder.cc:116
impeller::TRect< Scalar >::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:49
vertices_contents.h
path_builder.h
impeller::Entity
Definition: entity.h:21
impeller::testing::CreateColorVertices
std::shared_ptr< VerticesGeometry > CreateColorVertices(const std::vector< Point > &vertices, const std::vector< Color > &colors)
Definition: vertices_contents_unittests.cc:25
impeller::testing::EntityTest
EntityPlayground EntityTest
Definition: checkerboard_contents_unittests.cc:19
impeller::EntityPlayground
Definition: entity_playground.h:18
impeller::VerticesGeometry::VertexMode::kTriangles
@ kTriangles
impeller::TRect< Scalar >::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:27
render_target.h
impeller::testing::TEST_P
TEST_P(AiksTest, CanRenderLinearGradientClamp)
Definition: aiks_gradient_unittests.cc:48
impeller
Definition: aiks_context.cc:10
impeller::SolidColorContents::Make
static std::unique_ptr< SolidColorContents > Make(Path path, Color color)
Definition: solid_color_contents.cc:89
impeller::RenderTarget::CreateOffscreenMSAA
static RenderTarget CreateOffscreenMSAA(const Context &context, RenderTargetAllocator &allocator, ISize size, const std::string &label="Offscreen MSAA", AttachmentConfigMSAA color_attachment_config=kDefaultColorAttachmentConfigMSAA, std::optional< AttachmentConfig > stencil_attachment_config=kDefaultStencilAttachmentConfig)
Definition: render_target.cc:265
entity_playground.h