[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / guilib / GUITexture.h
blobbbedc3aa212e5ece7d6bcbc8a4be196042eec0c7
1 /*
2 * Copyright (C) 2005-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 "TextureManager.h"
12 #include "guiinfo/GUIInfoColor.h"
13 #include "utils/ColorUtils.h"
14 #include "utils/Geometry.h"
16 #include <functional>
18 // image alignment for <aspect>keep</aspect>, <aspect>scale</aspect> or <aspect>center</aspect>
19 #define ASPECT_ALIGN_CENTER 0
20 #define ASPECT_ALIGN_LEFT 1
21 #define ASPECT_ALIGN_RIGHT 2
22 #define ASPECT_ALIGNY_CENTER 0
23 #define ASPECT_ALIGNY_TOP 4
24 #define ASPECT_ALIGNY_BOTTOM 8
25 #define ASPECT_ALIGN_MASK 3
26 #define ASPECT_ALIGNY_MASK ~3
28 class CAspectRatio
30 public:
31 enum ASPECT_RATIO { AR_STRETCH = 0, AR_SCALE, AR_KEEP, AR_CENTER };
32 CAspectRatio(ASPECT_RATIO aspect = AR_STRETCH)
34 ratio = aspect;
35 align = ASPECT_ALIGN_CENTER | ASPECT_ALIGNY_CENTER;
36 scaleDiffuse = true;
38 bool operator!=(const CAspectRatio &right) const
40 if (ratio != right.ratio) return true;
41 if (align != right.align) return true;
42 if (scaleDiffuse != right.scaleDiffuse) return true;
43 return false;
46 ASPECT_RATIO ratio;
47 uint32_t align;
48 bool scaleDiffuse;
51 class CTextureInfo
53 public:
54 CTextureInfo();
55 explicit CTextureInfo(const std::string &file);
56 bool useLarge;
57 CRect border; // scaled - unneeded if we get rid of scale on load
58 bool m_infill{
59 true}; // if false, the main body of a texture is not drawn. useful for borders with no inner filling
60 int orientation; // orientation of the texture (0 - 7 == EXIForientation - 1)
61 std::string diffuse; // diffuse overlay texture
62 KODI::GUILIB::GUIINFO::CGUIInfoColor diffuseColor; // diffuse color
63 std::string filename; // main texture file
66 class CGUITexture;
68 using CreateGUITextureFunc = std::function<CGUITexture*(
69 float posX, float posY, float width, float height, const CTextureInfo& texture)>;
70 using DrawQuadFunc = std::function<void(const CRect& coords,
71 UTILS::COLOR::Color color,
72 CTexture* texture,
73 const CRect* texCoords,
74 const float depth,
75 const bool blending)>;
77 class CGUITexture
79 public:
80 virtual ~CGUITexture() = default;
82 static void Register(const CreateGUITextureFunc& createFunction,
83 const DrawQuadFunc& drawQuadFunction);
85 static CGUITexture* CreateTexture(
86 float posX, float posY, float width, float height, const CTextureInfo& texture);
87 virtual CGUITexture* Clone() const = 0;
89 static void DrawQuad(const CRect& coords,
90 UTILS::COLOR::Color color,
91 CTexture* texture = nullptr,
92 const CRect* texCoords = nullptr,
93 const float depth = 1.0,
94 const bool blending = true);
96 bool Process(unsigned int currentTime);
97 void Render(int32_t depthOffset = 0, int32_t overrideDepth = -1);
99 void DynamicResourceAlloc(bool bOnOff);
100 bool AllocResources();
101 void FreeResources(bool immediately = false);
102 void SetInvalid();
104 bool SetVisible(bool visible);
105 bool SetAlpha(unsigned char alpha);
106 bool SetDiffuseColor(UTILS::COLOR::Color color, const CGUIListItem* item = nullptr);
107 bool SetPosition(float x, float y);
108 bool SetWidth(float width);
109 bool SetHeight(float height);
110 bool SetFileName(const std::string &filename);
111 void SetUseCache(const bool useCache = true);
112 bool SetAspectRatio(const CAspectRatio &aspect);
114 const std::string& GetFileName() const { return m_info.filename; }
115 float GetTextureWidth() const { return m_frameWidth; }
116 float GetTextureHeight() const { return m_frameHeight; }
117 float GetWidth() const { return m_width; }
118 float GetHeight() const { return m_height; }
119 float GetXPosition() const { return m_posX; }
120 float GetYPosition() const { return m_posY; }
121 int GetOrientation() const;
122 const CRect& GetRenderRect() const { return m_vertex; }
123 bool IsLazyLoaded() const { return m_info.useLarge; }
126 * @brief Get the diffuse color (info color) associated to this texture
127 * @return the infocolor associated to this texture
129 KODI::GUILIB::GUIINFO::CGUIInfoColor GetDiffuseColor() const { return m_info.diffuseColor; }
131 bool HitTest(const CPoint& point) const
133 return CRect(m_posX, m_posY, m_posX + m_width, m_posY + m_height).PtInRect(point);
135 bool IsAllocated() const { return m_isAllocated != NO; }
136 bool FailedToAlloc() const
138 return m_isAllocated == NORMAL_FAILED || m_isAllocated == LARGE_FAILED;
140 bool ReadyToRender() const;
142 protected:
143 CGUITexture(float posX, float posY, float width, float height, const CTextureInfo& texture);
144 CGUITexture(const CGUITexture& left);
146 bool CalculateSize();
147 bool AllocateOnDemand();
148 bool UpdateAnimFrame(unsigned int currentTime);
149 void Render(float left,
150 float top,
151 float right,
152 float bottom,
153 float u1,
154 float v1,
155 float u2,
156 float v2,
157 float u3,
158 float v3);
159 static void OrientateTexture(CRect &rect, float width, float height, int orientation);
160 void ResetAnimState();
162 // functions that our implementation classes handle
163 virtual void Allocate() {}; ///< called after our textures have been allocated
164 virtual void Free() {}; ///< called after our textures have been freed
165 virtual void Begin(UTILS::COLOR::Color color) = 0;
166 virtual void Draw(float* x,
167 float* y,
168 float* z,
169 const CRect& texture,
170 const CRect& diffuse,
171 int orientation) = 0;
172 virtual void End() = 0;
174 bool m_visible;
175 UTILS::COLOR::Color m_diffuseColor;
177 float m_posX; // size of the frame
178 float m_posY;
179 float m_width;
180 float m_height;
181 float m_depth{0};
183 CRect m_vertex; // vertex coords to render
184 bool m_invalid; // if true, we need to recalculate
185 bool m_use_cache;
186 unsigned char m_alpha;
188 float m_frameWidth, m_frameHeight; // size in pixels of the actual frame within the texture
189 float m_texCoordsScaleU, m_texCoordsScaleV; // scale factor for pixel->texture coordinates
191 // animations
192 int m_currentLoop;
193 unsigned int m_currentFrame;
194 uint32_t m_lasttime;
196 float m_diffuseU, m_diffuseV; // size of the diffuse frame (in tex coords)
197 float m_diffuseScaleU, m_diffuseScaleV; // scale factor of the diffuse frame (from texture coords to diffuse tex coords)
198 CPoint m_diffuseOffset; // offset into the diffuse frame (it's not always the origin)
200 bool m_allocateDynamically;
201 enum ALLOCATE_TYPE { NO = 0, NORMAL, LARGE, NORMAL_FAILED, LARGE_FAILED };
202 ALLOCATE_TYPE m_isAllocated;
204 CTextureInfo m_info;
205 CAspectRatio m_aspect;
207 CTextureArray m_diffuse;
208 CTextureArray m_texture;
210 private:
211 static CreateGUITextureFunc m_createGUITextureFunc;
212 static DrawQuadFunc m_drawQuadFunc;