forked from xbmc/xbmc
/
TexturePi.cpp
141 lines (127 loc) · 3.83 KB
/
TexturePi.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright (C) 2013-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 "ServiceBroker.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "Texture.h"
#include "cores/omxplayer/OMXImage.h"
#include "guilib/TextureManager.h"
#include "utils/GLUtils.h"
#include "utils/URIUtils.h"
#include "utils/log.h"
/************************************************************************/
/* CPiTexture */
/************************************************************************/
CPiTexture::CPiTexture(unsigned int width, unsigned int height, unsigned int format)
: CGLTexture(width, height, format)
{
m_egl_image = NULL;
}
CPiTexture::~CPiTexture()
{
if (m_egl_image)
{
g_OMXImage.DestroyTexture(m_egl_image);
m_egl_image = NULL;
}
}
void CPiTexture::Allocate(unsigned int width, unsigned int height, unsigned int format)
{
if (m_egl_image)
{
m_imageWidth = m_originalWidth = width;
m_imageHeight = m_originalHeight = height;
m_format = format;
m_orientation = 0;
m_textureWidth = m_imageWidth;
m_textureHeight = m_imageHeight;
return;
}
return CGLTexture::Allocate(width, height, format);
}
void CPiTexture::CreateTextureObject()
{
if (m_egl_image && !m_texture)
{
g_OMXImage.GetTexture(m_egl_image, &m_texture);
return;
}
CGLTexture::CreateTextureObject();
}
void CPiTexture::LoadToGPU()
{
if (m_egl_image)
{
if (m_loadedToGPU)
{
// nothing to load - probably same image (no change)
return;
}
if (m_texture == 0)
{
// Have OpenGL generate a texture object handle for us
// this happens only one time - the first time the texture is loaded
CreateTextureObject();
}
// Bind the texture object
glBindTexture(GL_TEXTURE_2D, m_texture);
if (IsMipmapped()) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
}
m_loadedToGPU = true;
return;
}
CGLTexture::LoadToGPU();
}
void CPiTexture::Update(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, const unsigned char *pixels, bool loadToGPU)
{
if (m_egl_image)
{
if (loadToGPU)
LoadToGPU();
return;
}
CGLTexture::Update(width, height, pitch, format, pixels, loadToGPU);
}
bool CPiTexture::LoadFromFileInternal(const std::string& texturePath, const XFILE::auto_buffer &buf, unsigned int maxWidth, unsigned int maxHeight, bool requirePixels, const std::string& strMimeType)
{
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool("videoplayer.acceleratedjpegs") && URIUtils::HasExtension(texturePath, ".jpg|.tbn"))
{
unsigned int width = 0, height = 0;
int orientation = 0;
std::string error;
if (g_OMXImage.GetCodingType(buf, width, height, orientation, error))
{
bool okay = false;
// limit the sizes of jpegs (even if we fail to decode)
g_OMXImage.ClampLimits(maxWidth, maxHeight, width, height, orientation & 4);
if (requirePixels)
{
Allocate(maxWidth, maxHeight, XB_FMT_A8R8G8B8);
if (m_pixels && COMXImage::DecodeJpeg(texturePath, buf, maxWidth, GetRows(), GetPitch(), (void *)m_pixels))
okay = true;
}
else
{
if (g_OMXImage.DecodeJpegToTexture(texturePath, buf, maxWidth, maxHeight, &m_egl_image) && m_egl_image)
{
Allocate(maxWidth, maxHeight, XB_FMT_A8R8G8B8);
okay = true;
}
}
if (okay)
{
m_hasAlpha = false;
m_orientation = orientation;
return true;
}
}
}
return CGLTexture::LoadFromFileInternal(texturePath, buf, maxWidth, maxHeight, requirePixels);
}