Debian Codegraph @

xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/DRMPRIMEEGL.cpp

raw
1 /*
2 * Copyright (C) 2007-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "DRMPRIMEEGL.h"
10
11 #include "utils/log.h"
12
13 #include <memory>
14
15 using namespace DRMPRIME;
16
17 namespace
18 {
19
20 int GetEGLColorSpace(const VideoPicture& picture)
21 {
22 switch (picture.color_space)
23 {
24 case AVCOL_SPC_BT2020_CL:
25 case AVCOL_SPC_BT2020_NCL:
26 return EGL_ITU_REC2020_EXT;
27 case AVCOL_SPC_SMPTE170M:
28 case AVCOL_SPC_BT470BG:
29 case AVCOL_SPC_FCC:
30 return EGL_ITU_REC601_EXT;
31 case AVCOL_SPC_BT709:
32 return EGL_ITU_REC709_EXT;
33 case AVCOL_SPC_RESERVED:
34 case AVCOL_SPC_UNSPECIFIED:
35 default:
36 if (picture.iWidth > 1024 || picture.iHeight >= 600)
37 return EGL_ITU_REC709_EXT;
38 else
39 return EGL_ITU_REC601_EXT;
40 }
41 }
42
43 int GetEGLColorRange(const VideoPicture& picture)
44 {
45 if (picture.color_range)
46 return EGL_YUV_FULL_RANGE_EXT;
47
48 return EGL_YUV_NARROW_RANGE_EXT;
49 }
50
51 } // namespace
52
53 CDRMPRIMETexture::~CDRMPRIMETexture()
54 {
55 glDeleteTextures(1, &m_texture);
56 }
57
58 void CDRMPRIMETexture::Init(EGLDisplay eglDisplay)
59 {
60 m_eglImage = std::make_unique<CEGLImage>(eglDisplay);
61 }
62
63 bool CDRMPRIMETexture::Map(CVideoBufferDRMPRIME* buffer)
64 {
65 if (m_primebuffer)
66 return true;
67
68 if (!buffer->AcquireDescriptor())
69 {
70 CLog::Log(LOGERROR, "CDRMPRIMETexture::{} - failed to acquire descriptor", __FUNCTION__);
71 return false;
72 }
73
74 m_texWidth = buffer->GetWidth();
75 m_texHeight = buffer->GetHeight();
76
77 AVDRMFrameDescriptor* descriptor = buffer->GetDescriptor();
78 if (descriptor && descriptor->nb_layers)
79 {
80 AVDRMLayerDescriptor* layer = &descriptor->layers[0];
81
82 std::array<CEGLImage::EglPlane, CEGLImage::MAX_NUM_PLANES> planes;
83
84 for (int i = 0; i < layer->nb_planes; i++)
85 {
86 planes[i].fd = descriptor->objects[layer->planes[i].object_index].fd;
87 planes[i].modifier = descriptor->objects[layer->planes[i].object_index].format_modifier;
88 planes[i].offset = layer->planes[i].offset;
89 planes[i].pitch = layer->planes[i].pitch;
90 }
91
92 CEGLImage::EglAttrs attribs;
93
94 attribs.width = m_texWidth;
95 attribs.height = m_texHeight;
96 attribs.format = layer->format;
97 attribs.colorSpace = GetEGLColorSpace(buffer->GetPicture());
98 attribs.colorRange = GetEGLColorRange(buffer->GetPicture());
99 attribs.planes = planes;
100
101 if (!m_eglImage->CreateImage(attribs))
102 {
103 buffer->ReleaseDescriptor();
104 return false;
105 }
106
107 if (!glIsTexture(m_texture))
108 glGenTextures(1, &m_texture);
109 glBindTexture(m_textureTarget, m_texture);
110 glTexParameteri(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
111 glTexParameteri(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
112 glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
113 glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
114 m_eglImage->UploadImage(m_textureTarget);
115 glBindTexture(m_textureTarget, 0);
116 }
117
118 m_primebuffer = buffer;
119 m_primebuffer->Acquire();
120
121 return true;
122 }
123
124 void CDRMPRIMETexture::Unmap()
125 {
126 if (!m_primebuffer)
127 return;
128
129 m_eglImage->DestroyImage();
130
131 m_primebuffer->ReleaseDescriptor();
132
133 m_primebuffer->Release();
134 m_primebuffer = nullptr;
135 }