libvideorender: CF2 add set display rate feature [1/1]

PD#SWPL-172524

Problem:
set frame rate to weston, weston will select drm mode by
frame rate.

Solution:
1.add set display rate feature
2.set default 59.94 fps to weston if frame rate is
invalid

Verify:
ap222

Change-Id: Ie0ed78eb3e747776b3905e3276801b3f3d01b44f
Signed-off-by: fei.deng <fei.deng@amlogic.com>
diff --git a/weston/wayland-protocol/wayland.xml b/weston/wayland-protocol/wayland.xml
index be8b0fe..05f51a5 100644
--- a/weston/wayland-protocol/wayland.xml
+++ b/weston/wayland-protocol/wayland.xml
@@ -431,10 +431,15 @@
   <interface name="wl_buffer" version="1">
     <description summary="content for a wl_surface">
       A buffer provides the content for a wl_surface. Buffers are
-      created through factory interfaces such as wl_drm, wl_shm or
-      similar. It has a width and a height and can be attached to a
-      wl_surface, but the mechanism by which a client provides and
-      updates the contents is defined by the buffer factory interface.
+      created through factory interfaces such as wl_shm, wp_linux_buffer_params
+      (from the linux-dmabuf protocol extension) or similar. It has a width and
+      a height and can be attached to a wl_surface, but the mechanism by which a
+      client provides and updates the contents is defined by the buffer factory
+      interface.
+
+      If the buffer uses a format that has an alpha channel, the alpha channel
+      is assumed to be premultiplied in the color channels unless otherwise
+      specified.
     </description>
 
     <request name="destroy" type="destructor">
@@ -953,9 +958,10 @@
 	immediately before receiving keyboard focus and when a new
 	selection is set while the client has keyboard focus.  The
 	data_offer is valid until a new data_offer or NULL is received
-	or until the client loses keyboard focus.  The client must
-	destroy the previous selection data_offer, if any, upon receiving
-	this event.
+	or until the client loses keyboard focus.  Switching surface with
+	keyboard focus within the same client doesn't mean a new selection
+	will be sent.  The client must destroy the previous selection
+	data_offer, if any, upon receiving this event.
       </description>
       <arg name="id" type="object" interface="wl_data_offer" allow-null="true"
 	   summary="selection data_offer object"/>
@@ -1411,7 +1417,14 @@
 	buffer's upper left corner, relative to the current buffer's upper
 	left corner, in surface-local coordinates. In other words, the
 	x and y, combined with the new surface size define in which
-	directions the surface's size changes.
+	directions the surface's size changes. Setting anything other than 0
+	as x and y arguments is discouraged, and should instead be replaced
+	with using the separate wl_surface.offset request.
+
+	When the bound wl_surface version is 5 or higher, passing any
+	non-zero x or y is a protocol violation, and will result in an
+	'invalid_offset' error being raised. To achieve equivalent semantics,
+	use wl_surface.offset.
 
 	Surface contents are double-buffered state, see wl_surface.commit.
 
@@ -1439,9 +1452,12 @@
 	from the same backing storage or use wp_linux_buffer_release.
 
 	Destroying the wl_buffer after wl_buffer.release does not change
-	the surface contents. However, if the client destroys the
-	wl_buffer before receiving the wl_buffer.release event, the surface
-	contents become undefined immediately.
+	the surface contents. Destroying the wl_buffer before wl_buffer.release
+	is allowed as long as the underlying buffer storage isn't re-used (this
+	can happen e.g. on client process termination). However, if the client
+	destroys the wl_buffer before receiving the wl_buffer.release event and
+	mutates the underlying buffer storage, the surface contents become
+	undefined immediately.
 
 	If wl_surface.attach is sent with a NULL wl_buffer, the
 	following wl_surface.commit will remove the surface content.
@@ -1894,9 +1910,22 @@
 
     <event name="name" since="2">
       <description summary="unique identifier for this seat">
