1 #include "evas_common.h"
2 #include "evas_private.h"
3 #include "evas_engine.h"
4 #include "Evas_Engine_Software_16_X11.h"
5 #include "evas_common_soft16.h"
7 int _evas_engine_soft16_x11_log_dom = -1;
8 /* function tables - filled in later (func and parent func) */
9 static Evas_Func func, pfunc;
17 static struct xrdb_user xrdb_user = {0, 0, NULL};
20 xrdb_user_query(const char *name, const char *cls, char **type, XrmValue *val)
22 time_t last = xrdb_user.last_stat, now = time(NULL);
24 xrdb_user.last_stat = now;
25 if (last != now) /* don't stat() more than once every second */
28 const char *home = getenv("HOME");
31 if (!home) goto failed;
32 snprintf(tmp, sizeof(tmp), "%s/.Xdefaults", home);
33 if (stat(tmp, &st) != 0) goto failed;
34 if (xrdb_user.last_mtime != st.st_mtime)
36 if (xrdb_user.db) XrmDestroyDatabase(xrdb_user.db);
37 xrdb_user.db = XrmGetFileDatabase(tmp);
38 if (!xrdb_user.db) goto failed;
39 xrdb_user.last_mtime = st.st_mtime;
43 if (!xrdb_user.db) return EINA_FALSE;
44 return XrmGetResource(xrdb_user.db, name, cls, type, val);
49 XrmDestroyDatabase(xrdb_user.db);
52 xrdb_user.last_mtime = 0;
56 /* engine struct data */
57 typedef struct _Render_Engine Render_Engine;
67 Tilebuf_Rect *cur_rect;
69 XrmDatabase xrdb; // xres - dpi
70 struct { // xres - dpi
71 int dpi; // xres - dpi
74 X_Output_Buffer *shbuf;
75 Soft16_Image *tmp_out; /* used by indirect render, like rotation */
77 unsigned char end : 1;
78 unsigned char shm : 1;
81 /* prototypes we will use here */
83 static void *eng_info(Evas *e);
84 static void eng_info_free(Evas *e, void *info);
85 static int eng_setup(Evas *e, void *info);
86 static void eng_output_free(void *data);
87 static void eng_output_resize(void *data, int w, int h);
88 static void eng_output_tile_size_set(void *data, int w, int h);
89 static void eng_output_redraws_rect_add(void *data, int x, int y, int w, int h);
90 static void eng_output_redraws_rect_del(void *data, int x, int y, int w, int h);
91 static void eng_output_redraws_clear(void *data);
92 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);
93 static void eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h);
94 static void eng_output_flush(void *data);
95 static void eng_output_idle_flush(void *data);
97 /* engine api this module provides */
101 Evas_Engine_Info_Software_16_X11 *info;
103 info = calloc(1, sizeof(Evas_Engine_Info_Software_16_X11));
104 if (!info) return NULL;
105 info->magic.magic = rand();
106 info->render_mode = EVAS_RENDER_MODE_BLOCKING;
112 eng_info_free(Evas *e __UNUSED__, void *info)
114 Evas_Engine_Info_Software_16_X11 *in;
115 in = (Evas_Engine_Info_Software_16_X11 *)info;
120 _tmp_out_alloc(Render_Engine *re)
125 EINA_INLIST_FOREACH(re->rects, r)
127 if (r->w > w) w = r->w;
128 if (r->h > h) h = r->h;
133 if ((re->tmp_out->cache_entry.w < w) || (re->tmp_out->cache_entry.h < h))
135 evas_cache_image_drop(&re->tmp_out->cache_entry);
144 im = (Soft16_Image *) evas_cache_image_empty(evas_common_soft16_image_cache_get());
145 im->cache_entry.flags.alpha = 0;
146 evas_cache_image_surface_alloc(&im->cache_entry, w, h);
154 eng_setup(Evas *e, void *in)
157 Evas_Engine_Info_Software_16_X11 *info;
158 /* X_Output_Buffer *xob; */
161 info = (Evas_Engine_Info_Software_16_X11 *)in;
162 if (!e->engine.data.output)
164 /* the only check - simplistic, i know, but enough for this
165 * "special purpose" engine. Remember it is meant to be used
166 * for limited power devices that have a 16bit display mode
167 * and no real other acceleration, and high resolution so we
168 * can pre-dither into 16bpp. */
169 // if (DefaultDepth(info->info.display,
170 // DefaultScreen(info->info.display)) != 16)
172 /* do common routine init - we wil at least use it for core
173 * image loading and font loading/glyph rendering & placement */
174 evas_common_cpu_init();
176 evas_common_blend_init();
177 evas_common_image_init();
178 evas_common_convert_init();
179 evas_common_scale_init();
180 evas_common_rectangle_init();
181 evas_common_gradient_init();
182 evas_common_polygon_init();
183 evas_common_line_init();
184 evas_common_font_init();
185 evas_common_draw_init();
186 evas_common_tilebuf_init();
187 evas_common_soft16_image_init();
189 /* render engine specific data */
190 re = calloc(1, sizeof(Render_Engine));
193 e->engine.data.output = re;
194 re->disp = info->info.display;
195 re->draw = info->info.drawable;
196 re->gc = XCreateGC(re->disp, re->draw, 0, &gcv);
199 re->rot = info->info.rotation;
200 re->tb = evas_common_tilebuf_new(e->output.w, e->output.h);
202 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
206 /* we changed the info after first init - do a re-eval where
208 // if (DefaultDepth(info->info.display,
209 // DefaultScreen(info->info.display)) != 16)
211 re = e->engine.data.output;
212 if (re->tb) evas_common_tilebuf_free(re->tb);
213 re->disp = info->info.display;
214 re->draw = info->info.drawable;
215 XFreeGC(re->disp, re->gc);
216 re->gc = XCreateGC(re->disp, re->draw, 0, &gcv);
219 re->rot = info->info.rotation;
220 re->tb = evas_common_tilebuf_new(e->output.w, e->output.h);
222 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
225 evas_cache_image_drop(&re->tmp_out->cache_entry);
229 if (!e->engine.data.output) return 0;
237 re->xr.dpi = 75000; // dpy * 1000
239 status = xrdb_user_query("Xft.dpi", "Xft.Dpi", &type, &val);
240 if ((!status) || (!type))
242 if (!re->xrdb) re->xrdb = XrmGetDatabase(re->disp);
244 status = XrmGetResource(re->xrdb,
245 "Xft.dpi", "Xft.Dpi", &type, &val);
248 if ((status) && (type))
250 if (!strcmp(type, "String"))
252 const char *str, *dp;
255 dp = strchr(str, '.');
256 if (!dp) dp = strchr(str, ',');
263 buf = alloca(dp - str + 1);
264 strncpy(buf, str, dp - str);
266 len = strlen(dp + 1);
267 subdpi = atoi(dp + 1);
271 for (i = len; i < 3; i++) subdpi *= 10;
275 for (i = len; i > 3; i--) subdpi /= 10;
277 re->xr.dpi = atoi(buf) * 1000;
280 re->xr.dpi = atoi(str) * 1000;
283 evas_common_font_dpi_set(re->xr.dpi / 1000);
286 /* add a draw context if we dont have one */
287 if (!e->engine.data.context)
288 e->engine.data.context =
289 e->engine.func->context_new(e->engine.data.output);
290 /* check if the display can do shm */
291 re->shm = evas_software_x11_x_can_do_shm(re->disp);
297 eng_output_free(void *data)
301 re = (Render_Engine *)data;
303 // NOTE: XrmGetDatabase() result is shared per connection, do not free it.
304 // if (re->xrdb) XrmDestroyDatabase(re->xrdb);
306 if (re->shbuf) evas_software_x11_x_output_buffer_free(re->shbuf, 0);
307 if (re->clip_rects) XDestroyRegion(re->clip_rects);
308 if (re->gc) XFreeGC(re->disp, re->gc);
309 if (re->tb) evas_common_tilebuf_free(re->tb);
310 if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
311 if (re->tmp_out) evas_cache_image_drop(&re->tmp_out->cache_entry);
314 evas_common_font_shutdown();
315 evas_common_image_shutdown();
316 evas_common_soft16_image_shutdown();
320 eng_output_resize(void *data, int w, int h)
324 re = (Render_Engine *)data;
326 if ((re->w == w) && (re->h == h)) return;
328 evas_common_tilebuf_free(re->tb);
331 re->tb = evas_common_tilebuf_new(w, h);
333 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
336 evas_software_x11_x_output_buffer_free(re->shbuf, 0);
341 XDestroyRegion(re->clip_rects);
342 re->clip_rects = NULL;
346 evas_cache_image_drop(&re->tmp_out->cache_entry);
352 eng_output_tile_size_set(void *data, int w, int h)
356 re = (Render_Engine *)data;
357 evas_common_tilebuf_set_tile_size(re->tb, w, h);
361 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
365 re = (Render_Engine *)data;
366 evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
370 eng_output_redraws_rect_del(void *data, int x, int y, int w, int h)
374 re = (Render_Engine *)data;
375 evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
379 eng_output_redraws_clear(void *data)
383 re = (Render_Engine *)data;
384 evas_common_tilebuf_clear(re->tb);
388 _output_buffer_alloc(Render_Engine *re)
391 if (re->shbuf) return;
393 if ((re->rot == 0) || (re->rot == 180))
404 re->shbuf = evas_software_x11_x_output_buffer_new
405 (re->disp, DefaultVisual(re->disp, DefaultScreen(re->disp)),
406 DefaultDepth(re->disp, DefaultScreen(re->disp)),
411 eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
417 re = (Render_Engine *)data;
425 re->rects = evas_common_tilebuf_get_render_rects(re->tb);
426 if (!re->rects) return NULL;
428 re->cur_rect = re->rects;
429 _output_buffer_alloc(re);
430 if (re->rot != 0) _tmp_out_alloc(re); /* grows if required */
434 if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
439 ux = rect->x; uy = rect->y; uw = rect->w; uh = rect->h;
440 re->cur_rect = (Tilebuf_Rect *)((EINA_INLIST_GET(re->cur_rect))->next);
443 evas_common_tilebuf_free_render_rects(re->rects);
448 *x = ux; *y = uy; *w = uw; *h = uh;
451 *cx = ux; *cy = uy; *cw = uw; *ch = uh;
452 return re->shbuf->im;
456 *cx = 0; *cy = 0; *cw = uw; *ch = uh;
462 _blit_rot_90(Soft16_Image *dst, const Soft16_Image *src,
463 int out_x, int out_y, int w, int h)
469 dp = dst->pixels + (out_x +
470 (w + out_y - 1) * dst->stride);
472 for (y = 0; y < h; y++)
474 DATA16 *dp_itr, *sp_itr;
479 for (x = 0; x < w; x++)
484 dp_itr -= dst->stride;
492 _blit_rot_180(Soft16_Image *dst, const Soft16_Image *src,
493 int out_x, int out_y, int w, int h)
499 dp = dst->pixels + ((w + out_x - 1) +
500 (h + out_y - 1) * dst->stride);
502 for (y = 0; y < h; y++)
504 DATA16 *dp_itr, *sp_itr;
509 for (x = 0; x < w; x++)
522 _blit_rot_270(Soft16_Image *dst, const Soft16_Image *src,
523 int out_x, int out_y, int w, int h)
529 dp = dst->pixels + ((h + out_x - 1) +
530 out_y * dst->stride);
532 for (y = 0; y < h; y++)
534 DATA16 *dp_itr, *sp_itr;
539 for (x = 0; x < w; x++)
544 dp_itr += dst->stride;
552 _tmp_out_process(Render_Engine *re, int out_x, int out_y, int w, int h)
559 if ((w < 1) || (h < 1) || (out_x >= d->cache_entry.w) || (out_y >= d->cache_entry.h))
563 _blit_rot_90(d, s, out_x, out_y, w, h);
564 else if (re->rot == 180)
565 _blit_rot_180(d, s, out_x, out_y, w, h);
566 else if (re->rot == 270)
567 _blit_rot_270(d, s, out_x, out_y, w, h);
571 eng_output_redraws_next_update_push(void *data, void *surface __UNUSED__, int x, int y, int w, int h)
574 XRectangle r = { 0, 0, 0, 0 };
576 re = (Render_Engine *)data;
579 re->clip_rects = XCreateRegion();
588 else if (re->rot == 90)
595 else if (re->rot == 180)
602 else if (re->rot == 270)
611 _tmp_out_process(re, r.x, r.y, w, h);
612 XUnionRectWithRegion(&r, re->clip_rects, re->clip_rects);
616 eng_output_flush(void *data)
620 re = (Render_Engine *)data;
623 XSetRegion(re->disp, re->gc, re->clip_rects);
624 XDestroyRegion(re->clip_rects);
625 re->clip_rects = NULL;
629 evas_software_x11_x_output_buffer_paste
630 (re->shbuf, re->draw, re->gc, 0, 0, re->shbuf->im->cache_entry.w, re->shbuf->im->cache_entry.h, 1);
631 XSetClipMask(re->disp, re->gc, None);
635 eng_output_idle_flush(void *data)
639 re = (Render_Engine *)data;
642 evas_software_x11_x_output_buffer_free(re->shbuf, 0);
647 XDestroyRegion(re->clip_rects);
648 re->clip_rects = NULL;
652 evas_cache_image_drop(&re->tmp_out->cache_entry);
658 eng_canvas_alpha_get(void *data __UNUSED__, void *context __UNUSED__)
663 /* module advertising code */
665 module_open(Evas_Module *em)
667 static Eina_Bool xrm_inited = EINA_FALSE;
670 xrm_inited = EINA_TRUE;
675 /* get whatever engine module we inherit from */
676 if (!_evas_module_engine_inherit(&pfunc, "software_16")) return 0;
677 _evas_engine_soft16_x11_log_dom = eina_log_domain_register("EvasSoft16X11", EVAS_DEFAULT_LOG_COLOR);
678 if(_evas_engine_soft16_x11_log_dom < 0)
680 EINA_LOG_ERR("Impossible to create a log domain for the Soft16_X11 engine.\n");
684 /* store it for later use */
686 /* now to override methods */
687 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
691 ORD(canvas_alpha_get);
694 ORD(output_tile_size_set);
695 ORD(output_redraws_rect_add);
696 ORD(output_redraws_rect_del);
697 ORD(output_redraws_clear);
698 ORD(output_redraws_next_update_get);
699 ORD(output_redraws_next_update_push);
701 ORD(output_idle_flush);
702 /* now advertise out own api */
703 em->functions = (void *)(&func);
708 module_close(Evas_Module *em)
710 eina_log_domain_unregister(_evas_engine_soft16_x11_log_dom);
713 XrmDestroyDatabase(xrdb_user.db);
714 xrdb_user.last_stat = 0;
715 xrdb_user.last_mtime = 0;
720 static Evas_Module_Api evas_modapi =
722 EVAS_MODULE_API_VERSION,
731 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_16_x11);
733 #ifndef EVAS_STATIC_BUILD_SOFTWARE_16_X11
734 EVAS_EINA_MODULE_DEFINE(engine, software_16_x11);