Skip to content

Commit f4defc1

Browse files
jluiImav-intel
authored andcommitted
Implement GTK using OpenGL in SD and SMT
commit b0ad21c1ea3aebb7bf7a98bb1cd408cd5938a72a Author: jlui <jonathan.ming.jun.lui@intel.com> Date: Tue Aug 27 05:22:43 2024 +0000 Fix rendering issue on Weston commit 99701f7a1d066564166e53c421f0dde8d4602e10 Author: jlui <jonathan.ming.jun.lui@intel.com> Date: Fri Aug 23 04:40:23 2024 +0000 Update Changelog and fix race condition commit 968d277f8751e9a3f695e937c73e17585cd1c5b5 Author: jlui <jonathan.ming.jun.lui@intel.com> Date: Thu Aug 15 01:06:38 2024 +0000 Implement GTK using OpenGL in SD and SMT
1 parent 073787f commit f4defc1

25 files changed

+948
-37
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ GPUs from the command line.
1616
- VVC decode support to sample_decode
1717
- Embedded version information to all shared libraries
1818
- Screen content coding tools for AV1 to sample_encode
19+
- GTK renderer option to samplde_decode and sample_multi_transcode
20+
- `-fullscreen` option to sample_decode and sample_multi_transcode when using GTK.
21+
Enter fullscreen with Ctrl+f and exit with Esc
1922

2023
### Changed
2124
- Metrics monitor library to now build statically by default

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ if(CMAKE_SYSTEM_NAME MATCHES Linux)
212212
message(STATUS " ENABLE_WAYLAND : ${ENABLE_WAYLAND}")
213213
message(STATUS " ENABLE_X11 : ${ENABLE_X11}")
214214
message(STATUS " ENABLE_DRI3 : ${ENABLE_DRI3}")
215+
message(STATUS " ENABLE_GTK4 : ${ENABLE_GTK4}")
215216
endif()
216217

217218
message(STATUS "Surface sharing test tools:")

tools/legacy/sample_common/CMakeLists.txt

+35-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ if(CMAKE_SYSTEM_NAME MATCHES Linux)
2424
pkg_check_modules(PKG_WAYLAND_CLIENT wayland-client IMPORTED_TARGET GLOBAL)
2525
find_program(WAYLAND_SCANNER_BIN "wayland-scanner")
2626
pkg_check_modules(PKG_WAYLAND_PROTOCOLS "wayland-protocols>=1.15")
27-
27+
pkg_check_modules(PKG_GTK4 GLOBAL IMPORTED_TARGET gtkmm-4.0)
28+
pkg_check_modules(PKG_EPOXY GLOBAL IMPORTED_TARGET epoxy)
29+
find_package(OpenGL)
2830
# Set defaults for ENABLE_VA
2931
if(PKG_LIBVA_FOUND AND PKG_LIBVA_DRM_FOUND)
3032
set(VA_DEFAULT ON)
@@ -79,6 +81,17 @@ if(CMAKE_SYSTEM_NAME MATCHES Linux)
7981
set(ENABLE_DRI3
8082
${DRI3_DEFAULT}
8183
CACHE BOOL "Enable X11/DRI3 in tools.")
84+
85+
if(X11_DEFAULT AND PKG_GTK4_FOUND)
86+
set(GTK4_DEFAULT ON)
87+
else()
88+
set(GTK4_DEFAULT OFF)
89+
endif()
90+
91+
set(ENABLE_GTK4
92+
${GTK4_DEFAULT}
93+
CACHE BOOL "Enable X11/GTK4 in tools.")
94+
8295
endif()
8396

8497
# Error if options conflict
@@ -87,6 +100,7 @@ if(NOT ENABLE_VA
87100
OR ENABLE_WAYLAND
88101
OR ENABLE_X11
89102
OR ENABLE_DRI3
103+
OR ENABLE_GTK4
90104
))
91105
message(
92106
SEND_ERROR "conflicting options: VA backend requested but ENABLE_VA=OFF")
@@ -102,6 +116,12 @@ if(ENABLE_DRI3 AND (NOT ENABLE_X11 OR NOT ENABLE_DRM))
102116
"conflicting options: DRI3 requires ENABLE_X11=ON and ENABLE_DRM=ON")
103117
endif()
104118

