OSDN Git Service

android-x86/external-drm_hwcomposer.git
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>
2 years agodrm_hwcomposer: Fix property_get() linux impl.
Roman Stratiienko [Wed, 4 Aug 2021 19:43:06 +0000 (22:43 +0300)]
drm_hwcomposer: Fix property_get() linux impl.

Bad implementation was found during code surfing.
At this moment function is used only as a stub for CI.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2 years agodrm_hwcomposer: CI: Tune the readability-identifier-naming settings
Roman Stratiienko [Thu, 4 Mar 2021 13:22:09 +0000 (15:22 +0200)]
drm_hwcomposer: CI: Tune the readability-identifier-naming settings

Copy rules from [1], which is based on Google cpp code-style guide [2]

[1]: https://gist.github.com/airglow923/1fa3bda42f2b193920d7f46ee8345e04
[2]: https://google.github.io/styleguide/cppguide.html

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2 years agodrm_hwcomposer: CI: Upgrade clang-* to v12
Roman Stratiienko [Wed, 4 Aug 2021 16:55:37 +0000 (19:55 +0300)]
drm_hwcomposer: CI: Upgrade clang-* to v12

- Enabling readability-ientifier-naming tidy check does require to specify
MacroDefinitionIgnoredRegexp key, which is available only in clang-tidy-12.

- Clang-12 isn't available on ubuntu 20.10, therefore upgrade to 21.04.

- "DEBIAN_FRONTEND: noninteractive" is required to prevent ubuntu 21.04
from hanging, presumably due to waiting for the user input.

- A positive side effect of upgrading to clang-12 is new clang-tidy-12,
which exposed new issues in the code which is also fixed by this commit,
e.g:

    Failed cppcoreguidelines-narrowing-conversions check with error:
    error: narrowing conversion from 'uint32_t' (aka 'unsigned int') to 'float'

require explicit casting to pass the check, while some of such fails are caused
by incorrect variable type and fixed by changing the type to correct one.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2 years agodrm_hwcomposer: Don't close same handle several times.
Roman Stratiienko [Wed, 25 Aug 2021 03:15:42 +0000 (06:15 +0300)]
drm_hwcomposer: Don't close same handle several times.

Video (YUV) frames can have several planes in the same buffer,
in this case all the planes will be represented by the same
gem_handle, which must be closed only once.

Fixes logcat noise during video playback.

Reported-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2 years agodrm_hwcomposer: Quiet noisy errors when planes don't support various attributes
John Stultz [Tue, 24 Aug 2021 04:59:25 +0000 (04:59 +0000)]
drm_hwcomposer: Quiet noisy errors when planes don't support various attributes

If a plane doesn't support alpha or rotation, and IsValidForLayer()
fails, we see lots of logcat noise to the effect of:
08-24 04:45:42.957   453   453 E hwc-platform: Failed to emplace layer 0, dropping it
08-24 04:45:42.957   453   453 E hwc-platform: Failed provision stage with ret -22
08-24 04:45:42.957   453   453 E hwc-drm-display-composition: Planner failed provisioning planes ret=-22
08-24 04:45:42.957   453   453 E hwc-drm-two: Failed to plan the composition ret=-22

This noise is unneccessarily worrisome, as they don't really
help explain why things fail, and we still fall back to client
composing and frames are correctly composited.

Thus, this patch switches the errors to verbose-level warnings,
which match the level in IsValidForLayer() which explain what
actually is going wrong.

Change-Id: I7ed06906b8d9e02e6ec0ac50a94346e9f9c05ac6
Signed-off-by: John Stultz <john.stultz@linaro.org>
2 years agodrm_hwcomposer: Fix sync_file fd leak from "Rework audofd"
John Stultz [Sat, 31 Jul 2021 00:19:50 +0000 (00:19 +0000)]
drm_hwcomposer: Fix sync_file fd leak from "Rework audofd"

In commit 0fade37afd60 ("drm_hwcomposer: Rework autofd"),
a change to some very subtle existing code caused a resource
leak such that after 10 minutes or so of active display
output, we would start seeing:

  android.hardware.graphics.composer@2.3-service: failed to dup fence 10

over and over in logcat. Moving the mouse would cause black
frame to flicker and eventually Surfaceflinger would crash
and restart.

