xbmc
TextureCacheJob.h
1 /*
2  * Copyright (C) 2012-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 "pictures/PictureScalingAlgorithm.h"
12 #include "utils/Job.h"
13 
14 #include <cstddef>
15 #include <memory>
16 #include <stdint.h>
17 #include <string>
18 #include <vector>
19 
20 class CTexture;
21 
27 {
28 public:
30  {
31  id = -1;
32  width = height = 0;
33  updateable = false;
34  };
35  bool operator==(const CTextureDetails &right) const
36  {
37  return (id == right.id &&
38  file == right.file &&
39  width == right.width );
40  };
41  int id;
42  std::string file;
43  std::string hash;
44  unsigned int width;
45  unsigned int height;
46  bool updateable;
47 };
48 
55 class CTextureCacheJob : public CJob
56 {
57 public:
58  CTextureCacheJob(const std::string &url, const std::string &oldHash = "");
59  ~CTextureCacheJob() override;
60 
61  const char* GetType() const override { return kJobTypeCacheImage; }
62  bool operator==(const CJob *job) const override;
63  bool DoWork() override;
64 
70  bool CacheTexture(std::unique_ptr<CTexture>* texture = nullptr);
71 
72  static bool ResizeTexture(const std::string &url, uint8_t* &result, size_t &result_size);
73 
74  std::string m_url;
75  std::string m_oldHash;
76  CTextureDetails m_details;
77 private:
83  static std::string GetImageHash(const std::string &url);
84 
92  bool UpdateableURL(const std::string &url) const;
93 
102  static std::string DecodeImageURL(const std::string &url, unsigned int &width, unsigned int &height, CPictureScalingAlgorithm::Algorithm& scalingAlgorithm, std::string &additional_info);
103 
115  static std::unique_ptr<CTexture> LoadImage(const std::string& image,
116  unsigned int width,
117  unsigned int height,
118  const std::string& additional_info,
119  bool requirePixels = false);
120 
121  std::string m_cachePath;
122 };
123 
124 /* \brief Job class for storing the use count of textures
125  */
126 class CTextureUseCountJob : public CJob
127 {
128 public:
129  explicit CTextureUseCountJob(const std::vector<CTextureDetails> &textures);
130 
131  const char* GetType() const override { return "usecount"; }
132  bool operator==(const CJob *job) const override;
133  bool DoWork() override;
134 
135 private:
136  std::vector<CTextureDetails> m_textures;
137 };
Definition: TextureCacheJob.h:126
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
Simple class for passing texture detail around.
Definition: TextureCacheJob.h:26
const char * GetType() const override
Function that returns the type of job.
Definition: TextureCacheJob.h:131
Job class for caching textures.
Definition: TextureCacheJob.h:55
Base texture class, subclasses of which depend on the render spec (DX, GL etc.)
Definition: Texture.h:34
const char * GetType() const override
Function that returns the type of job.
Definition: TextureCacheJob.h:61