2
* Copyright © 2012 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: Kevin DuBois <kevin.dubois@canonical.com>
19
#include "src/server/graphics/android/android_framebuffer_window.h"
21
#include "mir_test_doubles/mock_egl.h"
24
#include <system/window.h>
25
#include <gtest/gtest.h>
28
namespace mga = mir::graphics::android;
29
namespace mtd = mir::test::doubles;
31
class ANativeWindowInterface
34
virtual ~ANativeWindowInterface() = default;
35
virtual int query_interface(const ANativeWindow* win , int code, int* value) const = 0;
38
class MockANativeWindow : public ANativeWindowInterface,
45
using namespace testing;
49
ON_CALL(*this, query_interface(_,_,_))
51
SetArgPointee<2>(fake_visual_id),
55
~MockANativeWindow() noexcept {}
57
static int hook_query(const ANativeWindow* anw, int code, int *ret)
59
const MockANativeWindow* mocker = static_cast<const MockANativeWindow*>(anw);
60
return mocker->query_interface(anw, code, ret);
63
MOCK_CONST_METHOD3(query_interface,int(const ANativeWindow*,int,int*));
68
class AndroidFramebufferWindowConfigSelection : public ::testing::Test
73
using namespace testing;
75
/* silence uninteresting warning messages */
76
mock_egl.silence_uninteresting();
78
mock_anw = std::make_shared<MockANativeWindow>();
79
fb_win = std::make_shared<mga::AndroidFramebufferWindow>(mock_anw);
81
EXPECT_CALL(*mock_anw, query_interface(_,_,_))
85
std::shared_ptr<MockANativeWindow> mock_anw;
86
std::shared_ptr<mga::AndroidFramebufferWindow> fb_win;
87
mtd::MockEGL mock_egl;
90
TEST_F(AndroidFramebufferWindowConfigSelection, queries_for_native_visual_id)
92
using namespace testing;
93
EXPECT_CALL(*mock_anw, query_interface(_,NATIVE_WINDOW_FORMAT,_))
96
fb_win->android_display_egl_config(mock_egl.fake_egl_display);
99
TEST_F(AndroidFramebufferWindowConfigSelection, eglChooseConfig_attr_is_terminated_by_null)
101
using namespace testing;
105
EXPECT_CALL(mock_egl, eglChooseConfig(mock_egl.fake_egl_display, _, _, _, _))
109
SetArgPointee<2>(mock_egl.fake_configs),
110
SetArgPointee<4>(mock_egl.fake_configs_num),
113
fb_win->android_display_egl_config(mock_egl.fake_egl_display);
116
while(attr[i++] != EGL_NONE);
121
TEST_F(AndroidFramebufferWindowConfigSelection, eglChooseConfig_attr_contains_window_bit)
123
using namespace testing;
127
EXPECT_CALL(mock_egl, eglChooseConfig(mock_egl.fake_egl_display, _, _, _, _))
131
SetArgPointee<2>(mock_egl.fake_configs),
132
SetArgPointee<4>(mock_egl.fake_configs_num),
135
fb_win->android_display_egl_config(mock_egl.fake_egl_display);
138
bool validated = false;
139
while(attr[i] != EGL_NONE)
141
if ((attr[i] == EGL_SURFACE_TYPE) && (attr[i+1] == EGL_WINDOW_BIT))
149
EXPECT_TRUE(validated);
152
TEST_F(AndroidFramebufferWindowConfigSelection, eglChooseConfig_attr_requests_ogl2)
154
using namespace testing;
158
EXPECT_CALL(mock_egl, eglChooseConfig(mock_egl.fake_egl_display, _, _, _, _))
162
SetArgPointee<2>(mock_egl.fake_configs),
163
SetArgPointee<4>(mock_egl.fake_configs_num),
166
fb_win->android_display_egl_config(mock_egl.fake_egl_display);
169
bool validated = false;
170
while(attr[i] != EGL_NONE)
172
if ((attr[i] == EGL_RENDERABLE_TYPE) && (attr[i+1] == EGL_OPENGL_ES2_BIT))
180
EXPECT_TRUE(validated);
183
TEST_F(AndroidFramebufferWindowConfigSelection, queries_with_enough_room_for_all_potential_cfg)
185
using namespace testing;
190
EXPECT_CALL(mock_egl, eglGetConfigs(mock_egl.fake_egl_display, NULL, 0, _))
193
SetArgPointee<3>(num_cfg),
196
EXPECT_CALL(mock_egl, eglChooseConfig(mock_egl.fake_egl_display, _, _, num_cfg, _))
200
SetArgPointee<2>(mock_egl.fake_configs),
201
SetArgPointee<4>(mock_egl.fake_configs_num),
204
fb_win->android_display_egl_config(mock_egl.fake_egl_display);
206
/* should be able to ref this spot */
207
EGLint test_last_spot = attr[num_cfg-1];
208
EXPECT_EQ(test_last_spot, test_last_spot);
212
TEST_F(AndroidFramebufferWindowConfigSelection, creates_with_proper_visual_id)
214
using namespace testing;
216
EGLConfig cfg, chosen_cfg;
218
EXPECT_CALL(mock_egl, eglGetConfigAttrib(mock_egl.fake_egl_display, _, EGL_NATIVE_VISUAL_ID, _))
220
.WillRepeatedly(DoAll(
221
SetArgPointee<3>(mock_anw->fake_visual_id),
225
chosen_cfg = fb_win->android_display_egl_config(mock_egl.fake_egl_display);
227
EXPECT_EQ(cfg, chosen_cfg);
230
TEST_F(AndroidFramebufferWindowConfigSelection, creates_with_proper_visual_id_mixed_valid_invalid)
232
using namespace testing;
234
EGLConfig cfg, chosen_cfg;
236
int bad_id = mock_anw->fake_visual_id + 1;
238
EXPECT_CALL(mock_egl, eglGetConfigAttrib(mock_egl.fake_egl_display, _, EGL_NATIVE_VISUAL_ID, _))
241
SetArgPointee<3>(bad_id),
244
SetArgPointee<3>(mock_anw->fake_visual_id),
247
.WillRepeatedly(DoAll(
248
SetArgPointee<3>(bad_id),
251
chosen_cfg = fb_win->android_display_egl_config(mock_egl.fake_egl_display);
253
EXPECT_EQ(cfg, chosen_cfg);
256
TEST_F(AndroidFramebufferWindowConfigSelection, without_proper_visual_id_throws)
258
using namespace testing;
262
int bad_id = mock_anw->fake_visual_id + 1;
263
EXPECT_CALL(mock_egl, eglGetConfigAttrib(mock_egl.fake_egl_display, _, EGL_NATIVE_VISUAL_ID, _))
265
.WillRepeatedly(DoAll(
266
SetArgPointee<3>(bad_id),
272
fb_win->android_display_egl_config(mock_egl.fake_egl_display);
273
}, std::runtime_error );
276
TEST_F(AndroidFramebufferWindowConfigSelection, anw_is_not_null)
278
using namespace testing;
280
auto win_handle = fb_win->android_native_window_type();
282
EXPECT_NE(win_handle, (EGLNativeWindowType) NULL);