The problem was subtle change in the following hunk:
@@ -1047,10 +1049,9 @@ HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBlendMode(int32_t mode) {
 HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBuffer(buffer_handle_t buffer,
                                                 int32_t acquire_fence) {
   supported(__func__);
-  UniqueFd uf(acquire_fence);

   set_buffer(buffer);
-  set_acquire_fence(uf.get());
+  acquire_fence_ = UniqueFd(fcntl(acquire_fence, F_DUPFD_CLOEXEC));
   return HWC2::Error::None;
 }

The core of the problem being, that the UniqueFd class calls
close(fd_) in its descructor. So while the change using
fcntl(...,F_DUPFD_CLOEXEC) matches what was burried in
set_acquire_fence(), dropping the creation (and more importantly
the destruction when it goes out of scope) of uf changes the
logic so we don't end up calling close on the aquire_fence fd
argument passed in.

One can confirm this resource leak by doing:
  adb shell lsof | grep composer

And noticing the number of sync_file fds growing over time.

Thus, this patch fixes the logic, so instead of dup()'ing the
passed in fd, (and then closing it as done before Roman's
patch), we can just set aquire_fence_ to a new UniqueFd directly
using the aquire_fence fd passed in.

This pattern actually occured twice, so I've fixed it in both
places.

Fixes: 0fade37afd60 ("drm_hwcomposer: Rework autofd")
Signed-off-by: John Stultz <john.stultz@linaro.org>
Change-Id: Iff2ca1c0b6701abbdc10c6ee92edb21a4b84a841

2 years agodrm_hwcomposer: Add links to the HWC2 API description
Roman Stratiienko [Fri, 21 May 2021 11:33:28 +0000 (14:33 +0300)]
drm_hwcomposer: Add links to the HWC2 API description

Some part of the API is not streightforward and wrong implementation
may cause leaks and other hard-to-debug runtime issues.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2 years agodrm_hwcomposer: Rework autofd
Roman Stratiienko [Sat, 20 Feb 2021 11:59:55 +0000 (13:59 +0200)]
drm_hwcomposer: Rework autofd

Motivation:

Current implementation of UniqueFd can be used in a different ways,
making analytical tracking of FD lifecycle much harder than it may be.
Keep this part clean is very important, since any wrong code may open
a hard-to-detect runtime bugs and fd leaks, which may accidentally slip
into the production.

Implementation:

1. Combine UniqueFd anf OutputFd into single class.
2. Reduce the API to be minimal and sufficient.
3. Document the API and use cases.
4. Move to utils/UniqueFd.h.
5. dup(fd) was replaced with fcntl(fd, F_DUPFD_CLOEXEC)) to
   address clang-tidy findings. Find more information at [1]

[1]: https://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-dup.html

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: cleanup hwcutils
Roman Stratiienko [Wed, 10 Feb 2021 12:59:52 +0000 (14:59 +0200)]
drm_hwcomposer: cleanup hwcutils

Remove DrmHwcBuffer class. Wrap remaining logic into
DrmHwcLayer class.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: Stop importing native_handle_t into the mapper
Roman Stratiienko [Wed, 10 Feb 2021 10:11:16 +0000 (12:11 +0200)]
drm_hwcomposer: Stop importing native_handle_t into the mapper

Composer service is already importing buffers from binder pipe
into the mapper and caches them making native handles valid
for a whole composition processing cycle.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: Tracking of the DRM FB objects using RAII
Roman Stratiienko [Tue, 9 Feb 2021 15:49:55 +0000 (17:49 +0200)]
drm_hwcomposer: Tracking of the DRM FB objects using RAII

DRM framebuffer objects must be kept registered in DRM/KMS
while used for scanning-out (After atomic commit applied
for processing by display controller and until next atomic
commit is applied for processing).

Existing logic for tracking current state is overcomplicated and
needs to be redesigned. Also further developing of drm_hwc will
require migration to asynchronous atomic commit, so additional
asynchronous FB cleanup logic must be created.
Buffer caching logic will also benefit from this.

With the RAII all further changes will be less painful and more robust.

By this commit I also renamed DrmGenericImporter to DrmFbImporter:
'Fb' word is present in most of existing composers (android and linux)
so it will be easier to compare different implementations.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: update README for clang-format-diff-11 and touch up formatting
Benjamin Li [Sun, 9 May 2021 16:01:38 +0000 (09:01 -0700)]
drm_hwcomposer: update README for clang-format-diff-11 and touch up formatting

