weston: all patch add merge weston [1/1]

PD#SWPL-169736

Problem:
all patch merge to weston

Solution:
all patch merge to weston

Verify:
ah212

Change-Id: I15b12aa89264c6b129d7bc64f3fc44b8a541286d
Signed-off-by: leng.fang <leng.fang@amlogic.com>
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 66d4337..b90e02f 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -79,6 +79,7 @@
 
 #include "weston-log-internal.h"
 
+#include "../aml-weston/aml-compositor.c"
 /**
  * \defgroup head Head
  * \defgroup output Output
@@ -410,6 +411,9 @@
 	pixman_region32_init(&view->geometry.scissor);
 	pixman_region32_init(&view->transform.boundingbox);
 	view->transform.dirty = 1;
+#ifdef MESON_VIDEO_PLAN_SUPPORT
+	pixman_region32_init(&view->transform.transparent);
+#endif
 
 	return view;
 }
@@ -557,8 +561,6 @@
 	pixman_region32_fini(&state->damage_surface);
 	pixman_region32_fini(&state->damage_buffer);
 
-	if (state->buffer)
-		wl_list_remove(&state->buffer_destroy_listener.link);
 	state->buffer = NULL;
 
 	fd_clear(&state->acquire_fence_fd);
@@ -572,12 +574,12 @@
 	if (state->buffer == buffer)
 		return;
 
-	if (state->buffer)
-		wl_list_remove(&state->buffer_destroy_listener.link);
+	/*if (state->buffer)
+		wl_list_remove(&state->buffer_destroy_listener.link);*/
 	state->buffer = buffer;
-	if (state->buffer)
+	/*if (state->buffer)
 		wl_signal_add(&state->buffer->destroy_signal,
-			      &state->buffer_destroy_listener);
+			      &state->buffer_destroy_listener);*/
 }
 
 WL_EXPORT struct weston_surface *
@@ -626,6 +628,8 @@
 	surface->current_protection = WESTON_HDCP_DISABLE;
 	surface->protection_mode = WESTON_SURFACE_PROTECTION_MODE_RELAXED;
 
+	weston_init_video_surface_info(surface);
+
 	return surface;
 }
 
@@ -2268,7 +2272,6 @@
 weston_view_destroy(struct weston_view *view)
 {
 	struct weston_paint_node *pnode, *pntmp;
-
 	weston_signal_emit_mutable(&view->destroy_signal, view);
 
 	assert(wl_list_empty(&view->geometry.child_list));
@@ -2289,6 +2292,9 @@
 	pixman_region32_fini(&view->geometry.scissor);
 	pixman_region32_fini(&view->transform.boundingbox);
 	pixman_region32_fini(&view->transform.opaque);
+#ifdef MESON_VIDEO_PLAN_SUPPORT
+	pixman_region32_fini(&view->transform.transparent);
+#endif
 
 	weston_view_set_transform_parent(view, NULL);
 	weston_view_set_output(view, NULL);
@@ -2301,6 +2307,7 @@
 WL_EXPORT void
 weston_surface_destroy(struct weston_surface *surface)
 {
+	weston_log("\n weston_surface_destroy :%p\n", surface);
 	struct wl_resource *cb, *next;
 	struct weston_view *ev, *nv;
 	struct weston_pointer_constraint *constraint, *next_constraint;
@@ -2348,7 +2355,9 @@
 
 	fd_clear(&surface->acquire_fence_fd);
 
+	weston_clear_video_surface_info(surface);
 	free(surface);
+	weston_log("\n weston_surface_destroy :%p end\n", surface);
 }
 
 static void
@@ -2380,6 +2389,7 @@
 	struct weston_buffer *buffer =
 		container_of(listener, struct weston_buffer, destroy_listener);
 
+	weston_log("\n weston_buffer_destroy_handler buffer:%p\n",buffer);
 	weston_signal_emit_mutable(&buffer->destroy_signal, buffer);
 	free(buffer);
 }
@@ -2430,7 +2440,7 @@
 		ref->buffer->busy_count--;
 		if (ref->buffer->busy_count == 0) {
 			assert(wl_resource_get_client(ref->buffer->resource));
-			wl_buffer_send_release(ref->buffer->resource);
+			buffer_send_release(ref);
 		}
 		wl_list_remove(&ref->destroy_listener.link);
 	}
@@ -2518,6 +2528,7 @@
 			weston_surface_unmap(surface);
 	}
 
+	weston_video_surface_attach(surface, buffer);
 	surface->compositor->renderer->attach(surface, buffer);
 
 	weston_surface_calculate_size_from_buffer(surface);
