From 1f242afdefd27cc11eb71bc598f4e7903ceb5ea9 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Mon, 18 Sep 2017 19:30:30 +0900 Subject: [PATCH] evas: Use Eina.Size2D for gfx.buffer For consistency. --- src/bin/elementary/test_evas_snapshot.c | 4 +--- src/examples/evas/evas-3d-proxy.c | 6 +++--- src/lib/efl/interfaces/efl_gfx_buffer.eo | 19 +++++----------- src/lib/elementary/efl_ui_win.c | 8 +++++-- src/lib/evas/canvas/efl_canvas_image.c | 37 +++++++++++++++++++++----------- src/lib/evas/canvas/efl_canvas_proxy.c | 20 +++++++++++++---- src/lib/evas/canvas/efl_canvas_scene3d.c | 19 ++++++++++++++-- src/lib/evas/canvas/evas_image_legacy.c | 5 ++++- src/lib/evas/canvas/evas_object_image.c | 19 ++++++++++++++-- 9 files changed, 93 insertions(+), 44 deletions(-) diff --git a/src/bin/elementary/test_evas_snapshot.c b/src/bin/elementary/test_evas_snapshot.c index 6259019..a6d41eb 100644 --- a/src/bin/elementary/test_evas_snapshot.c +++ b/src/bin/elementary/test_evas_snapshot.c @@ -62,7 +62,6 @@ _render_post(void *data, const Efl_Event *ev) static void _save_image(void *data, const Efl_Event *ev EINA_UNUSED) { - Eina_Size2D sz; Eo *win = data; Eo *snap; @@ -75,8 +74,7 @@ _save_image(void *data, const Efl_Event *ev EINA_UNUSED) // This is a special case handled by snapshot for the purpose of taking // screenshots like this. This is useful only if the button click has no // animation on screen and there is no spinning wheel either. - sz = efl_gfx_size_get(snap); - efl_gfx_buffer_update_add(snap, 0, 0, sz.w, sz.h); + efl_gfx_buffer_update_add(snap, NULL); } static void diff --git a/src/examples/evas/evas-3d-proxy.c b/src/examples/evas/evas-3d-proxy.c index 3c89ebe..06032c7 100644 --- a/src/examples/evas/evas-3d-proxy.c +++ b/src/examples/evas/evas-3d-proxy.c @@ -84,7 +84,7 @@ _animate_scene(void *data) #ifdef USE_EO_IMAGE Eina_Rw_Slice slice; - if (!efl_gfx_buffer_map(source, &slice, EFL_GFX_BUFFER_ACCESS_MODE_WRITE, 0, 0, 0, 0, + if (!efl_gfx_buffer_map(source, &slice, EFL_GFX_BUFFER_ACCESS_MODE_WRITE, NULL, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride)) return EINA_TRUE; pixels = slice.mem; @@ -105,7 +105,7 @@ _animate_scene(void *data) #ifdef USE_EO_IMAGE efl_gfx_buffer_unmap(source, &slice); - efl_gfx_buffer_update_add(source, 0, 0, IMG_WIDTH, IMG_HEIGHT); + efl_gfx_buffer_update_add(source, NULL); #else evas_object_image_data_set(source, pixels); evas_object_image_data_update_add(source, 0, 0, IMG_WIDTH, IMG_HEIGHT); @@ -227,7 +227,7 @@ main(void) /* Add a background image. */ #ifdef USE_EO_IMAGE source = efl_add(EFL_CANVAS_IMAGE_CLASS, evas); - efl_gfx_buffer_copy_set(source, NULL, IMG_WIDTH, IMG_HEIGHT, 0, EFL_GFX_COLORSPACE_ARGB8888, 0); + efl_gfx_buffer_copy_set(source, NULL, EINA_SIZE2D(IMG_WIDTH, IMG_HEIGHT), 0, EFL_GFX_COLORSPACE_ARGB8888, 0); efl_gfx_position_set(source, EINA_POSITION2D((WIDTH / 2), (HEIGHT / 2))); efl_gfx_size_set(source, EINA_SIZE2D((WIDTH / 2), (HEIGHT / 2))); efl_gfx_visible_set(source, EINA_TRUE); diff --git a/src/lib/efl/interfaces/efl_gfx_buffer.eo b/src/lib/efl/interfaces/efl_gfx_buffer.eo index 9da3b41..f355a79 100644 --- a/src/lib/efl/interfaces/efl_gfx_buffer.eo +++ b/src/lib/efl/interfaces/efl_gfx_buffer.eo @@ -24,8 +24,7 @@ interface Efl.Gfx.Buffer () } get {} values { - w: int; [[Width in pixels.]] - h: int; [[Height in pixels.]] + sz: Eina.Size2D; [[Size of the buffer in pixels.]] } } @property colorspace { @@ -96,10 +95,7 @@ interface Efl.Gfx.Buffer () image object to be updated (redrawn) at the next rendering cycle. ]] params { - @in x: int; [[X-offset of the region to be updated.]] - @in y: int; [[Y-offset of the region to be updated.]] - @in w: int; [[Width of the region to be updated.]] - @in h: int; [[Height of the region to be updated.]] + @in region: const(ptr(Eina.Rect)) @optional; [[The updated region.]] } } @@ -136,10 +132,7 @@ interface Efl.Gfx.Buffer () @out slice: Eina.Rw_Slice; [[Pointer to the top-left pixel data.]] @in mode: Efl.Gfx.Buffer.Access_Mode; [[Specifies whether to map for read-only, write-only or read-write access (OR combination of flags).]] - @in x: int @optional; [[X position of the top-left pixel to map, defaults to 0.]] - @in y: int @optional; [[Y position of the top-left pixel to map, defaults to 0.]] - @in w: int @optional; [[If 0, defaults to the buffer width.]] - @in h: int @optional; [[If 0, defaults to the buffer height.]] + @in region: const(ptr(Eina.Rect)) @optional; [[The region to map.]] @in cspace: Efl.Gfx.Colorspace @optional; [[Requested colorspace. If different from the internal cspace, map should try to convert the data into a new buffer. argb8888 by default.]] @@ -182,8 +175,7 @@ interface Efl.Gfx.Buffer () ]] params { @in slice: ptr(const(Eina.Slice)) @nullable; [[If $null, allocates an empty buffer]] - @in width: int; [[Width]] - @in height: int; [[Height]] + @in size: Eina.Size2D; [[The size in pixels.]] @in stride: int @optional; [[If 0, automatically guessed from the $width.]] @in cspace: Efl.Gfx.Colorspace @optional; [[argb8888 by default.]] @in plane: int @optional; [[Plane ID. 0 by default. Useful for planar formats only.]] @@ -208,8 +200,7 @@ interface Efl.Gfx.Buffer () ]] params { @in slice: ptr(const(Eina.Slice)) @nullable; [[If $null, detaches the previous buffer.]] - @in width: int; [[Width]] - @in height: int; [[Height]] + @in size: Eina.Size2D; [[The size in pixels.]] @in stride: int @optional; [[If 0, automatically guessed from the $width.]] @in cspace: Efl.Gfx.Colorspace @optional; [[argb8888 by default.]] @in plane: int @optional; [[Plane ID. 0 by default. Useful for planar formats only.]] diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c index 7cf004a..4fad992 100644 --- a/src/lib/elementary/efl_ui_win.c +++ b/src/lib/elementary/efl_ui_win.c @@ -3286,11 +3286,15 @@ _elm_win_xwin_update(Efl_Ui_Win_Data *sd) if (efl_isa(image, EFL_CANVAS_IMAGE_CLASS)) { + Eina_Rect rect = {}; + unmap = EINA_TRUE; - efl_gfx_buffer_size_get(image, &w, &h); + rect.size = efl_gfx_buffer_size_get(image); efl_gfx_buffer_map(image, &sl, EFL_GFX_BUFFER_ACCESS_MODE_READ, - 0, 0, w, h, EFL_GFX_COLORSPACE_ARGB8888, 0, + &rect, EFL_GFX_COLORSPACE_ARGB8888, 0, &stride); + w = rect.w; + h = rect.h; } else { diff --git a/src/lib/evas/canvas/efl_canvas_image.c b/src/lib/evas/canvas/efl_canvas_image.c index 6a42af1..71d16c9 100644 --- a/src/lib/evas/canvas/efl_canvas_image.c +++ b/src/lib/evas/canvas/efl_canvas_image.c @@ -617,13 +617,12 @@ _efl_canvas_image_efl_image_animated_animated_frame_get(Eo *eo_obj, void *_pd EI return _evas_image_animated_frame_get(eo_obj); } -EOLIAN static void -_efl_canvas_image_efl_gfx_buffer_buffer_size_get(Eo *eo_obj, void *_pd EINA_UNUSED EINA_UNUSED, int *w, int *h) +EOLIAN static Eina_Size2D +_efl_canvas_image_efl_gfx_buffer_buffer_size_get(Eo *eo_obj, void *_pd EINA_UNUSED EINA_UNUSED) { Evas_Image_Data *o = efl_data_scope_get(eo_obj, EFL_CANVAS_IMAGE_INTERNAL_CLASS); - if (w) *w = o->cur->image.w; - if (h) *h = o->cur->image.h; + return EINA_SIZE2D(o->cur->image.w, o->cur->image.h); } static Eina_Bool @@ -731,32 +730,32 @@ end: if (resized) evas_object_inform_call_image_resize(obj->object); - efl_gfx_buffer_update_add(obj->object, 0, 0, w, h); + efl_gfx_buffer_update_add(obj->object, NULL); return ret; } EOLIAN static Eina_Bool _efl_canvas_image_efl_gfx_buffer_buffer_managed_set(Eo *eo_obj, void *_pd EINA_UNUSED, const Eina_Slice *slice, - int w, int h, int stride, + Eina_Size2D size, int stride, Efl_Gfx_Colorspace cspace, int plane) { Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS); Evas_Image_Data *o = efl_data_scope_get(eo_obj, EFL_CANVAS_IMAGE_INTERNAL_CLASS); - return _image_pixels_set(obj, o, slice, w, h, stride, cspace, plane, EINA_FALSE); + return _image_pixels_set(obj, o, slice, size.w, size.h, stride, cspace, plane, EINA_FALSE); } EOLIAN static Eina_Bool _efl_canvas_image_efl_gfx_buffer_buffer_copy_set(Eo *eo_obj, void *_pd EINA_UNUSED, - const Eina_Slice *slice, int w, int h, int stride, + const Eina_Slice *slice, Eina_Size2D size, int stride, Efl_Gfx_Colorspace cspace, int plane) { Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS); Evas_Image_Data *o = efl_data_scope_get(eo_obj, EFL_CANVAS_IMAGE_INTERNAL_CLASS); - return _image_pixels_set(obj, o, slice, w, h, stride, cspace, plane, EINA_TRUE); + return _image_pixels_set(obj, o, slice, size.w, size.h, stride, cspace, plane, EINA_TRUE); } EOLIAN static Eina_Bool @@ -782,7 +781,7 @@ EOLIAN static Eina_Bool _efl_canvas_image_efl_gfx_buffer_buffer_map(Eo *eo_obj, void *_pd EINA_UNUSED, Eina_Rw_Slice *slice, Efl_Gfx_Buffer_Access_Mode mode, - int x, int y, int w, int h, + const Eina_Rect *region, Efl_Gfx_Colorspace cspace, int plane, int *stride) { @@ -790,6 +789,7 @@ _efl_canvas_image_efl_gfx_buffer_buffer_map(Eo *eo_obj, void *_pd EINA_UNUSED, Evas_Image_Data *o = efl_data_scope_get(eo_obj, EFL_CANVAS_IMAGE_INTERNAL_CLASS); int s = 0, width = 0, height = 0; Eina_Bool ret = EINA_FALSE; + int x, y, w, h; EINA_SAFETY_ON_NULL_RETURN_VAL(slice, EINA_FALSE); @@ -810,10 +810,21 @@ _efl_canvas_image_efl_gfx_buffer_buffer_map(Eo *eo_obj, void *_pd EINA_UNUSED, goto end; } - if (!w) w = width; - if (!h) h = height; + if (region) + { + x = region->x; + y = region->y; + w = region->w; + h = region->h; + } + else + { + x = y = 0; + w = width; + h = height; + } - if ((x < 0) || (y < 0) || ((x + w) > width) || ((y + h) > height)) + if ((x < 0) || (y < 0) || (w <= 0) || (h <= 0) || ((x + w) > width) || ((y + h) > height)) { ERR("Invalid map dimensions: %dx%d +%d,%d. Image is %dx%d.", w, h, x, y, width, height); diff --git a/src/lib/evas/canvas/efl_canvas_proxy.c b/src/lib/evas/canvas/efl_canvas_proxy.c index 19773af..26bbd94 100644 --- a/src/lib/evas/canvas/efl_canvas_proxy.c +++ b/src/lib/evas/canvas/efl_canvas_proxy.c @@ -263,7 +263,7 @@ EOLIAN static Eina_Bool _efl_canvas_proxy_efl_gfx_buffer_buffer_map(Eo *eo_obj, void *_pd EINA_UNUSED, Eina_Rw_Slice *slice, Efl_Gfx_Buffer_Access_Mode mode, - int x, int y, int w, int h, + const Eina_Rect *region, Efl_Gfx_Colorspace cspace, int plane, int *stride) { @@ -271,6 +271,7 @@ _efl_canvas_proxy_efl_gfx_buffer_buffer_map(Eo *eo_obj, void *_pd EINA_UNUSED, Evas_Image_Data *o = efl_data_scope_get(eo_obj, EFL_CANVAS_IMAGE_INTERNAL_CLASS); int s = 0, width = 0, height = 0; Eina_Bool ret = EINA_FALSE; + int x, y, w, h; void *image; EINA_SAFETY_ON_NULL_RETURN_VAL(slice, EINA_FALSE); @@ -305,10 +306,21 @@ _efl_canvas_proxy_efl_gfx_buffer_buffer_map(Eo *eo_obj, void *_pd EINA_UNUSED, goto end; } - if (!w) w = width; - if (!h) h = height; + if (region) + { + x = region->x; + y = region->y; + w = region->w; + h = region->h; + } + else + { + x = y = 0; + w = width; + h = height; + } - if ((x < 0) || (y < 0) || ((x + w) > width) || ((y + h) > height)) + if ((x < 0) || (y < 0) || (w <= 0) || (h <= 0) || ((x + w) > width) || ((y + h) > height)) { ERR("Invalid map dimensions: %dx%d +%d,%d. Image is %dx%d.", w, h, x, y, width, height); diff --git a/src/lib/evas/canvas/efl_canvas_scene3d.c b/src/lib/evas/canvas/efl_canvas_scene3d.c index 2601940..6b6dc35 100644 --- a/src/lib/evas/canvas/efl_canvas_scene3d.c +++ b/src/lib/evas/canvas/efl_canvas_scene3d.c @@ -212,7 +212,7 @@ EOLIAN static Eina_Bool _efl_canvas_scene3d_efl_gfx_buffer_buffer_map(Eo *eo_obj, void *_pd EINA_UNUSED, Eina_Rw_Slice *slice, Efl_Gfx_Buffer_Access_Mode mode, - int x, int y, int w, int h, + const Eina_Rect *region, Efl_Gfx_Colorspace cspace, int plane, int *stride) { @@ -222,6 +222,7 @@ _efl_canvas_scene3d_efl_gfx_buffer_buffer_map(Eo *eo_obj, void *_pd EINA_UNUSED, Evas_Canvas3D_Scene_Data *pd_scene; int width = -1, height = -1, ntex = -1; unsigned char *pixels = NULL; + int x, y, w, h; size_t len = 0; EINA_SAFETY_ON_NULL_RETURN_VAL(slice, EINA_FALSE); @@ -255,7 +256,21 @@ _efl_canvas_scene3d_efl_gfx_buffer_buffer_map(Eo *eo_obj, void *_pd EINA_UNUSED, pd_scene->surface, &width, &height); } - if ((x < 0) || (y < 0) || ((x + w) > width) || ((y + h) > height)) + if (region) + { + x = region->x; + y = region->y; + w = region->w; + h = region->h; + } + else + { + x = y = 0; + w = width; + h = height; + } + + if ((x < 0) || (y < 0) || (w <= 0) || (h <= 0) || ((x + w) > width) || ((y + h) > height)) { ERR("Invalid map dimensions : %dx%d +%d,%d. Image is %dx%d.", w, h, x, y, width, height); diff --git a/src/lib/evas/canvas/evas_image_legacy.c b/src/lib/evas/canvas/evas_image_legacy.c index c78c97d..29ea9e0 100644 --- a/src/lib/evas/canvas/evas_image_legacy.c +++ b/src/lib/evas/canvas/evas_image_legacy.c @@ -181,8 +181,11 @@ evas_object_image_stride_get(const Evas_Object *obj) EAPI void evas_object_image_data_update_add(Evas_Object *obj, int x, int y, int w, int h) { + Eina_Rect r; + EVAS_IMAGE_API(obj); - efl_gfx_buffer_update_add(obj, x, y, w, h); + r = EINA_RECT(x, y, w, h); + efl_gfx_buffer_update_add(obj, &r); } EAPI void diff --git a/src/lib/evas/canvas/evas_object_image.c b/src/lib/evas/canvas/evas_object_image.c index 0bc3fe7..7d56927 100644 --- a/src/lib/evas/canvas/evas_object_image.c +++ b/src/lib/evas/canvas/evas_object_image.c @@ -732,12 +732,27 @@ _efl_canvas_image_internal_efl_gfx_view_view_size_get(Eo *eo_obj, Evas_Image_Dat } EOLIAN static void -_efl_canvas_image_internal_efl_gfx_buffer_buffer_update_add(Eo *eo_obj, Evas_Image_Data *o, int x, int y, int w, int h) +_efl_canvas_image_internal_efl_gfx_buffer_buffer_update_add(Eo *eo_obj, Evas_Image_Data *o, const Eina_Rect *region) { Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS); Eina_Rectangle *r; + int x, y, w, h; int cnt; + if (region) + { + x = region->x; + y = region->y; + w = region->w; + h = region->h; + } + else + { + x = y = 0; + w = o->cur->image.w; + h = o->cur->image.h; + } + RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, o->cur->image.w, o->cur->image.h); if ((w <= 0) || (h <= 0)) return; if (obj->cur->snapshot) @@ -826,7 +841,7 @@ _efl_canvas_image_internal_efl_gfx_buffer_alpha_set(Eo *eo_obj, Evas_Image_Data } o->written = EINA_TRUE; } - efl_gfx_buffer_update_add(eo_obj, 0, 0, o->cur->image.w, o->cur->image.h); + efl_gfx_buffer_update_add(eo_obj, NULL); EVAS_OBJECT_WRITE_IMAGE_FREE_FILE_AND_KEY(o); } -- 2.7.4