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 04/18] drm_hwcomposer: Add resource manager class
Date: Tue, 17 Apr 2018 11:33:05 -0400 [thread overview]
Message-ID: <20180417153305.GD73214@art_vandelay> (raw)
In-Reply-To: <1523460149-1740-5-git-send-email-alexandru-cosmin.gheorghe@arm.com>
On Wed, Apr 11, 2018 at 04:22:15PM +0100, Alexandru Gheorghe wrote:
> Add a resource manager object that is responsible for detecting all
> kms devices and allocates unique display numbers for every detected
> display.
>
> This is controlled by the value of hwc.drm.device property, if it ends
> with a %, it will try to open minor devices until and error is detected.
> E.g: /dev/dri/card%
I'm a bit on the fence as to whether to use the %, or add a new
hwc.drm.scan_devices property. I guess since we need to convey the path anyways
this is fine, but it really needs to be better documented.
>
> Additionally, this will be used for finding an available writeback
> connector that will be used for the flattening of the currently
> displayed scene.
>
> Signed-off-by: Alexandru Gheorghe <alexandru-cosmin.gheorghe@arm.com>
> ---
> Android.mk | 1 +
> resourcemanager.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> resourcemanager.h | 29 ++++++++++++++++++++++
> 3 files changed, 101 insertions(+)
> create mode 100644 resourcemanager.cpp
> create mode 100644 resourcemanager.h
>
> diff --git a/Android.mk b/Android.mk
> index 1add286..736fe24 100644
> --- a/Android.mk
> +++ b/Android.mk
> @@ -52,6 +52,7 @@ LOCAL_C_INCLUDES := \
>
> LOCAL_SRC_FILES := \
> autolock.cpp \
> + resourcemanager.cpp \
> drmresources.cpp \
> drmconnector.cpp \
> drmcrtc.cpp \
> diff --git a/resourcemanager.cpp b/resourcemanager.cpp
> new file mode 100644
> index 0000000..e7b654e
> --- /dev/null
> +++ b/resourcemanager.cpp
> @@ -0,0 +1,71 @@
> +#include "resourcemanager.h"
> +#include <cutils/log.h>
> +#include <cutils/properties.h>
> +
> +namespace android {
> +
> +ResourceManager::ResourceManager() : gralloc_(NULL) {
> +}
> +
> +int ResourceManager::Init() {
> + char path_pattern[PROPERTY_VALUE_MAX];
> + property_get("hwc.drm.device", path_pattern, "/dev/dri/card%");
We probably also don't want to default to scanning, since that might change
behavior in existing boards.
> +
> + uint8_t minor = 0;
Please use unsigned/int instead of fixed-size types. Unless the number of bits
is relevant to use of the variable, let the compiler handle it.
> + int last_display_index = 0;
Could we just call this num_displays? It was kind of hard for me to reason
through this, especially when it's call "start_display_index" when you jump into
drm::Init(). I also think drm->Init's return pair should return
<ret, displays_added> instead of <ret, display_index>, so each time you call
Init(), you're adding to num_displays.
> + int last_char = strlen(path_pattern) - 1;
> + do {
> + char path[PROPERTY_VALUE_MAX];
Please use string
> + if (path_pattern[last_char] == '%') {
> + path_pattern[last_char] = '\0';
> + snprintf(path, PROPERTY_VALUE_MAX, "%s%d", path_pattern, minor);
> + path_pattern[last_char] = '%';
This doesn't work for minor > 10.
> + } else {
> + snprintf(path, PROPERTY_VALUE_MAX, "%s", path_pattern);
> + }
> + std::unique_ptr<DrmResources> drm = std::make_unique<DrmResources>();
> + last_display_index = drm->Init(this, path, last_display_index);
> + if (last_display_index < 0) {
> + break;
> + }
> + std::shared_ptr<Importer> importer;
> + importer.reset(Importer::CreateInstance(drm.get()));
> + if (!importer) {
> + ALOGE("Failed to create importer instance");
> + break;
> + }
> + importers_.push_back(importer);
> + drms_.push_back(std::move(drm));
> + minor++;
> + last_display_index++;
> + } while (path_pattern[last_char] == '%');
> +
> + if (!drms_.size()) {
> + ALOGE("Failed to find any working drm device");
> + return -EINVAL;
> + }
> +
> + return hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
> + (const hw_module_t **)&gralloc_);
> +}
Consider the following:
int ResourceManager::AddDrmDevice(std::string path) {
std::unique_ptr<DrmDevice> drm = std::make_unique<DrmDevice>();
int displays_added, ret;
std::tie(displays_added, ret) = drm->Init(path.c_str(), num_displays_);
if (ret)
return ret;
std::shared_ptr<Importer> importer;
importer.reset(Importer::CreateInstance(drm.get()));
if (!importer) {
ALOGE("Failed to create importer instance");
return -ENODEV;
}
importers_.push_back(importer);
drms_.push_back(std::move(drm));
num_displays_ += displays_added;
return 0;
}
int ResourceManager::Init() {
char path_pattern[PROPERTY_VALUE_MAX];
int path_len = property_get("hwc.drm.device", path_pattern, "/dev/dri/card%");
if (path_pattern[path_len - 1] != '%')
return AddDrmDevice(std::string(path_pattern);
path_pattern[path_len - 1] = '\0';
for (int ret = 0, idx = 0; !ret; ++idx) {
ostringstream path;
path << path_pattern << idx;
ret = AddDrmDevice(path.str());
}
if (!num_displays_) {
ALOGE("Failed to initialize any displays");
return -EINVAL;
}
return hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
(const hw_module_t **)&gralloc_);
}
I think resolves the issues from the original patches and incorporates the
suggestions of drm->Init() returning the tuple of added displays, as well as
eliminating the backpointer.
> +
> +DrmResources *ResourceManager::GetDrmResources(int display) {
> + for (uint32_t i = 0; i < drms_.size(); i++) {
for (auto &drm_: drms_) {
> + if (drms_[i]->HandlesDisplay(display))
> + return drms_[i].get();
> + }
> + return NULL;
> +}
> +
> +std::shared_ptr<Importer> ResourceManager::GetImporter(int display) {
> + for (uint32_t i = 0; i < drms_.size(); i++) {
Same here
> + if (drms_[i]->HandlesDisplay(display))
> + return importers_[i];
> + }
> + return NULL;
> +}
> +
> +const gralloc_module_t *ResourceManager::GetGralloc() {
I think this should be called gralloc()
> + return gralloc_;
> +}
> +}
> diff --git a/resourcemanager.h b/resourcemanager.h
> new file mode 100644
> index 0000000..b8caa9a
> --- /dev/null
> +++ b/resourcemanager.h
> @@ -0,0 +1,29 @@
> +#ifndef RESOURCEMANAGER_H
> +#define RESOURCEMANAGER_H
> +
> +#include "drmresources.h"
> +#include "platform.h"
> +
> +namespace android {
> +
> +class DrmResources;
> +class Importer;
I think you need either the forward declarations or the includes, but not both?
> +
> +class ResourceManager {
> + public:
> + ResourceManager();
> + ResourceManager(const ResourceManager &) = delete;
> + ResourceManager &operator=(const ResourceManager &) = delete;
> + int Init();
> + DrmResources *GetDrmResources(int display);
> + std::shared_ptr<Importer> GetImporter(int display);
> + const gralloc_module_t *GetGralloc();
> +
> + private:
> + std::vector<std::unique_ptr<DrmResources>> drms_;
> + std::vector<std::shared_ptr<Importer>> importers_;
> + const gralloc_module_t *gralloc_;
> +};
> +}
> +
> +#endif // RESOURCEMANAGER_H
> --
> 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
next prev parent reply other threads:[~2018-04-17 15:33 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 [this message]
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
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=20180417153305.GD73214@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.