[XAudio2] avoid leak + fix voice creation for closest match
[xbmc.git] / xbmc / TextureCacheJob.h
blob859e04c3c7c570e07bd8ac3f9b8b74f16fed6407
1 /*
2 * Copyright (C) 2012-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 "pictures/PictureScalingAlgorithm.h"
12 #include "utils/Job.h"
14 #include <memory>
15 #include <string>
16 #include <vector>
18 class CTexture;
19 namespace IMAGE_FILES
21 class CImageFileURL;
24 /*!
25 \ingroup textures
26 \brief Simple class for passing texture detail around
28 class CTextureDetails
30 public:
31 bool operator==(const CTextureDetails &right) const
33 return (id == right.id &&
34 file == right.file &&
35 width == right.width );
38 int id{-1};
39 std::string file;
40 std::string hash;
41 unsigned int width{0};
42 unsigned int height{0};
43 bool updateable{false};
44 bool hashRevalidated{false};
47 /*!
48 \ingroup textures
49 \brief Job class for caching textures
51 Handles loading and caching of textures.
53 class CTextureCacheJob : public CJob
55 public:
56 CTextureCacheJob(const std::string &url, const std::string &oldHash = "");
57 ~CTextureCacheJob() override;
59 const char* GetType() const override { return kJobTypeCacheImage; }
60 bool operator==(const CJob *job) const override;
61 bool DoWork() override;
63 /*! \brief retrieve a hash for the given image
64 Combines the size, ctime and mtime of the image file into a "unique" hash
65 \param url location of the image
66 \return a hash string for this image
68 bool CacheTexture(std::unique_ptr<CTexture>* texture = nullptr);
70 static bool ResizeTexture(const std::string& url,
71 unsigned int height,
72 unsigned int width,
73 CPictureScalingAlgorithm::Algorithm scalingAlgorithm,
74 uint8_t*& result,
75 size_t& result_size);
77 std::string m_url;
78 std::string m_oldHash;
79 CTextureDetails m_details;
80 private:
81 /*! \brief retrieve a hash for the given image
82 Combines the size, ctime and mtime of the image file into a "unique" hash
83 \param url location of the image
84 \return a hash string for this image
86 static std::string GetImageHash(const std::string &url);
88 /*! \brief Load an image at a given target size and orientation.
90 Doesn't necessarily load the image at the desired size - the loader *may* decide to load it slightly larger
91 or smaller than the desired size for speed reasons.
93 \param image the URL of the image file.
94 \return a pointer to a CTexture object, NULL if failed.
96 static std::unique_ptr<CTexture> LoadImage(const IMAGE_FILES::CImageFileURL& imageURL);
98 std::string m_cachePath;
101 /* \brief Job class for storing the use count of textures
103 class CTextureUseCountJob : public CJob
105 public:
106 explicit CTextureUseCountJob(const std::vector<CTextureDetails> &textures);
108 const char* GetType() const override { return "usecount"; }
109 bool operator==(const CJob *job) const override;
110 bool DoWork() override;
112 private:
113 std::vector<CTextureDetails> m_textures;