Skip to content

Commit 4ca6a24

Browse files
committed
fix(vdd): handle mode change during deferred restore reuse
When cancelling a deferred restore to reuse VDD, check if the new session's vdd_prep mode differs from the previous one. If the mode changed, execute the full deferred restore first to clean up topology state, then start fresh — preventing stale topology metadata from the previous mode from causing issues.
1 parent 695c23d commit 4ca6a24

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

src/display_device/session.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,32 @@ namespace display_device {
338338
// VDD 已存在。如果有 deferred restore(grace period 内),取消它并复用 VDD。
339339
// 这是 Cancel 快速 Launch 切换应用的高效路径:VDD 不销毁不重建,persistent_data 有效,GUID 不变。
340340
if (deferred_restore_) {
341-
BOOST_LOG(info) << "VDD 延迟恢复取消:新串流到来,复用现有 VDD(GUID 不变)";
342-
deferred_restore_ = false;
343-
timer->setup_timer(nullptr);
344-
// persistent_data 仍然有效,不设置 pre_saved_initial_topology,让 apply_config 复用已有的
341+
// 检查新的 vdd_prep 是否与当前的相同
342+
// 如果模式变了(如 ensure_only_display → no_operation),persistent_data 中的拓扑记忆可能不匹配,
343+
// 此时需要先执行 deferred restore 恢复到干净状态,再重新配置。
344+
auto new_vdd_prep = static_cast<parsed_config_t::vdd_prep_e>(config.vdd_prep);
345+
if (session.custom_vdd_screen_mode != -1) {
346+
new_vdd_prep = static_cast<parsed_config_t::vdd_prep_e>(session.custom_vdd_screen_mode);
347+
}
348+
const auto old_vdd_prep = current_vdd_prep.value_or(new_vdd_prep);
349+
350+
if (new_vdd_prep == old_vdd_prep) {
351+
BOOST_LOG(info) << "VDD 延迟恢复取消:新串流到来,复用现有 VDD(GUID 不变,模式一致)";
352+
deferred_restore_ = false;
353+
timer->setup_timer(nullptr);
354+
// persistent_data 仍然有效,不设置 pre_saved_initial_topology,让 apply_config 复用已有的
355+
}
356+
else {
357+
BOOST_LOG(info) << "VDD 延迟恢复:模式变化(" << static_cast<int>(old_vdd_prep)
358+
<< " -> " << static_cast<int>(new_vdd_prep) << "),执行完整恢复后重新配置";
359+
deferred_restore_ = false;
360+
timer->setup_timer(nullptr);
361+
execute_deferred_restore(deferred_restore_reason_);
362+
// 执行完整恢复后,VDD 已销毁,需要重新创建
363+
// 保存当前拓扑作为新的初始拓扑
364+
pre_saved_initial_topology = get_current_topology();
365+
BOOST_LOG(debug) << "Pre-saved initial topology after full restore: " << to_string(*pre_saved_initial_topology);
366+
}
345367
}
346368
else if (pending_restore_ && settings.has_persistent_data()) {
347369
BOOST_LOG(info) << "有待恢复的设置且 VDD 仍存在,保留原有初始拓扑";

0 commit comments

Comments
 (0)