weston: sync vidda patch(44-48) [2/2]

PD#SWPL-172524

Problem:
frame lost when video play

Solution:
sync vidda patch

Verify:
t5w

Change-Id: I5769c9cb31f968c49f08650c0c8592dbcbc56595
Signed-off-by: limin.tian <limin.tian@amlogic.com>
diff --git a/aml-weston/aml-backend.c b/aml-weston/aml-backend.c
index d0c2ffd..fdc652d 100644
--- a/aml-weston/aml-backend.c
+++ b/aml-weston/aml-backend.c
@@ -42,7 +42,7 @@
 #include "vaapi-recorder.h"
 
 #include "aml-backend.h"
-
+#include "linux-dmabuf.h"
 #ifdef ENABLE_DRM_HELP
 static const char *const aspect_ratio_as_string[] = {
 		[WESTON_MODE_PIC_AR_NONE] = "",
@@ -54,7 +54,6 @@
 drm_cmd *g_cmd = NULL;
 #endif
 
-#ifdef BUILD_AML_TV
 #include <linux/amlogic/tvin.h>
 
 #define FRAME_RATE_DURATION_2397                4004
@@ -84,7 +83,6 @@
 	FPS_119 = 119,
 	FPS_120 = 120,
 };
-#endif
 
 bool drm_change_to_dummy_mode( struct weston_compositor *compositor )
 {
@@ -201,10 +199,24 @@
 {
 	int rc = -1;
 	struct drm_backend* b = to_drm_backend(ec);
-	struct drm_plane* plane_drm = drm_get_weston_plane(b, to_drm_plane(plane));
+	struct drm_plane* plane_drm = NULL;
 	uint32_t crtc_id = 0;
+	if (!plane) {
+		struct weston_plane* plane_tmp = NULL;
+		struct drm_plane* drm_plane_temp = NULL;
+		wl_list_for_each(plane, &ec->plane_list, link) {
+			drm_plane_temp = to_drm_plane(plane);
+			if (drm_plane_temp && drm_plane_temp->is_video_plane && drm_plane_temp->crtc) {
+				plane_drm = drm_plane_temp;
+				break;
+			}
+		}
+	} else {
+		plane_drm = drm_get_weston_plane(b, plane);
+	}
+
 	weston_log("\n %s %d plane:%p crtc:%p\n", __FUNCTION__, __LINE__, plane_drm, plane_drm ? plane_drm->crtc : NULL );
-	if (plane_drm && plane_drm->crtc && plane_drm->state_cur) {
+	if (plane_drm && plane_drm->crtc) {
 		crtc_id = plane_drm->crtc->crtc_id;
 		rc= drmModeSetPlane( b->drm.fd,
 					plane_drm->plane_id,
@@ -213,15 +225,15 @@
 					0, // flags
 					0, // plane x
 					0, // plane y
-					plane_drm->state_cur->dest_w,
-					plane_drm->state_cur->dest_h,
+					1920,
+					1080,
 					0, // fb rect x
 					0, // fb rect y
-					plane_drm->state_cur->dest_w<<16,
-					plane_drm->state_cur->dest_h<<16 );
+					1920<<16,
+					1080<<16 );
 
 		weston_log("\n %s %d crtc id:%d dest(%d %d) rc:%d\n",__FUNCTION__, __LINE__,
-			crtc_id, plane_drm->state_cur->dest_w, plane_drm->state_cur->dest_h, rc );
+			crtc_id, 1920, 1080, rc );
 	}
 	return rc;
 }
@@ -480,7 +492,6 @@
 #endif
 }
 
