comparison src/graph_engine_openvg.c @ 589:d733e198bb25 openvg

Move functions from mb_graph_engine_openvg.h to the C file
author Thinker K.F. Li <thinker@branda.to>
date Wed, 30 Jun 2010 18:06:36 +0800
parents e9923024f65e
children b714f0c9992e
comparison
equal deleted inserted replaced
588:e9923024f65e 589:d733e198bb25
1 #include "mb_graph_engine_openvg.h" 1 #include "mb_graph_engine_openvg.h"
2 2
3 EGLNativeDisplayType _ge_openvg_disp_id = EGL_DEFAULT_DISPLAY; 3 EGLNativeDisplayType _ge_openvg_disp_id = EGL_DEFAULT_DISPLAY;
4 mbe_t *_ge_openvg_current_canvas = NULL; 4 mbe_t *_ge_openvg_current_canvas = NULL;
5
6 #ifndef ASSERT
7 #define ASSERT(x)
8 #endif
5 9
6 void 10 void
7 mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) { 11 mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) {
8 static VGint *coords = NULL; 12 static VGint *coords = NULL;
9 static int coords_sz = 0; 13 static int coords_sz = 0;
29 *coord++ = area->h; 33 *coord++ = area->h;
30 } 34 }
31 35
32 vgSetiv(VG_SCISSOR_RECTS, n_areas * 4, coords); 36 vgSetiv(VG_SCISSOR_RECTS, n_areas * 4, coords);
33 } 37 }
38
39 static int
40 _openvg_find_config(mb_img_fmt_t fmt, int w, int h,
41 EGLConfig *config) {
42 EGLDisplay display;
43 EGLint attrib_list[16];
44 EGLConfig configs[1];
45 EGLint nconfigs;
46 int i = 0;
47 EGLBoolean r;
48
49 switch(fmt) {
50 case MB_IFMT_ARGB32:
51 attrib_list[i++] = EGL_RED_SIZE;
52 attrib_list[i++] = 8;
53 attrib_list[i++] = EGL_GREEN_SIZE;
54 attrib_list[i++] = 8;
55 attrib_list[i++] = EGL_BLUE_SIZE;
56 attrib_list[i++] = 8;
57 attrib_list[i++] = EGL_ALPHA_SIZE;
58 attrib_list[i++] = 8;
59 break;
60
61 case MB_IFMT_RGB24:
62 attrib_list[i++] = EGL_RED_SIZE;
63 attrib_list[i++] = 8;
64 attrib_list[i++] = EGL_GREEN_SIZE;
65 attrib_list[i++] = 8;
66 attrib_list[i++] = EGL_BLUE_SIZE;
67 attrib_list[i++] = 8;
68 break;
69
70 case MB_IFMT_A8:
71 attrib_list[i++] = EGL_ALPHA_SIZE;
72 attrib_list[i++] = 8;
73 break;
74
75 case MB_IFMT_A1:
76 attrib_list[i++] = EGL_ALPHA_SIZE;
77 attrib_list[i++] = 1;
78 break;
79
80 case MB_IFMT_RGB16_565:
81 attrib_list[i++] = EGL_RED_SIZE;
82 attrib_list[i++] = 5;
83 attrib_list[i++] = EGL_GREEN_SIZE;
84 attrib_list[i++] = 6;
85 attrib_list[i++] = EGL_BLUE_SIZE;
86 attrib_list[i++] = 5;
87 break;
88
89 default:
90 return -1;
91 }
92
93 attrib_list[i++] = EGL_SURFACE_TYPE;
94 attrib_list[i++] = EGL_PBUFFER_BIT;
95 #if 0
96 attrib_list[i++] = EGL_MAX_PBUFFER_WIDTH;
97 attrib_list[i++] = w;
98 attrib_list[i++] = EGL_MAX_PBUFFER_HEIGHT;
99 attrib_list[i++] = h;
100 #endif
101
102 attrib_list[i++] = EGL_NONE;
103
104 display = _VG_DISPLAY();
105 r = eglChooseConfig(display, attrib_list, configs, 1, &nconfigs);
106 if(!r)
107 return -1;
108
109 *config = configs[0];
110
111 return 0;
112 }
113
114 #ifdef EGL_GLX
115 #include <X11/Xlib.h>
116 #include <X11/Xutil.h>
117
118 static int
119 _get_img_fmt_from_xvisual(Display *display, Visual *visual) {
120 VisualID visual_id;
121 XVisualInfo temp;
122 XVisualInfo *infos;
123 int n;
124 int fmt = -1;
125
126 visual_id = XVisualIDFromVisual(visual);
127 temp.visualid = visual_id;
128 infos = XGetVisualInfo(display, VisualIDMask, &temp, &n);
129 if(n != 1)
130 return -1;
131
132 switch(infos->depth) {
133 case 32:
134 fmt = MB_IFMT_ARGB32;
135 break;
136
137 case 24:
138 fmt = MB_IFMT_RGB24;
139 break;
140
141 case 16:
142 fmt = MB_IFMT_RGB16_565;
143 break;
144
145 case 8:
146 fmt = MB_IFMT_A8;
147 break;
148
149 case 1:
150 fmt = MB_IFMT_A1;
151 break;
152 }
153
154 return fmt;
155 }
156
157 /*! \brief Create an EGL window surface for X11.
158 *
159 * This function is compiled only for GLX enabled.
160 */
161 mbe_surface_t *
162 mbe_vg_win_surface_create(Display *display, Drawable drawable,
163 Visual *visual, int width, int height) {
164 EGLDisplay egl_disp;
165 EGLSurface egl_surface;
166 mbe_surface_t *surface;
167 EGLConfig config;
168 EGLint attrib_list[2] = {EGL_NONE};
169 int fmt;
170 int r;
171
172 fmt = _get_img_fmt_from_xvisual(display, visual);
173 if(fmt == -1)
174 return NULL;
175
176 r = _openvg_find_config(fmt, width, height, &config);
177 if(r != 0)
178 return NULL;
179
180 egl_disp = eglGetDisplay(display);
181 if(egl_disp == EGL_NO_DISPLAY || egl_disp != _VG_DISPLAY())
182 return NULL;
183
184 egl_surface = eglCreateWindowSurface(egl_disp, config, drawable,
185 attrib_list);
186
187 surface = (mbe_surface_t *)malloc(sizeof(mbe_surface_t));
188 if(surface == NULL) {
189 eglDestroySurface(egl_disp, egl_surface);
190 return NULL;
191 }
192
193 surface->surface = egl_surface;
194
195 return surface;
196 }
197
198 #endif
199
200 mbe_surface_t *
201 mbe_image_surface_create(mb_img_fmt_t fmt, int w, int h) {
202 EGLSurface surface;
203 EGLDisplay display;
204 EGLConfig config;
205 EGLint attrib_list[2] = {EGL_NONE};
206 mbe_surface_t *mbe_surface;
207 int r;
208
209
210 r = _openvg_find_config(fmt, w, h, &config);
211 if(r != 0)
212 return NULL;
213
214 display = _VG_DISPLAY();
215 /* Some implementation does not support pbuffer.
216 * We need use some other surface to replace this one.
217 */
218 surface = eglCreatePbufferSurface(display, config, attrib_list);
219 if(surface == EGL_NO_SURFACE)
220 return NULL;
221
222 mbe_surface = (mbe_surface_t *)malloc(sizeof(mbe_surface_t));
223 if(mbe_surface == NULL)
224 return NULL;
225 mbe_surface->surface = surface;
226 mbe_surface->asso_mbe = NULL;
227
228 return mbe_surface;
229 }
230
231 mbe_t *
232 mbe_create(mbe_surface_t *surface) {
233 EGLDisplay display;
234 EGLConfig config;
235 EGLContext ctx, shared;
236 EGLint attrib_list[2] = {EGL_NONE};
237 mbe_t *canvas;
238
239 display = _VG_DISPLAY();
240 ctx = eglCreateContext(display, config, shared, attrib_list);
241 if(ctx == EGL_NO_CONTEXT)
242 return NULL;
243
244 canvas = (mbe_t *)malloc(sizeof(mbe_t));
245 if(canvas == NULL)
246 return NULL;
247
248 canvas->src = NULL;
249 canvas->tgt = surface;
250 canvas->ctx = ctx;
251
252 return canvas;
253 }