| Flutter Impeller |

blend_filter_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 "flutter/testing/testing.h"
6 #include "gmock/gmock.h"
7 #include "impeller/entity/contents/content_context.h"
8 #include "impeller/entity/contents/filters/blend_filter_contents.h"
9 #include "impeller/entity/entity_playground.h"
10
11 namespace impeller {
12 namespace testing {
13
14 class BlendFilterContentsTest : public EntityPlayground {
15 public:
16 /// Create a texture that has been cleared to transparent black.
17 std::shared_ptr<Texture> MakeTexture(ISize size) {
18 std::shared_ptr<CommandBuffer> command_buffer =
19 GetContentContext()->GetContext()->CreateCommandBuffer();
20 if (!command_buffer) {
21 return nullptr;
22 }
23
24 auto render_target = GetContentContext()->MakeSubpass(
25 "Clear Subpass", size, command_buffer,
26 [](const ContentContext&, RenderPass&) { return true; });
27
28 if (!GetContentContext()
29 ->GetContext()
30 ->GetCommandQueue()
31 ->Submit(/*buffers=*/{command_buffer})
32 .ok()) {
33 return nullptr;
34 }
35
36 if (render_target.ok()) {
37 return render_target.value().GetRenderTargetTexture();
38 }
39 return nullptr;
40 }
41 };
42 INSTANTIATE_PLAYGROUND_SUITE(BlendFilterContentsTest);
43
44 // https://github.com/flutter/flutter/issues/149216
45 TEST_P(BlendFilterContentsTest, AdvancedBlendColorAlignsColorTo4) {
46 std::shared_ptr<Texture> texture = MakeTexture(ISize(100, 100));
47 BlendFilterContents filter_contents;
48 filter_contents.SetInputs({FilterInput::Make(texture)});
49 filter_contents.SetForegroundColor(Color(1.0, 0.0, 0.0, 1.0));
50 filter_contents.SetBlendMode(BlendMode::kColorDodge);
51
52 std::shared_ptr<ContentContext> renderer = GetContentContext();
53 // Add random byte to get the HostBuffer in a bad alignment.
54 uint8_t byte = 0xff;
55 BufferView buffer_view =
56 renderer->GetTransientsBuffer().Emplace(&byte, /*length=*/1, /*align=*/1);
57 EXPECT_EQ(buffer_view.range.offset, 4u);
58 EXPECT_EQ(buffer_view.range.length, 1u);
59 Entity entity;
60
61 std::optional<Entity> result = filter_contents.GetEntity(
62 *renderer, entity, /*coverage_hint=*/std::nullopt);
63
64 EXPECT_TRUE(result.has_value());
65 }
66
67 } // namespace testing
68 } // namespace impeller
impeller::ISize
ISize64 ISize
Definition: size.h:140
impeller::FilterContents::SetInputs
void SetInputs(FilterInput::Vector inputs)
The input texture sources for this filter. Each input's emitted texture is expected to have premultip...
Definition: filter_contents.cc:121
impeller::BlendFilterContents::SetBlendMode
void SetBlendMode(BlendMode blend_mode)
Definition: blend_filter_contents.cc:936
impeller::BlendFilterContents::SetForegroundColor
void SetForegroundColor(std::optional< Color > color)
Sets a source color which is blended after all of the inputs have been blended.
Definition: blend_filter_contents.cc:967
impeller::Color
Definition: color.h:123
impeller::FilterInput::Make
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
impeller::BlendMode::kColorDodge
@ kColorDodge
buffer_view
BufferView buffer_view
Definition: blit_command_gles.cc:128
impeller::testing::INSTANTIATE_PLAYGROUND_SUITE
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
impeller::Entity
Definition: entity.h:20
impeller::TSize
Definition: size.h:19
impeller::testing::BlendFilterContentsTest::MakeTexture
std::shared_ptr< Texture > MakeTexture(ISize size)
Create a texture that has been cleared to transparent black.
Definition: blend_filter_contents_unittests.cc:17
impeller::testing::BlendFilterContentsTest
Definition: blend_filter_contents_unittests.cc:14
impeller::BlendFilterContents
Definition: blend_filter_contents.h:35
impeller::testing::TEST_P
TEST_P(AiksTest, DrawAtlasNoColor)
Definition: aiks_dl_atlas_unittests.cc:78
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
content_context.h
impeller::BufferView
Definition: buffer_view.h:15
impeller::EntityPlayground
Definition: entity_playground.h:16
impeller::FilterContents::GetEntity
std::optional< Entity > GetEntity(const ContentContext &renderer, const Entity &entity, const std::optional< Rect > &coverage_hint) const
Create an Entity that renders this filter's output.
Definition: filter_contents.cc:218
blend_filter_contents.h
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:90
impeller
Definition: allocation.cc:12
impeller::ContentContext
Definition: content_context.h:366
impeller::EntityPlayground::GetContentContext
std::shared_ptr< ContentContext > GetContentContext() const
Definition: entity_playground.cc:23
entity_playground.h