dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Paul <seanpaul@chromium.org>
To: Alexandru Gheorghe <alexandru-cosmin.gheorghe@arm.com>
Cc: ayan.halder@arm.com, liviu.dudau@arm.com,
	dri-devel@lists.freedesktop.org, nd@arm.com
Subject: Re: [PATCH hwc v2 05/18] drm_hwcomposer: Enable resource manager support
Date: Mon, 16 Apr 2018 15:54:02 -0400	[thread overview]
Message-ID: <20180416195402.GT73214@art_vandelay> (raw)
In-Reply-To: <1523460149-1740-6-git-send-email-alexandru-cosmin.gheorghe@arm.com>

On Wed, Apr 11, 2018 at 04:22:16PM +0100, Alexandru Gheorghe wrote:
> Use the newly added ResourceManager for creating and detecting all the
> drm devices instead of assuming that there is only one device.
> 
> Signed-off-by: Alexandru Gheorghe <alexandru-cosmin.gheorghe@arm.com>
> ---
>  drmhwctwo.cpp    | 34 +++++++++++++---------------------
>  drmhwctwo.h      |  4 +---
>  drmresources.cpp | 25 ++++++++++++++++++-------
>  drmresources.h   | 14 +++++++++++---
>  4 files changed, 43 insertions(+), 34 deletions(-)
> 
> diff --git a/drmhwctwo.cpp b/drmhwctwo.cpp
> index dfca1a6..cddd5da 100644
> --- a/drmhwctwo.cpp
> +++ b/drmhwctwo.cpp
> @@ -58,40 +58,32 @@ DrmHwcTwo::DrmHwcTwo() {
>  }
>  
>  HWC2::Error DrmHwcTwo::Init() {
> -  int ret = drm_.Init();
> +  int ret = resource_manager_.Init();
>    if (ret) {
> -    ALOGE("Can't initialize drm object %d", ret);
> +    ALOGE("Can't initialize the resource manager %d", ret);
>      return HWC2::Error::NoResources;
>    }
>  
> -  importer_.reset(Importer::CreateInstance(&drm_));
> -  if (!importer_) {
> -    ALOGE("Failed to create importer instance");
> +  DrmResources *drm = resource_manager_.GetDrmResources(HWC_DISPLAY_PRIMARY);
> +  std::shared_ptr<Importer> importer =
> +      resource_manager_.GetImporter(HWC_DISPLAY_PRIMARY);
> +  if (!drm || !importer) {
> +    ALOGE("Failed to get a valid drmresource and importer");
>      return HWC2::Error::NoResources;
>    }
> +  displays_.emplace(
> +      std::piecewise_construct, std::forward_as_tuple(HWC_DISPLAY_PRIMARY),
> +      std::forward_as_tuple(drm, importer, resource_manager_.GetGralloc(),
> +                            HWC_DISPLAY_PRIMARY, HWC2::DisplayType::Physical));
>  
> -  ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
> -                      (const hw_module_t **)&gralloc_);
> -  if (ret) {
> -    ALOGE("Failed to open gralloc module %d", ret);
> -    return HWC2::Error::NoResources;
> -  }
> -
> -  displays_.emplace(std::piecewise_construct,
> -                    std::forward_as_tuple(HWC_DISPLAY_PRIMARY),
> -                    std::forward_as_tuple(&drm_, importer_, gralloc_,
> -                                          HWC_DISPLAY_PRIMARY,
> -                                          HWC2::DisplayType::Physical));
> -
> -  DrmCrtc *crtc = drm_.GetCrtcForDisplay(static_cast<int>(HWC_DISPLAY_PRIMARY));
> +  DrmCrtc *crtc = drm->GetCrtcForDisplay(static_cast<int>(HWC_DISPLAY_PRIMARY));
>    if (!crtc) {
>      ALOGE("Failed to get crtc for display %d",
>            static_cast<int>(HWC_DISPLAY_PRIMARY));
>      return HWC2::Error::BadDisplay;
>    }
> -
>    std::vector<DrmPlane *> display_planes;
> -  for (auto &plane : drm_.planes()) {
> +  for (auto &plane : drm->planes()) {
>      if (plane->GetCrtcSupported(*crtc))
>        display_planes.push_back(plane.get());
>    }
> diff --git a/drmhwctwo.h b/drmhwctwo.h
> index 0490e2a..beb5d2d 100644
> --- a/drmhwctwo.h
> +++ b/drmhwctwo.h
> @@ -262,9 +262,7 @@ class DrmHwcTwo : public hwc2_device_t {
>    HWC2::Error RegisterCallback(int32_t descriptor, hwc2_callback_data_t data,
>                                 hwc2_function_pointer_t function);
>  
> -  DrmResources drm_;
> -  std::shared_ptr<Importer> importer_;  // Shared with HwcDisplay
> -  const gralloc_module_t *gralloc_;
> +  ResourceManager resource_manager_;
>    std::map<hwc2_display_t, HwcDisplay> displays_;
>    std::map<HWC2::Callback, HwcCallback> callbacks_;
>  };
> diff --git a/drmresources.cpp b/drmresources.cpp
> index 32dd376..a5ddda0 100644
> --- a/drmresources.cpp
> +++ b/drmresources.cpp
> @@ -42,10 +42,9 @@ DrmResources::~DrmResources() {
>    event_listener_.Exit();
>  }
>  
> -int DrmResources::Init() {
> -  char path[PROPERTY_VALUE_MAX];
> -  property_get("hwc.drm.device", path, "/dev/dri/card0");
> -
> +int DrmResources::Init(ResourceManager *resource_manager, char *path,
> +                       int start_display_index) {
> +  resource_manager_ = resource_manager;

You can avoid the backpointer if you just pass the RM to the right places (looks
like compositor + composition). Bonus points if you can remove drm_ from those
objects once you've done that.

>    /* TODO: Use drmOpenControl here instead */
>    fd_.Set(open(path, O_RDWR));
>    if (fd() < 0) {
> @@ -76,8 +75,8 @@ int DrmResources::Init() {
>    max_resolution_ =
>        std::pair<uint32_t, uint32_t>(res->max_width, res->max_height);
>  
> -  bool found_primary = false;
> -  int display_num = 1;
> +  bool found_primary = start_display_index != 0;
> +  int display_num = found_primary ? start_display_index : 1;

This could use a comment. AFAICT, you're assuming the primary display will
always be in the first drm device, which is fine, but should be explained
_somewhere_.

>  
>    for (int i = 0; !ret && i < res->count_crtcs; ++i) {
>      drmModeCrtcPtr c = drmModeGetCrtc(fd(), res->crtcs[i]);
> @@ -161,9 +160,11 @@ int DrmResources::Init() {
>    for (auto &conn : connectors_) {
>      if (conn->internal() && !found_primary) {
>        conn->set_display(0);
> +      displays_[0] = 0;
>        found_primary = true;
>      } else {
>        conn->set_display(display_num);
> +      displays_[display_num] = display_num;
>        ++display_num;
>      }
>    }
> @@ -171,7 +172,9 @@ int DrmResources::Init() {
>    // Then look for primary amongst external connectors
>    for (auto &conn : connectors_) {
>      if (conn->external() && !found_primary) {
> +      displays_.erase(conn->display());
>        conn->set_display(0);
> +      displays_[0] = 0;
>        found_primary = true;
>      }
>    }
> @@ -226,7 +229,11 @@ int DrmResources::Init() {
>        return ret;
>      }
>    }
> -  return 0;
> +  return displays_.size() ? displays_.rbegin()->first : -EINVAL;

I'd rather not change the meaning of the return value (especially without a
comment somewhere to let readers know this function doesn't follow the 0 ||
-ERRNO convention). Consider returning a pair of ret,display.

> +}
> +
> +bool DrmResources::HandlesDisplay(int display) const {
> +  return displays_.find(display) != displays_.end();
>  }
>  
>  DrmConnector *DrmResources::GetConnectorForDisplay(int display) const {
> @@ -349,6 +356,10 @@ DrmEventListener *DrmResources::event_listener() {
>    return &event_listener_;
>  }
>  
> +ResourceManager *DrmResources::resource_manager() {
> +  return resource_manager_;
> +}
> +
>  int DrmResources::GetProperty(uint32_t obj_id, uint32_t obj_type,
>                                const char *prop_name, DrmProperty *property) {
>    drmModeObjectPropertiesPtr props;
> diff --git a/drmresources.h b/drmresources.h
> index 4cca48c..4cdcd87 100644
> --- a/drmresources.h
> +++ b/drmresources.h
> @@ -17,22 +17,26 @@
>  #ifndef ANDROID_DRM_H_
>  #define ANDROID_DRM_H_
>  
> +#include <stdint.h>
>  #include "drmconnector.h"
>  #include "drmcrtc.h"
>  #include "drmencoder.h"
>  #include "drmeventlistener.h"
>  #include "drmplane.h"
> -
> -#include <stdint.h>

Why this change?

> +#include "platform.h"
> +#include "resourcemanager.h"
>  
>  namespace android {
>  
> +class ResourceManager;
> +
>  class DrmResources {
>   public:
>    DrmResources();
>    ~DrmResources();
>  
> -  int Init();
> +  int Init(ResourceManager *resource_manager, char *path,
> +           int start_display_index);
>  
>    int fd() const {
>      return fd_.get();
> @@ -58,6 +62,7 @@ class DrmResources {
>    DrmCrtc *GetCrtcForDisplay(int display) const;
>    DrmPlane *GetPlane(uint32_t id) const;
>    DrmEventListener *event_listener();
> +  ResourceManager *resource_manager();
>  
>    int GetPlaneProperty(const DrmPlane &plane, const char *prop_name,
>                         DrmProperty *property);
> @@ -71,6 +76,7 @@ class DrmResources {
>  
>    int CreatePropertyBlob(void *data, size_t length, uint32_t *blob_id);
>    int DestroyPropertyBlob(uint32_t blob_id);
> +  bool HandlesDisplay(int display) const;
>  
>   private:
>    int TryEncoderForDisplay(int display, DrmEncoder *enc);
> @@ -90,6 +96,8 @@ class DrmResources {
>  
>    std::pair<uint32_t, uint32_t> min_resolution_;
>    std::pair<uint32_t, uint32_t> max_resolution_;
> +  std::map<int, int> displays_;
> +  ResourceManager *resource_manager_;
>  };
>  }
>  
> -- 
> 2.7.4
> 

-- 
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2018-04-16 19:54 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-11 15:22 [PATCH hwc v2 00/18] Add scene flattening support Alexandru Gheorghe
2018-04-11 15:22 ` [PATCH hwc v2 01/18] drm_hwcomposer: vsyncworker: Fix uninitialized enabled_ field Alexandru Gheorghe
2018-04-16 10:30   ` Robert Foss
2018-04-16 12:18     ` Alexandru-Cosmin Gheorghe
2018-04-17 13:45       ` Sean Paul
2018-04-17 14:09         ` Alexandru-Cosmin Gheorghe
2018-04-11 15:22 ` [PATCH hwc v2 02/18] drm_hwcomposer: vsyncworker: Fix deadlock on exit path Alexandru Gheorghe
2018-04-16 10:31   ` Robert Foss
2018-04-16 19:25   ` Sean Paul
2018-04-17 13:32     ` Alexandru-Cosmin Gheorghe
2018-04-11 15:22 ` [PATCH hwc v2 03/18] drm_hwcomposer: drmeventlistener: Set nl_pid to 0 Alexandru Gheorghe
2018-04-16 10:32   ` Robert Foss
2018-04-11 15:22 ` [PATCH hwc v2 04/18] drm_hwcomposer: Add resource manager class Alexandru Gheorghe
2018-04-17 15:33   ` Sean Paul
2018-04-17 16:08     ` Robert Foss
2018-04-18 10:12       ` Alexandru-Cosmin Gheorghe
2018-04-18 10:14         ` Robert Foss
2018-04-11 15:22 ` [PATCH hwc v2 05/18] drm_hwcomposer: Enable resource manager support Alexandru Gheorghe
2018-04-16 19:54   ` Sean Paul [this message]
2018-04-17 13:43     ` Alexandru-Cosmin Gheorghe
2018-04-17 14:22       ` Sean Paul
2018-04-17 14:26   ` Sean Paul
2018-04-11 15:22 ` [PATCH hwc v2 06/18] drm_hwcomposer: Add writeback connector support Alexandru Gheorghe
2018-04-16 19:59   ` Sean Paul
2018-04-17 13:46     ` Alexandru-Cosmin Gheorghe
2018-04-11 15:22 ` [PATCH hwc v2 07/18] drm_hwcomposer: Add display field to Drmencoder Alexandru Gheorghe
2018-04-16 20:02   ` Sean Paul
2018-04-17 13:49     ` Alexandru-Cosmin Gheorghe
2018-04-11 15:22 ` [PATCH hwc v2 08/18] drm_hwcomposer: Parse and store possible_clones information Alexandru Gheorghe
2018-04-16 20:19   ` Sean Paul
2018-04-17 14:03     ` Alexandru-Cosmin Gheorghe
2018-04-11 15:22 ` [PATCH hwc v2 09/18] drm_hwcomposer: Handle writeback connectors Alexandru Gheorghe
2018-04-17 15:45   ` Sean Paul
2018-04-11 15:22 ` [PATCH hwc v2 10/18] drm_hwcomposer: hwcutils: Add function for cloning a DrmHwcLayer Alexandru Gheorghe
2018-04-17 16:14   ` Sean Paul
2018-04-18 10:22     ` Alexandru-Cosmin Gheorghe
2018-04-11 15:22 ` [PATCH hwc v2 11/18] drm_hwcomposer: Add utility functions to copy displaycomposition internals Alexandru Gheorghe
2018-04-17 16:34   ` Sean Paul
2018-04-11 15:22 ` [PATCH hwc v2 12/18] drm_hwcomposer: Add utility function to create an initialized composition Alexandru Gheorghe
2018-04-17 16:37   ` Sean Paul
2018-04-18 10:29     ` Alexandru-Cosmin Gheorghe
2018-04-11 15:22 ` [PATCH hwc v2 13/18] drm_hwcomposer: Pass buffer sizes to Prepareframebuffer Alexandru Gheorghe
2018-04-17 16:51   ` Sean Paul
2018-04-11 15:22 ` [PATCH hwc v2 14/18] drm_hwcomposer: Fix race in ApplyFrame Alexandru Gheorghe
2018-04-17 17:02   ` Sean Paul
2018-04-18 10:43     ` Alexandru-Cosmin Gheorghe
2018-04-11 15:22 ` [PATCH hwc v2 15/18] drm_hwcomposer: Add worker to trigger scene flattenning Alexandru Gheorghe
2018-04-17 17:07   ` Sean Paul
2018-04-11 15:22 ` [PATCH hwc v2 16/18] drm_hwcomposer: Find writeback connector for scene flattening Alexandru Gheorghe
2018-04-17 17:15   ` Sean Paul
2018-04-11 15:22 ` [PATCH hwc v2 17/18] drm_hwcomposer: Flatten scene synchronously Alexandru Gheorghe
2018-04-17 17:47   ` Sean Paul
2018-04-18 11:14     ` Alexandru-Cosmin Gheorghe
2018-04-18 14:49       ` Sean Paul
2018-04-11 15:22 ` [PATCH hwc v2 18/18] drm_hwcomposer: Flatten scene asynchronously Alexandru Gheorghe
2018-04-12 23:18 ` [PATCH hwc v2 00/18] Add scene flattening support John Stultz
2018-04-13  9:52   ` Alexandru-Cosmin Gheorghe
2018-04-13 12:48     ` Alexandru-Cosmin Gheorghe
2018-04-18 17:21       ` John Stultz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180416195402.GT73214@art_vandelay \
    --to=seanpaul@chromium.org \
    --cc=alexandru-cosmin.gheorghe@arm.com \
    --cc=ayan.halder@arm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=liviu.dudau@arm.com \
    --cc=nd@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox