1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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);
}
|