-	In a multiseat configuration this can be used by the client to help
-	identify which physical devices the seat represents. Based on
-	the seat configuration used by the compositor.
+	In a multi-seat configuration the seat name can be used by clients to
+	help identify which physical devices the seat represents.
+
+	The seat name is a UTF-8 string with no convention defined for its
+	contents. Each name is unique among all wl_seat globals. The name is
+	only guaranteed to be unique for the current compositor instance.
+
+	The same seat names are used for all clients. Thus, the name can be
+	shared across processes to refer to a specific wl_seat global.
+
+	The name event is sent after binding to the seat global. This event is
+	only sent once per seat object, and the name does not change over the
+	lifetime of the wl_seat global.
+
+	Compositors may re-use the same seat name if the wl_seat global is
+	destroyed and re-created later.
       </description>
       <arg name="name" type="string" summary="seat identifier"/>
     </event>
@@ -1961,6 +1990,10 @@
 	wl_surface is no longer used as the cursor. When the use as a
 	cursor ends, the current and pending input regions become
 	undefined, and the wl_surface is unmapped.
+
+	The serial parameter must match the latest wl_pointer.enter
+	serial number sent to the client. Otherwise the request will be
+	ignored.
       </description>
       <arg name="serial" type="uint" summary="serial number of the enter event"/>
       <arg name="surface" type="object" interface="wl_surface" allow-null="true"
@@ -2255,7 +2288,8 @@
     <event name="keymap">
       <description summary="keyboard mapping">
 	This event provides a file descriptor to the client which can be
-	memory-mapped to provide a keyboard mapping description.
+	memory-mapped in read-only mode to provide a keyboard mapping
+	description.
 
 	From version 7 onwards, the fd must be mapped with MAP_PRIVATE by
 	the recipient, as MAP_SHARED may fail.
diff --git a/weston/wayland_buffer.cpp b/weston/wayland_buffer.cpp
index 9f21045..01d1cee 100644
--- a/weston/wayland_buffer.cpp
+++ b/weston/wayland_buffer.cpp
@@ -84,7 +84,7 @@
     int fh = waylandBuffer->mDisplay->getFrameHeight();
     if ( (waylandBuffer->mFrameWidth != fw || waylandBuffer->mFrameHeight != fh) &&
             waylandBuffer->mWaylandWlWrap) {
-        TRACE(waylandBuffer->mLogCategory,"to delete WaylandBuffer:%p,WaylandDmaBuffer:%p",waylandBuffer,waylandBuffer->mWaylandWlWrap);
+        TRACE(waylandBuffer->mLogCategory,"resolution changed,delete WaylandBuffer:%p,WaylandDmaBuffer:%p",waylandBuffer,waylandBuffer->mWaylandWlWrap);
         delete waylandBuffer->mWaylandWlWrap;
         waylandBuffer->mWaylandWlWrap = NULL;
     }
diff --git a/weston/wayland_display.cpp b/weston/wayland_display.cpp
index 43ace70..aa96bb9 100644
--- a/weston/wayland_display.cpp
+++ b/weston/wayland_display.cpp
@@ -489,6 +489,10 @@
             TRACE(self->mLogCategory,"weston enable surface_destroy_cb");
             self->mAmlConfigAPIList.enableSurfaceDestroyCallback = true;
         }
+        if (strstr(list, "set_display_rate")) {
+            TRACE(self->mLogCategory,"weston enable set_display_rate");
+            self->mAmlConfigAPIList.enableSetDisplayRate = true;
+        }
     }
 }
 
@@ -690,6 +694,9 @@
     mReCommitAreaSurface = false;
     mXdgSurfaceConfigured = false;
     mUpdateRenderRectangle = false;
+    mFrameRateFractionNum = 0;
+    mFrameRateFractionDenom = 1;
+    mFrameRateChanged = false;
     memset(&mRenderRect, 0, sizeof(struct Rectangle));
     memset(&mVideoRect, 0, sizeof(struct Rectangle));
     memset(&mWindowRect, 0, sizeof(struct Rectangle));
@@ -701,6 +708,7 @@
     mAmlConfigAPIList.enableSetPts = false;
     mAmlConfigAPIList.enableSetVideoPlane = false;
     mAmlConfigAPIList.enableSurfaceDestroyCallback = false;
