changeset 1519:74635b07a83a

Porting Skia backend to latest version and with X
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 17 May 2011 12:17:15 +0800
parents 80e055978461
children 8bc2e824f155
files configure.ac include/mb_graph_engine_skia.h src/X_supp.c src/graph_engine_skia.cpp
diffstat 4 files changed, 95 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Sat May 14 12:20:57 2011 +0800
+++ b/configure.ac	Tue May 17 12:17:15 2011 +0800
@@ -134,6 +134,7 @@
     X-cairo-*|X-openvg-imlib2|X-openvg-dummy) ;;
     dfb-cairo-*) ;;
     console-openvg-imlib2|console-openvg-dummy) ;;
+    X-skia-imlib2) ;;
     none-*-*) ;;
     *)] AC_MSG_ERROR([The combination of --with-backend=${backend}, --with-graphic-engine=${graphic_engine} and --with-image-loader=${image_loader} is invalid]) [;;
 esac]
@@ -226,9 +227,9 @@
 [fi]
 
 AM_CONDITIONAL([XSHM],
-	[test x"${xshm}" = xtrue -a x"${graphic_engine}" = x"cairo" -a x$backend = x'X'])
+	[test x"${xshm}" = xtrue -a \( x"${graphic_engine}" = x"cairo" -o x"${graphic_engine}" = x"skia" \) -a x$backend = x'X'])
 
-[if [ x"${xshm}" = xtrue -a x"${graphic_engine}" = x"cairo" -a x$backend = x'X' ]; then]
+[if [ x"${xshm}" = xtrue -a \( x"${graphic_engine}" = x"cairo" -o x"${graphic_engine}" = x"skia" \) -a x$backend = x'X' ]; then]
     AC_DEFINE([XSHM])
 [fi]
 
--- a/include/mb_graph_engine_skia.h	Sat May 14 12:20:57 2011 +0800
+++ b/include/mb_graph_engine_skia.h	Tue May 17 12:17:15 2011 +0800
@@ -87,7 +87,8 @@
 extern mbe_font_face_t *mbe_get_font_face(mbe_t *canvas);
 extern void mbe_fill_preserve(mbe_t *canvas);
 extern void mbe_set_source(mbe_t *canvas, mbe_pattern_t *source);
-extern void mbe_reset_clip(mbe_t *canvas);
+extern void mbe_reset_scissoring(mbe_t *canvas);
+extern void mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas);
 extern mbe_surface_t *mbe_get_target(mbe_t *canvas);
 extern void mbe_close_path(mbe_t *canvas);
 extern void mbe_text_path(mbe_t *canvas, const char *txt);
@@ -108,17 +109,25 @@
 extern void mbe_paint(mbe_t *canvas);
 extern void mbe_save(mbe_t *canvas);
 extern void mbe_fill(mbe_t *canvas);
-extern void mbe_clip(mbe_t *canvas);
 
 extern mbe_font_face_t * mbe_query_font_face(const char *family,
 					     int slant, int weight);
 extern void mbe_free_font_face(mbe_font_face_t *face);
 
+extern mbe_pattern_t *mbe_pattern_create_image(mb_img_data_t *img);
 extern void mbe_clear(mbe_t *canvas);
 extern void mbe_copy_source(mbe_t *src, mbe_t *dst);
 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);
+extern mbe_surface_t *mbe_win_surface_create(void *display,
+					     void *drawable,
+					     int fmt,
+					     int width,
+					     int height);
+#define mbe_init()
+#define mbe_flush(canvas)
+
 /* @} */
 
 #endif /* __MB_GE_SKIA_H_ */
--- a/src/X_supp.c	Sat May 14 12:20:57 2011 +0800
+++ b/src/X_supp.c	Tue May 17 12:17:15 2011 +0800
@@ -745,8 +745,8 @@
     XShmAttach(display, shminfo);
 
     switch(depth) {
-    case 24: surf_fmt = CAIRO_FORMAT_RGB24; break;
-    case 32: surf_fmt = CAIRO_FORMAT_ARGB32; break;
+    case 24: surf_fmt = MB_IFMT_RGB24; break;
+    case 32: surf_fmt = MB_IFMT_ARGB32; break;
     }
 
     xmb_rt->backend_surface =
@@ -843,6 +843,7 @@
 				   xmb_rt->win,
 				   fmt,
 				   w, h);
+	ASSERT(xmb_rt->backend_surface != NULL);
     }
 
     xmb_rt->cr = mbe_create(xmb_rt->surface);
--- a/src/graph_engine_skia.cpp	Sat May 14 12:20:57 2011 +0800
+++ b/src/graph_engine_skia.cpp	Tue May 17 12:17:15 2011 +0800
@@ -35,6 +35,7 @@
  * setted.
  */
 #include <stdio.h>
+#include <stdlib.h>
 #include <SkCanvas.h>
 #include <SkBitmap.h>
 #include <SkRegion.h>
@@ -62,6 +63,7 @@
  */
 struct _mbe_pattern_t {
     SkShader *shader;
+    SkBitmap *bitmap;
     int w, h;
     int has_size;
     co_aix matrix[6];
@@ -245,6 +247,7 @@
     }
 
     ptn->has_size = 1;
+    ptn->bitmap = NULL;
     ptn->w = bitmap->width();
     ptn->h = bitmap->height();
 