The README.md is out of date -- clang-format-diff-5.0 is not what runs on
CI anymore. To help contributors better test their changes locally before
submitting a merge request, update to the actual linting command being run
in CI.

Signed-off-by: Benjamin Li <benl@squareup.com>
3 years agodrm_hwcomposer: remove unused variable blend
Benjamin Li [Sun, 9 May 2021 15:52:35 +0000 (08:52 -0700)]
drm_hwcomposer: remove unused variable blend

The first tuple element returned by GetEnumValueWithName is just the index
of that enum, which is not useful.

Signed-off-by: Benjamin Li <benl@squareup.com>
3 years agodrm_hwcomposer: reject rotations reported as unsupported by hardware
Benjamin Li [Sun, 9 May 2021 15:52:18 +0000 (08:52 -0700)]
drm_hwcomposer: reject rotations reported as unsupported by hardware

Currently we only check for the presence of any rotation support -- but
hardware may choose to, say, only support 180 degree rotation. Respect
the specific rotation capabilities reported through DRM properties.

Signed-off-by: Benjamin Li <benl@squareup.com>
3 years agodrm_hwcomposer: add DRM_PROPERTY_TYPE_BITMASK
Benjamin Li [Wed, 5 May 2021 16:23:15 +0000 (09:23 -0700)]
drm_hwcomposer: add DRM_PROPERTY_TYPE_BITMASK

Bitmask properties are integers that additionally have strings associated
with each bit. For example, the "rotation" property's bits are described
as "rotate-90", "reflect-x", and so on.

The bitmask integer is not actually passed to us -- instead, the interface
for enums is used, except that more than one value can be set. This means we
must query using the associated strings, rather than use bit index mappings
provided as constants in the public kernel header drm_mode.h.

Signed-off-by: Benjamin Li <benl@squareup.com>
3 years agodrm_hwcomposer: Fix regression after composition creation cleanup
Matvii Zorin [Mon, 26 Apr 2021 14:24:56 +0000 (17:24 +0300)]
drm_hwcomposer: Fix regression after composition creation cleanup

During rebasing of the local integration branch, one code chunk was not
updated accidentally and the client range was not selected properly which
leads to jank frames appearance.

The issue has been already fixed by the commit 3f89182bb9df
("drm_hwcomposer: Fix client range selection logic").

Issue: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/53
Fixes: b3b15166f9da ("drm_hwcomposer: Add GetExtraClientRange method")
Suggested-by: Roman Stratiienko <r.stratiienko@gmail.com>
Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Move ValidatePlane method into DrmPlane
Matvii Zorin [Sun, 31 Jan 2021 12:45:05 +0000 (14:45 +0200)]
drm_hwcomposer: Move ValidatePlane method into DrmPlane

It is more common to validate the layer for the proper object.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Remove useless setters from DrmHwcLayer
Roman Kovalivskyi [Sun, 24 Jan 2021 18:32:37 +0000 (20:32 +0200)]
drm_hwcomposer: Remove useless setters from DrmHwcLayer

SetDisplayFrame and SetSourceCrop methods are unnecessary in
the DrmHwcLayer structure without any private members.

Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Add GetOrderLayersByZPos method
Matvii Zorin [Fri, 29 Jan 2021 16:32:06 +0000 (18:32 +0200)]
drm_hwcomposer: Add GetOrderLayersByZPos method

The GetOrderLayersByZPos copies an ordered list of layer pointers.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Move HardwareSupportsLayerType into Backend
Matvii Zorin [Fri, 29 Jan 2021 14:45:25 +0000 (16:45 +0200)]
drm_hwcomposer: Move HardwareSupportsLayerType into Backend

The HardwareSupportsLayerType function is used only for display validation
which is implemented in the generic backend.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Move MarkValidated into Backend
Matvii Zorin [Fri, 29 Jan 2021 14:40:25 +0000 (16:40 +0200)]
drm_hwcomposer: Move MarkValidated into Backend

The MarkValidated function is used only for display validation which is
implemented in the generic backend.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Add GetExtraClientRange method
Matvii Zorin [Fri, 29 Jan 2021 13:48:20 +0000 (15:48 +0200)]
drm_hwcomposer: Add GetExtraClientRange method

