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 gl_client_context_t * 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 image=0x%x", 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 DEFINE_AND_VALIDATE_HOST_CONNECTION(); 51 rcEnc->rcBindTexture(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle); 52 53 return; 54 } 55 56 void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image) 57 { 58 DBG("glEGLImageTargetRenderbufferStorageOES v1 image=0x%x", image); 59 //TODO: check error - we don't have a way to set gl error 60 android_native_buffer_t* native_buffer = (android_native_buffer_t*)image; 61 62 if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) { 63 return; 64 } 65 66 if (native_buffer->common.version != sizeof(android_native_buffer_t)) { 67 return; 68 } 69 70 DEFINE_AND_VALIDATE_HOST_CONNECTION(); 71 rcEnc->rcBindRenderbuffer(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle); 72 73 return; 74 } 75 76 void * getProcAddress(const char * procname) 77 { 78 // search in GL function table 79 for (int i=0; i<gl_num_funcs; i++) { 80 if (!strcmp(gl_funcs_by_name[i].name, procname)) { 81 return gl_funcs_by_name[i].proc; 82 } 83 } 84 return NULL; 85 } 86 87 void finish() 88 { 89 glFinish(); 90 } 91 92 const GLubyte *my_glGetString (void *self, GLenum name) 93 { 94 if (s_egl) { 95 return (const GLubyte*)s_egl->getGLString(name); 96 } 97 return NULL; 98 } 99 100 void init() 101 { 102 GET_CONTEXT; 103 ctx->set_glEGLImageTargetTexture2DOES(glEGLImageTargetTexture2DOES); 104 ctx->set_glEGLImageTargetRenderbufferStorageOES(glEGLImageTargetRenderbufferStorageOES); 105 ctx->set_glGetString(my_glGetString); 106 } 107 108 extern "C" { 109 EGLClient_glesInterface * init_emul_gles(EGLClient_eglInterface *eglIface) 110 { 111 s_egl = eglIface; 112 113 if (!s_gl) { 114 s_gl = new EGLClient_glesInterface(); 115 s_gl->getProcAddress = getProcAddress; 116 s_gl->finish = finish; 117 s_gl->init = init; 118 } 119 120 return s_gl; 121 } 122 } //extern 123 124 125