summaryrefslogtreecommitdiff
path: root/es_2_0/EGLImage.c
diff options
context:
space:
mode:
Diffstat (limited to 'es_2_0/EGLImage.c')
-rwxr-xr-xes_2_0/EGLImage.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/es_2_0/EGLImage.c b/es_2_0/EGLImage.c
new file mode 100755
index 0000000..07d0631
--- /dev/null
+++ b/es_2_0/EGLImage.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Edwin Zhai <edwin.zhai@intel.com>
+ * SangJin Kim <sangjin3.kim@samsung.com>
+ * Yeongkyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunGoo Kang <hyungoo1.kang@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Contributors:
+ * - Intel Corporation
+ * - S-Core Co., Ltd
+ *
+ */
+
+ /*
+ * EGLImage.c
+ *
+ */
+#include "es2front.h"
+#include <EGL/egl.h>
+#include <GLES2/gl2ext.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <dlfcn.h>
+
+//#define EGL_SO_FILENAME "libEGL.so"
+#define EGL_SO_FILENAME "/usr/lib/host-gl/libEGL.so.1.0"
+#define EGLCROSS_PREFIX "__hazel_cross__"
+
+void* g_dlhandle_egl = NULL;
+
+void GL_APIENTRY ES2ENTRY(EGLImageTargetTexture2DOES) (GLenum target,
+ GLeglImageOES image) {
+
+ int width, height, depth;
+ EGLNativeDisplayType dpy;
+ Pixmap pixmap;
+ XImage *img;
+
+ int (*fpGetEGLImagePixmapInfo)(void *eglimg,
+ EGLNativeDisplayType *dpy,
+ Pixmap *pixmap,
+ int *width, int *height, int *depth) = NULL;
+
+ if (g_dlhandle_egl == NULL) {
+ if ((g_dlhandle_egl = dlopen(EGL_SO_FILENAME, RTLD_NOW | RTLD_GLOBAL)) == NULL) {
+ ES2INTER(SetError)(GL_INVALID_OPERATION);
+ return;
+ }
+ }
+
+ fpGetEGLImagePixmapInfo = dlsym(g_dlhandle_egl, EGLCROSS_PREFIX "GetEGLImagePixmapInfo");
+ if (fpGetEGLImagePixmapInfo != NULL) {
+ (*fpGetEGLImagePixmapInfo)(image, &dpy, &pixmap, &width, &height, &depth);
+ }
+
+ fprintf (stderr, "EGLImage: glEGLImageTargetTexture2DOES () was called!\n");
+ fprintf (stderr, "======== target = 0x%x\n", (unsigned int)target);
+ fprintf (stderr, "======== image = 0x%x\n", (unsigned int)image);
+ fprintf (stderr, "======== width = 0x%x\n", (unsigned int)width);
+ fprintf (stderr, "======== height = 0x%x\n", (unsigned int)height);
+ fprintf (stderr, "======== depth = 0x%x\n", (unsigned int)depth);
+
+ /* EGLImageTargetTexture2DOES support 2D rendering results in the
+ * xpixmap as texture, so firstly TexImage2D then trap into host, where
+ * the 2D & 3D rendering need to be combined as texture
+ */
+
+ img = XGetImage ((Display*)dpy, pixmap, 0, 0, width, height, AllPlanes, ZPixmap);
+ if (img == NULL) {
+ fprintf (stderr, "EGLImage: Failed to get pixmap image!\n");
+ }
+
+ /* 2D rendering from Xlib doesn't produce alpha channel. Make a
+ * option(default off) to add alpha as 0xff for each pixel with
+ * possible performance drop */
+//#define FILL_IN_ALPHA
+#ifdef FILL_IN_ALPHA
+ /* Add alpha channel if needed, as Xlib rendering doesn't produce it */
+ if ( img->bits_per_pixel == 32 )
+ {
+ int x, y;
+ for ( y = 0; y < img->height; y++ )
+ for ( x = 0; x < img->width; x++ )
+ {
+ char* pixel = img->data +
+ y * img->bytes_per_line +
+ x * (img->bits_per_pixel / 8);
+ pixel[3] = 0xff;
+ }
+ }
+#endif
+
+/* pixels in 2D rendering results is BGR format, which is not in the
+ * header of gles. XXX:Need generic method to detect the RBG format and
+ * alpha, like DefaultVisual */
+#ifndef GL_BGRA
+#define GL_BGRA 0x80E1
+#endif
+ FNPTR(TexImage2D)(target, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, img->data);
+
+ XDestroyImage (img);
+
+ FNPTR(EGLImageTargetTexture2DOES)(target, pixmap);
+}