[Test] Added tests for CUtil::SplitParams
[xbmc.git] / xbmc / guilib / TextureManager.h
blobef3128e360f41fc2c82d25fbd2c7c72487ea1901
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "GUIComponent.h"
12 #include "TextureBundle.h"
13 #include "threads/CriticalSection.h"
15 #include <chrono>
16 #include <cstddef>
17 #include <cstdint>
18 #include <list>
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
24 class CTexture;
26 /************************************************************************/
27 /* */
28 /************************************************************************/
29 class CTextureArray
31 public:
32 CTextureArray(int width, int height, int loops, bool texCoordsArePixels = false);
33 CTextureArray();
35 virtual ~CTextureArray();
37 void Reset();
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;
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;
55 /*!
56 \ingroup textures
57 \brief
59 /************************************************************************/
60 /* */
61 /************************************************************************/
62 class CTextureMap
64 public:
65 CTextureMap();
66 CTextureMap(const std::string& textureName, int width, int height, int loops);
67 virtual ~CTextureMap();
69 void Add(std::unique_ptr<CTexture> texture, int delay);
70 bool Release();
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();
83 CTextureArray m_texture;
84 std::string m_textureName;
85 unsigned int m_referenceCount;
86 uint32_t m_memUsage;
89 /*!
90 \ingroup textures
91 \brief
93 /************************************************************************/
94 /* */
95 /************************************************************************/
96 class CGUITextureManager
98 public:
99 CGUITextureManager(void);
100 virtual ~CGUITextureManager(void);
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); ///< Returns true if the texture manager can load this texture
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);
113 void AddTexturePath(const std::string &texturePath); ///< Add a new path to the paths to check when loading media
114 void SetTexturePath(const std::string &texturePath); ///< Set a single path as the path to check when loading media (clear then add)
115 void RemoveTexturePath(const std::string &texturePath); ///< Remove a path from the paths to check when loading media
117 void FreeUnusedTextures(unsigned int timeDelay = 0); ///< Free textures (called from app thread only)
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];
128 std::vector<std::string> m_texturePaths;
129 CCriticalSection m_section;