evas/cserve2: Use scalecache with cserve2

Let's reuse the logic from scalecache and call cserve2
functions when the scalecache should be used.
So, now, cserve2 server will not scale any image... This is
too computationally intensive for the server's main thread.

This is not optimal but makes a hell of a lot more sense for
the moment. (since cserve2 manages the SHM segments)
This commit is contained in:
Jean-Philippe Andre 2013-09-23 17:51:06 +09:00
parent fc73405c40
commit 1e82480c9a
8 changed files with 68 additions and 101 deletions

View File

@ -320,7 +320,7 @@ void cserve2_cache_client_del(Client *client);
int cserve2_cache_file_open(Client *client, unsigned int client_file_id, const char *path, const char *key, unsigned int rid, Evas_Image_Load_Opts *lo);
void cserve2_cache_file_close(Client *client, unsigned int client_file_id);
int cserve2_cache_image_entry_create(Client *client, int rid, unsigned int client_file_id, unsigned int image_id, Evas_Image_Load_Opts *opts);
void cserve2_rgba_image_scale_do(void *src_data, void *dst_data, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int alpha, int smooth);
void cserve2_rgba_image_scale_do(void *src_data, int src_full_w, int src_full_h, void *dst_data, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int alpha, int smooth);
void cserve2_cache_image_load(Client *client, unsigned int client_image_id, unsigned int rid);
void cserve2_cache_image_preload(Client *client, unsigned int client_image_id, unsigned int rid);
void cserve2_cache_image_unload(Client *client, unsigned int client_image_id);

View File

