Merge pull request #22634 from CastagnaIT/webvtt_overllaped_segment
[xbmc.git] / xbmc / windowing / GraphicContext.h
blob9cd4f327184708f1827e87754c86ac55f12a0f4c
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 "Resolution.h"
12 #include "rendering/RenderSystem.h"
13 #include "threads/CriticalSection.h"
14 #include "utils/ColorUtils.h"
15 #include "utils/Geometry.h" // for CRect/CPoint
16 #include "utils/TransformMatrix.h" // for the members m_guiTransform etc.
18 #include <map>
19 #include <stack>
20 #include <string>
21 #include <vector>
23 // required by clients
24 #include "ServiceBroker.h"
25 #include "WinSystem.h"
27 #define D3DPRESENTFLAG_INTERLACED 1
28 #define D3DPRESENTFLAG_WIDESCREEN 2
29 #define D3DPRESENTFLAG_PROGRESSIVE 4
30 #define D3DPRESENTFLAG_MODE3DSBS 8
31 #define D3DPRESENTFLAG_MODE3DTB 16
33 /* what types are important for mode setting */
34 #define D3DPRESENTFLAG_MODEMASK ( D3DPRESENTFLAG_INTERLACED \
35 | D3DPRESENTFLAG_MODE3DSBS \
36 | D3DPRESENTFLAG_MODE3DTB )
38 enum VIEW_TYPE { VIEW_TYPE_NONE = 0,
39 VIEW_TYPE_LIST,
40 VIEW_TYPE_ICON,
41 VIEW_TYPE_BIG_LIST,
42 VIEW_TYPE_BIG_ICON,
43 VIEW_TYPE_WIDE,
44 VIEW_TYPE_BIG_WIDE,
45 VIEW_TYPE_WRAP,
46 VIEW_TYPE_BIG_WRAP,
47 VIEW_TYPE_INFO,
48 VIEW_TYPE_BIG_INFO,
49 VIEW_TYPE_AUTO,
50 VIEW_TYPE_MAX };
52 enum AdjustRefreshRate
54 ADJUST_REFRESHRATE_OFF = 0,
55 ADJUST_REFRESHRATE_ALWAYS,
56 ADJUST_REFRESHRATE_ON_STARTSTOP,
57 ADJUST_REFRESHRATE_ON_START,
60 class CGraphicContext : public CCriticalSection
62 public:
63 CGraphicContext(void);
64 virtual ~CGraphicContext();
66 // methods related to windowing
67 float GetFPS() const;
68 void SetFPS(float fps);
69 float GetDisplayLatency() const;
70 bool IsFullScreenRoot() const;
71 void ToggleFullScreen();
72 void SetFullScreenVideo(bool bOnOff);
73 bool IsFullScreenVideo() const;
74 bool IsValidResolution(RESOLUTION res);
75 void SetVideoResolution(RESOLUTION res, bool forceUpdate);
76 void ApplyModeChange(RESOLUTION res);
77 void ApplyWindowResize(int newWidth, int newHeight);
78 RESOLUTION GetVideoResolution() const;
79 const RESOLUTION_INFO GetResInfo() const;
80 const RESOLUTION_INFO GetResInfo(RESOLUTION res) const;
81 void SetResInfo(RESOLUTION res, const RESOLUTION_INFO& info);
83 void Flip(bool rendered, bool videoLayer);
85 // gfx context interface
86 int GetWidth() const;
87 int GetHeight() const;
88 bool SetViewPort(float fx, float fy , float fwidth, float fheight, bool intersectPrevious = false);
89 void RestoreViewPort();
90 void SetScissors(const CRect &rect);
91 void ResetScissors();
92 const CRect &GetScissors() const;
93 const CRect GetViewWindow() const;
94 void SetViewWindow(float left, float top, float right, float bottom);
95 bool IsCalibrating() const;
96 void SetCalibrating(bool bOnOff);
97 void ResetOverscan(RESOLUTION res, OVERSCAN &overscan);
98 void ResetOverscan(RESOLUTION_INFO &resinfo);
99 void ResetScreenParameters(RESOLUTION res);
100 void CaptureStateBlock();
101 void ApplyStateBlock();
102 void Clear(UTILS::COLOR::Color color = 0);
103 void GetAllowedResolutions(std::vector<RESOLUTION> &res);
105 /* \brief Get UI scaling information from a given resolution to the screen resolution.
106 Takes account of overscan and UI zooming.
107 \param res the resolution to scale from.
108 \param scaleX [out] the scaling amount in the X direction.
109 \param scaleY [out] the scaling amount in the Y direction.
110 \param matrix [out] if non-NULL, a suitable transformation from res to screen resolution is set.
112 void GetGUIScaling(const RESOLUTION_INFO &res, float &scaleX, float &scaleY, TransformMatrix *matrix = NULL);
113 void SetRenderingResolution(const RESOLUTION_INFO &res, bool needsScaling); ///< Sets scaling up for rendering
114 void SetScalingResolution(const RESOLUTION_INFO &res, bool needsScaling); ///< Sets scaling up for skin loading etc.
115 float GetScalingPixelRatio() const;
116 void InvertFinalCoords(float &x, float &y) const;
117 float ScaleFinalXCoord(float x, float y) const;
118 float ScaleFinalYCoord(float x, float y) const;
119 float ScaleFinalZCoord(float x, float y) const;
120 void ScaleFinalCoords(float &x, float &y, float &z) const;
121 bool RectIsAngled(float x1, float y1, float x2, float y2) const;
122 const TransformMatrix &GetGUIMatrix() const;
123 float GetGUIScaleX() const;
124 float GetGUIScaleY() const;
125 UTILS::COLOR::Color MergeAlpha(UTILS::COLOR::Color color) const;
126 UTILS::COLOR::Color MergeColor(UTILS::COLOR::Color color) const;
127 void SetOrigin(float x, float y);
128 void RestoreOrigin();
129 void SetCameraPosition(const CPoint &camera);
130 void SetStereoView(RENDER_STEREO_VIEW view);
131 RENDER_STEREO_VIEW GetStereoView() { return m_stereoView; }
132 void SetStereoMode(RENDER_STEREO_MODE mode) { m_nextStereoMode = mode; }
133 RENDER_STEREO_MODE GetStereoMode() { return m_stereoMode; }
134 void RestoreCameraPosition();
135 void SetStereoFactor(float factor);
136 void RestoreStereoFactor();
137 /*! \brief Set a region in which to clip all rendering
138 Anything that is rendered after setting a clip region will be clipped so that no part renders
139 outside of the clip region. Successive calls to SetClipRegion intersect the clip region, which
140 means the clip region may eventually become an empty set. In this case SetClipRegion returns false
141 to indicate that no rendering need be performed.
143 This call must be matched with a RestoreClipRegion call unless SetClipRegion returns false.
145 Usage should be of the form:
147 if (SetClipRegion(x, y, w, h))
150 perform rendering
152 RestoreClipRegion();
155 \param x the left-most coordinate of the clip region
156 \param y the top-most coordinate of the clip region
157 \param w the width of the clip region
158 \param h the height of the clip region
159 \returns true if the region is set and the result is non-empty. Returns false if the resulting region is empty.
160 \sa RestoreClipRegion
162 bool SetClipRegion(float x, float y, float w, float h);
163 void RestoreClipRegion();
164 void ClipRect(CRect &vertex, CRect &texture, CRect *diffuse = NULL);
165 CRect GetClipRegion();
166 void AddGUITransform();
167 TransformMatrix AddTransform(const TransformMatrix &matrix);
168 void SetTransform(const TransformMatrix &matrix);
169 void SetTransform(const TransformMatrix &matrix, float scaleX, float scaleY);
170 void RemoveTransform();
172 /* modifies final coordinates according to stereo mode if needed */
173 CRect StereoCorrection(const CRect &rect) const;
174 CPoint StereoCorrection(const CPoint &point) const;
176 CRect GenerateAABB(const CRect &rect) const;
178 //@todo move those somewhere else
179 const std::string& GetMediaDir() const;
180 void SetMediaDir(const std::string& strMediaDir);
182 protected:
184 void UpdateCameraPosition(const CPoint &camera, const float &factor);
185 void SetVideoResolutionInternal(RESOLUTION res, bool forceUpdate);
186 void ApplyVideoResolution(RESOLUTION res);
187 void UpdateInternalStateWithResolution(RESOLUTION res);
189 int m_iScreenHeight = 576;
190 int m_iScreenWidth = 720;
191 std::string m_strMediaDir;
192 CRect m_videoRect;
193 bool m_bFullScreenRoot = true;
194 bool m_bFullScreenVideo = false;
195 bool m_bCalibrating = false;
196 RESOLUTION m_Resolution = RES_INVALID;
197 float m_fFPSOverride = 0.0f;
199 RESOLUTION_INFO m_windowResolution;
200 std::stack<CPoint> m_cameras;
201 std::stack<CPoint> m_origins;
202 std::stack<CRect> m_clipRegions;
203 std::stack<float> m_stereoFactors;
204 std::stack<CRect> m_viewStack;
205 CRect m_scissors;
207 class UITransform
209 public:
210 UITransform() : matrix() {}
211 UITransform(const TransformMatrix& m, const float sX = 1.0f, const float sY = 1.0f)
212 : matrix(m), scaleX(sX), scaleY(sY)
215 void Reset()
217 matrix.Reset();
218 scaleX = scaleY = 1.0f;
221 TransformMatrix matrix;
222 float scaleX = 1.0f;
223 float scaleY = 1.0f;
226 UITransform m_guiTransform;
227 UITransform m_finalTransform;
228 std::stack<UITransform> m_transforms;
229 RENDER_STEREO_VIEW m_stereoView = RENDER_STEREO_VIEW_OFF;
230 RENDER_STEREO_MODE m_stereoMode = RENDER_STEREO_MODE_OFF;
231 RENDER_STEREO_MODE m_nextStereoMode = RENDER_STEREO_MODE_OFF;