-#ifdef BUILD_AML_TV
 int udev_event_frame_rate_hint(struct udev_device *device)
 {
 	const char *val;
@@ -558,14 +569,17 @@
 drm_output_choose_mode_by_name(struct drm_output *output,
 				   const char *name)
 {
-	struct drm_mode *tmp_mode = NULL, *mode;
+	struct drm_mode *tmp_mode = NULL, *mode = NULL;
 
 	if (strlen(name) == 0)
 		return tmp_mode;
 
 	wl_list_for_each(mode, &output->base.mode_list, base.link) {
-		if (!strcmp(mode->mode_info.name, name))
+		if (!strcmp(mode->mode_info.name, name)) {
 			tmp_mode = mode;
+			weston_log("\n drm_output_choose_mode_by_name:%s\n", tmp_mode->mode_info.name);
+			break;
+		}
 	}
 	return tmp_mode;
 }
@@ -667,6 +681,8 @@
 				drm_mode = drm_output_choose_mode_by_name(output, firstMode);
 				if (drm_mode) {
 					*mode = drm_mode->base;
+					mode->width = drm_mode->mode_info.hdisplay;
+					mode->height = drm_mode->mode_info.vdisplay;
 					drm_debug(output->backend, "mode: %s, %dx%d\n",
 							drm_mode->mode_info.name, mode->width, mode->height);
 				}
@@ -687,7 +703,7 @@
 				sprintf(secondMode, "%s%s", resolution, "60hz");
 				break;
 			case FRAME_RATE_DURATION_2997:
-				sprintf(secondMode, "%s%s", resolution, "59hz");
+				sprintf(firstMode, "%s%s", resolution, "59hz");
 				sprintf(secondMode, "%s%s", resolution, "60hz");
 				break;
 			case FRAME_RATE_DURATION_30:
@@ -716,16 +732,20 @@
 			}
 			weston_log("\n update mode first(%s) second(%s)", firstMode, secondMode);
 			drm_mode = drm_output_choose_mode_by_name(output, firstMode);
-			if (drm_mode && strcmp(firstMode, cur_drm_mode->mode_info.name)) {
+			if (drm_mode) {
 				*mode = drm_mode->base;
+				mode->width = drm_mode->mode_info.hdisplay;
+				mode->height = drm_mode->mode_info.vdisplay;
 				weston_log("\n need switch to first mode: %s, %dx%d\n",
 						drm_mode->mode_info.name, mode->width, mode->height);
 				return;
 			}
 
 			drm_mode = drm_output_choose_mode_by_name(output, secondMode);
-			if (drm_mode && strcmp(secondMode, cur_drm_mode->mode_info.name)) {
+			if (drm_mode) {
 				*mode = drm_mode->base;
+				mode->width = drm_mode->mode_info.hdisplay;
+				mode->height = drm_mode->mode_info.vdisplay;
 				weston_log("\n need switch to second mode: %s, %dx%d\n",
 						drm_mode->mode_info.name, mode->width, mode->height);
 				return;
@@ -757,6 +777,8 @@
 					rate_hint,
 					frame_value);
 			if (mode.width > 0 && mode.height > 0) {
+				weston_log("\n %s %d mode.width:%d mode.height:%d\n",
+					__FUNCTION__,__LINE__, mode.width, mode.height);
 				output->switch_mode(output, &mode);
 				weston_output_damage(output);
 			}
@@ -819,7 +841,7 @@
 
 	wl_list_for_each(output, &compositor->output_list, link) {
 		weston_log("\n output name %s", output->name);
-		if (!strstr(output->name, "LVDS"))
+		if (!strstr(output->name, "LVDS") && !strstr(output->name, "HDMI") )
 			continue;
 		drm_get_match_dur_output_mode(output,
 				FRAME_RATE_HDMI_SWITCH_FORCE,
@@ -835,7 +857,6 @@
 		}
 	}
 }
-#endif
 
 #ifdef ENABLE_DRM_HELP
 void weston_print_info(struct weston_compositor* ec, int count)
@@ -1103,9 +1124,7 @@
 	b->base.print_output_status = drm_print_output_status;
 	b->base.get_frame_time = drm_get_frame_time;
 	b->base.close_video_plane = drm_close_video_plane;
-#ifdef BUILD_AML_TV
 	b->base.update_frame_rate = drm_backend_update_rate;
-#endif
 }
 
 struct weston_plane *
