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
30 #include "TextureBundle.h"
31 #include "threads/CriticalSection.h"
35 /************************************************************************/
37 /************************************************************************/
41 CTextureArray(int width, int height, int loops, bool texCoordsArePixels = false);
44 virtual ~CTextureArray();
48 void Add(CBaseTexture *texture, int delay);
49 void Set(CBaseTexture *texture, int width, int height);
51 unsigned int size() const;
53 std::vector<CBaseTexture* > m_textures;
54 std::vector<int> m_delays;
61 bool m_texCoordsArePixels;
68 /************************************************************************/
70 /************************************************************************/
75 CTextureMap(const CStdString& textureName, int width, int height, int loops);
76 virtual ~CTextureMap();
78 void Add(CBaseTexture* texture, int delay);
81 const CStdString& GetName() const;
82 const CTextureArray& GetTexture();
84 uint32_t GetMemoryUsage() const;
90 CStdString m_textureName;
91 CTextureArray m_texture;
92 unsigned int m_referenceCount;
100 /************************************************************************/
102 /************************************************************************/
103 class CGUITextureManager
106 CGUITextureManager(void);
107 virtual ~CGUITextureManager(void);
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);
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(); ///< Free textures (called from app thread only)
126 void ReleaseHwTexture(unsigned int texture);
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];
135 std::vector<CStdString> m_texturePaths;
136 CCriticalSection m_section;
143 extern CGUITextureManager g_TextureManager;