OSDN Git Service

Add support to query supported format from DisplayPlane.
authorXiaosong Wei <xiaosong.wei@intel.com>
Mon, 2 Oct 2017 07:22:49 +0000 (00:22 -0700)
committerKalyan Kondapally <kalyan.kondapally@intel.com>
Tue, 3 Oct 2017 22:44:03 +0000 (15:44 -0700)
When unable to directly use Display Composition for layers,
we want to fall back to a optimal format which can be scanned out.
This information needs to be queried from DisplayPlane. We now
add the needed support and use this format when creating offscreen
buffers, rather than hardcoding it like now.

Jira: None.
Test: Build passes on Linux and Android. No regressions on Linux
      and Android.
Signed-off-by: Xiaosong Wei <xiaosong.wei@intel.com>
common/compositor/nativesurface.cpp
common/compositor/nativesurface.h
common/display/displayplanemanager.cpp
wsi/displayplane.h
wsi/drm/drmplane.cpp
wsi/drm/drmplane.h

index a7dbd9f..fb7eb11 100644 (file)
@@ -41,7 +41,7 @@ NativeSurface::~NativeSurface() {
   }
 }
 
-bool NativeSurface::Init(NativeBufferHandler *buffer_handler,
+bool NativeSurface::Init(NativeBufferHandler *buffer_handler, uint32_t format,
                          bool cursor_layer) {
   buffer_handler_ = buffer_handler;
   uint32_t usage = hwcomposer::kLayerNormal;
@@ -49,7 +49,8 @@ bool NativeSurface::Init(NativeBufferHandler *buffer_handler,
     usage = hwcomposer::kLayerCursor;
   }
 
-  buffer_handler_->CreateBuffer(width_, height_, 0, &native_handle_, usage);
+  buffer_handler_->CreateBuffer(width_, height_, format, &native_handle_,
+                                usage);
   if (!native_handle_) {
     ETRACE("NativeSurface: Failed to create buffer.");
     return false;
index e9d0cd2..4e45ac9 100644 (file)
@@ -36,7 +36,8 @@ class NativeSurface {
 
   virtual ~NativeSurface();
 
-  bool Init(NativeBufferHandler* buffer_handler, bool cursor_layer = false);
+  bool Init(NativeBufferHandler* buffer_handler, uint32_t format,
+            bool cursor_layer = false);
 
   bool InitializeForOffScreenRendering(NativeBufferHandler* buffer_handler,
                                        HWCNativeHandle native_handle);
index af06149..19a740a 100644 (file)
@@ -243,16 +243,20 @@ void DisplayPlaneManager::SetOffScreenPlaneTarget(DisplayPlaneState &plane) {
 void DisplayPlaneManager::SetOffScreenCursorPlaneTarget(
     DisplayPlaneState &plane, uint32_t width, uint32_t height) {
   NativeSurface *surface = NULL;
+  uint32_t preferred_format = plane.plane()->GetPreferredFormat();
   for (auto &fb : cursor_surfaces_) {
     if (!fb->InUse()) {
-      surface = fb.get();
-      break;
+      uint32_t surface_format = fb->GetLayer()->GetBuffer()->GetFormat();
+      if (preferred_format == surface_format) {
+        surface = fb.get();
+        break;
+      }
     }
   }
 
   if (!surface) {
     NativeSurface *new_surface = Create3DBuffer(width, height);
-    new_surface->Init(buffer_handler_, true);
+    new_surface->Init(buffer_handler_, preferred_format, true);
     cursor_surfaces_.emplace_back(std::move(new_surface));
     surface = cursor_surfaces_.back().get();
   }
@@ -289,16 +293,20 @@ void DisplayPlaneManager::ReleaseFreeOffScreenTargets() {
 
 void DisplayPlaneManager::EnsureOffScreenTarget(DisplayPlaneState &plane) {
   NativeSurface *surface = NULL;
+  uint32_t preferred_format = plane.plane()->GetPreferredFormat();
   for (auto &fb : surfaces_) {
     if (!fb->InUse()) {
-      surface = fb.get();
-      break;
+      uint32_t surface_format = fb->GetLayer()->GetBuffer()->GetFormat();
+      if (preferred_format == surface_format) {
+        surface = fb.get();
+        break;
+      }
     }
   }
 
   if (!surface) {
     NativeSurface *new_surface = Create3DBuffer(width_, height_);
-    new_surface->Init(buffer_handler_);
+    new_surface->Init(buffer_handler_, preferred_format);
     surfaces_.emplace_back(std::move(new_surface));
     surface = surfaces_.back().get();
   }
index a531d95..73900fd 100644 (file)
@@ -46,6 +46,12 @@ class DisplayPlane {
    */
   virtual uint32_t GetPreferredVideoFormat() const = 0;
 
+  /**
+   * API for querying preferred format supported by this
+   * plane for non-media content.
+   */
+  virtual uint32_t GetPreferredFormat() const = 0;
+
   virtual void Dump() const = 0;
 };
 
index 29f2529..d5dfd3c 100644 (file)
@@ -78,22 +78,25 @@ bool DrmPlane::Initialize(uint32_t gpu_fd,
     }
   }
 
-  if (prefered_video_format_ == 0) {
-    for (uint32_t j = 0; j < total_size; j++) {
-      uint32_t format = supported_formats_.at(j);
-      switch (format) {
-        case DRM_FORMAT_RGB888:
-        case DRM_FORMAT_XRGB8888:
-        case DRM_FORMAT_XBGR8888:
-        case DRM_FORMAT_RGBX8888:
-        case DRM_FORMAT_ABGR8888:
-        case DRM_FORMAT_RGBA8888:
-          prefered_video_format_ = format;
-          break;
-      }
+  for (uint32_t j = 0; j < total_size; j++) {
+    uint32_t format = supported_formats_.at(j);
+    switch (format) {
+      case DRM_FORMAT_RGB888:
+      case DRM_FORMAT_XRGB8888:
+      case DRM_FORMAT_XBGR8888:
+      case DRM_FORMAT_RGBX8888:
+      case DRM_FORMAT_ABGR8888:
+      case DRM_FORMAT_RGBA8888:
+      case DRM_FORMAT_BGRA8888:
+        prefered_format_ = format;
+        break;
     }
   }
 
+  if (prefered_video_format_ == 0) {
+    prefered_video_format_ = prefered_format_;
+  }
+
   ScopedDrmObjectPropertyPtr plane_props(
       drmModeObjectGetProperties(gpu_fd, id_, DRM_MODE_OBJECT_PLANE));
   if (!plane_props) {
@@ -366,6 +369,10 @@ uint32_t DrmPlane::GetPreferredVideoFormat() const {
   return prefered_video_format_;
 }
 
+uint32_t DrmPlane::GetPreferredFormat() const {
+  return prefered_format_;
+}
+
 void DrmPlane::Dump() const {
   DUMPTRACE("Plane Information Starts. -------------");
   DUMPTRACE("Plane ID: %d", id_);
@@ -427,7 +434,8 @@ void DrmPlane::Dump() const {
   if (in_fence_fd_prop_.id != 0)
     DUMPTRACE("IN_FENCE_FD is supported.");
 
-  DUMPTRACE("Preferred Video Formar: %4.4s", (char*)&(prefered_video_format_));
+  DUMPTRACE("Preferred Video Format: %4.4s", (char*)&(prefered_video_format_));
+  DUMPTRACE("Preferred Video Format: %4.4s", (char*)&(prefered_format_));
 
   DUMPTRACE("Plane Information Ends. -------------");
 }
index d6b0573..6209dc3 100644 (file)
@@ -66,6 +66,7 @@ class DrmPlane : public DisplayPlane {
 
   uint32_t GetFormatForFrameBuffer(uint32_t format) override;
   uint32_t GetPreferredVideoFormat() const override;
+  uint32_t GetPreferredFormat() const override;
 
   void Dump() const override;
 
@@ -104,6 +105,7 @@ class DrmPlane : public DisplayPlane {
   std::vector<uint32_t> supported_formats_;
   int32_t kms_fence_ = 0;
   uint32_t prefered_video_format_ = 0;
+  uint32_t prefered_format_ = 0;
 };
 
 }  // namespace hwcomposer