@@ -1236,8 +1255,10 @@
 		fb->plane = ps->plane;
 		fb->plane->keep_last_frame = true;
 		ev->surface->plane = drm_get_weston_plane(ps->output->backend, fb->plane);
-		if (ev->surface->plane)
+		if (ev->surface->plane && ev->surface->keep_last_frame != INIT_VALUE ) {
 			ev->surface->plane->keep_last_frame = ev->surface->keep_last_frame;
+		}
+
 		drm_debug(ps->output->backend, "\n \t\t\t\t[view] video surface: %d keep_last_frame %d "
 			"view:%p surface: %p plane:%d weston_plane:%p drm_plane:%p\n",
 			ev->surface->is_video_surface, ev->surface->keep_last_frame,
@@ -1262,3 +1283,15 @@
 	}
 	return false;
 }
+
+bool is_direct_display(struct weston_buffer* buffer)
+{
+	bool ret = false;
+	struct linux_dmabuf_buffer *dmabuf = NULL;
+	if (buffer) {
+		dmabuf = linux_dmabuf_buffer_get(buffer->resource);
+		if (dmabuf)
+			ret = dmabuf->direct_display;
+	}
+	return ret;
+}
diff --git a/aml-weston/aml-backend.h b/aml-weston/aml-backend.h
index c5eb2d3..63bf35c 100644
--- a/aml-weston/aml-backend.h
+++ b/aml-weston/aml-backend.h
@@ -71,4 +71,6 @@
 			struct weston_view *ev,
 			struct drm_plane *plane,
 			const char *p_name);
+bool is_direct_display(struct weston_buffer* buffer);
+
 #endif
diff --git a/aml-weston/aml-compositor.c b/aml-weston/aml-compositor.c
index 0ccbd2a..babbc84 100644
--- a/aml-weston/aml-compositor.c
+++ b/aml-weston/aml-compositor.c
@@ -102,7 +102,7 @@
 	surface->queue_capacity = SURFACE_QUEUE_CAPACITY;
 	surface->queue_size = 0;
 	wl_list_init(&surface->link);
-	surface->keep_last_frame = false;
+	surface->keep_last_frame = INIT_VALUE;
 }
 
 static void weston_clear_video_surface_info(struct weston_surface *surface)
@@ -130,8 +130,16 @@
 		surface->commit_queue = NULL;
 	}
 
-	if (surface->is_video_surface && !surface->keep_last_frame)
-		surface->compositor->backend->close_video_plane(surface->compositor, surface->plane);
+	if (surface->keep_last_frame == 0 && !surface->plane
+		&& surface->compositor->backend->close_video_plane)
+		surface->compositor->backend->close_video_plane(surface->compositor, NULL);
+
+	if (surface->destroy_cb) {
+		weston_log("\n weston_surface_destroy :%p destroy completely\n", surface);
+		wl_callback_send_done(surface->destroy_cb, 1);
+		wl_resource_destroy(surface->destroy_cb);
+	}
+
 }
 
 static int video_fence( struct weston_buffer *buffer)
@@ -579,7 +587,7 @@
 	weston_compositor_read_presentation_clock(compositor, &now);
 	int64_t mdiff;
 	mdiff = timespec_sub_to_msec(&now, &compositor->last_repaint_start);
-	if (mdiff > 17)
+	if (mdiff > 17 && compositor->enable_video_debug)
 		weston_log("\n output_repaint_timer_handler %d now (%ld.%09ld) last (%ld.%09ld) diff:%lld\n", __LINE__,
 			now.tv_sec, now.tv_nsec, compositor->last_repaint_start.tv_sec, compositor->last_repaint_start.tv_nsec, mdiff);
 	compositor->last_repaint_start = now;
@@ -640,12 +648,13 @@
 	int64_t take;
 	weston_compositor_read_presentation_clock(compositor, &t1);
 	take =  timespec_sub_to_msec(&t1, &now);