@@ -291,6 +294,8 @@
 	goto fail;
 
     memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6);
+    
+    ptn->bitmap = NULL;
 
     delete colors;
     delete poses;
@@ -342,6 +347,8 @@
 
     memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6);
 
+    ptn->bitmap = NULL;
+
     delete colors;
     delete poses;
     return ptn;
@@ -364,6 +371,8 @@
 void mbe_pattern_destroy(mbe_pattern_t *ptn) {
     if(ptn->shader)
 	delete ptn->shader;
+    if(ptn->bitmap)
+	delete ptn->bitmap;
     free(ptn);
 }
 
@@ -385,11 +394,9 @@
 
 mbe_surface_t *mbe_image_surface_create_from_png(const char *filename) {}
 
-mbe_surface_t *
-mbe_image_surface_create_for_data(unsigned char *data,
-				  mb_img_fmt_t fmt,
-				  int width, int height,
-				  int stride) {
+static SkBitmap *
+_mbe_bitmap_create_for_data(unsigned char *data, mb_img_fmt_t fmt,
+			    int width, int height, int stride) {
     SkBitmap *bitmap;
     SkBitmap::Config cfg;
 
@@ -418,6 +425,17 @@
     bitmap->setConfig(cfg, width, height, stride);
     bitmap->setPixels(data);
 
+    return bitmap;
+}
+
+mbe_surface_t *
+mbe_image_surface_create_for_data(unsigned char *data,
+				  mb_img_fmt_t fmt,
+				  int width, int height,
+				  int stride) {
+    SkBitmap *bitmap;
+
+    bitmap = _mbe_bitmap_create_for_data(data, fmt, width, height, stride);
     return (mbe_surface_t *)bitmap;
 }
 
@@ -502,8 +520,8 @@
 
     color = ((uint32_t)(alpha * 255)) << 24;
     filter =
-	SkColorFilter::CreatePorterDuffFilter(color,
-					      SkPorterDuff::kSrcOver_Mode);
+	SkColorFilter::CreateModeFilter(color,
+					SkXfermode::kSrcOver_Mode);
     mbe_paint(canvas);
 
 }
@@ -558,7 +576,7 @@
     canvas->states->ptn = source;
 }
 
-void mbe_reset_clip(mbe_t *canvas) {
+void mbe_reset_scissoring(mbe_t *canvas) {
     SkRegion clip;
 
     _canvas_device_region(canvas->canvas, &clip);
@@ -782,6 +800,21 @@
     canvas->subpath->rewind();
 }
 
+void mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) {
+    SkRegion region;
+    area_t *area;
+    co_aix right, bottom;
+    int i;
+
+    for(i = 0; i < n_areas; i++) {
+	area = areas[i];
+	right = area->x + area->w;
+	bottom = area->y + area->h;
+	region.setRect(area->x, area->y, right, bottom);
+	canvas->canvas->clipRegion(region, SkRegion::kIntersect_Op);
+    }
+}
+
 void mbe_clip(mbe_t *canvas) {
     if(!canvas->subpath->isEmpty())
 	_update_path(canvas);
@@ -795,10 +828,37 @@
 					     int slant, int weight) {}
 void mbe_free_font_face(mbe_font_face_t *face) {}
 
+mbe_pattern_t *mbe_pattern_create_image(mb_img_data_t *img) {
+    mbe_pattern_t *ptn;
+    SkBitmap *bitmap;
+
+    bitmap = _mbe_bitmap_create_for_data((unsigned char *)img->content,
+					 img->fmt,
+					 img->w, img->h, img->stride);
+    ptn = (mbe_pattern_t *)malloc(sizeof(mbe_pattern_t));
+    ptn->shader = SkShader::CreateBitmapShader(*bitmap,
+					       SkShader::kClamp_TileMode,
+					       SkShader::kClamp_TileMode);
+    if(ptn->shader == NULL) {
+	free(ptn);
+	delete bitmap;
+	return NULL;
+    }
+
+    ptn->has_size = 1;
+    ptn->w = bitmap->width();
+    ptn->h = bitmap->height();
+    ptn->bitmap = NULL;
+
+    memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6);
+
+    return ptn;
+}
+
 void mbe_clear(mbe_t *canvas) {
     SkColor color = 0;
 
-    canvas->canvas->drawColor(color, SkPorterDuff::kClear_Mode);
+    canvas->canvas->drawColor(color, SkXfermode::kClear_Mode);
 }
 
 void mbe_copy_source(mbe_t *src, mbe_t *dst) {
@@ -807,7 +867,7 @@
     SkXfermode *mode;
 
     /* _prepare_paint(dst, SkPaint::kFill_Style); */
-    mode = SkPorterDuff::CreateXfermode(SkPorterDuff::kSrc_Mode);
+    mode = SkXfermode::Create(SkXfermode::kSrc_Mode);
     paint->setXfermode(mode);
     bmap = &src->canvas->getDevice()->accessBitmap(false);
 
@@ -867,5 +927,13 @@
     }
 }
 
+mbe_surface_t *
+mbe_win_surface_create(void *display, void *drawable,
+		       int fmt, int width, int height) {
+    fprintf(stderr, "%s:%d:mbe_win_surface_create: not implemented!\n",
+	    __FILE__, __LINE__);
+    abort();
+    return NULL;
+}
 
 C_END