VTB: release CVBuffer after it actually has been rendered
[xbmc.git] / xbmc / TextureCacheJob.h
blobdc716eb133d20ccb0154bdb0a035f115cb2f51eb
1 /*
2 * Copyright (C) 2012-2013 Team XBMC
3 * http://xbmc.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include <stdint.h>
24 #include <string>
25 #include <vector>
27 #include "pictures/PictureScalingAlgorithm.h"
28 #include "utils/Job.h"
30 class CBaseTexture;
32 /*!
33 \ingroup textures
34 \brief Simple class for passing texture detail around
36 class CTextureDetails
38 public:
39 CTextureDetails()
41 id = -1;
42 width = height = 0;
43 updateable = false;
45 bool operator==(const CTextureDetails &right) const
47 return (id == right.id &&
48 file == right.file &&
49 width == right.width );
51 int id;
52 std::string file;
53 std::string hash;
54 unsigned int width;
55 unsigned int height;
56 bool updateable;
59 /*!
60 \ingroup textures
61 \brief Job class for caching textures
63 Handles loading and caching of textures.
65 class CTextureCacheJob : public CJob
67 public:
68 CTextureCacheJob(const std::string &url, const std::string &oldHash = "");
69 virtual ~CTextureCacheJob();
71 virtual const char* GetType() const { return kJobTypeCacheImage; };
72 virtual bool operator==(const CJob *job) const;
73 virtual bool DoWork();
75 /*! \brief retrieve a hash for the given image
76 Combines the size, ctime and mtime of the image file into a "unique" hash
77 \param url location of the image
78 \return a hash string for this image
80 bool CacheTexture(CBaseTexture **texture = NULL);
82 static bool ResizeTexture(const std::string &url, uint8_t* &result, size_t &result_size);
84 std::string m_url;
85 std::string m_oldHash;
86 CTextureDetails m_details;
87 private:
88 /*! \brief retrieve a hash for the given image
89 Combines the size, ctime and mtime of the image file into a "unique" hash
90 \param url location of the image
91 \return a hash string for this image
93 static std::string GetImageHash(const std::string &url);
95 /*! \brief Check whether a given URL represents an image that can be updated
96 We currently don't check http:// and https:// URLs for updates, under the assumption that
97 a image URL is much more likely to be static and the actual image at the URL is unlikely
98 to change, so no point checking all the time.
99 \param url the url to check
100 \return true if the image given by the URL should be checked for updates, false otehrwise
102 bool UpdateableURL(const std::string &url) const;
104 /*! \brief Decode an image URL to the underlying image, width, height and orientation
105 \param url wrapped URL of the image
106 \param width width derived from URL
107 \param height height derived from URL
108 \param scalingAlgorithm scaling algorithm derived from URL
109 \param additional_info additional information, such as "flipped" to flip horizontally
110 \return URL of the underlying image file.
112 static std::string DecodeImageURL(const std::string &url, unsigned int &width, unsigned int &height, CPictureScalingAlgorithm::Algorithm& scalingAlgorithm, std::string &additional_info);
114 /*! \brief Load an image at a given target size and orientation.
116 Doesn't necessarily load the image at the desired size - the loader *may* decide to load it slightly larger
117 or smaller than the desired size for speed reasons.
119 \param image the URL of the image file.
120 \param width the desired maximum width.
121 \param height the desired maximum height.
122 \param additional_info extra info for loading, such as whether to flip horizontally.
123 \return a pointer to a CBaseTexture object, NULL if failed.
125 static CBaseTexture *LoadImage(const std::string &image, unsigned int width, unsigned int height, const std::string &additional_info, bool requirePixels = false);
127 std::string m_cachePath;
130 /* \brief Job class for storing the use count of textures
132 class CTextureUseCountJob : public CJob
134 public:
135 CTextureUseCountJob(const std::vector<CTextureDetails> &textures);
137 virtual const char* GetType() const { return "usecount"; };
138 virtual bool operator==(const CJob *job) const;
139 virtual bool DoWork();
141 private:
142 std::vector<CTextureDetails> m_textures;