-	if (take >= 10)
+	if (take >= 10 && compositor->enable_video_debug)
 		weston_log("\n timer_handler %d start (%ld.%09ld) end (%ld.%09ld) take:%lld\n", __LINE__,
 			now.tv_sec, now.tv_nsec, t1.tv_sec, t1.tv_nsec, take);
 	if ( need_repaint ) {
 		wl_list_for_each(output, &compositor->output_list, link) {
-			weston_log("\n %s %d ret:%d  need_repaint:%d\n", __FUNCTION__, __LINE__, ret, need_repaint);
+			if (compositor->enable_video_debug)
+				weston_log("\n %s %d ret:%d  need_repaint:%d\n", __FUNCTION__, __LINE__, ret, need_repaint);
 			weston_output_schedule_repaint_reset(output);
 			weston_output_schedule_repaint(output);
 			return 0;
@@ -670,12 +679,32 @@
 	       int32_t keep_last_frame)
 {
 	struct weston_surface *surface = wl_resource_get_user_data(resource);
-	if ( keep_last_frame < 0 )
-		return;
+
 	surface->keep_last_frame = true;
 	if ( keep_last_frame == 0 )
-		surface->keep_last_frame = false;
-	weston_log("\n surface_keep_last_frame:%d \n", surface->keep_last_frame);
+		surface->keep_last_frame = 0;
+	else
+		surface->keep_last_frame = 1;
+
+	if (surface->plane)
+		surface->plane->keep_last_frame = (bool)surface->keep_last_frame;
+	weston_log("\n surface_keep_last_frame surface:%p:%d surface->plane:%p\n", surface, surface->keep_last_frame, surface->plane);
+}
+
+static void
+surface_destroy_callback(struct wl_client *client,
+	      struct wl_resource *resource, uint32_t callback)
+{
+	struct wl_resource *cb;
+		struct weston_surface *surface = wl_resource_get_user_data(resource);
+	cb = wl_resource_create(client, &wl_callback_interface, 1, callback);
+		if (cb == NULL) {
+		wl_resource_post_no_memory(resource);
+		return;
+	}
+	surface->destroy_cb = cb;
+	weston_log("\n %s %d surface:%p cb:%p\n", __FUNCTION__,__LINE__, surface, cb);
+
 }
 
 static void
@@ -689,6 +718,39 @@
 	if (compositor->backend->update_frame_rate)
 		compositor->backend->update_frame_rate(compositor, frame_rate_value, frame_rate_scale);
 }
