jni: add a wait for window in egl for android, and use a live copy
[vuplus_xbmc] / xbmc / windowing / egl / EGLNativeTypeAndroid.cpp
1 /*
2  *      Copyright (C) 2011-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 #include "system.h"
21 #include <EGL/egl.h>
22 #include "EGLNativeTypeAndroid.h"
23 #include "utils/log.h"
24 #include "guilib/gui3d.h"
25 #if defined(TARGET_ANDROID)
26 #include "android/activity/XBMCApp.h"
27 #endif
28 CEGLNativeTypeAndroid::CEGLNativeTypeAndroid()
29 {
30 }
31
32 CEGLNativeTypeAndroid::~CEGLNativeTypeAndroid()
33 {
34
35
36 bool CEGLNativeTypeAndroid::CheckCompatibility()
37 {
38 #if defined(TARGET_ANDROID)
39   return true;
40 #endif
41   return false;
42 }
43
44 void CEGLNativeTypeAndroid::Initialize()
45 {
46   return;
47 }
48 void CEGLNativeTypeAndroid::Destroy()
49 {
50   return;
51 }
52
53 bool CEGLNativeTypeAndroid::CreateNativeDisplay()
54 {
55   m_nativeDisplay = EGL_DEFAULT_DISPLAY;
56   return true;
57 }
58
59 bool CEGLNativeTypeAndroid::CreateNativeWindow()
60 {
61 #if defined(TARGET_ANDROID)
62   // Android hands us a window, we don't have to create it
63   return true;
64 #else
65   return false;
66 #endif
67 }  
68
69 bool CEGLNativeTypeAndroid::GetNativeDisplay(XBNativeDisplayType **nativeDisplay) const
70 {
71   if (!nativeDisplay)
72     return false;
73   *nativeDisplay = (XBNativeDisplayType*) &m_nativeDisplay;
74   return true;
75 }
76
77 bool CEGLNativeTypeAndroid::GetNativeWindow(XBNativeWindowType **nativeWindow) const
78 {
79   if (!nativeWindow)
80     return false;
81   *nativeWindow = (XBNativeWindowType*) CXBMCApp::GetNativeWindow(30000);
82   return (*nativeWindow != NULL);
83 }
84
85 bool CEGLNativeTypeAndroid::DestroyNativeDisplay()
86 {
87   return true;
88 }
89
90 bool CEGLNativeTypeAndroid::DestroyNativeWindow()
91 {
92   return true;
93 }
94
95 bool CEGLNativeTypeAndroid::GetNativeResolution(RESOLUTION_INFO *res) const
96 {
97 #if defined(TARGET_ANDROID)
98   EGLNativeWindowType *nativeWindow = (EGLNativeWindowType*)CXBMCApp::GetNativeWindow(30000);
99   if (!nativeWindow)
100     return false;
101
102   ANativeWindow_acquire(*nativeWindow);
103   res->iWidth = ANativeWindow_getWidth(*nativeWindow);
104   res->iHeight= ANativeWindow_getHeight(*nativeWindow);
105   ANativeWindow_release(*nativeWindow);
106
107   res->fRefreshRate = 60;
108   res->dwFlags= D3DPRESENTFLAG_PROGRESSIVE;
109   res->iScreen       = 0;
110   res->bFullScreen   = true;
111   res->iSubtitles    = (int)(0.965 * res->iHeight);
112   res->fPixelRatio   = 1.0f;
113   res->iScreenWidth  = res->iWidth;
114   res->iScreenHeight = res->iHeight;
115   res->strMode.Format("%dx%d @ %.2f%s - Full Screen", res->iScreenWidth, res->iScreenHeight, res->fRefreshRate,
116   res->dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
117   CLog::Log(LOGNOTICE,"Current resolution: %s\n",res->strMode.c_str());
118   return true;
119 #else
120   return false;
121 #endif
122 }
123
124 bool CEGLNativeTypeAndroid::SetNativeResolution(const RESOLUTION_INFO &res)
125 {
126   return false;
127 }
128
129 bool CEGLNativeTypeAndroid::ProbeResolutions(std::vector<RESOLUTION_INFO> &resolutions)
130 {
131   RESOLUTION_INFO res;
132   bool ret = false;
133   ret = GetNativeResolution(&res);
134   if (ret && res.iWidth > 1 && res.iHeight > 1)
135   {
136     resolutions.push_back(res);
137     return true;
138   }
139   return false;
140 }
141
142 bool CEGLNativeTypeAndroid::GetPreferredResolution(RESOLUTION_INFO *res) const
143 {
144   return false;
145 }
146
147 bool CEGLNativeTypeAndroid::ShowWindow(bool show)
148 {
149   return false;
150 }