enigma2: 4.3.2r8
[opendreambox.git] / meta-opendreambox / recipes-mediacenter / kodi / kodi / 0001-EGL-Port-to-Dreambox.patch
1 From 799250e65c12b957db0014d6602fbb2f8644d149 Mon Sep 17 00:00:00 2001
2 From: Andreas Oberritter <obi@opendreambox.org>
3 Date: Thu, 16 Feb 2017 21:29:11 +0100
4 Subject: [PATCH] EGL: Port to Dreambox
5
6 ---
7  xbmc/utils/DreamboxUtils.cpp                 | 102 ++++++++++++++
8  xbmc/utils/DreamboxUtils.h                   |  24 ++++
9  xbmc/utils/Makefile.in                       |   1 +
10  xbmc/windowing/egl/EGLNativeTypeDreambox.cpp | 191 +++++++++++++++++++++++++++
11  xbmc/windowing/egl/EGLNativeTypeDreambox.h   |  61 +++++++++
12  xbmc/windowing/egl/EGLWrapper.cpp            |   2 +
13  xbmc/windowing/egl/Makefile.in               |   1 +
14  7 files changed, 382 insertions(+)
15  create mode 100644 xbmc/utils/DreamboxUtils.cpp
16  create mode 100644 xbmc/utils/DreamboxUtils.h
17  create mode 100644 xbmc/windowing/egl/EGLNativeTypeDreambox.cpp
18  create mode 100644 xbmc/windowing/egl/EGLNativeTypeDreambox.h
19
20 diff --git a/xbmc/utils/DreamboxUtils.cpp b/xbmc/utils/DreamboxUtils.cpp
21 new file mode 100644
22 index 0000000..0395201
23 --- /dev/null
24 +++ b/xbmc/utils/DreamboxUtils.cpp
25 @@ -0,0 +1,102 @@
26 +/*
27 + *      Copyright (C) 2011-2013 Team XBMC
28 + *      http://xbmc.org
29 + *
30 + *  This Program is free software; you can redistribute it and/or modify
31 + *  it under the terms of the GNU General Public License as published by
32 + *  the Free Software Foundation; either version 2, or (at your option)
33 + *  any later version.
34 + *
35 + *  This Program is distributed in the hope that it will be useful,
36 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
37 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 + *  GNU General Public License for more details.
39 + *
40 + *  You should have received a copy of the GNU General Public License
41 + *  along with XBMC; see the file COPYING.  If not, see
42 + *  <http://www.gnu.org/licenses/>.
43 + *
44 + */
45 +
46 +#include "DreamboxUtils.h"
47 +#include "guilib/gui3d.h"
48 +#include "utils/StringUtils.h"
49 +
50 +bool dreambox_mode_to_resolution(const char *mode, RESOLUTION_INFO *res)
51 +{
52 +  if (!res)
53 +    return false;
54 +
55 +  res->iWidth = 0;
56 +  res->iHeight = 0;
57 +  res->iScreenWidth = 0;
58 +  res->iScreenHeight = 0;
59 +
60 +  if (!mode)
61 +    return false;
62 +
63 +  std::string fromMode = mode;
64 +  StringUtils::Trim(fromMode);
65 +
66 +  const char types[] = { 'p', 'i', 'x' };
67 +  for (unsigned int i = 0; i < 3; i++) {
68 +    std::size_t pos = fromMode.find(types[i]);
69 +    if (pos == 0 || pos == std::string::npos)
70 +      continue;
71 +
72 +    std::string t1 = fromMode.substr(0, pos);
73 +    if (!StringUtils::IsInteger(t1))
74 +      return false;
75 +
76 +    std::string t2 = fromMode.substr(pos + 1);
77 +    if (types[i] == 'x') {
78 +      if (StringUtils::IsInteger(t2)) {
79 +        res->iScreenWidth = StringUtils::ReturnDigits(t1);
80 +        res->iScreenHeight = StringUtils::ReturnDigits(t2);
81 +      }
82 +    } else {
83 +      res->iScreenHeight = StringUtils::ReturnDigits(t1);
84 +
85 +      if (t2.empty())
86 +        res->fRefreshRate = 60;
87 +      else if (StringUtils::IsInteger(t2))
88 +        res->fRefreshRate = StringUtils::ReturnDigits(t2);
89 +
90 +      if (types[i] == 'p')
91 +        res->dwFlags = D3DPRESENTFLAG_PROGRESSIVE;
92 +      else
93 +        res->dwFlags = D3DPRESENTFLAG_INTERLACED;
94 +
95 +      if (res->iScreenHeight == 480)
96 +        res->iScreenWidth = 640;
97 +      else if (res->iScreenHeight == 576)
98 +        res->iScreenWidth = 720;
99 +      else if (res->iScreenHeight == 720)
100 +        res->iScreenWidth = 1280;
101 +      else if (res->iScreenHeight == 1080)
102 +        res->iScreenWidth = 1920;
103 +      else if (res->iScreenHeight == 2160)
104 +        res->iScreenWidth = 3840;
105 +
106 +      break;
107 +    }
108 +  }
109 +
110 +  if (res->iScreenHeight > 1080) {
111 +    res->iWidth = 1920;
112 +    res->iHeight = 1080;
113 +  } else {
114 +    res->iWidth = res->iScreenWidth;
115 +    res->iHeight = res->iScreenHeight;
116 +  }
117 +
118 +  res->iScreen       = 0;
119 +  res->bFullScreen   = true;
120 +  res->iSubtitles    = (int)(0.965 * res->iHeight);
121 +  res->fPixelRatio   = 1.0f;
122 +  res->strId         = fromMode;
123 +  res->strMode       = StringUtils::Format("%dx%d @ %.2f%s - Full Screen", res->iScreenWidth, res->iScreenHeight, res->fRefreshRate,
124 +    res->dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
125 +
126 +  return res->iWidth > 0 && res->iHeight> 0;
127 +}
128 diff --git a/xbmc/utils/DreamboxUtils.h b/xbmc/utils/DreamboxUtils.h
129 new file mode 100644
130 index 0000000..2f50360
131 --- /dev/null
132 +++ b/xbmc/utils/DreamboxUtils.h
133 @@ -0,0 +1,24 @@
134 +#pragma once
135 +/*
136 + *      Copyright (C) 2011-2013 Team XBMC
137 + *      http://xbmc.org
138 + *
139 + *  This Program is free software; you can redistribute it and/or modify
140 + *  it under the terms of the GNU General Public License as published by
141 + *  the Free Software Foundation; either version 2, or (at your option)
142 + *  any later version.
143 + *
144 + *  This Program is distributed in the hope that it will be useful,
145 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
146 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
147 + *  GNU General Public License for more details.
148 + *
149 + *  You should have received a copy of the GNU General Public License
150 + *  along with XBMC; see the file COPYING.  If not, see
151 + *  <http://www.gnu.org/licenses/>.
152 + *
153 + */
154 +
155 +#include "guilib/Resolution.h"
156 +
157 +bool dreambox_mode_to_resolution(const char *mode, RESOLUTION_INFO *res);
158 diff --git a/xbmc/utils/Makefile.in b/xbmc/utils/Makefile.in
159 index 7ec1b21..71d88d7 100644
160 --- a/xbmc/utils/Makefile.in
161 +++ b/xbmc/utils/Makefile.in
162 @@ -81,6 +81,7 @@ SRCS += SysfsUtils.cpp
163  
164  ifeq (@USE_OPENGLES@,1)
165  SRCS += AMLUtils.cpp
166 +SRCS += DreamboxUtils.cpp
167  endif
168  
169  ifeq (@USE_LIBAMCODEC@,1)
170 diff --git a/xbmc/windowing/egl/EGLNativeTypeDreambox.cpp b/xbmc/windowing/egl/EGLNativeTypeDreambox.cpp
171 new file mode 100644
172 index 0000000..9ffc351
173 --- /dev/null
174 +++ b/xbmc/windowing/egl/EGLNativeTypeDreambox.cpp
175 @@ -0,0 +1,191 @@
176 +/*
177 + *      Copyright (C) 2011-2013 Team XBMC
178 + *      http://xbmc.org
179 + *
180 + *  This Program is free software; you can redistribute it and/or modify
181 + *  it under the terms of the GNU General Public License as published by
182 + *  the Free Software Foundation; either version 2, or (at your option)
183 + *  any later version.
184 + *
185 + *  This Program is distributed in the hope that it will be useful,
186 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
187 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
188 + *  GNU General Public License for more details.
189 + *
190 + *  You should have received a copy of the GNU General Public License
191 + *  along with XBMC; see the file COPYING.  If not, see
192 + *  <http://www.gnu.org/licenses/>.
193 + *
194 + */
195 +
196 +#include "EGLNativeTypeDreambox.h"
197 +#include "guilib/gui3d.h"
198 +#include "utils/DreamboxUtils.h"
199 +#include "utils/StringUtils.h"
200 +#include "utils/SysfsUtils.h"
201 +
202 +#include <dlfcn.h>
203 +#include <stdio.h>
204 +#include <stdlib.h>
205 +#include <linux/fb.h>
206 +#include <sys/ioctl.h>
207 +#include <EGL/egl.h>
208 +
209 +CEGLNativeTypeDreambox::CEGLNativeTypeDreambox()
210 +{
211 +  m_nativeWindow = (XBNativeWindowType)0L;
212 +}
213 +
214 +CEGLNativeTypeDreambox::~CEGLNativeTypeDreambox()
215 +{
216 +}
217 +
218 +bool CEGLNativeTypeDreambox::CheckCompatibility()
219 +{
220 +  std::string name;
221 +  SysfsUtils::GetString("/proc/stb/info/model", name);
222 +  return name == "dm820" || name == "dm900" || name == "dm7080";
223 +}
224 +
225 +void CEGLNativeTypeDreambox::Initialize()
226 +{
227 +}
228 +
229 +void CEGLNativeTypeDreambox::Destroy()
230 +{
231 +}
232 +
233 +bool CEGLNativeTypeDreambox::CreateNativeDisplay()
234 +{
235 +  m_nativeDisplay = EGL_DEFAULT_DISPLAY;
236 +  return true;
237 +}
238 +
239 +bool CEGLNativeTypeDreambox::CreateNativeWindow()
240 +{
241 +  RESOLUTION_INFO res;
242 +  if (GetNativeResolution(&res))
243 +    SetFramebufferResolution(res.iWidth, res.iHeight);
244 +  else
245 +    SetFramebufferResolution(1280, 720);
246 +  return true;
247 +}
248 +
249 +bool CEGLNativeTypeDreambox::GetNativeDisplay(XBNativeDisplayType **nativeDisplay) const
250 +{
251 +  if (!nativeDisplay)
252 +    return false;
253 +  *nativeDisplay = (XBNativeDisplayType *)&m_nativeDisplay;
254 +  return true;
255 +}
256 +
257 +bool CEGLNativeTypeDreambox::GetNativeWindow(XBNativeWindowType **nativeWindow) const
258 +{
259 +  if (!nativeWindow)
260 +    return false;
261 +  *nativeWindow = (XBNativeWindowType *)&m_nativeWindow;
262 +  return true;
263 +}
264 +
265 +bool CEGLNativeTypeDreambox::DestroyNativeDisplay()
266 +{
267 +  return true;
268 +}
269 +
270 +bool CEGLNativeTypeDreambox::DestroyNativeWindow()
271 +{
272 +  return true;
273 +}
274 +
275 +bool CEGLNativeTypeDreambox::GetNativeResolution(RESOLUTION_INFO *res) const
276 +{
277 +  std::string mode;
278 +  SysfsUtils::GetString("/proc/stb/video/videomode", mode);
279 +  return dreambox_mode_to_resolution(mode.c_str(), res);
280 +}
281 +
282 +bool CEGLNativeTypeDreambox::SetNativeResolution(const RESOLUTION_INFO &res)
283 +{
284 +  // Don't set the same mode as current
285 +  std::string mode;
286 +  SysfsUtils::GetString("/proc/stb/video/videomode", mode);
287 +  if (res.strId == mode)
288 +    return false;
289 +
290 +  return SetDisplayResolution(res.strId.c_str());
291 +}
292 +
293 +bool CEGLNativeTypeDreambox::ProbeResolutions(std::vector<RESOLUTION_INFO> &resolutions)
294 +{
295 +  std::string valstr;
296 +  SysfsUtils::GetString("/proc/stb/video/videomode_choices", valstr);
297 +  std::vector<std::string> probe_str = StringUtils::Split(valstr, " ");
298 +
299 +  resolutions.clear();
300 +  RESOLUTION_INFO res;
301 +  for (std::vector<std::string>::const_iterator i = probe_str.begin(); i != probe_str.end(); ++i)
302 +  {
303 +    if (dreambox_mode_to_resolution(i->c_str(), &res))
304 +      resolutions.push_back(res);
305 +  }
306 +
307 +  return resolutions.size() > 0;
308 +}
309 +
310 +bool CEGLNativeTypeDreambox::GetPreferredResolution(RESOLUTION_INFO *res) const
311 +{
312 +  // check display/mode, it gets defaulted at boot
313 +  if (!GetNativeResolution(res))
314 +  {
315 +    // punt to 720p if we get nothing
316 +    dreambox_mode_to_resolution("720p", res);
317 +  }
318 +
319 +  return true;
320 +}
321 +
322 +bool CEGLNativeTypeDreambox::ShowWindow(bool show)
323 +{
324 +  SysfsUtils::SetInt("/proc/stb/video/alpha", show ? 255 : 0);
325 +  return true;
326 +}
327 +
328 +bool CEGLNativeTypeDreambox::SetDisplayResolution(const char *mode)
329 +{
330 +  // switch display resolution
331 +  SysfsUtils::SetString("/proc/stb/video/videomode", mode);
332 +
333 +  RESOLUTION_INFO res;
334 +  dreambox_mode_to_resolution(mode, &res);
335 +  SetFramebufferResolution(res);
336 +
337 +  return true;
338 +}
339 +
340 +void CEGLNativeTypeDreambox::SetFramebufferResolution(const RESOLUTION_INFO &res) const
341 +{
342 +  SetFramebufferResolution(res.iScreenWidth, res.iScreenHeight);
343 +}
344 +
345 +void CEGLNativeTypeDreambox::SetFramebufferResolution(int width, int height) const
346 +{
347 +  const char fbdev[] = "/dev/fb0";
348 +  int fd;
349 +
350 +  fd = open(fbdev, O_RDWR | O_CLOEXEC);
351 +  if (fd >= 0)
352 +  {
353 +    struct fb_var_screeninfo vinfo;
354 +    if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == 0)
355 +    {
356 +      vinfo.xres = width;
357 +      vinfo.yres = height;
358 +      vinfo.xres_virtual = width;
359 +      vinfo.yres_virtual = height * 2;
360 +      vinfo.bits_per_pixel = 32;
361 +      vinfo.activate = FB_ACTIVATE_ALL;
362 +      ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo);
363 +    }
364 +    close(fd);
365 +  }
366 +}
367 diff --git a/xbmc/windowing/egl/EGLNativeTypeDreambox.h b/xbmc/windowing/egl/EGLNativeTypeDreambox.h
368 new file mode 100644
369 index 0000000..eb03206
370 --- /dev/null
371 +++ b/xbmc/windowing/egl/EGLNativeTypeDreambox.h
372 @@ -0,0 +1,61 @@
373 +#pragma once
374 +
375 +/*
376 + *      Copyright (C) 2011-2013 Team XBMC
377 + *      http://xbmc.org
378 + *
379 + *  This Program is free software; you can redistribute it and/or modify
380 + *  it under the terms of the GNU General Public License as published by
381 + *  the Free Software Foundation; either version 2, or (at your option)
382 + *  any later version.
383 + *
384 + *  This Program is distributed in the hope that it will be useful,
385 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
386 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
387 + *  GNU General Public License for more details.
388 + *
389 + *  You should have received a copy of the GNU General Public License
390 + *  along with XBMC; see the file COPYING.  If not, see
391 + *  <http://www.gnu.org/licenses/>.
392 + *
393 + */
394 +
395 +#include <string>
396 +#include <vector>
397 +
398 +#include "EGLNativeType.h"
399 +class CEGLNativeTypeDreambox : public CEGLNativeType
400 +{
401 +public:
402 +  CEGLNativeTypeDreambox();
403 +  virtual ~CEGLNativeTypeDreambox();
404 +  virtual std::string GetNativeName() const { return "dreambox"; };
405 +  virtual bool  CheckCompatibility();
406 +  virtual void  Initialize();
407 +  virtual void  Destroy();
408 +  virtual int   GetQuirks() { return EGL_QUIRK_NONE; };
409 +
410 +  virtual bool  CreateNativeDisplay();
411 +  virtual bool  CreateNativeWindow();
412 +  virtual bool  GetNativeDisplay(XBNativeDisplayType **nativeDisplay) const;
413 +  virtual bool  GetNativeWindow(XBNativeWindowType **nativeWindow) const;
414 +
415 +  virtual bool  DestroyNativeWindow();
416 +  virtual bool  DestroyNativeDisplay();
417 +
418 +  virtual bool  GetNativeResolution(RESOLUTION_INFO *res) const;
419 +  virtual bool  SetNativeResolution(const RESOLUTION_INFO &res);
420 +  virtual bool  ProbeResolutions(std::vector<RESOLUTION_INFO> &resolutions);
421 +  virtual bool  GetPreferredResolution(RESOLUTION_INFO *res) const;
422 +
423 +  virtual bool  ShowWindow(bool show);
424 +
425 +protected:
426 +  bool SetDisplayResolution(const char *resolution);
427 +  void SetupVideoScaling(const char *mode);
428 +  void DisableFreeScale();
429 +
430 +private:
431 +  void SetFramebufferResolution(const RESOLUTION_INFO &res) const;
432 +  void SetFramebufferResolution(int width, int height) const;
433 +};
434 diff --git a/xbmc/windowing/egl/EGLWrapper.cpp b/xbmc/windowing/egl/EGLWrapper.cpp
435 index 583d43a..83064e2 100644
436 --- a/xbmc/windowing/egl/EGLWrapper.cpp
437 +++ b/xbmc/windowing/egl/EGLWrapper.cpp
438 @@ -33,6 +33,7 @@
439    #include "EGLNativeTypeIMX.h"
440  #endif
441  #include "EGLNativeTypeAmlogic.h"
442 +#include "EGLNativeTypeDreambox.h"
443  #include "EGLWrapper.h"
444  
445  #define CheckError() m_result = eglGetError(); if(m_result != EGL_SUCCESS) CLog::Log(LOGERROR, "EGL error in %s: %x",__FUNCTION__, m_result);
446 @@ -96,6 +97,7 @@ bool CEGLWrapper::Initialize(const std::string &implementation)
447  #elif defined(HAS_IMXVPU)
448        (nativeGuess = CreateEGLNativeType<CEGLNativeTypeIMX>(implementation))
449  #else
450 +      (nativeGuess = CreateEGLNativeType<CEGLNativeTypeDreambox>(implementation)) ||
451        (nativeGuess = CreateEGLNativeType<CEGLNativeTypeAmlogic>(implementation))
452  #endif
453        )
454 diff --git a/xbmc/windowing/egl/Makefile.in b/xbmc/windowing/egl/Makefile.in
455 index 68f7862..37517da 100644
456 --- a/xbmc/windowing/egl/Makefile.in
457 +++ b/xbmc/windowing/egl/Makefile.in
458 @@ -1,6 +1,7 @@
459  INCLUDES=-I.
460  
461  SRCS = WinSystemEGL.cpp
462 +SRCS+= EGLNativeTypeDreambox.cpp
463  SRCS+= EGLNativeTypeAmlogic.cpp
464  ifeq (@USE_ANDROID@,1)
465  SRCS+= EGLNativeTypeAndroid.cpp