7#include "gmock/gmock.h"
8#include "gtest/gtest.h"
27using ::testing::ElementsAreArray;
28using ::testing::NiceMock;
29using ::testing::Return;
30using ::testing::SetArgPointee;
31using ::testing::TestWithParam;
33class TestReactorGLES :
public ReactorGLES {
58 :
public TestWithParam<DiscardFrameBufferParams> {};
61std::shared_ptr<ContextGLES> CreateFakeGLESContext() {
63 auto dummy_shader_library = std::vector<std::shared_ptr<fml::Mapping>>{};
66 dummy_shader_library,
false);
71 auto mock_gl_impl = std::make_unique<NiceMock<MockGLESImpl>>();
72 auto& mock_gl_impl_ref = *mock_gl_impl;
74 MockGLES::Init(std::move(mock_gl_impl), {{
"GL_EXT_discard_framebuffer"}},
77 auto context = CreateFakeGLESContext();
78 auto dummy_worker = std::make_shared<MockWorker>();
79 context->AddReactorWorker(dummy_worker);
80 auto reactor = context->GetReactor();
82 const auto command_buffer =
83 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
88 const auto& test_params = GetParam();
89 auto framebuffer_texture =
94 render_target.SetColorAttachment(color_attachment, 0);
95 const auto render_pass = command_buffer->CreateRenderPass(render_target);
97 EXPECT_CALL(mock_gl_impl_ref, GetIntegerv(GL_FRAMEBUFFER_BINDING, _))
98 .WillOnce(SetArgPointee<1>(test_params.frame_buffer_id));
100 EXPECT_CALL(mock_gl_impl_ref, DiscardFramebufferEXT(GL_FRAMEBUFFER, _, _))
101 .With(Args<2, 1>(ElementsAreArray(test_params.expected_attachments)))
103 ASSERT_TRUE(render_pass->EncodeCommands());
104 ASSERT_TRUE(reactor->React());
110 ::testing::ValuesIn(std::vector<DiscardFrameBufferParams>{
111 {.frame_buffer_id = 0,
112 .expected_attachments = {GL_COLOR_EXT, GL_DEPTH_EXT, GL_STENCIL_EXT}},
113 {.frame_buffer_id = 1,
114 .expected_attachments = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT,
115 GL_STENCIL_ATTACHMENT}}}),
116 [](const ::testing::TestParamInfo<DiscardFrameBufferParams>& info) {
117 return (info.param.frame_buffer_id == 0) ?
"Default" :
"NonDefault";
121 auto mock_gl_impl = std::make_unique<NiceMock<MockGLESImpl>>();
122 auto& mock_gl_impl_ref = *mock_gl_impl;
124 MockGLES::Init(std::move(mock_gl_impl), std::nullopt,
"OpenGL ES 3.0");
126 auto context = CreateFakeGLESContext();
127 auto dummy_worker = std::make_shared<MockWorker>();
128 context->AddReactorWorker(dummy_worker);
129 auto reactor = context->GetReactor();
131 const auto command_buffer =
132 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
137 const auto& test_params = GetParam();
138 auto framebuffer_texture =
143 render_target.SetColorAttachment(color_attachment, 0);
144 const auto render_pass = command_buffer->CreateRenderPass(render_target);
146 EXPECT_CALL(mock_gl_impl_ref, GetIntegerv(GL_FRAMEBUFFER_BINDING, _))
147 .WillOnce(SetArgPointee<1>(test_params.frame_buffer_id));
150 EXPECT_CALL(mock_gl_impl_ref, InvalidateFramebuffer(GL_FRAMEBUFFER, _, _))
151 .With(Args<2, 1>(ElementsAreArray(test_params.expected_attachments)))
153 EXPECT_CALL(mock_gl_impl_ref, DiscardFramebufferEXT(GL_FRAMEBUFFER, _, _))
156 ASSERT_TRUE(render_pass->EncodeCommands());
157 ASSERT_TRUE(reactor->React());
160TEST(RenderPassGLESTest, ResolvingMultisampleTextureCachesResolveFBO) {
161 auto mock_gl_impl = std::make_unique<NiceMock<MockGLESImpl>>();
162 auto& mock_gl_impl_ref = *mock_gl_impl;
165 MockGLES::Init(std::move(mock_gl_impl), std::nullopt,
"OpenGL ES 3.0");
167 auto context = CreateFakeGLESContext();
168 auto dummy_worker = std::make_shared<MockWorker>();
169 context->AddReactorWorker(dummy_worker);
170 auto reactor = context->GetReactor();
172 const auto command_buffer =
173 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
175 const auto msaa_desc =
181 const auto resolve_desc =
189 auto msaa_tex = std::make_shared<TextureGLES>(reactor, msaa_desc);
190 auto resolve_tex = std::make_shared<TextureGLES>(reactor, resolve_desc);
195 .resolve_texture = resolve_tex,
200 render_target.SetColorAttachment(color_attachment, 0);
202 EXPECT_CALL(mock_gl_impl_ref, CheckFramebufferStatus(_))
203 .WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE));
207 EXPECT_CALL(mock_gl_impl_ref, GenFramebuffers(_, _)).Times(2);
210 const auto render_pass = command_buffer->CreateRenderPass(render_target);
211 ASSERT_TRUE(render_pass->EncodeCommands());
212 ASSERT_TRUE(reactor->React());
215 const auto render_pass2 = command_buffer->CreateRenderPass(render_target);
216 ASSERT_TRUE(render_pass2->EncodeCommands());
217 ASSERT_TRUE(reactor->React());
235 std::unique_ptr<NiceMock<MockGLESImpl>> mock_gl_impl =
236 std::make_unique<NiceMock<MockGLESImpl>>();
237 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = *mock_gl_impl;
238 std::shared_ptr<MockGLES> mock_gl =
MockGLES::Init(std::move(mock_gl_impl));
240 std::shared_ptr<ContextGLES> context = CreateFakeGLESContext();
241 std::shared_ptr<MockWorker> dummy_worker = std::make_shared<MockWorker>();
242 context->AddReactorWorker(dummy_worker);
243 std::shared_ptr<ReactorGLES> reactor = context->GetReactor();
246 tex_desc.
size = {100, 100};
248 auto texture = std::make_shared<TextureGLES>(reactor, tex_desc,
false);
255 target.SetColorAttachment(color0, 0);
257 std::shared_ptr<CommandBuffer> command_buffer =
258 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
259 std::shared_ptr<RenderPass> render_pass =
260 command_buffer->CreateRenderPass(
target);
262 EXPECT_CALL(mock_gl_impl_ref, CheckFramebufferStatus(_))
263 .WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE));
271 std::shared_ptr<PipelineGLES> pipeline =
273 reactor, std::weak_ptr<PipelineLibrary>(), desc,
274 std::make_shared<UniqueHandleGLES>(reactor, pipeline_handle)));
275 pipeline->buffer_bindings_ = std::make_unique<BufferBindingsGLES>();
277 return {std::move(mock_gl), mock_gl_impl_ref,
278 std::move(context), std::move(dummy_worker),
279 std::move(reactor), std::move(command_buffer),
280 std::move(render_pass), std::move(pipeline)};
285 auto ctx = CreateRenderPassGLESContext();
286 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
287 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
288 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
289 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
292 render_pass->SetElementCount(1);
294 EXPECT_TRUE(render_pass->Draw().ok());
297 render_pass->SetElementCount(1);
299 render_pass->SetViewport(
301 EXPECT_TRUE(render_pass->Draw().ok());
304 render_pass->SetElementCount(1);
306 render_pass->SetViewport(
308 EXPECT_TRUE(render_pass->Draw().ok());
312 EXPECT_CALL(mock_gl_impl_ref,
Viewport(_, _, _, _)).Times(0);
313 EXPECT_CALL(mock_gl_impl_ref,
Viewport(0, 0, 100, 100)).Times(1);
314 EXPECT_CALL(mock_gl_impl_ref,
Viewport(0, 50, 50, 50)).Times(1);
316 EXPECT_TRUE(render_pass->EncodeCommands());
317 EXPECT_TRUE(reactor->React());
321 CommandsWithoutViewportGetRenderPassViewport) {
322 auto ctx = CreateRenderPassGLESContext();
323 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
324 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
325 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
326 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
329 render_pass->SetElementCount(1);
331 EXPECT_TRUE(render_pass->Draw().ok());
334 render_pass->SetElementCount(1);
336 render_pass->SetViewport(
338 EXPECT_TRUE(render_pass->Draw().ok());
341 render_pass->SetElementCount(1);
343 EXPECT_TRUE(render_pass->Draw().ok());
345 EXPECT_CALL(mock_gl_impl_ref,
Viewport(_, _, _, _)).Times(0);
346 EXPECT_CALL(mock_gl_impl_ref,
Viewport(0, 0, 100, 100)).Times(2);
347 EXPECT_CALL(mock_gl_impl_ref,
Viewport(0, 50, 50, 50)).Times(1);
349 EXPECT_TRUE(render_pass->EncodeCommands());
350 EXPECT_TRUE(reactor->React());
357 auto ctx = CreateRenderPassGLESContext();
358 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref;
359 std::shared_ptr<RenderPass>& render_pass = ctx.render_pass;
360 std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline;
361 std::shared_ptr<ReactorGLES>& reactor = ctx.reactor;
364 render_pass->SetElementCount(1);
366 render_pass->SetViewport(
368 EXPECT_TRUE(render_pass->Draw().ok());
370 EXPECT_CALL(mock_gl_impl_ref,
Viewport(_, _, _, _)).Times(0);
371 EXPECT_CALL(mock_gl_impl_ref,
Viewport(25, 0, 50, 100)).Times(1);
373 EXPECT_TRUE(render_pass->EncodeCommands());
374 EXPECT_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)
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
PipelineDescriptor & SetColorAttachmentDescriptor(size_t index, ColorAttachmentDescriptor desc)
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.
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 ...
RenderPassGLESContext CreateRenderPassGLESContext()
~TestReactorGLES()=default
TEST(FrameTimingsRecorderTest, RecordVsync)
TEST_P(AiksTest, DrawAtlasNoColor)
const ProcTableGLES::Resolver kMockResolverGLES
TEST_F(GoldenTests, ConicalGradient)
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";})
@ kNone
Does not use the index buffer.
raw_ptr< Pipeline< PipelineDescriptor > > PipelineRef
A raw ptr to a pipeline object.
std::shared_ptr< Texture > texture
Describe the color attachment that will be used with this pipeline.
static constexpr Color Black()
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
std::array< GLenum, 3 > expected_attachments
std::shared_ptr< CommandBuffer > command_buffer
std::shared_ptr< ReactorGLES > reactor
std::shared_ptr< PipelineGLES > pipeline
std::shared_ptr< RenderPass > render_pass
testing::NiceMock< MockGLESImpl > & mock_gl_impl_ref
std::shared_ptr< ContextGLES > context
std::shared_ptr< MockGLES > mock_gl
std::shared_ptr< MockWorker > dummy_worker