2 * Copyright 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "EGLClientIface.h"
18 #include "HostConnection.h"
19 #include "GL2Encoder.h"
21 #include "GLES/glext.h"
23 #include "gralloc_cb.h"
24 #include "ThreadInfo.h"
27 //XXX: fix this macro to get the context from fast tls path
28 #define GET_CONTEXT GL2Encoder * ctx = getEGLThreadInfo()->hostConn->gl2Encoder();
30 #include "gl2_entry.cpp"
33 #include "gl2_ftable.h"
36 static EGLClient_eglInterface * s_egl = NULL;
37 static EGLClient_glesInterface * s_gl = NULL;
39 #define DEFINE_AND_VALIDATE_HOST_CONNECTION(ret) \
40 HostConnection *hostCon = HostConnection::get(); \
42 ALOGE("egl: Failed to get host connection\n"); \
45 renderControl_encoder_context_t *rcEnc = hostCon->rcEncoder(); \
47 ALOGE("egl: Failed to get renderControl encoder context\n"); \
52 void glEGLImageTargetTexture2DOES(void * self, GLenum target, GLeglImageOES img)
57 DBG("glEGLImageTargetTexture2DOES v2 target=%#x img=%p\n", target, img);
59 EGLImage_t *image = (EGLImage_t*)img;
61 if (image->target == EGL_NATIVE_BUFFER_ANDROID) {
62 //TODO: check error - we don't have a way to set gl error
63 android_native_buffer_t* native_buffer = image->native_buffer;
65 if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
69 if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
74 DEFINE_AND_VALIDATE_HOST_CONNECTION();
76 ctx->override2DTextureTarget(target);
77 rcEnc->rcBindTexture(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle);
78 ctx->restore2DTextureTarget();
80 else if (image->target == EGL_GL_TEXTURE_2D_KHR) {
82 ctx->override2DTextureTarget(target);
83 GLeglImageOES hostImage = reinterpret_cast<GLeglImageOES>((intptr_t)image->host_egl_image);
84 ctx->m_glEGLImageTargetTexture2DOES_enc(self, target, hostImage);
85 ctx->restore2DTextureTarget();
89 void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image)
94 DBG("glEGLImageTargetRenderbufferStorageOES v2 image=%p\n", image);
95 //TODO: check error - we don't have a way to set gl error
96 android_native_buffer_t* native_buffer = (android_native_buffer_t*)image;
98 if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
102 if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
106 DEFINE_AND_VALIDATE_HOST_CONNECTION();
107 rcEnc->rcBindRenderbuffer(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle);
112 void * getProcAddress(const char * procname)
114 // search in GL function table
115 for (int i=0; i<gl2_num_funcs; i++) {
116 if (!strcmp(gl2_funcs_by_name[i].name, procname)) {
117 return gl2_funcs_by_name[i].proc;
128 const GLubyte *my_glGetString (void *self, GLenum name)
132 //see ref in https://www.khronos.org/opengles/sdk/docs/man
133 //name in glGetString can be one of the following five values
138 case GL_SHADING_LANGUAGE_VERSION:
141 return (const GLubyte*)s_egl->getGLString(name);
146 ctx->setError(GL_INVALID_ENUM);
155 ctx->m_glEGLImageTargetTexture2DOES_enc = ctx->glEGLImageTargetTexture2DOES;
156 ctx->glEGLImageTargetTexture2DOES = &glEGLImageTargetTexture2DOES;
157 ctx->glEGLImageTargetRenderbufferStorageOES = &glEGLImageTargetRenderbufferStorageOES;
158 ctx->glGetString = &my_glGetString;
162 EGLClient_glesInterface * init_emul_gles(EGLClient_eglInterface *eglIface)
167 s_gl = new EGLClient_glesInterface();
168 s_gl->getProcAddress = getProcAddress;
169 s_gl->finish = finish;