2 * Copyright (C) 2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
23 #include "windowing/WindowingFactory.h"
24 #include "utils/log.h"
25 #include "utils/GLUtils.h"
26 #include "guilib/TextureManager.h"
27 #include "utils/URIUtils.h"
29 #if defined(HAS_OMXPLAYER)
30 #include "cores/omxplayer/OMXImage.h"
34 /************************************************************************/
36 /************************************************************************/
38 CPiTexture::CPiTexture(unsigned int width, unsigned int height, unsigned int format)
39 : CGLTexture(width, height, format)
44 CPiTexture::~CPiTexture()
48 g_OMXImage.DestroyTexture(m_egl_image);
53 void CPiTexture::Allocate(unsigned int width, unsigned int height, unsigned int format)
57 m_imageWidth = m_originalWidth = width;
58 m_imageHeight = m_originalHeight = height;
62 m_textureWidth = m_imageWidth;
63 m_textureHeight = m_imageHeight;
66 return CGLTexture::Allocate(width, height, format);
69 void CPiTexture::CreateTextureObject()
71 if (m_egl_image && !m_texture)
73 g_OMXImage.GetTexture(m_egl_image, &m_texture);
76 CGLTexture::CreateTextureObject();
79 void CPiTexture::LoadToGPU()
85 // nothing to load - probably same image (no change)
90 // Have OpenGL generate a texture object handle for us
91 // this happens only one time - the first time the texture is loaded
92 CreateTextureObject();
95 // Bind the texture object
96 glBindTexture(GL_TEXTURE_2D, m_texture);
101 CGLTexture::LoadToGPU();
104 void CPiTexture::Update(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, const unsigned char *pixels, bool loadToGPU)
112 CGLTexture::Update(width, height, pitch, format, pixels, loadToGPU);
115 bool CPiTexture::LoadFromFileInternal(const CStdString& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool autoRotate, bool requirePixels, const std::string& strMimeType)
117 if (URIUtils::HasExtension(texturePath, ".jpg|.tbn"))
119 COMXImageFile *file = g_OMXImage.LoadJpeg(texturePath);
123 int orientation = file->GetOrientation();
124 // limit the sizes of jpegs (even if we fail to decode)
125 g_OMXImage.ClampLimits(maxWidth, maxHeight, file->GetWidth(), file->GetHeight(), orientation & 4);
129 Allocate(maxWidth, maxHeight, XB_FMT_A8R8G8B8);
130 if (m_pixels && COMXImage::DecodeJpeg(file, maxWidth, GetRows(), GetPitch(), (void *)m_pixels))
135 if (g_OMXImage.DecodeJpegToTexture(file, maxWidth, maxHeight, &m_egl_image) && m_egl_image)
137 Allocate(maxWidth, maxHeight, XB_FMT_A8R8G8B8);
141 g_OMXImage.CloseJpeg(file);
145 if (autoRotate && orientation)
146 m_orientation = orientation - 1;
151 return CGLTexture::LoadFromFileInternal(texturePath, maxWidth, maxHeight, autoRotate, requirePixels);