Separate the correction of client range into the separate method.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Move CalcPixOps into Backend
Matvii Zorin [Fri, 29 Jan 2021 13:39:55 +0000 (15:39 +0200)]
drm_hwcomposer: Move CalcPixOps into Backend

The CalcPixOps is used only for display validation which is implemented
in the generic backend.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Remove ctrc from DrmCompositionPlane
Matvii Zorin [Mon, 18 Jan 2021 13:54:22 +0000 (15:54 +0200)]
drm_hwcomposer: Remove ctrc from DrmCompositionPlane

CRTC is set at CreateComposition function and it matches the current
display.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Remove SquashState class declaration
Matvii Zorin [Tue, 12 Jan 2021 09:06:56 +0000 (11:06 +0200)]
drm_hwcomposer: Remove SquashState class declaration

There is no use of SquashState class, so the declaration could be removed
in the scope of cleanup.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Remove DrmCompositionDisplayLayersMap
Matvii Zorin [Tue, 12 Jan 2021 08:53:08 +0000 (10:53 +0200)]
drm_hwcomposer: Remove DrmCompositionDisplayLayersMap

The structure is used only at the CreateComposition function.
Data consolidation is unnecessary in this case.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Remove DrmCompositionRegion struct
Matvii Zorin [Tue, 12 Jan 2021 08:40:44 +0000 (10:40 +0200)]
drm_hwcomposer: Remove DrmCompositionRegion struct

The structure is currently unused.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Cleanup DrmDisplayComposition initialization
Matvii Zorin [Fri, 8 Jan 2021 10:55:45 +0000 (12:55 +0200)]
drm_hwcomposer: Cleanup DrmDisplayComposition initialization

Remove unused members (drm, importer, frame_no). Move initialization
from the proper function to the constructor.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: CI: Increase coverage
Roman Stratiienko [Tue, 9 Mar 2021 19:56:50 +0000 (21:56 +0200)]
drm_hwcomposer: CI: Increase coverage

Add the following files to the build:
backend/BackendClient.cpp
backend/Backend.cpp
backend/BackendManager.cpp
backend/BackendRCarDu.cpp
bufferinfo/legacy/BufferInfoImagination.cpp
bufferinfo/legacy/BufferInfoLibdrm.cpp
bufferinfo/legacy/BufferInfoMaliHisi.cpp
bufferinfo/legacy/BufferInfoMaliMediatek.cpp
bufferinfo/legacy/BufferInfoMaliMeson.cpp
bufferinfo/legacy/BufferInfoMinigbm.cpp
compositor/DrmDisplayComposition.cpp
compositor/DrmDisplayCompositor.cpp
compositor/Planner.cpp
drm/DrmGenericImporter.cpp
DrmHwcTwo.cpp
drm/ResourceManager.cpp
drm/VSyncWorker.cpp
tests/worker_test.cpp
utils/autolock.cpp

Files 'bufferinfo/BufferInfoMapperMetadata.cpp' and 'utils/hwcutils.cpp' require
a lot of additional headers, therefore move them out of the scope of this commit.

'utils/gralloc.h' isn't planned to use in pure-linux builds, therefore remove
it from 'utils' and put it into '.ci/android_headers/hardware/'

Fix minor tidy fails.

Fix linux build fails (missing includes) due to differences between libc and
bionic.

Comment-out some sections in 'tests/test_include' which aren't used by drm_hwc
but causing build failures for CI due to missing dependencies.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: CI: Pull headers from the AOSPv11
Roman Stratiienko [Fri, 2 Apr 2021 14:19:54 +0000 (17:19 +0300)]
drm_hwcomposer: CI: Pull headers from the AOSPv11

The goal is to check compilation and clang-tidy at CI stage.
For both compile and tidy all dependent headers are required.
Compilation and tidy-check enabled by the next commit.

Done by invoking the following bash commands:

cp system/core/libcutils/include/cutils/native_handle.h \
   system/core/libcutils/include/cutils/compiler.h \
   system/core/libcutils/include/cutils/trace.h \
   external/drm_hwcomposer/.ci/android_headers/cutils/

