1
#include "mir/graphics/basic_platform.h"
2
#include "src/server/graphics/offscreen/display.h"
3
#include "mir/graphics/null_display_report.h"
4
#include "src/server/graphics/default_display_configuration_policy.h"
5
#include "mir/graphics/display_buffer.h"
7
#include "mir_test_doubles/mock_egl.h"
8
#include "mir_test_doubles/mock_gl.h"
10
#include <gmock/gmock.h>
11
#include <gtest/gtest.h>
15
namespace mg=mir::graphics;
16
namespace mgo=mir::graphics::offscreen;
17
namespace mtd=mir::test::doubles;
22
class StubBasicPlatform : public mg::BasicPlatform
25
StubBasicPlatform(EGLNativeDisplayType native_display)
26
: native_display{native_display}
30
EGLNativeDisplayType egl_native_display() const
32
return native_display;
36
EGLNativeDisplayType const native_display;
39
class OffscreenDisplayTest : public ::testing::Test
42
OffscreenDisplayTest()
44
using namespace ::testing;
46
ON_CALL(mock_egl, eglChooseConfig(_,_,_,1,_))
47
.WillByDefault(DoAll(SetArgPointee<2>(mock_egl.fake_configs[0]),
51
const char* const egl_exts = "EGL_KHR_image EGL_KHR_image_base";
52
const char* const gl_exts = "GL_OES_EGL_image";
54
ON_CALL(mock_egl, eglQueryString(_,EGL_EXTENSIONS))
55
.WillByDefault(Return(egl_exts));
56
ON_CALL(mock_gl, glGetString(GL_EXTENSIONS))
57
.WillByDefault(Return(reinterpret_cast<const GLubyte*>(gl_exts)));
58
ON_CALL(mock_gl, glCheckFramebufferStatus(_))
59
.WillByDefault(Return(GL_FRAMEBUFFER_COMPLETE));
62
::testing::NiceMock<mtd::MockEGL> mock_egl;
63
::testing::NiceMock<mtd::MockGL> mock_gl;
68
TEST_F(OffscreenDisplayTest, uses_basic_platform_egl_native_display)
70
using namespace ::testing;
72
EGLNativeDisplayType const native_display{
73
reinterpret_cast<EGLNativeDisplayType>(0x12345)};
76
EXPECT_CALL(mock_egl, eglGetDisplay(native_display));
77
EXPECT_CALL(mock_egl, eglInitialize(mock_egl.fake_egl_display, _, _));
78
EXPECT_CALL(mock_egl, eglTerminate(mock_egl.fake_egl_display));
81
std::make_shared<StubBasicPlatform>(native_display),
82
std::make_shared<mg::DefaultDisplayConfigurationPolicy>(),
83
std::make_shared<mg::NullDisplayReport>()};
86
TEST_F(OffscreenDisplayTest, makes_fbo_current_rendering_target)
88
using namespace ::testing;
91
EGLNativeDisplayType const native_display{
92
reinterpret_cast<EGLNativeDisplayType>(0x12345)};
94
/* Creates GL framebuffer objects */
95
EXPECT_CALL(mock_gl, glGenFramebuffers(1,_))
97
.WillRepeatedly(SetArgPointee<1>(fbo));
100
std::make_shared<StubBasicPlatform>(native_display),
101
std::make_shared<mg::DefaultDisplayConfigurationPolicy>(),
102
std::make_shared<mg::NullDisplayReport>()};
104
Mock::VerifyAndClearExpectations(&mock_gl);
106
/* Binds the GL framebuffer objects */
107
display.for_each_display_buffer(
108
[this](mg::DisplayBuffer& db)
110
EXPECT_CALL(mock_egl, eglMakeCurrent(_,_,_,Ne(EGL_NO_CONTEXT)));
111
EXPECT_CALL(mock_gl, glBindFramebuffer(_,Ne(0)));
115
Mock::VerifyAndClearExpectations(&mock_egl);
116
Mock::VerifyAndClearExpectations(&mock_gl);
120
TEST_F(OffscreenDisplayTest, restores_previous_state_on_fbo_setup_failure)
122
using namespace ::testing;
124
GLuint const old_fbo{66};
125
GLuint const new_fbo{67};
126
EGLNativeDisplayType const native_display{
127
reinterpret_cast<EGLNativeDisplayType>(0x12345)};
129
EXPECT_CALL(mock_gl, glGetIntegerv(GL_FRAMEBUFFER_BINDING, _))
130
.WillOnce(SetArgPointee<1>(old_fbo));
131
EXPECT_CALL(mock_gl, glGetIntegerv(GL_VIEWPORT, _));
134
EXPECT_CALL(mock_gl, glGenFramebuffers(1,_))
135
.WillOnce(SetArgPointee<1>(new_fbo));
136
EXPECT_CALL(mock_gl, glBindFramebuffer(_,new_fbo));
137
EXPECT_CALL(mock_gl, glCheckFramebufferStatus(_))
138
.WillOnce(Return(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT));
139
EXPECT_CALL(mock_gl, glBindFramebuffer(_,old_fbo));
142
mgo::Display display(
143
std::make_shared<StubBasicPlatform>(native_display),
144
std::make_shared<mg::DefaultDisplayConfigurationPolicy>(),
145
std::make_shared<mg::NullDisplayReport>());
146
}, std::runtime_error);