• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #include "EGLClientIface.h"
18 #include "HostConnection.h"
19 #include "GLEncoder.h"
20 #include "GLES/gl.h"
21 #include "GLES/glext.h"
22 #include "ErrorLog.h"
23 #include "gralloc_cb.h"
24 #include "ThreadInfo.h"
25 
26 
27 //XXX: fix this macro to get the context from fast tls path
28 #define GET_CONTEXT GLEncoder * ctx = getEGLThreadInfo()->hostConn->glEncoder();
29 
30 #include "gl_entry.cpp"
31 
32 //The functions table
33 #include "gl_ftable.h"
34 
35 static EGLClient_eglInterface * s_egl = NULL;
36 static EGLClient_glesInterface * s_gl = NULL;
37 
38 #define DEFINE_AND_VALIDATE_HOST_CONNECTION(ret) \
39     HostConnection *hostCon = HostConnection::get(); \
40     if (!hostCon) { \
41         ALOGE("egl: Failed to get host connection\n"); \
42         return ret; \
43     } \
44     renderControl_encoder_context_t *rcEnc = hostCon->rcEncoder(); \
45     if (!rcEnc) { \
46         ALOGE("egl: Failed to get renderControl encoder context\n"); \
47         return ret; \
48     }
49 
50 //GL extensions
glEGLImageTargetTexture2DOES(void * self,GLenum target,GLeglImageOES image)51 void glEGLImageTargetTexture2DOES(void * self, GLenum target, GLeglImageOES image)
52 {
53     DBG("glEGLImageTargetTexture2DOES v1 target=%#x image=%p", target, image);
54     //TODO: check error - we don't have a way to set gl error
55     android_native_buffer_t* native_buffer = (android_native_buffer_t*)image;
56 
57     if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
58         return;
59     }
60 
61     if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
62         return;
63     }
64 
65     GET_CONTEXT;
66     DEFINE_AND_VALIDATE_HOST_CONNECTION();
67 
68     ctx->override2DTextureTarget(target);
69     rcEnc->rcBindTexture(rcEnc,
70             ((cb_handle_t *)(native_buffer->handle))->hostHandle);
71     ctx->restore2DTextureTarget();
72 
73     return;
74 }
75 
glEGLImageTargetRenderbufferStorageOES(void * self,GLenum target,GLeglImageOES image)76 void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image)
77 {
78     DBG("glEGLImageTargetRenderbufferStorageOES v1 target=%#x image=%p",
79             target, image);
80     //TODO: check error - we don't have a way to set gl error
81     android_native_buffer_t* native_buffer = (android_native_buffer_t*)image;
82 
83     if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
84         return;
85     }
86 
87     if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
88         return;
89     }
90 
91     DEFINE_AND_VALIDATE_HOST_CONNECTION();
92     rcEnc->rcBindRenderbuffer(rcEnc,
93             ((cb_handle_t *)(native_buffer->handle))->hostHandle);
94 
95     return;
96 }
97 
getProcAddress(const char * procname)98 void * getProcAddress(const char * procname)
99 {
100     // search in GL function table
101     for (int i=0; i<gl_num_funcs; i++) {
102         if (!strcmp(gl_funcs_by_name[i].name, procname)) {
103             return gl_funcs_by_name[i].proc;
104         }
105     }
106     return NULL;
107 }
108 
finish()109 void finish()
110 {
111     glFinish();
112 }
113 
my_glGetString(void * self,GLenum name)114 const GLubyte *my_glGetString (void *self, GLenum name)
115 {
116     if (s_egl) {
117         return (const GLubyte*)s_egl->getGLString(name);
118     }
119     return NULL;
120 }
121 
init()122 void init()
123 {
124     GET_CONTEXT;
125     ctx->set_glEGLImageTargetTexture2DOES(glEGLImageTargetTexture2DOES);
126     ctx->set_glEGLImageTargetRenderbufferStorageOES(glEGLImageTargetRenderbufferStorageOES);
127     ctx->set_glGetString(my_glGetString);
128 }
129 
130 extern "C" {
init_emul_gles(EGLClient_eglInterface * eglIface)131 EGLClient_glesInterface * init_emul_gles(EGLClient_eglInterface *eglIface)
132 {
133     s_egl = eglIface;
134 
135     if (!s_gl) {
136         s_gl = new EGLClient_glesInterface();
137         s_gl->getProcAddress = getProcAddress;
138         s_gl->finish = finish;
139         s_gl->init = init;
140     }
141 
142     return s_gl;
143 }
144 } //extern
145 
146 
147