Merge pull request #4687 from ruuk/textboxgettext
[vuplus_xbmc] / xbmc / guilib / TextureManager.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 /*!
22 \file TextureManager.h
23 \brief
24 */
25
26 #ifndef GUILIB_TEXTUREMANAGER_H
27 #define GUILIB_TEXTUREMANAGER_H
28
29 #include <vector>
30 #include <list>
31 #include "TextureBundle.h"
32 #include "threads/CriticalSection.h"
33
34 #pragma once
35
36 /************************************************************************/
37 /*                                                                      */
38 /************************************************************************/
39 class CTextureArray
40 {
41 public:
42   CTextureArray(int width, int height, int loops, bool texCoordsArePixels = false);
43   CTextureArray();
44
45   virtual ~CTextureArray();
46
47   void Reset();
48
49   void Add(CBaseTexture *texture, int delay);
50   void Set(CBaseTexture *texture, int width, int height);
51   void Free();
52   unsigned int size() const;
53
54   std::vector<CBaseTexture* > m_textures;
55   std::vector<int> m_delays;
56   int m_width;
57   int m_height;
58   int m_orientation;
59   int m_loops;
60   int m_texWidth;
61   int m_texHeight;
62   bool m_texCoordsArePixels;
63 };
64
65 /*!
66  \ingroup textures
67  \brief
68  */
69 /************************************************************************/
70 /*                                                                      */
71 /************************************************************************/
72 class CTextureMap
73 {
74 public:
75   CTextureMap();
76   CTextureMap(const CStdString& textureName, int width, int height, int loops);
77   virtual ~CTextureMap();
78
79   void Add(CBaseTexture* texture, int delay);
80   bool Release();
81
82   const CStdString& GetName() const;
83   const CTextureArray& GetTexture();
84   void Dump() const;
85   uint32_t GetMemoryUsage() const;
86   void Flush();
87   bool IsEmpty() const;
88 protected:
89   void FreeTexture();
90
91   CStdString m_textureName;
92   CTextureArray m_texture;
93   unsigned int m_referenceCount;
94   uint32_t m_memUsage;
95 };
96
97 /*!
98  \ingroup textures
99  \brief
100  */
101 /************************************************************************/
102 /*                                                                      */
103 /************************************************************************/
104 class CGUITextureManager
105 {
106 public:
107   CGUITextureManager(void);
108   virtual ~CGUITextureManager(void);
109
110   bool HasTexture(const CStdString &textureName, CStdString *path = NULL, int *bundle = NULL, int *size = NULL);
111   static bool CanLoad(const CStdString &texturePath); ///< Returns true if the texture manager can load this texture
112   const CTextureArray& Load(const CStdString& strTextureName, bool checkBundleOnly = false);
113   void ReleaseTexture(const CStdString& strTextureName, bool immediately = false);
114   void Cleanup();
115   void Dump() const;
116   uint32_t GetMemoryUsage() const;
117   void Flush();
118   CStdString GetTexturePath(const CStdString& textureName, bool directory = false);
119   void GetBundledTexturesFromPath(const CStdString& texturePath, std::vector<CStdString> &items);
120
121   void AddTexturePath(const CStdString &texturePath);    ///< Add a new path to the paths to check when loading media
122   void SetTexturePath(const CStdString &texturePath);    ///< Set a single path as the path to check when loading media (clear then add)
123   void RemoveTexturePath(const CStdString &texturePath); ///< Remove a path from the paths to check when loading media
124
125   void FreeUnusedTextures(unsigned int timeDelay = 0); ///< Free textures (called from app thread only)
126   void ReleaseHwTexture(unsigned int texture);
127 protected:
128   std::vector<CTextureMap*> m_vecTextures;
129   std::list<std::pair<CTextureMap*, unsigned int> > m_unusedTextures;
130   std::vector<unsigned int> m_unusedHwTextures;
131   typedef std::vector<CTextureMap*>::iterator ivecTextures;
132   typedef std::list<std::pair<CTextureMap*, unsigned int> >::iterator ilistUnused;
133   // we have 2 texture bundles (one for the base textures, one for the theme)
134   CTextureBundle m_TexBundle[2];
135
136   std::vector<CStdString> m_texturePaths;
137   CCriticalSection m_section;
138 };
139
140 /*!
141  \ingroup textures
142  \brief
143  */
144 extern CGUITextureManager g_TextureManager;
145 #endif