comparison include/mb_graph_engine_openvg.h @ 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
139 _MK_CURRENT_CTX(canvas); 139 _MK_CURRENT_CTX(canvas);
140 MB_MATRIX_2_OPENVG(vg_mtx, mtx); 140 MB_MATRIX_2_OPENVG(vg_mtx, mtx);
141 vgLoadMatrix(vg_mtx); 141 vgLoadMatrix(vg_mtx);
142 } 142 }
143 143
144 static int
145 _openvg_find_confg(mb_img_fmt_t fmt, int w, int h,
146 EGLConfig *config) {
147 EGLDisplay display;
148 EGLint attrib_list[16];
149 EGLConfig configs[1];
150 EGLint nconfigs;
151 int i = 0;
152 EGLBoolean r;
153
154 switch(fmt) {
155 case MB_IFMT_ARGB32:
156 attrib_list[i++] = EGL_RED_SIZE;
157 attrib_list[i++] = 8;
158 attrib_list[i++] = EGL_GREEN_SIZE;
159 attrib_list[i++] = 8;
160 attrib_list[i++] = EGL_BLUE_SIZE;
161 attrib_list[i++] = 8;
162 attrib_list[i++] = EGL_ALPHA_SIZE;
163 attrib_list[i++] = 8;
164 break;
165
166 case MB_IFMT_RGB24:
167 attrib_list[i++] = EGL_RED_SIZE;
168 attrib_list[i++] = 8;
169 attrib_list[i++] = EGL_GREEN_SIZE;
170 attrib_list[i++] = 8;
171 attrib_list[i++] = EGL_BLUE_SIZE;
172 attrib_list[i++] = 8;
173 break;
174
175 case MB_IFMT_A8:
176 attrib_list[i++] = EGL_ALPHA_SIZE;
177 attrib_list[i++] = 8;
178 break;
179
180 case MB_IFMT_A1:
181 attrib_list[i++] = EGL_ALPHA_SIZE;
182 attrib_list[i++] = 1;
183 break;
184
185 case MB_IFMT_RGB16_565:
186 attrib_list[i++] = EGL_RED_SIZE;
187 attrib_list[i++] = 5;
188 attrib_list[i++] = EGL_GREEN_SIZE;
189 attrib_list[i++] = 6;
190 attrib_list[i++] = EGL_BLUE_SIZE;
191 attrib_list[i++] = 5;
192 break;
193
194 default:
195 return -1;
196 }
197
198 attrib_list[i++] = EGL_SURFACE_TYPE;
199 attrib_list[i++] = EGL_PBUFFER_BIT;
200 #if 0
201 attrib_list[i++] = EGL_MAX_PBUFFER_WIDTH;
202 attrib_list[i++] = w;
203 attrib_list[i++] = EGL_MAX_PBUFFER_HEIGHT;
204 attrib_list[i++] = h;
205 #endif
206
207 attrib_list[i++] = EGL_NONE;
208
209 display = _VG_DISPLAY();
210 r = eglChooseConfig(display, attrib_list, configs, 1, &nconfigs);
211 if(!r)
212 return -1;
213
214 *config = configs[0];
215
216 return 0;
217 }
218
219 #define EGL_GLX 1 144 #define EGL_GLX 1
220 #ifdef EGL_GLX 145 #ifdef EGL_GLX
221 #include <X11/Xlib.h> 146 #include <X11/Xlib.h>
222 #include <X11/Xutil.h> 147 #include <X11/Xutil.h>
223 148
224 static int 149 extern mbe_surface_t *mbe_vg_win_surface_create(Display *display,
225 _get_img_fmt_from_xvisual(Display *display, Visual *visual) { 150 Drawable drawable,
226 VisualID visual_id; 151 Visual *visual,
227 XVisualInfo temp; 152 int width, int height);
228 XVisualInfo *infos;
229 int n;
230 int fmt = -1;
231
232 visual_id = XVisualIDFromVisual(visual);
233 temp.visualid = visual_id;
234 infos = XGetVisualInfo(display, VisualIDMask, &temp, &n);
235 if(n != 1)
236 return -1;
237
238 switch(infos->depth) {
239 case 32:
240 fmt = MB_IFMT_ARGB32;
241 break;
242
243 case 24:
244 fmt = MB_IFMT_RGB24;
245 break;
246
247 case 16:
248 fmt = MB_IFMT_RGB16_565;
249 break;
250
251 case 8:
252 fmt = MB_IFMT_A8;
253 break;
254
255 case 1:
256 fmt = MB_IFMT_A1;
257 break;
258 }
259
260 return fmt;
261 }
262
263 /*! \brief Create an EGL window surface for X11.
264 *
265 * This function is compiled only for GLX enabled.
266 */
267 static mbe_surface_t *
268 mbe_vg_win_surface_create(Display *display, Drawable drawable,
269 Visual *visual, int width, int height) {
270 EGLDisplay egl_disp;
271 EGLSurface egl_surface;
272 mbe_surface_t *surface;
273 EGLConfig config;
274 EGLint attrib_list[2] = {EGL_NONE};
275 int fmt;
276 int r;
277
278 fmt = _get_img_fmt_from_xvisual(display, visual);
279 if(fmt == -1)
280 return NULL;
281
282 r = _openvg_find_confg(fmt, width, height, &config);
283 if(r != 0)
284 return NULL;
285
286 egl_disp = eglGetDisplay(display);
287 if(egl_disp == EGL_NO_DISPLAY || egl_disp != _VG_DISPLAY())
288 return NULL;
289
290 egl_surface = eglCreateWindowSurface(egl_disp, config, drawable,
291 attrib_list);
292
293 surface = (mbe_surface_t *)malloc(sizeof(mbe_surface_t));
294 if(surface == NULL) {
295 eglDestroySurface(egl_disp, egl_surface);
296 return NULL;
297 }
298
299 surface->surface = egl_surface;
300
301 return surface;
302 }
303
304 #endif 153 #endif
305 154
306 static mbe_surface_t * 155 extern mbe_surface_t *mbe_image_surface_create(mb_img_fmt_t fmt,
307 mbe_image_surface_create(mb_img_fmt_t fmt, int w, int h) { 156 int w, int h);
308 EGLSurface surface;
309 EGLDisplay display;
310 EGLConfig config;
311 EGLint attrib_list[2] = {EGL_NONE};
312 mbe_surface_t *mbe_surface;
313 int r;
314
315
316 r = _openvg_find_confg(fmt, w, h, &config);
317 if(r != 0)
318 return NULL;
319
320 display = _VG_DISPLAY();
321 /* Some implementation does not support pbuffer.
322 * We need use some other surface to replace this one.
323 */
324 surface = eglCreatePbufferSurface(display, config, attrib_list);
325 if(surface == EGL_NO_SURFACE)
326 return NULL;
327
328 mbe_surface = (mbe_surface_t *)malloc(sizeof(mbe_surface_t));
329 if(mbe_surface == NULL)
330 return NULL;
331 mbe_surface->surface = surface;
332 mbe_surface->asso_mbe = NULL;
333
334 return mbe_surface;
335 }
336 157
337 static void 158 static void
338 mbe_surface_destroy(mbe_surface_t *surface) { 159 mbe_surface_destroy(mbe_surface_t *surface) {
339 EGLDisplay display; 160 EGLDisplay display;
340 161
345 surface->asso_mbe->tgt = NULL; 166 surface->asso_mbe->tgt = NULL;
346 167
347 free(surface); 168 free(surface);
348 } 169 }
349 170
350 static mbe_t * 171 extern mbe_t *mbe_create(mbe_surface_t *surface);
351 mbe_create(mbe_surface_t *surface) {
352 EGLDisplay display;
353 EGLConfig config;
354 EGLContext ctx, shared;
355 EGLint attrib_list[2] = {EGL_NONE};
356 mbe_t *canvas;
357
358 display = _VG_DISPLAY();
359 ctx = eglCreateContext(display, config, shared, attrib_list);
360 if(ctx == EGL_NO_CONTEXT)
361 return NULL;
362
363 canvas = (mbe_t *)malloc(sizeof(mbe_t));
364 if(canvas == NULL)
365 return NULL;
366
367 canvas->src = NULL;
368 canvas->tgt = surface;
369 canvas->ctx = ctx;
370
371 return canvas;
372 }
373 172
374 /* @} */ 173 /* @} */
375 174
376 #endif /* __MB_GE_OPENVG_H_ */ 175 #endif /* __MB_GE_OPENVG_H_ */