OSDN Git Service

android-x86/external-drm_hwcomposer.git
2 years agodrm_hwcomposer: allow to force mode by a property (v5) r-x86
Mauro Rossi [Sun, 16 Jan 2022 14:19:42 +0000 (15:19 +0100)]
drm_hwcomposer: allow to force mode by a property (v5)

The desired resolution can be set by property debug.drm.mode.force.
The other modes are ignored.

(v2) Resolve conflict after commit 13cc366
     "drm_hwcomposer: use CamelCase in source/header files related to class"

(v3) Changes due to commit a148f21
     "drm_hwcomposer: Rework display modes handling"

(v4) Changes due to commit 650299a2
     "drm_hwcomposer: Tidy-up DrmConnector class"

(v5) Changes due to commit 7d89911c
     "drm_hwcomposer: Tidy-up DrmDevice class"

2 years agodrm_hwcomposer: Rework HwcDisplay disposal to avoid races
Roman Stratiienko [Fri, 18 Feb 2022 14:52:03 +0000 (16:52 +0200)]
drm_hwcomposer: Rework HwcDisplay disposal to avoid races

The code prior to this commit has a flaw:

    HwcDisplay::~HwcDisplay() {
      ...
      auto &main_lock = hwc2_->GetResMan().GetMainLock();
      /* Unlock to allow pending vsync callbacks to finish */
      main_lock.unlock();

At this point display is no longer in displays_[] list. After
lock is released, hwc2 API thread starts to process transactions
which may fail with BAD_SIAPLAY responce and cause SF to crash.

      vsync_worker_.VSyncControl(false);
      vsync_worker_.Exit();
      main_lock.lock();
    }

1. Rework the logic in order to avoid such scenariuos:
1.a. Temporary switch non-primary unplugged displays to headless state
     allowing remaining transactions to succeed without impacting the
     pipeline.
1.b. Give 100mSec delay before destroying / removing display from the
     displays_[] list to allow all pending hwc2 transactions to complete.

2. Support hotswap of the DrmDisplayPipeline, which makes primary display
   reattaching process smoother.
   Now SF should be able to gracefully remove all layers.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Add test utility to listen for uevents
Roman Stratiienko [Fri, 18 Feb 2022 14:51:53 +0000 (16:51 +0200)]
drm_hwcomposer: Add test utility to listen for uevents

Dumping uevents is useful for debugging purposes.

1. Extract logic related to uevent socket into utils/UEvent.h class.
2. Use it by both UEventListener.cpp and tests/uevent_print.cpp.

Bump clang-tidy level of UEventListener.cpp to normal.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Define DRM_FORMAT_XYUV8888 if missing
Roman Stratiienko [Thu, 10 Feb 2022 08:45:06 +0000 (10:45 +0200)]
drm_hwcomposer: Define DRM_FORMAT_XYUV8888 if missing

Fixes drm_hwcomposer build for Android-9.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Change-Id: I14e931c37c3d09284dfd338e6482a27cf21e0e10

2 years agodrm_hwcomposer: fix sign-compare building error in uevent listener
Mauro Rossi [Sun, 16 Jan 2022 15:11:46 +0000 (16:11 +0100)]
drm_hwcomposer: fix sign-compare building error in uevent listener

d26619b5 ("drm_hwcomposer: CI: Upgrade clang-* to v12") declared 'ret' as ssize_t
but after commit 1e053b4e ("drm_hwcomposer: Make uevent listener standalone")
drm/UEventListener.cpp is affected by the following builing error:

