diff mbox

[hwc,v2,11/18] drm_hwcomposer: Add utility functions to copy displaycomposition internals

Message ID 1523460149-1740-12-git-send-email-alexandru-cosmin.gheorghe@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alexandru-Cosmin Gheorghe April 11, 2018, 3:22 p.m. UTC
Add utility functions to copy the DrmHwcLayer and DrmCompositionPlanes
from another DrmDisplayComposition.

Signed-off-by: Alexandru Gheorghe <alexandru-cosmin.gheorghe@arm.com>
---
 drmdisplaycomposition.cpp | 29 +++++++++++++++++++++++++++++
 drmdisplaycomposition.h   |  3 +++
 2 files changed, 32 insertions(+)

Comments

Sean Paul April 17, 2018, 4:34 p.m. UTC | #1
On Wed, Apr 11, 2018 at 04:22:22PM +0100, Alexandru Gheorghe wrote:
> Add utility functions to copy the DrmHwcLayer and DrmCompositionPlanes
> from another DrmDisplayComposition.
> 
> Signed-off-by: Alexandru Gheorghe <alexandru-cosmin.gheorghe@arm.com>
> ---
>  drmdisplaycomposition.cpp | 29 +++++++++++++++++++++++++++++
>  drmdisplaycomposition.h   |  3 +++
>  2 files changed, 32 insertions(+)
> 
> diff --git a/drmdisplaycomposition.cpp b/drmdisplaycomposition.cpp
> index 66e67a4..dd64f46 100644
> --- a/drmdisplaycomposition.cpp
> +++ b/drmdisplaycomposition.cpp
> @@ -99,6 +99,35 @@ int DrmDisplayComposition::SetLayers(DrmHwcLayer *layers, size_t num_layers,
>    return 0;
>  }
>  
> +int DrmDisplayComposition::CopyLayers(DrmDisplayComposition *src) {
> +  geometry_changed_ = true;
> +  type_ = DRM_COMPOSITION_TYPE_FRAME;
> +  std::shared_ptr<Importer> importer =
> +      drm_->resource_manager()->GetImporter(crtc()->display());
> +  if (!importer) {
> +    ALOGE("Failed to find a valid importer");
> +    return -EINVAL;
> +  }
> +  for (DrmHwcLayer &src_layer : src->layers()) {
> +    DrmHwcLayer copy;
> +    copy.PopulateFromDrmHwcLayer(&src_layer);
> +    int ret = copy.ImportBuffer(importer.get(),
> +                                drm_->resource_manager()->GetGralloc());
> +    if (ret) {
> +      ALOGE("Failed to import buffer ret = %d", ret);
> +      return -EINVAL;
> +    }
> +    layers_.emplace_back(std::move(copy));
> +  }
> +  return 0;
> +}

This seems to do more than just CopyLayers, and it seems quite specialized to
your purpose. Can you do something similar to SquashFrame(), where the new
composition is crafted in context? It might be a little less awkward than
sprinkling in these seemingly generic copy functions.

Sean

> +
> +void DrmDisplayComposition::CopyCompPlanes(DrmDisplayComposition *src) {
> +  for (auto comp_plane : src->composition_planes()) {
> +    composition_planes_.push_back(comp_plane);
> +  }
> +}
> +
>  int DrmDisplayComposition::SetDpmsMode(uint32_t dpms_mode) {
>    if (!validate_composition_type(DRM_COMPOSITION_TYPE_DPMS))
>      return -EINVAL;
> diff --git a/drmdisplaycomposition.h b/drmdisplaycomposition.h
> index 9183925..c646420 100644
> --- a/drmdisplaycomposition.h
> +++ b/drmdisplaycomposition.h
> @@ -68,6 +68,7 @@ class DrmCompositionPlane {
>  
>    DrmCompositionPlane() = default;
>    DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
> +  DrmCompositionPlane(const DrmCompositionPlane &rhs) = default;
>    DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
>    DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc)
>        : type_(type), plane_(plane), crtc_(crtc) {
> @@ -120,6 +121,8 @@ class DrmDisplayComposition {
>             Planner *planner, uint64_t frame_no);
>  
>    int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
> +  int CopyLayers(DrmDisplayComposition *src);
> +  void CopyCompPlanes(DrmDisplayComposition *src);
>    int AddPlaneComposition(DrmCompositionPlane plane);
>    int AddPlaneDisable(DrmPlane *plane);
>    int SetDpmsMode(uint32_t dpms_mode);
> -- 
> 2.7.4
>
diff mbox

Patch

diff --git a/drmdisplaycomposition.cpp b/drmdisplaycomposition.cpp
index 66e67a4..dd64f46 100644
--- a/drmdisplaycomposition.cpp
+++ b/drmdisplaycomposition.cpp
@@ -99,6 +99,35 @@  int DrmDisplayComposition::SetLayers(DrmHwcLayer *layers, size_t num_layers,
   return 0;
 }
 
+int DrmDisplayComposition::CopyLayers(DrmDisplayComposition *src) {
+  geometry_changed_ = true;
+  type_ = DRM_COMPOSITION_TYPE_FRAME;
+  std::shared_ptr<Importer> importer =
+      drm_->resource_manager()->GetImporter(crtc()->display());
+  if (!importer) {
+    ALOGE("Failed to find a valid importer");
+    return -EINVAL;
+  }
+  for (DrmHwcLayer &src_layer : src->layers()) {
+    DrmHwcLayer copy;
+    copy.PopulateFromDrmHwcLayer(&src_layer);
+    int ret = copy.ImportBuffer(importer.get(),
+                                drm_->resource_manager()->GetGralloc());
+    if (ret) {
+      ALOGE("Failed to import buffer ret = %d", ret);
+      return -EINVAL;
+    }
+    layers_.emplace_back(std::move(copy));
+  }
+  return 0;
+}
+
+void DrmDisplayComposition::CopyCompPlanes(DrmDisplayComposition *src) {
+  for (auto comp_plane : src->composition_planes()) {
+    composition_planes_.push_back(comp_plane);
+  }
+}
+
 int DrmDisplayComposition::SetDpmsMode(uint32_t dpms_mode) {
   if (!validate_composition_type(DRM_COMPOSITION_TYPE_DPMS))
     return -EINVAL;
diff --git a/drmdisplaycomposition.h b/drmdisplaycomposition.h
index 9183925..c646420 100644
--- a/drmdisplaycomposition.h
+++ b/drmdisplaycomposition.h
@@ -68,6 +68,7 @@  class DrmCompositionPlane {
 
   DrmCompositionPlane() = default;
   DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
+  DrmCompositionPlane(const DrmCompositionPlane &rhs) = default;
   DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
   DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc)
       : type_(type), plane_(plane), crtc_(crtc) {
@@ -120,6 +121,8 @@  class DrmDisplayComposition {
            Planner *planner, uint64_t frame_no);
 
   int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
+  int CopyLayers(DrmDisplayComposition *src);
+  void CopyCompPlanes(DrmDisplayComposition *src);
   int AddPlaneComposition(DrmCompositionPlane plane);
   int AddPlaneDisable(DrmPlane *plane);
   int SetDpmsMode(uint32_t dpms_mode);