commit 1b3c8b7701c2ed471d88cae8ae475810a654c598
Author: Shuai.Zeng <Shuai.Zeng@desay-svautomotive.com>
Date:   Wed Jul 19 13:54:57 2017 +0800

    set display mode use drmModeSetPlane

diff --git a/kmscube.c b/kmscube.c
index 9dbefa3..f781aa0 100644
--- a/kmscube.c
+++ b/kmscube.c
@@ -74,6 +74,8 @@ static struct {
 	uint32_t encoder[MAX_DISPLAYS];
 	drmModeModeInfo *mode[MAX_DISPLAYS];
 	drmModeConnector *connectors[MAX_DISPLAYS];
+		drmModePlaneRes *plane_resources;
+		drmModePlanePtr current_plane;
 } drm;
 
 struct drm_fb {
@@ -91,6 +93,9 @@ static int init_drm(void)
 	drmModeEncoder *encoder = NULL;
 	drmModeCrtc *crtc = NULL;
 
+	drmModePlaneRes *vid_plane_resources;
+	drmModePlanePtr current_plane;
+
 	int i, j, k;
 	uint32_t maxRes, curRes;
 
@@ -117,6 +122,24 @@ static int init_drm(void)
 	}
 	drm.resource_id = (uint32_t) resources;
 
+
+	vid_plane_resources = drmModeGetPlaneResources(drm.fd);
+	if (!vid_plane_resources) {
+		printf("drmModeGetVidPlaneResources failed: %s", strerror(errno));
+		return -1;
+	}
+	
+	for (j = 2; j < vid_plane_resources->count_planes; j++) {
+		current_plane = drmModeGetPlane(drm.fd, vid_plane_resources->planes[j]);
+		if (current_plane != NULL) {
+			break;
+		}
+		printf("could not get plane %i: %s",
+			vid_plane_resources->planes[j], strerror(errno));
+		return -1;
+	}
+
+
 	/* find a connected connector: */
 	for (i = 0; i < resources->count_connectors; i++) {
 		connector = drmModeGetConnector(drm.fd, resources->connectors[i]);
@@ -201,6 +224,10 @@ static int init_drm(void)
 			drm.crtc_id[drm.ndisp] = encoder->crtc_id;
 			drm.connectors[drm.ndisp] = connector;
 
+	        drm.plane_resources = vid_plane_resources;
+	        drm.current_plane = current_plane;
+
+
 			printf("### Display [%d]: CRTC = %d, Connector = %d\n", drm.ndisp, drm.crtc_id[drm.ndisp], drm.connector_id[drm.ndisp]);
 			printf("\tMode chosen [%s] : Clock => %d, Vertical refresh => %d, Type => %d\n", drm.mode[drm.ndisp]->name, drm.mode[drm.ndisp]->clock, drm.mode[drm.ndisp]->vrefresh, drm.mode[drm.ndisp]->type);
 			printf("\tHorizontal => %d, %d, %d, %d, %d\n", drm.mode[drm.ndisp]->hdisplay, drm.mode[drm.ndisp]->hsync_start, drm.mode[drm.ndisp]->hsync_end, drm.mode[drm.ndisp]->htotal, drm.mode[drm.ndisp]->hskew);
@@ -786,7 +813,7 @@ int main(int argc, char *argv[])
 	eglSwapBuffers(gl.display, gl.surface);
 	bo = gbm_surface_lock_front_buffer(gbm.surface);
 	fb = drm_fb_get_from_bo(bo);
-
+#if 0
 	/* set mode: */
 	if (all_display) {
 		for (i=0; i<drm.ndisp; i++) {
@@ -805,7 +832,7 @@ int main(int argc, char *argv[])
 			return ret;
 		}
 	}
-
+#endif
 	while (frame_count != 0) {
 		struct gbm_bo *next_bo;
 		int waiting_for_flip = 1;
@@ -821,6 +848,19 @@ int main(int argc, char *argv[])
 		 * hw composition
 		 */
 
+		ret = drmModeSetPlane(drm.fd, drm.current_plane->plane_id,
+				drm.crtc_id[DISP_ID], fb->fb_id, 0,
+				/* Use x and y as co-ordinates of overlay */
+				0, 0, drm.mode[DISP_ID]->hdisplay, drm.mode[DISP_ID]->vdisplay,
+				/* Consider source x and y is 0 always */
+				0, 0, (drm.mode[DISP_ID]->hdisplay) << 16,
+				(drm.mode[DISP_ID]->vdisplay) << 16);
+
+		if (ret) {
+			printf("failed to queue page flip: %s\n", strerror(errno));
+			return NULL;
+		}
+#if 0
 		ret = drmModePageFlip(drm.fd, drm.crtc_id[DISP_ID], fb->fb_id,
 				DRM_MODE_PAGE_FLIP_EVENT, &waiting_for_flip);
 		if (ret) {
@@ -841,7 +881,7 @@ int main(int argc, char *argv[])
 			}
 			drmHandleEvent(drm.fd, &evctx);
 		}
-
+#endif
 		/* release last buffer to render on again: */
 		gbm_surface_release_buffer(gbm.surface, bo);
 		bo = next_bo;
