/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. #pragma once
  9. #include "GUIComponent.h"
  10. #include "TextureBundle.h"
  11. #include "threads/CriticalSection.h"
  12. #include <list>
  13. #include <utility>
  14. #include <vector>
  15. /************************************************************************/
  16. /* */
  17. /************************************************************************/
  18. class CTextureArray
  19. {
  20. public:
  21. CTextureArray(int width, int height, int loops, bool texCoordsArePixels = false);
  22. CTextureArray();
  23. virtual ~CTextureArray();
  24. void Reset();
  25. void Add(CBaseTexture *texture, int delay);
  26. void Set(CBaseTexture *texture, int width, int height);
  27. void Free();
  28. unsigned int size() const;
  29. std::vector<CBaseTexture* > m_textures;
  30. std::vector<int> m_delays;
  31. int m_width;
  32. int m_height;
  33. int m_orientation;
  34. int m_loops;
  35. int m_texWidth;
  36. int m_texHeight;
  37. bool m_texCoordsArePixels;
  38. };
  39. /*!
  40. \ingroup textures
  41. \brief
  42. */
  43. /************************************************************************/
  44. /* */
  45. /************************************************************************/
  46. class CTextureMap
  47. {
  48. public:
  49. CTextureMap();
  50. CTextureMap(const std::string& textureName, int width, int height, int loops);
  51. virtual ~CTextureMap();
  52. void Add(CBaseTexture* texture, int delay);
  53. bool Release();
  54. const std::string& GetName() const;
  55. const CTextureArray& GetTexture();
  56. void Dump() const;
  57. uint32_t GetMemoryUsage() const;
  58. void Flush();
  59. bool IsEmpty() const;
  60. void SetHeight(int height);
  61. void SetWidth(int height);
  62. protected:
  63. void FreeTexture();
  64. CTextureArray m_texture;
  65. std::string m_textureName;
  66. unsigned int m_referenceCount;
  67. uint32_t m_memUsage;
  68. };
  69. /*!
  70. \ingroup textures
  71. \brief
  72. */
  73. /************************************************************************/
  74. /* */
  75. /************************************************************************/
  76. class CGUITextureManager
  77. {
  78. public:
  79. CGUITextureManager(void);
  80. virtual ~CGUITextureManager(void);
  81. bool HasTexture(const std::string &textureName, std::string *path = NULL, int *bundle = NULL, int *size = NULL);
  82. static bool CanLoad(const std::string &texturePath); ///< Returns true if the texture manager can load this texture
  83. const CTextureArray& Load(const std::string& strTextureName, bool checkBundleOnly = false);
  84. void ReleaseTexture(const std::string& strTextureName, bool immediately = false);
  85. void Cleanup();
  86. void Dump() const;
  87. uint32_t GetMemoryUsage() const;
  88. void Flush();
  89. std::string GetTexturePath(const std::string& textureName, bool directory = false);
  90. void GetBundledTexturesFromPath(const std::string& texturePath, std::vector<std::string> &items);
  91. void AddTexturePath(const std::string &texturePath); ///< Add a new path to the paths to check when loading media
  92. void SetTexturePath(const std::string &texturePath); ///< Set a single path as the path to check when loading media (clear then add)
  93. void RemoveTexturePath(const std::string &texturePath); ///< Remove a path from the paths to check when loading media
  94. void FreeUnusedTextures(unsigned int timeDelay = 0); ///< Free textures (called from app thread only)
  95. void ReleaseHwTexture(unsigned int texture);
  96. protected:
  97. std::vector<CTextureMap*> m_vecTextures;
  98. std::list<std::pair<CTextureMap*, unsigned int> > m_unusedTextures;
  99. std::vector<unsigned int> m_unusedHwTextures;
  100. typedef std::vector<CTextureMap*>::iterator ivecTextures;
  101. typedef std::list<std::pair<CTextureMap*, unsigned int> >::iterator ilistUnused;
  102. // we have 2 texture bundles (one for the base textures, one for the theme)
  103. CTextureBundle m_TexBundle[2];
  104. std::vector<std::string> m_texturePaths;
  105. CCriticalSection m_section;
  106. };