@@ -2588,7 +2599,11 @@
 	pixman_region32_union(&view->plane->damage,
 			      &view->plane->damage, &damage);
 	pixman_region32_fini(&damage);
+#if MESON_VIDEO_PLAN_SUPPORT
+	pixman_region32_union(&view->clip, &view->clip, opaque);
+#else
 	pixman_region32_copy(&view->clip, opaque);
+#endif
 	pixman_region32_union(opaque, opaque, &view->transform.opaque);
 }
 
@@ -2611,6 +2626,13 @@
 				 z_order_link) {
 			if (pnode->view->plane != plane)
 				continue;
+#if MESON_VIDEO_PLAN_SUPPORT
+			// meson platform video plane is below primary plane.(but the zpos may hight then primary plane.
+			// Avoid video plane region make the primary plane be occlude.
+
+			// We assume the overlay plane only have one surface, on weston just primary plane support glrender compositor.
+			if (!pnode->view->surface->is_video_surface)
+#endif
 
 			view_accumulate_damage(pnode->view, &opaque);
 		}
@@ -2951,7 +2973,12 @@
 	weston_compositor_repick(ec);
 
 	frame_time_msec = timespec_to_msec(&output->frame_time);
+	if (ec->enable_video_debug) {
+		struct timespec time;
 
+		weston_compositor_get_time(&time);
+		weston_log("%llu repaint send done\n", timespec_to_usec(&time));
+	}
 	wl_resource_for_each_safe(cb, cnext, &frame_callback_list) {
 		wl_callback_send_done(cb, frame_time_msec);
 		wl_resource_destroy(cb);
@@ -2988,19 +3015,24 @@
 		return ret;
 
 	msec_to_repaint = timespec_sub_to_msec(&output->next_repaint, now);
-	if (msec_to_repaint > 1)
+	if (msec_to_repaint > 1) {
+		weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
 		return ret;
+	}
 
 	/* If we're sleeping, drop the repaint machinery entirely; we will
 	 * explicitly repaint all outputs when we come back. */
 	if (compositor->state == WESTON_COMPOSITOR_SLEEPING ||
-	    compositor->state == WESTON_COMPOSITOR_OFFSCREEN)
+		compositor->state == WESTON_COMPOSITOR_OFFSCREEN) {
+		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)
+	if (!output->repaint_needed) {
+		weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
 		goto err;
+	}
 
 	/* If repaint fails, we aren't going to get weston_output_finish_frame
 	 * to trigger a new repaint, so drop it from repaint and hope
@@ -3009,9 +3041,10 @@
 	 * output. */
 	ret = weston_output_repaint(output, repaint_data);
 	weston_compositor_read_presentation_clock(compositor, now);
-	if (ret != 0)
+	if (ret != 0) {
+		weston_log("\n %s %d return ret:%d\n", __FUNCTION__,__LINE__,ret);
 		goto err;
-
+	}
 	output->repainted = true;
 	return ret;
 
@@ -3501,6 +3534,7 @@
 	wl_resource_set_implementation(cb, NULL, NULL,
 				       destroy_frame_callback);
 
+	wl_list_init(&surface->pending.frame_callback_list);
 	wl_list_insert(surface->pending.frame_callback_list.prev,
 		       wl_resource_get_link(cb));
 }
@@ -3919,6 +3953,7 @@
 	struct weston_surface *surface = wl_resource_get_user_data(resource);
 	struct weston_subsurface *sub = weston_surface_to_subsurface(surface);
 
+	weston_surface_commit_time(surface);
 	if (!weston_surface_is_pending_viewport_source_valid(surface)) {
 		assert(surface->viewport_resource);
 
@@ -3980,7 +4015,7 @@
 	}
 
 	if (sub) {
-		weston_subsurface_commit(sub);
+		weston_video_subsurface_commit(surface, sub);
 		return;
 	}
 
@@ -4041,7 +4076,11 @@
 	surface_commit,
 	surface_set_buffer_transform,
 	surface_set_buffer_scale,
-	surface_damage_buffer
+	surface_damage_buffer,
+	surface_set_video_plane,
+	surface_set_pts,
+	surface_keep_last_frame,
+	surface_set_display_rate
 };
 
 static int
@@ -4782,6 +4821,7 @@
 static void
 weston_subsurface_destroy(struct weston_subsurface *sub)
 {
+	weston_log("\nweston_subsurface_destroy sub:%p ->%p\n", sub, sub->surface);
 	struct weston_view *view, *next;
 
 	assert(sub->surface);
@@ -4853,6 +4893,7 @@
 	weston_surface_state_init(&sub->cached);
 	sub->cached_buffer_ref.buffer = NULL;
 	sub->synchronized = 1;
+	weston_log("\n weston_subsurface_create :%p sub:%p\n",surface, sub );
 
 	return sub;
 }