+#define USE_LOW_LATENCY  "/sys/module/aml_media/parameters/use_low_latency"
+static int set_sysfs_strs(const char *path, const char *val)
+{
+	int fd;
+	int bytes;
+	fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0644);
+	if (fd >= 0) {
+		bytes = write(fd, val, strlen(val));
+		close(fd);
+		if (bytes != strlen(val))
+			return -1;
+		else
+			return 0;
+	}
+	return -1;
+}
+static void
+surface_enable_ll_mode(struct wl_client *client,
+	      struct wl_resource *resource, int enable)
+{
+	struct weston_surface *surface = wl_resource_get_user_data(resource);
+	weston_log("\n %s %d surface:%p enable:%d\n", __FUNCTION__,__LINE__, surface, enable);
+	if (surface) {
+		char s_enable[5] = {'\0'};
+		sprintf(s_enable, "%d", enable);
+		if (set_sysfs_strs(USE_LOW_LATENCY, s_enable) != 0) {
+			weston_log("\n %s %d surface:%p enable:%d fail\n", __FUNCTION__,__LINE__, surface, enable);
+		} else {
+			weston_log("\n %s %d surface:%p enable:%d success\n", __FUNCTION__,__LINE__, surface, enable);
+		}
+	}
+
+}
 
 static FILE *
 file_create(const char *path, const char *prefix, const char *suffix,
@@ -1018,8 +1080,12 @@
 		struct timespec time;
 
 		weston_compositor_get_time(&time);
-		uint64_t commit_time = timespec_to_usec(&time);
-		weston_log("%llu, surface_commit :%p\n", commit_time, surface);
+		int64_t commit_time = timespec_to_usec(&time);
+		char desc[512];
+		if (!surface->get_label || surface->get_label(surface, desc, sizeof(desc)) < 0) {
+			strcpy(desc, "[no description available]");
+		}
+		weston_log("%llu, surface_commit :%p %s %s\n", commit_time, surface, surface->role_name, desc);
 		if ((commit_time - surface->commit_time) > 18000)
 			weston_log("%llu, surface_commit :%p interval > 18ms\n", commit_time, surface);
 		surface->commit_time = commit_time;
diff --git a/aml-weston/aml-util.c b/aml-weston/aml-util.c
new file mode 100644
index 0000000..4dcdaaa
--- /dev/null
+++ b/aml-weston/aml-util.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2022 Amlogic, Inc. All rights reserved.
+ *
+ * This source code is subject to the terms and conditions defined in the
+ * file 'LICENSE' which is part of this source code package.
+ *
+ * Description:
+ */
+#include "aml-util.h"
+bool disable_all_log()
+{
+	bool disable_log = false;
+	char* env_log  = getenv("WESTON_DISABLL_ALL_LOG");
+	fprintf(stderr, "\n WESTON_DISABLL_ALL_LOG :%s \n", env_log);
+	if (env_log && atoi(env_log)) {
+		disable_log = true;
+		fprintf(stderr, "\n disable_log is true :%s \n", env_log);
+	}
+	return disable_log;
+}
+
diff --git a/aml-weston/aml-util.h b/aml-weston/aml-util.h
new file mode 100644
index 0000000..01c4b5d
--- /dev/null
+++ b/aml-weston/aml-util.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2022 Amlogic, Inc. All rights reserved.
+ *
+ * This source code is subject to the terms and conditions defined in the
+ * file 'LICENSE' which is part of this source code package.
+ *
+ * Description:
+ */
+#ifndef AML_UTIL_H
+#define AML_UTIL_H
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+bool disable_all_log();
+#endif
diff --git a/aml-weston/aml_config.c b/aml-weston/aml_config.c
index b3dd818..36254fe 100644
--- a/aml-weston/aml_config.c
+++ b/aml-weston/aml_config.c
@@ -64,7 +64,7 @@
 	wl_resource_set_implementation(resource,
 				       &aml_config_interface_v1,
 				       ec, NULL);
-	const char* aml_config_list = "set_video_plane, keep_last_frame";
+	const char* aml_config_list = "set_video_plane, keep_last_frame, set_display_rate, surface_destroy_cb";
 	aml_config_send_aml_config_list(resource, aml_config_list);
 }
 
diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h
index e8585af..e2bb735 100644
--- a/include/libweston/libweston.h
+++ b/include/libweston/libweston.h
@@ -45,6 +45,7 @@
 #include <libweston/zalloc.h>
 #define MESON_VIDEO_PLAN_SUPPORT 1
 #define SURFACE_QUEUE_CAPACITY 10
+#define INIT_VALUE 255
 
 struct weston_geometry {
 	int32_t x, y;
@@ -1601,10 +1602,11 @@
 	int queue_size;
 	int queue_capacity;
 	void* commit_queue;
-	bool keep_last_frame;
+	int keep_last_frame;
 	int frameN;
 	uint64_t commit_time;
 	struct weston_plane* plane;
+	struct wl_resource *destroy_cb;
 };
 
 struct weston_subsurface {
diff --git a/libweston/backend-drm/drm-internal.h b/libweston/backend-drm/drm-internal.h
index b9ee319..7b471c6 100644
--- a/libweston/backend-drm/drm-internal.h
+++ b/libweston/backend-drm/drm-internal.h
@@ -317,9 +317,7 @@
 	 * after enable fixed ui size.	*/
 	struct weston_size	fixed_ui_size;
 #endif
-#ifdef BUILD_AML_TV
 	int vdin_detect_fd;
-#endif
 	bool allow_modeset;
 	int display_enable;
 };
diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
index d69da58..563a346 100644
--- a/libweston/backend-drm/drm.c
+++ b/libweston/backend-drm/drm.c
@@ -708,9 +708,10 @@
 		return -1;
 	}
 
-	if (&drm_mode->base == output->base.current_mode)
+	if (&drm_mode->base == output->base.current_mode) {
+		weston_log("\n drm_output_switch_mode same mode return \n");
 		return 0;
-
+	}
 	output->base.current_mode->flags = 0;
 
 	drm_switch_mode_aml_config_ui_size(output, output_base, drm_mode);
diff --git a/libweston/backend-drm/fb.c b/libweston/backend-drm/fb.c
index 01b1ee1..5ac46ef 100644
--- a/libweston/backend-drm/fb.c
+++ b/libweston/backend-drm/fb.c
@@ -536,8 +536,8 @@
 	if (ev->alpha != 1.0f)
 		return NULL;
 
-	if (!drm_view_transform_supported(ev, &output->base))
-		return NULL;
+	//if (!drm_view_transform_supported(ev, &output->base))
+	//	return NULL;
 
 	if (ev->surface->protection_mode == WESTON_SURFACE_PROTECTION_MODE_ENFORCED &&
 	    ev->surface->desired_protection > output->base.current_protection)
diff --git a/libweston/backend-drm/kms.c b/libweston/backend-drm/kms.c
index 83ad3cc..b27b3f3 100644
--- a/libweston/backend-drm/kms.c
+++ b/libweston/backend-drm/kms.c
@@ -43,6 +43,7 @@
 #include "presentation-time-server-protocol.h"
 
 #include "aml-weston/aml-backend.h"
