5#include <initializer_list>
9#include "gtest/gtest.h"
20using ::testing::Return;
44 const std::shared_ptr<ReactorGLES>& reactor,
48 tex_desc.
size = {10, 10};
50 auto texture = std::make_shared<TextureGLES>(reactor, tex_desc);
56std::shared_ptr<DeviceBufferGLES> CreateBuffer(
57 const std::shared_ptr<ReactorGLES>& reactor) {
58 DeviceBufferDescriptor buffer_desc;
59 buffer_desc.size = 10 * 10 * 4;
61 auto allocation = std::make_unique<Allocation>();
63 auto buffer = std::make_shared<DeviceBufferGLES>(buffer_desc, reactor,
64 std::move(allocation));
68BlitCopyBufferToTextureCommandGLES CreateCopyBufferToTextureCommand(
69 const std::shared_ptr<DeviceBufferGLES>& source,
70 const std::shared_ptr<TextureGLES>& dest) {
71 BlitCopyBufferToTextureCommandGLES command;
73 command.destination = dest;
74 command.destination_region =
76 command.mip_level = 0;
78 command.label =
"TestBlit";
82BlitCopyTextureToBufferCommandGLES CreateCopyTextureToBufferCommand(
83 const std::shared_ptr<TextureGLES>& source,
84 const std::shared_ptr<DeviceBufferGLES>& dest) {
85 BlitCopyTextureToBufferCommandGLES command;
86 command.source = source;
87 command.destination = dest;
88 command.source_region =
IRect::MakeSize(source->GetTextureDescriptor().size);
89 command.label =
"TestBlit";
95TEST(BlitCommandGLESTest, BlitCopyBufferToTextureCommandGLESRGBA) {
96 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
97 auto& mock_gles_impl_ref = *mock_gles_impl;
99 std::shared_ptr<MockGLES> mock_gl =
MockGLES::Init(std::move(mock_gles_impl));
100 auto reactor = std::make_shared<TestReactorGLES>();
101 auto worker = std::make_shared<MockWorker>();
102 reactor->AddWorker(worker);
105 std::shared_ptr<TextureGLES> dest_texture =
107 std::shared_ptr<DeviceBufferGLES> source_buffer = CreateBuffer(reactor);
109 CreateCopyBufferToTextureCommand(source_buffer, dest_texture);
112 EXPECT_CALL(mock_gles_impl_ref,
113 TexSubImage2D(GL_TEXTURE_2D, _, _, _, _, _, GL_RGBA, _, _))
116 EXPECT_TRUE(command.
Encode(*reactor));
119TEST(BlitCommandGLESTest, BlitCopyBufferToTextureCommandGLESBGRA) {
120 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
121 auto& mock_gles_impl_ref = *mock_gles_impl;
125 std::move(mock_gles_impl),
126 std::vector<const char*>{
"GL_EXT_texture_format_BGRA8888"});
127 auto reactor = std::make_shared<TestReactorGLES>();
128 auto worker = std::make_shared<MockWorker>();
129 reactor->AddWorker(worker);
132 std::shared_ptr<TextureGLES> dest_texture =
134 std::shared_ptr<DeviceBufferGLES> source_buffer = CreateBuffer(reactor);
136 CreateCopyBufferToTextureCommand(source_buffer, dest_texture);
139 EXPECT_CALL(mock_gles_impl_ref,
140 TexSubImage2D(GL_TEXTURE_2D, _, _, _, _, _, GL_BGRA_EXT, _, _))
143 EXPECT_TRUE(command.
Encode(*reactor));
148TEST(BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESBindsFramebuffer) {
149 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
150 auto& mock_gles_impl_ref = *mock_gles_impl;
152 EXPECT_CALL(mock_gles_impl_ref, GenFramebuffers(1, _))
153 .WillOnce(::testing::SetArgPointee<1>(3));
154 EXPECT_CALL(mock_gles_impl_ref, GenTextures(1, _))
155 .WillOnce(::testing::SetArgPointee<1>(1));
156 EXPECT_CALL(mock_gles_impl_ref, BindFramebuffer(GL_FRAMEBUFFER, 3)).Times(1);
157 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(GL_FRAMEBUFFER))
158 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
159 EXPECT_CALL(mock_gles_impl_ref, ReadPixels(_, _, _, _, _, _, _)).Times(1);
160 EXPECT_CALL(mock_gles_impl_ref, BindFramebuffer(GL_FRAMEBUFFER, 0)).Times(1);
162 std::shared_ptr<MockGLES> mock_gl =
MockGLES::Init(std::move(mock_gles_impl));
163 auto reactor = std::make_shared<TestReactorGLES>();
164 auto worker = std::make_shared<MockWorker>();
165 reactor->AddWorker(worker);
167 std::shared_ptr<TextureGLES> source_texture =
169 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
171 ASSERT_TRUE(reactor->React());
174 CreateCopyTextureToBufferCommand(source_texture, dest_buffer);
176 EXPECT_TRUE(command.
Encode(*reactor));
178 source_texture.reset();
181 ASSERT_TRUE(reactor->React());
184TEST(BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESRGBA) {
185 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
186 auto& mock_gles_impl_ref = *mock_gles_impl;
188 std::shared_ptr<MockGLES> mock_gl =
MockGLES::Init(std::move(mock_gles_impl));
189 auto reactor = std::make_shared<TestReactorGLES>();
190 auto worker = std::make_shared<MockWorker>();
191 reactor->AddWorker(worker);
194 std::shared_ptr<TextureGLES> source_texture =
196 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
198 CreateCopyTextureToBufferCommand(source_texture, dest_buffer);
200 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(_))
201 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
203 EXPECT_CALL(mock_gles_impl_ref, ReadPixels(_, _, _, _, GL_RGBA, _, _))
206 EXPECT_TRUE(command.
Encode(*reactor));
209TEST(BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESBGRA) {
210 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
211 auto& mock_gles_impl_ref = *mock_gles_impl;
215 std::move(mock_gles_impl),
216 std::vector<const char*>{
"GL_EXT_texture_format_BGRA8888"});
217 auto reactor = std::make_shared<TestReactorGLES>();
218 auto worker = std::make_shared<MockWorker>();
219 reactor->AddWorker(worker);
222 std::shared_ptr<TextureGLES> source_texture =
224 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
226 CreateCopyTextureToBufferCommand(source_texture, dest_buffer);
228 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(_))
229 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
231 EXPECT_CALL(mock_gles_impl_ref, ReadPixels(_, _, _, _, GL_BGRA_EXT, _, _))
234 EXPECT_TRUE(command.
Encode(*reactor));
238 BlitCopyTextureToBufferCommandGLESUnsupportedPixelFormats) {
239 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
240 auto& mock_gles_impl_ref = *mock_gles_impl;
242 std::shared_ptr<MockGLES> mock_gl =
MockGLES::Init(std::move(mock_gles_impl));
243 auto reactor = std::make_shared<TestReactorGLES>();
244 auto worker = std::make_shared<MockWorker>();
245 reactor->AddWorker(worker);
247 std::shared_ptr<DeviceBufferGLES> dest_buffer = CreateBuffer(reactor);
249 std::shared_ptr<TextureGLES> source_texture_D32FloatS8Uint =
252 CreateCopyTextureToBufferCommand(source_texture_D32FloatS8Uint,
255 std::shared_ptr<TextureGLES> source_texture_R8G8UNormInt =
258 CreateCopyTextureToBufferCommand(source_texture_R8G8UNormInt,
261 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(_)).Times(0);
264 EXPECT_FALSE(command_for_D32FloatS8Uint.
Encode(*reactor));
267 EXPECT_FALSE(command_for_R8G8UNormInt.
Encode(*reactor));
272std::shared_ptr<TextureGLES> CreateMipTexture(
273 const std::shared_ptr<ReactorGLES>& reactor,
284 auto texture = std::make_shared<TextureGLES>(reactor, tex_desc);
290std::shared_ptr<DeviceBufferGLES> CreateMipBuffer(
291 const std::shared_ptr<ReactorGLES>& reactor,
293 DeviceBufferDescriptor buffer_desc;
294 buffer_desc.size = size_bytes;
296 auto allocation = std::make_unique<Allocation>();
298 return std::make_shared<DeviceBufferGLES>(buffer_desc, reactor,
299 std::move(allocation));
308 BlitCopyBufferToTextureCommandAllocatesOnlyTheRequestedBaseMip) {
309 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
310 auto& mock_gles_impl_ref = *mock_gles_impl;
311 std::shared_ptr<MockGLES> mock_gl =
MockGLES::Init(std::move(mock_gles_impl));
312 auto reactor = std::make_shared<TestReactorGLES>();
313 auto worker = std::make_shared<MockWorker>();
314 reactor->AddWorker(worker);
318 auto source = CreateMipBuffer(reactor, 8 * 8 * 4);
326 command.
label =
"TestBlit";
328 EXPECT_CALL(mock_gles_impl_ref,
329 TexImage2D(GL_TEXTURE_2D, 0, _, 8, 8, _, _, _,
nullptr))
332 EXPECT_CALL(mock_gles_impl_ref,
333 TexImage2D(GL_TEXTURE_2D, 1, _, _, _, _, _, _,
nullptr))
335 EXPECT_CALL(mock_gles_impl_ref,
336 TexImage2D(GL_TEXTURE_2D, 2, _, _, _, _, _, _,
nullptr))
338 EXPECT_CALL(mock_gles_impl_ref,
339 TexSubImage2D(GL_TEXTURE_2D, 0, _, _, 8, 8, _, _, _))
342 EXPECT_TRUE(command.
Encode(*reactor));
351 BlitCopyBufferToTextureCommandAllocatesNonZeroMipLevelOnFirstUpload) {
352 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
353 auto& mock_gles_impl_ref = *mock_gles_impl;
354 std::shared_ptr<MockGLES> mock_gl =
MockGLES::Init(std::move(mock_gles_impl));
355 auto reactor = std::make_shared<TestReactorGLES>();
356 auto worker = std::make_shared<MockWorker>();
357 reactor->AddWorker(worker);
361 auto source = CreateMipBuffer(reactor, 4 * 4 * 4);
369 command.
label =
"TestBlit";
372 EXPECT_CALL(mock_gles_impl_ref,
373 TexImage2D(GL_TEXTURE_2D, 1, _, 4, 4, _, _, _,
nullptr))
375 EXPECT_CALL(mock_gles_impl_ref,
376 TexImage2D(GL_TEXTURE_2D, 0, _, _, _, _, _, _,
nullptr))
378 EXPECT_CALL(mock_gles_impl_ref,
379 TexImage2D(GL_TEXTURE_2D, 2, _, _, _, _, _, _,
nullptr))
381 EXPECT_CALL(mock_gles_impl_ref,
382 TexSubImage2D(GL_TEXTURE_2D, 1, _, _, 4, 4, _, _, _))
385 EXPECT_TRUE(command.
Encode(*reactor));
394 BlitCopyBufferToTextureCommandAllocatesEachMipLevelOnFirstWrite) {
395 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
396 auto& mock_gles_impl_ref = *mock_gles_impl;
397 std::shared_ptr<MockGLES> mock_gl =
MockGLES::Init(std::move(mock_gles_impl));
398 auto reactor = std::make_shared<TestReactorGLES>();
399 auto worker = std::make_shared<MockWorker>();
400 reactor->AddWorker(worker);
406 auto source0 = CreateMipBuffer(reactor, 8 * 8 * 4);
407 auto source1 = CreateMipBuffer(reactor, 4 * 4 * 4);
408 auto source2 = CreateMipBuffer(reactor, 2 * 2 * 4);
410 EXPECT_CALL(mock_gles_impl_ref,
411 TexImage2D(GL_TEXTURE_2D, 0, _, 8, 8, _, _, _,
nullptr))
413 EXPECT_CALL(mock_gles_impl_ref,
414 TexImage2D(GL_TEXTURE_2D, 1, _, 4, 4, _, _, _,
nullptr))
416 EXPECT_CALL(mock_gles_impl_ref,
417 TexImage2D(GL_TEXTURE_2D, 2, _, 2, 2, _, _, _,
nullptr))
419 EXPECT_CALL(mock_gles_impl_ref,
420 TexSubImage2D(GL_TEXTURE_2D, 0, _, _, 8, 8, _, _, _))
422 EXPECT_CALL(mock_gles_impl_ref,
423 TexSubImage2D(GL_TEXTURE_2D, 1, _, _, 4, 4, _, _, _))
425 EXPECT_CALL(mock_gles_impl_ref,
426 TexSubImage2D(GL_TEXTURE_2D, 2, _, _, 2, 2, _, _, _))
429 for (
const auto& [level, w, source] : std::initializer_list<
430 std::tuple<uint32_t, int32_t, std::shared_ptr<DeviceBufferGLES>>>{
431 {0, 8, source0}, {1, 4, source1}, {2, 2, source2}}) {
438 command.
label =
"TestBlit";
439 EXPECT_TRUE(command.
Encode(*reactor));
446 BlitCopyBufferToTextureCommandDoesNotReallocateOnSubsequentUpload) {
447 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
448 auto& mock_gles_impl_ref = *mock_gles_impl;
449 std::shared_ptr<MockGLES> mock_gl =
MockGLES::Init(std::move(mock_gles_impl));
450 auto reactor = std::make_shared<TestReactorGLES>();
451 auto worker = std::make_shared<MockWorker>();
452 reactor->AddWorker(worker);
456 auto source = CreateMipBuffer(reactor, 4 * 4 * 4);
464 command.
label =
"TestBlit";
467 EXPECT_CALL(mock_gles_impl_ref,
468 TexImage2D(GL_TEXTURE_2D, 0, _, 4, 4, _, _, _,
nullptr))
470 EXPECT_CALL(mock_gles_impl_ref,
471 TexImage2D(GL_TEXTURE_2D, 1, _, _, _, _, _, _,
nullptr))
473 EXPECT_CALL(mock_gles_impl_ref,
474 TexSubImage2D(GL_TEXTURE_2D, 0, _, _, _, _, _, _, _))
477 EXPECT_TRUE(command.
Encode(*reactor));
478 EXPECT_TRUE(command.
Encode(*reactor));
486 BlitCopyBufferToTextureCommandUsesCubemapFaceTargetForCubemap) {
487 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
488 auto& mock_gles_impl_ref = *mock_gles_impl;
489 std::shared_ptr<MockGLES> mock_gl =
MockGLES::Init(std::move(mock_gles_impl));
490 auto reactor = std::make_shared<TestReactorGLES>();
491 auto worker = std::make_shared<MockWorker>();
492 reactor->AddWorker(worker);
497 auto source = CreateMipBuffer(reactor, 4 * 4 * 4);
505 command.
label =
"TestBlit";
507 const GLenum face_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + 2;
511 EXPECT_CALL(mock_gles_impl_ref, BindTexture(GL_TEXTURE_CUBE_MAP, _)).Times(1);
512 EXPECT_CALL(mock_gles_impl_ref,
513 TexImage2D(face_target, 0, _, 4, 4, _, _, _,
nullptr))
516 EXPECT_CALL(mock_gles_impl_ref,
517 TexImage2D(face_target, 1, _, _, _, _, _, _,
nullptr))
520 EXPECT_CALL(mock_gles_impl_ref, TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, _,
521 _, _, _, _, _, _,
nullptr))
523 EXPECT_CALL(mock_gles_impl_ref,
524 TexImage2D(GL_TEXTURE_2D, _, _, _, _, _, _, _,
nullptr))
526 EXPECT_CALL(mock_gles_impl_ref,
527 TexSubImage2D(face_target, 0, _, _, 4, 4, _, _, _))
530 EXPECT_TRUE(command.
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.
static std::shared_ptr< MockGLES > Init(std::unique_ptr< MockGLESImpl > impl, const std::optional< std::vector< const char * > > &extensions=std::nullopt, const char *version_string="OpenGL ES 3.0")
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
uint32_t uint32_t * format
#define FML_CHECK(condition)
TEST(FrameTimingsRecorderTest, RecordVsync)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all 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
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
const ProcTableGLES::Resolver kMockResolverGLES
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)
impeller::ShaderType type
bool Encode(const ReactorGLES &reactor) const override
std::shared_ptr< Texture > destination
bool Encode(const ReactorGLES &reactor) const override
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
static constexpr TRect MakeSize(const TSize< U > &size)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...