2 * Copyright (C) 2005-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/>.
22 \file TextureManager.h
26 #ifndef GUILIB_TEXTUREMANAGER_H
27 #define GUILIB_TEXTUREMANAGER_H
31 #include "TextureBundle.h"
32 #include "threads/CriticalSection.h"
36 /************************************************************************/
38 /************************************************************************/
42 CTextureArray(int width, int height, int loops, bool texCoordsArePixels = false);
45 virtual ~CTextureArray();
49 void Add(CBaseTexture *texture, int delay);
50 void Set(CBaseTexture *texture, int width, int height);
52 unsigned int size() const;
54 std::vector<CBaseTexture* > m_textures;
55 std::vector<int> m_delays;
62 bool m_texCoordsArePixels;
69 /************************************************************************/
71 /************************************************************************/
76 CTextureMap(const CStdString& textureName, int width, int height, int loops);
77 virtual ~CTextureMap();
79 void Add(CBaseTexture* texture, int delay);
82 const CStdString& GetName() const;
83 const CTextureArray& GetTexture();
85 uint32_t GetMemoryUsage() const;
91 CStdString m_textureName;
92 CTextureArray m_texture;
93 unsigned int m_referenceCount;
101 /************************************************************************/
103 /************************************************************************/
104 class CGUITextureManager
107 CGUITextureManager(void);
108 virtual ~CGUITextureManager(void);
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);
116 uint32_t GetMemoryUsage() const;
118 CStdString GetTexturePath(const CStdString& textureName, bool directory = false);
119 void GetBundledTexturesFromPath(const CStdString& texturePath, std::vector<CStdString> &items);
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
125 void FreeUnusedTextures(unsigned int timeDelay = 0); ///< Free textures (called from app thread only)
126 void ReleaseHwTexture(unsigned int texture);
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];
136 std::vector<CStdString> m_texturePaths;
137 CCriticalSection m_section;
144 extern CGUITextureManager g_TextureManager;