194cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall/*
2de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian ** Copyright 2007, The Android Open Source Project
3de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian **
494cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall ** Licensed under the Apache License, Version 2.0 (the "License");
594cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall ** you may not use this file except in compliance with the License.
694cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall ** You may obtain a copy of the License at
7de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian **
894cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall **     http://www.apache.org/licenses/LICENSE-2.0
9de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian **
1094cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall ** Unless required by applicable law or agreed to in writing, software
1194cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall ** distributed under the License is distributed on an "AS IS" BASIS,
1294cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1394cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall ** See the License for the specific language governing permissions and
14de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian ** limitations under the License.
15de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian */
16de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
17de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian#include <ctype.h>
18de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian#include <stdlib.h>
19de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian#include <stdio.h>
20de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian#include <string.h>
21de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian#include <errno.h>
22de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian#include <dlfcn.h>
23de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian#include <limits.h>
24993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian#include <dirent.h>
25de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
26de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian#include <cutils/log.h>
2780b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner#include <cutils/properties.h>
28de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
29de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian#include <EGL/egl.h>
30de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
311cadb25da1ed875bdd078270e642966724a0c39aMathias Agopian#include "egldefs.h"
32de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian#include "Loader.h"
33de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
34de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian// ----------------------------------------------------------------------------
35de58697644a52a614ad9498aa087e95d4a223673Mathias Agopiannamespace android {
36de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian// ----------------------------------------------------------------------------
37de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
38de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
39de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian/*
40993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian * EGL userspace drivers must be provided either:
41993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian * - as a single library:
42993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *      /vendor/lib/egl/libGLES.so
43993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *
44993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian * - as separate libraries:
45993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *      /vendor/lib/egl/libEGL.so
46993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *      /vendor/lib/egl/libGLESv1_CM.so
47993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *      /vendor/lib/egl/libGLESv2.so
48993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *
49993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian * The software renderer for the emulator must be provided as a single
50993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian * library at:
51993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *
52993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *      /system/lib/egl/libGLES_android.so
53993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *
54993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *
55993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian * For backward compatibility and to facilitate the transition to
56993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian * this new naming scheme, the loader will additionally look for:
5794cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall *
58993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian *      /{vendor|system}/lib/egl/lib{GLES | [EGL|GLESv1_CM|GLESv2]}_*.so
5994cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall *
60de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian */
61de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
62de58697644a52a614ad9498aa087e95d4a223673Mathias AgopianANDROID_SINGLETON_STATIC_INSTANCE( Loader )
63de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
6480b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner/* This function is called to check whether we run inside the emulator,
6580b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner * and if this is the case whether GLES GPU emulation is supported.
6680b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner *
6780b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner * Returned values are:
6880b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner *  -1   -> not running inside the emulator
6980b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner *   0   -> running inside the emulator, but GPU emulation not supported
7080b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner *   1   -> running inside the emulator, GPU emulation is supported
71776951f9db5744c94167d463584e9ee42c849712Nicolas Capens *          through the "emulation" host-side OpenGL ES implementation.
72776951f9db5744c94167d463584e9ee42c849712Nicolas Capens *   2   -> running inside the emulator, GPU emulation is supported
73776951f9db5744c94167d463584e9ee42c849712Nicolas Capens *          through a guest-side vendor driver's OpenGL ES implementation.
7480b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner */
7580b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turnerstatic int
7680b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' TurnercheckGlesEmulationStatus(void)
7780b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner{
7880b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner    /* We're going to check for the following kernel parameters:
7980b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner     *
8080b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner     *    qemu=1                      -> tells us that we run inside the emulator
8180b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner     *    android.qemu.gles=<number>  -> tells us the GLES GPU emulation status
8280b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner     *
8380b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner     * Note that we will return <number> if we find it. This let us support
8480b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner     * more additionnal emulation modes in the future.
8580b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner     */
8680b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner    char  prop[PROPERTY_VALUE_MAX];
8780b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner    int   result = -1;
8880b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner
8980b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner    /* First, check for qemu=1 */
9080b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner    property_get("ro.kernel.qemu",prop,"0");
9180b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner    if (atoi(prop) != 1)
9280b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner        return -1;
9380b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner
9480b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner    /* We are in the emulator, get GPU status value */
9569e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    property_get("qemu.gles",prop,"0");
9680b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner    return atoi(prop);
9780b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner}
9880b30c24ffc0f67b87d7a6b29f616d1c521d40aeDavid 'Digit' Turner
99de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian// ----------------------------------------------------------------------------
100de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
101d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopianstatic char const * getProcessCmdline() {
102d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian    long pid = getpid();
103d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian    char procPath[128];
104d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian    snprintf(procPath, 128, "/proc/%ld/cmdline", pid);
105d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian    FILE * file = fopen(procPath, "r");
106d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian    if (file) {
107d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian        static char cmdline[256];
108d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian        char *str = fgets(cmdline, sizeof(cmdline) - 1, file);
109d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian        fclose(file);
110d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian        if (str) {
111d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian            return cmdline;
112d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian        }
113d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian    }
114d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian    return NULL;
115d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian}
116d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian
117d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian// ----------------------------------------------------------------------------
118d75f84d6410da934d1b1760fdc0d05d4ba1e8f35Mathias Agopian
11994cdba97ce1de140623d84c14fb15f12f7da89ddJesse HallLoader::driver_t::driver_t(void* gles)
120de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian{
121de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    dso[0] = gles;
122de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    for (size_t i=1 ; i<NELEM(dso) ; i++)
123de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        dso[i] = 0;
124de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian}
125de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
12694cdba97ce1de140623d84c14fb15f12f7da89ddJesse HallLoader::driver_t::~driver_t()
127de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian{
128de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    for (size_t i=0 ; i<NELEM(dso) ; i++) {
129de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        if (dso[i]) {
130de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            dlclose(dso[i]);
131de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            dso[i] = 0;
132de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        }
133de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    }
134de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian}
135de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
136de58697644a52a614ad9498aa087e95d4a223673Mathias Agopianstatus_t Loader::driver_t::set(void* hnd, int32_t api)
137de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian{
138de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    switch (api) {
139de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        case EGL:
140de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            dso[0] = hnd;
141de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            break;
142de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        case GLESv1_CM:
143de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            dso[1] = hnd;
144de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            break;
145de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        case GLESv2:
146de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            dso[2] = hnd;
147de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            break;
148de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        default:
149de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            return BAD_INDEX;
150de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    }
151de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    return NO_ERROR;
152de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian}
153de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
154de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian// ----------------------------------------------------------------------------
155de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
156de58697644a52a614ad9498aa087e95d4a223673Mathias AgopianLoader::Loader()
157993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    : getProcAddress(NULL) {
158de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian}
159de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
160993814255fc248454368ed9fe34b4703a05eaf99Mathias AgopianLoader::~Loader() {
161de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian}
162de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
163c07b52060acd627c8510c1a9151e0753fce76330Jesse Hallstatic void* load_wrapper(const char* path) {
164c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    void* so = dlopen(path, RTLD_NOW | RTLD_LOCAL);
165c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    ALOGE_IF(!so, "dlopen(\"%s\") failed: %s", path, dlerror());
166c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    return so;
167c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall}
168c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall
169c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov#ifndef EGL_WRAPPER_DIR
170c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov#if defined(__LP64__)
171c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov#define EGL_WRAPPER_DIR "/system/lib64"
172c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov#else
173c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov#define EGL_WRAPPER_DIR "/system/lib"
174c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov#endif
175c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov#endif
176c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov
17769e5b1ab80018817b1d4ffbbdb5695ff70168c95bohustatic void setEmulatorGlesValue(void) {
17869e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    char prop[PROPERTY_VALUE_MAX];
17969e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    property_get("ro.kernel.qemu", prop, "0");
18069e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    if (atoi(prop) != 1) return;
18169e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu
18269e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    property_get("ro.kernel.qemu.gles",prop,"0");
18369e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    if (atoi(prop) == 1) {
18469e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu        ALOGD("Emulator has host GPU support, qemu.gles is set to 1.");
18569e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu        property_set("qemu.gles", "1");
18669e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu        return;
18769e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    }
18869e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu
18969e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    // for now, checking the following
19069e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    // directory is good enough for emulator system images
19169e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    const char* vendor_lib_path =
19269e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu#if defined(__LP64__)
19369e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu        "/vendor/lib64/egl";
19469e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu#else
19569e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu        "/vendor/lib/egl";
19669e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu#endif
19769e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu
19869e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    const bool has_vendor_lib = (access(vendor_lib_path, R_OK) == 0);
19969e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    if (has_vendor_lib) {
20069e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu        ALOGD("Emulator has vendor provided software renderer, qemu.gles is set to 2.");
20169e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu        property_set("qemu.gles", "2");
20269e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    } else {
20369e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu        ALOGD("Emulator without GPU support detected. "
20469e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu              "Fallback to legacy software renderer, qemu.gles is set to 0.");
20569e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu        property_set("qemu.gles", "0");
20669e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    }
20769e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu}
20869e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu
209ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopianvoid* Loader::open(egl_connection_t* cnx)
210de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian{
211de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    void* dso;
212de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    driver_t* hnd = 0;
21394cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall
21469e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu    setEmulatorGlesValue();
21569e5b1ab80018817b1d4ffbbdb5695ff70168c95bohu
216993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    dso = load_driver("GLES", cnx, EGL | GLESv1_CM | GLESv2);
217993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    if (dso) {
218993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian        hnd = new driver_t(dso);
219993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    } else {
220993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian        // Always load EGL first
221993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian        dso = load_driver("EGL", cnx, EGL);
222de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        if (dso) {
223de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            hnd = new driver_t(dso);
224993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            hnd->set( load_driver("GLESv1_CM", cnx, GLESv1_CM), GLESv1_CM );
225993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            hnd->set( load_driver("GLESv2",    cnx, GLESv2),    GLESv2 );
226de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        }
227de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    }
228de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
229993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    LOG_ALWAYS_FATAL_IF(!hnd, "couldn't find an OpenGL ES implementation");
230c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall
231c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov    cnx->libEgl   = load_wrapper(EGL_WRAPPER_DIR "/libEGL.so");
232c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov    cnx->libGles2 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv2.so");
233c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov    cnx->libGles1 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv1_CM.so");
234c2466e6f005e9cbeea7764e9d8864fa6bca17633Evgenii Stepanov
235c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock    LOG_ALWAYS_FATAL_IF(!cnx->libEgl,
236c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock            "couldn't load system EGL wrapper libraries");
237c0ec5e2333b6350480851b8b48f000c78ea3f88aMichael Chock
238c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall    LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1,
239c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall            "couldn't load system OpenGL ES wrapper libraries");
240c07b52060acd627c8510c1a9151e0753fce76330Jesse Hall
241de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    return (void*)hnd;
242de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian}
243de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
244de58697644a52a614ad9498aa087e95d4a223673Mathias Agopianstatus_t Loader::close(void* driver)
245de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian{
246de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    driver_t* hnd = (driver_t*)driver;
247de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    delete hnd;
248de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    return NO_ERROR;
249de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian}
250de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
25194cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hallvoid Loader::init_api(void* dso,
25294cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall        char const * const * api,
25394cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall        __eglMustCastToProperFunctionPointerType* curr,
25494cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall        getProcAddressType getProcAddress)
255de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian{
2567773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian    const ssize_t SIZE = 256;
2570ad71a97c6061e3b12d2308bd43e02dfeeb63db4Mathias Agopian    char scrap[SIZE];
258de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    while (*api) {
259de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        char const * name = *api;
26094cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall        __eglMustCastToProperFunctionPointerType f =
261de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            (__eglMustCastToProperFunctionPointerType)dlsym(dso, name);
262de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        if (f == NULL) {
263de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            // couldn't find the entry-point, use eglGetProcAddress()
264de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            f = getProcAddress(name);
265de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        }
266de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        if (f == NULL) {
267de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            // Try without the OES postfix
268de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            ssize_t index = ssize_t(strlen(name)) - 3;
2690ad71a97c6061e3b12d2308bd43e02dfeeb63db4Mathias Agopian            if ((index>0 && (index<SIZE-1)) && (!strcmp(name+index, "OES"))) {
270de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian                strncpy(scrap, name, index);
271de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian                scrap[index] = 0;
272de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian                f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap);
2739d4536835248525f32f1504a3d28d5bbfa0a2910Steve Block                //ALOGD_IF(f, "found <%s> instead", scrap);
274de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            }
275de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        }
276de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        if (f == NULL) {
277de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            // Try with the OES postfix
2780ad71a97c6061e3b12d2308bd43e02dfeeb63db4Mathias Agopian            ssize_t index = ssize_t(strlen(name)) - 3;
2790ad71a97c6061e3b12d2308bd43e02dfeeb63db4Mathias Agopian            if (index>0 && strcmp(name+index, "OES")) {
2800ad71a97c6061e3b12d2308bd43e02dfeeb63db4Mathias Agopian                snprintf(scrap, SIZE, "%sOES", name);
281de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian                f = (__eglMustCastToProperFunctionPointerType)dlsym(dso, scrap);
2829d4536835248525f32f1504a3d28d5bbfa0a2910Steve Block                //ALOGD_IF(f, "found <%s> instead", scrap);
283de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            }
284de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        }
285de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        if (f == NULL) {
2869d4536835248525f32f1504a3d28d5bbfa0a2910Steve Block            //ALOGD("%s", name);
287de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented;
28848d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian
28948d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian            /*
29048d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian             * GL_EXT_debug_label is special, we always report it as
29148d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian             * supported, it's handled by GLES_trace. If GLES_trace is not
29248d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian             * enabled, then these are no-ops.
29348d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian             */
29448d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian            if (!strcmp(name, "glInsertEventMarkerEXT")) {
29548d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian                f = (__eglMustCastToProperFunctionPointerType)gl_noop;
29648d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian            } else if (!strcmp(name, "glPushGroupMarkerEXT")) {
29748d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian                f = (__eglMustCastToProperFunctionPointerType)gl_noop;
29848d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian            } else if (!strcmp(name, "glPopGroupMarkerEXT")) {
29948d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian                f = (__eglMustCastToProperFunctionPointerType)gl_noop;
30048d438d05f14c2f4bd83ae89f520368cd49122dfMathias Agopian            }
301de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        }
302de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        *curr++ = f;
303de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        api++;
304de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    }
305de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian}
306de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
307993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopianvoid *Loader::load_driver(const char* kind,
308618fa10949c42eb83fa5fe105fe542bcff833ddaMathias Agopian        egl_connection_t* cnx, uint32_t mask)
309de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian{
310993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    class MatchFile {
311993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    public:
312993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian        static String8 find(const char* kind) {
313993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            String8 result;
314776951f9db5744c94167d463584e9ee42c849712Nicolas Capens            int emulationStatus = checkGlesEmulationStatus();
315776951f9db5744c94167d463584e9ee42c849712Nicolas Capens            switch (emulationStatus) {
316776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                case 0:
317776951f9db5744c94167d463584e9ee42c849712Nicolas Capens#if defined(__LP64__)
318776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                    result.setTo("/system/lib64/egl/libGLES_android.so");
319776951f9db5744c94167d463584e9ee42c849712Nicolas Capens#else
320776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                    result.setTo("/system/lib/egl/libGLES_android.so");
321776951f9db5744c94167d463584e9ee42c849712Nicolas Capens#endif
322776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                    return result;
323776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                case 1:
324776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                    // Use host-side OpenGL through the "emulation" library
325776951f9db5744c94167d463584e9ee42c849712Nicolas Capens#if defined(__LP64__)
326776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                    result.appendFormat("/system/lib64/egl/lib%s_emulation.so", kind);
327776951f9db5744c94167d463584e9ee42c849712Nicolas Capens#else
328776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                    result.appendFormat("/system/lib/egl/lib%s_emulation.so", kind);
329776951f9db5744c94167d463584e9ee42c849712Nicolas Capens#endif
330776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                    return result;
331776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                default:
332776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                    // Not in emulator, or use other guest-side implementation
333776951f9db5744c94167d463584e9ee42c849712Nicolas Capens                    break;
334776951f9db5744c94167d463584e9ee42c849712Nicolas Capens            }
335776951f9db5744c94167d463584e9ee42c849712Nicolas Capens
336993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            String8 pattern;
337993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            pattern.appendFormat("lib%s", kind);
338993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            const char* const searchPaths[] = {
3398edb8f5f2d016e4e31530ad7a0c44a4a7a853f64Dan Willemsen#if defined(__LP64__)
3408edb8f5f2d016e4e31530ad7a0c44a4a7a853f64Dan Willemsen                    "/vendor/lib64/egl",
3418edb8f5f2d016e4e31530ad7a0c44a4a7a853f64Dan Willemsen                    "/system/lib64/egl"
3428edb8f5f2d016e4e31530ad7a0c44a4a7a853f64Dan Willemsen#else
343993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    "/vendor/lib/egl",
344993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    "/system/lib/egl"
3458edb8f5f2d016e4e31530ad7a0c44a4a7a853f64Dan Willemsen#endif
346993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            };
347993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian
348993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            // first, we search for the exact name of the GLES userspace
349993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            // driver in both locations.
350993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            // i.e.:
351993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            //      libGLES.so, or:
352993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            //      libEGL.so, libGLESv1_CM.so, libGLESv2.so
353993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian
354993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            for (size_t i=0 ; i<NELEM(searchPaths) ; i++) {
355993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                if (find(result, pattern, searchPaths[i], true)) {
356993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    return result;
357993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                }
358993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            }
359993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian
360993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            // for compatibility with the old "egl.cfg" naming convention
361993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            // we look for files that match:
362993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            //      libGLES_*.so, or:
363993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            //      libEGL_*.so, libGLESv1_CM_*.so, libGLESv2_*.so
364993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian
365993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            pattern.append("_");
366993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            for (size_t i=0 ; i<NELEM(searchPaths) ; i++) {
367993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                if (find(result, pattern, searchPaths[i], false)) {
368993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    return result;
369993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                }
370993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            }
371993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian
372993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            // we didn't find the driver. gah.
373993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            result.clear();
374993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            return result;
375993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian        }
376993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian
377993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    private:
378993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian        static bool find(String8& result,
379993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                const String8& pattern, const char* const search, bool exact) {
380993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            if (exact) {
381993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                String8 absolutePath;
382993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                absolutePath.appendFormat("%s/%s.so", search, pattern.string());
383993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                if (!access(absolutePath.string(), R_OK)) {
384993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    result = absolutePath;
385993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    return true;
386993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                }
387993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                return false;
388993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            }
389993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian
390993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            DIR* d = opendir(search);
391993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            if (d != NULL) {
392993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                struct dirent cur;
393993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                struct dirent* e;
394993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                while (readdir_r(d, &cur, &e) == 0 && e) {
395993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    if (e->d_type == DT_DIR) {
396993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                        continue;
397993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    }
398993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    if (!strcmp(e->d_name, "libGLES_android.so")) {
399993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                        // always skip the software renderer
400993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                        continue;
401993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    }
402993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    if (strstr(e->d_name, pattern.string()) == e->d_name) {
403993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                        if (!strcmp(e->d_name + strlen(e->d_name) - 3, ".so")) {
404993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                            result.clear();
405993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                            result.appendFormat("%s/%s", search, e->d_name);
406993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                            closedir(d);
407993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                            return true;
408993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                        }
409993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                    }
410993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                }
411993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian                closedir(d);
412993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            }
413993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian            return false;
4142b9e4f6a2490864ead44e88a68da78be5cb3da22Brian Swetland        }
415993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    };
416993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian
417993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian
418993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    String8 absolutePath = MatchFile::find(kind);
419993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    if (absolutePath.isEmpty()) {
420993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian        // this happens often, we don't want to log an error
421993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian        return 0;
4228c17384a5edd027376926b857af1fb170dbe9b43Mathias Agopian    }
423993814255fc248454368ed9fe34b4703a05eaf99Mathias Agopian    const char* const driver_absolute_path = absolutePath.string();
4248c17384a5edd027376926b857af1fb170dbe9b43Mathias Agopian
4258c17384a5edd027376926b857af1fb170dbe9b43Mathias Agopian    void* dso = dlopen(driver_absolute_path, RTLD_NOW | RTLD_LOCAL);
4268c17384a5edd027376926b857af1fb170dbe9b43Mathias Agopian    if (dso == 0) {
4278c17384a5edd027376926b857af1fb170dbe9b43Mathias Agopian        const char* err = dlerror();
428e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block        ALOGE("load_driver(%s): %s", driver_absolute_path, err?err:"unknown");
4298c17384a5edd027376926b857af1fb170dbe9b43Mathias Agopian        return 0;
4308c17384a5edd027376926b857af1fb170dbe9b43Mathias Agopian    }
431de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
4329d4536835248525f32f1504a3d28d5bbfa0a2910Steve Block    ALOGD("loaded %s", driver_absolute_path);
433baca89c06a40c6c19ae2294fb4263d893126320cMathias Agopian
434de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    if (mask & EGL) {
435de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        getProcAddress = (getProcAddressType)dlsym(dso, "eglGetProcAddress");
436de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
43794cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall        ALOGE_IF(!getProcAddress,
4388c17384a5edd027376926b857af1fb170dbe9b43Mathias Agopian                "can't find eglGetProcAddress() in %s", driver_absolute_path);
439de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
440618fa10949c42eb83fa5fe105fe542bcff833ddaMathias Agopian        egl_t* egl = &cnx->egl;
441de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        __eglMustCastToProperFunctionPointerType* curr =
442de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            (__eglMustCastToProperFunctionPointerType*)egl;
443de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        char const * const * api = egl_names;
444de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        while (*api) {
445de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            char const * name = *api;
44694cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall            __eglMustCastToProperFunctionPointerType f =
447de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian                (__eglMustCastToProperFunctionPointerType)dlsym(dso, name);
448de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            if (f == NULL) {
449de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian                // couldn't find the entry-point, use eglGetProcAddress()
450de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian                f = getProcAddress(name);
451de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian                if (f == NULL) {
452de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian                    f = (__eglMustCastToProperFunctionPointerType)0;
453de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian                }
454de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            }
455de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            *curr++ = f;
456de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            api++;
457de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian        }
458de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    }
45994cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall
460de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    if (mask & GLESv1_CM) {
461618fa10949c42eb83fa5fe105fe542bcff833ddaMathias Agopian        init_api(dso, gl_names,
462618fa10949c42eb83fa5fe105fe542bcff833ddaMathias Agopian            (__eglMustCastToProperFunctionPointerType*)
4637773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                &cnx->hooks[egl_connection_t::GLESv1_INDEX]->gl,
464618fa10949c42eb83fa5fe105fe542bcff833ddaMathias Agopian            getProcAddress);
465de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    }
466de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
467de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    if (mask & GLESv2) {
468618fa10949c42eb83fa5fe105fe542bcff833ddaMathias Agopian      init_api(dso, gl_names,
469618fa10949c42eb83fa5fe105fe542bcff833ddaMathias Agopian            (__eglMustCastToProperFunctionPointerType*)
4707773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian                &cnx->hooks[egl_connection_t::GLESv2_INDEX]->gl,
471de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian            getProcAddress);
472de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    }
47394cdba97ce1de140623d84c14fb15f12f7da89ddJesse Hall
474de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian    return dso;
475de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian}
476de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian
477de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian// ----------------------------------------------------------------------------
478de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian}; // namespace android
479de58697644a52a614ad9498aa087e95d4a223673Mathias Agopian// ----------------------------------------------------------------------------
480