xbmc
TextureManager.h
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 <chrono>
16 #include <cstddef>
17 #include <cstdint>
18 #include <list>
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 class CTexture;
25 
26 /************************************************************************/
27 /* */
28 /************************************************************************/
30 {
31 public:
32  CTextureArray(int width, int height, int loops, bool texCoordsArePixels = false);
33  CTextureArray();
34 
35  virtual ~CTextureArray();
36 
37  void Reset();
38 
39  void Add(std::shared_ptr<CTexture> texture, int delay);
40  void Set(std::shared_ptr<CTexture> texture, int width, int height);
41  void Free();
42  unsigned int size() const;
43 
44  std::vector<std::shared_ptr<CTexture>> m_textures;
45  std::vector<int> m_delays;
46  int m_width;
47  int m_height;
48  int m_orientation;
49  int m_loops;
50  int m_texWidth;
51  int m_texHeight;
52  bool m_texCoordsArePixels;
53 };
54 
59 /************************************************************************/
60 /* */
61 /************************************************************************/
63 {
64 public:
65  CTextureMap();
66  CTextureMap(const std::string& textureName, int width, int height, int loops);
67  virtual ~CTextureMap();
68 
69  void Add(std::unique_ptr<CTexture> texture, int delay);
70  bool Release();
71 
72  const std::string& GetName() const;
73  const CTextureArray& GetTexture();
74  void Dump() const;
75  uint32_t GetMemoryUsage() const;
76  void Flush();
77  bool IsEmpty() const;
78  void SetHeight(int height);
79  void SetWidth(int height);
80 protected:
81  void FreeTexture();
82 
83  CTextureArray m_texture;
84  std::string m_textureName;
85  unsigned int m_referenceCount;
86  uint32_t m_memUsage;
87 };
88 
93 /************************************************************************/
94 /* */
95 /************************************************************************/
97 {
98 public:
99  CGUITextureManager(void);
100  virtual ~CGUITextureManager(void);
101 
102  bool HasTexture(const std::string &textureName, std::string *path = NULL, int *bundle = NULL, int *size = NULL);
103  static bool CanLoad(const std::string &texturePath);
104  const CTextureArray& Load(const std::string& strTextureName, bool checkBundleOnly = false);
105  void ReleaseTexture(const std::string& strTextureName, bool immediately = false);
106  void Cleanup();
107  void Dump() const;
108  uint32_t GetMemoryUsage() const;
109  void Flush();
110  std::string GetTexturePath(const std::string& textureName, bool directory = false);
111  std::vector<std::string> GetBundledTexturesFromPath(const std::string& texturePath);
112 
113  void AddTexturePath(const std::string &texturePath);
114  void SetTexturePath(const std::string &texturePath);
115  void RemoveTexturePath(const std::string &texturePath);
116 
117  void FreeUnusedTextures(unsigned int timeDelay = 0);
118  void ReleaseHwTexture(unsigned int texture);
119 protected:
120  std::vector<CTextureMap*> m_vecTextures;
121  std::list<std::pair<CTextureMap*, std::chrono::time_point<std::chrono::steady_clock>>>
122  m_unusedTextures;
123  std::vector<unsigned int> m_unusedHwTextures;
124  typedef std::vector<CTextureMap*>::iterator ivecTextures;
125  // we have 2 texture bundles (one for the base textures, one for the theme)
126  CTextureBundle m_TexBundle[2];
127 
128  std::vector<std::string> m_texturePaths;
129  CCriticalSection m_section;
130 };
131 
Definition: TextureManager.h:29
Base texture class, subclasses of which depend on the render spec (DX, GL etc.)
Definition: Texture.h:34
Definition: TextureManager.h:62
Definition: TextureBundle.h:20
Definition: TextureManager.h:96