drm_hwcomposer: Add blocking SetConfig
Config changes within the same config group are intended to change
the refresh rate and are expected to be seamless, and as such are queued
up to be applied along with other frame updates such as pageflips. These
commits ought not to result in a full modeset.
For config changes that go between config groups, there might be visible
artifacts (modesets).
Introduce HwcDisplay::SetConfig to implement support for changing
between config groups. Config changes that are expected to be seamless
and not introduce jank or other visual artifacts should continue to go
through HwcDisplay::QueueConfig.
Since there may not be an appropriate client buffer available for the
initial SetConfig, allocate a CPU-writable buffer for scanout that can
be used for the first commit. The buffer can be destroyed after the
next frame is presented.
Change-Id: I48a87a070130dd2328f415719032486d9659c5b6
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/hwc3/ComposerClient.cpp b/hwc3/ComposerClient.cpp
index dca118f..47ffc7e 100644
--- a/hwc3/ComposerClient.cpp
+++ b/hwc3/ComposerClient.cpp
@@ -1081,13 +1081,36 @@
return ToBinderStatus(hwc3::Error::kBadDisplay);
}
- ::QueuedConfigTiming timing{};
- HwcDisplay::ConfigError
- result = display->QueueConfig(config, constraints.desiredTimeNanos,
- constraints.seamlessRequired, &timing);
- timeline->newVsyncAppliedTimeNanos = timing.new_vsync_time_ns;
- timeline->refreshTimeNanos = timing.refresh_time_ns;
- timeline->refreshRequired = true;
+ if (constraints.seamlessRequired) {
+ return ToBinderStatus(hwc3::Error::kSeamlessNotAllowed);
+ }
+
+ const bool future_config = constraints.desiredTimeNanos >
+ ::android::ResourceManager::GetTimeMonotonicNs();
+ const HwcDisplayConfig* current_config = display->GetCurrentConfig();
+ const HwcDisplayConfig* next_config = display->GetConfig(config);
+ const bool same_config_group = current_config != nullptr &&
+ next_config != nullptr &&
+ current_config->group_id ==
+ next_config->group_id;
+ // If the contraints dictate that this is to be applied in the future, it
+ // must be queued. If the new config is in the same config group as the
+ // current one, then queue it to reduce jank.
+ HwcDisplay::ConfigError result{};
+ if (future_config || same_config_group) {
+ QueuedConfigTiming timing = {};
+ result = display->QueueConfig(config, constraints.desiredTimeNanos,
+ constraints.seamlessRequired, &timing);
+ timeline->newVsyncAppliedTimeNanos = timing.new_vsync_time_ns;
+ timeline->refreshTimeNanos = timing.refresh_time_ns;
+ timeline->refreshRequired = true;
+ } else {
+ // Fall back to a blocking commit, which may modeset.
+ result = display->SetConfig(config);
+ timeline->newVsyncAppliedTimeNanos = ::android::ResourceManager::
+ GetTimeMonotonicNs();
+ timeline->refreshRequired = false;
+ }
switch (result) {
case HwcDisplay::ConfigError::kBadConfig: