Debian Codegraph @

xbmc/cores/RetroPlayer/buffers/video/RenderBufferGuiTexture.cpp

raw
1 /*
2 * Copyright (C) 2017-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 "RenderBufferGuiTexture.h"
10
11 using namespace KODI;
12 using namespace RETRO;
13
14 CRenderBufferGuiTexture::CRenderBufferGuiTexture(SCALINGMETHOD scalingMethod)
15 : m_scalingMethod(scalingMethod)
16 {
17 m_textureFormat = XB_FMT_A8R8G8B8;
18 }
19
20 bool CRenderBufferGuiTexture::Allocate(AVPixelFormat format,
21 unsigned int width,
22 unsigned int height)
23 {
24 // Initialize IRenderBuffer
25 m_format = TranslateFormat(m_textureFormat);
26
27 if (m_format != AV_PIX_FMT_NONE)
28 {
29 m_texture = CTexture::CreateTexture(width, height, m_textureFormat);
30 m_texture->SetScalingMethod(TranslateScalingMethod(m_scalingMethod));
31 m_texture->SetCacheMemory(true);
32
33 // Update IRenderBuffer
34 m_width = m_texture->GetTextureWidth();
35 m_height = m_texture->GetTextureHeight();
36
37 return true;
38 }
39
40 return false;
41 }
42
43 size_t CRenderBufferGuiTexture::GetFrameSize() const
44 {
45 if (m_texture)
46 return m_texture->GetPitch() * m_texture->GetRows();
47
48 return 0;
49 }
50
51 uint8_t* CRenderBufferGuiTexture::GetMemory()
52 {
53 if (m_texture)
54 return m_texture->GetPixels();
55
56 return nullptr;
57 }
58
59 bool CRenderBufferGuiTexture::UploadTexture()
60 {
61 bool bLoaded = false;
62
63 if (m_texture)
64 {
65 m_texture->LoadToGPU();
66 bLoaded = true;
67 }
68
69 return bLoaded;
70 }
71
72 void CRenderBufferGuiTexture::BindToUnit(unsigned int unit)
73 {
74 if (m_texture)
75 m_texture->BindToUnit(unit);
76 }
77
78 AVPixelFormat CRenderBufferGuiTexture::TranslateFormat(XB_FMT textureFormat)
79 {
80 switch (textureFormat)
81 {
82 case XB_FMT_RGBA8:
83 case XB_FMT_A8R8G8B8:
84 return AV_PIX_FMT_BGRA;
85 default:
86 break;
87 }
88
89 return AV_PIX_FMT_NONE;
90 }
91
92 TEXTURE_SCALING CRenderBufferGuiTexture::TranslateScalingMethod(SCALINGMETHOD scalingMethod)
93 {
94 switch (scalingMethod)
95 {
96 case SCALINGMETHOD::NEAREST:
97 return TEXTURE_SCALING::NEAREST;
98 case SCALINGMETHOD::LINEAR:
99 return TEXTURE_SCALING::LINEAR;
100 default:
101 break;
102 }
103
104 return TEXTURE_SCALING::NEAREST;
105 }