evas: simplify Wayland_SHM backend to use software generic infrastructure.

This commit is contained in:
Cedric BAIL 2014-06-27 10:16:36 +02:00
parent e4a4304dc4
commit 0fdf8fab3a
4 changed files with 82 additions and 415 deletions

View File

@ -9,48 +9,16 @@ typedef struct _Render_Engine Render_Engine;
struct _Render_Engine
{
Evas_Engine_Info_Wayland_Shm *info;
Outbuf *ob;
Tilebuf *tb;
Render_Engine_Software_Generic generic;
Tilebuf_Rect *rects;
Tilebuf_Rect *prev_rects[3];
Eina_Inlist *cur_rect;
short mode;
Eina_Bool end : 1;
Eina_Bool lost_back : 1;
/* function pointers for output buffer functions that we can
* override based on if we are swapping or not */
void (*outbuf_free)(Outbuf *ob);
void (*outbuf_reconfigure)(Outbuf *ob, int x, int y, int w, int h, unsigned int rotation, Outbuf_Depth depth, Eina_Bool alpha);
RGBA_Image *(*outbuf_update_region_new)(Outbuf *ob, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch);
void (*outbuf_update_region_push)(Outbuf *ob, RGBA_Image *update, int x, int y, int w, int h);
void (*outbuf_update_region_free)(Outbuf *ob, RGBA_Image *update);
void (*outbuf_flush)(Outbuf *ob);
void (*outbuf_idle_flush)(Outbuf *ob);
void (*outbuf_reconfigure)(Outbuf *ob, int x, int y, int w, int h, int rot, Outbuf_Depth depth, Eina_Bool alpha);
};
/* local function prototypes */
static void *_output_engine_setup(int w, int h, unsigned int rotation, unsigned int depth, Eina_Bool destination_alpha, struct wl_shm *wl_shm, struct wl_surface *wl_surface, int try_swap);
static Tilebuf_Rect *_merge_rects(Tilebuf *tb, Tilebuf_Rect *r1, Tilebuf_Rect *r2, Tilebuf_Rect *r3);
/* engine function prototypes */
static void *eng_info(Evas *eo_evas EINA_UNUSED);
static void eng_info_free(Evas *eo_evas EINA_UNUSED, void *einfo);
static int eng_setup(Evas *eo_evas, void *einfo);
static void eng_output_free(void *data);
static void eng_output_resize(void *data, int w, int h);
static void eng_output_tile_size_set(void *data, int w, int h);
static void eng_output_redraws_rect_add(void *data, int x, int y, int w, int h);
static void eng_output_redraws_rect_del(void *data, int x, int y, int w, int h);
static void eng_output_redraws_clear(void *data);
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);
static void eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h, Evas_Render_Mode render_mode);
static void eng_output_flush(void *data, Evas_Render_Mode render_mode);
static void eng_output_idle_flush(void *data);
/* local variables */
static Evas_Func func, pfunc;
@ -60,107 +28,50 @@ int _evas_engine_way_shm_log_dom = -1;
/* local functions */
static void *
_output_engine_setup(int w, int h, unsigned int rotation, unsigned int depth, Eina_Bool destination_alpha, struct wl_shm *wl_shm, struct wl_surface *wl_surface, int try_swap)
_output_engine_setup(Evas_Engine_Info_Wayland_Shm *info,
int w, int h,
unsigned int rotation, unsigned int depth,
Eina_Bool destination_alpha,
struct wl_shm *wl_shm,
struct wl_surface *wl_surface)
{
Render_Engine *re = NULL;
Outbuf *ob;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
/* try to allocate a new render engine */
if (!(re = calloc(1, sizeof(Render_Engine))))
if (!(re = calloc(1, sizeof(Render_Engine))))
return NULL;
/* try to create a new tilebuf first */
if (!(re->tb = evas_common_tilebuf_new(w, h)))
{
free(re);
return NULL;
}
/* set tile size for the tile buffer */
evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
ob = evas_swapbuf_setup(info, w, h, rotation, depth,
destination_alpha, wl_shm,
wl_surface);
if (!ob) goto on_error;
if (try_swap)
{
if ((re->ob = evas_swapbuf_setup(w, h, rotation, depth,
destination_alpha, wl_shm,
wl_surface)))
{
re->outbuf_free = evas_swapbuf_free;
re->outbuf_reconfigure = evas_swapbuf_reconfigure;
re->outbuf_update_region_new = evas_swapbuf_update_region_new;
re->outbuf_update_region_push = evas_swapbuf_update_region_push;
re->outbuf_update_region_free = evas_swapbuf_update_region_free;
re->outbuf_flush = evas_swapbuf_flush;
re->outbuf_idle_flush = evas_swapbuf_idle_flush;
}
}
if (!evas_render_engine_software_generic_init(&re->generic, ob,
evas_swapbuf_state_get,
evas_swapbuf_rotation_get,
NULL,
evas_swapbuf_update_region_new,
evas_swapbuf_update_region_push,
evas_swapbuf_update_region_free,
evas_swapbuf_idle_flush,
evas_swapbuf_flush,
evas_swapbuf_free,
w, h))
goto on_error;
/* if creating an output buffer failed, then return NULL */
if (!re->ob)
{
if (re->tb) evas_common_tilebuf_free(re->tb);
free(re);
return NULL;
}
re->outbuf_reconfigure = evas_swapbuf_reconfigure;
/* return allocated render engine */
return re;
}
static Tilebuf_Rect *
_merge_rects(Tilebuf *tb, Tilebuf_Rect *r1, Tilebuf_Rect *r2, Tilebuf_Rect *r3)
{
Tilebuf_Rect *r, *rects;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
if (r1)
{
EINA_INLIST_FOREACH(EINA_INLIST_GET(r1), r)
evas_common_tilebuf_add_redraw(tb, r->x, r->y, r->w, r->h);
}
if (r2)
{
EINA_INLIST_FOREACH(EINA_INLIST_GET(r2), r)
evas_common_tilebuf_add_redraw(tb, r->x, r->y, r->w, r->h);
}
if (r3)
{
EINA_INLIST_FOREACH(EINA_INLIST_GET(r3), r)
evas_common_tilebuf_add_redraw(tb, r->x, r->y, r->w, r->h);
}
rects = evas_common_tilebuf_get_render_rects(tb);
/*
// bounding box -> make a bounding box single region update of all regions.
// yes we could try and be smart and figure out size of regions, how far
// apart etc. etc. to try and figure out an optimal "set". this is a tradeoff
// between multiple update regions to render and total pixels to render.
if (rects)
{
px1 = rects->x; py1 = rects->y;
px2 = rects->x + rects->w; py2 = rects->y + rects->h;
EINA_INLIST_FOREACH(EINA_INLIST_GET(rects), r)
{
if (r->x < x1) px1 = r->x;
if (r->y < y1) py1 = r->y;
if ((r->x + r->w) > x2) px2 = r->x + r->w;
if ((r->y + r->h) > y2) py2 = r->y + r->h;
}
evas_common_tilebuf_free_render_rects(rects);
rects = calloc(1, sizeof(Tilebuf_Rect));
if (rects)
{
rects->x = px1;
rects->y = py1;
rects->w = px2 - px1;
rects->h = py2 - py1;
}
}
*/
evas_common_tilebuf_clear(tb);
return rects;
on_error:
if (ob) evas_swapbuf_free(ob);
free(re);
return NULL;
}
/* engine functions */
@ -234,49 +145,31 @@ eng_setup(Evas *eo_evas, void *einfo)
else try_swap = 1;
}
if (!(re =
_output_engine_setup(epd->output.w, epd->output.h,
if (!(re =
_output_engine_setup(info, epd->output.w, epd->output.h,
info->info.rotation, info->info.depth,
info->info.destination_alpha,
info->info.wl_shm, info->info.wl_surface,
try_swap)))
info->info.wl_shm, info->info.wl_surface)))
return 0;
re->info = info;
}
}
else
{
Outbuf *ob;
int ponebuf = 0;
if ((re) && (re->ob)) ponebuf = re->ob->onebuf;
if ((re) && (re->generic.ob)) ponebuf = re->generic.ob->onebuf;
/* free any existing tile buffer */
if (re->tb) evas_common_tilebuf_free(re->tb);
ob = evas_swapbuf_setup(info, epd->output.w, epd->output.h,
info->info.rotation,
info->info.depth,
info->info.destination_alpha,
info->info.wl_shm,
info->info.wl_surface);
if (!ob) return 0;
/* we have an existing output buffer, free it */
if (re->ob) re->outbuf_free(re->ob);
evas_render_engine_software_generic_update(&re->generic, ob);
/* create new tile buffer */
if ((re->tb = evas_common_tilebuf_new(epd->output.w, epd->output.h)))
evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
if ((re->ob = evas_swapbuf_setup(epd->output.w, epd->output.h,
info->info.rotation,
info->info.depth,
info->info.destination_alpha,
info->info.wl_shm,
info->info.wl_surface)))
{
re->outbuf_free = evas_swapbuf_free;
re->outbuf_reconfigure = evas_swapbuf_reconfigure;
re->outbuf_update_region_new = evas_swapbuf_update_region_new;
re->outbuf_update_region_push = evas_swapbuf_update_region_push;
re->outbuf_update_region_free = evas_swapbuf_update_region_free;
re->outbuf_flush = evas_swapbuf_flush;
re->outbuf_idle_flush = evas_swapbuf_idle_flush;
}
re->info = info;
if ((re) && (re->ob)) re->ob->onebuf = ponebuf;
if ((re) && (re->generic.ob)) re->generic.ob->onebuf = ponebuf;
}
/* reassign render engine to output */
@ -293,33 +186,20 @@ eng_setup(Evas *eo_evas, void *einfo)
return 1;
}
static void
static void
eng_output_free(void *data)
{
Render_Engine *re;
Render_Engine *re = data;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
if ((re = data))
{
re->outbuf_free(re->ob);
evas_common_tilebuf_free(re->tb);
if (re->rects)
evas_common_tilebuf_free_render_rects(re->rects);
if (re->prev_rects[0])
evas_common_tilebuf_free_render_rects(re->prev_rects[0]);
if (re->prev_rects[1])
evas_common_tilebuf_free_render_rects(re->prev_rects[1]);
if (re->prev_rects[2])
evas_common_tilebuf_free_render_rects(re->prev_rects[2]);
free(re);
}
evas_render_engine_software_generic_clean(&re->generic);
free(re);
evas_common_font_shutdown();
evas_common_image_shutdown();
}
static void
static void
eng_output_resize(void *data, int w, int h)
{
Render_Engine *re;
@ -327,235 +207,33 @@ eng_output_resize(void *data, int w, int h)
int dx = 0, dy = 0;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
if (!(re = (Render_Engine *)data)) return;
if (!(info = re->info)) return;
if (!(info = re->generic.ob->info)) return;
if (info->info.edges & 4)
{
if ((info->info.rotation == 90) || (info->info.rotation == 270))
dx = re->ob->h - h;
dx = re->generic.ob->h - h;
else
dx = re->ob->w - w;
dx = re->generic.ob->w - w;
}
if (info->info.edges & 1)
{
if ((info->info.rotation == 90) || (info->info.rotation == 270))
dy = re->ob->w - w;
dy = re->generic.ob->w - w;
else
dy = re->ob->h - h;
dy = re->generic.ob->h - h;
}
re->outbuf_reconfigure(re->ob, dx, dy, w, h,
re->outbuf_reconfigure(re->generic.ob, dx, dy, w, h,
info->info.rotation, info->info.depth,
info->info.destination_alpha);
evas_common_tilebuf_free(re->tb);
if ((re->tb = evas_common_tilebuf_new(w, h)))
evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
}
static void
eng_output_tile_size_set(void *data, int w, int h)
{
Render_Engine *re;
if (!(re = (Render_Engine *)data)) return;
if (re->tb) evas_common_tilebuf_set_tile_size(re->tb, w, h);
}
static void
eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
{
Render_Engine *re;
if (!(re = (Render_Engine *)data)) return;
evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
}
static void
eng_output_redraws_rect_del(void *data, int x, int y, int w, int h)
{
Render_Engine *re;
if (!(re = (Render_Engine *)data)) return;
if (re->tb) evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
}
static void
eng_output_redraws_clear(void *data)
{
Render_Engine *re;
if (!(re = (Render_Engine *)data)) return;
if (re->tb) evas_common_tilebuf_clear(re->tb);
}
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)
{
Render_Engine *re;
RGBA_Image *surface;
Tilebuf_Rect *rect;
Eina_Bool first_rect = EINA_FALSE;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
#define CLEAR_PREV_RECTS(x) \
do { \
if (re->prev_rects[x]) \
evas_common_tilebuf_free_render_rects(re->prev_rects[x]); \
re->prev_rects[x] = NULL; \
} while (0)
re = (Render_Engine *)data;
if (re->end)
{
re->end = 0;
return NULL;
}
if (!re->rects)
{
re->mode = evas_swapbuf_state_get(re->ob);
re->rects = evas_common_tilebuf_get_render_rects(re->tb);
if (re->rects)
{
if ((re->lost_back) || (re->mode == MODE_FULL))
{
/* if we lost our backbuffer since the last frame redraw all */
re->lost_back = 0;
evas_common_tilebuf_add_redraw(re->tb, 0, 0, re->ob->w, re->ob->h);
evas_common_tilebuf_free_render_rects(re->rects);
re->rects = evas_common_tilebuf_get_render_rects(re->tb);
}
/* ensure we get rid of previous rect lists we dont need if mode
* changed/is appropriate */
evas_common_tilebuf_clear(re->tb);
CLEAR_PREV_RECTS(2);
re->prev_rects[2] = re->prev_rects[1];
re->prev_rects[1] = re->prev_rects[0];
re->prev_rects[0] = re->rects;
re->rects = NULL;
switch (re->mode)
{
case MODE_FULL:
case MODE_COPY: // no prev rects needed
re->rects =
_merge_rects(re->tb, re->prev_rects[0], NULL, NULL);
break;
case MODE_DOUBLE: // double mode - only 1 level of prev rect
re->rects =
_merge_rects(re->tb, re->prev_rects[0], re->prev_rects[1], NULL);
break;
case MODE_TRIPLE: // keep all
re->rects =
_merge_rects(re->tb, re->prev_rects[0], re->prev_rects[1], re->prev_rects[2]);
break;
default:
break;
}
first_rect = EINA_TRUE;
}
evas_common_tilebuf_clear(re->tb);
re->cur_rect = EINA_INLIST_GET(re->rects);
}
if (!re->cur_rect) return NULL;
rect = (Tilebuf_Rect *)re->cur_rect;
if (re->rects)
{
switch (re->mode)
{
case MODE_COPY:
case MODE_DOUBLE:
case MODE_TRIPLE:
rect = (Tilebuf_Rect *)re->cur_rect;
*x = rect->x;
*y = rect->y;
*w = rect->w;
*h = rect->h;
*cx = rect->x;
*cy = rect->y;
*cw = rect->w;
*ch = rect->h;
re->cur_rect = re->cur_rect->next;
break;
case MODE_FULL:
re->cur_rect = NULL;
if (x) *x = 0;
if (y) *y = 0;
if (w) *w = re->ob->w;
if (h) *h = re->ob->h;
if (cx) *cx = 0;
if (cy) *cy = 0;
if (cw) *cw = re->ob->w;
if (ch) *ch = re->ob->h;
break;
default:
break;
}
if (first_rect)
{
// do anything needed for the first frame
}
surface =
re->outbuf_update_region_new(re->ob,
*x, *y, *w, *h,
cx, cy, cw, ch);
if (!re->cur_rect) re->end = EINA_TRUE;
return surface;
}
return NULL;
}
static void
eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h, Evas_Render_Mode render_mode)
{
Render_Engine *re;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
if (render_mode == EVAS_RENDER_MODE_ASYNC_INIT) return;
if (!(re = (Render_Engine *)data)) return;
#if defined(BUILD_PIPE_RENDER)
evas_common_pipe_map_begin(surface);
#endif
re->outbuf_update_region_push(re->ob, surface, x, y, w, h);
re->outbuf_update_region_free(re->ob, surface);
evas_common_cpu_end_opt();
}
static void
eng_output_flush(void *data, Evas_Render_Mode render_mode)
{
Render_Engine *re;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
if (render_mode == EVAS_RENDER_MODE_ASYNC_INIT) return;
if (!(re = (Render_Engine *)data)) return;
re->outbuf_flush(re->ob);
if (re->rects)
{
evas_common_tilebuf_free_render_rects(re->rects);
re->rects = NULL;
}
}
static void
eng_output_idle_flush(void *data)
{
Render_Engine *re;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
if (!(re = (Render_Engine *)data)) return;
re->outbuf_idle_flush(re->ob);
evas_common_tilebuf_free(re->generic.tb);
if ((re->generic.tb = evas_common_tilebuf_new(w, h)))
evas_common_tilebuf_set_tile_size(re->generic.tb, TILESIZE, TILESIZE);
}
/* module functions */
@ -591,14 +269,6 @@ module_open(Evas_Module *em)
ORD(setup);
ORD(output_free);
ORD(output_resize);
ORD(output_tile_size_set);
ORD(output_redraws_rect_add);
ORD(output_redraws_rect_del);
ORD(output_redraws_clear);
ORD(output_redraws_next_update_get);
ORD(output_redraws_next_update_push);
ORD(output_flush);
ORD(output_idle_flush);
/* advertise out our own api */
em->functions = (void *)(&func);

