diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/evas/src/modules/engines/wayland_shm/evas_engine.c | 370 |
1 files changed, 370 insertions, 0 deletions
diff --git a/libraries/evas/src/modules/engines/wayland_shm/evas_engine.c b/libraries/evas/src/modules/engines/wayland_shm/evas_engine.c new file mode 100644 index 0000000..7c55517 --- /dev/null +++ b/libraries/evas/src/modules/engines/wayland_shm/evas_engine.c | |||
@@ -0,0 +1,370 @@ | |||
1 | #include "evas_common.h" | ||
2 | #include "evas_private.h" | ||
3 | #include "evas_engine.h" | ||
4 | #include "Evas_Engine_Wayland_Shm.h" | ||
5 | |||
6 | /* local structures */ | ||
7 | typedef struct _Render_Engine Render_Engine; | ||
8 | struct _Render_Engine | ||
9 | { | ||
10 | Tilebuf *tb; | ||
11 | Tilebuf_Rect *rects; | ||
12 | Outbuf *ob; | ||
13 | Eina_Inlist *cur_rect; | ||
14 | |||
15 | Eina_Bool end : 1; | ||
16 | |||
17 | void (*outbuf_free)(Outbuf *ob); | ||
18 | void (*outbuf_resize)(Outbuf *ob, int w, int h); | ||
19 | RGBA_Image *(*outbuf_new_region_for_update)(Outbuf *ob, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch); | ||
20 | void (*outbuf_push_updated_region)(Outbuf *ob, RGBA_Image *surface, int x, int y, int w, int h); | ||
21 | void (*outbuf_free_region_for_update)(Outbuf *ob, RGBA_Image *update); | ||
22 | }; | ||
23 | |||
24 | /* local variables */ | ||
25 | static Evas_Func func, pfunc; | ||
26 | |||
27 | /* external variables */ | ||
28 | int _evas_engine_way_shm_log_dom = -1; | ||
29 | |||
30 | /* local function prototypes */ | ||
31 | static void *_output_setup(int w, int h, int rotation, void *dest); | ||
32 | |||
33 | /* engine function prototypes */ | ||
34 | static void *eng_info(Evas *evas __UNUSED__); | ||
35 | static void eng_info_free(Evas *evas __UNUSED__, void *info); | ||
36 | static int eng_setup(Evas *evas, void *info); | ||
37 | static void eng_output_free(void *data); | ||
38 | static void eng_output_resize(void *data, int w, int h); | ||
39 | static void eng_output_tile_size_set(void *data, int w, int h); | ||
40 | static void eng_output_redraws_rect_add(void *data, int x, int y, int w, int h); | ||
41 | static void eng_output_redraws_rect_del(void *data, int x, int y, int w, int h); | ||
42 | static void eng_output_redraws_clear(void *data); | ||
43 | 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); | ||
44 | static void eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h); | ||
45 | static void eng_output_flush(void *data); | ||
46 | static void eng_output_idle_flush(void *data); | ||
47 | static Eina_Bool eng_canvas_alpha_get(void *data, void *context __UNUSED__); | ||
48 | |||
49 | /* local functions */ | ||
50 | static void * | ||
51 | _output_setup(int w, int h, int rotation, void *dest) | ||
52 | { | ||
53 | Render_Engine *re = NULL; | ||
54 | |||
55 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
56 | |||
57 | if (!(re = calloc(1, sizeof(Render_Engine)))) return NULL; | ||
58 | |||
59 | if (!(re->ob = evas_outbuf_setup(w, h, rotation, dest))) | ||
60 | { | ||
61 | free(re); | ||
62 | return NULL; | ||
63 | } | ||
64 | |||
65 | if (!(re->tb = evas_common_tilebuf_new(w, h))) | ||
66 | { | ||
67 | evas_outbuf_free(re->ob); | ||
68 | free(re); | ||
69 | return NULL; | ||
70 | } | ||
71 | |||
72 | evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE); | ||
73 | return re; | ||
74 | } | ||
75 | |||
76 | /* engine functions */ | ||
77 | static void * | ||
78 | eng_info(Evas *evas __UNUSED__) | ||
79 | { | ||
80 | Evas_Engine_Info_Wayland_Shm *info; | ||
81 | |||
82 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
83 | |||
84 | if (!(info = calloc(1, sizeof(Evas_Engine_Info_Wayland_Shm)))) | ||
85 | return NULL; | ||
86 | |||
87 | info->magic.magic = rand(); | ||
88 | info->info.debug = EINA_FALSE; | ||
89 | info->render_mode = EVAS_RENDER_MODE_BLOCKING; | ||
90 | |||
91 | return info; | ||
92 | } | ||
93 | |||
94 | static void | ||
95 | eng_info_free(Evas *evas __UNUSED__, void *info) | ||
96 | { | ||
97 | Evas_Engine_Info_Wayland_Shm *in; | ||
98 | |||
99 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
100 | |||
101 | if (!(in = (Evas_Engine_Info_Wayland_Shm *)info)) return; | ||
102 | free(in); | ||
103 | } | ||
104 | |||
105 | static int | ||
106 | eng_setup(Evas *evas, void *info) | ||
107 | { | ||
108 | Evas_Engine_Info_Wayland_Shm *in; | ||
109 | Render_Engine *re = NULL; | ||
110 | |||
111 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
112 | |||
113 | if (!(in = (Evas_Engine_Info_Wayland_Shm *)info)) return 0; | ||
114 | |||
115 | if (!evas->engine.data.output) | ||
116 | { | ||
117 | evas_common_cpu_init(); | ||
118 | evas_common_blend_init(); | ||
119 | evas_common_image_init(); | ||
120 | evas_common_convert_init(); | ||
121 | evas_common_scale_init(); | ||
122 | evas_common_rectangle_init(); | ||
123 | evas_common_polygon_init(); | ||
124 | evas_common_line_init(); | ||
125 | evas_common_font_init(); | ||
126 | evas_common_draw_init(); | ||
127 | evas_common_tilebuf_init(); | ||
128 | |||
129 | re = _output_setup(evas->output.w, evas->output.h, | ||
130 | in->info.rotation, in->info.dest); | ||
131 | if (!re) return 0; | ||
132 | |||
133 | re->outbuf_free = evas_outbuf_free; | ||
134 | re->outbuf_resize = evas_outbuf_resize; | ||
135 | re->outbuf_new_region_for_update = evas_outbuf_new_region_for_update; | ||
136 | re->outbuf_push_updated_region = evas_outbuf_push_updated_region; | ||
137 | re->outbuf_free_region_for_update = evas_outbuf_free_region_for_update; | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | if (!(re = evas->engine.data.output)) return 0; | ||
142 | if (re->ob) re->outbuf_free(re->ob); | ||
143 | re->ob = evas_outbuf_setup(evas->output.w, evas->output.h, | ||
144 | in->info.rotation, in->info.dest); | ||
145 | if (re->tb) evas_common_tilebuf_free(re->tb); | ||
146 | if ((re->tb = evas_common_tilebuf_new(evas->output.w, evas->output.h))) | ||
147 | evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE); | ||
148 | } | ||
149 | |||
150 | evas->engine.data.output = re; | ||
151 | |||
152 | if (!evas->engine.data.context) | ||
153 | { | ||
154 | evas->engine.data.context = | ||
155 | evas->engine.func->context_new(evas->engine.data.output); | ||
156 | } | ||
157 | |||
158 | return 1; | ||
159 | } | ||
160 | |||
161 | static void | ||
162 | eng_output_free(void *data) | ||
163 | { | ||
164 | Render_Engine *re = NULL; | ||
165 | |||
166 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
167 | |||
168 | if ((re = (Render_Engine *)data)) | ||
169 | { | ||
170 | if (re->ob) re->outbuf_free(re->ob); | ||
171 | if (re->tb) evas_common_tilebuf_free(re->tb); | ||
172 | if (re->rects) evas_common_tilebuf_free_render_rects(re->rects); | ||
173 | free(re); | ||
174 | } | ||
175 | evas_common_font_shutdown(); | ||
176 | evas_common_image_shutdown(); | ||
177 | } | ||
178 | |||
179 | static void | ||
180 | eng_output_resize(void *data, int w, int h) | ||
181 | { | ||
182 | Render_Engine *re = NULL; | ||
183 | |||
184 | LOGFN(__FILE__, __LINE__, __FUNCTION__); | ||
185 | |||
186 | if (!(re = (Render_Engine *)data)) return; | ||
187 | |||
188 | if (re->ob) re->outbuf_resize(re->ob, w, h); | ||
189 | if (re->tb) evas_common_tilebuf_free(re->tb); | ||
190 | if ((re->tb = evas_common_tilebuf_new(w, h))) | ||
191 | evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE); | ||
192 | } | ||
193 | |||
194 | static void | ||
195 | eng_output_tile_size_set(void *data, int w, int h) | ||
196 | { | ||
197 | Render_Engine *re = NULL; | ||
198 | |||
199 | if (!(re = (Render_Engine *)data)) return; | ||
200 | if (re->tb) evas_common_tilebuf_set_tile_size(re->tb, w, h); | ||
201 | } | ||
202 | |||
203 | static void | ||
204 | eng_output_redraws_rect_add(void *data, int x, int y, int w, int h) | ||
205 | { | ||
206 | Render_Engine *re = NULL; | ||
207 | |||
208 | if (!(re = (Render_Engine *)data)) return; | ||
209 | if (re->tb) evas_common_tilebuf_add_redraw(re->tb, x, y, w, h); | ||
210 | } | ||
211 | |||
212 | static void | ||
213 | eng_output_redraws_rect_del(void *data, int x, int y, int w, int h) | ||
214 | { | ||
215 | Render_Engine *re = NULL; | ||
216 | |||
217 | if (!(re = (Render_Engine *)data)) return; | ||
218 | if (re->tb) evas_common_tilebuf_del_redraw(re->tb, x, y, w, h); | ||
219 | } | ||
220 | |||
221 | static void | ||
222 | eng_output_redraws_clear(void *data) | ||
223 | { | ||
224 | Render_Engine *re = NULL; | ||
225 | |||
226 | if (!(re = (Render_Engine *)data)) return; | ||
227 | if (re->tb) evas_common_tilebuf_clear(re->tb); | ||
228 | } | ||
229 | |||
230 | static void * | ||
231 | eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch) | ||
232 | { | ||
233 | Render_Engine *re = NULL; | ||
234 | RGBA_Image *surface; | ||
235 | Tilebuf_Rect *rect; | ||
236 | int ux = 0, uy = 0, uw = 0, uh = 0; | ||
237 | |||
238 | if (!(re = (Render_Engine *)data)) return NULL; | ||
239 | if (re->end) | ||
240 | { | ||
241 | re->end = EINA_FALSE; | ||
242 | return NULL; | ||
243 | } | ||
244 | if (!re->rects) | ||
245 | { | ||
246 | re->rects = evas_common_tilebuf_get_render_rects(re->tb); | ||
247 | re->cur_rect = EINA_INLIST_GET(re->rects); | ||
248 | } | ||
249 | if (!re->cur_rect) return NULL; | ||
250 | rect = (Tilebuf_Rect *)re->cur_rect; | ||
251 | ux = rect->x; | ||
252 | uy = rect->y; | ||
253 | uw = rect->w; | ||
254 | uh = rect->h; | ||
255 | re->cur_rect = re->cur_rect->next; | ||
256 | if (!re->cur_rect) | ||
257 | { | ||
258 | evas_common_tilebuf_free_render_rects(re->rects); | ||
259 | re->rects = NULL; | ||
260 | re->end = EINA_TRUE; | ||
261 | } | ||
262 | if ((ux + uw) > re->ob->w) uw = re->ob->w - ux; | ||
263 | if ((uy + uh) > re->ob->h) uh = re->ob->h - uy; | ||
264 | if ((uw <= 0) || (uh <= 0)) return NULL; | ||
265 | surface = | ||
266 | re->outbuf_new_region_for_update(re->ob, ux, uy, uw, uh, cx, cy, cw, ch); | ||
267 | if (x) *x = ux; | ||
268 | if (y) *y = uy; | ||
269 | if (w) *w = uw; | ||
270 | if (h) *h = uh; | ||
271 | return surface; | ||
272 | } | ||
273 | |||
274 | static void | ||
275 | eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h) | ||
276 | { | ||
277 | Render_Engine *re = NULL; | ||
278 | |||
279 | if (!(re = (Render_Engine *)data)) return; | ||
280 | #ifdef BUILD_PIPE_RENDER | ||
281 | evas_common_pipe_map_begin(surface); | ||
282 | #endif | ||
283 | if (re->ob) | ||
284 | { | ||
285 | re->outbuf_push_updated_region(re->ob, surface, x, y, w, h); | ||
286 | re->outbuf_free_region_for_update(re->ob, surface); | ||
287 | } | ||
288 | evas_common_cpu_end_opt(); | ||
289 | } | ||
290 | |||
291 | static void | ||
292 | eng_output_flush(void *data) | ||
293 | { | ||
294 | Render_Engine *re = NULL; | ||
295 | |||
296 | if (!(re = (Render_Engine *)data)) return; | ||
297 | } | ||
298 | |||
299 | static void | ||
300 | eng_output_idle_flush(void *data) | ||
301 | { | ||
302 | Render_Engine *re = NULL; | ||
303 | |||
304 | if (!(re = (Render_Engine *)data)) return; | ||
305 | } | ||
306 | |||
307 | static Eina_Bool | ||
308 | eng_canvas_alpha_get(void *data, void *context __UNUSED__) | ||
309 | { | ||
310 | Render_Engine *re = NULL; | ||
311 | |||
312 | if (!(re = (Render_Engine *)data)) return EINA_FALSE; | ||
313 | return EINA_TRUE; | ||
314 | } | ||
315 | |||
316 | /* module functions */ | ||
317 | static int | ||
318 | module_open(Evas_Module *em) | ||
319 | { | ||
320 | if (!em) return 0; | ||
321 | |||
322 | if (!_evas_module_engine_inherit(&pfunc, "software_generic")) | ||
323 | return 0; | ||
324 | |||
325 | _evas_engine_way_shm_log_dom = | ||
326 | eina_log_domain_register("evas-wayland_shm", EVAS_DEFAULT_LOG_COLOR); | ||
327 | if (_evas_engine_way_shm_log_dom < 0) | ||
328 | { | ||
329 | EINA_LOG_ERR("Could not create a module log domain."); | ||
330 | return 0; | ||
331 | } | ||
332 | |||
333 | func = pfunc; | ||
334 | |||
335 | #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_) | ||
336 | ORD(info); | ||
337 | ORD(info_free); | ||
338 | ORD(setup); | ||
339 | ORD(canvas_alpha_get); | ||
340 | ORD(output_free); | ||
341 | ORD(output_resize); | ||
342 | ORD(output_tile_size_set); | ||
343 | ORD(output_redraws_rect_add); | ||
344 | ORD(output_redraws_rect_del); | ||
345 | ORD(output_redraws_clear); | ||
346 | ORD(output_redraws_next_update_get); | ||
347 | ORD(output_redraws_next_update_push); | ||
348 | ORD(output_flush); | ||
349 | ORD(output_idle_flush); | ||
350 | |||
351 | em->functions = (void *)(&func); | ||
352 | return 1; | ||
353 | } | ||
354 | |||
355 | static void | ||
356 | module_close(Evas_Module *em __UNUSED__) | ||
357 | { | ||
358 | eina_log_domain_unregister(_evas_engine_way_shm_log_dom); | ||
359 | } | ||
360 | |||
361 | static Evas_Module_Api evas_modapi = | ||
362 | { | ||
363 | EVAS_MODULE_API_VERSION, "wayland_shm", "none", {module_open, module_close} | ||
364 | }; | ||
365 | |||
366 | EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, wayland_shm); | ||
367 | |||
368 | #ifndef EVAS_STATIC_BUILD_WAYLAND_SHM | ||
369 | EVAS_EINA_MODULE_DEFINE(engine, wayland_shm); | ||
370 | #endif | ||