From 2cb3f31fcb411a5a438936f427755206b1a915d6 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Mon, 12 Oct 2020 15:42:16 +0900 Subject: [PATCH] e_comp_wl_tbm: use capturable buffer at capture to file Change-Id: I13b28b64196d58fe066e6ed82dbdd3c78e72172b --- src/bin/e_comp_wl_capture.c | 24 ++++++++--------- src/bin/e_hwc_window.c | 9 ++++++- src/bin/e_info_server.c | 52 +++++++++++++++++++++++++++---------- src/bin/e_output.c | 31 +++++++++++++++------- 4 files changed, 80 insertions(+), 36 deletions(-) diff --git a/src/bin/e_comp_wl_capture.c b/src/bin/e_comp_wl_capture.c index bc901a0daa..4d7d977ce1 100644 --- a/src/bin/e_comp_wl_capture.c +++ b/src/bin/e_comp_wl_capture.c @@ -610,11 +610,11 @@ _e_capture_client_video_data_create(E_Client *ec) case E_COMP_WL_BUFFER_TYPE_VIDEO: /* capture_data->buffer_ref.buffer can indicate NULL pointer * if wl_buffer is destroyed later. */ - capture_data->tbm_surface = buffer->tbm_surface; - if (!capture_data->tbm_surface) goto err; + if (!buffer->tbm_surface) goto err; - /* Referencing tbm_surface_h to prevent it from being freed. */ - tbm_surface_internal_ref(capture_data->tbm_surface); + /* already capturable tbm_surface is referenced */ + capture_data->tbm_surface = e_comp_wl_tbm_capturable_buffer_get(buffer->tbm_surface); + if (!capture_data->tbm_surface) goto err; break; default: ERR("Unsupported buffer type(%d) win(0x%08zx) name(%s)", @@ -1220,16 +1220,16 @@ _e_capture_client_child_data_create(Thread_Data *td, E_Client *ec) tbm_surface = wayland_tbm_server_get_surface(e_comp_wl->tbm.server, buffer->resource); if (!tbm_surface) goto end; - tbm_surface_internal_ref(tbm_surface); - capture_data->tbm_surface = tbm_surface; + capture_data->tbm_surface = e_comp_wl_tbm_capturable_buffer_get(tbm_surface); + if (!capture_data->tbm_surface) goto end; break; case E_COMP_WL_BUFFER_TYPE_TBM: tbm_surface = buffer->tbm_surface; if (!tbm_surface) goto end; - tbm_surface_internal_ref(tbm_surface); - capture_data->tbm_surface = tbm_surface; + capture_data->tbm_surface = e_comp_wl_tbm_capturable_buffer_get(tbm_surface); + if (!capture_data->tbm_surface) goto end; break; default: @@ -1530,15 +1530,15 @@ _e_capture_client_save(E_Capture_Client *ecc, tbm_surface = wayland_tbm_server_get_surface(e_comp_wl->tbm.server, buffer->resource); if (!tbm_surface) goto end; - tbm_surface_internal_ref(tbm_surface); - td->tbm_surface = tbm_surface; + td->tbm_surface = e_comp_wl_tbm_capturable_buffer_get(tbm_surface); + if (!td->tbm_surface) goto end; break; case E_COMP_WL_BUFFER_TYPE_TBM: tbm_surface = buffer->tbm_surface; if (!tbm_surface) goto end; - tbm_surface_internal_ref(tbm_surface); - td->tbm_surface = tbm_surface; + td->tbm_surface = e_comp_wl_tbm_capturable_buffer_get(tbm_surface); + if (!td->tbm_surface) goto end; break; default: goto end; diff --git a/src/bin/e_hwc_window.c b/src/bin/e_hwc_window.c index ee56efb0d5..a5c6a9e0f3 100644 --- a/src/bin/e_hwc_window.c +++ b/src/bin/e_hwc_window.c @@ -2546,11 +2546,14 @@ e_hwc_window_trace_debug(Eina_Bool onoff) EINTERN void e_hwc_window_commit_data_buffer_dump(E_Hwc_Window *hwc_window, E_Hwc_Window_Commit_Data *commit_data) { + tbm_surface_h capturable_tsurface; char fname[64]; EINA_SAFETY_ON_FALSE_RETURN(hwc_window); EINA_SAFETY_ON_FALSE_RETURN(commit_data); + if (!commit_data->buffer.tsurface) return; + if (hwc_window->is_target) snprintf(fname, sizeof(fname), "hwc_commit_composite_%p", hwc_window); @@ -2558,8 +2561,12 @@ e_hwc_window_commit_data_buffer_dump(E_Hwc_Window *hwc_window, E_Hwc_Window_Comm snprintf(fname, sizeof(fname), "hwc_commit_0x%08zx_%p", e_client_util_win_get(hwc_window->ec), hwc_window); - tbm_surface_internal_dump_buffer(commit_data->buffer.tsurface, + capturable_tsurface = e_comp_wl_tbm_capturable_buffer_get(commit_data->buffer.tsurface); + EINA_SAFETY_ON_NULL_RETURN(capturable_tsurface); + + tbm_surface_internal_dump_buffer(capturable_tsurface, fname); + tbm_surface_internal_unref(capturable_tsurface); } EINTERN Eina_Bool diff --git a/src/bin/e_info_server.c b/src/bin/e_info_server.c index 7b1afa7c8b..3dd4bc5557 100644 --- a/src/bin/e_info_server.c +++ b/src/bin/e_info_server.c @@ -2774,7 +2774,7 @@ static void _e_info_server_cb_wins_dump_ns(const char *dir) E_Client *ec; Evas_Native_Surface *ns = NULL; Evas_Object *co = NULL; // native surface set - tbm_surface_h tbm_surface = NULL; + tbm_surface_h tbm_surface = NULL, capturable_tbm_surface = NULL; char fname[PATH_MAX]; const char *bltin_t = NULL; @@ -2820,15 +2820,26 @@ static void _e_info_server_cb_wins_dump_ns(const char *dir) { case EVAS_NATIVE_SURFACE_WL: snprintf(fname, sizeof(fname), "%s/0x%08zx_wl_%p.png", dir, win, co); - if (ns->data.wl.legacy_buffer) - tbm_surface = wayland_tbm_server_get_surface(NULL, ns->data.wl.legacy_buffer); - if (tbm_surface) - tdm_helper_dump_buffer(tbm_surface, fname); + if (!ns->data.wl.legacy_buffer) continue; + + tbm_surface = wayland_tbm_server_get_surface(NULL, ns->data.wl.legacy_buffer); + if (!tbm_surface) continue; + + capturable_tbm_surface = e_comp_wl_tbm_capturable_buffer_get(tbm_surface); + if (!capturable_tbm_surface) continue; + + tdm_helper_dump_buffer(capturable_tbm_surface, fname); + tbm_surface_internal_unref(capturable_tbm_surface); break; case EVAS_NATIVE_SURFACE_TBM: snprintf(fname, sizeof(fname), "%s/0x%08zx_tbm_%p.png", dir, win, co); - if (ns->data.tbm.buffer) - tdm_helper_dump_buffer(ns->data.tbm.buffer, fname); + if (!ns->data.tbm.buffer) continue; + + capturable_tbm_surface = e_comp_wl_tbm_capturable_buffer_get(ns->data.tbm.buffer); + if (!capturable_tbm_surface) continue; + + tdm_helper_dump_buffer(capturable_tbm_surface, fname); + tbm_surface_internal_unref(capturable_tbm_surface); break; default: break; @@ -2860,6 +2871,7 @@ static void _e_info_server_cb_wins_dump_hwc_wins(const char *dir) { char fname[PATH_MAX]; tbm_format fmt; + tbm_surface_h capturable_tbm_surface; if (!hwc_window) continue; if (!hwc_window->display.buffer.tsurface) continue; @@ -2875,7 +2887,11 @@ static void _e_info_server_cb_wins_dump_hwc_wins(const char *dir) snprintf(fname, sizeof(fname), "0x%08zx_hwin_%p_tbm_%p", e_client_util_win_get(hwc_window->ec), hwc_window, hwc_window->display.buffer.tsurface); - tbm_surface_internal_capture_buffer(hwc_window->display.buffer.tsurface, dir, fname, "png"); + capturable_tbm_surface = e_comp_wl_tbm_capturable_buffer_get(hwc_window->display.buffer.tsurface); + if (!capturable_tbm_surface) continue; + + tbm_surface_internal_capture_buffer(capturable_tbm_surface, dir, fname, "png"); + tbm_surface_internal_unref(capturable_tbm_surface); break; case TBM_FORMAT_YUV420: case TBM_FORMAT_YVU420: @@ -2889,7 +2905,11 @@ static void _e_info_server_cb_wins_dump_hwc_wins(const char *dir) snprintf(fname, sizeof(fname), "0x%08zx_hwin_%p_tbm_%p", e_client_util_win_get(hwc_window->ec), hwc_window, hwc_window->display.buffer.tsurface); - tbm_surface_internal_capture_buffer(hwc_window->display.buffer.tsurface, dir, fname, "yuv"); + capturable_tbm_surface = e_comp_wl_tbm_capturable_buffer_get(hwc_window->display.buffer.tsurface); + if (!capturable_tbm_surface) continue; + + tbm_surface_internal_capture_buffer(capturable_tbm_surface, dir, fname, "png"); + tbm_surface_internal_unref(capturable_tbm_surface); break; default: break; @@ -4315,7 +4335,7 @@ _e_info_server_cb_buffer_change(void *data, int type, void *event) Ecore_Window event_win; char fname[PATH_MAX]; E_Comp_Wl_Buffer *buffer; - tbm_surface_h tbm_surface; + tbm_surface_h tbm_surface, capturable_tbm_surface; struct wl_shm_buffer *shmbuffer = NULL; void *ptr; int stride, w, h, rotation, row, col; @@ -4386,6 +4406,9 @@ _e_info_server_cb_buffer_change(void *data, int type, void *event) tbm_surface = wayland_tbm_server_get_surface(NULL, buffer->resource); EINA_SAFETY_ON_NULL_RETURN_VAL(tbm_surface, ECORE_CALLBACK_PASS_ON); + capturable_tbm_surface = e_comp_wl_tbm_capturable_buffer_get(tbm_surface); + EINA_SAFETY_ON_NULL_RETURN_VAL(capturable_tbm_surface, ECORE_CALLBACK_PASS_ON); + if (e_info_dump_mark) { unsigned int colors[5] = {0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFF00FFFF, 0xFFFF00FF}; @@ -4393,8 +4416,8 @@ _e_info_server_cb_buffer_change(void *data, int type, void *event) int box_size = 20; int box = e_info_dump_mark_count * box_size; - w = tbm_surface_get_width(tbm_surface); - h = tbm_surface_get_height(tbm_surface); + w = tbm_surface_get_width(capturable_tbm_surface); + h = tbm_surface_get_height(capturable_tbm_surface); EINA_SAFETY_ON_FALSE_RETURN_VAL((w != 0), ECORE_CALLBACK_PASS_ON); EINA_SAFETY_ON_FALSE_RETURN_VAL((h != 0), ECORE_CALLBACK_PASS_ON); @@ -4407,11 +4430,12 @@ _e_info_server_cb_buffer_change(void *data, int type, void *event) pos.w = box_size; pos.h = box_size; - tdm_helper_clear_buffer_color(tbm_surface, &pos, colors[e_info_dump_mark_count % 5]); + tdm_helper_clear_buffer_color(capturable_tbm_surface, &pos, colors[e_info_dump_mark_count % 5]); e_info_dump_mark_count++; } - tbm_surface_internal_dump_buffer(tbm_surface, fname); + tbm_surface_internal_dump_buffer(capturable_tbm_surface, fname); + tbm_surface_internal_unref(capturable_tbm_surface); break; default: DBG("Unknown type resource:%u", wl_resource_get_id(buffer->resource)); diff --git a/src/bin/e_output.c b/src/bin/e_output.c index 21fa0a5a54..c53229076f 100644 --- a/src/bin/e_output.c +++ b/src/bin/e_output.c @@ -1980,7 +1980,7 @@ _e_output_vbuf_capture_hwc_windows(E_Output *output, E_Hwc_Window *hwc_window, E { int w = 0, h = 0; E_Comp_Wl_Video_Buf *tmp = NULL; - tbm_surface_h surface = NULL; + tbm_surface_h tsurface = NULL, capturable_tsurface = NULL; Eina_Rectangle showing_pos = {0, }; Eina_Rectangle dst_pos = {0, }; Eina_Rectangle src_crop = {0, }; @@ -1989,10 +1989,13 @@ _e_output_vbuf_capture_hwc_windows(E_Output *output, E_Hwc_Window *hwc_window, E e_output_size_get(output, &w, &h); - surface = e_hwc_window_displaying_surface_get(hwc_window); - if (!surface) return EINA_FALSE; + tsurface = e_hwc_window_displaying_surface_get(hwc_window); + if (!tsurface) return EINA_FALSE; - tmp = e_comp_wl_video_buffer_create_tbm(surface); + capturable_tsurface = e_comp_wl_tbm_capturable_buffer_get(tsurface); + if (!capturable_tsurface) return EINA_FALSE; + + tmp = e_comp_wl_video_buffer_create_tbm(capturable_tsurface); if (tmp == NULL) return EINA_FALSE; @@ -2015,6 +2018,7 @@ _e_output_vbuf_capture_hwc_windows(E_Output *output, E_Hwc_Window *hwc_window, E ret = EINA_TRUE; done: + tbm_surface_internal_unref(capturable_tsurface); e_comp_wl_video_buffer_unref(tmp); return ret; @@ -2124,7 +2128,7 @@ _e_output_vbuf_capture(E_Output *output, E_Comp_Wl_Video_Buf *vbuf, int rotate, E_Comp_Wl_Video_Buf *tmp = NULL; tdm_layer *layer; tdm_layer_capability capability; - tbm_surface_h surface = NULL; + tbm_surface_h tsurface = NULL, capturable_tsurface = NULL; Eina_Rectangle showing_pos = {0, }; Eina_Rectangle dst_pos = {0, }; Eina_Rectangle src_crop = {0, }; @@ -2142,17 +2146,24 @@ _e_output_vbuf_capture(E_Output *output, E_Comp_Wl_Video_Buf *vbuf, int rotate, if (capability & TDM_LAYER_CAPABILITY_VIDEO) continue; - surface = tdm_layer_get_displaying_buffer(layer, &error); - if (surface == NULL) + tsurface = tdm_layer_get_displaying_buffer(layer, &error); + if (tsurface == NULL) continue; - tmp = e_comp_wl_video_buffer_create_tbm(surface); + capturable_tsurface = e_comp_wl_tbm_capturable_buffer_get(tsurface); + if (!capturable_tsurface) continue; + + tmp = e_comp_wl_video_buffer_create_tbm(tsurface); if (tmp == NULL) - continue; + { + tbm_surface_internal_unref(capturable_tsurface); + continue; + } ret = _e_output_capture_src_crop_get(output, layer, &src_crop, &showing_pos); if (ret == EINA_FALSE) { + tbm_surface_internal_unref(capturable_tsurface); e_comp_wl_video_buffer_unref(tmp); continue; } @@ -2160,6 +2171,7 @@ _e_output_vbuf_capture(E_Output *output, E_Comp_Wl_Video_Buf *vbuf, int rotate, ret = _e_output_capture_position_get(output, vbuf->width, vbuf->height, &dst_pos, rotate_check); if (ret == EINA_FALSE) { + tbm_surface_internal_unref(capturable_tsurface); e_comp_wl_video_buffer_unref(tmp); continue; } @@ -2172,6 +2184,7 @@ _e_output_vbuf_capture(E_Output *output, E_Comp_Wl_Video_Buf *vbuf, int rotate, dst_crop.x, dst_crop.y, dst_crop.w, dst_crop.h, EINA_TRUE, rotate, 0, 0); + tbm_surface_internal_unref(capturable_tsurface); e_comp_wl_video_buffer_unref(tmp); } -- 2.34.1