1
0
Fork 0
Commit graph

38 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
Su Hong Koo
87ffe73cd7 drm_hwcomposer: Update VSyncWorker::last_timestamp_ on every present 2025-10-01 06:24:44 -06:00
Andrew Wolfers
9255d0d10b drm_hwcomposer: Migrate to android::drm_hwcomposer namespace
Change-Id: I2859aa8f55532d88231389724956fc77b0625339
2025-09-08 18:53:00 +00:00
Drew Davenport
6be6ee958d drm_hwcomposer: Use android-base/thread_annotations.h
This file already exists in android-base, so use this instead of
duplicating the macros in this project.

Since the copy in android-base provides a helper class to assist with
std::unique_lock, use that instead of disabling the warnings.

Change-Id: Ib1724045e3eea29946799fb99b3fbcfcc14a5013
2025-06-12 01:39:23 +00:00
Drew Davenport
609c353553 drm_hwcomposer: Add VSyncWorker::GetNextVsyncTimestamp
Add a function to approximate when the next vsync after a given
timestamp will be.

This can be used to support expectedPresentTime functionality to
determine if a pending property set should be committed immediately or
for a future vsync.

Change-Id: I6b1f0182d3416b0ffa361f54e6695b2894eb842a
Signed-off-by: Drew Davenport <ddavenport@google.com>
2025-03-14 11:38:40 -06:00
Drew Davenport
701a83cdba drm_hwcomposer: Remove redundant vsync timestamp
Vsync timestamp was being tracked in two values. One was used for
approximating the next timestamp when waiting for vblank failed, and the
other was used when vsync timestamp tracking was enabled.

Add a new bool to track whether a vsync has been recorded since a caller
enabled vsync timestamp tracking, and return the value of
vsync_timestamp_ if it is fresh.

Change-Id: I0129510d9ce7d72db8f1c64fa2178d2ce7836e81
Signed-off-by: Drew Davenport <ddavenport@google.com>
2025-02-21 10:51:42 -07:00
Drew Davenport
bf711ebeb6 drm_hwcomposer: Avoid resetting vsync timestamp
last_timestamp_ tracks the most recent timestamp from a vblank event. Do
not reset it when toggling vsync tracking on/off. This allows for
GetPhasedVSync to calculate a more precise approximation of the next
vsync relative to the current time, even if a vsync hasn't happened for
a while.

Reset last_timestamp_ when the vsync period changes, since the phased
vsync calculation is based on the current vsync.

Also change last_timestamp_ to std::optional type.

Change-Id: I101b36f87d6ba8197c321c83ac0bc230fba9cf7e
Signed-off-by: Drew Davenport <ddavenport@google.com>
2025-02-21 10:51:42 -07:00
Drew Davenport
35a395720a drm_hwcomposer: Use clang thread-safety analysis in VSyncWorker
See https://clang.llvm.org/docs/ThreadSafetyAnalysis.html for details.
Define thread annotation macros according to the example provided in the
documentation, and use these to annotate VSyncWorker members that can be
accessed from multiple threads.

Thread safety analysis does not yet work with std::unique_lock, so
disable the warnings when it is used.

Change-Id: I8b3b503fbaf0923588fbe3d0180f6fe6ec228350
Signed-off-by: Drew Davenport <ddavenport@google.com>
2025-02-21 10:51:42 -07:00
Drew Davenport
6bfccb83af drm_hwcomposer: Fix race conditions in VSyncWorker
vsync_period_ns_ and last_timestamp_ can be written to from both
threads, so ensure that they are protected by mutex_

Change-Id: Ifbfe0dcf057968fa27158c8a6f6edec186dbd5b4
Signed-off-by: Drew Davenport <ddavenport@google.com>
2025-02-21 10:51:42 -07:00
Roman Stratiienko
88bd6a2745 drm_hwcomposer: Enable readability-math-missing-parentheses tidy check
... and fix all related warnings.

Change-Id: Ic122235524e567f2be5040ae7742fefb531a9766
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2025-01-25 00:22:25 +02:00
Drew Davenport
30f4e9c593 drm_hwcomposer: Clean up VsyncWorker destruction
With VsyncWorker no longer acquiring the main lock, we can use
std:🧵:join on the main thread to ensure that the vsync thread is
stopped cleanly in the VSyncWorker destructor.

- Don't pass a shared_ptr<> into VSyncWorker::ThreadFn to simplify
  lifetime management
- Change to unique_ptr to simplify lifetime management
- Remove the hack to destroy the HwcDisplays in two stages when
  destructing ComposerClient
- Add std:🧵:join to VSyncWorker destructor

Change-Id: I25a34fd304c7b2ec48e43d538bf15794bdc9d68e
Signed-off-by: Drew Davenport <ddavenport@google.com>
2024-12-16 17:53:54 -07:00
Drew Davenport
15016c496c drm_hwcomposer: Remove VSyncWorkerCallbacks
This struct is no longer needed.

Change-Id: I85880d028c8d1931eeb964f10bccd94ee5fa3a5b
Signed-off-by: Drew Davenport <ddavenport@google.com>
2024-12-16 17:53:54 -07:00
Drew Davenport
b39a3f82f9 drm_hwcomposer: Enable VSyncWorker thread as needed
Rather than explicitly enabling and disabling the VSyncWorker thread
from HwcDisplay, move the logic to enable/disable the thread into
VSyncWorker, and enable it based on whether HwcDisplay has requested
vsync timeline events, or timeline tracking.

