• 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 "GL2Encoder.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 //XXX: fix this macro to get the context from fast tls path
27 #define GET_CONTEXT GL2Encoder * ctx = getEGLThreadInfo()->hostConn->gl2Encoder();
28 
29 #include "gl2_entry.cpp"
30 
31 //The functions table
32 #include "gl2_ftable.h"
33 
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 v2 target=%#x img=%p\n", 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, ((cb_handle_t *)(native_buffer->handle))->hostHandle);
70     ctx->restore2DTextureTarget();
71 
72     return;
73 }
74 
glEGLImageTargetRenderbufferStorageOES(void * self,GLenum target,GLeglImageOES image)75 void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image)
76 {
77     DBG("glEGLImageTargetRenderbufferStorageOES v2 image=%p\n", image);
78     //TODO: check error - we don't have a way to set gl error
79     android_native_buffer_t* native_buffer = (android_native_buffer_t*)image;
80 
81     if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
82         return;
83     }
84 
85     if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
86         return;
87     }
88 
89     DEFINE_AND_VALIDATE_HOST_CONNECTION();
90     rcEnc->rcBindRenderbuffer(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle);
91 
92     return;
93 }
94 
getProcAddress(const char * procname)95 void * getProcAddress(const char * procname)
96 {
97     // search in GL function table
98     for (int i=0; i<gl2_num_funcs; i++) {
99         if (!strcmp(gl2_funcs_by_name[i].name, procname)) {
100             return gl2_funcs_by_name[i].proc;
101         }
102     }
103     return NULL;
104 }
105 
finish()106 void finish()
107 {
108     glFinish();
109 }
110 
my_glGetString(void * self,GLenum name)111 const GLubyte *my_glGetString (void *self, GLenum name)
112 {
113     if (s_egl) {
114         return (const GLubyte*)s_egl->getGLString(name);
115     }
116     return NULL;
117 }
118 
init()119 void init()
120 {
121     GET_CONTEXT;
122     ctx->set_glEGLImageTargetTexture2DOES(glEGLImageTargetTexture2DOES);
123     ctx->set_glEGLImageTargetRenderbufferStorageOES(glEGLImageTargetRenderbufferStorageOES);
124     ctx->set_glGetString(my_glGetString);
125 }
126 
127 extern "C" {
init_emul_gles(EGLClient_eglInterface * eglIface)128 EGLClient_glesInterface * init_emul_gles(EGLClient_eglInterface *eglIface)
129 {
130     s_egl = eglIface;
131 
132     if (!s_gl) {
133         s_gl = new EGLClient_glesInterface();
134         s_gl->getProcAddress = getProcAddress;
135         s_gl->finish = finish;
136         s_gl->init = init;
137     }
138 
139     return s_gl;
140 }
141 } //extern
142 
143 
144