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"
10 
11 namespace impeller {
12 namespace testing {
13 
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 };
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;
56  renderer->GetTransientsBuffer().Emplace(&byte, /*length=*/1, /*align=*/1);
57  EXPECT_EQ(buffer_view.GetRange().offset, 4u);
58  EXPECT_EQ(buffer_view.GetRange().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
BufferView buffer_view
void SetBlendMode(BlendMode blend_mode)
void SetForegroundColor(std::optional< Color > color)
Sets a source color which is blended after all of the inputs have been blended.
std::shared_ptr< ContentContext > GetContentContext() const
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.
void SetInputs(FilterInput::Vector inputs)
The input texture sources for this filter. Each input's emitted texture is expected to have premultip...
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:91
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
std::shared_ptr< Texture > MakeTexture(ISize size)
Create a texture that has been cleared to transparent black.
TEST_P(AiksTest, DrawAtlasNoColor)
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
ISize64 ISize
Definition: size.h:162