RenderEngine.cpp revision 19e872912af66c53a4350afcc333bbafaf6a2294
1875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian/*
2875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * Copyright 2013 The Android Open Source Project
3875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian *
4875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * you may not use this file except in compliance with the License.
6875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * You may obtain a copy of the License at
7875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian *
8875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian *
10875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * Unless required by applicable law or agreed to in writing, software
11875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * See the License for the specific language governing permissions and
14875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * limitations under the License.
15875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian */
16875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
17875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include <cutils/log.h>
183f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include <ui/Rect.h>
193f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include <ui/Region.h>
20875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
21875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "RenderEngine.h"
22875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "GLES10RenderEngine.h"
23875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "GLES11RenderEngine.h"
243f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include "GLES20RenderEngine.h"
25875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "GLExtensions.h"
263f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include "Mesh.h"
27875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
2819e872912af66c53a4350afcc333bbafaf6a2294Jesse HallEGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name);
2919e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall
30875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
31875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiannamespace android {
32875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
33875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
3419e872912af66c53a4350afcc333bbafaf6a2294Jesse Hallstatic bool findExtension(const char* exts, const char* name) {
3519e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    if (!exts)
3619e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        return false;
3719e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    size_t len = strlen(name);
3819e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall
3919e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    const char* pos = exts;
4019e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    while ((pos = strstr(pos, name)) != NULL) {
4119e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        if (pos[len] == '\0' || pos[len] == ' ')
4219e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall            return true;
4319e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        pos += len;
4419e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    }
4519e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall
4619e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    return false;
4719e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall}
4819e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall
4905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse HallRenderEngine* RenderEngine::create(EGLDisplay display, int hwcFormat) {
5019e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // EGL_ANDROIDX_no_config_context is an experimental extension with no
5119e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // written specification. It will be replaced by something more formal.
5219e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // SurfaceFlinger is using it to allow a single EGLContext to render to
5319e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // both a 16-bit primary display framebuffer and a 32-bit virtual display
5419e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // framebuffer.
5519e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    //
5619e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // The code assumes that ES2 or later is available if this extension is
5719e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // supported.
5819e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    EGLConfig config = EGL_NO_CONFIG;
5919e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    if (!findExtension(
6019e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall            eglQueryStringImplementationANDROID(display, EGL_EXTENSIONS),
6119e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall            "EGL_ANDROIDX_no_config_context")) {
6219e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        config = chooseEglConfig(display, hwcFormat);
6319e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    }
6405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
652185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    EGLint renderableType = 0;
6619e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    if (config == EGL_NO_CONFIG) {
6719e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        renderableType = EGL_OPENGL_ES2_BIT;
6819e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    } else if (!eglGetConfigAttrib(display, config,
6919e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall            EGL_RENDERABLE_TYPE, &renderableType)) {
702185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian        LOG_ALWAYS_FATAL("can't query EGLConfig RENDERABLE_TYPE");
712185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    }
7219e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    EGLint contextClientVersion = 0;
732185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    if (renderableType & EGL_OPENGL_ES2_BIT) {
742185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian        contextClientVersion = 2;
752185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    } else if (renderableType & EGL_OPENGL_ES_BIT) {
762185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian        contextClientVersion = 1;
772185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    } else {
782185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian        LOG_ALWAYS_FATAL("no supported EGL_RENDERABLE_TYPEs");
792185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    }
802185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian
81875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    // Also create our EGLContext
82875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    EGLint contextAttributes[] = {
832185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian            EGL_CONTEXT_CLIENT_VERSION, contextClientVersion,      // MUST be first
84875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#ifdef EGL_IMG_context_priority
85875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#ifdef HAS_CONTEXT_PRIORITY
86875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#warning "using EGL_IMG_context_priority"
87875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG,
88875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif
89875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif
90875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            EGL_NONE, EGL_NONE
91875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    };
92458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    EGLContext ctxt = eglCreateContext(display, config, NULL, contextAttributes);
93875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
94875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    // if can't create a GL context, we can only abort.
95875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    LOG_ALWAYS_FATAL_IF(ctxt==EGL_NO_CONTEXT, "EGLContext creation failed");
96875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
97875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
98875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    // now figure out what version of GL did we actually get
99875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    // NOTE: a dummy surface is not needed if KHR_create_context is supported
100875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
10119e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    EGLConfig dummyConfig = config;
10219e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    if (dummyConfig == EGL_NO_CONFIG) {
10319e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        dummyConfig = chooseEglConfig(display, hwcFormat);
10419e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    }
105875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    EGLint attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE, EGL_NONE };
10619e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    EGLSurface dummy = eglCreatePbufferSurface(display, dummyConfig, attribs);
107875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    LOG_ALWAYS_FATAL_IF(dummy==EGL_NO_SURFACE, "can't create dummy pbuffer");
108875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    EGLBoolean success = eglMakeCurrent(display, dummy, dummy, ctxt);
109875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    LOG_ALWAYS_FATAL_IF(!success, "can't make dummy pbuffer current");
110875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
111875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    GLExtensions& extensions(GLExtensions::getInstance());
112875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    extensions.initWithGLStrings(
113875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            glGetString(GL_VENDOR),
114875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            glGetString(GL_RENDERER),
115875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            glGetString(GL_VERSION),
116875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            glGetString(GL_EXTENSIONS));
117875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
118875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    GlesVersion version = parseGlesVersion( extensions.getVersion() );
119875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
120875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    // initialize the renderer while GL is current
121875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
122875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    RenderEngine* engine = NULL;
123875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    switch (version) {
124875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    case GLES_VERSION_1_0:
125875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        engine = new GLES10RenderEngine();
126875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        break;
127875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    case GLES_VERSION_1_1:
128875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        engine = new GLES11RenderEngine();
129875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        break;
130875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    case GLES_VERSION_2_0:
131875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    case GLES_VERSION_3_0:
1323f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        engine = new GLES20RenderEngine();
133875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        break;
134875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
13505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    engine->setEGLHandles(config, ctxt);
136875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
137875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("OpenGL ES informations:");
138875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("vendor    : %s", extensions.getVendor());
139875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("renderer  : %s", extensions.getRenderer());
140875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("version   : %s", extensions.getVersion());
141875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("extensions: %s", extensions.getExtension());
142875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("GL_MAX_TEXTURE_SIZE = %d", engine->getMaxTextureSize());
143875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("GL_MAX_VIEWPORT_DIMS = %d", engine->getMaxViewportDims());
144875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
145875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
146875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    eglDestroySurface(display, dummy);
147875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
148875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    return engine;
149875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
150875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
151875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianRenderEngine::RenderEngine() : mEGLContext(EGL_NO_CONTEXT) {
152875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
153875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
154875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianRenderEngine::~RenderEngine() {
155875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
156875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
15705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hallvoid RenderEngine::setEGLHandles(EGLConfig config, EGLContext ctxt) {
15805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    mEGLConfig = config;
159875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    mEGLContext = ctxt;
160875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
161875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
16205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse HallEGLContext RenderEngine::getEGLConfig() const {
16305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    return mEGLConfig;
16405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall}
16505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
166875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianEGLContext RenderEngine::getEGLContext() const {
167875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    return mEGLContext;
168875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
169875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
170875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid RenderEngine::checkErrors() const {
171875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    do {
172875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        // there could be more than one error flag
173875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        GLenum error = glGetError();
174875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        if (error == GL_NO_ERROR)
175875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            break;
176875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        ALOGE("GL error 0x%04x", int(error));
177875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    } while (true);
178875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
179875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
180875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianRenderEngine::GlesVersion RenderEngine::parseGlesVersion(const char* str) {
181875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    int major, minor;
182875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (sscanf(str, "OpenGL ES-CM %d.%d", &major, &minor) != 2) {
183875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        if (sscanf(str, "OpenGL ES %d.%d", &major, &minor) != 2) {
184875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            ALOGW("Unable to parse GL_VERSION string: \"%s\"", str);
185875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            return GLES_VERSION_1_0;
186875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        }
187875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
188875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
189875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (major == 1 && minor == 0) return GLES_VERSION_1_0;
190875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (major == 1 && minor >= 1) return GLES_VERSION_1_1;
191875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (major == 2 && minor >= 0) return GLES_VERSION_2_0;
192875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (major == 3 && minor >= 0) return GLES_VERSION_3_0;
193875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
194875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGW("Unrecognized OpenGL ES version: %d.%d", major, minor);
195875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    return GLES_VERSION_1_0;
196875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
197875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
1983f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::fillRegionWithColor(const Region& region, uint32_t height,
1993f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        float red, float green, float blue, float alpha) {
2003f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    size_t c;
2013f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    Rect const* r = region.getArray(&c);
2023f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    Mesh mesh(Mesh::TRIANGLES, c*6, 2);
203ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian    Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
2043f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    for (size_t i=0 ; i<c ; i++, r++) {
2055cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 0].x = r->left;
2065cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 0].y = height - r->top;
2075cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 1].x = r->left;
2085cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 1].y = height - r->bottom;
2095cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 2].x = r->right;
2105cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 2].y = height - r->bottom;
2115cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 3].x = r->left;
2125cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 3].y = height - r->top;
2135cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 4].x = r->right;
2145cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 4].y = height - r->bottom;
2155cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 5].x = r->right;
2165cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 5].y = height - r->top;
2173f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    }
21819733a32799f792125913e746e8644d16f8dc223Mathias Agopian    setupFillWithColor(red, green, blue, alpha);
21919733a32799f792125913e746e8644d16f8dc223Mathias Agopian    drawMesh(mesh);
2203f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2213f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2223f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::clearWithColor(float red, float green, float blue, float alpha) {
2233f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glClearColor(red, green, blue, alpha);
2243f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glClear(GL_COLOR_BUFFER_BIT);
2253f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2263f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2273f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::setScissor(
2283f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        uint32_t left, uint32_t bottom, uint32_t right, uint32_t top) {
2293f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glScissor(left, bottom, right, top);
2303f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glEnable(GL_SCISSOR_TEST);
2313f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2323f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2333f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::disableScissor() {
2343f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glDisable(GL_SCISSOR_TEST);
2353f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2363f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2373f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::genTextures(size_t count, uint32_t* names) {
2383f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glGenTextures(count, names);
2393f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2403f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2413f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::deleteTextures(size_t count, uint32_t const* names) {
2423f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glDeleteTextures(count, names);
2433f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2443f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
245d555684cb36dfb959694db76962e570184f98838Mathias Agopianvoid RenderEngine::readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels) {
246d555684cb36dfb959694db76962e570184f98838Mathias Agopian    glReadPixels(l, b, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
247d555684cb36dfb959694db76962e570184f98838Mathias Agopian}
248d555684cb36dfb959694db76962e570184f98838Mathias Agopian
249458197de008be8fe561286b09f4edddb2f5c540aMathias Agopianvoid RenderEngine::dump(String8& result) {
250458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    const GLExtensions& extensions(GLExtensions::getInstance());
251458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    result.appendFormat("GLES: %s, %s, %s\n",
252458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian            extensions.getVendor(),
253458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian            extensions.getRenderer(),
254458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian            extensions.getVersion());
255458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    result.appendFormat("%s\n", extensions.getExtension());
256458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian}
257458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian
2583f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian// ---------------------------------------------------------------------------
2593f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2603f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias AgopianRenderEngine::BindImageAsFramebuffer::BindImageAsFramebuffer(
2613f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        RenderEngine& engine, EGLImageKHR image) : mEngine(engine)
2623f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian{
263458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    mEngine.bindImageAsFramebuffer(image, &mTexName, &mFbName, &mStatus);
264458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian
2653f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    ALOGE_IF(mStatus != GL_FRAMEBUFFER_COMPLETE_OES,
2663f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian            "glCheckFramebufferStatusOES error %d", mStatus);
2673f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2683f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2693f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias AgopianRenderEngine::BindImageAsFramebuffer::~BindImageAsFramebuffer() {
2703f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // back to main framebuffer
271458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    mEngine.unbindFramebuffer(mTexName, mFbName);
2723f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2733f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2743f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianstatus_t RenderEngine::BindImageAsFramebuffer::getStatus() const {
2753f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    return mStatus == GL_FRAMEBUFFER_COMPLETE_OES ? NO_ERROR : BAD_VALUE;
2763f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2773f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
278875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
27905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
28005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hallstatic status_t selectConfigForAttribute(EGLDisplay dpy, EGLint const* attrs,
28105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        EGLint attribute, EGLint wanted, EGLConfig* outConfig) {
28205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLConfig config = NULL;
28305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint numConfigs = -1, n = 0;
28405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglGetConfigs(dpy, NULL, 0, &numConfigs);
28505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLConfig* const configs = new EGLConfig[numConfigs];
28605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglChooseConfig(dpy, attrs, configs, numConfigs, &n);
28705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
28805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    if (n) {
28905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        if (attribute != EGL_NONE) {
29005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            for (int i=0 ; i<n ; i++) {
29105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                EGLint value = 0;
29205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                eglGetConfigAttrib(dpy, configs[i], attribute, &value);
29305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                if (wanted == value) {
29405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                    *outConfig = configs[i];
29505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                    delete [] configs;
29605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                    return NO_ERROR;
29705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                }
29805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            }
29905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        } else {
30005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            // just pick the first one
30105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            *outConfig = configs[0];
30205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            delete [] configs;
30305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            return NO_ERROR;
30405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
30505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
30605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    delete [] configs;
30705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    return NAME_NOT_FOUND;
30805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall}
30905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
31005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hallclass EGLAttributeVector {
31105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    struct Attribute;
31205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    class Adder;
31305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    friend class Adder;
31405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    KeyedVector<Attribute, EGLint> mList;
31505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    struct Attribute {
31605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        Attribute() {};
31705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        Attribute(EGLint v) : v(v) { }
31805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        EGLint v;
31905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        bool operator < (const Attribute& other) const {
32005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            // this places EGL_NONE at the end
32105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            EGLint lhs(v);
32205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            EGLint rhs(other.v);
32305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            if (lhs == EGL_NONE) lhs = 0x7FFFFFFF;
32405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            if (rhs == EGL_NONE) rhs = 0x7FFFFFFF;
32505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            return lhs < rhs;
32605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
32705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    };
32805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    class Adder {
32905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        friend class EGLAttributeVector;
33005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        EGLAttributeVector& v;
33105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        EGLint attribute;
33205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        Adder(EGLAttributeVector& v, EGLint attribute)
33305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            : v(v), attribute(attribute) {
33405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
33505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    public:
33605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        void operator = (EGLint value) {
33705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            if (attribute != EGL_NONE) {
33805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                v.mList.add(attribute, value);
33905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            }
34005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
34105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        operator EGLint () const { return v.mList[attribute]; }
34205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    };
34305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hallpublic:
34405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLAttributeVector() {
34505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        mList.add(EGL_NONE, EGL_NONE);
34605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
34705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    void remove(EGLint attribute) {
34805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        if (attribute != EGL_NONE) {
34905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            mList.removeItem(attribute);
35005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
35105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
35205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    Adder operator [] (EGLint attribute) {
35305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        return Adder(*this, attribute);
35405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
35505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint operator [] (EGLint attribute) const {
35605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall       return mList[attribute];
35705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
35805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    // cast-operator to (EGLint const*)
35905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    operator EGLint const* () const { return &mList.keyAt(0).v; }
36005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall};
36105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
36205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
36305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hallstatic status_t selectEGLConfig(EGLDisplay display, EGLint format,
36405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint renderableType, EGLConfig* config) {
36505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    // select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
36605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    // it is to be used with WIFI displays
36705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    status_t err;
36805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint wantedAttribute;
36905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint wantedAttributeValue;
37005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
37105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLAttributeVector attribs;
37205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    if (renderableType) {
37305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_RENDERABLE_TYPE]            = renderableType;
37405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_RECORDABLE_ANDROID]         = EGL_TRUE;
37505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_SURFACE_TYPE]               = EGL_WINDOW_BIT|EGL_PBUFFER_BIT;
37605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_FRAMEBUFFER_TARGET_ANDROID] = EGL_TRUE;
37705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_RED_SIZE]                   = 8;
37805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_GREEN_SIZE]                 = 8;
37905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_BLUE_SIZE]                  = 8;
38005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        wantedAttribute                         = EGL_NONE;
38105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        wantedAttributeValue                    = EGL_NONE;
38205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    } else {
38305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        // if no renderable type specified, fallback to a simplified query
38405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        wantedAttribute                         = EGL_NATIVE_VISUAL_ID;
38505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        wantedAttributeValue                    = format;
38605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
38705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
38805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    err = selectConfigForAttribute(display, attribs,
38905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            wantedAttribute, wantedAttributeValue, config);
39005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    if (err == NO_ERROR) {
39105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        EGLint caveat;
39205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        if (eglGetConfigAttrib(display, *config, EGL_CONFIG_CAVEAT, &caveat))
39305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            ALOGW_IF(caveat == EGL_SLOW_CONFIG, "EGL_SLOW_CONFIG selected!");
39405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
39505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
39605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    return err;
39705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall}
39805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
39905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse HallEGLConfig RenderEngine::chooseEglConfig(EGLDisplay display, int format) {
40005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    status_t err;
40105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLConfig config;
40205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
40305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    // First try to get an ES2 config
40405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    err = selectEGLConfig(display, format, EGL_OPENGL_ES2_BIT, &config);
40505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    if (err != NO_ERROR) {
40605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        // If ES2 fails, try ES1
40705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        err = selectEGLConfig(display, format, EGL_OPENGL_ES_BIT, &config);
40805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        if (err != NO_ERROR) {
40905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            // still didn't work, probably because we're on the emulator...
41005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            // try a simplified query
41105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            ALOGW("no suitable EGLConfig found, trying a simpler query");
41205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            err = selectEGLConfig(display, format, 0, &config);
41305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            if (err != NO_ERROR) {
41405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                // this EGL is too lame for android
41505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                LOG_ALWAYS_FATAL("no suitable EGLConfig found, giving up");
41605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            }
41705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
41805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
41905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
42005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    // print some debugging info
42105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint r,g,b,a;
42205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglGetConfigAttrib(display, config, EGL_RED_SIZE,   &r);
42305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &g);
42405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglGetConfigAttrib(display, config, EGL_BLUE_SIZE,  &b);
42505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &a);
42605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("EGL information:");
42705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("vendor    : %s", eglQueryString(display, EGL_VENDOR));
42805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("version   : %s", eglQueryString(display, EGL_VERSION));
42905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("extensions: %s", eglQueryString(display, EGL_EXTENSIONS));
43005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS)?:"Not Supported");
43105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, config);
43205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
43305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    return config;
43405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall}
43505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
43605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall// ---------------------------------------------------------------------------
437875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android
438875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
439