-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
RenderBufferGBM.cpp
113 lines (86 loc) · 2.49 KB
/
RenderBufferGBM.cpp
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
/*
* 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 "RenderBufferGBM.h"
#include "ServiceBroker.h"
#include "utils/EGLImage.h"
#include "utils/GBMBufferObject.h"
#include "windowing/gbm/WinSystemGbmEGLContext.h"
using namespace KODI;
using namespace RETRO;
CRenderBufferGBM::CRenderBufferGBM(CRenderContext &context,
int fourcc) :
m_context(context),
m_fourcc(fourcc),
m_egl(new CEGLImage(static_cast<CWinSystemGbmEGLContext*>(CServiceBroker::GetWinSystem())->GetEGLDisplay())),
m_bo(new CGBMBufferObject(fourcc))
{
}
CRenderBufferGBM::~CRenderBufferGBM()
{
DeleteTexture();
}
bool CRenderBufferGBM::Allocate(AVPixelFormat format, unsigned int width, unsigned int height)
{
// Initialize IRenderBuffer
m_format = format;
m_width = width;
m_height = height;
m_bo->CreateBufferObject(m_width, m_height);
return true;
}
size_t CRenderBufferGBM::GetFrameSize() const
{
return m_bo->GetStride() * m_height;
}
uint8_t *CRenderBufferGBM::GetMemory()
{
return m_bo->GetMemory();
}
void CRenderBufferGBM::ReleaseMemory()
{
m_bo->ReleaseMemory();
}
void CRenderBufferGBM::CreateTexture()
{
glGenTextures(1, &m_textureId);
glBindTexture(m_textureTarget, m_textureId);
glTexParameteri(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(m_textureTarget, 0);
}
bool CRenderBufferGBM::UploadTexture()
{
if (m_bo->GetFd() < 0)
return false;
if (!glIsTexture(m_textureId))
CreateTexture();
glBindTexture(m_textureTarget, m_textureId);
std::array<CEGLImage::EglPlane, CEGLImage::MAX_NUM_PLANES> planes;
planes[0].fd = m_bo->GetFd();
planes[0].offset = 0;
planes[0].pitch = m_bo->GetStride();
planes[0].modifier = m_bo->GetModifier();
CEGLImage::EglAttrs attribs;
attribs.width = m_width;
attribs.height = m_height;
attribs.format = m_fourcc;
attribs.planes = planes;
if (m_egl->CreateImage(attribs))
m_egl->UploadImage(m_textureTarget);
m_egl->DestroyImage();
glBindTexture(m_textureTarget, 0);
return true;
}
void CRenderBufferGBM::DeleteTexture()
{
if (glIsTexture(m_textureId))
glDeleteTextures(1, &m_textureId);
m_textureId = 0;
}