1
0
Fork 0
Commit graph

53 commits

Author SHA1 Message Date
Andrew Wolfers
5a9cc2cba3 Cleanup includes in drm/ per IWYU style
Change-Id: I613cb6656d887aab5221be3d3b2923f1f4ba9ab9
2025-11-11 19:14:37 +00:00
Andrew Wolfers
185f909299 Cleanup includes in compositor/ per IWYU style
Change-Id: I4362a5ff4228b1a30812ec564f6a0c81e1f5cf08
2025-11-11 19:14:32 +00:00
Andrew Wolfers
ee0b06e40c drm_hwcomposer: Preserve cursor scaling during commit
This change modifies cursor behavior during atomic commit
so that the scaling factor is preserved. Previously, the
src rect was being overwritten to match the dimensions of
the dst rect, because it was assumed that scaling is not
permitted with the cursor plane. The new behavior will
preserve any existing scaling factor while resizing the
src rect. For hardware that cannot use scaling on the
cursor plane, this behavior should now be caught during
test commit, and trigger the appropriate fallback. For
hardware that can use scaling on the cursor plane, the
behavior is fixed such that the cursor will now appear
with the correct sizing.

Change-Id: I1d3e01441bdc5d7076b15d66b1a7a1a498ea64a9
2025-09-11 13:17:00 +00:00
Andrew Wolfers
2261f81762 drm_hwcomposer: Add Rect utility type
This change refactors the IRect and FRect types into a single
templated type Rect<T>, which allows the implementation to be
shared across both variants. This change also adds convenience
getters for the rect widths and heights, and updates callsites
accordingly.

Change-Id: I38509631d57706266186a7b7fa21bd43c0860890
2025-09-10 13:41:51 +00:00
Andrew Wolfers
9255d0d10b drm_hwcomposer: Migrate to android::drm_hwcomposer namespace
Change-Id: I2859aa8f55532d88231389724956fc77b0625339
2025-09-08 18:53:00 +00:00
Andrew Wolfers
9e75410677 drm_hwcomposer: Fix cursor positioning
In some cases, the position of the cursor is controlled by the src rect.
For example, this is done when the cursor extends beyond the top or left
edges of the screen. This is not compatible with the hw cursor plane
however, because scaling and panning are both disallowed. As a workaround,
the position of the dst rect needs to be adjusted in the opposite
direction (in some cases taking a negative-valued position,) which
will correctly position the cursor while also assigning an acceptible
value to the src rect.

Change-Id: Ide7f75e01481bcd602a33d222d1ae6862703a1cd
2025-08-28 17:32:50 +00:00
Drew Davenport
4a84e27035 drm_hwcomposer: Make HwcLayer const in Backend
Backend shouldn't directly mutate HwcLayer state, so make HwcLayer
const. Make a few other related functions const correct as well.

Change-Id: Id7f8e255e9e72b756399b1a4dabc3db779d64bc9
2025-08-19 09:16:22 -06:00
Andrew Wolfers
f35210964c drm_hwcomposer: Remove cursor buffor validity check
This change removes a check in DrmPlane::IsValidForLayer which would
verify that the buffer size matches known accepted values from the
DRM_CAP_CURSOR or SIZE_HINTS properties. Those properties are required
to return valid buffer sizes for committing to the cursor plane, but
they are not meant to be exhaustive. As a result, this check was
returning false negatives, and forcing the cursor into client
composition unnecessarily. The intended usage is that these props
should be checked during buffer allocation, not during composition.
Instead, test commits are sufficient for detecting whether a buffer
is valid for the cursor plane, and triggering fallback logic as needed.

Change-Id: Iae14436a6f50e45a113a4d18de67e73810b2a83e
Signed-off-by: Andrew Wolfers <aswolfers@google.com>
2025-06-20 15:43:33 +00:00
Andrew Wolfers
6fa3500c7f drm_hwcomposer: Commit damage
This change adds per-plane damage info to atomic commit.

