xbmc
GUILargeTextureManager.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 "guilib/TextureManager.h"
12 #include "threads/CriticalSection.h"
13 #include "utils/Job.h"
14 
15 #include <memory>
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
20 class CTexture;
21 
30 class CImageLoader : public CJob
31 {
32 public:
33  CImageLoader(const std::string &path, const bool useCache);
34  ~CImageLoader() override;
35 
39  bool DoWork() override;
40 
41  bool m_use_cache;
42  std::string m_path;
43  std::unique_ptr<CTexture> m_texture;
44 };
45 
56 {
57 public:
59  ~CGUILargeTextureManager() override;
60 
68  void OnJobComplete(unsigned int jobID, bool success, CJob *job) override;
69 
84  bool GetImage(const std::string &path, CTextureArray &texture, bool firstRequest, bool useCache = true);
85 
97  void ReleaseImage(const std::string &path, bool immediately = false);
98 
108  void CleanupUnusedImages(bool immediately = false);
109 
110 private:
111  class CLargeTexture
112  {
113  public:
114  explicit CLargeTexture(const std::string &path);
115  virtual ~CLargeTexture();
116 
117  void AddRef();
118  bool DecrRef(bool deleteImmediately);
119  bool DeleteIfRequired(bool deleteImmediately = false);
120  void SetTexture(std::unique_ptr<CTexture> texture);
121 
122  const std::string& GetPath() const { return m_path; }
123  const CTextureArray& GetTexture() const { return m_texture; }
124 
125  private:
126  static const unsigned int TIME_TO_DELETE = 2000;
127 
128  unsigned int m_refCount;
129  std::string m_path;
131  unsigned int m_timeToDelete;
132  };
133 
134  void QueueImage(const std::string &path, bool useCache = true);
135 
136  std::vector< std::pair<unsigned int, CLargeTexture *> > m_queued;
137  std::vector<CLargeTexture *> m_allocated;
138  typedef std::vector<CLargeTexture *>::iterator listIterator;
139  typedef std::vector< std::pair<unsigned int, CLargeTexture *> >::iterator queueIterator;
140 
141  CCriticalSection m_listSection;
142 };
143 
Definition: TextureManager.h:29
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
bool m_use_cache
Whether or not to use any caching with this image.
Definition: GUILargeTextureManager.h:41
std::string m_path
path of image to load
Definition: GUILargeTextureManager.h:42
Background texture loading manager.
Definition: GUILargeTextureManager.h:55
Base texture class, subclasses of which depend on the render spec (DX, GL etc.)
Definition: Texture.h:34
Callback interface for asynchronous jobs.
Definition: Job.h:31
bool DoWork() override
Work function that loads in a particular image.
Definition: GUILargeTextureManager.cpp:35
Image loader job class.
Definition: GUILargeTextureManager.h:30
std::unique_ptr< CTexture > m_texture
Texture object to load the image into.
Definition: GUILargeTextureManager.h:43