PageRenderTime 18ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/xbmc/guilib/TextureManager.h

http://github.com/xbmc/xbmc
C Header | 124 lines | 81 code | 18 blank | 25 comment | 0 complexity | 13990c7107fc01a7e2439f79aa7c7162 MD5 | raw file
  1/*
  2 *  Copyright (C) 2005-2018 Team Kodi
  3 *  This file is part of Kodi - https://kodi.tv
  4 *
  5 *  SPDX-License-Identifier: GPL-2.0-or-later
  6 *  See LICENSES/README.md for more information.
  7 */
  8
  9#pragma once
 10
 11#include "GUIComponent.h"
 12#include "TextureBundle.h"
 13#include "threads/CriticalSection.h"
 14
 15#include <list>
 16#include <utility>
 17#include <vector>
 18
 19/************************************************************************/
 20/*                                                                      */
 21/************************************************************************/
 22class CTextureArray
 23{
 24public:
 25  CTextureArray(int width, int height, int loops, bool texCoordsArePixels = false);
 26  CTextureArray();
 27
 28  virtual ~CTextureArray();
 29
 30  void Reset();
 31
 32  void Add(CBaseTexture *texture, int delay);
 33  void Set(CBaseTexture *texture, int width, int height);
 34  void Free();
 35  unsigned int size() const;
 36
 37  std::vector<CBaseTexture* > m_textures;
 38  std::vector<int> m_delays;
 39  int m_width;
 40  int m_height;
 41  int m_orientation;
 42  int m_loops;
 43  int m_texWidth;
 44  int m_texHeight;
 45  bool m_texCoordsArePixels;
 46};
 47
 48/*!
 49 \ingroup textures
 50 \brief
 51 */
 52/************************************************************************/
 53/*                                                                      */
 54/************************************************************************/
 55class CTextureMap
 56{
 57public:
 58  CTextureMap();
 59  CTextureMap(const std::string& textureName, int width, int height, int loops);
 60  virtual ~CTextureMap();
 61
 62  void Add(CBaseTexture* texture, int delay);
 63  bool Release();
 64
 65  const std::string& GetName() const;
 66  const CTextureArray& GetTexture();
 67  void Dump() const;
 68  uint32_t GetMemoryUsage() const;
 69  void Flush();
 70  bool IsEmpty() const;
 71  void SetHeight(int height);
 72  void SetWidth(int height);
 73protected:
 74  void FreeTexture();
 75
 76  CTextureArray m_texture;
 77  std::string m_textureName;
 78  unsigned int m_referenceCount;
 79  uint32_t m_memUsage;
 80};
 81
 82/*!
 83 \ingroup textures
 84 \brief
 85 */
 86/************************************************************************/
 87/*                                                                      */
 88/************************************************************************/
 89class CGUITextureManager
 90{
 91public:
 92  CGUITextureManager(void);
 93  virtual ~CGUITextureManager(void);
 94
 95  bool HasTexture(const std::string &textureName, std::string *path = NULL, int *bundle = NULL, int *size = NULL);
 96  static bool CanLoad(const std::string &texturePath); ///< Returns true if the texture manager can load this texture
 97  const CTextureArray& Load(const std::string& strTextureName, bool checkBundleOnly = false);
 98  void ReleaseTexture(const std::string& strTextureName, bool immediately = false);
 99  void Cleanup();
100  void Dump() const;
101  uint32_t GetMemoryUsage() const;
102  void Flush();
103  std::string GetTexturePath(const std::string& textureName, bool directory = false);
104  void GetBundledTexturesFromPath(const std::string& texturePath, std::vector<std::string> &items);
105
106  void AddTexturePath(const std::string &texturePath);    ///< Add a new path to the paths to check when loading media
107  void SetTexturePath(const std::string &texturePath);    ///< Set a single path as the path to check when loading media (clear then add)
108  void RemoveTexturePath(const std::string &texturePath); ///< Remove a path from the paths to check when loading media
109
110  void FreeUnusedTextures(unsigned int timeDelay = 0); ///< Free textures (called from app thread only)
111  void ReleaseHwTexture(unsigned int texture);
112protected:
113  std::vector<CTextureMap*> m_vecTextures;
114  std::list<std::pair<CTextureMap*, unsigned int> > m_unusedTextures;
115  std::vector<unsigned int> m_unusedHwTextures;
116  typedef std::vector<CTextureMap*>::iterator ivecTextures;
117  typedef std::list<std::pair<CTextureMap*, unsigned int> >::iterator ilistUnused;
118  // we have 2 texture bundles (one for the base textures, one for the theme)
119  CTextureBundle m_TexBundle[2];
120
121  std::vector<std::string> m_texturePaths;
122  CCriticalSection m_section;
123};
124