Flutter Engine
The Flutter Engine
blit_pass_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 "gtest/gtest.h"
12
13namespace impeller {
14namespace testing {
15
18
19TEST_P(BlitPassTest, BlitAcrossDifferentPixelFormatsFails) {
20 ScopedValidationDisable scope; // avoid noise in output.
21 auto context = GetContext();
22 auto cmd_buffer = context->CreateCommandBuffer();
23 auto blit_pass = cmd_buffer->CreateBlitPass();
24
25 TextureDescriptor src_desc;
27 src_desc.size = {100, 100};
29 auto src = context->GetResourceAllocator()->CreateTexture(src_desc);
30
31 TextureDescriptor dst_format;
33 dst_format.size = {100, 100};
35 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
36
37 EXPECT_FALSE(blit_pass->AddCopy(src, dst));
38}
39
40TEST_P(BlitPassTest, BlitAcrossDifferentSampleCountsFails) {
41 ScopedValidationDisable scope; // avoid noise in output.
42 auto context = GetContext();
43 auto cmd_buffer = context->CreateCommandBuffer();
44 auto blit_pass = cmd_buffer->CreateBlitPass();
45
46 TextureDescriptor src_desc;
49 src_desc.size = {100, 100};
50 auto src = context->GetResourceAllocator()->CreateTexture(src_desc);
51
52 TextureDescriptor dst_format;
54 dst_format.size = {100, 100};
55 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
56
57 EXPECT_FALSE(blit_pass->AddCopy(src, dst));
58}
59
60TEST_P(BlitPassTest, BlitPassesForMatchingFormats) {
61 ScopedValidationDisable scope; // avoid noise in output.
62 auto context = GetContext();
63 auto cmd_buffer = context->CreateCommandBuffer();
64 auto blit_pass = cmd_buffer->CreateBlitPass();
65
66 TextureDescriptor src_desc;
68 src_desc.size = {100, 100};
70 auto src = context->GetResourceAllocator()->CreateTexture(src_desc);
71
72 TextureDescriptor dst_format;
74 dst_format.size = {100, 100};
76 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
77
78 EXPECT_TRUE(blit_pass->AddCopy(src, dst));
79}
80
81TEST_P(BlitPassTest, ChecksInvalidSliceParameters) {
82 ScopedValidationDisable scope; // avoid noise in output.
83 auto context = GetContext();
84 auto cmd_buffer = context->CreateCommandBuffer();
85 auto blit_pass = cmd_buffer->CreateBlitPass();
86
87 TextureDescriptor dst_format;
90 dst_format.size = {100, 100};
91 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
92
93 DeviceBufferDescriptor src_format;
94 src_format.size = 40000;
96 auto src = context->GetResourceAllocator()->CreateBuffer(src_format);
97
98 ASSERT_TRUE(dst);
99 ASSERT_TRUE(src);
100
101 EXPECT_FALSE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
102 std::nullopt, "", /*slice=*/25));
103 EXPECT_FALSE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
104 std::nullopt, "", /*slice=*/6));
105 EXPECT_TRUE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
106 std::nullopt, "", /*slice=*/0));
107}
108
109TEST_P(BlitPassTest, CanBlitSmallRegionToUninitializedTexture) {
110 auto context = GetContext();
111 auto cmd_buffer = context->CreateCommandBuffer();
112 auto blit_pass = cmd_buffer->CreateBlitPass();
113
114 TextureDescriptor dst_format;
117 dst_format.size = {1000, 1000};
118 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
119
120 DeviceBufferDescriptor src_format;
121 src_format.size = 4;
123 auto src = context->GetResourceAllocator()->CreateBuffer(src_format);
124
125 ASSERT_TRUE(dst);
126
127 EXPECT_TRUE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
128 IRect::MakeLTRB(0, 0, 1, 1), "", /*slice=*/0));
129 EXPECT_TRUE(blit_pass->EncodeCommands(GetContext()->GetResourceAllocator()));
130 EXPECT_TRUE(context->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok());
131}
132
133} // namespace testing
134} // namespace impeller
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
SK_API GrDirectContext * GetContext(const SkImage *src)
dst
Definition: cp.py:12
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678