This simplifies the public interface for VSyncWorker, and removes the
need for holding the global lock to check whether the thread should be
enabled or not.

Change-Id: Ic1632a19b268ea1d4ed2d8ec8704ef531481211c
Signed-off-by: Drew Davenport <ddavenport@google.com>
2024-12-16 17:53:48 -07:00
Drew Davenport
63a699e14e drm_hwcomposer: Set vsync callback on demand
Set and clear a vsync callback based on when the client requests vsync
events to be enabled or not. The new vsync callback does not need to
acquire the global resource lock.

The vsync callback uses the vsync period that was set in the VSyncWorker
rather than querying it from the HwcDisplay.

Change-Id: Ic7868af4963ad40aa5a0982a190c67f1642d5b32
Signed-off-by: Drew Davenport <ddavenport@google.com>
2024-12-16 17:53:16 -07:00
Drew Davenport
33121b799a drm_hwcomposer: Move vsync tracking into VSyncWorker
Track the timestamp of the last vsync event in VSyncWorker, and provide
an interface for HwcDisplay to enable/disable tracking, and to query the
most recent timestamp.

Moving this into VSyncWorker avoids the need for the VSyncWorker thread
to acquire the global lock.

Change-Id: Ib79d9a6dc5e0f7d6a36ca01dbcda5434a0f582a4
Signed-off-by: Drew Davenport <ddavenport@google.com>
2024-12-16 17:53:16 -07:00
Drew Davenport
d387c84940 drm_hwcomposer: Simplify default vsync period
VSyncWorker::SetVsyncPeriod won't be called with a value of 0, so the
only time the internal vsync period will be zero is if SetVsyncPeriod
was not called.

Set the 60Hz vsync period as a default value, and let the synthetic
vsync code expect it to be set to a reasonable value.

Change-Id: Ie1f83b0c11504acf304cc241923bfa60a5ffd647
Signed-off-by: Drew Davenport <ddavenport@google.com>
2024-12-16 17:53:10 -07:00
Drew Davenport
5983318f17 drm_hwcomposer: Set vsync period for vsync thread
Make HwcDisplay set the VsyncWorker's vsync_period whenever it changes,
rather than having VsyncWorker query the vsync_period from HwcDisplay.

Doing so prevents the VsyncWorker thread from needing to acquire the
global lock to read HwcDisplay's state.

The original change called GetVsyncPeriod, which checks the vsync period
for the mode that is currently committed to the kernel based on
HwcDisplay::configs_.active_config_id, so call
VsyncWorker::SetVsyncPeriod whenever active_config_id is set.

Change-Id: Ie301c47e2496748117db8cca8a6ee9691e723c74
Signed-off-by: Drew Davenport <ddavenport@google.com>
2024-12-16 17:01:49 -07: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
63762a9d5d drm_hwcomposer: Use shared pointer type for the pipeline_ variable
The change will help with resource management in further patches.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2023-10-01 15:00:59 +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
d2cc73874c drm_hwcomposer: Rework VSyncWorker to work without utils/worker
utils/worker just complicates the logic without providing any benefit.

Change-Id: I7b3c91aee9c0507d9ca35792d24ba6c8c3870033
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2022-12-28 19:18:29 +02:00
Roman Stratiienko
df3120f9f3 drm_hwcomposer: Rework DrmMode class
Simplify code and raise-up clang-tidy level of DrmMode 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
Keith Mok
554743de46 drm_hwcomposer: Fix EINTR handling in clock_nanosleep
clock_nanosleep return errno directly
instead of -1 with errno set

Signed-off-by: Keith Mok <keithmok@google.com>
[jstultz: Fixed minor style issues]
Signed-off-by: John Stultz <jstultz@google.com>
Change-Id: I779f2a8234b3dae46d64efee2210b7a2c5a92043
2022-06-22 02:16:35 +00:00
Roman Stratiienko
19c162fe79 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>
2022-02-02 12:57:32 +02: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
650299a235 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>
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
780f7dacf9 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>
2022-01-20 17:21:46 +02:00
Roman Stratiienko
863a3c207e 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>
2021-09-29 13:00:29 +03:00
Roman Stratiienko
d26619b5d0 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>
2021-08-29 15:54:17 +03:00
Roman Stratiienko
d21071f7d5 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>
2021-04-06 12:12:17 +03: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
6a10c4ce1f drm_hwcomposer: clang-tidy: enable clang-analyzer-* checks
+ fixed existing tidy warnings for these checks.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2021-03-03 16:12:14 +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
Roman Stratiienko
2370109af7 drm_hwcomposer: Fix RegisterCallback() function
- Fixes segfault during client switch.
- Allows to run VTS on Android-11.

VTS Results:
============================================
    arm64-v8a VtsHalGraphicsComposerV2_1TargetTest: [53 tests / 42808 msec]
    armeabi-v7a VtsHalGraphicsComposerV2_1TargetTest: [53 tests / 33353 msec]
=============== Summary ===============
2/2 modules completed
Total Tests       : 106
PASSED            : 106
FAILED            : 0
============================================

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
2020-09-28 15:21:29 +03:00
Roman Stratiienko
13cc3666c6 drm_hwcomposer: use CamelCase in source/header files related to class
Main goal is to increase readability of file names.
AOSP uses camelcase for files in many projects.
Lets do the same for drm_hwcomposer.

Keep platform/ directory as is, since class names is different from file names.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Change-Id: I7e992357851c2a86711f4da1241c4d507359e56b
2020-09-08 22:34:52 +03:00
Renamed from drm/vsyncworker.cpp (Browse further)