Home | History | Annotate | Download | only in GLESv1
      1 #include "EGLClientIface.h"
      2 #include "HostConnection.h"
      3 #include "GLEncoder.h"
      4 #include "GLES/gl.h"
      5 #include "GLES/glext.h"
      6 #include "ErrorLog.h"
      7 #include <private/ui/android_natives_priv.h>
      8 #include "gralloc_cb.h"
      9 #include "ThreadInfo.h"
     10 
     11 
     12 //XXX: fix this macro to get the context from fast tls path
     13 #define GET_CONTEXT GLEncoder * ctx = getEGLThreadInfo()->hostConn->glEncoder();
     14 
     15 #include "gl_entry.cpp"
     16 
     17 //The functions table
     18 #include "gl_ftable.h"
     19 
     20 static EGLClient_eglInterface * s_egl = NULL;
     21 static EGLClient_glesInterface * s_gl = NULL;
     22 
     23 #define DEFINE_AND_VALIDATE_HOST_CONNECTION(ret) \
     24     HostConnection *hostCon = HostConnection::get(); \
     25     if (!hostCon) { \
     26         LOGE("egl: Failed to get host connection\n"); \
     27         return ret; \
     28     } \
     29     renderControl_encoder_context_t *rcEnc = hostCon->rcEncoder(); \
     30     if (!rcEnc) { \
     31         LOGE("egl: Failed to get renderControl encoder context\n"); \
     32         return ret; \
     33     }
     34 
     35 //GL extensions
     36 void glEGLImageTargetTexture2DOES(void * self, GLenum target, GLeglImageOES image)
     37 {
     38     DBG("glEGLImageTargetTexture2DOES v1 target=%#x image=%p", target, image);
     39     //TODO: check error - we don't have a way to set gl error
     40     android_native_buffer_t* native_buffer = (android_native_buffer_t*)image;
     41 
     42     if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
     43         return;
     44     }
     45 
     46     if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
     47         return;
     48     }
     49 
     50     GET_CONTEXT;
     51     DEFINE_AND_VALIDATE_HOST_CONNECTION();
     52 
     53     ctx->override2DTextureTarget(target);
     54     rcEnc->rcBindTexture(rcEnc,
     55             ((cb_handle_t *)(native_buffer->handle))->hostHandle);
     56     ctx->restore2DTextureTarget();
     57 
     58     return;
     59 }
     60 
     61 void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image)
     62 {
     63     DBG("glEGLImageTargetRenderbufferStorageOES v1 target=%#x image=%p",
     64             target, image);
     65     //TODO: check error - we don't have a way to set gl error
     66     android_native_buffer_t* native_buffer = (android_native_buffer_t*)image;
     67 
     68     if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
     69         return;
     70     }
     71 
     72     if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
     73         return;
     74     }
     75 
     76     DEFINE_AND_VALIDATE_HOST_CONNECTION();
     77     rcEnc->rcBindRenderbuffer(rcEnc,
     78             ((cb_handle_t *)(native_buffer->handle))->hostHandle);
     79 
     80     return;
     81 }
     82 
     83 void * getProcAddress(const char * procname)
     84 {
     85     // search in GL function table
     86     for (int i=0; i<gl_num_funcs; i++) {
     87         if (!strcmp(gl_funcs_by_name[i].name, procname)) {
     88             return gl_funcs_by_name[i].proc;
     89         }
     90     }
     91     return NULL;
     92 }
     93 
     94 void finish()
     95 {
     96     glFinish();
     97 }
     98 
     99 const GLubyte *my_glGetString (void *self, GLenum name)
    100 {
    101     if (s_egl) {
    102         return (const GLubyte*)s_egl->getGLString(name);
    103     }
    104     return NULL;
    105 }
    106 
    107 void init()
    108 {
    109     GET_CONTEXT;
    110     ctx->set_glEGLImageTargetTexture2DOES(glEGLImageTargetTexture2DOES);
    111     ctx->set_glEGLImageTargetRenderbufferStorageOES(glEGLImageTargetRenderbufferStorageOES);
    112     ctx->set_glGetString(my_glGetString);
    113 }
    114 
    115 extern "C" {
    116 EGLClient_glesInterface * init_emul_gles(EGLClient_eglInterface *eglIface)
    117 {
    118     s_egl = eglIface;
    119 
    120     if (!s_gl) {
    121         s_gl = new EGLClient_glesInterface();
    122         s_gl->getProcAddress = getProcAddress;
    123         s_gl->finish = finish;
    124         s_gl->init = init;
    125     }
    126 
    127     return s_gl;
    128 }
    129 } //extern
    130 
    131 
    132