Change-Id: I55e6285a0b83fac6342fd736342b3950c488b508
Signed-off-by: Andrew Wolfers <aswolfers@google.com>
2025-04-09 15:08:46 +00:00
Drew Davenport
1629293792 drm_hwcomposer: Clip sourceCrop to buffer size
drm atomic test will fail if the source crop exceeds the size of the
buffer. This case could happen due to bugs in surfaceflinger.

To avoid an atomic test failure leading to scene flattening, check the
source crop before configuring the drm properties.

Change-Id: Ife33af8cd0dd0983ae9278945d653043a29e649d
Signed-off-by: Drew Davenport <ddavenport@google.com>
2025-04-03 11:54:59 -06:00
Andrew Wolfers
e5ca88ba86 drm_hwcomposer: Add adjustments for cursor plane commits
This change adds special handling for buffers that may be committed to the
cursor plane. Some drivers may enforce size constraints on cursor plane
commits, which can be satisfied by padding the buffer beyond its nominal
width and height. This change adds behavior to extract that padding
(i.e. the aligned dimensions) by analyzing the buffer pitch, size, and
format.

When the cursor usage flag is set on a buffer, the aligned dimensions
should be used in place of the nominal dimensions for creating the
framebuffer, checking compatibility to the cursor plane, and for setting
the display and crop rects during commit.

Change-Id: I1cc2aa2f9cd23173cae87ae6e486c3b140b78ad5
Signed-off-by: Andrew Wolfers <aswolfers@google.com>
2025-03-14 13:33:39 +00:00
Andrew Wolfers
45cb3e847e drm_hwcomposer: Cursor plane buffer validation
This change adds a check to DrmPlane::IsValidForLayer which
checks cursor-plane-specific requirements that the layer's
buffer has an acceptable size according to either the plane's
SIZE_HINTS or the device's DRM_CAP_CURSOR_{WIDTH|HEIGHT}
properties.

Change-Id: Ic88699996c6616e8da7a4527b03a12c12422fb8f
Signed-off-by: Andrew Wolfers <aswolfers@google.com>
2025-02-27 14:52:51 +00:00
Andrew Wolfers
bf7d29a7a3 drm_hwcomposer: Add SIZE_HINTS property to DrmPlane
This change reads and parses the SIZE_HINTS drm plane property. Once
parsed successfully, the size hints indicate recommended sizes to
use with cursor planes, in order of preference [1]. The property is
not populated on planes which do not have DRM_PLANE_TYPE_CURSOR.

[1] https://drmdb.emersion.fr/properties/4008636142/SIZE_HINTS

Change-Id: Ia98a45ab5f279573f61394a357eccc90952528c5
Signed-off-by: Andrew Wolfers <aswolfers@google.com>
2025-02-27 14:19:10 +00:00
Andrew Wolfers
c88294c89d drm_hwcomposer: Fix DrmPlane typos
This change resolves mispellings in DrmPlane.

Change-Id: I0eaa8963bbb24c3faa800b4cb31645ab78c0d7d3
Signed-off-by: Andrew Wolfers <aswolfers@google.com>
2025-02-14 13:37:11 +00:00
Andrew Wolfers
fdd437193f drm_hwcomposer: Fix alpha check
This change fixes a check which determines whether a layer's alpha
is set to opaque. The PresentInfo::alpha property was recently
converted to float, but the check in DrmPlane::IsValidForLayer was
still comparing it to the integer value.

Change-Id: Ie1a8304d7302d1d646d0542be92795e93f57e0d9
Signed-off-by: Andrew Wolfers <aswolfers@google.com>
2025-02-11 21:18:48 +00:00
Roman Stratiienko
fb9fed5389 drm_hwcomposer: Use float type to store alpha internally
0.0-1.0F range is a natural way to store alpha value internally,
to be converted later to DRM-specific 0-0xFFFF fixed point type at
DRM layer.

