1
0
Fork 0

drm_hwcomposer: Update FlatteningController behavior

Under the previous behavior, NewFrame both updated the internal state
tracking to indicate that the scene is not idle, as well as returning a
bool to indicate whether the scene should be flattened or not.
ShouldFlatten was not being used, and would return `true` during the
interval between the refresh callback being triggered and the next
NewFrame, which would be in response to the refresh callback. Subsequent
calls to ShouldFlatten would return `false` even though the scene
remains idle.

This commit updates NewFrame to only update the internal state. Callers
should call ShouldFlatten to check whether the controller has detected
that the scene should be flattened.

After the callback is triggered, ShouldFlatten returns true. It will
continue to return true after the first NewFrame, which would be in
response to the refresh callback. Subsequent NewFrame calls will reset
the idle detection.

Change-Id: I8b11a55bb6b101bb2ce473a844f5b9795a027956
This commit is contained in:
Drew Davenport 2025-09-16 14:46:30 -06:00
parent ce65d6c6e3
commit 2432cb0dfa
3 changed files with 18 additions and 12 deletions

View file

@ -51,15 +51,16 @@ FlatteningController::FlatteningController(FlatConCallbacks callbacks,
}
/* Compositor should call this every frame */
bool FlatteningController::NewFrame() {
void FlatteningController::NewFrame() {
bool wake_it = false;
auto lock = std::lock_guard<std::mutex>(mutex_);
if (flatten_next_frame_) {
flatten_next_frame_ = false;
return true;
return;
}
should_flatten_ = false;
sleep_until_ = std::chrono::system_clock::now() + timeout_;
if (disabled_) {
wake_it = true;
@ -68,8 +69,6 @@ bool FlatteningController::NewFrame() {
if (wake_it)
cv_.notify_all();
return false;
}
void FlatteningController::ThreadFn() {
@ -81,6 +80,7 @@ void FlatteningController::ThreadFn() {
if (sleep_until_ <= std::chrono::system_clock::now() && !disabled_) {
disabled_ = true;
flatten_next_frame_ = true;
should_flatten_ = true;
ALOGV("Timeout. Sending an event to compositor");
cbks_.trigger();
}

View file

@ -40,17 +40,22 @@ class FlatteningController {
thread_.join();
}
// Disable flattening and stop checking for an idle scene.
void Disable() {
auto lock = std::lock_guard<std::mutex>(mutex_);
flatten_next_frame_ = false;
should_flatten_ = false;
disabled_ = true;
}
/* Compositor should call this every frame */
bool NewFrame();
// Registers a new frame by updating the flattening state as needed and
// resetting the idle timer.
void NewFrame();
// Returns true if the FlatteningController detects that the scene is idle
// and should be flattened by the compositor.
auto ShouldFlatten() const {
return flatten_next_frame_;
return should_flatten_;
}
void StopThread() {
@ -70,6 +75,7 @@ class FlatteningController {
* https://cs.android.com/android/platform/superproject/main/+/cedca652b903e4f4e584e457b5a7038e0825fb94:hardware/interfaces/graphics/composer/aidl/vts/VtsComposerClient.cpp;drc=a2a6deaf5036e081f48379b6573db4465538b5ac;l=604
*/
bool flatten_next_frame_ = false;
bool should_flatten_ = false;
bool disabled_ = true;
decltype(std::chrono::system_clock::now()) sleep_until_{};
std::thread thread_;