Mercurial > MadButterfly
comparison src/redraw_man.c @ 448:16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
mb_graph_engine is a layer to separate MadButterfly from Cairo.
It is only a set of macro mapping to cairo implementation, now.
But, it provides a oppotunities to replace cairo with other engines;
likes skia.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 04 Aug 2009 23:35:41 +0800 |
parents | 94477e7d981e |
children | a417fd980228 |
comparison
equal
deleted
inserted
replaced
447:38aae921243f | 448:16116d84bc5e |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <string.h> | 3 #include <string.h> |
4 #include <math.h> | 4 #include <math.h> |
5 #include <cairo.h> | 5 #include "mb_graph_engine.h" |
6 #include "mb_types.h" | 6 #include "mb_types.h" |
7 #include "mb_shapes.h" | 7 #include "mb_shapes.h" |
8 #include "mb_tools.h" | 8 #include "mb_tools.h" |
9 #include "mb_redraw_man.h" | 9 #include "mb_redraw_man.h" |
10 #include "mb_observer.h" | 10 #include "mb_observer.h" |
328 | 328 |
329 #ifdef UNITTEST | 329 #ifdef UNITTEST |
330 typedef struct _sh_dummy sh_dummy_t; | 330 typedef struct _sh_dummy sh_dummy_t; |
331 | 331 |
332 extern void sh_dummy_transform(shape_t *shape); | 332 extern void sh_dummy_transform(shape_t *shape); |
333 extern void sh_dummy_fill(shape_t *, cairo_t *); | 333 extern void sh_dummy_fill(shape_t *, mbe_t *); |
334 #endif /* UNITTEST */ | 334 #endif /* UNITTEST */ |
335 | 335 |
336 static subject_t *ob_subject_alloc(ob_factory_t *factory); | 336 static subject_t *ob_subject_alloc(ob_factory_t *factory); |
337 static void ob_subject_free(ob_factory_t *factory, subject_t *subject); | 337 static void ob_subject_free(ob_factory_t *factory, subject_t *subject); |
338 static observer_t *ob_observer_alloc(ob_factory_t *factory); | 338 static observer_t *ob_observer_alloc(ob_factory_t *factory); |
505 free(rdman->free_objs.objs); | 505 free(rdman->free_objs.objs); |
506 } | 506 } |
507 | 507 |
508 | 508 |
509 | 509 |
510 static cairo_t *canvas_new(int w, int h) { | 510 static mbe_t *canvas_new(int w, int h) { |
511 #ifndef UNITTEST | 511 #ifndef UNITTEST |
512 cairo_surface_t *surface; | 512 mbe_surface_t *surface; |
513 cairo_t *cr; | 513 mbe_t *cr; |
514 | 514 |
515 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, | 515 surface = mbe_image_surface_create(CAIRO_FORMAT_ARGB32, |
516 w, h); | 516 w, h); |
517 cr = cairo_create(surface); | 517 cr = mbe_create(surface); |
518 | 518 |
519 return cr; | 519 return cr; |
520 #else | 520 #else |
521 return NULL; | 521 return NULL; |
522 #endif | 522 #endif |
523 } | 523 } |
524 | 524 |
525 static void canvas_free(cairo_t *canvas) { | 525 static void canvas_free(mbe_t *canvas) { |
526 #ifndef UNITTEST | 526 #ifndef UNITTEST |
527 cairo_destroy(canvas); | 527 mbe_destroy(canvas); |
528 #endif | 528 #endif |
529 } | 529 } |
530 | 530 |
531 static void canvas_get_size(cairo_t *canvas, int *w, int *h) { | 531 static void canvas_get_size(mbe_t *canvas, int *w, int *h) { |
532 #ifndef UNITTEST | 532 #ifndef UNITTEST |
533 cairo_surface_t *surface; | 533 mbe_surface_t *surface; |
534 | 534 |
535 surface = cairo_get_target(canvas); | 535 surface = mbe_get_target(canvas); |
536 *w = cairo_image_surface_get_width(surface); | 536 *w = mbe_image_surface_get_width(surface); |
537 *h = cairo_image_surface_get_height(surface); | 537 *h = mbe_image_surface_get_height(surface); |
538 #else | 538 #else |
539 *w = 0; | 539 *w = 0; |
540 *h = 0; | 540 *h = 0; |
541 #endif | 541 #endif |
542 } | 542 } |
574 coord->num_members--; | 574 coord->num_members--; |
575 } | 575 } |
576 | 576 |
577 static coord_canvas_info_t *coord_canvas_info_new(redraw_man_t *rdman, | 577 static coord_canvas_info_t *coord_canvas_info_new(redraw_man_t *rdman, |
578 coord_t *coord, | 578 coord_t *coord, |
579 cairo_t *canvas) { | 579 mbe_t *canvas) { |
580 coord_canvas_info_t *info; | 580 coord_canvas_info_t *info; |
581 | 581 |
582 info = (coord_canvas_info_t *)elmpool_elm_alloc(rdman->coord_canvas_pool); | 582 info = (coord_canvas_info_t *)elmpool_elm_alloc(rdman->coord_canvas_pool); |
583 if(info == NULL) | 583 if(info == NULL) |
584 return info; | 584 return info; |
597 } | 597 } |
598 | 598 |
599 static void mouse_event_root_dummy(event_t *evt, void *arg) { | 599 static void mouse_event_root_dummy(event_t *evt, void *arg) { |
600 } | 600 } |
601 | 601 |
602 int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, cairo_t *backend) { | 602 int redraw_man_init(redraw_man_t *rdman, mbe_t *cr, mbe_t *backend) { |
603 extern void redraw_man_destroy(redraw_man_t *rdman); | 603 extern void redraw_man_destroy(redraw_man_t *rdman); |
604 extern int _paint_color_size; | 604 extern int _paint_color_size; |
605 observer_t *addrm_ob; | 605 observer_t *addrm_ob; |
606 extern void addrm_monitor_hdlr(event_t *evt, void *arg); | 606 extern void addrm_monitor_hdlr(event_t *evt, void *arg); |
607 | 607 |
1351 co_aix min_x, min_y; | 1351 co_aix min_x, min_y; |
1352 co_aix max_x, max_y; | 1352 co_aix max_x, max_y; |
1353 co_aix x, y; | 1353 co_aix x, y; |
1354 int w, h; | 1354 int w, h; |
1355 int c_w, c_h; | 1355 int c_w, c_h; |
1356 cairo_t *canvas; | 1356 mbe_t *canvas; |
1357 co_aix *aggr; | 1357 co_aix *aggr; |
1358 co_aix poses[2][2]; | 1358 co_aix poses[2][2]; |
1359 | 1359 |
1360 if(coord->parent == NULL) /*! \note Should not zeroing root coord */ | 1360 if(coord->parent == NULL) /*! \note Should not zeroing root coord */ |
1361 abort(); | 1361 abort(); |
1780 /* Drawing and Redrawing | 1780 /* Drawing and Redrawing |
1781 * ============================================================ | 1781 * ============================================================ |
1782 */ | 1782 */ |
1783 | 1783 |
1784 #ifndef UNITTEST | 1784 #ifndef UNITTEST |
1785 static void set_shape_stroke_param(shape_t *shape, cairo_t *cr) { | 1785 static void set_shape_stroke_param(shape_t *shape, mbe_t *cr) { |
1786 cairo_set_line_width(cr, shape->stroke_width); | 1786 mbe_set_line_width(cr, shape->stroke_width); |
1787 } | 1787 } |
1788 | 1788 |
1789 static void fill_path_preserve(redraw_man_t *rdman) { | 1789 static void fill_path_preserve(redraw_man_t *rdman) { |
1790 cairo_fill_preserve(rdman->cr); | 1790 mbe_fill_preserve(rdman->cr); |
1791 } | 1791 } |
1792 | 1792 |
1793 static void fill_path(redraw_man_t *rdman) { | 1793 static void fill_path(redraw_man_t *rdman) { |
1794 cairo_fill(rdman->cr); | 1794 mbe_fill(rdman->cr); |
1795 } | 1795 } |
1796 | 1796 |
1797 static void stroke_path(redraw_man_t *rdman) { | 1797 static void stroke_path(redraw_man_t *rdman) { |
1798 cairo_stroke(rdman->cr); | 1798 mbe_stroke(rdman->cr); |
1799 } | 1799 } |
1800 #else | 1800 #else |
1801 static void set_shape_stroke_param(shape_t *shape, cairo_t *cr) { | 1801 static void set_shape_stroke_param(shape_t *shape, mbe_t *cr) { |
1802 } | 1802 } |
1803 | 1803 |
1804 static void fill_path_preserve(redraw_man_t *rdman) { | 1804 static void fill_path_preserve(redraw_man_t *rdman) { |
1805 } | 1805 } |
1806 | 1806 |
1809 | 1809 |
1810 static void stroke_path(redraw_man_t *rdman) { | 1810 static void stroke_path(redraw_man_t *rdman) { |
1811 } | 1811 } |
1812 #endif | 1812 #endif |
1813 | 1813 |
1814 static void draw_shape(redraw_man_t *rdman, cairo_t *cr, shape_t *shape) { | 1814 static void draw_shape(redraw_man_t *rdman, mbe_t *cr, shape_t *shape) { |
1815 paint_t *fill, *stroke; | 1815 paint_t *fill, *stroke; |
1816 | 1816 |
1817 /*! \todo Move operator of shapes into singleton structures that define | 1817 /*! \todo Move operator of shapes into singleton structures that define |
1818 * operators for them. | 1818 * operators for them. |
1819 */ | 1819 */ |
1863 } | 1863 } |
1864 } | 1864 } |
1865 | 1865 |
1866 #ifndef UNITTEST | 1866 #ifndef UNITTEST |
1867 static void clear_canvas(canvas_t *canvas) { | 1867 static void clear_canvas(canvas_t *canvas) { |
1868 cairo_operator_t old_op; | 1868 mbe_operator_t old_op; |
1869 | 1869 |
1870 old_op = cairo_get_operator(canvas); | 1870 old_op = mbe_get_operator(canvas); |
1871 cairo_set_operator(canvas, CAIRO_OPERATOR_CLEAR); | 1871 mbe_set_operator(canvas, CAIRO_OPERATOR_CLEAR); |
1872 cairo_paint(canvas); | 1872 mbe_paint(canvas); |
1873 cairo_set_operator(canvas, old_op); | 1873 mbe_set_operator(canvas, old_op); |
1874 } | 1874 } |
1875 | 1875 |
1876 static void make_clip(cairo_t *cr, int n_dirty_areas, | 1876 static void make_clip(mbe_t *cr, int n_dirty_areas, |
1877 area_t **dirty_areas) { | 1877 area_t **dirty_areas) { |
1878 int i; | 1878 int i; |
1879 area_t *area; | 1879 area_t *area; |
1880 | 1880 |
1881 cairo_new_path(cr); | 1881 mbe_new_path(cr); |
1882 for(i = 0; i < n_dirty_areas; i++) { | 1882 for(i = 0; i < n_dirty_areas; i++) { |
1883 area = dirty_areas[i]; | 1883 area = dirty_areas[i]; |
1884 cairo_rectangle(cr, area->x, area->y, area->w, area->h); | 1884 mbe_rectangle(cr, area->x, area->y, area->w, area->h); |
1885 } | 1885 } |
1886 cairo_clip(cr); | 1886 mbe_clip(cr); |
1887 } | 1887 } |
1888 | 1888 |
1889 static void reset_clip(canvas_t *cr) { | 1889 static void reset_clip(canvas_t *cr) { |
1890 cairo_reset_clip(cr); | 1890 mbe_reset_clip(cr); |
1891 } | 1891 } |
1892 | 1892 |
1893 static void copy_cr_2_backend(redraw_man_t *rdman, int n_dirty_areas, | 1893 static void copy_cr_2_backend(redraw_man_t *rdman, int n_dirty_areas, |
1894 area_t **dirty_areas) { | 1894 area_t **dirty_areas) { |
1895 cairo_operator_t saved_op; | 1895 mbe_operator_t saved_op; |
1896 | 1896 |
1897 if(n_dirty_areas) | 1897 if(n_dirty_areas) |
1898 make_clip(rdman->backend, n_dirty_areas, dirty_areas); | 1898 make_clip(rdman->backend, n_dirty_areas, dirty_areas); |
1899 | 1899 |
1900 saved_op = cairo_get_operator(rdman->backend); | 1900 saved_op = mbe_get_operator(rdman->backend); |
1901 cairo_set_operator(rdman->backend, CAIRO_OPERATOR_SOURCE); | 1901 mbe_set_operator(rdman->backend, CAIRO_OPERATOR_SOURCE); |
1902 cairo_paint(rdman->backend); | 1902 mbe_paint(rdman->backend); |
1903 cairo_set_operator(rdman->backend, saved_op); | 1903 mbe_set_operator(rdman->backend, saved_op); |
1904 } | 1904 } |
1905 #else /* UNITTEST */ | 1905 #else /* UNITTEST */ |
1906 static void make_clip(cairo_t *cr, int n_dirty_areas, | 1906 static void make_clip(mbe_t *cr, int n_dirty_areas, |
1907 area_t **dirty_areas) { | 1907 area_t **dirty_areas) { |
1908 } | 1908 } |
1909 | 1909 |
1910 static void clear_canvas(canvas_t *canvas) { | 1910 static void clear_canvas(canvas_t *canvas) { |
1911 } | 1911 } |
1918 } | 1918 } |
1919 #endif /* UNITTEST */ | 1919 #endif /* UNITTEST */ |
1920 | 1920 |
1921 static void update_cached_canvas_2_parent(redraw_man_t *rdman, | 1921 static void update_cached_canvas_2_parent(redraw_man_t *rdman, |
1922 coord_t *coord) { | 1922 coord_t *coord) { |
1923 cairo_t *pcanvas, *canvas; | 1923 mbe_t *pcanvas, *canvas; |
1924 cairo_surface_t *surface; | 1924 mbe_surface_t *surface; |
1925 cairo_pattern_t *pattern; | 1925 mbe_pattern_t *pattern; |
1926 cairo_matrix_t cr_matrix; | 1926 mbe_matrix_t cr_matrix; |
1927 co_aix reverse[6]; | 1927 co_aix reverse[6]; |
1928 co_aix canvas2pdev_matrix[6]; | 1928 co_aix canvas2pdev_matrix[6]; |
1929 | 1929 |
1930 if(coord_is_root(coord)) | 1930 if(coord_is_root(coord)) |
1931 return; | 1931 return; |
1940 cr_matrix.yy = reverse[4]; | 1940 cr_matrix.yy = reverse[4]; |
1941 cr_matrix.y0 = reverse[5]; | 1941 cr_matrix.y0 = reverse[5]; |
1942 | 1942 |
1943 canvas = _coord_get_canvas(coord); | 1943 canvas = _coord_get_canvas(coord); |
1944 pcanvas = _coord_get_canvas(coord->parent); | 1944 pcanvas = _coord_get_canvas(coord->parent); |
1945 surface = cairo_get_target(canvas); | 1945 surface = mbe_get_target(canvas); |
1946 pattern = cairo_pattern_create_for_surface(surface); | 1946 pattern = mbe_pattern_create_for_surface(surface); |
1947 cairo_pattern_set_matrix(pattern, &cr_matrix); | 1947 mbe_pattern_set_matrix(pattern, &cr_matrix); |
1948 cairo_set_source(pcanvas, pattern); | 1948 mbe_set_source(pcanvas, pattern); |
1949 cairo_paint_with_alpha(pcanvas, coord->opacity); | 1949 mbe_paint_with_alpha(pcanvas, coord->opacity); |
1950 } | 1950 } |
1951 | 1951 |
1952 static int draw_coord_shapes_in_dirty_areas(redraw_man_t *rdman, | 1952 static int draw_coord_shapes_in_dirty_areas(redraw_man_t *rdman, |
1953 coord_t *coord) { | 1953 coord_t *coord) { |
1954 int dirty = 0; | 1954 int dirty = 0; |
1955 int r; | 1955 int r; |
1956 area_t **areas; | 1956 area_t **areas; |
1957 int n_areas; | 1957 int n_areas; |
1958 cairo_t *canvas; | 1958 mbe_t *canvas; |
1959 geo_t *member; | 1959 geo_t *member; |
1960 coord_t *child; | 1960 coord_t *child; |
1961 int mem_idx; | 1961 int mem_idx; |
1962 | 1962 |
1963 if(coord->flags & COF_HIDDEN) | 1963 if(coord->flags & COF_HIDDEN) |
2001 | 2001 |
2002 static int draw_dirty_cached_coord(redraw_man_t *rdman, | 2002 static int draw_dirty_cached_coord(redraw_man_t *rdman, |
2003 coord_t *coord) { | 2003 coord_t *coord) { |
2004 area_t **areas, *area; | 2004 area_t **areas, *area; |
2005 int n_areas; | 2005 int n_areas; |
2006 cairo_t *canvas; | 2006 mbe_t *canvas; |
2007 int i; | 2007 int i; |
2008 int r; | 2008 int r; |
2009 | 2009 |
2010 areas = _coord_get_dirty_areas(coord)->ds; | 2010 areas = _coord_get_dirty_areas(coord)->ds; |
2011 n_areas = _coord_get_dirty_areas(coord)->num; | 2011 n_areas = _coord_get_dirty_areas(coord)->num; |
2127 */ | 2127 */ |
2128 | 2128 |
2129 int rdman_redraw_all(redraw_man_t *rdman) { | 2129 int rdman_redraw_all(redraw_man_t *rdman) { |
2130 area_t area; | 2130 area_t area; |
2131 #ifndef UNITTEST | 2131 #ifndef UNITTEST |
2132 cairo_surface_t *surface; | 2132 mbe_surface_t *surface; |
2133 #endif | 2133 #endif |
2134 int r; | 2134 int r; |
2135 | 2135 |
2136 area.x = area.y = 0; | 2136 area.x = area.y = 0; |
2137 #ifndef UNITTEST | 2137 #ifndef UNITTEST |
2138 surface = cairo_get_target(rdman->cr); | 2138 surface = mbe_get_target(rdman->cr); |
2139 area.w = cairo_image_surface_get_width(surface); | 2139 area.w = mbe_image_surface_get_width(surface); |
2140 area.h = cairo_image_surface_get_height(surface); | 2140 area.h = mbe_image_surface_get_height(surface); |
2141 #else | 2141 #else |
2142 area.w = 1024; | 2142 area.w = 1024; |
2143 area.h = 1024; | 2143 area.h = 1024; |
2144 #endif | 2144 #endif |
2145 add_dirty_area(rdman, rdman->root_coord, &area); | 2145 add_dirty_area(rdman, rdman->root_coord, &area); |
2375 geo_from_positions(shape->geo, 2, poses); | 2375 geo_from_positions(shape->geo, 2, poses); |
2376 } | 2376 } |
2377 dummy->trans_cnt++; | 2377 dummy->trans_cnt++; |
2378 } | 2378 } |
2379 | 2379 |
2380 void sh_dummy_fill(shape_t *shape, cairo_t *cr) { | 2380 void sh_dummy_fill(shape_t *shape, mbe_t *cr) { |
2381 sh_dummy_t *dummy; | 2381 sh_dummy_t *dummy; |
2382 | 2382 |
2383 dummy = (sh_dummy_t *)shape; | 2383 dummy = (sh_dummy_t *)shape; |
2384 dummy->draw_cnt++; | 2384 dummy->draw_cnt++; |
2385 } | 2385 } |
2386 | 2386 |
2387 static void dummy_paint_prepare(paint_t *paint, cairo_t *cr) { | 2387 static void dummy_paint_prepare(paint_t *paint, mbe_t *cr) { |
2388 } | 2388 } |
2389 | 2389 |
2390 static void dummy_paint_free(redraw_man_t *rdman, paint_t *paint) { | 2390 static void dummy_paint_free(redraw_man_t *rdman, paint_t *paint) { |
2391 if(paint) | 2391 if(paint) |
2392 free(paint); | 2392 free(paint); |