-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
VaapiEGL.h
128 lines (102 loc) · 2.95 KB
/
VaapiEGL.h
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
/*
* Copyright (C) 2007-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.
*/
#pragma once
#include <array>
#if defined(HAS_GL)
// always define GL_GLEXT_PROTOTYPES before include gl headers
#if !defined(GL_GLEXT_PROTOTYPES)
#define GL_GLEXT_PROTOTYPES
#endif
#include <GL/gl.h>
#elif defined(HAS_GLES)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl3.h>
#endif
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <va/va.h>
#include "utils/Geometry.h"
#include "platform/posix/utils/FileHandle.h"
namespace VAAPI
{
class CVaapiRenderPicture;
struct InteropInfo
{
EGLDisplay eglDisplay = nullptr;
PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
GLenum textureTarget;
};
class CVaapiTexture
{
public:
CVaapiTexture() = default;
virtual ~CVaapiTexture() = default;
virtual void Init(InteropInfo &interop) = 0;
virtual bool Map(CVaapiRenderPicture *pic) = 0;
virtual void Unmap() = 0;
virtual GLuint GetTextureY() = 0;
virtual GLuint GetTextureVU() = 0;
virtual CSizeInt GetTextureSize() = 0;
};
class CVaapi1Texture : public CVaapiTexture
{
public:
CVaapi1Texture() = default;
bool Map(CVaapiRenderPicture *pic) override;
void Unmap() override;
void Init(InteropInfo &interop) override;
GLuint GetTextureY() override;
GLuint GetTextureVU() override;
CSizeInt GetTextureSize() override;
static void TestInterop(VADisplay vaDpy, EGLDisplay eglDisplay, bool &general, bool &deepColor);
GLuint m_texture = 0;
GLuint m_textureY = 0;
GLuint m_textureVU = 0;
int m_texWidth = 0;
int m_texHeight = 0;
protected:
static bool TestInteropDeepColor(VADisplay vaDpy, EGLDisplay eglDisplay);
InteropInfo m_interop;
CVaapiRenderPicture *m_vaapiPic = nullptr;
struct GLSurface
{
VAImage vaImage{VA_INVALID_ID};
VABufferInfo vBufInfo;
EGLImageKHR eglImage;
EGLImageKHR eglImageY, eglImageVU;
} m_glSurface;
};
class CVaapi2Texture : public CVaapiTexture
{
public:
bool Map(CVaapiRenderPicture *pic) override;
void Unmap() override;
void Init(InteropInfo &interop) override;
GLuint GetTextureY() override;
GLuint GetTextureVU() override;
CSizeInt GetTextureSize() override;
static void TestInterop(VADisplay vaDpy, EGLDisplay eglDisplay, bool &general, bool &deepColor);
static bool TestInteropGeneral(VADisplay vaDpy, EGLDisplay eglDisplay);
private:
static bool TestEsh(VADisplay vaDpy, EGLDisplay eglDisplay, std::uint32_t rtFormat, std::int32_t pixelFormat);
struct MappedTexture
{
EGLImageKHR eglImage{EGL_NO_IMAGE_KHR};
GLuint glTexture{0};
};
InteropInfo m_interop;
CVaapiRenderPicture* m_vaapiPic{};
bool m_hasPlaneModifiers{false};
std::array<KODI::UTILS::POSIX::CFileHandle, 4> m_drmFDs;
MappedTexture m_y, m_vu;
CSizeInt m_textureSize;
};
}