RenderEngine.cpp revision c93afd54a05497c4ae42db99ea0310ee69cca492
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
177823e124e00576e20e47ec717cbe8bc89f0f2bf2Mark Salyzyn#include <log/log.h>
183f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include <ui/Rect.h>
193f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include <ui/Region.h>
20875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
21875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "RenderEngine.h"
223f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include "GLES20RenderEngine.h"
23875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include "GLExtensions.h"
243f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include "Mesh.h"
25875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
26c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard#include <vector>
27c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard#include <SurfaceFlinger.h>
28c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard
2919e872912af66c53a4350afcc333bbafaf6a2294Jesse HallEGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name);
3019e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall
31875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
32875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiannamespace android {
33875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
34875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
3519e872912af66c53a4350afcc333bbafaf6a2294Jesse Hallstatic bool findExtension(const char* exts, const char* name) {
3619e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    if (!exts)
3719e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        return false;
3819e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    size_t len = strlen(name);
3919e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall
4019e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    const char* pos = exts;
4119e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    while ((pos = strstr(pos, name)) != NULL) {
4219e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        if (pos[len] == '\0' || pos[len] == ' ')
4319e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall            return true;
4419e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        pos += len;
4519e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    }
4619e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall
4719e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    return false;
4819e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall}
4919e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall
5005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse HallRenderEngine* RenderEngine::create(EGLDisplay display, int hwcFormat) {
5119e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // EGL_ANDROIDX_no_config_context is an experimental extension with no
5219e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // written specification. It will be replaced by something more formal.
5319e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // SurfaceFlinger is using it to allow a single EGLContext to render to
5419e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // both a 16-bit primary display framebuffer and a 32-bit virtual display
5519e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // framebuffer.
5619e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    //
5719e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // The code assumes that ES2 or later is available if this extension is
5819e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    // supported.
5919e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    EGLConfig config = EGL_NO_CONFIG;
6019e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    if (!findExtension(
6119e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall            eglQueryStringImplementationANDROID(display, EGL_EXTENSIONS),
6219e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall            "EGL_ANDROIDX_no_config_context")) {
6319e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        config = chooseEglConfig(display, hwcFormat);
6419e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    }
6505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
662185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    EGLint renderableType = 0;
6719e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    if (config == EGL_NO_CONFIG) {
6819e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        renderableType = EGL_OPENGL_ES2_BIT;
6919e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    } else if (!eglGetConfigAttrib(display, config,
7019e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall            EGL_RENDERABLE_TYPE, &renderableType)) {
712185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian        LOG_ALWAYS_FATAL("can't query EGLConfig RENDERABLE_TYPE");
722185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    }
7319e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    EGLint contextClientVersion = 0;
742185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    if (renderableType & EGL_OPENGL_ES2_BIT) {
752185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian        contextClientVersion = 2;
762185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    } else if (renderableType & EGL_OPENGL_ES_BIT) {
772185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian        contextClientVersion = 1;
782185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    } else {
792185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian        LOG_ALWAYS_FATAL("no supported EGL_RENDERABLE_TYPEs");
802185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian    }
812185f8b420ee1b150f761893a9c47cffff645cdeMathias Agopian
82c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard    std::vector<EGLint> contextAttributes;
83c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard    contextAttributes.reserve(6);
84c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard    contextAttributes.push_back(EGL_CONTEXT_CLIENT_VERSION);
85c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard    contextAttributes.push_back(contextClientVersion);
86875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#ifdef EGL_IMG_context_priority
87c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard    if (SurfaceFlinger::useContextPriority) {
88c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard        contextAttributes.push_back(EGL_CONTEXT_PRIORITY_LEVEL_IMG);
89c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard        contextAttributes.push_back(EGL_CONTEXT_PRIORITY_HIGH_IMG);
90c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard    }
91875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif
92c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard    contextAttributes.push_back(EGL_NONE);
93c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard    contextAttributes.push_back(EGL_NONE);
94c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard
95c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard    EGLContext ctxt = eglCreateContext(display, config, NULL,
96c93afd54a05497c4ae42db99ea0310ee69cca492Fabien Sanglard                                       contextAttributes.data());
97875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
98875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    // if can't create a GL context, we can only abort.
99875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    LOG_ALWAYS_FATAL_IF(ctxt==EGL_NO_CONTEXT, "EGLContext creation failed");
100875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
101875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
102875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    // now figure out what version of GL did we actually get
103875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    // NOTE: a dummy surface is not needed if KHR_create_context is supported
104875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
10519e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    EGLConfig dummyConfig = config;
10619e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    if (dummyConfig == EGL_NO_CONFIG) {
10719e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall        dummyConfig = chooseEglConfig(display, hwcFormat);
10819e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    }
109875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    EGLint attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE, EGL_NONE };
11019e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall    EGLSurface dummy = eglCreatePbufferSurface(display, dummyConfig, attribs);
111875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    LOG_ALWAYS_FATAL_IF(dummy==EGL_NO_SURFACE, "can't create dummy pbuffer");
112875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    EGLBoolean success = eglMakeCurrent(display, dummy, dummy, ctxt);
113875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    LOG_ALWAYS_FATAL_IF(!success, "can't make dummy pbuffer current");
114875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
115875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    GLExtensions& extensions(GLExtensions::getInstance());
116875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    extensions.initWithGLStrings(
117875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            glGetString(GL_VENDOR),
118875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            glGetString(GL_RENDERER),
119875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            glGetString(GL_VERSION),
120875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            glGetString(GL_EXTENSIONS));
121875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
122875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    GlesVersion version = parseGlesVersion( extensions.getVersion() );
123875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
124875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    // initialize the renderer while GL is current
125875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
126875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    RenderEngine* engine = NULL;
127875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    switch (version) {
128875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    case GLES_VERSION_1_0:
129875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    case GLES_VERSION_1_1:
130efb93455b3a95458d68897c3b38f7f98046c697eFabien Sanglard        LOG_ALWAYS_FATAL("SurfaceFlinger requires OpenGL ES 2.0 minimum to run.");
131875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        break;
132875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    case GLES_VERSION_2_0:
133875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    case GLES_VERSION_3_0:
1343f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        engine = new GLES20RenderEngine();
135875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        break;
136875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
13705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    engine->setEGLHandles(config, ctxt);
138875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
139875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("OpenGL ES informations:");
140875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("vendor    : %s", extensions.getVendor());
141875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("renderer  : %s", extensions.getRenderer());
142875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("version   : %s", extensions.getVersion());
143875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGI("extensions: %s", extensions.getExtension());
1449ae79d869a37633fa956a4f16f3fa45b23c189f1Michael Lentine    ALOGI("GL_MAX_TEXTURE_SIZE = %zu", engine->getMaxTextureSize());
1459ae79d869a37633fa956a4f16f3fa45b23c189f1Michael Lentine    ALOGI("GL_MAX_VIEWPORT_DIMS = %zu", engine->getMaxViewportDims());
146875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
147875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
148875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    eglDestroySurface(display, dummy);
149875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
150875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    return engine;
151875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
152875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
15353390e1e8c33ebee5bb8100e846f5263ba05ff73Pablo CeballosRenderEngine::RenderEngine() : mEGLConfig(NULL), mEGLContext(EGL_NO_CONTEXT) {
154875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
155875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
156875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianRenderEngine::~RenderEngine() {
157875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
158875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
15905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hallvoid RenderEngine::setEGLHandles(EGLConfig config, EGLContext ctxt) {
16005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    mEGLConfig = config;
161875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    mEGLContext = ctxt;
162875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
163875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
16405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse HallEGLContext RenderEngine::getEGLConfig() const {
16505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    return mEGLConfig;
16605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall}
16705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
168875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianEGLContext RenderEngine::getEGLContext() const {
169875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    return mEGLContext;
170875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
171875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
172875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianvoid RenderEngine::checkErrors() const {
173875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    do {
174875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        // there could be more than one error flag
175875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        GLenum error = glGetError();
176875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        if (error == GL_NO_ERROR)
177875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            break;
178875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        ALOGE("GL error 0x%04x", int(error));
179875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    } while (true);
180875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
181875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
182875d8e1323536e16dcfc90c9674d7ad32116a69aMathias AgopianRenderEngine::GlesVersion RenderEngine::parseGlesVersion(const char* str) {
183875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    int major, minor;
184875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (sscanf(str, "OpenGL ES-CM %d.%d", &major, &minor) != 2) {
185875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        if (sscanf(str, "OpenGL ES %d.%d", &major, &minor) != 2) {
186875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            ALOGW("Unable to parse GL_VERSION string: \"%s\"", str);
187875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian            return GLES_VERSION_1_0;
188875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        }
189875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    }
190875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
191875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (major == 1 && minor == 0) return GLES_VERSION_1_0;
192875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (major == 1 && minor >= 1) return GLES_VERSION_1_1;
193875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (major == 2 && minor >= 0) return GLES_VERSION_2_0;
194875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    if (major == 3 && minor >= 0) return GLES_VERSION_3_0;
195875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
196875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    ALOGW("Unrecognized OpenGL ES version: %d.%d", major, minor);
197875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    return GLES_VERSION_1_0;
198875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}
199875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
2003f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::fillRegionWithColor(const Region& region, uint32_t height,
2013f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        float red, float green, float blue, float alpha) {
2023f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    size_t c;
2033f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    Rect const* r = region.getArray(&c);
2043f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    Mesh mesh(Mesh::TRIANGLES, c*6, 2);
205ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian    Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
2063f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    for (size_t i=0 ; i<c ; i++, r++) {
2075cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 0].x = r->left;
2085cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 0].y = height - r->top;
2095cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 1].x = r->left;
2105cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 1].y = height - r->bottom;
2115cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 2].x = r->right;
2125cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 2].y = height - r->bottom;
2135cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 3].x = r->left;
2145cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 3].y = height - r->top;
2155cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 4].x = r->right;
2165cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 4].y = height - r->bottom;
2175cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 5].x = r->right;
2185cdc8994a0ecd751a6350b16a1bef8b6b0d09b11Mathias Agopian        position[i*6 + 5].y = height - r->top;
2193f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    }
22019733a32799f792125913e746e8644d16f8dc223Mathias Agopian    setupFillWithColor(red, green, blue, alpha);
22119733a32799f792125913e746e8644d16f8dc223Mathias Agopian    drawMesh(mesh);
2223f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2233f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2249707f4df640c3369f873a934bb05ffa5a68a5640Riley Andrewsvoid RenderEngine::flush() {
2259707f4df640c3369f873a934bb05ffa5a68a5640Riley Andrews    glFlush();
2269707f4df640c3369f873a934bb05ffa5a68a5640Riley Andrews}
2279707f4df640c3369f873a934bb05ffa5a68a5640Riley Andrews
2283f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::clearWithColor(float red, float green, float blue, float alpha) {
2293f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glClearColor(red, green, blue, alpha);
2303f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glClear(GL_COLOR_BUFFER_BIT);
2313f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2323f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2333f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::setScissor(
2343f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        uint32_t left, uint32_t bottom, uint32_t right, uint32_t top) {
2353f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glScissor(left, bottom, right, top);
2363f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glEnable(GL_SCISSOR_TEST);
2373f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2383f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2393f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::disableScissor() {
2403f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glDisable(GL_SCISSOR_TEST);
2413f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2423f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2433f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::genTextures(size_t count, uint32_t* names) {
2443f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glGenTextures(count, names);
2453f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2463f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2473f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianvoid RenderEngine::deleteTextures(size_t count, uint32_t const* names) {
2483f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    glDeleteTextures(count, names);
2493f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2503f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
251d555684cb36dfb959694db76962e570184f98838Mathias Agopianvoid RenderEngine::readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels) {
252d555684cb36dfb959694db76962e570184f98838Mathias Agopian    glReadPixels(l, b, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
253d555684cb36dfb959694db76962e570184f98838Mathias Agopian}
254d555684cb36dfb959694db76962e570184f98838Mathias Agopian
255458197de008be8fe561286b09f4edddb2f5c540aMathias Agopianvoid RenderEngine::dump(String8& result) {
256458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    const GLExtensions& extensions(GLExtensions::getInstance());
257458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    result.appendFormat("GLES: %s, %s, %s\n",
258458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian            extensions.getVendor(),
259458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian            extensions.getRenderer(),
260458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian            extensions.getVersion());
261458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    result.appendFormat("%s\n", extensions.getExtension());
262458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian}
263458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian
2643f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian// ---------------------------------------------------------------------------
2653f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2663f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias AgopianRenderEngine::BindImageAsFramebuffer::BindImageAsFramebuffer(
2673f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        RenderEngine& engine, EGLImageKHR image) : mEngine(engine)
2683f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian{
269458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    mEngine.bindImageAsFramebuffer(image, &mTexName, &mFbName, &mStatus);
270458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian
2713f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    ALOGE_IF(mStatus != GL_FRAMEBUFFER_COMPLETE_OES,
2723f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian            "glCheckFramebufferStatusOES error %d", mStatus);
2733f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2743f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2753f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias AgopianRenderEngine::BindImageAsFramebuffer::~BindImageAsFramebuffer() {
2763f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // back to main framebuffer
277458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    mEngine.unbindFramebuffer(mTexName, mFbName);
2783f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
2803f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianstatus_t RenderEngine::BindImageAsFramebuffer::getStatus() const {
2813f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    return mStatus == GL_FRAMEBUFFER_COMPLETE_OES ? NO_ERROR : BAD_VALUE;
2823f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}
2833f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
284875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
28505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
28605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hallstatic status_t selectConfigForAttribute(EGLDisplay dpy, EGLint const* attrs,
28705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        EGLint attribute, EGLint wanted, EGLConfig* outConfig) {
28805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint numConfigs = -1, n = 0;
28905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglGetConfigs(dpy, NULL, 0, &numConfigs);
29005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLConfig* const configs = new EGLConfig[numConfigs];
29105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglChooseConfig(dpy, attrs, configs, numConfigs, &n);
29205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
29305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    if (n) {
29405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        if (attribute != EGL_NONE) {
29505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            for (int i=0 ; i<n ; i++) {
29605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                EGLint value = 0;
29705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                eglGetConfigAttrib(dpy, configs[i], attribute, &value);
29805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                if (wanted == value) {
29905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                    *outConfig = configs[i];
30005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                    delete [] configs;
30105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                    return NO_ERROR;
30205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                }
30305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            }
30405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        } else {
30505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            // just pick the first one
30605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            *outConfig = configs[0];
30705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            delete [] configs;
30805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            return NO_ERROR;
30905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
31005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
31105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    delete [] configs;
31205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    return NAME_NOT_FOUND;
31305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall}
31405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
31505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hallclass EGLAttributeVector {
31605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    struct Attribute;
31705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    class Adder;
31805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    friend class Adder;
31905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    KeyedVector<Attribute, EGLint> mList;
32005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    struct Attribute {
32153390e1e8c33ebee5bb8100e846f5263ba05ff73Pablo Ceballos        Attribute() : v(0) {};
322c406791ead6d864ec693ad01a80c5f471bdc2a7aChih-Hung Hsieh        explicit Attribute(EGLint v) : v(v) { }
32305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        EGLint v;
32405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        bool operator < (const Attribute& other) const {
32505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            // this places EGL_NONE at the end
32605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            EGLint lhs(v);
32705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            EGLint rhs(other.v);
32805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            if (lhs == EGL_NONE) lhs = 0x7FFFFFFF;
32905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            if (rhs == EGL_NONE) rhs = 0x7FFFFFFF;
33005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            return lhs < rhs;
33105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
33205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    };
33305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    class Adder {
33405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        friend class EGLAttributeVector;
33505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        EGLAttributeVector& v;
33605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        EGLint attribute;
33705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        Adder(EGLAttributeVector& v, EGLint attribute)
33805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            : v(v), attribute(attribute) {
33905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
34005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    public:
34105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        void operator = (EGLint value) {
34205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            if (attribute != EGL_NONE) {
343c406791ead6d864ec693ad01a80c5f471bdc2a7aChih-Hung Hsieh                v.mList.add(Attribute(attribute), value);
34405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            }
34505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
34605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        operator EGLint () const { return v.mList[attribute]; }
34705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    };
34805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hallpublic:
34905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLAttributeVector() {
350c406791ead6d864ec693ad01a80c5f471bdc2a7aChih-Hung Hsieh        mList.add(Attribute(EGL_NONE), EGL_NONE);
35105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
35205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    void remove(EGLint attribute) {
35305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        if (attribute != EGL_NONE) {
354c406791ead6d864ec693ad01a80c5f471bdc2a7aChih-Hung Hsieh            mList.removeItem(Attribute(attribute));
35505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
35605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
35705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    Adder operator [] (EGLint attribute) {
35805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        return Adder(*this, attribute);
35905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
36005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint operator [] (EGLint attribute) const {
36105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall       return mList[attribute];
36205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
36305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    // cast-operator to (EGLint const*)
36405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    operator EGLint const* () const { return &mList.keyAt(0).v; }
36505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall};
36605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
36705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
36805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hallstatic status_t selectEGLConfig(EGLDisplay display, EGLint format,
36905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint renderableType, EGLConfig* config) {
37005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    // select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
37105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    // it is to be used with WIFI displays
37205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    status_t err;
37305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint wantedAttribute;
37405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint wantedAttributeValue;
37505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
37605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLAttributeVector attribs;
37705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    if (renderableType) {
37805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_RENDERABLE_TYPE]            = renderableType;
37905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_RECORDABLE_ANDROID]         = EGL_TRUE;
38005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_SURFACE_TYPE]               = EGL_WINDOW_BIT|EGL_PBUFFER_BIT;
38105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_FRAMEBUFFER_TARGET_ANDROID] = EGL_TRUE;
38205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_RED_SIZE]                   = 8;
38305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_GREEN_SIZE]                 = 8;
38405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        attribs[EGL_BLUE_SIZE]                  = 8;
38505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        wantedAttribute                         = EGL_NONE;
38605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        wantedAttributeValue                    = EGL_NONE;
38705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    } else {
38805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        // if no renderable type specified, fallback to a simplified query
38905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        wantedAttribute                         = EGL_NATIVE_VISUAL_ID;
39005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        wantedAttributeValue                    = format;
39105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
39205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
39305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    err = selectConfigForAttribute(display, attribs,
39405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            wantedAttribute, wantedAttributeValue, config);
39505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    if (err == NO_ERROR) {
39605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        EGLint caveat;
39705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        if (eglGetConfigAttrib(display, *config, EGL_CONFIG_CAVEAT, &caveat))
39805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            ALOGW_IF(caveat == EGL_SLOW_CONFIG, "EGL_SLOW_CONFIG selected!");
39905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
40005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
40105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    return err;
40205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall}
40305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
40405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse HallEGLConfig RenderEngine::chooseEglConfig(EGLDisplay display, int format) {
40505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    status_t err;
40605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLConfig config;
40705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
40805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    // First try to get an ES2 config
40905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    err = selectEGLConfig(display, format, EGL_OPENGL_ES2_BIT, &config);
41005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    if (err != NO_ERROR) {
41105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        // If ES2 fails, try ES1
41205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        err = selectEGLConfig(display, format, EGL_OPENGL_ES_BIT, &config);
41305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        if (err != NO_ERROR) {
41405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            // still didn't work, probably because we're on the emulator...
41505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            // try a simplified query
41605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            ALOGW("no suitable EGLConfig found, trying a simpler query");
41705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            err = selectEGLConfig(display, format, 0, &config);
41805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            if (err != NO_ERROR) {
41905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                // this EGL is too lame for android
42005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall                LOG_ALWAYS_FATAL("no suitable EGLConfig found, giving up");
42105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall            }
42205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall        }
42305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    }
42405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
42505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    // print some debugging info
42605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLint r,g,b,a;
42705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglGetConfigAttrib(display, config, EGL_RED_SIZE,   &r);
42805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &g);
42905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglGetConfigAttrib(display, config, EGL_BLUE_SIZE,  &b);
43005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &a);
43105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("EGL information:");
43205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("vendor    : %s", eglQueryString(display, EGL_VENDOR));
43305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("version   : %s", eglQueryString(display, EGL_VERSION));
43405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("extensions: %s", eglQueryString(display, EGL_EXTENSIONS));
43505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS)?:"Not Supported");
43605f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, config);
43705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
43805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    return config;
43905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall}
44005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
4414e63777f75e9756c74352e62e79dfa8a994de2b3Dan Stoza
4424e63777f75e9756c74352e62e79dfa8a994de2b3Dan Stozavoid RenderEngine::primeCache() const {
4434e63777f75e9756c74352e62e79dfa8a994de2b3Dan Stoza    // Getting the ProgramCache instance causes it to prime its shader cache,
4444e63777f75e9756c74352e62e79dfa8a994de2b3Dan Stoza    // which is performed in its constructor
4454e63777f75e9756c74352e62e79dfa8a994de2b3Dan Stoza    ProgramCache::getInstance();
4464e63777f75e9756c74352e62e79dfa8a994de2b3Dan Stoza}
4474e63777f75e9756c74352e62e79dfa8a994de2b3Dan Stoza
44805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall// ---------------------------------------------------------------------------
449875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android
450875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
451