Merge pull request #5070 from Memphiz/osx_fix_devicechanged_recursionbp
[vuplus_xbmc] / xbmc / TextureCacheJob.h
1 /*
2  *      Copyright (C) 2012-2013 Team XBMC
3  *      http://xbmc.org
4  *
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.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #pragma once
22
23 #include "utils/StdString.h"
24 #include "utils/Job.h"
25
26 class CBaseTexture;
27
28 /*!
29  \ingroup textures
30  \brief Simple class for passing texture detail around
31  */
32 class CTextureDetails
33 {
34 public:
35   CTextureDetails()
36   {
37     id = -1;
38     width = height = 0;
39     updateable = false;
40   };
41   bool operator==(const CTextureDetails &right) const
42   {
43     return (id    == right.id    &&
44             file  == right.file  &&
45             width == right.width );
46   };
47   int          id;
48   std::string  file;
49   std::string  hash;
50   unsigned int width;
51   unsigned int height;
52   bool         updateable;
53 };
54
55 /*!
56  \ingroup textures
57  \brief Job class for caching textures
58  
59  Handles loading and caching of textures.
60  */
61 class CTextureCacheJob : public CJob
62 {
63 public:
64   CTextureCacheJob(const CStdString &url, const CStdString &oldHash = "");
65   virtual ~CTextureCacheJob();
66
67   virtual const char* GetType() const { return kJobTypeCacheImage; };
68   virtual bool operator==(const CJob *job) const;
69   virtual bool DoWork();
70
71   /*! \brief retrieve a hash for the given image
72    Combines the size, ctime and mtime of the image file into a "unique" hash
73    \param url location of the image
74    \return a hash string for this image
75    */
76   bool CacheTexture(CBaseTexture **texture = NULL);
77
78   CStdString m_url;
79   CStdString m_oldHash;
80   CTextureDetails m_details;
81 private:
82   friend class CEdenVideoArtUpdater;
83
84   /*! \brief retrieve a hash for the given image
85    Combines the size, ctime and mtime of the image file into a "unique" hash
86    \param url location of the image
87    \return a hash string for this image
88    */
89   static CStdString GetImageHash(const CStdString &url);
90
91   /*! \brief Check whether a given URL represents an image that can be updated
92    We currently don't check http:// and https:// URLs for updates, under the assumption that
93    a image URL is much more likely to be static and the actual image at the URL is unlikely
94    to change, so no point checking all the time.
95    \param url the url to check
96    \return true if the image given by the URL should be checked for updates, false otehrwise
97    */
98   bool UpdateableURL(const CStdString &url) const;
99
100   /*! \brief Decode an image URL to the underlying image, width, height and orientation
101    \param url wrapped URL of the image
102    \param width width derived from URL
103    \param height height derived from URL
104    \param additional_info additional information, such as "flipped" to flip horizontally
105    \return URL of the underlying image file.
106    */
107   static CStdString DecodeImageURL(const CStdString &url, unsigned int &width, unsigned int &height, std::string &additional_info);
108
109   /*! \brief Load an image at a given target size and orientation.
110
111    Doesn't necessarily load the image at the desired size - the loader *may* decide to load it slightly larger
112    or smaller than the desired size for speed reasons.
113
114    \param image the URL of the image file.
115    \param width the desired maximum width.
116    \param height the desired maximum height.
117    \param additional_info extra info for loading, such as whether to flip horizontally.
118    \return a pointer to a CBaseTexture object, NULL if failed.
119    */
120   static CBaseTexture *LoadImage(const CStdString &image, unsigned int width, unsigned int height, const std::string &additional_info, bool requirePixels = false);
121
122   CStdString    m_cachePath;
123 };
124
125 /* \brief Job class for creating .dds versions of textures
126  */
127 class CTextureDDSJob : public CJob
128 {
129 public:
130   CTextureDDSJob(const CStdString &original);
131
132   virtual const char* GetType() const { return kJobTypeDDSCompress; };
133   virtual bool operator==(const CJob *job) const;
134   virtual bool DoWork();
135
136   CStdString m_original;
137 };
138
139 /* \brief Job class for storing the use count of textures
140  */
141 class CTextureUseCountJob : public CJob
142 {
143 public:
144   CTextureUseCountJob(const std::vector<CTextureDetails> &textures);
145
146   virtual const char* GetType() const { return "usecount"; };
147   virtual bool operator==(const CJob *job) const;
148   virtual bool DoWork();
149
150 private:
151   std::vector<CTextureDetails> m_textures;
152 };