refactor(display): refactor auto brightness logic - #1192
Conversation
1. Use AmbientBrightness1 as the recommendation source and let Display1 arbitrate automatic and manual brightness updates. 2. Refactor brightness transitions to support target updates and deterministic cancellation. 3. Move power-saving brightness scaling to Display1 while keeping persisted brightness values unscaled. 4. Remove the obsolete sensor, filtering, curve, and power-saving dimming logic from Display1 and session/power1. 5. Remove dde-daemon's iio-sensor-proxy recommendation because sensor access is now owned by AmbientBrightness1. 6. Add regression tests and documentation for the new brightness architecture. Log: Refactor auto brightness logic and centralize brightness arbitration in Display1. Influence: 1. Verify automatic brightness follows recommendations from AmbientBrightness1. 2. Verify manual brightness changes stop automatic transitions and disable automatic adjustment. 3. Verify power-saving scaling affects hardware brightness without changing persisted values. 4. Verify brightness transitions can update targets and stop cleanly. refactor(display): 重构自动亮度逻辑 1. 使用 AmbientBrightness1 提供推荐亮度,由 Display1 统一仲裁自动和手动亮度更新。 2. 重构亮度渐变逻辑,支持动态更新目标值和确定性停止渐变任务。 3. 将节能亮度缩放迁移到 Display1,同时保持持久化亮度值不受缩放影响。 4. 移除 Display1 和 session/power1 中陈旧的传感器、滤波、曲线及节能调光逻辑。 5. 光感访问已由 AmbientBrightness1 负责,因此移除 dde-daemon 对 iio-sensor-proxy 的推荐依赖。 6. 为新的亮度架构补充回归测试和设计文档。 Log: 重构自动亮度逻辑,由 Display1 统一仲裁亮度更新。 Influence: 1. 验证自动亮度能够正确应用 AmbientBrightness1 的推荐值。 2. 验证手动调节亮度时会停止自动渐变并关闭自动调节。 3. 验证节能缩放影响实际亮度,但不会修改持久化亮度值。 4. 验证亮度渐变能够动态更新目标并可靠停止。 PMS: BUG-372191
There was a problem hiding this comment.
Sorry @fly602, your pull request is larger than the review limit of 150000 diff characters
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideRefactors auto-brightness to consume recommendations from AmbientBrightness1, replaces the generic TransitionManager with a dedicated brightness transition state machine, and centralizes power-saving brightness scaling inside Display1 while removing legacy sensor and power-saving brightness logic from session/power1 and keybinding1. Sequence diagram for applying ambient recommendation and handling manual brightnesssequenceDiagram
actor User
participant Manager as Display1_Manager
participant Auto as AutoBrightnessManager
participant Client as RecommendationClient
participant Trans as BrightnessTransition
Client->>Client: Refresh()
Client-->>Auto: onAmbientBrightnessStateChanged(state)
Auto->>Manager: setPropAutoBrightnessEnabled(state.Enabled)
Auto->>Trans: applyRecommendedBrightness()
Trans->>Manager: setBrightnessAndSync(monitorName, scaledValue)
User->>Manager: SetAndSaveBrightness(outputName, value)
Manager->>Auto: prepareManualBrightnessChange()
Auto->>Trans: DisableForManualAdjustment()
Trans->>Trans: Stop()
Auto->>Client: Enable(false)
Client-->>Auto: onAmbientBrightnessStateChanged(disabledState)
Manager->>Manager: setBrightnessAndSync(outputName, value)
Manager->>Manager: saveBrightnessInCfg(map[outputName]value)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // display1/recommendation_client.go
// 将属性解析逻辑提取为独立方法,提升 handlePropertiesChanged 的可读性与可维护性
// applyChangedProperties 将 D-Bus 变更字典应用到状态副本上。
// 对所有外部输入进行严格类型检查,失败时记录警告并使用安全默认值。
func applyChangedProperties(state RecommendationState, changed map[string]dbus.Variant) RecommendationState {
if value, ok := changed["Enabled"]; ok {
enabled, validType := value.Value().(bool)
if !validType {
logger.Warningf("[AutoBrightness] Invalid Enabled property type %T", value.Value())
state.Enabled = false
} else {
state.Enabled = enabled
}
}
if value, ok := changed["State"]; ok {
stateName, validType := value.Value().(string)
if !validType {
logger.Warningf("[AutoBrightness] Invalid State property type %T", value.Value())
state.State = ""
} else {
state.State = stateName
}
}
if value, ok := changed["Supported"]; ok {
supported, validType := value.Value().(bool)
if !validType {
logger.Warningf("[AutoBrightness] Invalid Supported property type %T", value.Value())
state.Supported = false
} else {
state.Supported = supported
}
}
if value, ok := changed["RecommendedBrightness"]; ok {
recommended, validType := value.Value().(float64)
if !validType || !isValidRecommendedBrightness(recommended) {
logger.Warningf("[AutoBrightness] Invalid RecommendedBrightness value %v", value.Value())
state.RecommendedBrightness = math.NaN()
} else {
state.RecommendedBrightness = recommended
}
}
return state
}
// handlePropertiesChanged 处理推荐服务属性变化信号(重构后版本)
func (c *RecommendationClient) handlePropertiesChanged(interfaceName string,
changed map[string]dbus.Variant, invalidated []string) {
if interfaceName != ambientBrightnessInterface {
return
}
c.mu.Lock()
state := c.state
state.Available = true
for _, name := range invalidated {
switch name {
case "Enabled":
state.Enabled = false
case "State":
state.State = ""
case "Supported":
state.Supported = false
case "RecommendedBrightness":
state.RecommendedBrightness = math.NaN()
}
}
// 使用提取出的独立方法处理变更字典
state = applyChangedProperties(state, changed)
if state == c.state {
c.mu.Unlock()
return
}
c.state = state
callback := c.callback
c.mu.Unlock()
if callback != nil {
callback(state)
}
} |
Log: Refactor auto brightness logic and centralize brightness arbitration in Display1.
Influence:
refactor(display): 重构自动亮度逻辑
Log: 重构自动亮度逻辑,由 Display1 统一仲裁亮度更新。
Influence:
PMS: BUG-372191
Summary by Sourcery
Centralize auto-brightness arbitration in Display1 using AmbientBrightness1 recommendations, introduce a new deterministic brightness transition engine, and apply power-saving brightness scaling in Display1 without persisting scaled values.
Enhancements:
Documentation:
Tests: