6 #include "flutter/testing/testing.h"
7 #include "gmock/gmock.h"
8 #include "gtest/gtest.h"
14 #include "impeller/renderer/backend/gles/test/mock_gles.h"
24 using ::testing::Args;
25 using ::testing::ElementsAreArray;
26 using ::testing::NiceMock;
27 using ::testing::Return;
28 using ::testing::SetArgPointee;
29 using ::testing::TestWithParam;
31 class TestReactorGLES :
public ReactorGLES {
56 :
public TestWithParam<DiscardFrameBufferParams> {};
59 std::shared_ptr<ContextGLES> CreateFakeGLESContext() {
60 auto dummy_gl_procs = std::make_unique<ProcTableGLES>(kMockResolverGLES);
61 auto dummy_shader_library = std::vector<std::shared_ptr<fml::Mapping>>{};
64 dummy_shader_library,
false);
69 auto mock_gl_impl = std::make_unique<NiceMock<MockGLESImpl>>();
70 auto& mock_gl_impl_ref = *mock_gl_impl;
72 MockGLES::Init(std::move(mock_gl_impl), {{
"GL_EXT_discard_framebuffer"}},
75 auto context = CreateFakeGLESContext();
76 auto dummy_worker = std::make_shared<MockWorker>();
77 context->AddReactorWorker(dummy_worker);
78 auto reactor = context->GetReactor();
80 const auto command_buffer =
81 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
86 const auto& test_params = GetParam();
87 auto framebuffer_texture =
92 render_target.SetColorAttachment(color_attachment, 0);
93 const auto render_pass = command_buffer->CreateRenderPass(render_target);
95 EXPECT_CALL(mock_gl_impl_ref, GetIntegerv(GL_FRAMEBUFFER_BINDING, _))
96 .WillOnce(SetArgPointee<1>(test_params.frame_buffer_id));
98 EXPECT_CALL(mock_gl_impl_ref, DiscardFramebufferEXT(GL_FRAMEBUFFER, _, _))
99 .With(Args<2, 1>(ElementsAreArray(test_params.expected_attachments)))
101 ASSERT_TRUE(render_pass->EncodeCommands());
102 ASSERT_TRUE(reactor->React());
108 ::testing::ValuesIn(std::vector<DiscardFrameBufferParams>{
109 {.frame_buffer_id = 0,
110 .expected_attachments = {GL_COLOR_EXT, GL_DEPTH_EXT, GL_STENCIL_EXT}},
111 {.frame_buffer_id = 1,
112 .expected_attachments = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT,
113 GL_STENCIL_ATTACHMENT}}}),
114 [](const ::testing::TestParamInfo<DiscardFrameBufferParams>& info) {
115 return (info.param.frame_buffer_id == 0) ?
"Default" :
"NonDefault";
119 auto mock_gl_impl = std::make_unique<NiceMock<MockGLESImpl>>();
120 auto& mock_gl_impl_ref = *mock_gl_impl;
122 MockGLES::Init(std::move(mock_gl_impl), std::nullopt,
"OpenGL ES 3.0");
124 auto context = CreateFakeGLESContext();
125 auto dummy_worker = std::make_shared<MockWorker>();
126 context->AddReactorWorker(dummy_worker);
127 auto reactor = context->GetReactor();
129 const auto command_buffer =
130 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
135 const auto& test_params = GetParam();
136 auto framebuffer_texture =
141 render_target.SetColorAttachment(color_attachment, 0);
142 const auto render_pass = command_buffer->CreateRenderPass(render_target);
144 EXPECT_CALL(mock_gl_impl_ref, GetIntegerv(GL_FRAMEBUFFER_BINDING, _))
145 .WillOnce(SetArgPointee<1>(test_params.frame_buffer_id));
148 EXPECT_CALL(mock_gl_impl_ref, InvalidateFramebuffer(GL_FRAMEBUFFER, _, _))
149 .With(Args<2, 1>(ElementsAreArray(test_params.expected_attachments)))
151 EXPECT_CALL(mock_gl_impl_ref, DiscardFramebufferEXT(GL_FRAMEBUFFER, _, _))
154 ASSERT_TRUE(render_pass->EncodeCommands());
155 ASSERT_TRUE(reactor->React());
158 TEST(RenderPassGLESTest, ResolvingMultisampleTextureCachesResolveFBO) {
159 auto mock_gl_impl = std::make_unique<NiceMock<MockGLESImpl>>();
160 auto& mock_gl_impl_ref = *mock_gl_impl;
163 MockGLES::Init(std::move(mock_gl_impl), std::nullopt,
"OpenGL ES 3.0");
165 auto context = CreateFakeGLESContext();
166 auto dummy_worker = std::make_shared<MockWorker>();
167 context->AddReactorWorker(dummy_worker);
168 auto reactor = context->GetReactor();
170 const auto command_buffer =
171 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
173 const auto msaa_desc =
179 const auto resolve_desc =
187 auto msaa_tex = std::make_shared<TextureGLES>(reactor, msaa_desc);
188 auto resolve_tex = std::make_shared<TextureGLES>(reactor, resolve_desc);
193 .resolve_texture = resolve_tex,
198 render_target.SetColorAttachment(color_attachment, 0);
200 EXPECT_CALL(mock_gl_impl_ref, CheckFramebufferStatus(_))
201 .WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE));
205 EXPECT_CALL(mock_gl_impl_ref, GenFramebuffers(_, _)).Times(2);
208 const auto render_pass = command_buffer->CreateRenderPass(render_target);
209 ASSERT_TRUE(render_pass->EncodeCommands());
210 ASSERT_TRUE(reactor->React());
213 const auto render_pass2 = command_buffer->CreateRenderPass(render_target);
214 ASSERT_TRUE(render_pass2->EncodeCommands());
215 ASSERT_TRUE(reactor->React());
static std::shared_ptr< ContextGLES > Create(const Flags &flags, std::unique_ptr< ProcTableGLES > gl, const std::vector< std::shared_ptr< fml::Mapping >> &shader_libraries, bool enable_gpu_tracing)
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< TextureGLES > WrapFBO(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, GLuint fbo)
Create a texture by wrapping an external framebuffer object whose lifecycle is owned by the caller.
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)
TEST_P(AiksTest, DrawAtlasNoColor)
INSTANTIATE_TEST_SUITE_P(FrameBufferObject, RenderPassGLESWithDiscardFrameBufferExtTest, ::testing::ValuesIn(std::vector< DiscardFrameBufferParams >{ {.frame_buffer_id=0,.expected_attachments={GL_COLOR_EXT, GL_DEPTH_EXT, GL_STENCIL_EXT}}, {.frame_buffer_id=1,.expected_attachments={GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}}}), [](const ::testing::TestParamInfo< DiscardFrameBufferParams > &info) { return(info.param.frame_buffer_id==0) ? "Default" :"NonDefault";})
std::shared_ptr< Texture > texture
static constexpr Color Black()
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
std::array< GLenum, 3 > expected_attachments