svn update: 57457 (latest:57457)
[framework/uifw/evas.git] / src / modules / engines / software_qtopia / evas_engine.c
1 #include "evas_common.h"
2 #include "evas_private.h"
3 #include "evas_engine.h"
4 #include "Evas_Engine_Software_Qtopia.h"
5
6 int _evas_engine_soft_qtopia_log_dom = -1;
7 /* function tables - filled in later (func and parent func) */
8 static Evas_Func func, pfunc;
9
10 /* engine struct data */
11 typedef struct _Render_Engine Render_Engine;
12
13 struct _Render_Engine
14 {
15    Tilebuf          *tb;
16    Outbuf           *ob;
17    Tilebuf_Rect     *rects;
18    Eina_Inlist      *cur_rect;
19    int               end : 1;
20 };
21
22 /* prototypes we will use here */
23 static void *_output_setup(int w, int h, int rot, QWidget *target);
24
25 static void *eng_info(Evas *e);
26 static void eng_info_free(Evas *e, void *info);
27 static int eng_setup(Evas *e, void *info);
28 static void eng_output_free(void *data);
29 static void eng_output_resize(void *data, int w, int h);
30 static void eng_output_tile_size_set(void *data, int w, int h);
31 static void eng_output_redraws_rect_add(void *data, int x, int y, int w, int h);
32 static void eng_output_redraws_rect_del(void *data, int x, int y, int w, int h);
33 static void eng_output_redraws_clear(void *data);
34 static void *eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch);
35 static void eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h);
36 static void eng_output_flush(void *data);
37 static void eng_output_idle_flush(void *data);
38
39 /* internal engine routines */
40 static void *
41 _output_setup(int w, int h, int rot, QWidget *target)
42 {
43    Render_Engine *re;
44
45    re = calloc(1, sizeof(Render_Engine));
46    if (!re)
47      return NULL;
48    /* if we haven't initialized - init (automatic abort if already done) */
49    evas_common_cpu_init();
50
51    evas_common_blend_init();
52    evas_common_image_init();
53    evas_common_convert_init();
54    evas_common_scale_init();
55    evas_common_rectangle_init();
56    evas_common_polygon_init();
57    evas_common_line_init();
58    evas_common_font_init();
59    evas_common_draw_init();
60    evas_common_tilebuf_init();
61
62    evas_qtopia_outbuf_software_qtopia_init();
63
64    /* get any stored performance metrics from device (xserver) */
65    re->ob = evas_qtopia_outbuf_software_qtopia_setup_q(w, h, rot, OUTBUF_DEPTH_INHERIT, target);
66    if (!re->ob)
67      {
68         free(re);
69         return NULL;
70      }
71    evas_qtopia_outbuf_software_qtopia_set_have_backbuf(re->ob, 0);
72    re->tb = evas_common_tilebuf_new(w, h);
73    if (!re->tb)
74      {
75         evas_qtopia_outbuf_software_qtopia_free(re->ob);
76         free(re);
77         return NULL;
78      }
79    /* in preliminary tests 16x16 gave highest framerates */
80    evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
81    return re;
82 }
83
84 /* engine api this module provides */
85 static void *
86 eng_info(Evas *e)
87 {
88    Evas_Engine_Info_Software_Qtopia *info;
89    info = calloc(1, sizeof(Evas_Engine_Info_Software_Qtopia));
90    if (!info) return NULL;
91    info->magic.magic = rand();
92    info->render_mode = EVAS_RENDER_MODE_BLOCKING;
93    return info;
94    e = NULL;
95 }
96
97 static void
98 eng_info_free(Evas *e, void *info)
99 {
100    Evas_Engine_Info_Software_Qtopia *in;
101    in = (Evas_Engine_Info_Software_Qtopia *)info;
102    free(in);
103 }
104
105 static int
106 eng_setup(Evas *e, void *in)
107 {
108    Render_Engine *re;
109    Evas_Engine_Info_Software_Qtopia *info;
110
111    info = (Evas_Engine_Info_Software_Qtopia *)in;
112    if (!e->engine.data.output)
113      e->engine.data.output =
114      _output_setup(e->output.w,
115                    e->output.h,
116                    info->info.rotation,
117                    info->info.target);
118   if (!e->engine.data.output) return 0;
119    if (!e->engine.data.context)
120      e->engine.data.context =
121      e->engine.func->context_new(e->engine.data.output);
122
123    re = e->engine.data.output;
124
125    return 1;
126 }
127
128 static void
129 eng_output_free(void *data)
130 {
131    Render_Engine *re;
132
133    re = (Render_Engine *)data;
134    evas_qtopia_outbuf_software_qtopia_free(re->ob);
135    evas_common_tilebuf_free(re->tb);
136    if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
137    free(re);
138
139    evas_common_font_shutdown();
140    evas_common_image_shutdown();
141 }
142
143 static void
144 eng_output_resize(void *data, int w, int h)
145 {
146    Render_Engine *re;
147
148    re = (Render_Engine *)data;
149    evas_qtopia_outbuf_software_qtopia_reconfigure(re->ob, w, h,
150                                                   evas_qtopia_outbuf_software_qtopia_get_rot(re->ob),
151                                                   OUTBUF_DEPTH_INHERIT);
152    evas_qtopia_outbuf_software_qtopia_set_have_backbuf(re->ob, 0);
153    evas_common_tilebuf_free(re->tb);
154    re->tb = evas_common_tilebuf_new(w, h);
155    if (re->tb)
156      evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
157 }
158
159 static void
160 eng_output_tile_size_set(void *data, int w, int h)
161 {
162    Render_Engine *re;
163
164    re = (Render_Engine *)data;
165    evas_common_tilebuf_set_tile_size(re->tb, w, h);
166 }
167
168 static void
169 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
170 {
171    Render_Engine *re;
172
173    re = (Render_Engine *)data;
174    evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
175 }
176
177 static void
178 eng_output_redraws_rect_del(void *data, int x, int y, int w, int h)
179 {
180    Render_Engine *re;
181
182    re = (Render_Engine *)data;
183    evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
184 }
185
186 static void
187 eng_output_redraws_clear(void *data)
188 {
189    Render_Engine *re;
190
191    re = (Render_Engine *)data;
192    evas_common_tilebuf_clear(re->tb);
193 }
194
195 static void *
196 eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
197 {
198    Render_Engine *re;
199    RGBA_Image *surface;
200    Tilebuf_Rect *rect;
201    int ux, uy, uw, uh;
202
203    re = (Render_Engine *)data;
204    if (re->end)
205      {
206         re->end = 0;
207         return NULL;
208      }
209    if (!re->rects)
210      {
211         re->rects = evas_common_tilebuf_get_render_rects(re->tb);
212         re->cur_rect = EINA_INLIST_GET(re->rects);
213      }
214    if (!re->cur_rect) return NULL;
215    rect = (Tilebuf_Rect *)re->cur_rect;
216    ux = rect->x; uy = rect->y; uw = rect->w; uh = rect->h;
217    re->cur_rect = re->cur_rect->next;
218    if (!re->cur_rect)
219      {
220         evas_common_tilebuf_free_render_rects(re->rects);
221         re->rects = NULL;
222         re->end = 1;
223      }
224
225    surface = evas_qtopia_outbuf_software_qtopia_new_region_for_update(re->ob,
226                                                           ux, uy, uw, uh,
227                                                           cx, cy, cw, ch);
228    *x = ux; *y = uy; *w = uw; *h = uh;
229    return surface;
230 }
231
232 static void
233 eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h)
234 {
235    Render_Engine *re;
236    Evas_Engine_Info_Software_Qtopia *info;
237
238    re = (Render_Engine *)data;
239 #ifdef BUILD_PIPE_RENDER
240    evas_common_pipe_map_begin(surface);
241 #endif   
242    evas_qtopia_outbuf_software_qtopia_push_updated_region(re->ob, surface, x, y, w, h);
243    evas_qtopia_outbuf_software_qtopia_free_region_for_update(re->ob, surface);
244    evas_common_cpu_end_opt();
245 }
246
247 static void
248 eng_output_flush(void *data)
249 {
250    Render_Engine *re;
251
252    re = (Render_Engine *)data;
253 }
254
255 static void
256 eng_output_idle_flush(void *data)
257 {
258    Render_Engine *re;
259
260    re = (Render_Engine *)data;
261 }
262
263 static Eina_Bool
264 eng_canvas_alpha_get(void *data, void *context)
265 {
266    return EINA_FALSE;
267 }
268
269 /* module advertising code */
270 static int
271 module_open(Evas_Module *em)
272 {
273    if (!em) return 0;
274    /* get whatever engine module we inherit from */
275    if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
276    _evas_engine_soft_qtopia_log_dom = eina_log_domain_register
277      ("evas-software_qtopia", EVAS_DEFAULT_LOG_COLOR);
278    if(_evas_engine_soft_qtopia_log_dom < 0)
279      {
280         EINA_LOG_ERR("Can not create a module log domain.");
281         return 0;
282      }
283    /* store it for later use */
284    func = pfunc;
285    /* now to override methods */
286 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
287    ORD(info);
288    ORD(info_free);
289    ORD(setup);
290    ORD(canvas_alpha_get);
291    ORD(output_free);
292    ORD(output_resize);
293    ORD(output_tile_size_set);
294    ORD(output_redraws_rect_add);
295    ORD(output_redraws_rect_del);
296    ORD(output_redraws_clear);
297    ORD(output_redraws_next_update_get);
298    ORD(output_redraws_next_update_push);
299    ORD(output_flush);
300    ORD(output_idle_flush);
301    /* now advertise out own api */
302    em->functions = (void *)(&func);
303    return 1;
304 }
305
306 static void
307 module_close(Evas_Module *em)
308 {
309   eina_log_domain_unregister(_evas_engine_soft_qtopia_log_dom);
310 }
311
312 static Evas_Module_Api evas_modapi =
313 {
314    EVAS_MODULE_API_VERSION,
315    "software_qtopia",
316    "none",
317    {
318      module_open,
319      module_close
320    }
321 };
322
323 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_qtopia);
324
325 #ifndef EVAS_STATIC_BUILD_SOFTWARE_QTOPIA
326 EVAS_EINA_MODULE_DEFINE(engine, software_qtopia);
327 #endif