external/drm_hwcomposer/drm/UEventListener.cpp:82:28:
error: comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'ssize_t' (aka 'int') [-Werror,-Wsign-compare]
    for (uint32_t i = 0; i < ret;) {
                         ~ ^ ~~~
1 error generated.

Fixes: 1e053b4e ("drm_hwcomposer: Make uevent listener standalone")
Signed-off-by: Mauro Rossi <issor.oruam@gmail.com>
[RomanS: Fixed CI nitpicks]
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Change-Id: Ia97d9019c21ac68be386a627cb101f6e423bbfc7

2 years agodrm_hwcomposer: build with -std=c++17 cppflag
Mauro Rossi [Sat, 4 Dec 2021 14:02:13 +0000 (15:02 +0100)]
drm_hwcomposer: build with -std=c++17 cppflag

Fixes the following building error:

external/drm_hwcomposer/DrmHwcTwo.cpp:985:14: error: decomposition declarations are a C++17 extension [-Werror,-Wc++17-extensions]
  for (auto &[handle, layer] : layers_) {
             ^~~~~~~~~~~~~~~
1 error generated.

Signed-off-by: Mauro Rossi <issor.oruam@gmail.com>
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Change-Id: I236f16969e4500ff2efb79c06500bc4d3a3d810c

2 years agodrm_hwcomposer: Rename DrmDisplayCompositor->DrmAtomicStateManager
Roman Stratiienko [Wed, 9 Feb 2022 15:40:35 +0000 (17:40 +0200)]
drm_hwcomposer: Rename DrmDisplayCompositor->DrmAtomicStateManager

Primary responsibilities of this class are:

1. Send composition/mode/active state over DRM atomic commit IOCTL
   to the kernel
2. Track commit state and keep planes owned by the Pipeline while they
   are either displayed or staged for displaying.
3. Keep framebuffers alive while they are in use or staged.

Not much related to composition itself, therefore rename it to
DrmAtomicStateManager and move it to drm folder.

Bump clang-tidy level of DrmAtomicStateManager.c to normal by fixing
minor clang-tidy findings.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove AtomicCommitArgs::clear_active_composition field
Roman Stratiienko [Wed, 9 Feb 2022 15:19:56 +0000 (17:19 +0200)]
drm_hwcomposer: Remove AtomicCommitArgs::clear_active_composition field

Now we can use empty DrmKmsPlan to achieve the same goal.

+ Remove unused HwcDisplay::ClearDisplay()

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove RCAR-DU specific code.
Roman Stratiienko [Fri, 4 Feb 2022 10:23:43 +0000 (12:23 +0200)]
drm_hwcomposer: Remove RCAR-DU specific code.

We are not testing it for more than year, therefore it's better
to use generic logic for 'rcar-du' instead.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Rework KMS composition planner + plane sharing support
Roman Stratiienko [Wed, 2 Feb 2022 07:53:50 +0000 (09:53 +0200)]
drm_hwcomposer: Rework KMS composition planner + plane sharing support

Rewrite Layer-to-Plane planner. Get rid of ~200 redundant lines of code
+ added plane sharing functionality.

Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/11
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Implement SetActiveConfigWithConstraints
Roman Stratiienko [Fri, 21 Jan 2022 13:12:56 +0000 (15:12 +0200)]
drm_hwcomposer: Implement SetActiveConfigWithConstraints

Enough to get 100% passes in Composer 2.4 VTS.
Some SOCs require a VTS fix to pass [1]

[1]: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1954544
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Use single VSyncWorker per display
Roman Stratiienko [Thu, 20 Jan 2022 09:50:54 +0000 (11:50 +0200)]
drm_hwcomposer: Use single VSyncWorker per display

Composer 2.4 will require another vsyncworker callback to send
VsyncPeriodTimingChanged event. It makes sence to use single
VSyncWorker and flags to indicate which actions are required
to perform. This should also save some runtime resources.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Dynamic DrmDisplayPipeline to HwcDisplay bindings
Roman Stratiienko [Tue, 11 Jan 2022 17:18:34 +0000 (19:18 +0200)]
drm_hwcomposer: Dynamic DrmDisplayPipeline to HwcDisplay bindings

The following use scenarios are now possible:

1. When no display connected, primary HwcDisplay is created in headless
   mode.

2. When user connects first display, it binds to primary slot, replacing
   headless HwcDisplay.

3. When user connects another display it binds to the new HwcDisplay
   slot, creating new display for the framework.

4. When user disconnects first (Primary) display, drm_hwc detaches
   second display and attaches it to the Primary slot. In this case
   framework is notified as Primary display resolution updated
   (Plugged->Plugged transition). And second display is disconnected
   (Plugged->Unplugged transition).

DrmDisplayPipeline is now created on demand (after hotplug event).

HwcDisplay class is now destructed on connector unplug, which will give
us ability to destroy any resource caches (will be required for FB
caching logic).

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Initialize HwcDisplay using DrmDisplayPIpeline
Roman Stratiienko [Tue, 1 Feb 2022 07:35:08 +0000 (09:35 +0200)]
drm_hwcomposer: Initialize HwcDisplay using DrmDisplayPIpeline

HwcDisplay can now take all necessary objects from DrmDisplayPipeline.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Fix PipelineBindable::BindPipeline
Roman Stratiienko [Wed, 2 Feb 2022 10:53:14 +0000 (12:53 +0200)]
drm_hwcomposer: Fix PipelineBindable::BindPipeline

We should assign weak pointer object to really take ownership.

Fixes: cad8e0ca57c2 ("drm_hwcomposer: Introduce DrmDisplayPipeline class")
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Introduce DrmDisplayPipeline class
Roman Stratiienko [Mon, 31 Jan 2022 14:40:16 +0000 (16:40 +0200)]
drm_hwcomposer: Introduce DrmDisplayPipeline class

Create systematic way of binding DRM objects (Crtc,Encoder,Planes...)
to the pipeline using RAII. Use it to create the pipeline.

+ Allow pipeline creation to fail.

Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/14
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Tidy-up DrmDevice class
Roman Stratiienko [Mon, 31 Jan 2022 09:30:27 +0000 (11:30 +0200)]
drm_hwcomposer: Tidy-up DrmDevice class

1. Move drm/DrmConnector.h to Normal clang-tidy checks list by fixing
   clang-tidy findings.

2. Remove DrmDevice self-reference.

3. Replace shared_ptr reference to DrmDevice in DrmFbImporter with a
   pointer, making ResourceManager only owner of DrmDevice and its
   chilren.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Tidy-up DrmConnector class
Roman Stratiienko [Sun, 30 Jan 2022 21:46:10 +0000 (23:46 +0200)]
drm_hwcomposer: Tidy-up DrmConnector class

Implement DrmConnector instantiation through CreateInstance() static method,
which helps to reduce complexity of DrmDevice::Init() function.

Move Connector-to-CRTC binding information to the DrmDevice class.

Move drm/DrmConnector.h to Normal clang-tidy checks list by fixing
clang-tidy findings.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Tidy-up DrmEncoder class
Roman Stratiienko [Sun, 30 Jan 2022 19:06:35 +0000 (21:06 +0200)]
drm_hwcomposer: Tidy-up DrmEncoder class

Implement DrmEncoder instantiation through CreateInstance() static method,
which helps to reduce complexity of DrmDevice::Init() function.

Move Encoder-to-CRTC binding information to the DrmDevice class.

Move drm/DrmEncoder.h to Normal clang-tidy checks list by fixing
clang-tidy findings.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Tidy-up DrmCrtc class
Roman Stratiienko [Sun, 30 Jan 2022 18:28:46 +0000 (20:28 +0200)]
drm_hwcomposer: Tidy-up DrmCrtc class

Implement DrmCrtc instantiation through CreateInstance() static method,
which helps to reduce complexity of DrmDevice::Init() function.

Move CRTC-to-Display binding information to the DrmDevice class.

Move drm/DrmCrtc.h to Normal clang-tidy checks list by fixing
clang-tidy findings.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove ability to prioritize primary display
Roman Stratiienko [Sat, 29 Jan 2022 17:53:14 +0000 (19:53 +0200)]
drm_hwcomposer: Remove ability to prioritize primary display

This feature isn't correctly fits hwc2 and SF requirements.

Primary display prioritization shall be done by introducing ability to
override internal/external connector type for any connector.

'vendor.hwc.drm.primary_display_order' property is no longer relevant.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Handle primary display in GetDisplayConnectionType()
Roman Stratiienko [Fri, 28 Jan 2022 23:17:39 +0000 (01:17 +0200)]
drm_hwcomposer: Handle primary display in GetDisplayConnectionType()

Primary display should always be internal.

Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/58
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Tidy-up DrmPlane class
Roman Stratiienko [Fri, 28 Jan 2022 22:50:22 +0000 (00:50 +0200)]
drm_hwcomposer: Tidy-up DrmPlane class

This allow to throw away few lines from DrmDevice::Init() making it less
complicated.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Simplify DrmHwcTwo::GetDisplay()
Roman Stratiienko [Fri, 28 Jan 2022 22:10:07 +0000 (00:10 +0200)]
drm_hwcomposer: Simplify DrmHwcTwo::GetDisplay()

Cosmetic change: make GetDisplay() non-static class method + use
deduced return type.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Fix build_deploy.sh script
Roman Stratiienko [Thu, 20 Jan 2022 15:12:40 +0000 (17:12 +0200)]
drm_hwcomposer: Fix build_deploy.sh script

Composer service has to be started again.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove utils/autolock.*
Roman Stratiienko [Tue, 18 Jan 2022 11:47:04 +0000 (13:47 +0200)]
drm_hwcomposer: Remove utils/autolock.*

AutoLock class is no longer used.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove write-back related helpers from DrmDevice class
Roman Stratiienko [Tue, 18 Jan 2022 08:35:30 +0000 (10:35 +0200)]
drm_hwcomposer: Remove write-back related helpers from DrmDevice class

Remove unused functionality.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove DrmDisplayCompositor:CreateInitializedComposition
Roman Stratiienko [Tue, 18 Jan 2022 08:21:48 +0000 (10:21 +0200)]
drm_hwcomposer: Remove DrmDisplayCompositor:CreateInitializedComposition

Remove unused functionality.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Add headless mode support
Roman Stratiienko [Mon, 17 Jan 2022 16:29:24 +0000 (18:29 +0200)]
drm_hwcomposer: Add headless mode support

Headless mode required to keep SurfaceFlinger alive when all displays are
disconnected, Without headless mode Android will continuously crash.
Only single internal (primary) display is required to be in HEADLESS mode
to prevent the crash. See [1].

[1]: https://source.android.com/devices/graphics/hotplug#handling-common-scenarios
Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/57
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Configuring Composer HAL to use sequential IDs
Roman Stratiienko [Mon, 17 Jan 2022 11:17:56 +0000 (13:17 +0200)]
drm_hwcomposer: Configuring Composer HAL to use sequential IDs

Implement Google guidelines from [1]

1. The supported display config IDs are:

    id=1, 1080x1920 60hz
    id=2, 1080x1920 50hz

2. When a change of display configs is processed, the next set of config IDs
   are assigned starting from the next unused integer, shown as follows:

    id=3, 2160x3840 60hz
    id=4, 2160x3840 50hz
    id=5, 1080x1920 60hz
    id=6, 1080x1920 50hz

+ Don't update modes in GetDisplayConfigs() . Modes is now updated at init or
after every hotplug event.

[1]: https://source.android.com/devices/graphics/hotplug#configuring-composer-hal-sequential-ids
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Introduce main lock
Roman Stratiienko [Mon, 17 Jan 2022 09:24:21 +0000 (11:24 +0200)]
drm_hwcomposer: Introduce main lock

Further development will require more asynchronous processing.
Introduce project-wide single mutex for these purposes.
Use it instead for callback handling instead of callback_lock.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Restore HWC2 API logging functionality
Roman Stratiienko [Mon, 17 Jan 2022 08:35:34 +0000 (10:35 +0200)]
drm_hwcomposer: Restore HWC2 API logging functionality

Process and log __PRETTY_FUNCTION__ compiler string.

Prints HWC2 API logs as follows:

hwc2-device: Display #0 Layer: #0 hook: android::HwcLayer::SetLayerBuffer
hwc2-device: Display #0 hook: android::HwcDisplay::ValidateDisplay
hwc2-device: Display #0 hook: android::HwcDisplay::GetChangedCompositionTypes
hwc2-device: Display #0 hook: android::HwcDisplay::GetChangedCompositionTypes
hwc2-device: Display #0 hook: android::HwcDisplay::GetDisplayRequests
hwc2-device: Display #0 hook: android::HwcDisplay::GetDisplayRequests
hwc2-device: Display #0 hook: android::HwcDisplay::AcceptDisplayChanges
hwc2-device: Display #0 hook: android::HwcDisplay::PresentDisplay
hwc2-device: Display #0 hook: android::HwcDisplay::GetReleaseFences
hwc2-device: Display #0 hook: android::HwcDisplay::GetReleaseFences

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: CI: Upgrade to clang-13 && clang-tidy-13
Roman Stratiienko [Mon, 10 Jan 2022 14:04:15 +0000 (16:04 +0200)]
drm_hwcomposer: CI: Upgrade to clang-13 && clang-tidy-13

+ address new clang-tidy findings.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Add delay between hotplug uevent and modes get
Roman Stratiienko [Thu, 20 Jan 2022 15:12:13 +0000 (17:12 +0200)]
drm_hwcomposer: Add delay between hotplug uevent and modes get

We need some delay to ensure DrmConnector::UpdateModes() will query
correct modes list, otherwise at least RPI4 board may report 0 modes.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Fix missing connector state assignment
Roman Stratiienko [Mon, 17 Jan 2022 16:44:22 +0000 (18:44 +0200)]
drm_hwcomposer: Fix missing connector state assignment

It was accidentally removed by my previous commit. Restore it.

Fixes: a148f21336ad ("drm_hwcomposer: Rework display modes handling")
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Add script for quick build and deploy drm_hwcomposer
Roman Stratiienko [Thu, 13 Jan 2022 09:10:00 +0000 (11:10 +0200)]
drm_hwcomposer: Add script for quick build and deploy drm_hwcomposer

It should help us with manual testing.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Use DPMS property to configure display pipeline
Roman Stratiienko [Thu, 13 Jan 2022 14:37:27 +0000 (16:37 +0200)]
drm_hwcomposer: Use DPMS property to configure display pipeline

Some of KMS drivers like kirin are sensitive to display pipeline
configuration, modern kernel will configure the pipeline correctly
when user sets DPMS property.

To be more precise current compositor logic will not attach primary
plane to the CRTC, while kirin relies on it internally.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move HwcDisplayConfigs out of HwcDisplay class
Roman Stratiienko [Tue, 4 Jan 2022 16:27:40 +0000 (18:27 +0200)]
drm_hwcomposer: Move HwcDisplayConfigs out of HwcDisplay class

To reduce complexity of HwcDisplay class.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move DrmHwcTwo.{cpp|h} to hwc2_device/ directory
Roman Stratiienko [Tue, 4 Jan 2022 14:13:12 +0000 (16:13 +0200)]
drm_hwcomposer: Move DrmHwcTwo.{cpp|h} to hwc2_device/ directory

To keep all frontend-related files in a single directory.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move HwcDisplay out of DrmHwcTwo class
Roman Stratiienko [Tue, 4 Jan 2022 14:02:55 +0000 (16:02 +0200)]
drm_hwcomposer: Move HwcDisplay out of DrmHwcTwo class

Reduces code complexity.

Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/35
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move HwcLayer out of DrmHwcTwo class
Roman Stratiienko [Tue, 4 Jan 2022 12:30:37 +0000 (14:30 +0200)]
drm_hwcomposer: Move HwcLayer out of DrmHwcTwo class

... to reduce complexity of DrmHwcTwo.* files.

Bump-up tidy level of new files to NORMAL (fix function naming,
add NOLINT, etc.)

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move hw_module related code out of DrmHwcTwo.* files
Roman Stratiienko [Tue, 4 Jan 2022 10:59:29 +0000 (12:59 +0200)]
drm_hwcomposer: Move hw_module related code out of DrmHwcTwo.* files

... to reduce complexity of DrmHwcTwo class.

Create "hwc2_device" directory that will be later used to fit
all frontend-related code.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: CI: Remove -readability-use-anyofallof from COARSE list
Roman Stratiienko [Tue, 4 Jan 2022 09:42:33 +0000 (11:42 +0200)]
drm_hwcomposer: CI: Remove -readability-use-anyofallof from COARSE list

We have single fail case of -readability-use-anyofallof.
Use NOLINTNEXTLINE comment instead.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: CI: Remove duplicate tidy checks
Roman Stratiienko [Tue, 4 Jan 2022 09:19:52 +0000 (11:19 +0200)]
drm_hwcomposer: CI: Remove duplicate tidy checks

This improves visibility and helps to distinguish which
particular checks are disabled at every level.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: CI: Move tidy FINE checklist to Makefile
Roman Stratiienko [Tue, 4 Jan 2022 09:10:22 +0000 (11:10 +0200)]
drm_hwcomposer: CI: Move tidy FINE checklist to Makefile

To make checklists definitions aligned and allow inheritance.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Raise clang-tidy level of some files to NORMAL
Roman Stratiienko [Thu, 30 Dec 2021 17:23:14 +0000 (19:23 +0200)]
drm_hwcomposer: Raise clang-tidy level of some files to NORMAL

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Fix float to 16.16 fixed point conversion
Roman Stratiienko [Thu, 30 Dec 2021 17:20:53 +0000 (19:20 +0200)]
drm_hwcomposer: Fix float to 16.16 fixed point conversion

Previously, the fractional part was truncated.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: CI: Find all source files instead of hardcoding them.
Roman Stratiienko [Thu, 30 Dec 2021 16:12:26 +0000 (18:12 +0200)]
drm_hwcomposer: CI: Find all source files instead of hardcoding them.

Goals:

1. Follow clang-tidy rules to maintain project clean.

2. Do not allow new code to break goal #1.

Requirements for CI:

1. In case new file appears in the project, it should be picked-up by CI
   automatically and CI should assign NORMAL clang-tidy check level.

2. CI makefile should have SKIP list to define files for which build
   by CI is impossible for some reason.

3. CI makefile should have ability to override clang-tidy check level for
   every file.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Make Planner class fully static
Roman Stratiienko [Thu, 30 Dec 2021 16:05:27 +0000 (18:05 +0200)]
drm_hwcomposer: Make Planner class fully static

clang-tidy suggested to make all methods of Planner static,
since they don't use any instance members.

This makes creation of Planner instances unnecessary, therefore
remove all such cases.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: CI: Set clang-tidy level to NORMAL for some files
Roman Stratiienko [Thu, 23 Dec 2021 17:04:29 +0000 (19:04 +0200)]
drm_hwcomposer: CI: Set clang-tidy level to NORMAL for some files

Some of files require small adjustments to move into NORMAL checks list.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: CI: Raise clang-tidy level from NONE to COARSE for *.h
Roman Stratiienko [Thu, 23 Dec 2021 15:36:12 +0000 (17:36 +0200)]
drm_hwcomposer: CI: Raise clang-tidy level from NONE to COARSE for *.h

To improve CI coverage.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: CI: Process every file with clang-tidy.
Roman Stratiienko [Thu, 23 Dec 2021 14:25:20 +0000 (16:25 +0200)]
drm_hwcomposer: CI: Process every file with clang-tidy.

Currently part of header files isn't processed by CI.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: CI: Fix Makefile dependencies
Roman Stratiienko [Thu, 23 Dec 2021 11:41:13 +0000 (13:41 +0200)]
drm_hwcomposer: CI: Fix Makefile dependencies

Previous dependencies relations was triggering FULL 'clang-tidy'
re-validation, even in case single source file has changed.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Update readability-identifier-naming rules
Roman Stratiienko [Fri, 24 Dec 2021 16:56:17 +0000 (18:56 +0200)]
drm_hwcomposer: Update readability-identifier-naming rules

Sync local rules with github gist [1] revision 7.

[1]: https://gist.github.com/airglow923/1fa3bda42f2b193920d7f46ee8345e04
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Free resources in HookDevClose()
Roman Stratiienko [Thu, 23 Dec 2021 10:59:20 +0000 (12:59 +0200)]
drm_hwcomposer: Free resources in HookDevClose()

Composer service won't free memory for us, see [1].

[1]: https://cs.android.com/android/platform/superproject/+/master:hardware/interfaces/graphics/composer/2.1/utils/passthrough/include/composer-passthrough/2.1/HwcHal.h;l=83;drc=7ae8af54b32a7eb827dbf9f2aedb647c9525a3d9
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Send crtc.active and crtc.mode together with the frame
Roman Stratiienko [Tue, 11 Jan 2022 17:47:24 +0000 (19:47 +0200)]
drm_hwcomposer: Send crtc.active and crtc.mode together with the frame

On HiKey/HiKey960 boards, enabling the crtc before the first
composition is set can cause trouble, as part of the display
engine is configured in the atomic plane update method.

So when commit 36a7f28516a4 ("drm_hwcomposer: Rework display
Mode Setting and DPMS handling"), which reworked the dpms and
modeset logic to commit the modeset immediately, landed it
caused bootup regressions on those boards.

Talking with others it seems other drivers likely may have
issues trying to enable the crtc without a plane.

Thus this patch changes the logic to queue modesets so they
are submitted with the initial composition. Similarly it
removes the crtc activation, as the initial composition will
implicitly activate the crtc.

Fixes: 36a7f28516a4  ("drm_hwcomposer: Rework display Mode Setting and DPMS handling")
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
[jstultz: Added commit message, reworked a comment]
Signed-off-by: John Stultz <john.stultz@linaro.org>
Change-Id: Ie4d1f967da052b0b3ef73257c2ca76b30504a6c2

2 years agodrm_hwcomposer: Remove supported()/unsupported() functions
Roman Stratiienko [Wed, 22 Dec 2021 15:34:18 +0000 (17:34 +0200)]
drm_hwcomposer: Remove supported()/unsupported() functions

Functions was used mostly for logging HWC2 API calls.

API calls logging will be re-introduced inside the hook templates in
further patches, which will improve logs quality and reduce LOC number.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Modify source_layers_ to be integer instead of array
Roman Stratiienko [Fri, 17 Dec 2021 13:09:28 +0000 (15:09 +0200)]
drm_hwcomposer: Modify source_layers_ to be integer instead of array

It isn't used as an array. Simplify the logic.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Tested-by: Martin Juecker <martin.juecker@gmail.com>
Reviewed-by: Matvii Zorin <matvii.zorin@globallogic.com>
2 years agodrm_hwcomposer: Cleanup Planner class
Roman Stratiienko [Fri, 17 Dec 2021 13:01:18 +0000 (15:01 +0200)]
drm_hwcomposer: Cleanup Planner class

Remove unused code.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Tested-by: Martin Juecker <martin.juecker@gmail.com>
Reviewed-by: Matvii Zorin <matvii.zorin@globallogic.com>
2 years agodrm_hwcomposer: Handle unused planes by DrmDisplayCompositor
Roman Stratiienko [Fri, 17 Dec 2021 11:31:27 +0000 (13:31 +0200)]
drm_hwcomposer: Handle unused planes by DrmDisplayCompositor

Rationale:
1. Cleanup/Simplify DrmDisplayComposition class
2. Prepare for shared planes support

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Tested-by: Martin Juecker <martin.juecker@gmail.com>
Reviewed-by: Matvii Zorin <matvii.zorin@globallogic.com>
2 years agodrm_hwcomposer: Rework KMS state tracking
Roman Stratiienko [Wed, 15 Dec 2021 11:46:05 +0000 (13:46 +0200)]
drm_hwcomposer: Rework KMS state tracking

1. Store only FrameBuffer shared handle to keep buffer alive while
it is a part of active composition.
2. Store used planes to allow clearing of the composition.

Before this both of mentioned above was a part of DrmDisplayComposition.
Any external modification DrmDisplayComposition caused framebuffer object
to be destroyed, which forced screen to go blank.

We want to modify DrmDisplayComposition, to allow re-using previous
composition data.

This change will also help us tracking STAGED frame state and
migrate to non-blocking atomic commit.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Tested-by: Martin Juecker <martin.juecker@gmail.com>
Reviewed-by: Matvii Zorin <matvii.zorin@globallogic.com>
2 years agodrm_hwcomposer: CI: Replace shell scripts with Makefile
Roman Stratiienko [Wed, 22 Dec 2021 14:22:24 +0000 (16:22 +0200)]
drm_hwcomposer: CI: Replace shell scripts with Makefile

This won't make much benefits for CI, but for local native builds will
significantly speed-up build cycle by allowing parallel build and by
using dependency tracking logic.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: CI: Tune clang-tidy coarse checks
Roman Stratiienko [Wed, 22 Dec 2021 09:46:03 +0000 (11:46 +0200)]
drm_hwcomposer: CI: Tune clang-tidy coarse checks

1. Switch to "enable all then disable unwanted" strategy
2. Enable checks that causes small number of failes, marking
   corresponding lines as NOLINT, so we won't introduce
   new such cases unintentionally.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Tidy-up the CI scripts
Roman Stratiienko [Wed, 22 Dec 2021 08:40:59 +0000 (10:40 +0200)]
drm_hwcomposer: Tidy-up the CI scripts

1. Use -Wextra instead of multiple -Wxxx arguments. It will turn on remaining
   checks (such as -Wunused-parameter, which is currently disabled in CI)

2. Bump-up ANDROID_API definitions to 31

3. Fix clang-format-diff-X version to match the one specified in the README.md

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: support more connector types
Yongqin Liu [Sun, 28 Nov 2021 00:46:30 +0000 (08:46 +0800)]
drm_hwcomposer: support more connector types

according to the drm_connector_enum_list defined
in the kernel file drivers/gpu/drm/drm_connector.c

Otherwise for the new connector type, the connector
name will be "None" to be printed  in the logcat, like this:
    12-13 05:38:06.263   383   383 I hwc-backend: Backend 'generic' for 'None' and driver 'omapdrm' was successfully set
with this change, it will be fixed with the connector type like this:
    12-13 06:01:57.672   342   342 I hwc-backend: Backend 'generic' for 'DPI-1' and driver 'omapdrm' was successfully set

Also updated the internal() and external() functions
to make the newly added SPI and USB are valid types

Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2 years agodrm_hwcomposer: Assume premultiplied alpha for CLIENT layer
Roman Stratiienko [Mon, 6 Dec 2021 12:56:14 +0000 (14:56 +0200)]
drm_hwcomposer: Assume premultiplied alpha for CLIENT layer

On db845c, we have seen an odd behavior with modal dialogs in
AOSP, where the background which is normally darkened, was
rendering as black, though it would occasionally flicker to the
right thing. This cropped up after alpha support on planes
landed in 5.15, so we assumed it was an edge case issue with the
dpu1 driver.

But while working on a separate issue seen on x86 hardware:
  https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/46

Roman noticed drm_hwcomposer always sets the blending type to
NONE for the client layer. Which had gone un-noticed becase he
didn't have any devices that exposed the NONE type.

Thus Roman implemented this patch, which sets up the client
blend type to PREMULTIPLIED.

While it did not resolve the x86 issue above, it does resolve
the incorrect rendering seen on db845c with alpha support
enabled.

Tested-by: Martin Juecker martin.juecker@gmail.com #Exynos 4412
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Change-Id: I95601c680ca1af0dc9d3b3f102f79f77af081b75

2 years agodrm_hwcomposer: Fix all cases which triggers an error on -Wsign-compare
Roman Stratiienko [Mon, 6 Dec 2021 10:59:26 +0000 (12:59 +0200)]
drm_hwcomposer: Fix all cases which triggers an error on -Wsign-compare

Android-9 has -Wsign-compare enabled by default and it causes build issues.
Enable -Wsign-compare option in CI, so we won't introduce such issues anymore.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Use gralloc0::perform API by minigbm bufferinfo getter
Roman Stratiienko [Tue, 30 Nov 2021 15:48:16 +0000 (17:48 +0200)]
drm_hwcomposer: Use gralloc0::perform API by minigbm bufferinfo getter

Using of internals of cros_gralloc_handle isn't recommended, since
it can be changed at any time. Meanwhile minigbm provides another
API to access buffer information based on gralloc0 perform() call.

ChromiumOS are using this API by mesa3d and other related projects.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Validate gralloc0 name for minigbm and libdrm getters
Roman Stratiienko [Tue, 30 Nov 2021 15:06:44 +0000 (17:06 +0200)]
drm_hwcomposer: Validate gralloc0 name for minigbm and libdrm getters

Using of incorrect gralloc0 results in a runtime issues, with logs like
"Cannot convert hal format to drm format <VALUE>" or other.

Validate gralloc name and exit gracefully in case it doesnt't match the one
we are expecting.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Rework display modes handling
Roman Stratiienko [Tue, 16 Nov 2021 16:23:18 +0000 (18:23 +0200)]
drm_hwcomposer: Rework display modes handling

Android likes to adapt display output frequency to match window context
frequency. Unfortunately platform code has some limitations, therefore
hwcomposer HAL should be careful with reporting supported display modes.

Known platform limitations:
1: Framework doesn't distinguish between interlaced/progressive modes.
2. Framework will not switch display frequency in case margin in FPS rate
   is very small (<1FPS or so). Not a big issue, but that is causing
   some CTS tests to fail.

In addition to that VRR technology (or seamless mode switching) require
hwcomposer to group modes which tells the framework that seamless mode
configuration change is supported within a group of display modes.

By this commit do the following:
1. Group modes by the resolution:
   E.g.

    Group 1:
    1024x768i@60
    1024x768i@90
    1024x768@50
    1024x768@50.1

    Group 2:
    1920x1080@60
    1920x1080@24.3
    1920x1080i@60
    1920x1080i@120

2. Disable modes in a way that each group keeps only interlaced or proressive
   modes enabled. In case KMS reported preferred mode is interlaced - prefer
   interlaced for the whole group, otherwise prefer progressive.

3. Disable mode in case different mode in the same group has similar frequency
   with delta less than 1FPS.

4. Report only modes which remain enabled to the framework.

Test: atest CtsGraphicsTestCases

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Don't use Mapper@4 metadata API for legacy getters
Roman Stratiienko [Thu, 28 Oct 2021 12:52:38 +0000 (15:52 +0300)]
drm_hwcomposer: Don't use Mapper@4 metadata API for legacy getters

As it turned out Mapper@4 metadata API calls are slow.
Allow using legacy getters again.

Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/56

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Make uevent listener standalone
Roman Stratiienko [Mon, 25 Oct 2021 19:54:20 +0000 (22:54 +0300)]
drm_hwcomposer: Make uevent listener standalone

1. DRM event listener doesn't work in this conditions, uevent blocks
   the thread and non-blocking select() doesn't make any sense.
   Remove DRM event handling for now.

2. UEvent listeren is common for all DrmDevices, therefore put it into
   ResourceManager class.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Route release fence directly
Roman Stratiienko [Sat, 23 Oct 2021 14:47:35 +0000 (17:47 +0300)]
drm_hwcomposer: Route release fence directly

Current release_fence merging logic doesn't make much sence, cleanup it.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Make single atomic function for all atomic commit ops.
Roman Stratiienko [Sat, 23 Oct 2021 14:35:44 +0000 (17:35 +0300)]
drm_hwcomposer: Make single atomic function for all atomic commit ops.

... to allow precise control on atomic commit operations.

This should also help to implement dynamic modechange, readback and
other useful features.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move CreateModeBlob to DrmMode class
Roman Stratiienko [Fri, 22 Oct 2021 15:13:09 +0000 (18:13 +0300)]
drm_hwcomposer: Move CreateModeBlob to DrmMode class

CreateModeBlob doesn't architecturally belongs to DrmDisplayCompositor.
+ align DrmMode internal types with libdrm types to avoid compilation errors.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove DrmDisplayCompositor::GetActiveModeResolution()
Roman Stratiienko [Thu, 7 Oct 2021 08:27:08 +0000 (11:27 +0300)]
drm_hwcomposer: Remove DrmDisplayCompositor::GetActiveModeResolution()

DrmDisplayCompositor::GetActiveModeResolution() isn't used, remove it.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Rework display Mode Setting and DPMS handling
Roman Stratiienko [Tue, 5 Oct 2021 15:17:53 +0000 (18:17 +0300)]
drm_hwcomposer: Rework display Mode Setting and DPMS handling

1. Remove DPMS logic. As stated in KMS kernel docs: CRTC "activate"
   property was implemented as a simplified atomic replacement of DPMS.
   And kernel internally will just update "activate" on DPMS setting.

2. Add SetDisplayActivate(bool state) method to compositor class,
   which is now replacement for SetDpmsMode().

3. Move mode settings out of DrmComposition class to DrmCompositor class.
   From now on DrmComposition describes only layer-to-plane composition
   as it should be.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Rework UserPropertyBlob to use RAII
Roman Stratiienko [Thu, 30 Sep 2021 07:18:28 +0000 (10:18 +0300)]
drm_hwcomposer: Rework UserPropertyBlob to use RAII

Makes code simpler and leak-free.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move GetPlaneProperty into DrmPlane class
Roman Stratiienko [Thu, 30 Sep 2021 07:15:05 +0000 (10:15 +0300)]
drm_hwcomposer: Move GetPlaneProperty into DrmPlane class

In addition move logging to GetPlaneProperty(), which allow to reduce
number of LoC by ~50 LoC and increase readability.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove unused DrmDisplayCompositor class fields
Roman Stratiienko [Thu, 30 Sep 2021 07:14:42 +0000 (10:14 +0300)]
drm_hwcomposer: Remove unused DrmDisplayCompositor class fields

Test: mmma external/drm_hwcomposer

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove unused {DrmComposition,DrmCompositor}::Dump()
Roman Stratiienko [Thu, 30 Sep 2021 07:09:46 +0000 (10:09 +0300)]
drm_hwcomposer: Remove unused {DrmComposition,DrmCompositor}::Dump()

Both DrmCompositor and DrmComposition have to be reworked to account
for shared DRM planes, asynchronous atomic commit, dynamic modechange and
composition reusing between Validate/Present steps.

Current dump logic will be obsolate anyway and keeping/supporting it will
slow-down reworking process. It make sense to remove it now and create
from scrach if needed.

Test: mmma external/drm_hwcomposer

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move client flattening closer to the frontend
Roman Stratiienko [Thu, 30 Sep 2021 07:09:31 +0000 (10:09 +0300)]
drm_hwcomposer: Move client flattening closer to the frontend

Remove unnecessary code from DrmCompositor.
Drops ~100 LoC.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Allow pre-multi layer to always pass DrmPlane validation
Roman Stratiienko [Thu, 30 Sep 2021 16:36:00 +0000 (19:36 +0300)]
drm_hwcomposer: Allow pre-multi layer to always pass DrmPlane validation

This logic was removed accidentaly during cleanup. Restore it.
Enables hardware-accelerated composition on raspberry-pi 4.

Fixes: 5063d53ddf7d ("drm_hwcomposer: Improve handling of blending mode")
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Improve Mapper@4 metadata API fds index guessing logic
Roman Stratiienko [Fri, 22 Oct 2021 09:34:36 +0000 (12:34 +0300)]
drm_hwcomposer: Improve Mapper@4 metadata API fds index guessing logic

Unfortunately Mapper@4.0 metadata API doesn't allow to query fd index or
getting fd another way for every layout plane, therefore users have to
provide their custom additional metadata API.

We are doing all our best to minimize custom per-platform logic in
drm_hwcomposer. So it was decided to implement primitive guessing logic,
allowing users to extend it with out-of-tree code if necessary.

As was reported by John Stultz in [1] our primitive logic has some flaws.

New guessing logic are using inputs from layout data (offsets, sizes),
and should be more precise.

[1]: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/merge_requests/159
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Add support for VSYNC_2_4 callback
Roman Stratiienko [Wed, 29 Sep 2021 10:01:39 +0000 (13:01 +0300)]
drm_hwcomposer: Add support for VSYNC_2_4 callback

Increase composer@2.4 implemented API coverage.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Handle all HWC2 callbacks in DrmHwcTwo.{h,cpp}
Roman Stratiienko [Wed, 29 Sep 2021 10:00:29 +0000 (13:00 +0300)]
drm_hwcomposer: Handle all HWC2 callbacks in DrmHwcTwo.{h,cpp}

Part of frontend isolation activities.
1. Use HWC2 HAL types only inside DrmHwcTwo.{h,cpp}.
2. Use single lock for all callbacks.
3. Communicate with other drm_dwc components using std::function
   without any locking.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move rotation enum querying into DrmPlane initialization
Roman Stratiienko [Wed, 29 Sep 2021 09:59:54 +0000 (12:59 +0300)]
drm_hwcomposer: Move rotation enum querying into DrmPlane initialization

Benefits:
1. Improve readability.
2. Less logic in runtime slightly reduces overhead on CPU.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Cleanup DrmPlane::Init()
Roman Stratiienko [Wed, 29 Sep 2021 09:59:48 +0000 (12:59 +0300)]
drm_hwcomposer: Cleanup DrmPlane::Init()

Adding enum value into map looks ugly.
Create a wrapper in order to fix it.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: DrmPlane: More atomic commit cleanup
Roman Stratiienko [Wed, 29 Sep 2021 09:52:22 +0000 (12:52 +0300)]
drm_hwcomposer: DrmPlane: More atomic commit cleanup

A few rearrangements to reduce LoC and increase readability.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove unused cursor_{x,y}_ and layer_color_ variables
Roman Stratiienko [Wed, 29 Sep 2021 09:50:10 +0000 (12:50 +0300)]
drm_hwcomposer: Remove unused cursor_{x,y}_ and layer_color_ variables

Make it clear that drm_hwcomposer doesn't handle these values.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Convert transform value at HWC hook call
Roman Stratiienko [Wed, 29 Sep 2021 09:47:35 +0000 (12:47 +0300)]
drm_hwcomposer: Convert transform value at HWC hook call

One more step towards "frontend" isolation.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Improve handling of blending mode
Roman Stratiienko [Wed, 29 Sep 2021 09:47:31 +0000 (12:47 +0300)]
drm_hwcomposer: Improve handling of blending mode

1. Convert to DrmHwcBlending inside HWC hook.
2. Use map for enum_values for cleaner atomic commit preparation.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Query color_encoding and color_range enums during init
Roman Stratiienko [Wed, 29 Sep 2021 09:47:26 +0000 (12:47 +0300)]
drm_hwcomposer: Query color_encoding and color_range enums during init

Should slightly reduce CPU load at runtime + improve
atomic commit readability.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Create intermediate enum for colorspace and samplerange
Roman Stratiienko [Wed, 29 Sep 2021 09:47:21 +0000 (12:47 +0300)]
drm_hwcomposer: Create intermediate enum for colorspace and samplerange

Part of "frontend" isolation activities.
Also allows to additionally simplify atomic commit.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move plane-related atomic commit logic to DrmPlane class
Roman Stratiienko [Wed, 29 Sep 2021 09:47:16 +0000 (12:47 +0300)]
drm_hwcomposer: Move plane-related atomic commit logic to DrmPlane class

Remove unnecessary property getter/setters from DrmPlane class.

As result: Removed ~50 unnecessary LoC. Improved readability.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Move IsKMSDev to DrmDevice
Roman Stratiienko [Wed, 29 Sep 2021 09:47:12 +0000 (12:47 +0300)]
drm_hwcomposer: Move IsKMSDev to DrmDevice

IsKMSDev() is a DRM device helper, therefore DrmDevice class
is better home for it.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove unused AvailableWritebackConnector()
Roman Stratiienko [Wed, 29 Sep 2021 09:47:06 +0000 (12:47 +0300)]
drm_hwcomposer: Remove unused AvailableWritebackConnector()

ResourceManager::AvailableWritebackConnector is not used anymore.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Remove unused ResourceManager::gralloc_ field
Roman Stratiienko [Wed, 29 Sep 2021 09:47:00 +0000 (12:47 +0300)]
drm_hwcomposer: Remove unused ResourceManager::gralloc_ field

It was added with initial ResourceManager implementation and was
never used.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Cleanup DRM atomic commit
Roman Stratiienko [Wed, 29 Sep 2021 09:46:54 +0000 (12:46 +0300)]
drm_hwcomposer: Cleanup DRM atomic commit

Create and use DrmPlane::AtomicSet() wrapper.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2 years agodrm_hwcomposer: Wrap libdrm drmMode*{Get|Free}* into RAII
Roman Stratiienko [Wed, 29 Sep 2021 09:46:28 +0000 (12:46 +0300)]
drm_hwcomposer: Wrap libdrm drmMode*{Get|Free}* into RAII

This should elliminate chance of any leaks in the future.
Fix drmModePropertyBlobPtr leak in DrmHwcTwo.cpp.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>