5 #include "flutter/testing/testing.h"
6 #include "gtest/gtest.h"
10 #include "impeller/renderer/backend/gles/test/mock_gles.h"
17 using ::testing::Return;
41 const std::shared_ptr<ReactorGLES>& reactor,
45 tex_desc.
size = {10, 10};
47 auto texture = std::make_shared<TextureGLES>(reactor, tex_desc);
53 std::shared_ptr<DeviceBufferGLES> CreateBuffer(
54 const std::shared_ptr<ReactorGLES>& reactor) {
55 DeviceBufferDescriptor buffer_desc;
56 buffer_desc.size = 10 * 10 * 4;
58 auto allocation = std::make_shared<Allocation>();
59 FML_CHECK(allocation->Truncate(
Bytes(buffer_desc.size)));
61 std::make_shared<DeviceBufferGLES>(buffer_desc, reactor, allocation);
65 BlitCopyBufferToTextureCommandGLES CreateCopyBufferToTextureCommand(
66 const std::shared_ptr<DeviceBufferGLES>& source,
67 const std::shared_ptr<TextureGLES>& dest) {
68 BlitCopyBufferToTextureCommandGLES command;
70 command.destination = dest;
71 command.destination_region =
73 command.mip_level = 0;
75 command.label =
"TestBlit";
79 BlitCopyTextureToBufferCommandGLES CreateCopyTextureToBufferCommand(
80 const std::shared_ptr<TextureGLES>& source,
81 const std::shared_ptr<DeviceBufferGLES>& dest) {
82 BlitCopyTextureToBufferCommandGLES command;
83 command.source = source;
84 command.destination = dest;
85 command.source_region =
IRect::MakeSize(source->GetTextureDescriptor().size);
86 command.label =
"TestBlit";
92 TEST(BlitCommandGLESTest, BlitCopyBufferToTextureCommandGLESRGBA) {
93 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
94 auto& mock_gles_impl_ref = *mock_gles_impl;
96 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
97 auto reactor = std::make_shared<TestReactorGLES>();
98 auto worker = std::make_shared<MockWorker>();
99 reactor->AddWorker(worker);
102 std::shared_ptr<TextureGLES> dest_texture =
104 std::shared_ptr<DeviceBufferGLES> source_buffer = CreateBuffer(reactor);
106 CreateCopyBufferToTextureCommand(source_buffer, dest_texture);
109 EXPECT_CALL(mock_gles_impl_ref,
110 TexSubImage2D(GL_TEXTURE_2D, _, _, _, _, _, GL_RGBA, _, _))
113 EXPECT_TRUE(command.
Encode(*reactor));
116 TEST(BlitCommandGLESTest, BlitCopyBufferToTextureCommandGLESBGRA) {
117 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
118 auto& mock_gles_impl_ref = *mock_gles_impl;
121 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(
122 std::move(mock_gles_impl),
123 std::vector<const char*>{
"GL_EXT_texture_format_BGRA8888"});
124 auto reactor = std::make_shared<TestReactorGLES>();
125 auto worker = std::make_shared<MockWorker>();
126 reactor->AddWorker(worker);
129 std::shared_ptr<TextureGLES> dest_texture =
131 std::shared_ptr<DeviceBufferGLES> source_buffer = CreateBuffer(reactor);
133 CreateCopyBufferToTextureCommand(source_buffer, dest_texture);
136 EXPECT_CALL(mock_gles_impl_ref,
137 TexSubImage2D(GL_TEXTURE_2D, _, _, _, _, _, GL_BGRA_EXT, _, _))
140 EXPECT_TRUE(command.
Encode(*reactor));
145 TEST(BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESBindsFramebuffer) {
146 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
147 auto& mock_gles_impl_ref = *mock_gles_impl;
149 EXPECT_CALL(mock_gles_impl_ref, GenFramebuffers(1, _))
150 .WillOnce(::testing::SetArgPointee<1>(3));
151 EXPECT_CALL(mock_gles_impl_ref, GenTextures(1, _))
152 .WillOnce(::testing::SetArgPointee<1>(1));
153 EXPECT_CALL(mock_gles_impl_ref, BindFramebuffer(GL_FRAMEBUFFER, 3)).Times(1);
154 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(GL_FRAMEBUFFER))
155 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
156 EXPECT_CALL(mock_gles_impl_ref, ReadPixels(_, _, _, _, _, _, _)).Times(1);
157 EXPECT_CALL(mock_gles_impl_ref, BindFramebuffer(GL_FRAMEBUFFER, 0)).Times(1);
159 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
160 auto reactor = std::make_shared<TestReactorGLES>();
161 auto worker = std::make_shared<MockWorker>();
162 reactor->AddWorker(worker);
164 std::shared_ptr<TextureGLES> source_texture =
166 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
168 ASSERT_TRUE(reactor->React());
171 CreateCopyTextureToBufferCommand(source_texture, dest_buffer);
173 EXPECT_TRUE(command.
Encode(*reactor));
175 source_texture.reset();
178 ASSERT_TRUE(reactor->React());
181 TEST(BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESRGBA) {
182 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
183 auto& mock_gles_impl_ref = *mock_gles_impl;
185 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
186 auto reactor = std::make_shared<TestReactorGLES>();
187 auto worker = std::make_shared<MockWorker>();
188 reactor->AddWorker(worker);
191 std::shared_ptr<TextureGLES> source_texture =
193 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
195 CreateCopyTextureToBufferCommand(source_texture, dest_buffer);
197 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(_))
198 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
200 EXPECT_CALL(mock_gles_impl_ref, ReadPixels(_, _, _, _, GL_RGBA, _, _))
203 EXPECT_TRUE(command.
Encode(*reactor));
206 TEST(BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESBGRA) {
207 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
208 auto& mock_gles_impl_ref = *mock_gles_impl;
211 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(
212 std::move(mock_gles_impl),
213 std::vector<const char*>{
"GL_EXT_texture_format_BGRA8888"});
214 auto reactor = std::make_shared<TestReactorGLES>();
215 auto worker = std::make_shared<MockWorker>();
216 reactor->AddWorker(worker);
219 std::shared_ptr<TextureGLES> source_texture =
221 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
223 CreateCopyTextureToBufferCommand(source_texture, dest_buffer);
225 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(_))
226 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
228 EXPECT_CALL(mock_gles_impl_ref, ReadPixels(_, _, _, _, GL_BGRA_EXT, _, _))
231 EXPECT_TRUE(command.
Encode(*reactor));
235 BlitCopyTextureToBufferCommandGLESUnsupportedPixelFormats) {
236 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
237 auto& mock_gles_impl_ref = *mock_gles_impl;
239 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
240 auto reactor = std::make_shared<TestReactorGLES>();
241 auto worker = std::make_shared<MockWorker>();
242 reactor->AddWorker(worker);
244 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
246 std::shared_ptr<TextureGLES> source_texture_D32FloatS8Uint =
249 CreateCopyTextureToBufferCommand(source_texture_D32FloatS8Uint,
252 std::shared_ptr<TextureGLES> source_texture_R8G8UNormInt =
255 CreateCopyTextureToBufferCommand(source_texture_R8G8UNormInt,
258 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(_)).Times(0);
261 EXPECT_FALSE(command_for_D32FloatS8Uint.
Encode(*reactor));
264 EXPECT_FALSE(command_for_R8G8UNormInt.
Encode(*reactor));
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
A delegate implemented by a thread on which an OpenGL context is current. There may be multiple worke...
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
bool CanReactorReactOnCurrentThreadNow(const ReactorGLES &reactor) const override
Determines the ability of the worker to service a reaction on the current thread. The OpenGL context ...
~TestReactorGLES()=default
TEST(AllocationSizeTest, CanCreateTypedAllocations)
AllocationSize< 1u > Bytes
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Mask< TextureUsage > TextureUsageMask
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &texture_descriptor, const std::vector< uint8_t > &data, const std::shared_ptr< impeller::Context > &context, std::string_view debug_label)
bool Encode(const ReactorGLES &reactor) const override
bool Encode(const ReactorGLES &reactor) const override
constexpr static TRect MakeSize(const TSize< U > &size)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...