[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / guilib / TextureManager.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.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 "TextureBundle.h"
31 #include "threads/CriticalSection.h"
32
33 #pragma once
34
35 /************************************************************************/
36 /*                                                                      */
37 /************************************************************************/
38 class CTextureArray
39 {
40 public:
41   CTextureArray(int width, int height, int loops, bool texCoordsArePixels = false);
42   CTextureArray();
43
44   virtual ~CTextureArray();
45
46   void Reset();
47
48   void Add(CBaseTexture *texture, int delay);
49   void Set(CBaseTexture *texture, int width, int height);
50   void Free();
51   unsigned int size() const;
52
53   std::vector<CBaseTexture* > m_textures;
54   std::vector<int> m_delays;
55   int m_width;
56   int m_height;
57   int m_orientation;
58   int m_loops;
59   int m_texWidth;
60   int m_texHeight;
61   bool m_texCoordsArePixels;
62 };
63
64 /*!
65  \ingroup textures
66  \brief
67  */
68 /************************************************************************/
69 /*                                                                      */
70 /************************************************************************/
71 class CTextureMap
72 {
73 public:
74   CTextureMap();
75   CTextureMap(const CStdString& textureName, int width, int height, int loops);
76   virtual ~CTextureMap();
77
78   void Add(CBaseTexture* texture, int delay);
79   bool Release();
80
81   const CStdString& GetName() const;
82   const CTextureArray& GetTexture();
83   void Dump() const;
84   uint32_t GetMemoryUsage() const;
85   void Flush();
86   bool IsEmpty() const;
87 protected:
88   void FreeTexture();
89
90   CStdString m_textureName;
91   CTextureArray m_texture;
92   unsigned int m_referenceCount;
93   uint32_t m_memUsage;
94 };
95
96 /*!
97  \ingroup textures
98  \brief
99  */
100 /************************************************************************/
101 /*                                                                      */
102 /************************************************************************/
103 class CGUITextureManager
104 {
105 public:
106   CGUITextureManager(void);
107   virtual ~CGUITextureManager(void);
108
109   bool HasTexture(const CStdString &textureName, CStdString *path = NULL, int *bundle = NULL, int *size = NULL);
110   bool CanLoad(const CStdString &texturePath) const; ///< Returns true if the texture manager can load this texture
111   int Load(const CStdString& strTextureName, bool checkBundleOnly = false);
112   const CTextureArray& GetTexture(const CStdString& strTextureName);
113   void ReleaseTexture(const CStdString& strTextureName);
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(); ///< Free textures (called from app thread only)
126   void ReleaseHwTexture(unsigned int texture);
127 protected:
128   std::vector<CTextureMap*> m_vecTextures;
129   std::vector<CTextureMap*> m_unusedTextures;
130   std::vector<unsigned int> m_unusedHwTextures;
131   typedef std::vector<CTextureMap*>::iterator ivecTextures;
132   // we have 2 texture bundles (one for the base textures, one for the theme)
133   CTextureBundle m_TexBundle[2];
134
135   std::vector<CStdString> m_texturePaths;
136   CCriticalSection m_section;
137 };
138
139 /*!
140  \ingroup textures
141  \brief
142  */
143 extern CGUITextureManager g_TextureManager;
144 #endif