refactor(display): refactor auto brightness logic - #1189
Conversation
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 Display1’s auto brightness to consume recommendations from AmbientBrightness1, replaces the old sensor/curve/transition stack with a single deterministic transition engine, and moves power‑saving brightness scaling into Display1 while keeping persisted brightness values unscaled, with tests and docs for the new architecture. Sequence diagram for automatic brightness recommendation and manual overridesequenceDiagram
participant AmbientBrightness1
participant RecommendationClient
participant AutoBrightnessManager
participant BrightnessTransition
participant DisplayManager
AmbientBrightness1->>RecommendationClient: PropertiesChanged(Enabled,State,RecommendedBrightness)
RecommendationClient->>AutoBrightnessManager: onAmbientBrightnessStateChanged(state)
AutoBrightnessManager->>AutoBrightnessManager: applyRecommendedBrightness()
AutoBrightnessManager->>DisplayManager: getBuiltinMonitor()
AutoBrightnessManager->>DisplayManager: getBrightnessScale()
AutoBrightnessManager->>BrightnessTransition: Run(current,target)
BrightnessTransition->>DisplayManager: setBrightnessAndSync(name,value)
BrightnessTransition-->>AutoBrightnessManager: onTransitionComplete(target)
AutoBrightnessManager->>DisplayManager: saveBrightnessInCfg(name: recommendedBrightness)
actor User
User->>DisplayManager: SetAndSaveBrightness(name,value)
DisplayManager->>AutoBrightnessManager: DisableForManualAdjustment()
AutoBrightnessManager->>BrightnessTransition: Stop()
AutoBrightnessManager->>AmbientBrightness1: Enable(false)
AmbientBrightness1->>RecommendationClient: PropertiesChanged(Enabled)
RecommendationClient->>AutoBrightnessManager: onAmbientBrightnessStateChanged(state)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
a1ef6bd to
a69b144
Compare
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
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // display1/recommendation_client.go
// 修复结构体比较导致的 NaN 问题,改为逐字段比较
// 在 RecommendationClient 中添加状态比较方法
func (s RecommendationState) equals(other RecommendationState) bool {
if s.Available != other.Available ||
s.Enabled != other.Enabled ||
s.Supported != other.Supported ||
s.State != other.State {
return false
}
// 处理浮点数比较,包括 NaN 情况
if math.IsNaN(s.RecommendedBrightness) && math.IsNaN(other.RecommendedBrightness) {
return true
}
if s.RecommendedBrightness != other.RecommendedBrightness {
return false
}
return true
}
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()
}
}
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
}
}
// 使用自定义的 equals 方法替代 ==
if state.equals(c.state) {
c.mu.Unlock()
return
}
c.state = state
callback := c.callback
c.mu.Unlock()
if callback != nil {
callback(state)
}
}
// 同样修改 setState 方法
func (c *RecommendationClient) setState(state RecommendationState) {
c.mu.Lock()
if state.equals(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 automatic brightness control around AmbientBrightness1 recommendations and Display1 arbitration, simplify the brightness transition mechanism, and move power-saving brightness scaling into Display1 while removing legacy sensor and curve-based logic.
New Features:
Enhancements:
Documentation:
Tests:
Chores: