Mercurial > MadButterfly
comparison include/mb_graph_engine_skia.h @ 472:4254eaa699d0 Android_Skia
Declare functions that should be implemented by Skia graphic engine
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 12 Nov 2009 21:32:52 +0800 |
parents | e54cd19cec28 |
children | ba64f928542b |
comparison
equal
deleted
inserted
replaced
471:e98ae1407ca2 | 472:4254eaa699d0 |
---|---|
5 #include "mb_img_ldr.h" | 5 #include "mb_img_ldr.h" |
6 | 6 |
7 /*! \defgroup mb_ge_skia MadButterfly Graphic Engine with Skia | 7 /*! \defgroup mb_ge_skia MadButterfly Graphic Engine with Skia |
8 * @{ | 8 * @{ |
9 */ | 9 */ |
10 #define MBE_OPERATOR_CLEAR CAIRO_OPERATOR_CLEAR | 10 #define MBE_OPERATOR_CLEAR 2 |
11 #define MBE_OPERATOR_SOURCE CAIRO_OPERATOR_SOURCE | 11 #define MBE_OPERATOR_SOURCE 1 |
12 #define MBE_STATUS_SUCCESS CAIRO_STATUS_SUCCESS | 12 #define MBE_STATUS_SUCCESS 0 |
13 | 13 |
14 #define mbe_image_surface_create_from_png | 14 typedef float co_aix; |
15 #define mbe_pattern_add_color_stop_rgba | 15 |
16 struct _mbe_text_extents_t { | |
17 co_aix x_bearing; | |
18 co_aix y_bearing; | |
19 co_aix width; | |
20 co_aix height; | |
21 co_aix x_advance; | |
22 co_aix y_advance; | |
23 }; | |
24 struct _mbe_scaled_font_t; | |
25 struct _mbe_font_face_t; | |
26 struct _mbe_surface_t; | |
27 struct _mbe_pattern_t; | |
28 struct _mbe_t; | |
29 | |
30 typedef struct _mbe_text_extents_t mbe_text_extents_t; | |
31 typedef struct _mbe_scaled_font_t mbe_scaled_font_t; | |
32 typedef struct _mbe_font_face_t mbe_font_face_t; | |
33 typedef struct _mbe_surface_t mbe_surface_t; | |
34 typedef struct _mbe_pattern_t mbe_pattern_t; | |
35 typedef struct { | |
36 co_aix xx; co_aix yx; | |
37 co_aix xy; co_aix yy; | |
38 co_aix x0; co_aix y0; | |
39 } mbe_matrix_t; | |
40 typedef struct _mbe_t mbe_t; | |
41 | |
42 extern void mbe_pattern_add_color_stop_rgba(mbe_pattern_t *ptn, | |
43 co_aix offset, | |
44 co_aix r, co_aix g, co_aix b, | |
45 co_aix a); | |
16 #define mbe_pattern_create_for_surface | 46 #define mbe_pattern_create_for_surface |
17 #define mbe_scaled_font_text_extents | 47 extern void mbe_scaled_font_text_extents(mbe_scaled_font_t *scaled, |
18 #define mbe_image_surface_get_stride | 48 const char *txt, |
19 #define mbe_image_surface_get_height | 49 mbe_text_extents_t *extents); |
20 #define mbe_image_surface_get_width | 50 extern int mbe_image_surface_get_stride(mbe_surface_t *surface); |
21 #define mbe_image_surface_get_data | 51 extern int mbe_image_surface_get_height(mbe_surface_t *surface); |
22 #define mbe_scaled_font_reference | 52 extern int mbe_image_surface_get_width(mbe_surface_t *surface); |
23 #define mbe_pattern_create_radial | 53 extern unsigned char *mbe_image_surface_get_data(mbe_surface_t *surface); |
24 #define mbe_pattern_create_linear | 54 extern mbe_scaled_font_t *mbe_scaled_font_reference(mbe_scaled_font_t *scaled); |
25 #define mbe_scaled_font_destroy | 55 extern mbe_pattern_t *mbe_pattern_create_radial(co_aix cx0, co_aix cy0, |
26 #define mbe_font_face_reference | 56 co_aix radius0, |
27 #define mbe_set_source_surface | 57 co_aix cx1, co_aix cy1, |
28 #define mbe_scaled_font_create | 58 co_aix radius1); |
29 #define mbe_pattern_set_matrix | 59 extern mbe_pattern_t *mbe_pattern_create_linear(co_aix x0, co_aix y0, |
30 #define mbe_font_face_destroy | 60 co_aix x1, co_aix y1); |
31 #define mbe_paint_with_alpha | 61 extern void mbe_scaled_font_destroy(mbe_scaled_font_t *scaled); |
32 #define mbe_surface_destroy | 62 extern mbe_font_face_t *mbe_font_face_reference(mbe_font_face_t *face); |
33 #define mbe_set_source_rgba | 63 extern void mbe_set_source_surface(mbe_t *canvas, mbe_surface_t *surface, |
34 #define mbe_set_scaled_font | 64 co_aix x, co_aix y); |
35 #define mbe_pattern_destroy | 65 extern mbe_scaled_font_t * |
36 #define mbe_get_scaled_font | 66 mbe_scaled_font_create(mbe_font_face_t *face, mbe_matrix_t *fnt_mtx, |
37 #define mbe_set_source_rgb | 67 mbe_matrix_t *ctm); |
38 #define mbe_set_line_width | 68 extern void mbe_pattern_set_matrix(mbe_pattern_t *ptn, |
39 #define mbe_get_font_face | 69 const mbe_matrix_t *matrix); |
40 #define mbe_fill_preserve | 70 extern void mbe_font_face_destroy(mbe_font_face_t *face); |
41 #define mbe_set_source | 71 extern void mbe_paint_with_alpha(mbe_t *canvas, co_aix alpha); |
42 #define mbe_reset_clip | 72 extern void mbe_surface_destroy(mbe_surface_t *surface); |
43 #define mbe_get_target | 73 extern void mbe_set_source_rgba(mbe_t *canvas, |
44 #define mbe_close_path | 74 co_aix r, co_aix g, co_aix b, co_aix a); |
45 #define mbe_text_path | 75 extern void mbe_set_scaled_font(mbe_t *canvas, |
46 #define mbe_rectangle | 76 const mbe_scaled_font_t *scaled); |
47 #define mbe_in_stroke | 77 extern void mbe_set_source_rgb(mbe_t *canvas, co_aix r, co_aix g, co_aix b); |
48 #define mbe_new_path | 78 extern void mbe_set_line_width(mbe_t *canvas, co_aix width); |
49 #define mbe_curve_to | 79 extern mbe_font_face_t *mbe_get_font_face(mbe_t *canvas); |
50 #define mbe_restore | 80 extern void mbe_fill_preserve(mbe_t *canvas); |
51 #define mbe_move_to | 81 extern void mbe_set_source(mbe_t *canvas, mbe_pattern_t *source); |
52 #define mbe_line_to | 82 extern void mbe_reset_clip(mbe_t *canvas); |
53 #define mbe_in_fill | 83 extern mbe_surface_t *mbe_get_target(mbe_t *canvas); |
54 #define mbe_destroy | 84 extern void mbe_close_path(mbe_t *canvas); |
55 #define mbe_stroke | 85 extern void mbe_text_path(mbe_t *canvas, const char *txt); |
56 #define mbe_create | 86 extern void mbe_rectangle(mbe_t *canvas, co_aix x, co_aix y, |
57 #define mbe_paint | 87 co_aix width, co_aix height); |
58 #define mbe_save | 88 extern int mbe_in_stroke(mbe_t *canvas, co_aix x, co_aix y); |
59 #define mbe_fill | 89 extern void mbe_new_path(mbe_t *canvas); |
60 #define mbe_clip | 90 extern void mbe_curve_to(mbe_t *canvas, co_aix x1, co_aix y1, |
61 | 91 co_aix x2, co_aix y2, |
62 typedef cairo_text_extents_t mbe_text_extents_t; | 92 co_aix x3, co_aix y3); |
63 typedef cairo_scaled_font_t mbe_scaled_font_t; | 93 extern void mbe_restore(mbe_t *canvas); |
64 typedef cairo_font_face_t mbe_font_face_t; | 94 extern void mbe_move_to(mbe_t *canvas, co_aix x, co_aix y); |
65 typedef cairo_surface_t mbe_surface_t; | 95 extern void mbe_line_to(mbe_t *canvas, co_aix x, co_aix y); |
66 typedef cairo_pattern_t mbe_pattern_t; | 96 extern int mbe_in_fill(mbe_t *canvas, co_aix x, co_aix y); |
67 typedef cairo_matrix_t mbe_matrix_t; | 97 extern void mbe_stroke(mbe_t *canvas); |
68 typedef cairo_t mbe_t; | 98 extern mbe_t *mbe_create(mbe_surface_t *target); |
69 typedef float co_aix; | 99 extern void mbe_destroy(mbe_t *canvas); |
100 extern void mbe_paint(mbe_t *canvas); | |
101 extern void mbe_save(mbe_t *canvas); | |
102 extern void mbe_fill(mbe_t *canvas); | |
103 extern void mbe_clip(mbe_t *canvas); | |
70 | 104 |
71 extern mbe_font_face_t * mbe_query_font_face(const char *family, | 105 extern mbe_font_face_t * mbe_query_font_face(const char *family, |
72 int slant, int weight); | 106 int slant, int weight); |
73 extern void mbe_free_font_face(mbe_font_face_t *face); | 107 extern void mbe_free_font_face(mbe_font_face_t *face); |
74 | 108 |
75 static void mbe_clear(mbe_t *canvas) { | 109 extern void mbe_clear(mbe_t *canvas); |
76 cairo_operator_t old_op; | 110 extern void mbe_copy_source(mbe_t *canvas); |
77 | 111 extern mbe_surface_t * |
78 old_op = mbe_get_operator(canvas); | |
79 mbe_set_operator(canvas, MBE_OPERATOR_CLEAR); | |
80 mbe_paint(canvas); | |
81 mbe_set_operator(canvas, old_op); | |
82 } | |
83 | |
84 static void mbe_copy_source(mbe_t *canvas) { | |
85 mbe_operator_t saved_op; | |
86 | |
87 saved_op = mbe_get_operator(canvas); | |
88 mbe_set_operator(canvas, MBE_OPERATOR_SOURCE); | |
89 mbe_paint(canvas); | |
90 mbe_set_operator(canvas, saved_op); | |
91 } | |
92 | |
93 static mbe_surface_t * | |
94 mbe_image_surface_create_for_data(unsigned char *data, | 112 mbe_image_surface_create_for_data(unsigned char *data, |
95 mb_img_fmt_t fmt, | 113 mb_img_fmt_t fmt, |
96 int width, int height, | 114 int width, int height, |
97 int stride) { | 115 int stride); |
98 cairo_format_t _fmt; | 116 extern mb_img_fmt_t mbe_image_surface_get_format(mbe_surface_t *surface); |
99 | 117 extern mbe_surface_t * |
100 switch(fmt) { | 118 mbe_image_surface_create(mb_img_fmt_t fmt, int width, int height); |
101 case MB_IFMT_ARGB32: | 119 extern void mbe_transform(mbe_t *mbe, mbe_matrix_t *matrix); |
102 _fmt = CAIRO_FORMAT_ARGB32; | 120 extern void mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius, |
103 break; | 121 co_aix angle_start, co_aix angle_stop); |
104 case MB_IFMT_RGB24: | |
105 _fmt = CAIRO_FORMAT_RGB24; | |
106 break; | |
107 case MB_IFMT_A8: | |
108 _fmt = CAIRO_FORMAT_A8; | |
109 break; | |
110 case MB_IFMT_A1: | |
111 _fmt = CAIRO_FORMAT_A1; | |
112 break; | |
113 default: | |
114 return NULL; | |
115 } | |
116 return cairo_image_surface_create_for_data(data, _fmt, | |
117 width, height, stride); | |
118 } | |
119 | |
120 static mb_img_fmt_t | |
121 mbe_image_surface_get_format(mbe_surface_t *surface) { | |
122 cairo_format_t _fmt; | |
123 mb_img_fmt_t fmt; | |
124 | |
125 _fmt = cairo_image_surface_get_format(surface); | |
126 switch(_fmt) { | |
127 case CAIRO_FORMAT_ARGB32: | |
128 fmt = MB_IFMT_ARGB32; | |
129 break; | |
130 case CAIRO_FORMAT_RGB24: | |
131 fmt = MB_IFMT_RGB24; | |
132 break; | |
133 case CAIRO_FORMAT_A8: | |
134 fmt = MB_IFMT_A8; | |
135 break; | |
136 case CAIRO_FORMAT_A1: | |
137 fmt = MB_IFMT_A1; | |
138 break; | |
139 default: | |
140 fmt = MB_IFMT_DUMMY; | |
141 break; | |
142 } | |
143 | |
144 return fmt; | |
145 } | |
146 | |
147 static mbe_surface_t * | |
148 mbe_image_surface_create(mb_img_fmt_t fmt, int width, int height) { | |
149 cairo_format_t _fmt; | |
150 | |
151 switch(fmt) { | |
152 case MB_IFMT_ARGB32: | |
153 _fmt = CAIRO_FORMAT_ARGB32; | |
154 break; | |
155 case MB_IFMT_RGB24: | |
156 _fmt = CAIRO_FORMAT_RGB24; | |
157 break; | |
158 case MB_IFMT_A8: | |
159 _fmt = CAIRO_FORMAT_A8; | |
160 break; | |
161 case MB_IFMT_A1: | |
162 _fmt = CAIRO_FORMAT_A1; | |
163 break; | |
164 default: | |
165 return NULL; | |
166 } | |
167 | |
168 return cairo_image_surface_create(_fmt, width, height); | |
169 } | |
170 | |
171 static void | |
172 mbe_transform(mbe_t *mbe, const co_aix matrix[6]) { | |
173 cairo_matrix_t cmtx; | |
174 | |
175 cmtx.xx = matrix[0]; | |
176 cmtx.xy = matrix[1]; | |
177 cmtx.x0 = matrix[2]; | |
178 cmtx.yx = matrix[3]; | |
179 cmtx.yy = matrix[4]; | |
180 cmtx.y0 = matrix[5]; | |
181 | |
182 cairo_transform(mbe, &cmtx); | |
183 } | |
184 | |
185 static void | |
186 mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius, | |
187 co_aix angle_start, co_aix angle_stop) { | |
188 if(angle_start <= angle_stop) | |
189 cairo_arc(mbe, x, y, radius, angle_start, angle_stop); | |
190 else | |
191 cairo_arc_negative(mbe, x, y, radius, angle_start, angle_stop); | |
192 } | |
193 /* @} */ | 122 /* @} */ |
194 | 123 |
195 #endif /* __MB_GE_SKIA_H_ */ | 124 #endif /* __MB_GE_SKIA_H_ */ |