-
Notifications
You must be signed in to change notification settings - Fork 6
/
EGLNativeTypeAndroid.cpp
173 lines (152 loc) · 4.47 KB
/
EGLNativeTypeAndroid.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* Copyright (C) 2011-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include <stdlib.h>
#include "system.h"
#include <EGL/egl.h>
#include "EGLNativeTypeAndroid.h"
#include "utils/log.h"
#include "guilib/gui3d.h"
#include "android/activity/XBMCApp.h"
#include "utils/StringUtils.h"
#include "android/jni/SystemProperties.h"
CEGLNativeTypeAndroid::CEGLNativeTypeAndroid()
: m_width(0), m_height(0)
{
}
CEGLNativeTypeAndroid::~CEGLNativeTypeAndroid()
{
}
bool CEGLNativeTypeAndroid::CheckCompatibility()
{
return true;
}
void CEGLNativeTypeAndroid::Initialize()
{
m_width = m_height = 0;
// FIXME: Temporary shield specific hack to obtain HDMI resolution
// Remove and use New Android M API
std::string displaySize = CJNISystemProperties::get("sys.display-size", "");
CLog::Log(LOGDEBUG, "CEGLNativeTypeAndroid: display-size: %s", displaySize.c_str());
if (!displaySize.empty())
{
std::vector<std::string> aSize = StringUtils::Split(displaySize, "x");
if (aSize.size() == 2)
{
m_width = StringUtils::IsInteger(aSize[0]) ? atoi(aSize[0].c_str()) : 0;
m_height = StringUtils::IsInteger(aSize[1]) ? atoi(aSize[1].c_str()) : 0;
}
}
return;
}
void CEGLNativeTypeAndroid::Destroy()
{
return;
}
bool CEGLNativeTypeAndroid::CreateNativeDisplay()
{
m_nativeDisplay = EGL_DEFAULT_DISPLAY;
return true;
}
bool CEGLNativeTypeAndroid::CreateNativeWindow()
{
// Android hands us a window, we don't have to create it
return true;
}
bool CEGLNativeTypeAndroid::GetNativeDisplay(XBNativeDisplayType **nativeDisplay) const
{
if (!nativeDisplay)
return false;
*nativeDisplay = (XBNativeDisplayType*) &m_nativeDisplay;
return true;
}
bool CEGLNativeTypeAndroid::GetNativeWindow(XBNativeWindowType **nativeWindow) const
{
if (!nativeWindow)
return false;
*nativeWindow = (XBNativeWindowType*) CXBMCApp::GetNativeWindow(30000);
return (*nativeWindow != NULL);
}
bool CEGLNativeTypeAndroid::DestroyNativeDisplay()
{
return true;
}
bool CEGLNativeTypeAndroid::DestroyNativeWindow()
{
return true;
}
bool CEGLNativeTypeAndroid::GetNativeResolution(RESOLUTION_INFO *res) const
{
EGLNativeWindowType *nativeWindow = (EGLNativeWindowType*)CXBMCApp::GetNativeWindow(30000);
if (!nativeWindow)
return false;
if (!m_width || !m_height)
{
ANativeWindow_acquire(*nativeWindow);
res->iWidth = ANativeWindow_getWidth(*nativeWindow);
res->iHeight= ANativeWindow_getHeight(*nativeWindow);
ANativeWindow_release(*nativeWindow);
}
else
{
res->iWidth = m_width;
res->iHeight = m_height;
}
res->fRefreshRate = 60;
res->dwFlags= D3DPRESENTFLAG_PROGRESSIVE;
res->iScreen = 0;
res->bFullScreen = true;
res->iSubtitles = (int)(0.965 * res->iHeight);
res->fPixelRatio = 1.0f;
res->iScreenWidth = res->iWidth;
res->iScreenHeight = res->iHeight;
res->strMode = StringUtils::Format("%dx%d @ %.2f%s - Full Screen", res->iScreenWidth, res->iScreenHeight, res->fRefreshRate,
res->dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
CLog::Log(LOGNOTICE,"Current resolution: %s\n",res->strMode.c_str());
return true;
}
bool CEGLNativeTypeAndroid::SetNativeResolution(const RESOLUTION_INFO &res)
{
CLog::Log(LOGDEBUG, "CEGLNativeTypeAndroid: SetNativeResolution: %dx%d", m_width, m_height);
if (m_width && m_height)
{
if (!CXBMCApp::SetBuffersGeometry(m_width, m_height, 0))
return false;
}
return true;
}
bool CEGLNativeTypeAndroid::ProbeResolutions(std::vector<RESOLUTION_INFO> &resolutions)
{
RESOLUTION_INFO res;
bool ret = GetNativeResolution(&res);
if (ret && res.iWidth > 1 && res.iHeight > 1)
{
resolutions.push_back(res);
return true;
}
return false;
}
bool CEGLNativeTypeAndroid::GetPreferredResolution(RESOLUTION_INFO *res) const
{
return false;
}
bool CEGLNativeTypeAndroid::ShowWindow(bool show)
{
return false;
}