View File

@ -39,31 +39,20 @@ extern int _evas_engine_way_shm_log_dom;
# include <wayland-client.h>
typedef enum _Outbuf_Depth Outbuf_Depth;
#include "Evas_Engine_Wayland_Shm.h"
#include "../software_generic/Evas_Engine_Software_Generic.h"
typedef struct _Outbuf Outbuf;
enum _Outbuf_Depth
{
OUTBUF_DEPTH_NONE,
OUTBUF_DEPTH_ARGB_32BPP_8888_8888,
OUTBUF_DEPTH_RGB_32BPP_8888_8888,
OUTBUF_DEPTH_LAST
};
enum
{
MODE_FULL,
MODE_COPY,
MODE_DOUBLE,
MODE_TRIPLE
};
struct _Outbuf
{
Evas_Engine_Info_Wayland_Shm *info;
int w, h;
unsigned int rotation;
Outbuf_Depth depth;
int rotation;
int onebuf;
Outbuf_Depth depth;
struct
{

View File

@ -21,7 +21,7 @@
/* local function prototypes */
Outbuf *
evas_swapbuf_setup(int w, int h, unsigned int rotation, Outbuf_Depth depth, Eina_Bool alpha, struct wl_shm *wl_shm, struct wl_surface *wl_surface)
evas_swapbuf_setup(Evas_Engine_Info_Wayland_Shm *info, int w, int h, unsigned int rotation, Outbuf_Depth depth, Eina_Bool alpha, struct wl_shm *wl_shm, struct wl_surface *wl_surface)
{
Outbuf *ob = NULL;
@ -39,6 +39,7 @@ evas_swapbuf_setup(int w, int h, unsigned int rotation, Outbuf_Depth depth, Eina
ob->priv.destination_alpha = alpha;
ob->priv.wl.shm = wl_shm;
ob->priv.wl.surface = wl_surface;
ob->info = info;
if ((ob->rotation == 0) || (ob->rotation == 180))
{
@ -88,7 +89,7 @@ evas_swapbuf_free(Outbuf *ob)
}
void
evas_swapbuf_reconfigure(Outbuf *ob, int x, int y, int w, int h, unsigned int rotation, Outbuf_Depth depth, Eina_Bool alpha)
evas_swapbuf_reconfigure(Outbuf *ob, int x, int y, int w, int h, int rotation, Outbuf_Depth depth, Eina_Bool alpha)
{
LOGFN(__FILE__, __LINE__, __FUNCTION__);
@ -511,7 +512,7 @@ evas_swapbuf_idle_flush(Outbuf *ob EINA_UNUSED)
/* evas_swapper_buffer_idle_flush(ob->priv.swapper); */
}
int
Render_Engine_Swap_Mode
evas_swapbuf_state_get(Outbuf *ob)
{
int mode = 0;
@ -523,4 +524,10 @@ evas_swapbuf_state_get(Outbuf *ob)
return mode;
}
int
evas_swapbuf_rotation_get(Outbuf *ob)
{
return ob->rotation;
}
/* local functions */

View File

@ -3,14 +3,15 @@
# include "evas_engine.h"
Outbuf *evas_swapbuf_setup(int w, int h, unsigned int rotation, Outbuf_Depth depth, Eina_Bool alpha, struct wl_shm *wl_shm, struct wl_surface *wl_surface);
Outbuf *evas_swapbuf_setup(Evas_Engine_Info_Wayland_Shm *info, int w, int h, unsigned int rotation, Outbuf_Depth depth, Eina_Bool alpha, struct wl_shm *wl_shm, struct wl_surface *wl_surface);
void evas_swapbuf_free(Outbuf *ob);
void evas_swapbuf_reconfigure(Outbuf *ob, int x, int y, int w, int h, unsigned int rotation, Outbuf_Depth depth, Eina_Bool alpha);
void evas_swapbuf_reconfigure(Outbuf *ob, int x, int y, int w, int h, int rotation, Outbuf_Depth depth, Eina_Bool alpha);
RGBA_Image *evas_swapbuf_update_region_new(Outbuf *ob, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch);
void evas_swapbuf_update_region_push(Outbuf *ob, RGBA_Image *update, int x, int y, int w, int h);
void evas_swapbuf_update_region_free(Outbuf *ob, RGBA_Image *update);
void evas_swapbuf_flush(Outbuf *ob);
void evas_swapbuf_idle_flush(Outbuf *ob EINA_UNUSED);
int evas_swapbuf_state_get(Outbuf *ob);
Render_Engine_Swap_Mode evas_swapbuf_state_get(Outbuf *ob);
int evas_swapbuf_rotation_get(Outbuf *ob);
#endif