@@ -5197,6 +5238,10 @@
 				    mode->height,
 				    mode->refresh);
 	}
+	struct drm_output *drm_output = to_drm_output(output);
+	int crtc_index = drm_output->crtc->pipe;
+	if (version >= WL_OUTPUT_CRTC_INDEX_SINCE_VERSION)
+	    wl_output_send_crtc_index(resource, crtc_index);
 
 	if (version >= WL_OUTPUT_DONE_SINCE_VERSION)
 		wl_output_send_done(resource);
@@ -7479,6 +7524,9 @@
 		fprintf(fp, "\t\t\tformat: 0x%lx %s\n",
 			(unsigned long) _format,
 			pixel_info ? pixel_info->drm_format_name : "UNKNOWN");
+#ifdef ENABLE_DRM_HELP
+		debug_write_shm_buffer_to_file(view, shm);
+#endif
 		return;
 	}
 
@@ -7495,6 +7543,9 @@
 		fprintf(fp, "\t\t\tmodifier: %s\n", modifier_name ? modifier_name :
 				"Failed to convert to a modifier name");
 		free(modifier_name);
+#ifdef ENABLE_DRM_HELP
+		debug_write_dma_buffer_to_file(view, dmabuf);
+#endif
 		return;
 	}
 
@@ -7508,6 +7559,7 @@
 	struct weston_output *output;
 	char desc[512];
 	pixman_box32_t *box;
+	pixman_box32_t *opaque_surface_box;
 	uint32_t surface_id = 0;
 	pid_t pid = 0;
 
@@ -7522,9 +7574,9 @@
 	    view->surface->get_label(view->surface, desc, sizeof(desc)) < 0) {
 		strcpy(desc, "[no description available]");
 	}
-	fprintf(fp, "\tView %d (role %s, PID %d, surface ID %u, %s, %p):\n",
+	fprintf(fp, "\tView %d (role %s, PID %d, surface ID %u, %s, %p %p video surface:%d):\n",
 		view_idx, view->surface->role_name, pid, surface_id,
-		desc, view);
+		desc, view, view->surface, view->surface->is_video_surface);
 
 	box = pixman_region32_extents(&view->transform.boundingbox);
 	fprintf(fp, "\t\tposition: (%d, %d) -> (%d, %d)\n",
@@ -7539,6 +7591,9 @@
 		fprintf(fp, "\t\t[opaque: (%d, %d) -> (%d, %d)]\n",
 			box->x1, box->y1, box->x2, box->y2);
 	}
+	opaque_surface_box = pixman_region32_extents(&view->surface->opaque);
+	fprintf(fp, "\t\t[surface:%p opaque: (%d, %d) -> (%d, %d)]\n",
+			view->surface, opaque_surface_box->x1, opaque_surface_box->y1, opaque_surface_box->x2, opaque_surface_box->y2);
 
 	if (view->alpha < 1.0)
 		fprintf(fp, "\t\talpha: %f\n", view->alpha);
@@ -7802,6 +7857,10 @@
 	if (weston_input_init(ec) != 0)
 		goto fail;
 
+	if (aml_config_setup(ec) != 0 ) {
+		weston_log("\n aml config fail\n");
+	}
+
 	wl_list_init(&ec->view_list);
 	wl_list_init(&ec->plane_list);
 	wl_list_init(&ec->layer_list);
@@ -7815,6 +7874,7 @@
 	wl_list_init(&ec->touch_binding_list);
 	wl_list_init(&ec->axis_binding_list);
 	wl_list_init(&ec->debug_binding_list);
+	wl_list_init(&ec->video_surface_list);
 
 	wl_list_init(&ec->plugin_api_list);
 
@@ -7828,8 +7888,9 @@
 	loop = wl_display_get_event_loop(ec->wl_display);
 	ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec);
 	ec->repaint_timer =
-		wl_event_loop_add_timer(loop, output_repaint_timer_handler,
+		wl_event_loop_add_timer(loop, output_repaint_timer_handler_aml,
 					ec);
+	wl_event_source_timer_update(ec->repaint_timer, 16);
 
 	weston_layer_init(&ec->fade_layer, ec);
 	weston_layer_init(&ec->cursor_layer, ec);
@@ -7850,6 +7911,7 @@
 						weston_timeline_create_subscription,
 						weston_timeline_destroy_subscription,
 						ec);
+	weston_compositor_aml_init(ec);
 	return ec;
 
 fail: