how Google Android's surface manager works?

943 views
Skip to first unread message

Susmith M R

unread,
Apr 17, 2008, 11:55:54 AM4/17/08
to Android Internals, susmi...@in.bosch.com
Hai,
I want to know about the native opengl es usage with and without
the windowing system of android. Are anybody tried to render using
libGLES_CM.so natively. Anyone have any idea about the windowing
system of android and EGL specific details.
I was testing one small program on android . I got this program from
one of the OpenGL site.
#include <stdio.h>
#include "egl.h"
#include "gl.h"
int main(int argc, char** argv)
{
EGLConfig myConfig;

static const char sAppName[] =
"OpenGL Test (Linux)";
static EGLConfig sEglConfig;
EGLBoolean success;
EGLint numConfigs;
EGLint majorVersion;
EGLint minorVersion;
/*EGLint attrib_list[ ] =
{
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, EGL_DONT_CARE,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, EGL_DONT_CARE,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE, EGL_NONE
};
*/
/* EGLint attrib_list[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_STENCIL_SIZE, 8, EGL_DEPTH_SIZE, 16,
EGL_NONE };*/


EGLint num_config = 1;
EGLint attrib_list[] = { EGL_ALPHA_SIZE, EGL_DONT_CARE, EGL_RED_SIZE,
5,
EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_DEPTH_SIZE, 16,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE,EGL_NONE };

EGLDisplay m_eglDisplay = EGL_NO_DISPLAY;
EGLSurface m_eglSurface = EGL_NO_SURFACE;
EGLContext m_eglContext = EGL_NO_CONTEXT;

printf("Trying to get Display!\n");
m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (m_eglDisplay == EGL_NO_DISPLAY || eglGetError() != EGL_SUCCESS)
printf("It failed up on eglGetDisplay! %d \n ",eglGetError());
else
printf("It passed on eglGetDisplay! %d %d \n ",
(int)m_eglDisplay,eglGetError());


printf("Trying to initialize the Display!\n");
if (eglInitialize(m_eglDisplay, 0, 0) == EGL_FALSE || eglGetError() !
= EGL_SUCCESS)
printf("It failed up on initializing eglGetDisplay!%d \n
",eglGetError());
else
printf("It passed on initializing eglGetDisplay! %d \n
",eglGetError());


// if (success != EGL_FALSE)
// success = eglGetConfigs(m_eglDisplay, NULL, 0, &num_config);
// if (success != EGL_FALSE)
{
success = eglChooseConfig(m_eglDisplay, attrib_list, &myConfig, 10,
&num_config);
printf("ChooseConfig %d == %d \n ",success,num_config);
}

printf("Trying to get Context!\n");

m_eglContext = eglCreateContext(m_eglDisplay, myConfig, 0,
attrib_list);
if (m_eglContext == EGL_NO_CONTEXT || eglGetError() != EGL_SUCCESS)
printf("It failed up on eglCreateContext! %d \n ",eglGetError());
else
printf("It passed on eglCreateContext! %d \n ",eglGetError());

m_eglSurface = eglCreateWindowSurface(m_eglDisplay, myConfig,0,
attrib_list);

printf("Trying to get Surface!\n");
if (m_eglSurface == EGL_NO_SURFACE || eglGetError() != EGL_SUCCESS)
printf("It failed up on eglCreateWindowSurface! %d \n
",eglGetError());
else
printf("It passed on eglCreateWindowSurface! %d \n ",eglGetError());






eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface,
m_eglContext);



const static GLfloat v[] = {
0.25, 0.25, 0.0,
0.75, 0.25, 0.0,
0.25, 0.75, 0.0,
0.75, 0.75, 0.0
};

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glVertexPointer(3, GL_FLOAT, 0, v);
glEnableClientState(GL_VERTEX_ARRAY);

/// display graphic ///

glClearColor(0.0, 1.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);

glColor4f (1.0, 0.0, 0.0, 1.0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

/////
glFlush();
eglSwapBuffers(m_eglDisplay, m_eglSurface); // actually write to the
RGB 16-bit file


return 0;
}


But it is not succeeding . It is showing error at
eglCreateWindowSurface .
Can anybody help?

David Given

unread,
Apr 17, 2008, 6:52:26 PM4/17/08
to android-...@googlegroups.com
Susmith M R wrote:
[...]

> I was testing one small program on android . I got this program from
> one of the OpenGL site.

The problem is here:

[...]


> m_eglContext = eglCreateContext(m_eglDisplay, myConfig, 0,
> attrib_list);

That third parameter (which is 0, and I have no idea how Khronos ever
imagined this program would work) is a NativeWindowType, which is a
handle to a *platform-specific* window structure that provides the
interface between the EGL layer and the platform.

Unfortunately, we have no way of knowing what Android is using for this,
which means we have no way of creating it. It's probably going to be a
handle to some structure encapsulating a View, and most likely will have
to be created from inside Java code --- which means I doubt you'll have
much luck doing anything in pure C.

--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup

signature.asc

Susmith M R

unread,
Apr 18, 2008, 12:05:08 AM4/18/08
to Android Internals
Hai,
But luckly it is succeceding in eglCreateContext function in android.
But the eglCreateWindowSurface is failing with the return error
EGL_BAD_MATCH.
Can u point out some reson?

David Given

unread,
Apr 18, 2008, 5:07:58 PM4/18/08
to android-...@googlegroups.com
Susmith M R wrote:
> Hai,
> But luckly it is succeceding in eglCreateContext function in android.
> But the eglCreateWindowSurface is failing with the return error
> EGL_BAD_MATCH.

Oops, my mistake. I carefully checked the API and then cut-and-pasted
the wrong function.

It's eglCreateWindowSurface() into which you pass the NativeWindowType
value as the third parameter, not eglCreateContext(). See the man page:

http://www.khronos.org/opengles/documentation/opengles1_0/html/eglCreateWindowSurface.html

signature.asc
Reply all
Reply to author
Forward
0 new messages