changeset 630:bd18951b51d5 openvg

Add initial code for graphic engines
author Thinker K.F. Li <thinker@branda.to>
date Mon, 19 Jul 2010 15:44:49 +0800
parents 608f58b9b84d
children 7b4e80ab671a
files include/mb_graph_engine_cairo.h include/mb_graph_engine_dummy.h include/mb_graph_engine_openvg.h include/mb_graph_engine_skia.h src/X_supp.c src/graph_engine_openvg.c
diffstat 6 files changed, 50 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/include/mb_graph_engine_cairo.h	Sat Jul 17 21:44:23 2010 +0800
+++ b/include/mb_graph_engine_cairo.h	Mon Jul 19 15:44:49 2010 +0800
@@ -50,6 +50,7 @@
 #define mbe_paint cairo_paint
 #define mbe_save cairo_save
 #define mbe_fill cairo_fill
+#define mbe_init()
 
 typedef cairo_text_extents_t mbe_text_extents_t;
 typedef cairo_scaled_font_t mbe_scaled_font_t;
--- a/include/mb_graph_engine_dummy.h	Sat Jul 17 21:44:23 2010 +0800
+++ b/include/mb_graph_engine_dummy.h	Mon Jul 19 15:44:49 2010 +0800
@@ -75,6 +75,9 @@
 #define mbe_scissoring(canvas, n_areas, areas)
 #define mbe_arc(canvas, x, y, radius, angle_start, angle_stop)
 
+/*! \brief Initialize graphic engine */
+#define mbe_init()
+
 typedef struct _mbe_text_extents_t mbe_text_extents_t;
 typedef int mbe_scaled_font_t;
 typedef int mbe_font_face_t;
--- a/include/mb_graph_engine_openvg.h	Sat Jul 17 21:44:23 2010 +0800
+++ b/include/mb_graph_engine_openvg.h	Mon Jul 19 15:44:49 2010 +0800
@@ -244,6 +244,7 @@
 extern void mbe_paint_with_alpha(mbe_t *canvas, co_comp_t alpha);
 extern void mbe_paint(mbe_t *canvas);
 extern void mbe_clear(mbe_t *canvas);
+extern void mbe_init();
 
 static void
 mbe_stroke(mbe_t *canvas) {
@@ -273,7 +274,6 @@
     mbe_fill_preserve(canvas);
     vgClearPath(canvas->path, VG_PATH_CAPABILITY_ALL);
 }
-
 /* @} */
 
 #endif /* __MB_GE_OPENVG_H_ */
--- a/include/mb_graph_engine_skia.h	Sat Jul 17 21:44:23 2010 +0800
+++ b/include/mb_graph_engine_skia.h	Mon Jul 19 15:44:49 2010 +0800
@@ -108,6 +108,7 @@
 extern void mbe_transform(mbe_t *mbe, co_aix matrix[6]);
 extern void mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius,
 		    co_aix angle_start, co_aix angle_stop);
+#define mbe_init()
 /* @} */
 
 #endif /* __MB_GE_SKIA_H_ */
--- a/src/X_supp.c	Sat Jul 17 21:44:23 2010 +0800
+++ b/src/X_supp.c	Mon Jul 19 15:44:49 2010 +0800
@@ -468,6 +468,11 @@
     xmb_rt->h = h;
     X_init_connection(display_name, w, h, &xmb_rt->display,
 		      &xmb_rt->visual, &xmb_rt->win);
+#ifdef OPENVG_GRAPH_ENGINE
+    _ge_openvg_disp_id = xmb_rt->display;
+#endif
+
+    mbe_init();
 
     xmb_rt->surface =
 	mbe_image_surface_create(MB_IFMT_ARGB32, w, h);
--- a/src/graph_engine_openvg.c	Sat Jul 17 21:44:23 2010 +0800
+++ b/src/graph_engine_openvg.c	Mon Jul 19 15:44:49 2010 +0800
@@ -474,6 +474,9 @@
     attrib_list[i++] = EGL_MAX_PBUFFER_HEIGHT;
     attrib_list[i++] = h;
 #endif
+
+    attrib_list[i++] = EGL_RENDERABLE_TYPE;
+    attrib_list[i++] = EGL_OPENVG_BIT;
     
     attrib_list[i++] = EGL_NONE;
     
@@ -800,3 +803,39 @@
     /* Clear regions to the color specified by mbe_create() */
     vgClear(0, 0, w, h);
 }
+
+void mbe_init() {
+    static EGLContext init_ctx;
+    static EGLSurface init_surf;
+    EGLDisplay display;
+    EGLConfig config;
+    EGLint nconfigs;
+    EGLint attrib_list[] = {
+	EGL_RED_SIZE, 1,
+	EGL_GREEN_SIZE, 1,
+	EGL_BLUE_SIZE, 1,
+	EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
+	EGL_NONE};
+    EGLint surf_attribs[] = {
+	EGL_WIDTH, 1,
+	EGL_HEIGHT, 1,
+	EGL_NONE};
+    EGLBoolean r;
+
+    display = _VG_DISPLAY();
+    eglInitialize(display, NULL, NULL);
+
+    r = eglChooseConfig(display, attrib_list, &config, 1, &nconfigs);
+    ASSERT(r);
+    
+    eglBindAPI(EGL_OPENVG_API);
+
+    init_ctx = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
+    ASSERT(init_ctx != EGL_NO_CONTEXT);
+
+    init_surf = eglCreatePbufferSurface(display, config, surf_attribs);
+    ASSERT(init_surf != EGL_NO_SURFACE);
+    
+    eglMakeCurrent(display, init_surf, init_surf, init_ctx);
+}
+