OSDN Git Service

drm_hwcomposer: Add checking if we can import a buffer
authorAlexey Firago <alexey_firago@mentor.com>
Wed, 21 Nov 2018 20:47:05 +0000 (23:47 +0300)
committerAlexey Firago <alexey_firago@mentor.com>
Tue, 27 Nov 2018 08:45:41 +0000 (11:45 +0300)
Add CanImportBuffer() function to the Importer interface.
Platform specific importer should check in this function if it can
import given buffer_handle_t. For example platformhisi will return
false for buffers without GRALLOC_USAGE_HW_FB.

This function should be used on ValidateDisplay step to avoid the
need of 'fake-importing' of buffers.

Signed-off-by: Alexey Firago <alexey_firago@mentor.com>
drmhwctwo.cpp
platform.h
platformdrmgeneric.cpp
platformdrmgeneric.h
platformhisi.cpp
platformhisi.h

index c801f2e..cd79e7b 100644 (file)
@@ -491,9 +491,13 @@ HWC2::Error DrmHwcTwo::HwcDisplay::CreateComposition(bool test) {
   std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map;
   for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
     HWC2::Composition comp_type;
-    if (test)
+    if (test) {
       comp_type = l.second.sf_type();
-    else
+      if (comp_type == HWC2::Composition::Device) {
+        if (!importer_->CanImportBuffer(l.second.buffer()))
+          comp_type = HWC2::Composition::Client;
+      }
+    } else
       comp_type = l.second.validated_type();
 
     switch (comp_type) {
@@ -735,7 +739,8 @@ HWC2::Error DrmHwcTwo::HwcDisplay::ValidateDisplay(uint32_t *num_types,
   for (std::pair<const uint32_t, DrmHwcTwo::HwcLayer *> &l : z_map) {
     if (comp_failed || !avail_planes--)
       break;
-    l.second->set_validated_type(HWC2::Composition::Device);
+    if (importer_->CanImportBuffer(l.second->buffer()))
+      l.second->set_validated_type(HWC2::Composition::Device);
   }
 
   for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
index 547a297..a58d62e 100644 (file)
@@ -49,6 +49,9 @@ class Importer {
   // Note: This can be called from a different thread than ImportBuffer. The
   //       implementation is responsible for ensuring thread safety.
   virtual int ReleaseBuffer(hwc_drm_bo_t *bo) = 0;
+
+  // Checks if importer can import the buffer.
+  virtual bool CanImportBuffer(buffer_handle_t handle) = 0;
 };
 
 class Planner {
index 24d0650..503c04a 100644 (file)
@@ -161,6 +161,12 @@ int DrmGenericImporter::ReleaseBuffer(hwc_drm_bo_t *bo) {
   return 0;
 }
 
+bool DrmGenericImporter::CanImportBuffer(buffer_handle_t handle) {
+  if (handle == NULL)
+    return false;
+  return true;
+}
+
 #ifdef USE_DRM_GENERIC_IMPORTER
 std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) {
   std::unique_ptr<Planner> planner(new Planner);
index d46e8b0..233ba55 100644 (file)
@@ -33,6 +33,7 @@ class DrmGenericImporter : public Importer {
 
   int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
   int ReleaseBuffer(hwc_drm_bo_t *bo) override;
+  bool CanImportBuffer(buffer_handle_t handle) override;
 
   uint32_t ConvertHalFormatToDrm(uint32_t hal_format);
   uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format);
index bf4033b..c5cadf6 100644 (file)
@@ -139,6 +139,12 @@ int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
   return ret;
 }
 
+bool HisiImporter::CanImportBuffer(buffer_handle_t handle) {
+  private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
+      handle);
+  return hnd && (hnd->usage & GRALLOC_USAGE_HW_FB);
+}
+
 class PlanStageHiSi : public Planner::PlanStage {
  public:
   int ProvisionPlanes(std::vector<DrmCompositionPlane> *composition,
index 2b2d439..927da17 100644 (file)
@@ -36,6 +36,8 @@ class HisiImporter : public DrmGenericImporter {
 
   int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
 
+  bool CanImportBuffer(buffer_handle_t handle) override;
+
  private:
   DrmDevice *drm_;