Tizen 2.4.0 rev3 SDK Public Release tizen_2.4
authorjk7744.park <jk7744.park@samsung.com>
Wed, 24 Feb 2016 09:51:07 +0000 (18:51 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Wed, 24 Feb 2016 09:51:07 +0000 (18:51 +0900)
evaspixmapsink/evaspixmapsink.c
evaspixmapsink/evaspixmapsink.h

index 05b1297..74a09ec 100755 (executable)
@@ -111,7 +111,7 @@ enum
 #define GST_TYPE_EVASPIXMAPSINK_ROTATE_ANGLE            (gst_evaspixmapsink_rotate_angle_get_type())
 #define GST_TYPE_EVASPIXMAPSINK_DISPLAY_GEOMETRY_METHOD (gst_evaspixmapsink_display_geometry_method_get_type())
 #define SIZE_FOR_UPDATE_VISIBILITY                      sizeof(gchar)
-#define EPIPE_REQUEST_LIMIT                             20
+#define EPIPE_REQUEST_LIMIT                             2
 
 static GType
 gst_evaspixmapsink_flip_get_type (void)
@@ -233,11 +233,6 @@ static gint gst_evaspixmapsink_get_format_from_info (GstXContext * context,
     GstVideoInfo * info);
 static void drm_close_gem (GstEvasPixmapSink * evaspixmapsink,
     unsigned int gem_handle);
-static void
-gst_evaspixmapsink_xpixmap_fillblack (tbm_bufmgr bufmgr, Display * disp,
-    Pixmap pixmap);
-static GstFlowReturn gst_evaspixmapsink_epipe_reset (GstEvasPixmapSink *
-    evaspixmapsink);
 #ifdef DUMP_IMG
 int util_write_rawdata (const char *file, const void *data, unsigned int size);
 int g_cnt = 0;
@@ -386,42 +381,32 @@ ecore_pipe_callback_handler (void *data, void *buffer, unsigned int nbyte)
       surf.data.x11.pixmap = evaspixmapsink->xpixmap[idx]->pixmap;
       evas_object_image_native_surface_set (evaspixmapsink->eo, &surf);
       evaspixmapsink->do_link = FALSE;
-      evaspixmapsink->last_updated_idx = idx;
     } else {
       GST_WARNING_OBJECT (evaspixmapsink, "pixmap is NULL..");
       return;
     }
