1 #include "EGLClientIface.h" 2 #include "HostConnection.h" 3 #include "GL2Encoder.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 //XXX: fix this macro to get the context from fast tls path 12 #define GET_CONTEXT GL2Encoder * ctx = getEGLThreadInfo()->hostConn->gl2Encoder(); 13 14 #include "gl2_entry.cpp" 15 16 //The functions table 17 #include "gl2_ftable.h" 18 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 v2 target=%#x img=%p\n", 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, ((cb_handle_t *)(native_buffer->handle))->hostHandle); 55 ctx->restore2DTextureTarget(); 56 57 return; 58 } 59 60 void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image) 61 { 62 DBG("glEGLImageTargetRenderbufferStorageOES v2 image=%p\n", image); 63 //TODO: check error - we don't have a way to set gl error 64 android_native_buffer_t* native_buffer = (android_native_buffer_t*)image; 65 66 if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) { 67 return; 68 } 69 70 if (native_buffer->common.version != sizeof(android_native_buffer_t)) { 71 return; 72 } 73 74 DEFINE_AND_VALIDATE_HOST_CONNECTION(); 75 rcEnc->rcBindRenderbuffer(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle); 76 77 return; 78 } 79 80 void * getProcAddress(const char * procname) 81 { 82 // search in GL function table 83 for (int i=0; i<gl2_num_funcs; i++) { 84 if (!strcmp(gl2_funcs_by_name[i].name, procname)) { 85 return gl2_funcs_by_name[i].proc; 86 } 87 } 88 return NULL; 89 } 90 91 void finish() 92 { 93 glFinish(); 94 } 95 96 const GLubyte *my_glGetString (void *self, GLenum name) 97 { 98 if (s_egl) { 99 return (const GLubyte*)s_egl->getGLString(name); 100 } 101 return NULL; 102 } 103 104 void init() 105 { 106 GET_CONTEXT; 107 ctx->set_glEGLImageTargetTexture2DOES(glEGLImageTargetTexture2DOES); 108 ctx->set_glEGLImageTargetRenderbufferStorageOES(glEGLImageTargetRenderbufferStorageOES); 109 ctx->set_glGetString(my_glGetString); 110 } 111 112 extern "C" { 113 EGLClient_glesInterface * init_emul_gles(EGLClient_eglInterface *eglIface) 114 { 115 s_egl = eglIface; 116 117 if (!s_gl) { 118 s_gl = new EGLClient_glesInterface(); 119 s_gl->getProcAddress = getProcAddress; 120 s_gl->finish = finish; 121 s_gl->init = init; 122 } 123 124 return s_gl; 125 } 126 } //extern 127 128 129