| Flutter Impeller |

blit_command_gles_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" // IWYU pragma: keep
6 #include "gtest/gtest.h"
7 #include "impeller/renderer/backend/gles/blit_command_gles.h"
8 #include "impeller/renderer/backend/gles/device_buffer_gles.h"
9 #include "impeller/renderer/backend/gles/test/mock_gles.h"
10 #include "impeller/renderer/backend/gles/texture_gles.h"
11
12 namespace impeller {
13 namespace testing {
14
15 using ::testing::_;
16 using ::testing::Return;
17
18 class TestReactorGLES : public ReactorGLES {
19 public:
20 TestReactorGLES()
21 : ReactorGLES(std::make_unique<ProcTableGLES>(kMockResolverGLES)) {}
22
23 ~TestReactorGLES() = default;
24 };
25
26 class MockWorker final : public ReactorGLES::Worker {
27 public:
28 MockWorker() = default;
29
30 // |ReactorGLES::Worker|
31 bool CanReactorReactOnCurrentThreadNow(
32 const ReactorGLES& reactor) const override {
33 return true;
34 }
35 };
36
37 // This test makes sure we bind to GL_FRAMEBUFFER so that it's compatible for
38 // OpenGLES 2 and OpenGLES 3.
39 TEST(BlitCommandGLESTest, BlitCopyTextureToBufferCommandGLESBindsFramebuffer) {
40 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
41 auto& mock_gles_impl_ref = *mock_gles_impl;
42
43 EXPECT_CALL(mock_gles_impl_ref, GenFramebuffers(1, _))
44 .WillOnce(::testing::SetArgPointee<1>(3));
45 EXPECT_CALL(mock_gles_impl_ref, GenTextures(1, _))
46 .WillOnce(::testing::SetArgPointee<1>(1));
47 EXPECT_CALL(mock_gles_impl_ref, BindFramebuffer(GL_FRAMEBUFFER, 3)).Times(1);
48 EXPECT_CALL(mock_gles_impl_ref, CheckFramebufferStatus(GL_FRAMEBUFFER))
49 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
50 EXPECT_CALL(mock_gles_impl_ref, ReadPixels(_, _, _, _, _, _, _)).Times(1);
51 EXPECT_CALL(mock_gles_impl_ref, BindFramebuffer(GL_FRAMEBUFFER, 0)).Times(1);
52
53 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
54 auto reactor = std::make_shared<TestReactorGLES>();
55 auto worker = std::make_shared<MockWorker>();
56 reactor->AddWorker(worker);
57
58 // Create source texture.
59 TextureDescriptor src_tex_desc;
60 src_tex_desc.format = PixelFormat::kR8G8B8A8UNormInt;
61 src_tex_desc.size = {10, 10};
62 src_tex_desc.usage =
63 static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
64 auto source_texture = std::make_shared<TextureGLES>(reactor, src_tex_desc);
65 // Avoids the flip which would crash.
66 source_texture->SetCoordinateSystem(TextureCoordinateSystem::kUploadFromHost);
67
68 // Create destination buffer.
69 DeviceBufferDescriptor dest_buffer_desc;
70 dest_buffer_desc.size = 10 * 10 * 4;
71 dest_buffer_desc.storage_mode = StorageMode::kHostVisible;
72 auto allocation = std::make_shared<Allocation>();
73 ASSERT_TRUE(allocation->Truncate(Bytes(dest_buffer_desc.size)));
74 auto dest_buffer =
75 std::make_shared<DeviceBufferGLES>(dest_buffer_desc, reactor, allocation);
76
77 ASSERT_TRUE(reactor->React());
78
79 BlitCopyTextureToBufferCommandGLES command;
80 command.source = source_texture;
81 command.destination = dest_buffer;
82 command.source_region =
83 IRect::MakeSize(source_texture->GetTextureDescriptor().size);
84 command.label = "TestBlit";
85
86 EXPECT_TRUE(command.Encode(*reactor));
87
88 source_texture.reset();
89 dest_buffer.reset();
90
91 ASSERT_TRUE(reactor->React());
92 }
93
94 } // namespace testing
95 } // namespace impeller
blit_command_gles.h
impeller::AllocationSize< 1u >
impeller::ProcTableGLES
Definition: proc_table_gles.h:282
impeller::ReactorGLES::Worker
A delegate implemented by a thread on which an OpenGL context is current. There may be multiple worke...
Definition: reactor_gles.h:69
impeller::ReactorGLES
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
Definition: reactor_gles.h:57
impeller::testing::MockWorker
Definition: blit_command_gles_unittests.cc:26
impeller::testing::MockWorker::MockWorker
MockWorker()=default
impeller::testing::MockWorker::CanReactorReactOnCurrentThreadNow
bool CanReactorReactOnCurrentThreadNow(const ReactorGLES &reactor) const override
Determines the ability of the worker to service a reaction on the current thread. The OpenGL context ...
Definition: blit_command_gles_unittests.cc:31
impeller::testing::TestReactorGLES
Definition: blit_command_gles_unittests.cc:18
impeller::testing::TestReactorGLES::TestReactorGLES
TestReactorGLES()
Definition: blit_command_gles_unittests.cc:20
impeller::testing::TestReactorGLES::~TestReactorGLES
~TestReactorGLES()=default
device_buffer_gles.h
impeller::testing::TEST
TEST(AllocationSizeTest, CanCreateTypedAllocations)
Definition: allocation_size_unittests.cc:10
impeller
Definition: allocation.cc:12
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::TextureCoordinateSystem::kUploadFromHost
@ kUploadFromHost
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
std
Definition: comparable.h:95
impeller::BlitCommand::label
std::string label
Definition: blit_command.h:16
impeller::BlitCopyTextureToBufferCommandGLES
Definition: blit_command_gles.h:45
impeller::BlitCopyTextureToBufferCommandGLES::Encode
bool Encode(const ReactorGLES &reactor) const override
Definition: blit_command_gles.cc:335
impeller::BlitCopyTextureToBufferCommand::destination
std::shared_ptr< DeviceBuffer > destination
Definition: blit_command.h:33
impeller::BlitCopyTextureToBufferCommand::source
std::shared_ptr< Texture > source
Definition: blit_command.h:32
impeller::BlitCopyTextureToBufferCommand::source_region
IRect source_region
Definition: blit_command.h:34
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
impeller::DeviceBufferDescriptor::storage_mode
StorageMode storage_mode
Definition: device_buffer_descriptor.h:15
impeller::DeviceBufferDescriptor::size
size_t size
Definition: device_buffer_descriptor.h:16
impeller::Mask< TextureUsage >
impeller::TRect::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
impeller::TextureDescriptor::usage
TextureUsageMask usage
Definition: texture_descriptor.h:44
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:42
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:41
texture_gles.h