kodi
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:
29  bool operator==(const CTextureDetails &right) const
30  {
31  return (id == right.id &&
32  file == right.file &&
33  width == right.width );
34  };
35 
36  int id{-1};
37  std::string file;
38  std::string hash;
39  unsigned int width{0};
40  unsigned int height{0};
41  bool updateable{false};
42  bool hashRevalidated{false};
43 };
44 
51 class CTextureCacheJob : public CJob
52 {
53 public:
54  CTextureCacheJob(const std::string &url, const std::string &oldHash = "");
55  ~CTextureCacheJob() override;
56 
57  const char* GetType() const override { return kJobTypeCacheImage; }
58  bool operator==(const CJob *job) const override;
59  bool DoWork() override;
60 
66  bool CacheTexture(std::unique_ptr<CTexture>* texture = nullptr);
67 
68  static bool ResizeTexture(const std::string &url, uint8_t* &result, size_t &result_size);
69 
70  std::string m_url;
71  std::string m_oldHash;
72  CTextureDetails m_details;
73 private:
79  static std::string GetImageHash(const std::string &url);
80 
89  static std::string DecodeImageURL(const std::string &url, unsigned int &width, unsigned int &height, CPictureScalingAlgorithm::Algorithm& scalingAlgorithm, std::string &additional_info);
90 
102  static std::unique_ptr<CTexture> LoadImage(const std::string& image,
103  unsigned int width,
104  unsigned int height,
105  const std::string& additional_info,
106  bool requirePixels = false);
107 
108  std::string m_cachePath;
109 };
110 
111 /* \brief Job class for storing the use count of textures
112  */
113 class CTextureUseCountJob : public CJob
114 {
115 public:
116  explicit CTextureUseCountJob(const std::vector<CTextureDetails> &textures);
117 
118  const char* GetType() const override { return "usecount"; }
119  bool operator==(const CJob *job) const override;
120  bool DoWork() override;
121 
122 private:
123  std::vector<CTextureDetails> m_textures;
124 };
Definition: TextureCacheJob.h:113
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:118
Job class for caching textures.
Definition: TextureCacheJob.h:51
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:57