Change-Id: Iedf2b11e53bf38efd08cd4eda1346647b9ff721f
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2025-02-05 22:39:35 +02:00
Roman Stratiienko
4e15bfc948 drm_hwcomposer: Support default values for Rect structures
This commit introduces two improvements:
1. Introduces frontend-agnostic structures for rects.
2. Support default values in them so that the backend can handle
   cases where rects are not specified by the client, like
   the client layer display frame, etc.
   This reduces the complexity of the Internal layer, making it
   feasible to use a single Frontend<->Internal layer API for
   regular layers, as well as for the Client and Output layers.

Change-Id: Iab5030ad523d36ea4c5af142f6f628952467d6ab
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2025-02-05 22:39:35 +02:00
Roman Stratiienko
da2fcf6676 drm_hwcomposer: Simplify LayerTransform
Fixes clang-analyzer-optin.core.EnumCastOutOfRange clang tidy check.

Change-Id: I0a88d1ef084848c924198e8bd3831533b6578675
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2025-01-24 23:33:35 +02:00
Sean Paul
634c89ccc0 drm_hwcomposer: Remove unnecessary warning
When mirroring, this message spams the logs since we loop over the
device planes for multiple CRTCs and print this message for the primary
planes of each active CRTC.

The case this is avoiding (avoid sharing primary planes) is still valid,
afaict, so leave the return statement.

Change-Id: I14afce4918baa5652ec16a3610fe374cccf72422
Signed-off-by: Sean Paul <seanpaul@chromium.org>
2024-10-24 19:25:51 +00:00
Sean Paul
468a7548bf drm_hwcomposer: Replace LOG_TAG with drmhwc
It's a pain to use logcat filters for drm_hwcomposer since each file has a different tag necessitating one to specify each tag for the logcat filter or use a regex.

Use one tag for all of drm_hwcomposer to simplify this.

Signed-off-by: Sean Paul <seanpaul@chromium.org>
2024-07-19 17:42:41 +00:00
Roman Stratiienko
b9bd2712fb drm_hwcomposer: Fix DRM and HWC rotation direction misalignment
[DRM API][1] uses a counter-clockwise direction, while [HWC API][2] uses
a clockwise.

[1]: https://elixir.bootlin.com/linux/v6.5.7/source/include/uapi/drm/drm_mode.h#L172
[2]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/libhardware/include_all/hardware/hwcomposer_defs.h;l=96;drc=e9d7337d9d1edc0d8e3ece246ecde747e345e876
Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/78
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2023-10-15 02:16:45 +03:00
Roman Stratiienko
76892784ac drm_hwcomposer: Introduce SharedFd, use standard c++ RAII for UniqueFd
We use too much dup() system calls for present fence propagating.
Also when propagating acquire fence we use additional logic for
skipping such propagation for the validate/test cycle.

Both issues can be solved by introducing SharedFd, which will track
reference count of fd object.

After that the UniqueFd is used very rarely and can be simplified by
wrapping it into std::unique_ptr without caring too much of adding
an extra malloc/free operation.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2023-01-16 20:13:58 +02:00
Roman Stratiienko
abd8e534d9 drm_hwcomposer: Rework DrmProperty class
Simplify code and raise-up clang-tidy level of DrmProperty class
to 'normal'.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2022-12-11 21:19:43 +02:00
Roman Stratiienko
a7913de518 drm_hwcomposer: CI: Bump-up clang toolchain to v15
Address new clang-tidy findings, in most cases 'misc-const-correctness'
check was addressed by adding 'const' modifier, or in some cases changed
to 'auto' (where it's better for formatting).

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2022-10-20 14:14:33 +03:00
Yongqin Liu
7ee6a9ea6b drm_hwcomposer: check if the primary plane is being used by any crtc
Some DRM driver such as omap_drm allow sharing primary plane between CRTCs.
drm_hwcomposer isn't ready for such a scenarios and fails with an error:

    Found more than 1 primary plane for CRTC

Don't report multiple primary planes for single CRTC to satisfy the drm_hwc.

Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2022-09-09 00:09:16 +08:00
Roman Stratiienko
4b2cc484f9 drm_hwcomposer: Reorganize struct DrmHwcLayer
1. Move BlendMode, ColorSpace, SampleRange fields to the struct BufferInfo,
   allowing extraction of the data from native_handle using Metadata@4 API.
   Use it when data from HWC2 API can't be used (Currently it's a BlendMode
   case for CLIENT layer)

