Flutter Engine
The Flutter Engine
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
11namespace impeller {
12namespace 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
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
45TEST_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.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
static bool ok(int result)
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:90
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
std::shared_ptr< Texture > MakeTexture(ISize size)
Create a texture that has been cleared to transparent black.
GAsyncResult * result
FlTexture * texture
SK_API sk_sp< SkShader > Color(SkColor)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
ISize64 ISize
Definition: size.h:140
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678