119+
if(ENABLE_GTK4 AND (NOT ENABLE_X11 OR NOT ENABLE_DRM))
120+
message(
121+
SEND_ERROR
122+
"conflicting options: GTK4 requires ENABLE_X11=ON and ENABLE_DRM=ON")
123+
endif()
124+
105125
set(TARGET sample_common)
106126
add_library(${TARGET} STATIC)
107127

@@ -131,6 +151,7 @@ target_sources(
131151
src/vaapi_utils.cpp
132152
src/vaapi_utils_drm.cpp
133153
src/vaapi_utils_x11.cpp
154+
src/vaapi_utils_gtk.cpp
134155
src/vpl_implementation_loader.cpp
135156
src/vpp_ex.cpp
136157
src/vm/atomic.cpp
@@ -140,7 +161,8 @@ target_sources(
140161
src/vm/thread_linux.cpp
141162
src/vm/thread_windows.cpp
142163
src/vm/time.cpp
143-
src/vm/time_linux.cpp)
164+
src/vm/time_linux.cpp
165+
src/gtkutils.cpp)
144166

145167
target_include_directories(
146168
${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
@@ -304,6 +326,7 @@ if(CMAKE_SYSTEM_NAME MATCHES Linux)
304326
else()
305327
message(STATUS "Building ${TARGET} without DRI3 support")
306328
endif()
329+
307330
else()
308331
message(
309332
SEND_ERROR
@@ -313,6 +336,16 @@ if(CMAKE_SYSTEM_NAME MATCHES Linux)
313336
else()
314337
message(STATUS "Building ${TARGET} without X11 support")
315338
endif()
339+
340+
if(ENABLE_GTK4)
341+
target_compile_definitions(${TARGET} PUBLIC LIBVA_GTK4_SUPPORT)
342+
target_link_libraries(${TARGET} PUBLIC PkgConfig::PKG_GTK4)
343+
target_link_libraries(${TARGET} PUBLIC OpenGL::GL)
344+
target_include_directories(${TARGET} PUBLIC OpenGL::GL)
345+
target_link_libraries(${TARGET} PUBLIC PkgConfig::PKG_EPOXY)
346+
target_include_directories(${TARGET} PUBLIC PkgConfig::PKG_EPOXY)
347+
endif()
348+
316349
else()
317350
message(
318351
SEND_ERROR

tools/legacy/sample_common/include/d3d11_device.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class CD3D11Device : public CHWDevice {
2525
public:
2626
CD3D11Device();
2727
virtual ~CD3D11Device();
28-
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum);
28+
virtual mfxStatus Init(mfxHDL hWindow,
29+
mfxU16 nViews,
30+
mfxU32 nAdapterNum,
31+
bool isFullScreen = false);
2932
virtual mfxStatus Reset();
3033
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL* pHdl);
3134
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl);

tools/legacy/sample_common/include/d3d_device.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class CD3D9Device : public CHWDevice {
2626
CD3D9Device();
2727
virtual ~CD3D9Device();
2828

29-
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum);
29+
virtual mfxStatus Init(mfxHDL hWindow,
30+
mfxU16 nViews,
31+
mfxU32 nAdapterNum,
32+
bool isFullScreen = false);
3033
virtual mfxStatus Reset();
3134
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL* pHdl);
3235
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*############################################################################
2+
# Copyright (C) 2024 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
############################################################################*/
6+
#ifndef __GTK_DATA_H__
7+
#define __GTK_DATA_H__
8+
9+
typedef struct {
10+
int fd;
11+
int width;
12+
int height;
13+
int stride[3];
14+
int num_planes;
15+
int offset[3];
16+
uint32_t fourcc;
17+
} gtk_data_t;
18+
19+
#endif // __GTK_DATA_H__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*############################################################################
2+
# Copyright (C) 2024 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
############################################################################*/
6+
#ifndef __GTK_UTILS_H__
7+
#define __GTK_UTILS_H__
8+
#if defined(LIBVA_GTK4_SUPPORT)
9+
#include <iostream>
10+
#include <string>
11+
#include <vector>
12+
13+
#include <epoxy/egl.h>
14+
#include <gtkmm.h>
15+
#include "gtkdata.h"
16+
17+
class GtkPlayer : public Gtk::Window {
18+
public:
19+
GtkPlayer(int width, int height, bool isFullscreen);
20+
~GtkPlayer();
21+
void frameReady();
22+
std::unique_ptr<Glib::Dispatcher> m_dispatcher;
23+
gtk_data_t m_frame_data;
24+
25+
protected:
26+
Gtk::Box m_VBox{ Gtk::Orientation::VERTICAL, false };
27+
28+
EGLDisplay m_egl_display;
29+
PFNEGLCREATEIMAGEPROC eglCreateImage;
30+
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
31+
Gtk::GLArea m_GLArea;
32+
33+
void realize();
34+
void unrealize();
35+
bool render(const Glib::RefPtr<Gdk::GLContext>& context);
36+
37+
void initBuffers();
38+
void initShaders();
39+
void initEgl(void);
40+
void getMonitorDimension();
41+
42+
bool onKeyPressEvent(guint keyval, guint a, Gdk::ModifierType state);
43+
44+
int m_target = GL_TEXTURE_2D;
45+
GLuint m_Vao{ 0 };
46+
GLuint m_Buffer{ 0 };
47+
GLuint m_program{ 0 };
48+
GLuint m_Mvp{ 0 };
49+
GLuint m_Ebo{ 0 };
50+
GLuint m_texture;
51+
52+
Gdk::Rectangle m_mon_dim;
53+
Gdk::Rectangle m_mon_work_area;
54+
bool m_isX11 = false;
55+
int m_height = 0;
56+
int m_width = 0;
57+
bool m_fullscreenMode;
58+
std::set<guint> m_pressed_keys;
59+
};
60+
61+
#endif /* #if defined(LIBVA_GTK4_SUPPORT) */
62+
63+
#endif /* __GTK_UTILS_H__ */

tools/legacy/sample_common/include/hw_device.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ class CHWDevice {
1616
@param[in] hWindow Window handle to bundle device to.
1717
@param[in] nViews Number of views to process.
1818
@param[in] nAdapterNum Number of adapter to use
19+
@param[in] isFullScreen Full screen is enabled or not
1920
*/
20-
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum) = 0;
21+
virtual mfxStatus Init(mfxHDL hWindow,
22+
mfxU16 nViews,
23+
mfxU32 nAdapterNum,
24+
bool isFullScreen = false) = 0;
2125
/// Reset device.
2226
virtual mfxStatus Reset() = 0;
2327
/// Get handle can be used for MFX session SetHandle calls

tools/legacy/sample_common/include/sample_defs.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ enum LibVABackend {
9696
MFX_LIBVA_DRM_RENDERNODE = MFX_LIBVA_DRM,
9797
MFX_LIBVA_DRM_MODESET,
9898
MFX_LIBVA_X11,
99-
MFX_LIBVA_WAYLAND
99+
MFX_LIBVA_WAYLAND,
100+
MFX_LIBVA_GTK
100101
};
101102

102103
#endif

tools/legacy/sample_common/include/vaapi_device.h

+94-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66

77
#if defined(LIBVA_DRM_SUPPORT) || defined(LIBVA_X11_SUPPORT) || defined(LIBVA_ANDROID_SUPPORT) || \
88
defined(LIBVA_WAYLAND_SUPPORT)
9-
109
#include "hw_device.h"
1110
#include "vaapi_utils_drm.h"
1211
#include "vaapi_utils_x11.h"
1312
#if defined(LIBVA_ANDROID_SUPPORT)
1413
#include "vaapi_utils_android.h"
1514
#endif
15+
#ifdef LIBVA_GTK4_SUPPORT
16+
#include <glibmm/dispatcher.h>
17+
#include <future>
18+
#include "gtkdata.h"
19+
#include "vaapi_utils_gtk.h"
20+
#endif
1621

1722
CHWDevice* CreateVAAPIDevice(const std::string& devicePath = "", int type = MFX_LIBVA_DRM);
1823

@@ -23,7 +28,10 @@ class CVAAPIDeviceDRM : public CHWDevice {
2328
CVAAPIDeviceDRM(const std::string& devicePath, int type);
2429
virtual ~CVAAPIDeviceDRM(void);
2530

26-
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum);
31+
virtual mfxStatus Init(mfxHDL hWindow,
32+
mfxU16 nViews,
33+
mfxU32 nAdapterNum,
34+
bool isFullScreen = false);
2735
virtual mfxStatus Reset(void) {
2836
return MFX_ERR_NONE;
2937
}
@@ -80,7 +88,10 @@ class CVAAPIDeviceX11 : public CHWDevice {
8088
}
8189
virtual ~CVAAPIDeviceX11(void);
8290

83-
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum);
91+
virtual mfxStatus Init(mfxHDL hWindow,
92+
mfxU16 nViews,
93+
mfxU32 nAdapterNum,
94+
bool isFullScreen = false);
8495
virtual mfxStatus Reset(void);
8596
virtual void Close(void);
8697