@ -506,6 +506,8 @@ _image_loaded_msg_create(Image_Entry *ientry, Image_Data *idata, int *size)
msg->shm.mmap_size = cserve2_shm_map_size_get(ientry->shm);
msg->shm.image_size = cserve2_shm_size_get(ientry->shm);
msg->alpha_sparse = idata->alpha_sparse;
msg->image.w = idata->w;
msg->image.h = idata->h;
if (idata->shm_id)
{
@ -805,7 +807,9 @@ _scaling_do(Shm_Handle *scale_shm, Image_Data *idata, Image_Entry *original)
char *scale_map, *orig_map;
void *src_data, *dst_data;
File_Data *fd;
Image_Data *orig_idata;
#warning FIXME Remove this call, add alpha flag to Image_Data
fd = _file_data_find(idata->file_id);
if (!fd)
{
@ -814,6 +818,13 @@ _scaling_do(Shm_Handle *scale_shm, Image_Data *idata, Image_Entry *original)
return -1;
}
orig_idata = _image_data_find(original->base.id);
if (!orig_idata)
{
ERR("Could not find image %u", original->base.id);
return -1;
}
scale_map = cserve2_shm_map(scale_shm);
if (scale_map == MAP_FAILED)
{
@ -833,14 +844,16 @@ _scaling_do(Shm_Handle *scale_shm, Image_Data *idata, Image_Entry *original)
src_data = orig_map + cserve2_shm_map_offset_get(original->shm);
dst_data = scale_map + cserve2_shm_map_offset_get(scale_shm);
DBG("Scaling image ([%d,%d:%dx%d] --> [%d,%d:%dx%d])",
DBG("Scaling image ([%dx%d]:[%d,%d:%dx%d] --> [%d,%d:%dx%d])",
orig_idata->w, orig_idata->h,
idata->opts.scale_load.src_x, idata->opts.scale_load.src_y,
idata->opts.scale_load.src_w, idata->opts.scale_load.src_h,
0, 0,
idata->opts.scale_load.dst_w, idata->opts.scale_load.dst_h);
cserve2_rgba_image_scale_do(
src_data, dst_data,
src_data, orig_idata->w, orig_idata->h,
dst_data,
idata->opts.scale_load.src_x, idata->opts.scale_load.src_y,
idata->opts.scale_load.src_w, idata->opts.scale_load.src_h,
0, 0,
@ -875,6 +888,8 @@ _scaling_prepare_and_do(Image_Entry *ientry, Image_Data *idata)
cserve2_shared_string_del(idata->shm_id);
ientry->shm = scale_shm;
idata->shm_id = 0;
idata->w = idata->opts.scale_load.dst_w;
idata->h = idata->opts.scale_load.dst_h;
return 0;
}
@ -895,6 +910,9 @@ _load_request_response(Image_Entry *ientry,
if (!idata->doload)
DBG("Entry %d loaded by speculative preload.", idata->id);
idata->w = resp->w;
idata->h = resp->h;
if (_scaling_needed(idata, resp))
{
DBG("About to scale image %u", idata->id);
@ -2781,7 +2799,7 @@ do_scaling:
CSERVE2_REQ_IMAGE_LOAD,
0, NULL, 0, &_load_funcs, orig_entry);
}
if (orig_entry->base.request || !orig_entry->shm)
if (orig_entry->base.request || !orig_entry->shm || !orig_data->valid)
return -1; // Not loaded yet
if (ientry->shm)

View File

@ -32,7 +32,8 @@ _cserve2_rgba_image_set(RGBA_Image *im, void *data, int w, int h, int alpha)
}
void
cserve2_rgba_image_scale_do(void *src_data, void *dst_data,
cserve2_rgba_image_scale_do(void *src_data, int src_full_w, int src_full_h,
void *dst_data,
int src_x, int src_y, int src_w, int src_h,
int dst_x, int dst_y, int dst_w, int dst_h,
int alpha, int smooth)
@ -40,8 +41,7 @@ cserve2_rgba_image_scale_do(void *src_data, void *dst_data,
RGBA_Image src, dst;
RGBA_Draw_Context ct;
_cserve2_rgba_image_set(&src, src_data, src_w, src_h, alpha);
_cserve2_rgba_image_set(&src, src_data, src_full_w, src_full_h, alpha);
_cserve2_rgba_image_set(&dst, dst_data, dst_w, dst_h, alpha);
dst.flags = RGBA_IMAGE_NOTHING;

View File

@ -799,7 +799,8 @@ evas_cache2_image_open_wait(Image_Entry *im)
}
static Image_Entry *
_scaled_image_find(Image_Entry *im, int src_x, int src_y, int src_w, int src_h, int dst_w, int dst_h, int smooth)
_scaled_image_find(Image_Entry *im, int src_x, int src_y, int src_w,
int src_h, int dst_w, int dst_h, int smooth)
{
size_t pathlen, keylen, size;
char *hkey;

View File

@ -3998,53 +3998,15 @@ evas_object_image_render(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj, v
(o->cur->border.b == 0) &&
(o->cur->border.fill != 0))
{
#ifdef EVAS_CSERVE2
if (evas_cserve2_use_get())
{
Image_Entry *ie;
void *data = pixels;
int w = imagew, h = imageh;
Eina_Bool mustclose = EINA_FALSE;
ie = evas_cache2_image_scale_load
((Image_Entry *)pixels,
0, 0,
imagew, imageh,
iw, ih, o->cur->smooth_scale);
if (ie != &((RGBA_Image *)pixels)->cache_entry)
{
data = ie;
w = iw;
h = ih;
mustclose = EINA_TRUE;
}
_draw_image
(obj, output, context, surface, data,
0, 0,
w, h,
obj->cur->geometry.x + ix + x,
obj->cur->geometry.y + iy + y,
iw, ih,
o->cur->smooth_scale,
do_async);
if (mustclose)
evas_cache2_image_close(ie);
}
else
#endif
{
_draw_image
(obj, output, context, surface, pixels,
0, 0,
imagew, imageh,
obj->cur->geometry.x + ix + x,
obj->cur->geometry.y + iy + y,
iw, ih,
o->cur->smooth_scale,
do_async);
}
_draw_image
(obj, output, context, surface, pixels,
0, 0,
imagew, imageh,
obj->cur->geometry.x + ix + x,
obj->cur->geometry.y + iy + y,
iw, ih,
o->cur->smooth_scale,
do_async);
}
else
{

View File

@ -759,6 +759,26 @@ evas_common_rgba_image_scalecache_do_cbs(Image_Entry *ie, RGBA_Image *dst,
}
}
}
#ifdef EVAS_CSERVE2
if (sci->populate_me && (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
&& evas_cserve2_use_get() && evas_cache2_image_cached(&im->cache_entry))
{
RGBA_Image *im2 = (RGBA_Image *) evas_cache2_image_scale_load
(&im->cache_entry, src_region_x, src_region_y,
src_region_w, src_region_h, dst_region_w, dst_region_h, smooth);
SLKL(cache_lock);
if (im2 != im)
{
sci->im = im2;
sci->populate_me = 0;
cache_list = eina_inlist_append(cache_list, (Eina_Inlist *)sci);
didpop = 1;
}
SLKU(cache_lock);
}
#endif
if (sci->populate_me)
{
// INF("##! populate!");

View File

@ -90,6 +90,9 @@ struct _Msg_Loaded {
int mmap_size;
int image_size;
} shm;
struct {
unsigned int w, h; // Real dimensions of this image. May differ from Msg_Opened::image::{w,h} after scaling.
} image;
Eina_Bool alpha_sparse : 1;
};
@ -354,6 +357,7 @@ struct _Image_Data {
uint32_t file_id;
string_t shm_id;
Evas_Image_Load_Opts opts;
uint32_t w, h;
Eina_Bool alpha_sparse : 1;
Eina_Bool unused : 1;
Eina_Bool doload : 1;

View File

@ -1352,52 +1352,14 @@ eng_image_draw(void *data EINA_UNUSED, void *context, void *surface, void *image
#endif
else
{
#if 0
#ifdef EVAS_CSERVE2
if (evas_cserve2_use_get())
{
evas_cache2_image_load_data(&im->cache_entry);
goto image_loaded;
}
#endif
if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
evas_cache_image_load_data(&im->cache_entry);
evas_common_image_colorspace_normalize(im);
image_loaded:
#endif
#ifdef EVAS_CSERVE2
if (evas_cserve2_use_get())
{
if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
evas_cache2_image_load_data(&im->cache_entry);
if (!im->cache_entry.flags.loaded) return EINA_FALSE;
evas_common_image_colorspace_normalize(im);
if (smooth)
evas_common_scale_rgba_in_to_out_clip_smooth
(im, surface, context,
src_x, src_y, src_w, src_h,
dst_x, dst_y, dst_w, dst_h);
else
evas_common_scale_rgba_in_to_out_clip_sample
(im, surface, context,
src_x, src_y, src_w, src_h,
dst_x, dst_y, dst_w, dst_h);
}
else
#endif
{
evas_common_rgba_image_scalecache_prepare
(&im->cache_entry, surface, context, smooth,
src_x, src_y, src_w, src_h,
dst_x, dst_y, dst_w, dst_h);
evas_common_rgba_image_scalecache_do
(&im->cache_entry, surface, context, smooth,
src_x, src_y, src_w, src_h,
dst_x, dst_y, dst_w, dst_h);
}
evas_common_rgba_image_scalecache_prepare
(&im->cache_entry, surface, context, smooth,
src_x, src_y, src_w, src_h,
dst_x, dst_y, dst_w, dst_h);
evas_common_rgba_image_scalecache_do
(&im->cache_entry, surface, context, smooth,
src_x, src_y, src_w, src_h,
dst_x, dst_y, dst_w, dst_h);
evas_common_cpu_end_opt();
}