cp external/libdrm/android/gralloc_handle.h \
   external/drm_hwcomposer/.ci/android_headers/gralloc_handle.h

cp hardware/libhardware/include/hardware/gralloc.h \
   hardware/libhardware/include/hardware/hardware.h \
   hardware/libhardware/include/hardware/hwcomposer.h \
   hardware/libhardware/include/hardware/hwcomposer2.h \
   hardware/libhardware/include/hardware/hwcomposer_defs.h \
   external/drm_hwcomposer/.ci/android_headers/hardware/

cp system/core/libsync/include/sync/sync.h \
   external/drm_hwcomposer/.ci/android_headers/sync/sync.h

cp system/core/libsync/include/ndk/sync.h \
   external/drm_hwcomposer/.ci/android_headers/ndk/sync.h

cp system/core/libsystem/include/system/graphics-base-v1.0.h \
   system/core/libsystem/include/system/graphics-base-v1.1.h \
   system/core/libsystem/include/system/graphics-base-v1.2.h \
   system/core/libsystem/include/system/graphics-base.h \
   system/core/libsystem/include/system/graphics-sw.h \
   system/core/libsystem/include/system/graphics.h \
   external/drm_hwcomposer/.ci/android_headers/system/

cp frameworks/native/libs/ui/include/ui/GraphicBuffer.h \
   external/drm_hwcomposer/.ci/android_headers/ui/GraphicBuffer.h

cp system/core/libutils/include/utils/Trace.h \
   external/drm_hwcomposer/.ci/android_headers/utils/Trace.h

Turn off clang-format check for these files.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Fix client range selection logic
Roman Stratiienko [Thu, 1 Apr 2021 12:52:54 +0000 (15:52 +0300)]
drm_hwcomposer: Fix client range selection logic

Original change aimed to fix clang-tidy checks, but
accidentally it caused wrong client range selection.

Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/53
Fixes: e2f2c929243f ("drm_hwcomposer: enable code analysis using clang-tidy")
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: Remove writeback-based flattening logic
Roman Stratiienko [Fri, 5 Feb 2021 14:32:47 +0000 (16:32 +0200)]
drm_hwcomposer: Remove writeback-based flattening logic

Writeback Pros:
a. Very tiny reduction in power consumption required for
   rendering the composition compared to CLIENT-based flattening.

Writeback Cons:
a. A lot of extra code. High maintenance cost(effort).
   Nobody tests it as for now.
b. Writeback isn't implemented by the set of KMS drivers
c. Require separate memory buffer to be allocated

Part of: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/47
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: add missing HAL pixel format
Riadh Ghaddab [Fri, 5 Feb 2021 12:06:50 +0000 (12:06 +0000)]
drm_hwcomposer: add missing HAL pixel format

using Android-11 (android-11.0.0_r27 )on i500 MediaTek SoC we can
see some log floods with the following trace:

E hwc-platform-drm-generic: Cannot convert hal format to drm format 43

Adding the conversion of this format : HAL_PIXEL_FORMAT_RGBA_1010102
resolves the log flood

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
3 years agodrm_hwcomposer: CI: Add more source files to the build
Roman Stratiienko [Fri, 26 Feb 2021 15:49:40 +0000 (17:49 +0200)]
drm_hwcomposer: CI: Add more source files to the build

Build bufferinfo/BufferInfoGetter.cpp and drm/DrmPlane.cpp

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: clang-tidy: enable cppcoreguidelines-* checks
Roman Stratiienko [Mon, 15 Feb 2021 11:44:19 +0000 (13:44 +0200)]
drm_hwcomposer: clang-tidy: enable cppcoreguidelines-* checks

Our code isn't ready for the following checks therefore keep disabled
-cppcoreguidelines-pro-bounds-array-to-pointer-decay
-cppcoreguidelines-pro-bounds-constant-array-index
-cppcoreguidelines-pro-bounds-pointer-arithmetic
-cppcoreguidelines-pro-type-cstyle-cast
-cppcoreguidelines-pro-type-vararg
-cppcoreguidelines-avoid-magic-numbers
-cppcoreguidelines-macro-usage
-cppcoreguidelines-avoid-c-arrays

+ fixed existing tidy warnings for these checks.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: clang-tidy: enable clang-analyzer-* checks
Roman Stratiienko [Mon, 15 Feb 2021 09:25:23 +0000 (11:25 +0200)]
drm_hwcomposer: clang-tidy: enable clang-analyzer-* checks

