Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff1448b5 authored by Mathias Agopian's avatar Mathias Agopian Committed by Android Git Automerger
Browse files

am d12a98e2: am 9abce39a: Merge "fix [2421247] implement eglGetProcAddress(),...

am d12a98e2: am 9abce39a: Merge "fix [2421247] implement eglGetProcAddress(), needed in the ndk" into gingerbread

Merge commit 'd12a98e2b1eb3a2ae20eace8a7d4b5fa13bbedfb'

* commit 'd12a98e2b1eb3a2ae20eace8a7d4b5fa13bbedfb':
  fix [2421247] implement eglGetProcAddress(), needed in the ndk
parents 6067d75d 574a26fa
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -8,6 +8,7 @@ include $(CLEAR_VARS)


LOCAL_SRC_FILES:= 	       \
LOCAL_SRC_FILES:= 	       \
	EGL/egl.cpp 	       \
	EGL/egl.cpp 	       \
	EGL/getProcAddress.cpp.arm \
	EGL/hooks.cpp 	       \
	EGL/hooks.cpp 	       \
	EGL/Loader.cpp 	       \
	EGL/Loader.cpp 	       \
#
#
+50 −45
Original line number Original line Diff line number Diff line
@@ -37,6 +37,8 @@
#include <cutils/memory.h>
#include <cutils/memory.h>


#include <utils/SortedVector.h>
#include <utils/SortedVector.h>
#include <utils/KeyedVector.h>
#include <utils/String8.h>


#include "hooks.h"
#include "hooks.h"
#include "egl_impl.h"
#include "egl_impl.h"
@@ -410,7 +412,11 @@ static const extention_map_t gExtentionMap[] = {
            (__eglMustCastToProperFunctionPointerType)&eglGetRenderBufferANDROID }, 
            (__eglMustCastToProperFunctionPointerType)&eglGetRenderBufferANDROID }, 
};
};


static extention_map_t gGLExtentionMap[MAX_NUMBER_OF_GL_EXTENSIONS];
extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS];

// accesses protected by gInitDriverMutex
static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> gGLExtentionMap;
static int gGLExtentionSlot = 0;


static void(*findProcAddress(const char* name,
static void(*findProcAddress(const char* name,
        const extention_map_t* map, size_t n))() 
        const extention_map_t* map, size_t n))() 
@@ -1369,55 +1375,54 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
    addr = findProcAddress(procname, gExtentionMap, NELEM(gExtentionMap));
    addr = findProcAddress(procname, gExtentionMap, NELEM(gExtentionMap));
    if (addr) return addr;
    if (addr) return addr;


    return NULL; // TODO: finish implementation below
    // this protects accesses to gGLExtentionMap and gGLExtentionSlot
    pthread_mutex_lock(&gInitDriverMutex);


    addr = findProcAddress(procname, gGLExtentionMap, NELEM(gGLExtentionMap));
        /*
    if (addr) return addr;
         * Since eglGetProcAddress() is not associated to anything, it needs
         * to return a function pointer that "works" regardless of what
         * the current context is.
         *
         * For this reason, we return a "forwarder", a small stub that takes
         * care of calling the function associated with the context
         * currently bound.
         *
         * We first look for extensions we've already resolved, if we're seeing
         * this extension for the first time, we go through all our
         * implementations and call eglGetProcAddress() and record the
         * result in the appropriate implementation hooks and return the
         * address of the forwarder corresponding to that hook set.
         *
         */

        const String8 name(procname);
        addr = gGLExtentionMap.valueFor(name);
        const int slot = gGLExtentionSlot;


    addr = 0;
        LOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS,
    int slot = -1;
                "no more slots for eglGetProcAddress(\"%s\")",
                procname);

        if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) {
            bool found = false;
            for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) {
            for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) {
                egl_connection_t* const cnx = &gEGLImpl[i];
                egl_connection_t* const cnx = &gEGLImpl[i];
        if (cnx->dso) {
                if (cnx->dso && cnx->egl.eglGetProcAddress) {
            if (cnx->egl.eglGetProcAddress) {
                    found = true;
                addr = cnx->egl.eglGetProcAddress(procname);
                    cnx->hooks[i]->ext.extensions[slot] =
                if (addr) {
                            cnx->egl.eglGetProcAddress(procname);
                    if (slot == -1) {
                        slot = 0; // XXX: find free slot
                        if (slot == -1) {
                            addr = 0;
                            break;
                        }
                    }
                    //cnx->hooks->ext.extensions[slot] = addr;
                }
                }
            }
            }
            if (found) {
                addr = gExtensionForwarders[slot];
                gGLExtentionMap.add(name, addr);
                gGLExtentionSlot++;
            }
            }
        }
        }


    if (slot >= 0) {
    pthread_mutex_unlock(&gInitDriverMutex);
        addr = 0; // XXX: address of stub 'slot'
        gGLExtentionMap[slot].name = strdup(procname);
        gGLExtentionMap[slot].address = addr;
    }


    return addr;
    return addr;

    
    /*
     *  TODO: For OpenGL ES extensions, we must generate a stub
     *  that looks like
     *      mov     r12, #0xFFFF0FFF
     *      ldr     r12, [r12, #-15]
     *      ldr     r12, [r12, #TLS_SLOT_OPENGL_API*4]
     *      mov     r12, [r12, #api_offset]
     *      ldrne   pc, r12
     *      mov     pc, #unsupported_extension
     * 
     *  and write the address of the extension in *all*
     *  gl_hooks_t::gl_ext_t at offset "api_offset" from gl_hooks_t
     * 
     */
}
}


EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw)
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw)
+176 −0
Original line number Original line Diff line number Diff line
/*
 ** Copyright 2009, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 **
 **     http://www.apache.org/licenses/LICENSE-2.0
 **
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.
 */

#include <ctype.h>
#include <stdlib.h>
#include <errno.h>

#include <cutils/log.h>

#include "hooks.h"

// ----------------------------------------------------------------------------
namespace android {
// ----------------------------------------------------------------------------

#undef API_ENTRY
#undef CALL_GL_API
#undef GL_EXTENSION
#undef GL_EXTENSION_NAME

#if defined(__arm__)

    #ifdef HAVE_ARM_TLS_REGISTER
        #define GET_TLS(reg) \
            "mrc p15, 0, " #reg ", c13, c0, 3 \n"
    #else
        #define GET_TLS(reg) \
            "mov   " #reg ", #0xFFFF0FFF      \n"  \
            "ldr   " #reg ", [" #reg ", #-15] \n"
    #endif

    #define API_ENTRY(_api) __attribute__((naked)) _api

    #define CALL_GL_EXTENSION_API(_api)                         \
         asm volatile(                                          \
            GET_TLS(r12)                                        \
            "ldr   r12, [r12, %[tls]] \n"                       \
            "cmp   r12, #0            \n"                       \
            "ldrne r12, [r12, %[api]] \n"                       \
            "cmpne r12, #0            \n"                       \
            "bxne  r12                \n"                       \
            "bx    lr                 \n"                       \
            :                                                   \
            : [tls] "J"(TLS_SLOT_OPENGL_API*4),                 \
              [api] "J"(__builtin_offsetof(gl_hooks_t,          \
                                      ext.extensions[_api]))    \
            :                                                   \
            );

    #define GL_EXTENSION_NAME(_n)  __glExtFwd##_n

    #define GL_EXTENSION(_n)                         \
        void API_ENTRY(GL_EXTENSION_NAME(_n))() {    \
            CALL_GL_EXTENSION_API(_n);               \
        }


#else

    #define GL_EXTENSION_NAME(_n) NULL

    #define GL_EXTENSION(_n)

