big patch from Samsung SAIT (Advanced research group) for async multi-frame
[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_gradient_init();
57    evas_common_polygon_init();
58    evas_common_line_init();
59    evas_common_font_init();
60    evas_common_draw_init();
61    evas_common_tilebuf_init();
62
63    evas_qtopia_outbuf_software_qtopia_init();
64
65    /* get any stored performance metrics from device (xserver) */
66    re->ob = evas_qtopia_outbuf_software_qtopia_setup_q(w, h, rot, OUTBUF_DEPTH_INHERIT, target);
67    if (!re->ob)
68      {
69         free(re);
70         return NULL;
71      }
72    evas_qtopia_outbuf_software_qtopia_set_have_backbuf(re->ob, 0);
73    re->tb = evas_common_tilebuf_new(w, h);
74    if (!re->tb)
75      {
76         evas_qtopia_outbuf_software_qtopia_free(re->ob);
77         free(re);
78         return NULL;
79      }
80    /* in preliminary tests 16x16 gave highest framerates */
81    evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
82    return re;
83 }
84
85 /* engine api this module provides */
86 static void *
87 eng_info(Evas *e)
88 {
89    Evas_Engine_Info_Software_Qtopia *info;
90    info = calloc(1, sizeof(Evas_Engine_Info_Software_Qtopia));
91    if (!info) return NULL;
92    info->magic.magic = rand();
93    info->render_mode = EVAS_RENDER_MODE_BLOCKING;
94    return info;
95    e = NULL;
96 }
97
98 static void
99 eng_info_free(Evas *e, void *info)
100 {
101    Evas_Engine_Info_Software_Qtopia *in;
102    in = (Evas_Engine_Info_Software_Qtopia *)info;
103    free(in);
104 }
105
106 static int
107 eng_setup(Evas *e, void *in)
108 {
109    Render_Engine *re;
110    Evas_Engine_Info_Software_Qtopia *info;
111
112    info = (Evas_Engine_Info_Software_Qtopia *)in;
113    if (!e->engine.data.output)
114      e->engine.data.output =
115      _output_setup(e->output.w,
116                    e->output.h,
117                    info->info.rotation,
118                    info->info.target);
119   if (!e->engine.data.output) return 0;
120    if (!e->engine.data.context)
121      e->engine.data.context =
122      e->engine.func->context_new(e->engine.data.output);
123
124    re = e->engine.data.output;
125
126    return 1;
127 }
128
129 static void
130 eng_output_free(void *data)
131 {
132    Render_Engine *re;
133
134    re = (Render_Engine *)data;
135    evas_qtopia_outbuf_software_qtopia_free(re->ob);
136    evas_common_tilebuf_free(re->tb);
137    if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
138    free(re);
139
140    evas_common_font_shutdown();
141    evas_common_image_shutdown();
142 }
143
144 static void
145 eng_output_resize(void *data, int w, int h)
146 {
147    Render_Engine *re;
148
149    re = (Render_Engine *)data;
150    evas_qtopia_outbuf_software_qtopia_reconfigure(re->ob, w, h,
151                                                   evas_qtopia_outbuf_software_qtopia_get_rot(re->ob),
152                                                   OUTBUF_DEPTH_INHERIT);
153    evas_qtopia_outbuf_software_qtopia_set_have_backbuf(re->ob, 0);
154    evas_common_tilebuf_free(re->tb);
155    re->tb = evas_common_tilebuf_new(w, h);
156    if (re->tb)
157      evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
158 }
159
160 static void
161 eng_output_tile_size_set(void *data, int w, int h)
162 {
163    Render_Engine *re;
164
165    re = (Render_Engine *)data;
166    evas_common_tilebuf_set_tile_size(re->tb, w, h);
167 }
168
169 static void
170 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
171 {
172    Render_Engine *re;
173
174    re = (Render_Engine *)data;
175    evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
176 }
177
178 static void
179 eng_output_redraws_rect_del(void *data, int x, int y, int w, int h)
180 {
181    Render_Engine *re;
182
183    re = (Render_Engine *)data;
184    evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
185 }
186
187 static void
188 eng_output_redraws_clear(void *data)
189 {
190    Render_Engine *re;
191
192    re = (Render_Engine *)data;
193    evas_common_tilebuf_clear(re->tb);
194 }
195
196 static void *
197 eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
198 {
199    Render_Engine *re;
200    RGBA_Image *surface;
201    Tilebuf_Rect *rect;
202    int ux, uy, uw, uh;
203
204    re = (Render_Engine *)data;
205    if (re->end)
206      {
207         re->end = 0;
208         return NULL;
209      }
210    if (!re->rects)
211      {
212         re->rects = evas_common_tilebuf_get_render_rects(re->tb);
213         re->cur_rect = EINA_INLIST_GET(re->rects);
214      }
215    if (!re->cur_rect) return NULL;
216    rect = (Tilebuf_Rect *)re->cur_rect;
217    ux = rect->x; uy = rect->y; uw = rect->w; uh = rect->h;
218    re->cur_rect = re->cur_rect->next;
219    if (!re->cur_rect)
220      {
221         evas_common_tilebuf_free_render_rects(re->rects);
222         re->rects = NULL;
223         re->end = 1;
224      }
225
226    surface = evas_qtopia_outbuf_software_qtopia_new_region_for_update(re->ob,
227                                                           ux, uy, uw, uh,
228                                                           cx, cy, cw, ch);
229    *x = ux; *y = uy; *w = uw; *h = uh;
230    return surface;
231 }
232
233 static void
234 eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h)
235 {
236    Render_Engine *re;
237    Evas_Engine_Info_Software_Qtopia *info;
238
239    re = (Render_Engine *)data;
240 #ifdef BUILD_PIPE_RENDER
241    evas_common_pipe_map4_begin(surface);
242 #endif   
243    evas_qtopia_outbuf_software_qtopia_push_updated_region(re->ob, surface, x, y, w, h);
244    evas_qtopia_outbuf_software_qtopia_free_region_for_update(re->ob, surface);
245    evas_common_cpu_end_opt();
246 }
247
248 static void
249 eng_output_flush(void *data)
250 {
251    Render_Engine *re;
252
253    re = (Render_Engine *)data;
254 }
255
256 static void
257 eng_output_idle_flush(void *data)
258 {
259    Render_Engine *re;
260
261    re = (Render_Engine *)data;
262 }
263
264 static Eina_Bool
265 eng_canvas_alpha_get(void *data, void *context)
266 {
267    return EINA_FALSE;
268 }
269
270 /* module advertising code */
271 static int
272 module_open(Evas_Module *em)
273 {
274    if (!em) return 0;
275    /* get whatever engine module we inherit from */
276    if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
277    _evas_engine_soft_qtopia_log_dom = eina_log_domain_register("EvasSoftQtopia",EVAS_DEFAULT_LOG_COLOR);
278    if(_evas_engine_soft_qtopia_log_dom < 0)
279      {
280        EINA_LOG_ERR("Impossible to create a log domain for the qtopia engine.\n");
281        return NULL;
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