2. Rename DrmHwcLayer to LayerData and move it to compositor/ directory.
   (I was confused in the past because of similarity of names DrmHwcLayer
    vs HwcLayer, so this step should meke it easier for newcomers to
    understand the code)

3. Allow clonning of the LayerData to propagate it through the composition
   pipeline. Thus LayerData can be used by both HwcLayer to track state
   and by the compositor.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2022-05-17 11:20:44 +03:00
Roman Stratiienko
e9fbd8d626 drm_hwcomposer: Set return type to std::optional for BufferInfoGetters
This is a bit of code modernization. Further changes will require indication
that buffer_info is valid, and using std::optional is the most correct
approach to do that.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2022-05-17 10:35:29 +03:00
Roman Stratiienko
7d89911c32 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>
2022-01-31 21:48:40 +02:00
Roman Stratiienko
10be875de0 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>
2022-01-31 21:31:32 +02:00
Roman Stratiienko
b671fab16a 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>
2022-01-31 21:31:31 +02:00
Roman Stratiienko
f815d38c2a drm_hwcomposer: Raise clang-tidy level of some files to NORMAL
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2022-01-12 10:47:23 +02:00
Roman Stratiienko
57b9ba3a7d 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>
2022-01-12 10:47:23 +02:00
Roman Stratiienko
fc014f5792 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>
2022-01-12 10:33:55 +02:00
Roman Stratiienko
0b06388081 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>
2021-10-23 04:47:33 +03:00
Roman Stratiienko
013d068198 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: 5063d53ddf ("drm_hwcomposer: Improve handling of blending mode")
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
2021-10-23 04:47:33 +03:00
Roman Stratiienko
24a4c180c2 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>
2021-09-29 12:59:54 +03:00
Roman Stratiienko
0f679aadfe 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>
2021-09-29 12:59:48 +03:00
Roman Stratiienko
6662f71844 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>
2021-09-29 12:52:22 +03:00
Roman Stratiienko
5063d53ddf 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>
2021-09-29 12:47:31 +03:00
Roman Stratiienko
4f1effa2d6 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>
2021-09-29 12:47:26 +03:00
Roman Stratiienko
515da8f626 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>
2021-09-29 12:47:21 +03:00
Roman Stratiienko
0dbe639438 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>
2021-09-29 12:47:16 +03:00
Roman Stratiienko
5128715b42 drm_hwcomposer: cleanup hwcutils
Remove DrmHwcBuffer class. Wrap remaining logic into
DrmHwcLayer class.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2021-05-19 19:31:29 +03:00
Benjamin Li
f75099aa93 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>
2021-05-09 08:53:09 -07:00
Benjamin Li
b00b28d1e7 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>
2021-05-09 08:52:18 -07:00
Matvii Zorin
67a89d33b8 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>
2021-04-06 12:46:22 +03:00
Roman Stratiienko
2640cd88d1 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>
2021-03-03 16:12:22 +02:00
Roman Stratiienko
b3b5c1e937 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>
2021-03-03 16:12:22 +02:00
Roman Stratiienko
e2f2c92924 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>
2021-03-03 16:07:25 +02:00
Roman Stratiienko
d518a0594a 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>
2021-03-03 12:14:13 +02:00