| Flutter Impeller |

render_pass_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 <memory>
6 #include "flutter/testing/testing.h" // IWYU pragma: keep
7 #include "gmock/gmock.h"
8 #include "gtest/gtest.h"
9 #include "impeller/core/formats.h"
10 #include "impeller/renderer/backend/gles/command_buffer_gles.h"
11 #include "impeller/renderer/backend/gles/context_gles.h"
12 #include "impeller/renderer/backend/gles/proc_table_gles.h"
13 #include "impeller/renderer/backend/gles/reactor_gles.h"
14 #include "impeller/renderer/backend/gles/test/mock_gles.h"
15 #include "impeller/renderer/backend/gles/texture_gles.h"
16 #include "impeller/renderer/context.h"
17 #include "impeller/renderer/render_pass.h"
18 #include "impeller/renderer/render_target.h"
19
20 namespace impeller {
21 namespace testing {
22
23 using ::testing::_;
24 using ::testing::Args;
25 using ::testing::ElementsAreArray;
26 using ::testing::NiceMock;
27 using ::testing::Return;
28 using ::testing::SetArgPointee;
29 using ::testing::TestWithParam;
30
31 class TestReactorGLES : public ReactorGLES {
32 public:
33 TestReactorGLES()
34 : ReactorGLES(std::make_unique<ProcTableGLES>(kMockResolverGLES)) {}
35
36 ~TestReactorGLES() = default;
37 };
38
39 class MockWorker final : public ReactorGLES::Worker {
40 public:
41 MockWorker() = default;
42
43 // |ReactorGLES::Worker|
44 bool CanReactorReactOnCurrentThreadNow(
45 const ReactorGLES& reactor) const override {
46 return true;
47 }
48 };
49
50 struct DiscardFrameBufferParams {
51 GLuint frame_buffer_id;
52 std::array<GLenum, 3> expected_attachments;
53 };
54
55 class RenderPassGLESWithDiscardFrameBufferExtTest
56 : public TestWithParam<DiscardFrameBufferParams> {};
57
58 namespace {
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>>{};
62 auto flags = Flags{};
63 return ContextGLES::Create(flags, std::move(dummy_gl_procs),
64 dummy_shader_library, false);
65 }
66 } // namespace
67
68 TEST_P(RenderPassGLESWithDiscardFrameBufferExtTest, DiscardFramebufferExt) {
69 auto mock_gl_impl = std::make_unique<NiceMock<MockGLESImpl>>();
70 auto& mock_gl_impl_ref = *mock_gl_impl;
71 auto mock_gl =
72 MockGLES::Init(std::move(mock_gl_impl), {{"GL_EXT_discard_framebuffer"}});
73
74 auto context = CreateFakeGLESContext();
75 auto dummy_worker = std::make_shared<MockWorker>();
76 context->AddReactorWorker(dummy_worker);
77 auto reactor = context->GetReactor();
78
79 const auto command_buffer =
80 std::static_pointer_cast<Context>(context)->CreateCommandBuffer();
81 auto render_target = RenderTarget{};
82 const auto description = TextureDescriptor{
83 .format = PixelFormat::kR8G8B8A8UNormInt, .size = {10, 10}};
84
85 const auto& test_params = GetParam();
86 auto framebuffer_texture =
87 TextureGLES::WrapFBO(reactor, description, test_params.frame_buffer_id);
88
89 auto color_attachment = ColorAttachment{Attachment{
90 .texture = framebuffer_texture, .store_action = StoreAction::kDontCare}};
91 render_target.SetColorAttachment(color_attachment, 0);
92 const auto render_pass = command_buffer->CreateRenderPass(render_target);
93
94 EXPECT_CALL(mock_gl_impl_ref, GetIntegerv(GL_FRAMEBUFFER_BINDING, _))
95 .WillOnce(SetArgPointee<1>(test_params.frame_buffer_id));
96
97 EXPECT_CALL(mock_gl_impl_ref, DiscardFramebufferEXT(GL_FRAMEBUFFER, _, _))
98 .With(Args<2, 1>(ElementsAreArray(test_params.expected_attachments)))
99 .Times(1);
100 ASSERT_TRUE(render_pass->EncodeCommands());
101 ASSERT_TRUE(reactor->React());
102 }
103
104 INSTANTIATE_TEST_SUITE_P(
105 FrameBufferObject,
106 RenderPassGLESWithDiscardFrameBufferExtTest,
107 ::testing::ValuesIn(std::vector<DiscardFrameBufferParams>{
108 {.frame_buffer_id = 0,
109 .expected_attachments = {GL_COLOR_EXT, GL_DEPTH_EXT, GL_STENCIL_EXT}},
110 {.frame_buffer_id = 1,
111 .expected_attachments = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT,
112 GL_STENCIL_ATTACHMENT}}}),
113 [](const ::testing::TestParamInfo<DiscardFrameBufferParams>& info) {
114 return (info.param.frame_buffer_id == 0) ? "Default" : "NonDefault";
115 });
116
117 } // namespace testing
118 } // namespace impeller
impeller::ContextGLES::Create
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)
Definition: context_gles.cc:21
impeller::ProcTableGLES
Definition: proc_table_gles.h:283
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::RenderTarget
Definition: render_target.h:38
impeller::TextureGLES::WrapFBO
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.
Definition: texture_gles.cc:153
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: render_pass_gles_unittests.cc:44
impeller::testing::RenderPassGLESWithDiscardFrameBufferExtTest
Definition: render_pass_gles_unittests.cc:56
impeller::testing::TestReactorGLES::TestReactorGLES
TestReactorGLES()
Definition: render_pass_gles_unittests.cc:33
impeller::testing::TestReactorGLES::~TestReactorGLES
~TestReactorGLES()=default
command_buffer_gles.h
formats.h
impeller::testing::TEST_P
TEST_P(AiksTest, DrawAtlasNoColor)
Definition: aiks_dl_atlas_unittests.cc:59
impeller::testing::INSTANTIATE_TEST_SUITE_P
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";})
impeller
Definition: allocation.cc:12
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::StoreAction::kDontCare
@ kDontCare
std
Definition: comparable.h:95
proc_table_gles.h
reactor_gles.h
render_pass.h
render_target.h
context_gles.h
context.h
impeller::Attachment
Definition: formats.h:660
impeller::Attachment::texture
std::shared_ptr< Texture > texture
Definition: formats.h:661
impeller::ColorAttachment
Definition: formats.h:669
impeller::Flags
Definition: flags.h:9
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::format
PixelFormat format
Definition: texture_descriptor.h:41
impeller::testing::DiscardFrameBufferParams
Definition: render_pass_gles_unittests.cc:50
impeller::testing::DiscardFrameBufferParams::frame_buffer_id
GLuint frame_buffer_id
Definition: render_pass_gles_unittests.cc:51
impeller::testing::DiscardFrameBufferParams::expected_attachments
std::array< GLenum, 3 > expected_attachments
Definition: render_pass_gles_unittests.cc:52
texture_gles.h