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"
9 #include "impeller/renderer/backend/gles/test/mock_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:
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|
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;
61  src_tex_desc.size = {10, 10};
62  src_tex_desc.usage =
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 
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
A delegate implemented by a thread on which an OpenGL context is current. There may be multiple worke...
Definition: reactor_gles.h:69
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
Definition: reactor_gles.h:57
bool CanReactorReactOnCurrentThreadNow(const ReactorGLES &reactor) const override
Determines the ability of the worker to service a reaction on the current thread. The OpenGL context ...
TEST(AllocationSizeTest, CanCreateTypedAllocations)
Definition: comparable.h:95
bool Encode(const ReactorGLES &reactor) const override
std::shared_ptr< DeviceBuffer > destination
Definition: blit_command.h:33
std::shared_ptr< Texture > source
Definition: blit_command.h:32
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...