+    mAmlConfigAPIList.enableSetDisplayRate = false;
     mCurrentDisplayOutput = &mOutput[0];
     for (int i = 0; i < DEFAULT_DISPLAY_OUTPUT_NUM; i++) {
         mOutput[i].wlOutput = NULL;
@@ -1312,6 +1320,12 @@
 
 void WaylandDisplay::displayFrameBuffer(RenderBuffer * buf, int64_t realDisplayTime)
 {
+    //set frame rate to weston,it lets weston to select suitable mode
+    if (mFrameRateChanged && mAmlConfigAPIList.enableSetDisplayRate) {
+        mFrameRateChanged = false;
+        TRACE(mLogCategory,"set frame rate %d/%d to weston", mFrameRateFractionNum, mFrameRateFractionDenom);
+        wl_surface_set_display_rate(mVideoSurfaceWrapper, mFrameRateFractionNum, mFrameRateFractionDenom);
+    }
     //update video surface size
     if (mUpdateVideoSurface && mVideoSurface &&
         buf->dma.width == mVideoWidth && buf->dma.height == mVideoHeight) {
@@ -1663,4 +1677,21 @@
         return;
     }
     mToSendKeepLastFrame = true;
+}
+
+void WaylandDisplay::setFrameRate(int frameRateNum, int frameRateDenom)
+{
+    mFrameRateFractionNum = frameRateNum;
+    mFrameRateFractionDenom = frameRateDenom;
+    if (mFrameRateFractionDenom == 0) {
+        mFrameRateFractionDenom = 1;
+    }
+    /*cobalt is not set frame rate to gst pipeline. we set default 59.94
+    frame rate to weston*/
+    if (mFrameRateFractionNum == 0 && mFrameRateFractionDenom == 1) {
+        mFrameRateFractionNum = 59940;
+        mFrameRateFractionDenom = 1000;
+    }
+    mFrameRateChanged = true;
+    INFO(mLogCategory,"num:%d,denom:%d",mFrameRateFractionNum, mFrameRateFractionDenom);
 }
\ No newline at end of file
diff --git a/weston/wayland_display.h b/weston/wayland_display.h
index 3c3fa59..a8349ba 100644
--- a/weston/wayland_display.h
+++ b/weston/wayland_display.h
@@ -51,6 +51,7 @@
         bool enableDropFrame;
         bool enableKeepLastFrame;
         bool enableSurfaceDestroyCallback;
+        bool enableSetDisplayRate;
     } AmlConfigAPIList;
 
     WaylandDisplay(WaylandPlugin *plugin, int logCategory);
@@ -175,6 +176,8 @@
         return mVideoHeight;
     };
 
+    void setFrameRate(int frameRateNum, int frameRateDenom);
+
     void handleBufferReleaseCallback(WaylandBuffer *buf);
     void handleFrameDisplayedCallback(WaylandBuffer *buf);
     void handleFrameDropedCallback(WaylandBuffer *buf);
@@ -376,6 +379,11 @@
 
     double mPixelAspectRatio;
     bool mUpdateVideoSurface; //default false
+
+    /*frame rate info*/
+    int mFrameRateFractionNum;
+    int mFrameRateFractionDenom;
+    bool mFrameRateChanged;
 };
 
 #endif /*__WAYLAND_DISPLAY_H__*/
\ No newline at end of file
diff --git a/weston/wayland_plugin.cpp b/weston/wayland_plugin.cpp
index ee6807c..95c7841 100644
--- a/weston/wayland_plugin.cpp
+++ b/weston/wayland_plugin.cpp
@@ -249,6 +249,11 @@
             INFO(mLogCategory,"pixel aspect ratio :%f",ratio);
             mDisplay->setPixelAspectRatio((double)ratio);
         } break;
+        case PLUGIN_KEY_VIDEO_FRAME_RATE: {
+            RenderFraction * fraction = static_cast<RenderFraction*>(value);
+            INFO(mLogCategory,"frame rate,num:%d,denom:%d",fraction->num,fraction->denom);
+            mDisplay->setFrameRate(fraction->num, fraction->denom);
+        } break;
     }
     return 0;
 }