comparison include/mb_graph_engine_skia.h @ 465:d8181696b689 Android_Skia

Move functions into graphic engine layers. Cairo and Skia have their own header files and C/C++ files. Some functions are refactoried and move into graphic engine layer to make reset of MadButterfly independently from graphic engines.
author Thinker K.F. Li <thinker@branda.to>
date Thu, 12 Nov 2009 21:22:30 +0800
parents
children 4dc0be6c044a
comparison
equal deleted inserted replaced
464:271212f325b4 465:d8181696b689
1 #ifndef __MB_GE_SKIA_H_
2 #define __MB_GE_SKIA_H_
3
4 #include <stdio.h>
5 #include "mb_img_ldr.h"
6
7 /*! \defgroup mb_ge_skia MadButterfly Graphic Engine with Skia
8 * @{
9 */
10 #define MBE_OPERATOR_CLEAR CAIRO_OPERATOR_CLEAR
11 #define MBE_OPERATOR_SOURCE CAIRO_OPERATOR_SOURCE
12 #define MBE_STATUS_SUCCESS CAIRO_STATUS_SUCCESS
13
14 #define mbe_ft_font_face_create_for_pattern
15 #define mbe_image_surface_create_from_png
16 #define mbe_pattern_add_color_stop_rgba
17 #define mbe_pattern_create_for_surface
18 #define mbe_scaled_font_text_extents
19 #define mbe_image_surface_get_stride
20 #define mbe_image_surface_get_height
21 #define mbe_image_surface_get_width
22 #define mbe_image_surface_get_data
23 #define mbe_scaled_font_reference
24 #define mbe_pattern_create_radial
25 #define mbe_pattern_create_linear
26 #define mbe_xlib_surface_create
27 #define mbe_scaled_font_destroy
28 #define mbe_font_face_reference
29 #define mbe_set_source_surface
30 #define mbe_scaled_font_status
31 #define mbe_scaled_font_create
32 #define mbe_pattern_set_matrix
33 #define mbe_font_face_destroy
34 #define mbe_paint_with_alpha
35 #define mbe_font_face_status
36 #define mbe_surface_destroy
37 #define mbe_set_source_rgba
38 #define mbe_set_scaled_font
39 #define mbe_pattern_destroy
40 #define mbe_get_scaled_font
41 #define mbe_set_source_rgb
42 #define mbe_set_line_width
43 #define mbe_get_font_face
44 #define mbe_fill_preserve
45 #define mbe_set_operator
46 #define mbe_get_operator
47 #define mbe_set_source
48 #define mbe_reset_clip
49 #define mbe_get_target
50 #define mbe_close_path
51 #define mbe_text_path
52 #define mbe_show_text
53 #define mbe_rectangle
54 #define mbe_in_stroke
55 #define mbe_new_path
56 #define mbe_curve_to
57 #define mbe_restore
58 #define mbe_move_to
59 #define mbe_line_to
60 #define mbe_in_fill
61 #define mbe_destroy
62 #define mbe_stroke
63 #define mbe_create
64 #define mbe_paint
65 #define mbe_save
66 #define mbe_fill
67 #define mbe_clip
68
69 typedef cairo_text_extents_t mbe_text_extents_t;
70 typedef cairo_scaled_font_t mbe_scaled_font_t;
71 typedef cairo_font_face_t mbe_font_face_t;
72 typedef cairo_operator_t mbe_operator_t;
73 typedef cairo_surface_t mbe_surface_t;
74 typedef cairo_pattern_t mbe_pattern_t;
75 typedef cairo_status_t mbe_status_t;
76 typedef cairo_matrix_t mbe_matrix_t;
77 typedef cairo_t mbe_t;
78 typedef float co_aix;
79
80 extern mbe_font_face_t * mbe_query_font_face(const char *family,
81 int slant, int weight);
82 extern void mbe_free_font_face(mbe_font_face_t *face);
83
84 static mbe_surface_t *
85 mbe_image_surface_create_for_data(unsigned char *data,
86 mb_img_fmt_t fmt,
87 int width, int height,
88 int stride) {
89 cairo_format_t _fmt;
90
91 switch(fmt) {
92 case MB_IFMT_ARGB32:
93 _fmt = CAIRO_FORMAT_ARGB32;
94 break;
95 case MB_IFMT_RGB24:
96 _fmt = CAIRO_FORMAT_RGB24;
97 break;
98 case MB_IFMT_A8:
99 _fmt = CAIRO_FORMAT_A8;
100 break;
101 case MB_IFMT_A1:
102 _fmt = CAIRO_FORMAT_A1;
103 break;
104 default:
105 return NULL;
106 }
107 return cairo_image_surface_create_for_data(data, _fmt,
108 width, height, stride);
109 }
110
111 static mb_img_fmt_t
112 mbe_image_surface_get_format(mbe_surface_t *surface) {
113 cairo_format_t _fmt;
114 mb_img_fmt_t fmt;
115
116 _fmt = cairo_image_surface_get_format(surface);
117 switch(_fmt) {
118 case CAIRO_FORMAT_ARGB32:
119 fmt = MB_IFMT_ARGB32;
120 break;
121 case CAIRO_FORMAT_RGB24:
122 fmt = MB_IFMT_RGB24;
123 break;
124 case CAIRO_FORMAT_A8:
125 fmt = MB_IFMT_A8;
126 break;
127 case CAIRO_FORMAT_A1:
128 fmt = MB_IFMT_A1;
129 break;
130 default:
131 fmt = MB_IFMT_DUMMY;
132 break;
133 }
134
135 return fmt;
136 }
137
138 static mbe_surface_t *
139 mbe_image_surface_create(mb_img_fmt_t fmt, int width, int height) {
140 cairo_format_t _fmt;
141
142 switch(fmt) {
143 case MB_IFMT_ARGB32:
144 _fmt = CAIRO_FORMAT_ARGB32;
145 break;
146 case MB_IFMT_RGB24:
147 _fmt = CAIRO_FORMAT_RGB24;
148 break;
149 case MB_IFMT_A8:
150 _fmt = CAIRO_FORMAT_A8;
151 break;
152 case MB_IFMT_A1:
153 _fmt = CAIRO_FORMAT_A1;
154 break;
155 default:
156 return NULL;
157 }
158
159 return cairo_image_surface_create(_fmt, width, height);
160 }
161
162 static void
163 mbe_transform(mbe_t *mbe, const co_aix matrix[6]) {
164 cairo_matrix_t cmtx;
165
166 cmtx.xx = matrix[0];
167 cmtx.xy = matrix[1];
168 cmtx.x0 = matrix[2];
169 cmtx.yx = matrix[3];
170 cmtx.yy = matrix[4];
171 cmtx.y0 = matrix[5];
172
173 cairo_transform(mbe, &cmtx);
174 }
175
176 static void
177 mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius,
178 co_aix angle_start, co_aix angle_stop) {
179 if(angle_start <= angle_stop)
180 cairo_arc(mbe, x, y, radius, angle_start, angle_stop);
181 else
182 cairo_arc_negative(mbe, x, y, radius, angle_start, angle_stop);
183 }
184 /* @} */
185
186 #endif /* __MB_GE_SKIA_H_ */