+ fixed existing tidy warnings for these checks.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: enable code analysis using clang-tidy
Roman Stratiienko [Sat, 13 Feb 2021 08:57:47 +0000 (10:57 +0200)]
drm_hwcomposer: enable code analysis using clang-tidy

Drm hwcomposer project has some code-style inconsistencies.
This is the initial step to unify code-style of the code.

Clang-tidy is a great tool which can not only suggest correct styling,
but also allow predicting the errors in the code and suggest correct
coding approaches to avoid potential weaknesses.

CI was tuned to check clang-tidy recommendation for some part of the
code which is ready ATM (can be built outside AOSP tree).
For this part a limited set of clang-tidy checks has applied (coarse check).
Header files aren't checked at all.

Starting from now new code files must be included into the list that is
checked by almost all clang-tidy checks (fine checklist). New header files
should be also included into this list.
See '.gitlab-ci-clang-tidy-fine.sh'.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: CI: Use bpfmt to check Android.bp files style
Roman Stratiienko [Sat, 27 Feb 2021 20:08:51 +0000 (22:08 +0200)]
drm_hwcomposer: CI: Use bpfmt to check Android.bp files style

Fix available errors by executing:
$ find -name "*.bp" -exec bpfmt -d -s -w {} \;

Suggested-by: Marijn Suijten <marijn.suijten@somainline.org>
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: CI: Initial build and clang-tidy checks
Roman Stratiienko [Thu, 25 Feb 2021 17:15:14 +0000 (19:15 +0200)]
drm_hwcomposer: CI: Initial build and clang-tidy checks

Build android-agnostic code in linux environment.
Enable static code analysis using clang-tidy.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: CI: Use clang-11 for the CI
Roman Stratiienko [Thu, 25 Feb 2021 16:33:26 +0000 (18:33 +0200)]
drm_hwcomposer: CI: Use clang-11 for the CI

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: Create make target to test filegroups
Roman Stratiienko [Mon, 15 Feb 2021 13:41:53 +0000 (15:41 +0200)]
drm_hwcomposer: Create make target to test filegroups

Android.bp contains filegroups that are not built by default
(e.g. using $ mmma external/drm_hwcomposer)

Fix it.

To ensure build will work on wide range of Android versions,
pull depended headers from AOSP-11 tree:
1. Mali: "device/linaro/hikey/gralloc960"
2. Imagination: "hardware/ti/am57x/libhwcomposer"
and put it into ./tests/test_include directory.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: Fix drmSetMaster() usage
John Stultz [Tue, 2 Feb 2021 01:34:45 +0000 (01:34 +0000)]
drm_hwcomposer: Fix drmSetMaster() usage

