• 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     (void)self;
54     (void)target;
55 
56     DBG("glEGLImageTargetTexture2DOES v2 target=%#x img=%p\n", target, image);
57     //TODO: check error - we don't have a way to set gl error
58     android_native_buffer_t* native_buffer = (android_native_buffer_t*)image;
59 
60     if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
61         return;
62     }
63 
64     if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
65         return;
66     }
67 
68     GET_CONTEXT;
69     DEFINE_AND_VALIDATE_HOST_CONNECTION();
70 
71     ctx->override2DTextureTarget(target);
72     rcEnc->rcBindTexture(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle);
73     ctx->restore2DTextureTarget();
74 
75     return;
76 }
77 
glEGLImageTargetRenderbufferStorageOES(void * self,GLenum target,GLeglImageOES image)78 void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image)
79 {
80     (void)self;
81     (void)target;
82 
83     DBG("glEGLImageTargetRenderbufferStorageOES v2 image=%p\n", image);
84     //TODO: check error - we don't have a way to set gl error
85     android_native_buffer_t* native_buffer = (android_native_buffer_t*)image;
86 
87     if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
88         return;
89     }
90 
91     if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
92         return;
93     }
94 
95     DEFINE_AND_VALIDATE_HOST_CONNECTION();
96     rcEnc->rcBindRenderbuffer(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle);
97 
98     return;
99 }
100 
getProcAddress(const char * procname)101 void * getProcAddress(const char * procname)
102 {
103     // search in GL function table
104     for (int i=0; i<gl2_num_funcs; i++) {
105         if (!strcmp(gl2_funcs_by_name[i].name, procname)) {
106             return gl2_funcs_by_name[i].proc;
107         }
108     }
109     return NULL;
110 }
111 
finish()112 void finish()
113 {
114     glFinish();
115 }
116 
my_glGetString(void * self,GLenum name)117 const GLubyte *my_glGetString (void *self, GLenum name)
118 {
119     (void)self;
120 
121     if (s_egl) {
122         return (const GLubyte*)s_egl->getGLString(name);
123     }
124     return NULL;
125 }
126 
init()127 void init()
128 {
129     GET_CONTEXT;
130     ctx->glEGLImageTargetTexture2DOES = &glEGLImageTargetTexture2DOES;
131     ctx->glEGLImageTargetRenderbufferStorageOES = &glEGLImageTargetRenderbufferStorageOES;
132     ctx->glGetString = &my_glGetString;
133 }
134 
135 extern "C" {
init_emul_gles(EGLClient_eglInterface * eglIface)136 EGLClient_glesInterface * init_emul_gles(EGLClient_eglInterface *eglIface)
137 {
138     s_egl = eglIface;
139 
140     if (!s_gl) {
141         s_gl = new EGLClient_glesInterface();
142         s_gl->getProcAddress = getProcAddress;
143         s_gl->finish = finish;
144         s_gl->init = init;
145     }
146 
147     return s_gl;
148 }
149 } //extern
150 
151 
152