-
-    /* flush previous pool */
-    for (i = 0; i < NUM_OF_PREV_PIXMAP; i++) {
-      if (evaspixmapsink->prev[i]->pixmap || evaspixmapsink->prev[i]->gc
-          || evaspixmapsink->prev[i]->damage)
+    for (i = 0; i < evaspixmapsink->num_of_pixmaps; i++) {
+      if (evaspixmapsink->xpixmap[i]->prev_pixmap
+          && evaspixmapsink->xpixmap[i]->prev_gc
+          && evaspixmapsink->prev_damage[i]) {
         GST_LOG_OBJECT (evaspixmapsink,
             "Free pixmap(%ld), gc(%p), destroy previous damage(%ld)",
-            evaspixmapsink->prev[i]->pixmap,
-            evaspixmapsink->prev[i]->gc, evaspixmapsink->prev[i]->damage);
-      g_mutex_lock (&evaspixmapsink->x_lock);
-      if (evaspixmapsink->prev[i]->pixmap)
+            evaspixmapsink->xpixmap[i]->prev_pixmap,
+            evaspixmapsink->xpixmap[i]->prev_gc,
+            evaspixmapsink->prev_damage[i]);
+        g_mutex_lock (&evaspixmapsink->x_lock);
         XFreePixmap (evaspixmapsink->xcontext->disp,
-            evaspixmapsink->prev[i]->pixmap);
-      if (evaspixmapsink->prev[i]->gc)
-        XFreeGC (evaspixmapsink->xcontext->disp, evaspixmapsink->prev[i]->gc);
-      if (evaspixmapsink->prev[i]->damage)
+            evaspixmapsink->xpixmap[i]->prev_pixmap);
+        XFreeGC (evaspixmapsink->xcontext->disp,
+            evaspixmapsink->xpixmap[i]->prev_gc);
         XDamageDestroy (evaspixmapsink->xcontext->disp,
-            evaspixmapsink->prev[i]->damage);
-
-      XSync (evaspixmapsink->xcontext->disp, FALSE);
-      evaspixmapsink->prev[i]->pixmap = 0;
-      evaspixmapsink->prev[i]->gc = NULL;
-      evaspixmapsink->prev[i]->damage = 0;
-      g_mutex_unlock (&evaspixmapsink->x_lock);
-    }
-    int ret = GST_FLOW_OK;
-    ret = gst_evaspixmapsink_epipe_reset (evaspixmapsink);
-    if (ret != GST_FLOW_OK) {
-      GST_ERROR_OBJECT (evaspixmapsink,
-          "evas epipe reset ret=%d, need to check", ret);
-      return GST_STATE_CHANGE_FAILURE;
+            evaspixmapsink->prev_damage[i]);
+        XSync (evaspixmapsink->xcontext->disp, FALSE);
+        g_mutex_unlock (&evaspixmapsink->x_lock);
+        evaspixmapsink->xpixmap[i]->prev_pixmap = 0;
+        evaspixmapsink->xpixmap[i]->prev_gc = 0;
+        evaspixmapsink->prev_damage[i] = 0;
+      }
     }
     if (evaspixmapsink->visible
         && !evas_object_visible_get (evaspixmapsink->eo)) {
@@ -462,7 +447,6 @@ ecore_pipe_callback_handler (void *data, void *buffer, unsigned int nbyte)
 
     xpixmap = evaspixmapsink->xpixmap[idx];
     if (xpixmap->pixmap) {
-      GST_LOG ("last_update_idx (%d)", evaspixmapsink->last_updated_idx);
       if (evaspixmapsink->last_updated_idx != idx) {
         Evas_Native_Surface surf;
         surf.version = EVAS_NATIVE_SURFACE_VERSION;
@@ -477,22 +461,28 @@ ecore_pipe_callback_handler (void *data, void *buffer, unsigned int nbyte)
         evas_object_image_native_surface_set (evaspixmapsink->eo, &surf);
         GST_LOG_OBJECT (evaspixmapsink,
             "update, native_surface_set of xpixmap[%d]", idx);
-        xpixmap = evaspixmapsink->xpixmap[evaspixmapsink->last_updated_idx];
-        if (xpixmap->ref > 0 && xpixmap->damaged_time > 0) {
-          xpixmap->ref--;
+        if (evaspixmapsink->last_updated_idx == -1) {
           xpixmap->damaged_time = 0;
           GST_INFO_OBJECT (evaspixmapsink,
-              "last updated pixmap[%d] ref-count DECREASED : pixmap(%ld), refcount(%d), damaged_time(%d), idx(%d)",
-              evaspixmapsink->last_updated_idx, xpixmap->pixmap, xpixmap->ref,
-              xpixmap->damaged_time);
+              "this is the first time to request to update(do not DECREASE ref-count) : pixmap(%ld), refcount(%d), damaged_time(%d), idx(%d)",
+              xpixmap->pixmap, xpixmap->ref, xpixmap->damaged_time, idx);
         } else {
-          GST_LOG
-              ("skip decreasing refcount : pixmap(%ld), refcount(%d), damaged_time(%d), idx(%d)",
-              xpixmap->pixmap, xpixmap->ref, xpixmap->damaged_time,
-              evaspixmapsink->last_updated_idx);
+          xpixmap = evaspixmapsink->xpixmap[evaspixmapsink->last_updated_idx];
+          if (xpixmap->ref > 0 && xpixmap->damaged_time > 0) {
+            xpixmap->ref--;
+            xpixmap->damaged_time = 0;
+            GST_INFO_OBJECT (evaspixmapsink,
+                "pixmap ref-count DECREASED : pixmap(%ld), refcount(%d), damaged_time(%d), idx(%d)",
+                xpixmap->pixmap, xpixmap->ref, xpixmap->damaged_time,
+                evaspixmapsink->last_updated_idx);
+          } else {
+            GST_LOG
+                ("skip decreasing refcount : pixmap(%ld), refcount(%d), damaged_time(%d), idx(%d)",
+                xpixmap->pixmap, xpixmap->ref, xpixmap->damaged_time,
+                evaspixmapsink->last_updated_idx);
+          }
         }
         evaspixmapsink->last_updated_idx = idx;
-        GST_LOG ("last_update_idx (%d)", evaspixmapsink->last_updated_idx);
       }
 
       evas_object_image_fill_set (evaspixmapsink->eo, 0, 0, evaspixmapsink->w,
@@ -518,7 +508,6 @@ evas_callback_resize_event (void *data, Evas * e, Evas_Object * obj,
 
   int w = 0;
   int h = 0;
-  int ret = GST_FLOW_OK;
 #ifdef COMPARE_RATIO
   float former_ratio = 0;
   float ratio = 0;
@@ -559,18 +548,7 @@ evas_callback_resize_event (void *data, Evas * e, Evas_Object * obj,
 #endif
   }
 
-  ret = gst_evaspixmapsink_epipe_reset (evaspixmapsink);
-  if (ret != GST_FLOW_OK) {
-    GST_ERROR_OBJECT (evaspixmapsink,
-        "evas epipe reset ret=%d, need to check", ret);
-    return GST_STATE_CHANGE_FAILURE;
-  }
-
-  if (GST_STATE (evaspixmapsink) >= GST_STATE_PAUSED) {
-    g_mutex_lock (&evaspixmapsink->flow_lock);
-    gst_evaspixmap_buffer_put (evaspixmapsink, evaspixmapsink->evas_pixmap_buf);
-    g_mutex_unlock (&evaspixmapsink->flow_lock);
-  }
+  gst_evaspixmap_buffer_put (evaspixmapsink, evaspixmapsink->evas_pixmap_buf);
 
   GST_DEBUG_OBJECT (evaspixmapsink, "[END]");
 }
@@ -972,11 +950,12 @@ gst_evaspixmap_buffer_destroy (GstEvasPixmapBuffer * evaspixmapbuf)
 
   GstEvasPixmapSink *evaspixmapsink;
 
+  GST_DEBUG_OBJECT (evaspixmapsink, "Destroying buffer");
+
   evaspixmapsink = evaspixmapbuf->evaspixmapsink;
   if (G_UNLIKELY (evaspixmapsink == NULL)) {
     goto no_sink;
   }
-  GST_DEBUG_OBJECT (evaspixmapsink, "Destroying buffer");
 
   g_return_if_fail (GST_IS_EVASPIXMAPSINK (evaspixmapsink));
 
@@ -1125,16 +1104,11 @@ gst_evaspixmap_buffer_new (GstEvasPixmapSink * evaspixmapsink, GstCaps * caps)
       evaspixmapbuf->height);
   GST_LOG_OBJECT (evaspixmapsink, "aligned size %dx%d",
       evaspixmapsink->aligned_width, evaspixmapsink->aligned_height);
-  if (!evaspixmapsink->is_zero_copy_format) {
-    GST_INFO_OBJECT (evaspixmapsink,
-        "it is not zero copy format. set size of caps.");
+  if (evaspixmapsink->aligned_width == 0 || evaspixmapsink->aligned_height == 0) {
+    GST_INFO_OBJECT (evaspixmapsink, "aligned size is zero. set size of caps.");
     evaspixmapsink->aligned_width = evaspixmapbuf->width;
     evaspixmapsink->aligned_height = evaspixmapbuf->height;
   }
-  if (evaspixmapsink->aligned_width == 0 || evaspixmapsink->aligned_height == 0) {
-    GST_ERROR ("wrong size information");
-    goto beach_unlocked;
-  }
 
   evaspixmapbuf->im_format =
       gst_evaspixmapsink_get_format_from_info (evaspixmapsink->xcontext,
@@ -1368,22 +1342,25 @@ gst_evaspixmap_buffer_put (GstEvasPixmapSink * evaspixmapsink,
   int idx = 0;
   GstXPixmap *xpixmap = NULL;
   int i = 0;
-  int (*handler) (Display *, XErrorEvent *) = NULL;
 
   /* We take the flow_lock. If expose is in there we don't want to run
      concurrently from the data flow thread */
+  g_mutex_lock (&evaspixmapsink->flow_lock);
 
   if (G_UNLIKELY (evaspixmapsink->xpixmap[idx] == NULL)) {
     GST_WARNING_OBJECT (evaspixmapsink, "xpixmap is NULL. Skip buffer_put.");
+    g_mutex_unlock (&evaspixmapsink->flow_lock);
     return FALSE;
   }
   if (evaspixmapsink->visible == FALSE) {
     GST_WARNING_OBJECT (evaspixmapsink, "visible is FALSE. Skip buffer_put.");
+    g_mutex_unlock (&evaspixmapsink->flow_lock);
     return TRUE;
   }
   if (!evaspixmapbuf) {
     GST_WARNING_OBJECT (evaspixmapsink,
         "evaspixmapbuf is NULL. Skip buffer_put.");
+    g_mutex_unlock (&evaspixmapsink->flow_lock);
     return TRUE;
   }
   g_mutex_lock (&evaspixmapsink->pixmap_ref_lock);
@@ -1417,6 +1394,7 @@ gst_evaspixmap_buffer_put (GstEvasPixmapSink * evaspixmapsink,
       GST_LOG_OBJECT (evaspixmapsink,
           "Could not find a pixmap with idle state, skip buffer_put.");
       g_mutex_unlock (&evaspixmapsink->pixmap_ref_lock);
+      g_mutex_unlock (&evaspixmapsink->flow_lock);
       return TRUE;
     }
   }
@@ -1683,12 +1661,10 @@ gst_evaspixmap_buffer_put (GstEvasPixmapSink * evaspixmapsink,
         evaspixmapsink->result_prev.w, evaspixmapsink->result_prev.h, result.w,
         result.h);
     for (i = 0; i < evaspixmapsink->num_of_pixmaps; i++) {
-      DRI2CreateDrawable (evaspixmapsink->xcontext->disp,
-          evaspixmapsink->xpixmap[i]->pixmap);
-      gst_evaspixmapsink_xpixmap_fillblack (evaspixmapsink->bufmgr_for_black,
-          evaspixmapsink->xcontext->disp, evaspixmapsink->xpixmap[i]->pixmap);
-      DRI2DestroyDrawable (evaspixmapsink->xcontext->disp,
-          evaspixmapsink->xpixmap[i]->pixmap);
+      XFillRectangle (evaspixmapsink->xcontext->disp,
+          evaspixmapsink->xpixmap[i]->pixmap, evaspixmapsink->xpixmap[i]->gc, 0,
+          0, evaspixmapsink->xpixmap[i]->width,
+          evaspixmapsink->xpixmap[i]->height);
       GST_LOG_OBJECT (evaspixmapsink,
           "fill black to xpixmap[%ld] with size(w:%d,h:%d)",
           evaspixmapsink->xpixmap[i]->pixmap, evaspixmapsink->xpixmap[i]->width,
@@ -1713,16 +1689,13 @@ gst_evaspixmap_buffer_put (GstEvasPixmapSink * evaspixmapsink,
     if (src_input.h % 2 == 1) {
       src_input.h += 1;
     }
-    error_caught = FALSE;
-    handler = XSetErrorHandler (gst_evaspixmapsink_handle_xerror);
 
     GST_LOG_OBJECT (evaspixmapsink,
-        "screen[%dx%d],pixmap[%d,%d,%dx%d],idx(%d)[%ld],method[%d],rotate[%d],src[%dx%d],dst[%d,%d,%dx%d],input[%d,%d,%dx%d],result[%d,%d,%dx%d]",
+        "screen[%dx%d],pixmap[%d,%d,%dx%d],method[%d],rotate[%d],src[%dx%d],dst[%d,%d,%dx%d],input[%d,%d,%dx%d],result[%d,%d,%dx%d]",
         evaspixmapsink->scr_w, evaspixmapsink->scr_h,
         evaspixmapsink->xpixmap[idx]->x, evaspixmapsink->xpixmap[idx]->y,
         evaspixmapsink->xpixmap[idx]->width,
         evaspixmapsink->xpixmap[idx]->height,
-        idx, evaspixmapsink->xpixmap[idx]->pixmap,
         evaspixmapsink->display_geometry_method, rotate, src_origin.w,
         src_origin.h, dst.x, dst.y, dst.w, dst.h, src_input.x, src_input.y,
         src_input.w, src_input.h, result.x, result.y, result.w, result.h);
@@ -1739,25 +1712,6 @@ gst_evaspixmap_buffer_put (GstEvasPixmapSink * evaspixmapsink,
       GST_WARNING_OBJECT (evaspixmapsink,
           "visible is FALSE. skip this image...");
     }
-    XSync (evaspixmapsink->xcontext->disp, FALSE);
-    if (ret != Success || error_caught) {
-      GST_WARNING ("putimage error");
-      if (evaspixmapsink->xpixmap[idx]->ref > 0) {
-        evaspixmapsink->xpixmap[idx]->ref--;
-        evaspixmapsink->xpixmap[idx]->damaged_time = 0;
-        GST_INFO_OBJECT (evaspixmapsink,
-            "pixmap ref-count DECREASED : pixmap(%ld), refcount(%d), damaged_time(%d), idx(%d)",
-            evaspixmapsink->xpixmap[idx]->pixmap,
-            evaspixmapsink->xpixmap[idx]->ref,
-            evaspixmapsink->xpixmap[idx]->damaged_time,
-            evaspixmapsink->last_updated_idx);
-      }
-    }
-    /* Reset error handler */
-    if (handler) {
-      error_caught = FALSE;
-      XSetErrorHandler (handler);
-    }
   } else
 #endif /* HAVE_XSHM */
   {
@@ -1783,6 +1737,7 @@ gst_evaspixmap_buffer_put (GstEvasPixmapSink * evaspixmapsink,
   XSync (evaspixmapsink->xcontext->disp, FALSE);
 
   g_mutex_unlock (&evaspixmapsink->x_lock);
+  g_mutex_unlock (&evaspixmapsink->flow_lock);
 
 
   return TRUE;
@@ -2129,10 +2084,9 @@ gst_evaspixmapsink_xpixmap_clear (GstEvasPixmapSink * evaspixmapsink,
   /* Preview area is not updated before other UI is updated in the screen. */
   XSetForeground (evaspixmapsink->xcontext->disp, xpixmap->gc,
       evaspixmapsink->xcontext->black);
-  DRI2CreateDrawable (evaspixmapsink->xcontext->disp, xpixmap->pixmap);
-  gst_evaspixmapsink_xpixmap_fillblack (evaspixmapsink->bufmgr_for_black,
-      evaspixmapsink->xcontext->disp, xpixmap->pixmap);
-  DRI2DestroyDrawable (evaspixmapsink->xcontext->disp, xpixmap->pixmap);
+  XFillRectangle (evaspixmapsink->xcontext->disp, xpixmap->pixmap, xpixmap->gc,
+      evaspixmapsink->render_rect.x, evaspixmapsink->render_rect.y,
+      evaspixmapsink->render_rect.w, evaspixmapsink->render_rect.h);
 
   XSync (evaspixmapsink->xcontext->disp, FALSE);
 
@@ -3473,11 +3427,9 @@ gst_evaspixmapsink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
             evaspixmapsink->video_width, evaspixmapsink->video_height);
         GST_INFO_OBJECT (evaspixmapsink, "Use aligned width,height[%dx%d]",
             evaspixmapsink->aligned_width, evaspixmapsink->aligned_height);
-        evaspixmapsink->is_zero_copy_format = TRUE;
         break;
       default:
         GST_INFO_OBJECT (evaspixmapsink, "Use original width,height of caps");
-        evaspixmapsink->is_zero_copy_format = FALSE;
         break;
     }
     evaspixmapsink->evas_pixmap_buf =
@@ -3505,8 +3457,8 @@ gst_evaspixmapsink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
 
       if (evaspixmapsink->evas_pixmap_buf->xvimage->data) {
         img_data =
-            (XV_PUTIMAGE_DATA_PTR) evaspixmapsink->evas_pixmap_buf->xvimage->
-            data;
+            (XV_PUTIMAGE_DATA_PTR) evaspixmapsink->evas_pixmap_buf->
+            xvimage->data;
         XV_PUTIMAGE_INIT_DATA (img_data);
 
         mem = gst_buffer_peek_memory (buf, 1);
@@ -3555,13 +3507,13 @@ gst_evaspixmapsink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
               img_data->bo[2]);
           /* export bo */
           if (img_data->bo[0]) {
-            img_data->YBuf = tbm_bo_export ((tbm_bo) img_data->bo[0]);
+            img_data->YBuf = tbm_bo_export((tbm_bo)img_data->bo[0]);
           }
           if (img_data->bo[1]) {
-            img_data->CbBuf = tbm_bo_export ((tbm_bo) img_data->bo[1]);
+            img_data->CbBuf = tbm_bo_export((tbm_bo)img_data->bo[1]);
           }
           if (img_data->bo[2]) {
-            img_data->CrBuf = tbm_bo_export ((tbm_bo) img_data->bo[2]);
+            img_data->CrBuf = tbm_bo_export((tbm_bo)img_data->bo[2]);
           }
           if (mm_video_buf->type != MM_VIDEO_BUFFER_TYPE_TBM_BO) {
             mm_video_buf->type = MM_VIDEO_BUFFER_TYPE_TBM_BO;
@@ -3601,13 +3553,10 @@ gst_evaspixmapsink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
   if (mm_video_buf && g_cnt < 20)
     input_dump (mm_video_buf);
 #endif
-  g_mutex_lock (&evaspixmapsink->flow_lock);
   if (!gst_evaspixmap_buffer_put (evaspixmapsink,
           evaspixmapsink->evas_pixmap_buf)) {
-    g_mutex_unlock (&evaspixmapsink->flow_lock);
     goto no_pixmap;
   }
-  g_mutex_unlock (&evaspixmapsink->flow_lock);
 
   return GST_FLOW_OK;
 
@@ -3664,10 +3613,7 @@ gst_evaspixmapsink_navigation_send_event (GstNavigation * navigation,
 
   if ((peer = gst_pad_get_peer (GST_VIDEO_SINK_PAD (evaspixmapsink)))) {
     GstEvent *event;
-    GstVideoRectangle src = { 0, };
-    GstVideoRectangle dst = { 0, };
-    GstVideoRectangle result = { 0, };
-
+    GstVideoRectangle src, dst, result;
     gdouble x, y, xscale = 1.0, yscale = 1.0;
 
     event = gst_event_new_navigation (structure);
@@ -3702,10 +3648,8 @@ gst_evaspixmapsink_navigation_send_event (GstNavigation * navigation,
 
     /* We calculate scaling using the original video frames geometry to include
        pixel aspect ratio scaling. */
-    if (result.w != 0)
-      xscale = (gdouble) evaspixmapsink->video_width / result.w;
-    if (result.h != 0)
-      yscale = (gdouble) evaspixmapsink->video_height / result.h;
+    xscale = (gdouble) evaspixmapsink->video_width / result.w;
+    yscale = (gdouble) evaspixmapsink->video_height / result.h;
 
     /* Converting pointer coordinates to the non scaled geometry */
     if (gst_structure_get_double (structure, "pointer_x", &x)) {
@@ -4011,9 +3955,6 @@ gst_evaspixmapsink_xpixmap_link (GstEvasPixmapSink * evaspixmapsink)
   guint xw = 0;
   guint xh = 0;
   int i = 0;
-  int j = 0;
-  int empty = -1;
-  gboolean full = TRUE;
   XGCValues gc_values_black;
   gc_values_black.foreground = 0xff000000;
 
@@ -4051,14 +3992,11 @@ gst_evaspixmapsink_xpixmap_link (GstEvasPixmapSink * evaspixmapsink)
             if (evaspixmapsink->need_to_fill_black) {
               for (i = 0; i < evaspixmapsink->num_of_pixmaps; i++) {
                 g_mutex_lock (&evaspixmapsink->x_lock);
-                DRI2CreateDrawable (evaspixmapsink->xcontext->disp,
-                    evaspixmapsink->xpixmap[i]->pixmap);
-                gst_evaspixmapsink_xpixmap_fillblack
-                    (evaspixmapsink->bufmgr_for_black,
-                    evaspixmapsink->xcontext->disp,
-                    evaspixmapsink->xpixmap[i]->pixmap);
-                DRI2DestroyDrawable (evaspixmapsink->xcontext->disp,
-                    evaspixmapsink->xpixmap[i]->pixmap);
+                XFillRectangle (evaspixmapsink->xcontext->disp,
+                    evaspixmapsink->xpixmap[i]->pixmap,
+                    evaspixmapsink->xpixmap[i]->gc, 0, 0,
+                    evaspixmapsink->xpixmap[i]->width,
+                    evaspixmapsink->xpixmap[i]->height);
                 GST_LOG_OBJECT (evaspixmapsink,
                     "fill black to xpixmap[%ld] with size(w:%d,h:%d)",
                     evaspixmapsink->xpixmap[i]->pixmap,
@@ -4157,47 +4095,43 @@ gst_evaspixmapsink_xpixmap_link (GstEvasPixmapSink * evaspixmapsink)
         }
         goto GO_OUT_OF_FUNC;
       }
+      evaspixmapsink->need_to_fill_black = FALSE;
       GST_INFO_OBJECT (evaspixmapsink, "creation pixmap_id[%d]:%ld success", i,
           pixmap_id[i]);
       GST_DEBUG_OBJECT (evaspixmapsink,
           "evas_object_width(%d),evas_object_height(%d),pixmap:%ld,depth:%d",
           evas_object_width, evas_object_height, pixmap_id[i],
           DefaultDepth (dpy, DefaultScreen (dpy)));
-      DRI2CreateDrawable (evaspixmapsink->xcontext->disp, pixmap_id[i]);
-      gst_evaspixmapsink_xpixmap_fillblack
-          (evaspixmapsink->bufmgr_for_black,
-          evaspixmapsink->xcontext->disp, pixmap_id[i]);
-      DRI2DestroyDrawable (evaspixmapsink->xcontext->disp, pixmap_id[i]);
     }
-    evaspixmapsink->need_to_fill_black = FALSE;
   }
 
-  /* keep previous pixmap id */
   for (i = 0; i < evaspixmapsink->num_of_pixmaps; i++) {
     if (evaspixmapsink->xpixmap[i]->pixmap
         && pixmap_id[i] != evaspixmapsink->xpixmap[i]->pixmap) {
       g_mutex_unlock (&evaspixmapsink->x_lock);
       g_mutex_lock (&evaspixmapsink->pixmap_ref_lock);
-      /* find empty spaces */
-      for (j = 0; j < NUM_OF_PREV_PIXMAP; j++) {
-        if (!evaspixmapsink->prev[j]->pixmap) {
-          empty = j;
-          full = FALSE;
-          break;
-        }
-      }
-      if (full || empty == -1)
-        GST_ERROR ("previous pixmap pool is full");
-      else {
-        evaspixmapsink->prev[empty]->pixmap =
-            evaspixmapsink->xpixmap[i]->pixmap;
-        evaspixmapsink->prev[empty]->gc = evaspixmapsink->xpixmap[i]->gc;
-        evaspixmapsink->prev[empty]->damage = evaspixmapsink->damage[i];
-        GST_LOG ("saved %ld %p %ld",
-            evaspixmapsink->prev[empty]->pixmap,
-            evaspixmapsink->prev[empty]->gc,
-            evaspixmapsink->prev[empty]->damage);
+
+      /* If we reset another pixmap, do below */
+      if (evaspixmapsink->xpixmap[i]->prev_pixmap) {
+        GST_LOG_OBJECT (evaspixmapsink,
+            "Free pixmap(%ld), gc(%p), destroy previous damage(%ld)",
+            evaspixmapsink->xpixmap[i]->prev_pixmap,
+            evaspixmapsink->xpixmap[i]->prev_gc,
+            evaspixmapsink->prev_damage[i]);
+        g_mutex_lock (&evaspixmapsink->x_lock);
+        XFreePixmap (evaspixmapsink->xcontext->disp,
+            evaspixmapsink->xpixmap[i]->prev_pixmap);
+        XFreeGC (evaspixmapsink->xcontext->disp,
+            evaspixmapsink->xpixmap[i]->prev_gc);
+        XDamageDestroy (evaspixmapsink->xcontext->disp,
+            evaspixmapsink->prev_damage[i]);
+        XSync (evaspixmapsink->xcontext->disp, FALSE);
+        g_mutex_unlock (&evaspixmapsink->x_lock);
+        evaspixmapsink->prev_damage[i] = 0;
       }
+      evaspixmapsink->xpixmap[i]->prev_pixmap =
+          evaspixmapsink->xpixmap[i]->pixmap;
+      evaspixmapsink->xpixmap[i]->prev_gc = evaspixmapsink->xpixmap[i]->gc;
       evaspixmapsink->xpixmap[i]->pixmap = 0;
       evaspixmapsink->xpixmap[i]->ref = 0;
       evaspixmapsink->xpixmap[i]->damaged_time = 0;
@@ -4217,6 +4151,9 @@ gst_evaspixmapsink_xpixmap_link (GstEvasPixmapSink * evaspixmapsink)
     evaspixmapsink->xpixmap[i]->height = xh;
 
     /* Create XDamage */
+    if (evaspixmapsink->damage[i]) {
+      evaspixmapsink->prev_damage[i] = evaspixmapsink->damage[i];
+    }
     evaspixmapsink->damage[i] =
         XDamageCreate (dpy, evaspixmapsink->xpixmap[i]->pixmap,
         XDamageReportRawRectangles);
@@ -4225,6 +4162,14 @@ gst_evaspixmapsink_xpixmap_link (GstEvasPixmapSink * evaspixmapsink)
         "xpixmap[%d]->(pixmap:%ld,gc:%p), damage[%d]:%ld", i,
         evaspixmapsink->xpixmap[i]->pixmap, evaspixmapsink->xpixmap[i]->gc, i,
         evaspixmapsink->damage[i]);
+
+    /* Fill blackcolor for the new pixmap */
+    XFillRectangle (evaspixmapsink->xcontext->disp, pixmap_id[i],
+        evaspixmapsink->xpixmap[i]->gc, 0, 0, evaspixmapsink->w,
+        evaspixmapsink->h);
+    GST_LOG_OBJECT (evaspixmapsink,
+        "fill black to xpixmap[%ld] with size(w:%d,h:%d)", pixmap_id[i],
+        evaspixmapsink->w, evaspixmapsink->h);
   }
 
   XSync (dpy, FALSE);
@@ -4237,7 +4182,6 @@ gst_evaspixmapsink_xpixmap_link (GstEvasPixmapSink * evaspixmapsink)
         "epipe_request_count(%d), skip ecore_pipe_write()",
         evaspixmapsink->epipe_request_count);
   } else {
-    GST_WARNING_OBJECT (evaspixmapsink, ">>>>>ecore_pipe_write()");
     ecore_pipe_write (evaspixmapsink->epipe, evaspixmapsink,
         sizeof (GstEvasPixmapSink));
     evaspixmapsink->epipe_request_count++;
@@ -4385,10 +4329,8 @@ gst_evaspixmapsink_set_property (GObject * object, guint prop_id,
           }
         }
         if (evaspixmapsink->xcontext) {
-          g_mutex_lock (&evaspixmapsink->flow_lock);
           gst_evaspixmap_buffer_put (evaspixmapsink,
               evaspixmapsink->evas_pixmap_buf);
-          g_mutex_unlock (&evaspixmapsink->flow_lock);
         }
       }
       break;
@@ -4541,10 +4483,8 @@ gst_evaspixmapsink_set_property (GObject * object, guint prop_id,
             GST_INFO_OBJECT (evaspixmapsink, "object hide (forcely)");
             g_mutex_unlock (&evaspixmapsink->flow_lock);
           } else {
-            g_mutex_lock (&evaspixmapsink->flow_lock);
             gst_evaspixmap_buffer_put (evaspixmapsink,
                 evaspixmapsink->evas_pixmap_buf);
-            g_mutex_unlock (&evaspixmapsink->flow_lock);
           }
         } else {
           GST_WARNING_OBJECT (evaspixmapsink, "evas image object was not set");
@@ -4694,58 +4634,6 @@ gst_evaspixmapsink_get_property (GObject * object, guint prop_id,
 }
 
 static void
-gst_evaspixmapsink_xpixmap_fillblack (tbm_bufmgr bufmgr, Display * disp,
-    Pixmap pixmap)
-{
-  unsigned int attachments[1] = { DRI2BufferFrontLeft };
-  int dri2_out_temp, dri2_out_width, dri2_out_height;
-  DRI2Buffer *pDRI2Buffer =
-      DRI2GetBuffers (disp, pixmap, &dri2_out_width, &dri2_out_height,
-      attachments, 1, &dri2_out_temp);
-  if (!pDRI2Buffer)
-    GST_ERROR ("failed to get DRI2 buffers for fillblack.");
-  else {
-    GST_DEBUG ("width=%d height=%d name=%d flags=0x%x", dri2_out_width,
-        dri2_out_height, pDRI2Buffer[0].name, pDRI2Buffer[0].flags);
-    tbm_bo bo = tbm_bo_import (bufmgr, pDRI2Buffer[0].name);
-    memset (tbm_bo_map (bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE).ptr, 0,
-        tbm_bo_size (bo));
-    tbm_bo_unmap (bo);
-    tbm_bo_unref (bo);
-    XFree (pDRI2Buffer);
-  }
-}
-
-static GstFlowReturn
-gst_evaspixmapsink_epipe_reset (GstEvasPixmapSink * evaspixmapsink)
-{
-  if (evaspixmapsink == NULL) {
-    GST_ERROR ("handle is NULL");
-    return GST_FLOW_ERROR;
-  }
-
-  if (evaspixmapsink->epipe) {
-    GST_DEBUG ("ecore-pipe will be deleted");
-    ecore_pipe_del (evaspixmapsink->epipe);
-    evaspixmapsink->epipe = NULL;
-  }
-
-  if (!evaspixmapsink->epipe) {
-    evaspixmapsink->epipe =
-        ecore_pipe_add ((Ecore_Pipe_Cb) ecore_pipe_callback_handler,
-        evaspixmapsink);
-    if (!evaspixmapsink->epipe) {
-      GST_ERROR ("ecore-pipe create failed");
-      return GST_FLOW_ERROR;
-    }
-    GST_DEBUG ("ecore-pipe create success");
-  }
-  evaspixmapsink->epipe_request_count = 0;
-
-  return GST_FLOW_OK;
-}
-
-static void
 gst_evaspixmapsink_reset (GstEvasPixmapSink * evaspixmapsink)
 {
   FUNCTION_ENTER ();
@@ -4776,16 +4664,6 @@ gst_evaspixmapsink_reset (GstEvasPixmapSink * evaspixmapsink)
       evaspixmapsink->damage[i] = 0;
     }
   }
-  for (i = 0; i < NUM_OF_PREV_PIXMAP; i++) {
-    if (evaspixmapsink->prev[i]->damage) {
-      g_mutex_lock (&evaspixmapsink->x_lock);
-      GST_DEBUG_OBJECT (evaspixmapsink, "Free damage");
-      XDamageDestroy (evaspixmapsink->xcontext->disp,
-          evaspixmapsink->prev[i]->damage);
-      g_mutex_unlock (&evaspixmapsink->x_lock);
-      evaspixmapsink->prev[i]->damage = 0;
-    }
-  }
 
   if (evaspixmapsink->handler) {
     ecore_event_handler_del (evaspixmapsink->handler);
@@ -4808,22 +4686,6 @@ gst_evaspixmapsink_reset (GstEvasPixmapSink * evaspixmapsink)
         evaspixmapsink->xpixmap[i]);
     evaspixmapsink->xpixmap[i] = NULL;
   }
-  for (i = 0; i < NUM_OF_PREV_PIXMAP; i++) {
-    g_mutex_lock (&evaspixmapsink->x_lock);
-    if (evaspixmapsink->prev[i]->pixmap) {
-      GST_DEBUG_OBJECT (evaspixmapsink, "Free pixmap");
-      XFreePixmap (evaspixmapsink->xcontext->disp,
-          evaspixmapsink->prev[i]->pixmap);
-      evaspixmapsink->prev[i]->pixmap = 0;
-    }
-    if (evaspixmapsink->prev[i]->gc) {
-      GST_DEBUG_OBJECT (evaspixmapsink, "Free gc");
-      XFreeGC (evaspixmapsink->xcontext->disp, evaspixmapsink->prev[i]->gc);
-      evaspixmapsink->prev[i]->gc = NULL;
-    }
-    XSync (evaspixmapsink->xcontext->disp, FALSE);
-    g_mutex_unlock (&evaspixmapsink->x_lock);
-  }
   if (evaspixmapsink->eo) {
     evas_object_image_native_surface_set (evaspixmapsink->eo, NULL);
     evas_object_image_data_set (evaspixmapsink->eo, NULL);
@@ -4857,7 +4719,6 @@ gst_evaspixmapsink_finalize (GObject * object)
   FUNCTION_ENTER ();
 
   GstEvasPixmapSink *evaspixmapsink;
-  int i = 0;
   evaspixmapsink = GST_EVASPIXMAPSINK (object);
   GST_DEBUG_OBJECT (evaspixmapsink, "[START]");
 
@@ -4869,15 +4730,10 @@ gst_evaspixmapsink_finalize (GObject * object)
     g_free (evaspixmapsink->par);
     evaspixmapsink->par = NULL;
   }
-  for (i = 0; i < NUM_OF_PREV_PIXMAP; i++) {
-    g_free (evaspixmapsink->prev[i]);
-  }
 
   g_mutex_clear (&evaspixmapsink->x_lock);
   g_mutex_clear (&evaspixmapsink->flow_lock);
   g_mutex_clear (&evaspixmapsink->pixmap_ref_lock);
-  if (evaspixmapsink->bufmgr_for_black)
-    tbm_bufmgr_deinit (evaspixmapsink->bufmgr_for_black);
 
   GST_DEBUG_OBJECT (evaspixmapsink, "[END]");
 
@@ -4888,7 +4744,7 @@ gst_evaspixmapsink_finalize (GObject * object)
 static void
 gst_evaspixmapsink_init (GstEvasPixmapSink * evaspixmapsink)
 {
-  GST_DEBUG_OBJECT (evaspixmapsink, "[START]");
+  FUNCTION_ENTER ();
 
   int i = 0;
   evaspixmapsink->display_name = NULL;
@@ -4898,22 +4754,6 @@ gst_evaspixmapsink_init (GstEvasPixmapSink * evaspixmapsink)
     evaspixmapsink->xpixmap[i] = NULL;
     evaspixmapsink->damage[i] = 0;
   }
-  for (i = 0; i < NUM_OF_PREV_PIXMAP; i++) {
-    evaspixmapsink->prev[i] = NULL;
-  }
-
-  /* create prev structure */
-  for (i = 0; i < NUM_OF_PREV_PIXMAP; i++) {
-    /* prev can be created in this function only */
-    evaspixmapsink->prev[i] = g_new0 (GstPrevPixmap, 1);
-    if (!evaspixmapsink->prev[i]) {
-      GST_ERROR_OBJECT (evaspixmapsink, "prev structure is not valid..");
-      int j = 0;
-      for (j = 0; j < i; j++) {
-        g_free (evaspixmapsink->prev[j]);
-      }
-    }
-  }
   evaspixmapsink->num_of_pixmaps = NUM_OF_PIXMAP;
   evaspixmapsink->evas_pixmap_buf = NULL;
 
@@ -4968,9 +4808,6 @@ gst_evaspixmapsink_init (GstEvasPixmapSink * evaspixmapsink)
   evaspixmapsink->use_origin_size = FALSE;
   evaspixmapsink->former_origin_size = FALSE;
   evaspixmapsink->last_updated_idx = -1;
-  evaspixmapsink->bufmgr_for_black = tbm_bufmgr_init (-1);
-  if (!evaspixmapsink->bufmgr_for_black)
-    GST_WARNING ("tbm_bufmgr_init is failed");
 
   memset (&evaspixmapsink->src_prev, 0, sizeof (GstVideoRectangle));
   memset (&evaspixmapsink->result_prev, 0, sizeof (GstVideoRectangle));
@@ -4979,8 +4816,6 @@ gst_evaspixmapsink_init (GstEvasPixmapSink * evaspixmapsink)
      Add XInitThread() before XOpenDisplay() */
   if (!XInitThreads ())
     GST_WARNING ("FAIL to call XInitThreads()");
-
-  GST_DEBUG_OBJECT (evaspixmapsink, "[END]");
 }
 
 static void
index 3c68c6f..a1bef91 100755 (executable)
@@ -87,10 +87,8 @@ G_BEGIN_DECLS
 #define XV_SCREEN_SIZE_HEIGHT 4096
 #define MARGIN_OF_ERROR 0.005
 #define NUM_OF_PIXMAP         3
-#define NUM_OF_PREV_PIXMAP    15
 typedef struct _GstXContext GstXContext;
 typedef struct _GstXPixmap GstXPixmap;
-typedef struct _GstPrevPixmap GstPrevPixmap;
 typedef struct _GstEvasPixmapFormat GstEvasPixmapFormat;
 typedef struct _GstEvasPixmapBuffer GstEvasPixmapBuffer;
 typedef struct _GstEvasPixmapBufferClass GstEvasPixmapBufferClass;
@@ -177,13 +175,8 @@ struct _GstXPixmap
   GC gc;
   gint ref;
   gint damaged_time;
-};
-
-struct _GstPrevPixmap
-{
-  Pixmap pixmap;
-  GC gc;
-  Damage damage;
+  Pixmap prev_pixmap;
+  GC prev_gc;
 };
 
 /**
@@ -264,7 +257,6 @@ struct _GstEvasPixmapSink
 
   GstXContext *xcontext;
   GstXPixmap *xpixmap[NUM_OF_PIXMAP];
-  GstPrevPixmap *prev[NUM_OF_PREV_PIXMAP];
   GstEvasPixmapBuffer *evas_pixmap_buf;
 
   GThread *event_thread;
@@ -344,19 +336,16 @@ struct _GstEvasPixmapSink
 
   /* damage event */
   Damage damage[NUM_OF_PIXMAP];
+  Damage prev_damage[NUM_OF_PIXMAP];
   int damage_case;
   Ecore_Event_Handler *handler;
   Ecore_Pipe *epipe;
 
   gint drm_fd;
   gem_info_t gem_info[MAX_GEM_BUFFER_NUM];
-  tbm_bufmgr bufmgr_for_black;
 
   GstVideoRectangle src_prev;
   GstVideoRectangle result_prev;
-
-  /* zero copy format */
-  gboolean is_zero_copy_format;
 #ifdef DUMP_IMG
   void *pixmap_addr[NUM_OF_PIXMAP];
 #endif