e_comp_wl_tbm: use capturable buffer at capture to file 47/245547/10
authorChangyeon Lee <cyeon.lee@samsung.com>
Mon, 12 Oct 2020 06:42:16 +0000 (15:42 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Tue, 27 Oct 2020 08:05:17 +0000 (17:05 +0900)
Change-Id: I13b28b64196d58fe066e6ed82dbdd3c78e72172b

src/bin/e_comp_wl_capture.c
src/bin/e_hwc_window.c
src/bin/e_info_server.c
src/bin/e_output.c

index bc901a0daa996aa9daaec845ce20ebb4a5237496..4d7d977ce143864132beffcf4f8ae80e46cfc9a8 100644 (file)
@@ -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;
index ee56efb0d5a22c4fe66a1501d3cab2d7dce75cfa..a5c6a9e0f3e3f89949fff472189b9158b850181c 100644 (file)
@@ -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
index 7b1afa7c8bbd541b276a0b6689a70e8fc365fa5a..3dd4bc55572f9188af097f658f97ba7f1abeaf98 100644 (file)
@@ -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));
index 21fa0a5a548a3ec3b24d82f66b74ca02ad3b2f6e..c53229076f4ab4167dac67eb093dd9fd9dc7e4f8 100644 (file)
@@ -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);
      }