1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/*
* Copyright (C) 2017-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "WinSystemWaylandEGLContext.h"
#include "Connection.h"
#include "cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h"
#include "cores/VideoPlayer/VideoRenderers/RenderFactory.h"
#include "utils/log.h"
#include "windowing/GraphicContext.h"
#include <EGL/eglext.h>
using namespace KODI::WINDOWING::WAYLAND;
using namespace KODI::WINDOWING::LINUX;
CWinSystemWaylandEGLContext::CWinSystemWaylandEGLContext()
: CWinSystemEGL{EGL_PLATFORM_WAYLAND_EXT, "EGL_EXT_platform_wayland"}
{}
bool CWinSystemWaylandEGLContext::InitWindowSystemEGL(EGLint renderableType, EGLint apiType)
{
VIDEOPLAYER::CRendererFactory::ClearRenderer();
CDVDFactoryCodec::ClearHWAccels();
if (!CWinSystemWayland::InitWindowSystem())
{
return false;
}
if (!m_eglContext.CreatePlatformDisplay(GetConnection()->GetDisplay(), GetConnection()->GetDisplay()))
{
return false;
}
if (!m_eglContext.InitializeDisplay(apiType))
{
return false;
}
if (!m_eglContext.ChooseConfig(renderableType))
{
return false;
}
return true;
}
bool CWinSystemWaylandEGLContext::CreateNewWindow(const std::string& name,
bool fullScreen,
RESOLUTION_INFO& res)
{
if (!CWinSystemWayland::CreateNewWindow(name, fullScreen, res))
{
return false;
}
if (!CreateContext())
{
return false;
}
m_nativeWindow = wayland::egl_window_t{GetMainSurface(), GetBufferSize().Width(), GetBufferSize().Height()};
// CWinSystemWayland::CreateNewWindow sets internal m_bufferSize
// to the resolution that should be used for the initial surface size
// - the compositor might want something other than the resolution given
if (!m_eglContext.CreatePlatformSurface(
m_nativeWindow.c_ptr(), reinterpret_cast<khronos_uintptr_t>(m_nativeWindow.c_ptr())))
{
return false;
}
if (!m_eglContext.BindContext())
{
return false;
}
// Never enable the vsync of the EGL implementation, we handle that ourselves
// in WinSystemWayland
m_eglContext.SetVSync(false);
return true;
}
bool CWinSystemWaylandEGLContext::DestroyWindow()
{
m_eglContext.DestroySurface();
m_nativeWindow = {};
return CWinSystemWayland::DestroyWindow();
}
bool CWinSystemWaylandEGLContext::DestroyWindowSystem()
{
m_eglContext.Destroy();
return CWinSystemWayland::DestroyWindowSystem();
}
CSizeInt CWinSystemWaylandEGLContext::GetNativeWindowAttachedSize()
{
int width, height;
m_nativeWindow.get_attached_size(width, height);
return {width, height};
}
void CWinSystemWaylandEGLContext::SetContextSize(CSizeInt size)
{
// Change EGL surface size if necessary
if (GetNativeWindowAttachedSize() != size)
{
CLog::LogF(LOGDEBUG, "Updating egl_window size to {}x{}", size.Width(), size.Height());
m_nativeWindow.resize(size.Width(), size.Height(), 0, 0);
}
}
void CWinSystemWaylandEGLContext::PresentFrame(bool rendered)
{
PrepareFramePresentation();
if (rendered)
{
if (!m_eglContext.TrySwapBuffers())
{
// For now we just hard fail if this fails
// Theoretically, EGL_CONTEXT_LOST could be handled, but it needs to be checked
// whether egl implementations actually use it (mesa does not)
CEGLUtils::Log(LOGERROR, "eglSwapBuffers failed");
throw std::runtime_error("eglSwapBuffers failed");
}
// eglSwapBuffers() (hopefully) calls commit on the surface and flushes
// ... well mesa does anyway
}
else
{
// For presentation feedback: Get notification of the next vblank even
// when contents did not change
GetMainSurface().commit();
// Make sure it reaches the compositor
GetConnection()->GetDisplay().flush();
}
FinishFramePresentation();
}
|