After commit 3b24cd911ebf ("drm_hwcomposer: Ensure composer has
master access to DRM/KMS") was merged I started seeing failures
on 5.4 based kernels.

Diggin into it, it seemed on those kernels drmSetMaster() was
always returning -EACCES, due to the following upstream kernel
change not being present:
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=45bc3d26c95a8fc63a7d8668ca9e57ef0883351c

That change landed around 5.6, so for older kernels we need to
make sure older kernels without this patch still work. So this
patch, as suggested by Roman Stratiienko, reworks the logic
so we call drmSetMaster() and then check drmIsMaster(), rather
then failing due to the return value.

With this patch, things are back to working on both hikey960
and db845c with 5.4 based kernels.

Signed-off-by: John Stultz <john.stultz@linaro.org>
Change-Id: I7f2adba3ddbd36169b6d26baf49299046efcf906

3 years agodrm_hwcomposer: Initial composer@2.4 HAL support
Roman Stratiienko [Sun, 27 Sep 2020 19:48:08 +0000 (22:48 +0300)]
drm_hwcomposer: Initial composer@2.4 HAL support

Enough to boot Android with composer@2.4 enabled.

VTS at this point:
============================================
================= Results ==================
    arm64-v8a VtsHalGraphicsComposerV2_4TargetTest: 34s
    armeabi-v7a VtsHalGraphicsComposerV2_4TargetTest: 31s
=============== Summary ===============
2/2 modules completed
Total Tests       : 46
PASSED            : 44
FAILED            : 2
============================================

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: Add support for color encoding and range properties
Matvii Zorin [Tue, 8 Sep 2020 13:12:51 +0000 (16:12 +0300)]
drm_hwcomposer: Add support for color encoding and range properties

Starting from the linux-v4.17, the DRM module has support for different
non-RGB color encodings that are controlled through plane-specific
COLOR_ENCODING and COLOR_RANGE properties.

This patch creates a matching between the HWC layer dataspace which is
supported by DRM driver and DRM plane properties.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
3 years agodrm_hwcomposer: Add minigbm video and format_modifier support
Roman Stratiienko [Sun, 13 Dec 2020 15:41:04 +0000 (17:41 +0200)]
drm_hwcomposer: Add minigbm video and format_modifier support

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: Support unique fd for every YUV plane
Roman Stratiienko [Fri, 8 Jan 2021 16:30:31 +0000 (18:30 +0200)]
drm_hwcomposer: Support unique fd for every YUV plane

Fixes video playback on DEVICE while using minigbm gralloc[0,3,4],
and other grallocs that have more than 1 prime_fd for YUV buffers.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: Ensure composer has master access to DRM/KMS
Roman Stratiienko [Wed, 13 Jan 2021 08:32:04 +0000 (10:32 +0200)]
drm_hwcomposer: Ensure composer has master access to DRM/KMS

Allocator service is always loaded before Composer service.
Kernel will assign master access to the first client that
opened /dev/dri/cardX node.

Allocator should immediately execute drmDropMaster() to
allow Composer service to acquire master privileges.

If this does not happen, the composer should gracefully exit,
otherwise a lot of DRM ioctls will fail without displaying anything
on the UI.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: Reorganize modifiers handling logic
Roman Stratiienko [Fri, 20 Nov 2020 14:21:55 +0000 (16:21 +0200)]
drm_hwcomposer: Reorganize modifiers handling logic

Reasons for this change:
1. Remove redundant code lines.
2. Workaround for cases when DRM_FORMAT_MOD_INVALID is set by gralloc.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: libdrmgetter: fix RGB565 format translation
Roman Stratiienko [Fri, 30 Oct 2020 11:53:00 +0000 (13:53 +0200)]
drm_hwcomposer: libdrmgetter: fix RGB565 format translation

FOSS graphic components (gbm_gralloc, mesa3d) are translating
HAL_PIXEL_FORMAT_RGB_565 to DRM_FORMAT_RGB565 without swapping
the R and B components. Same must be done here.

Fixes wrong colors in some games (i.e. Pixel Wheels).

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: check ConvertBoInfo errors before importing
Jason Macnak [Mon, 2 Nov 2020 15:04:11 +0000 (07:04 -0800)]
drm_hwcomposer: check ConvertBoInfo errors before importing

Signed-off-by: Jason Macnak <natsu@google.com>
3 years agodrm_hwcomposer: implement Gralloc 4 BufferInfoMapperMetadata
Dennis Tsiang [Fri, 30 Oct 2020 08:43:33 +0000 (08:43 +0000)]
drm_hwcomposer: implement Gralloc 4 BufferInfoMapperMetadata

Implements the BufferInfoMapperMetadata that uses the
GraphicBufferMapper to set the fields of the hwc_drm_bo_t struct.

New class function GetFds created to obtain the file descriptors from
the native_handle_t. Function is marked weak so that vendors can
override it to match their system if required.

Change-Id: I74445487dec6bda2915b21f4b63804832bfead23
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Reviewed-by: Roman Stratiienko <r.stratiienko@gmail.com>
3 years agodrm_hwcomposer: stop using pixel_stride
Roman Stratiienko [Fri, 23 Oct 2020 19:28:38 +0000 (22:28 +0300)]
drm_hwcomposer: stop using pixel_stride

pixel_stride is used only to validate buffer when importing using
GraphicBufferMapper::importBuffer() method.

The problem is we can't always get this value from buffer_handle_t.
Libdrm and MapperMetadata getters can only calculate this value based
on byte stride and buffer format. But this calculation isn't always
possible, which causes importBuffer() to fail.

Instead we can use GrallocMapper::importBuffer() method,
which doesn't require to validate the buffer.

This commit is not compatible with Android-P.

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