xbmc
OverlayRenderer.h
1 /*
2  * Initial code sponsored by: Voddler Inc (voddler.com)
3  * Copyright (C) 2005-2018 Team Kodi
4  * This file is part of Kodi - https://kodi.tv
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  * See LICENSES/README.md for more information.
8  */
9 
10 #pragma once
11 
12 #include "BaseRenderer.h"
13 #include "cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlay.h"
14 #include "cores/VideoPlayer/DVDSubtitles/SubtitlesStyle.h"
15 #include "settings/SubtitlesSettings.h"
16 #include "threads/CriticalSection.h"
17 #include "utils/Observer.h"
18 
19 #include <atomic>
20 #include <map>
21 #include <memory>
22 #include <vector>
23 
24 class CDVDOverlay;
25 class CDVDOverlayLibass;
26 class CDVDOverlayImage;
27 class CDVDOverlaySpu;
28 class CDVDOverlaySSA;
29 class CDVDOverlayText;
30 
31 namespace OVERLAY {
32 
33  struct SRenderState
34  {
35  float x;
36  float y;
37  float width;
38  float height;
39  };
40 
41  class COverlay
42  {
43  public:
44  COverlay();
45  virtual ~COverlay();
46 
47  virtual void Render(SRenderState& state) = 0;
48 
49  enum EType
50  {
51  TYPE_NONE,
52  TYPE_TEXTURE
53  } m_type;
54 
55  enum EAlign
56  {
57  ALIGN_SCREEN,
58  ALIGN_SCREEN_AR,
59  ALIGN_VIDEO,
60  ALIGN_SUBTITLE
61  } m_align;
62 
63  enum EPosition
64  {
65  POSITION_ABSOLUTE,
66  POSITION_ABSOLUTE_SCREEN,
67  POSITION_RELATIVE
68  } m_pos;
69 
70  float m_x{0};
71  float m_y{0};
72  float m_width{1.0f};
73  float m_height{1.0f};
74  float m_source_width{0}; // Video source width resolution used to calculate aspect ratio
75  float m_source_height{0}; // Video source height resolution used to calculate aspect ratio
76 
77  protected:
83  bool IsSquareResolution(float resRatio) { return resRatio > 1.22f && resRatio < 1.34f; }
84  };
85 
86  class CRenderer : public Observer
87  {
88  public:
89  CRenderer();
90  virtual ~CRenderer();
91 
92  // Implementation of Observer
93  void Notify(const Observable& obs, const ObservableMessage msg) override;
94 
95  void AddOverlay(std::shared_ptr<CDVDOverlay> o, double pts, int index);
96  virtual void Render(int idx);
97 
101  void UnInit();
102 
103  void Flush();
104 
108  void Reset();
109 
110  void Release(int idx);
111  bool HasOverlay(int idx);
112  void SetVideoRect(CRect &source, CRect &dest, CRect &view);
113  void SetStereoMode(const std::string &stereomode);
114 
121  void SetSubtitleVerticalPosition(const int value, bool save);
122 
123  protected:
127  void ResetSubtitlePosition();
128 
132  void OnViewChange();
133 
134  struct SElement
135  {
136  SElement()
137  {
138  overlay_dvd = NULL;
139  pts = 0.0;
140  }
141  double pts;
142  std::shared_ptr<CDVDOverlay> overlay_dvd;
143  };
144 
145  void Render(COverlay* o);
146  std::shared_ptr<COverlay> Convert(CDVDOverlay& o, double pts);
154  std::shared_ptr<COverlay> ConvertLibass(
156  double pts,
157  bool updateStyle,
158  const std::shared_ptr<struct KODI::SUBTITLES::STYLE::style>& overlayStyle);
159 
160  void CreateSubtitlesStyle();
161 
162  void Release(std::vector<SElement>& list);
163  void ReleaseCache();
164  void ReleaseUnused();
165 
169  void LoadSettings();
170 
171  enum PositonResInfoState
172  {
173  POSRESINFO_UNSET = -1,
174  POSRESINFO_SAVE_CHANGES = -2,
175  };
176 
177  CCriticalSection m_section;
178  std::vector<SElement> m_buffers[NUM_BUFFERS];
179  std::map<unsigned int, std::shared_ptr<COverlay>> m_textureCache;
180  static unsigned int m_textureid;
181  CRect m_rv; // Frame size
182  CRect m_rs; // Source size
183  CRect m_rd; // Video size, may be influenced by video settings (e.g. zoom)
184  std::string m_stereomode;
185  // Current subtitle position
186  int m_subtitlePosition{0};
187  // Current subtitle position from resolution info,
188  // or PositonResInfoState enum values for deferred processing
189  int m_subtitlePosResInfo{POSRESINFO_UNSET};
190  int m_subtitleVerticalMargin{0};
191  bool m_saveSubtitlePosition{false}; // To save subtitle position permanently
192  KODI::SUBTITLES::HorizontalAlign m_subtitleHorizontalAlign{
193  KODI::SUBTITLES::HorizontalAlign::CENTER};
194  KODI::SUBTITLES::Align m_subtitleAlign{KODI::SUBTITLES::Align::BOTTOM_OUTSIDE};
195 
196  std::shared_ptr<struct KODI::SUBTITLES::STYLE::style> m_overlayStyle;
197  std::atomic<bool> m_isSettingsChanged{false};
198  };
199 }
Definition: DVDOverlayText.h:16
Definition: DVDOverlaySSA.h:16
Definition: OverlayRenderer.h:41
Definition: OverlayRenderer.h:86
Definition: OverlayRenderer.h:31
Definition: DVDOverlayImage.h:18
bool IsSquareResolution(float resRatio)
Given the resolution ratio determines if it is a 4/3 resolution.
Definition: OverlayRenderer.h:83
Definition: DVDOverlayLibass.h:16
Definition: Observer.h:31
Definition: OverlayRenderer.h:33
Definition: OverlayRenderer.h:134
Definition: DVDOverlaySpu.h:16
Definition: Observer.h:44
Definition: DVDOverlay.h:27