2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
19
#include "src/server/compositor/screencast_display_buffer.h"
21
#include "mir_test_doubles/mock_buffer.h"
22
#include "mir_test_doubles/stub_buffer.h"
23
#include "mir_test_doubles/mock_gl.h"
24
#include "mir_test_doubles/stub_renderable.h"
26
#include <gtest/gtest.h>
27
#include <gmock/gmock.h>
29
namespace mc = mir::compositor;
30
namespace mtd = mir::test::doubles;
31
namespace geom = mir::geometry;
32
namespace mg = mir::graphics;
37
struct MockRenderFunctor
39
void operator()(mg::Renderable const& r)
44
MOCK_METHOD1(operator_call, void(mg::Renderable const*));
47
struct ScreencastDisplayBufferTest : testing::Test
49
testing::NiceMock<mtd::MockGL> mock_gl;
54
TEST_F(ScreencastDisplayBufferTest, cleans_up_gl_resources)
56
using namespace testing;
57
GLuint const texture{11};
58
GLuint const renderbuffer{12};
59
GLuint const framebuffer{13};
61
EXPECT_CALL(mock_gl, glGenTextures(1,_))
62
.WillOnce(SetArgPointee<1>(texture));
63
EXPECT_CALL(mock_gl, glGenRenderbuffers(1,_))
64
.WillOnce(SetArgPointee<1>(renderbuffer));
65
EXPECT_CALL(mock_gl, glGenFramebuffers(1,_))
66
.WillOnce(SetArgPointee<1>(framebuffer));
68
EXPECT_CALL(mock_gl, glDeleteTextures(1,Pointee(texture)));
69
EXPECT_CALL(mock_gl, glDeleteRenderbuffers(1,Pointee(renderbuffer)));
70
EXPECT_CALL(mock_gl, glDeleteFramebuffers(1,Pointee(framebuffer)));
72
geom::Rectangle const rect{{100,100}, {800,600}};
73
mtd::StubBuffer stub_buffer;
75
mc::ScreencastDisplayBuffer db{rect, stub_buffer};
78
TEST_F(ScreencastDisplayBufferTest, cleans_up_gl_resources_on_construction_failure)
80
using namespace testing;
81
GLuint const texture{11};
82
GLuint const renderbuffer{12};
83
GLuint const framebuffer{13};
85
EXPECT_CALL(mock_gl, glGenTextures(1,_))
86
.WillOnce(SetArgPointee<1>(texture));
87
EXPECT_CALL(mock_gl, glGenRenderbuffers(1,_))
88
.WillOnce(SetArgPointee<1>(renderbuffer));
89
EXPECT_CALL(mock_gl, glGenFramebuffers(1,_))
90
.WillOnce(SetArgPointee<1>(framebuffer));
92
EXPECT_CALL(mock_gl, glCheckFramebufferStatus(_))
93
.WillOnce(Return(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT));
95
EXPECT_CALL(mock_gl, glDeleteTextures(1,Pointee(texture)));
96
EXPECT_CALL(mock_gl, glDeleteRenderbuffers(1,Pointee(renderbuffer)));
97
EXPECT_CALL(mock_gl, glDeleteFramebuffers(1,Pointee(framebuffer)));
99
geom::Rectangle const rect{{100,100}, {800,600}};
100
mtd::StubBuffer stub_buffer;
103
mc::ScreencastDisplayBuffer db(rect, stub_buffer);
104
}, std::runtime_error);
107
TEST_F(ScreencastDisplayBufferTest, renders_to_supplied_buffer)
109
using namespace testing;
111
geom::Rectangle const rect{{100,100}, {800,600}};
112
testing::NiceMock<mtd::MockBuffer> mock_buffer{
113
rect.size, geom::Stride{100}, mir_pixel_format_xbgr_8888};
116
/* Set the buffer as rendering target */
117
EXPECT_CALL(mock_buffer, bind_to_texture());
120
mock_buffer.size().width.as_int(),
121
mock_buffer.size().height.as_int()));
122
/* Restore previous viewport on exit */
123
EXPECT_CALL(mock_gl, glViewport(0, 0, 0, 0));
125
mc::ScreencastDisplayBuffer db{rect, mock_buffer};
129
TEST_F(ScreencastDisplayBufferTest, forces_rendering_to_complete_on_post_update)
131
using namespace testing;
133
geom::Rectangle const rect{{100,100}, {800,600}};
134
mtd::StubBuffer stub_buffer;
136
mc::ScreencastDisplayBuffer db{rect, stub_buffer};
138
Mock::VerifyAndClearExpectations(&mock_gl);
139
EXPECT_CALL(mock_gl, glFinish());
144
TEST_F(ScreencastDisplayBufferTest, renders_renderables_on_render_and_post_update)
146
using namespace testing;
148
geom::Rectangle const rect{{100,100}, {800,600}};
149
mtd::StubBuffer stub_buffer;
151
std::list<std::shared_ptr<mg::Renderable>> renderables{
152
std::make_shared<mtd::StubRenderable>(),
153
std::make_shared<mtd::StubRenderable>(),
154
std::make_shared<mtd::StubRenderable>()};
156
mc::ScreencastDisplayBuffer db{rect, stub_buffer};
158
Mock::VerifyAndClearExpectations(&mock_gl);
159
MockRenderFunctor mock_render_functor;
163
for (auto const& renderable : renderables)
164
EXPECT_CALL(mock_render_functor, operator_call(renderable.get()));
166
EXPECT_CALL(mock_gl, glFinish());
168
db.render_and_post_update(renderables, std::ref(mock_render_functor));