@@ -128,7 +139,10 @@ class CVAAPIDeviceWayland : public CHWDevice {
128139
}
129140
virtual ~CVAAPIDeviceWayland(void);
130141

131-
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum);
142+
virtual mfxStatus Init(mfxHDL hWindow,
143+
mfxU16 nViews,
144+
mfxU32 nAdapterNum,
145+
bool isFullScreen = false);
132146
virtual mfxStatus Reset(void) {
133147
return MFX_ERR_NONE;
134148
}
@@ -192,7 +206,10 @@ class CVAAPIDeviceAndroid : public CHWDevice {
192206
Close();
193207
}
194208

195-
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum) {
209+
virtual mfxStatus Init(mfxHDL hWindow,
210+
mfxU16 nViews,
211+
mfxU32 nAdapterNum,
212+
bool isFullScreen = false) {
196213
return MFX_ERR_NONE;
197214
}
198215
virtual mfxStatus Reset(void) {
@@ -222,6 +239,78 @@ class CVAAPIDeviceAndroid : public CHWDevice {
222239

223240
protected:
224241
AndroidLibVA* m_pAndroidLibVA;
242+
};
243+
#endif
244+
#if defined(LIBVA_GTK4_SUPPORT)
245+
class CVAAPIDeviceGTK : public CHWDevice {
246+
public:
247+
CVAAPIDeviceGTK(const std::string& devicePath) {
248+
m_nRenderWinX = 0;
249+
m_nRenderWinY = 0;
250+
m_nRenderWinW = 0;
251+
m_nRenderWinH = 0;
252+
m_bRenderWin = false;
253+
m_device_path = devicePath;
254+
255+
if (isWayland()) {
256+
m_DRMLibVA = new DRMLibVA(devicePath);
257+
}
258+
else {
259+
m_GtkLibVA = new X11GtkVA(devicePath);
260+
}
261+
}
262+
263+
virtual ~CVAAPIDeviceGTK(void) {
264+
delete m_GtkLibVA;
265+
delete m_DRMLibVA;
266+
}
267+
268+
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum, bool isFullScreen);
269+
virtual mfxStatus Reset(void) {
270+
return MFX_ERR_NONE;
271+
}
272+
virtual void Close(void) {}
273+
274+
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl) {
275+
return MFX_ERR_UNSUPPORTED;
276+
}
277+
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL* pHdl);
278+
279+
virtual mfxStatus RenderFrame(mfxFrameSurface1* pSurface, mfxFrameAllocator* pmfxAlloc);
280+
281+
virtual void UpdateTitle(double fps) {}
282+
virtual void SetMondelloInput(bool isMondelloInputEnabled) {}
283+
virtual void SetDxgiFullScreen() {}
284+
285+
bool GetInitDone() {
286+
return m_initComplete.get();
287+
}
288+
289+
bool isWayland() {
290+
return std::getenv("WAYLAND_DISPLAY") != nullptr;
291+
}
292+
293+
private:
294+
bool m_bRenderWin;
295+
mfxU32 m_nRenderWinX;
296+
mfxU32 m_nRenderWinY;
297+
mfxU32 m_nRenderWinW;
298+
mfxU32 m_nRenderWinH;
299+
std::string m_device_path;
300+
std::atomic<bool> m_ForceStop = false;
301+
std::promise<bool> m_initPromise;
302+
std::future<bool> m_initComplete;
303+
304+
protected:
305+
X11GtkVA* m_GtkLibVA;
306+
DRMLibVA* m_DRMLibVA;
307+
virtual void SetForceStop() {
308+
m_ForceStop = true;
309+
}
310+
void gtkMain(bool isFullScreen, std::promise<bool>&& initPromise);
311+
Glib::Dispatcher* m_dispatcher_ptr;
312+
gtk_data_t* m_frame_data_ptr;
313+
std::thread* m_gtk_thread;
225314
};
226315
#endif
227316
#endif //#if defined(LIBVA_DRM_SUPPORT) || defined(LIBVA_X11_SUPPORT) || defined(LIBVA_ANDROID_SUPPORT)

0 commit comments

Comments
 (0)