+#include "shared/timespec-util.h"
 
 struct drm_property_enum_info plane_type_enums[] = {
 	[WDRM_PLANE_TYPE_PRIMARY] = {
@@ -1424,6 +1425,9 @@
 			 WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION |
 			 WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK;
 
+	struct timespec ts1, ts2, ts3;
+	weston_compositor_get_time(&ts1);
+
 	crtc = drm_crtc_find(b, crtc_id);
 	assert(crtc);
 
@@ -1440,6 +1444,7 @@
 		return;
 
 	drm_output_update_msc(output, frame);
+	weston_compositor_get_time(&ts2);
 
 	drm_debug(b, "[atomic][CRTC:%u] flip processing started output_change:%d\n",
 		crtc_id,crtc->output_change );
@@ -1452,6 +1457,15 @@
 
 	crtc->output_change = false;
 	drm_debug(b, "[atomic][CRTC:%u] flip processing completed\n", crtc_id);
+
+	weston_compositor_get_time(&ts3);
+	if ( (timespec_to_usec(&ts3) - timespec_to_usec(&ts1)) > 10000 )
+		weston_log("\n %s %d take:(%lld %lld %lld)\n",
+		__FUNCTION__,__LINE__,
+		(timespec_to_usec(&ts3) - timespec_to_usec(&ts1)),
+		(timespec_to_usec(&ts2) - timespec_to_usec(&ts1)),
+		(timespec_to_usec(&ts3) - timespec_to_usec(&ts2))
+		);
 	atomic_flip_handler_time(b);
 }
 
@@ -1460,6 +1474,8 @@
 {
 	struct drm_backend *b = data;
 	drmEventContext evctx;
+	struct timespec ts1, ts2, ts3;
+	weston_compositor_get_time(&ts1);
 
 	memset(&evctx, 0, sizeof evctx);
 	evctx.version = 3;
@@ -1467,7 +1483,17 @@
 		evctx.page_flip_handler2 = atomic_flip_handler;
 	else
 		evctx.page_flip_handler = page_flip_handler;
+
+	weston_compositor_get_time(&ts2);
 	drmHandleEvent(fd, &evctx);
+	weston_compositor_get_time(&ts3);
+	if ( (timespec_to_usec(&ts3) - timespec_to_usec(&ts1)) > 10000 )
+			weston_log("\n %s %d  %lld %lld,take:(%lld %lld %lld)\n",
+			__FUNCTION__,__LINE__, timespec_to_usec(&ts1), timespec_to_usec(&ts3),
+			(timespec_to_usec(&ts3) - timespec_to_usec(&ts1)),
+			(timespec_to_usec(&ts2) - timespec_to_usec(&ts1)),
+			(timespec_to_usec(&ts3) - timespec_to_usec(&ts2))
+			);
 
 	return 1;
 }
diff --git a/libweston/backend-drm/state-helpers.c b/libweston/backend-drm/state-helpers.c
index 20c0034..b0388ba 100644
--- a/libweston/backend-drm/state-helpers.c
+++ b/libweston/backend-drm/state-helpers.c
@@ -199,8 +199,8 @@
 	pixman_box32_t *box, tbox;
 	float sxf1, syf1, sxf2, syf2;
 
-	if (!drm_view_transform_supported(ev, &output->base))
-		return false;
+	//if (!drm_view_transform_supported(ev, &output->base))
+	//	return false;
 
 	/* Update the base weston_plane co-ordinates. */
 	box = pixman_region32_extents(&ev->transform.boundingbox);
diff --git a/libweston/backend-drm/state-propose.c b/libweston/backend-drm/state-propose.c
index e5aca12..2fc8da3 100644
--- a/libweston/backend-drm/state-propose.c
+++ b/libweston/backend-drm/state-propose.c
@@ -716,6 +716,8 @@
 	buffer = ev->surface->buffer_ref.buffer;
 	shmbuf = wl_shm_buffer_get(buffer->resource);
 	fb = drm_fb_get_from_view(state, ev, try_view_on_plane_failure_reasons);
+	drm_debug(b, "\t\t\t\t buffer:%p shmbuf:%p fb:%p",
+					 buffer, shmbuf, fb);
 	if (!shmbuf && !fb)
 		return NULL;
 
@@ -1017,9 +1019,15 @@
 			 * no need force to gpu composition.
 			 */
 			if (!ev->surface->is_video_surface) {
-				drm_debug(b, "\t\t\t\t[view]none-video surface not assigning view %p to plane "
+				if (ev->surface->buffer_ref.buffer && is_direct_display(ev->surface->buffer_ref.buffer)) {
+					drm_debug(b, "\t\t\t\t[view]direct display buffer %p to plane "
+						"(client send commit continuous memory buffer)\n", ev);
+				}
+				else {
+					drm_debug(b, "\t\t\t\t[view]none-video surface not assigning view %p to plane "
 						"(occluded by renderer views)\n", ev);
-				force_renderer = true;
+					force_renderer = true;
+				}
 			}
 #else
 			drm_debug(b, "\t\t\t\t[view] not assigning view %p to plane "
@@ -1027,14 +1035,20 @@
 			force_renderer = true;
 #endif
 		}
+		if ((!ev->surface->is_video_surface) && (ev->surface->buffer_ref.buffer)
+			&& (!is_direct_display(ev->surface->buffer_ref.buffer))) {
+			drm_debug(b, "\t\t\t\t[view] view %p not video view not direct display "
+						 "(force render)\n", ev);
+			force_renderer = true;
+		}
 
 #if MESON_VIDEO_PLAN_SUPPORT
 		pixman_region32_intersect(&surface_overlap, &video_cover_region,
 				&clipped_view);
 		if (pixman_region32_not_empty(&surface_overlap)) {
-			if (!ev->surface->is_video_surface) {
+			if (!ev->surface->is_video_surface && (!is_direct_display(ev->surface->buffer_ref.buffer))) {
 				drm_debug(b, "\t\t\t\t[view] not assigning view %p to plane "
-						"(block the video views)\n", ev);
+						"(block the video views) \n", ev);
 				force_renderer = true;
 				pixman_region32_copy(&ev->transform.transparent, &surface_overlap);
 			}
diff --git a/libweston/compositor.c b/libweston/compositor.c
index b993690..55855cb 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -2155,7 +2155,7 @@
 WL_EXPORT void
 weston_compositor_get_time(struct timespec *time)
 {
-	clock_gettime(CLOCK_REALTIME, time);
+	clock_gettime(CLOCK_MONOTONIC, time);
 }
 
 /** weston_compositor_pick_view
@@ -3024,7 +3024,8 @@
 
 	msec_to_repaint = timespec_sub_to_msec(&output->next_repaint, now);
 	if (msec_to_repaint > 1) {
-		weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
+		if (compositor->enable_video_debug)
+			weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
 		return ret;
 	}
 
@@ -3032,13 +3033,15 @@
 	 * explicitly repaint all outputs when we come back. */
 	if (compositor->state == WESTON_COMPOSITOR_SLEEPING ||
 		compositor->state == WESTON_COMPOSITOR_OFFSCREEN) {
-		weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
+		if (compositor->enable_video_debug)
+			weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
 		goto err;
 		}
 	/* We don't actually need to repaint this output; drop it from
 	 * repaint until something causes damage. */
 	if (!output->repaint_needed) {
-		weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
+		if (compositor->enable_video_debug)
+			weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
 		goto err;
 	}
 
@@ -3050,7 +3053,8 @@
 	ret = weston_output_repaint(output, repaint_data);
 	weston_compositor_read_presentation_clock(compositor, now);
 	if (ret != 0) {
-		weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
+		if (compositor->enable_video_debug)
+			weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
 		goto err;
 	}
 	output->repainted = true;
@@ -4088,7 +4092,9 @@
 	surface_set_video_plane,
 	surface_set_pts,
 	surface_keep_last_frame,
-	surface_set_display_rate
+	surface_set_display_rate,
+	surface_destroy_callback,
+	surface_enable_ll_mode
 };
 
 static int
diff --git a/libweston/log.c b/libweston/log.c
index 911feae..8e0838e 100644
--- a/libweston/log.c
+++ b/libweston/log.c
@@ -36,6 +36,7 @@
 
 #include <libweston/libweston.h>
 #include "weston-log-internal.h"
+#include "aml-weston/aml-util.h"
 
 /**
  * \defgroup wlog weston-logging
@@ -90,9 +91,14 @@
  *
  * \ingroup wlog
  */
+
+static bool disable_log = false;
+
 WL_EXPORT void
 weston_log_set_handler(log_func_t log, log_func_t cont)
 {
+	disable_log = disable_all_log();
+
 	log_handler = log;
 	log_continue_handler = cont;
 }
@@ -119,6 +125,9 @@
 WL_EXPORT int
 weston_log(const char *fmt, ...)
 {
+	if (disable_log) {
+		return 0;
+	}
 	int l;
 	va_list argp;
 
diff --git a/libweston/meson.build b/libweston/meson.build
index aace4a6..d67da90 100644
--- a/libweston/meson.build
+++ b/libweston/meson.build
@@ -38,6 +38,7 @@
 	'weston-direct-display.c',
 	'zoom.c',
 	'../aml-weston/aml_config.c',
+	'../aml-weston/aml-util.c',
 	linux_dmabuf_unstable_v1_protocol_c,
 	linux_dmabuf_unstable_v1_server_protocol_h,
 	linux_explicit_synchronization_unstable_v1_protocol_c,
diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c
index 6819e13..062f6e5 100644
--- a/libweston/renderer-gl/gl-renderer.c
+++ b/libweston/renderer-gl/gl-renderer.c
@@ -1783,7 +1783,7 @@
 
 	weston_compositor_get_time(&time);
 	diff = timespec_to_usec(&time) - start;
-	if (diff > 8000)
+	if ( diff > 8000 && compositor->enable_video_debug )
 		weston_log("\n %s %d take:%lld(us)\n", __FUNCTION__, __LINE__, diff);
 }