    #warning "eglGetProcAddress() partially supported on this architecture"

#endif

GL_EXTENSION(0)
GL_EXTENSION(1)
GL_EXTENSION(2)
GL_EXTENSION(3)
GL_EXTENSION(4)
GL_EXTENSION(5)
GL_EXTENSION(6)
GL_EXTENSION(7)
GL_EXTENSION(8)
GL_EXTENSION(9)
GL_EXTENSION(10)
GL_EXTENSION(11)
GL_EXTENSION(12)
GL_EXTENSION(13)
GL_EXTENSION(14)
GL_EXTENSION(15)

GL_EXTENSION(16)
GL_EXTENSION(17)
GL_EXTENSION(18)
GL_EXTENSION(19)
GL_EXTENSION(20)
GL_EXTENSION(21)
GL_EXTENSION(22)
GL_EXTENSION(23)
GL_EXTENSION(24)
GL_EXTENSION(25)
GL_EXTENSION(26)
GL_EXTENSION(27)
GL_EXTENSION(28)
GL_EXTENSION(29)
GL_EXTENSION(30)
GL_EXTENSION(31)

GL_EXTENSION(32)
GL_EXTENSION(33)
GL_EXTENSION(34)
GL_EXTENSION(35)
GL_EXTENSION(36)
GL_EXTENSION(37)
GL_EXTENSION(38)
GL_EXTENSION(39)
GL_EXTENSION(40)
GL_EXTENSION(41)
GL_EXTENSION(42)
GL_EXTENSION(43)
GL_EXTENSION(44)
GL_EXTENSION(45)
GL_EXTENSION(46)
GL_EXTENSION(47)

GL_EXTENSION(48)
GL_EXTENSION(49)
GL_EXTENSION(50)
GL_EXTENSION(51)
GL_EXTENSION(52)
GL_EXTENSION(53)
GL_EXTENSION(54)
GL_EXTENSION(55)
GL_EXTENSION(56)
GL_EXTENSION(57)
GL_EXTENSION(58)
GL_EXTENSION(59)
GL_EXTENSION(60)
GL_EXTENSION(61)
GL_EXTENSION(62)
GL_EXTENSION(63)

extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS] = {
     GL_EXTENSION_NAME(0),  GL_EXTENSION_NAME(1),  GL_EXTENSION_NAME(2),  GL_EXTENSION_NAME(3),
     GL_EXTENSION_NAME(4),  GL_EXTENSION_NAME(5),  GL_EXTENSION_NAME(6),  GL_EXTENSION_NAME(7),
     GL_EXTENSION_NAME(8),  GL_EXTENSION_NAME(9),  GL_EXTENSION_NAME(10), GL_EXTENSION_NAME(11),
     GL_EXTENSION_NAME(12), GL_EXTENSION_NAME(13), GL_EXTENSION_NAME(14), GL_EXTENSION_NAME(15),
     GL_EXTENSION_NAME(16), GL_EXTENSION_NAME(17), GL_EXTENSION_NAME(18), GL_EXTENSION_NAME(19),
     GL_EXTENSION_NAME(20), GL_EXTENSION_NAME(21), GL_EXTENSION_NAME(22), GL_EXTENSION_NAME(23),
     GL_EXTENSION_NAME(24), GL_EXTENSION_NAME(25), GL_EXTENSION_NAME(26), GL_EXTENSION_NAME(27),
     GL_EXTENSION_NAME(28), GL_EXTENSION_NAME(29), GL_EXTENSION_NAME(30), GL_EXTENSION_NAME(31),
     GL_EXTENSION_NAME(32), GL_EXTENSION_NAME(33), GL_EXTENSION_NAME(34), GL_EXTENSION_NAME(35),
     GL_EXTENSION_NAME(36), GL_EXTENSION_NAME(37), GL_EXTENSION_NAME(38), GL_EXTENSION_NAME(39),
     GL_EXTENSION_NAME(40), GL_EXTENSION_NAME(41), GL_EXTENSION_NAME(42), GL_EXTENSION_NAME(43),
     GL_EXTENSION_NAME(44), GL_EXTENSION_NAME(45), GL_EXTENSION_NAME(46), GL_EXTENSION_NAME(47),
     GL_EXTENSION_NAME(48), GL_EXTENSION_NAME(49), GL_EXTENSION_NAME(50), GL_EXTENSION_NAME(51),
     GL_EXTENSION_NAME(52), GL_EXTENSION_NAME(53), GL_EXTENSION_NAME(54), GL_EXTENSION_NAME(55),
     GL_EXTENSION_NAME(56), GL_EXTENSION_NAME(57), GL_EXTENSION_NAME(58), GL_EXTENSION_NAME(59),
     GL_EXTENSION_NAME(60), GL_EXTENSION_NAME(61), GL_EXTENSION_NAME(62), GL_EXTENSION_NAME(63)
 };

#undef GL_EXTENSION_NAME
#undef GL_EXTENSION
#undef API_ENTRY
#undef CALL_GL_API

// ----------------------------------------------------------------------------
}; // namespace android
// ----------------------------------------------------------------------------
+2 −2
Original line number Original line Diff line number Diff line
@@ -37,7 +37,7 @@
#endif
#endif
#undef NELEM
#undef NELEM
#define NELEM(x)                    (sizeof(x)/sizeof(*(x)))
#define NELEM(x)                    (sizeof(x)/sizeof(*(x)))
#define MAX_NUMBER_OF_GL_EXTENSIONS 32
#define MAX_NUMBER_OF_GL_EXTENSIONS 64




#if defined(HAVE_ANDROID_OS) && !USE_SLOW_BINDING && __OPTIMIZE__
#if defined(HAVE_ANDROID_OS) && !USE_SLOW_BINDING && __OPTIMIZE__
@@ -86,7 +86,7 @@ struct gl_hooks_t {
        #include "entries.in"
        #include "entries.in"
    } gl;
    } gl;
    struct gl_ext_t {
    struct gl_ext_t {
        void (*extensions[MAX_NUMBER_OF_GL_EXTENSIONS])(void);
        __eglMustCastToProperFunctionPointerType extensions[MAX_NUMBER_OF_GL_EXTENSIONS];
    } ext;
    } ext;
};
};
#undef GL_ENTRY
#undef GL_ENTRY