• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.display.config;
18 
19 import android.annotation.Nullable;
20 
21 import com.android.internal.annotations.VisibleForTesting;
22 
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 
27 /**
28  * Brightness config for HDR content
29  */
30 public class HdrBrightnessData {
31 
32     /**
33      * Lux to brightness map
34      */
35     public final Map<Float, Float> mMaxBrightnessLimits;
36 
37     /**
38      * Debounce time for brightness increase
39      */
40     public final long mBrightnessIncreaseDebounceMillis;
41 
42     /**
43      * Brightness increase animation speed
44      */
45     public final float mScreenBrightnessRampIncrease;
46 
47     /**
48      * Debounce time for brightness decrease
49      */
50     public final long mBrightnessDecreaseDebounceMillis;
51 
52     /**
53      * Brightness decrease animation speed
54      */
55     public final float mScreenBrightnessRampDecrease;
56 
57     @VisibleForTesting
HdrBrightnessData(Map<Float, Float> maxBrightnessLimits, long brightnessIncreaseDebounceMillis, float screenBrightnessRampIncrease, long brightnessDecreaseDebounceMillis, float screenBrightnessRampDecrease)58     public HdrBrightnessData(Map<Float, Float> maxBrightnessLimits,
59             long brightnessIncreaseDebounceMillis, float screenBrightnessRampIncrease,
60             long brightnessDecreaseDebounceMillis, float screenBrightnessRampDecrease) {
61         mMaxBrightnessLimits = maxBrightnessLimits;
62         mBrightnessIncreaseDebounceMillis = brightnessIncreaseDebounceMillis;
63         mScreenBrightnessRampIncrease = screenBrightnessRampIncrease;
64         mBrightnessDecreaseDebounceMillis = brightnessDecreaseDebounceMillis;
65         mScreenBrightnessRampDecrease = screenBrightnessRampDecrease;
66     }
67 
68     @Override
toString()69     public String toString() {
70         return "HdrBrightnessData {"
71                 + "mMaxBrightnessLimits: " + mMaxBrightnessLimits
72                 + ", mBrightnessIncreaseDebounceMillis: " + mBrightnessIncreaseDebounceMillis
73                 + ", mScreenBrightnessRampIncrease: " + mScreenBrightnessRampIncrease
74                 + ", mBrightnessDecreaseDebounceMillis: " + mBrightnessDecreaseDebounceMillis
75                 + ", mScreenBrightnessRampDecrease: " + mScreenBrightnessRampDecrease
76                 + "} ";
77     }
78 
79     /**
80      * Loads HdrBrightnessData from DisplayConfiguration
81      */
82     @Nullable
loadConfig(DisplayConfiguration config)83     public static HdrBrightnessData loadConfig(DisplayConfiguration config) {
84         HdrBrightnessConfig hdrConfig = config.getHdrBrightnessConfig();
85         if (hdrConfig == null) {
86             return null;
87         }
88 
89         List<NonNegativeFloatToFloatPoint> points = hdrConfig.getBrightnessMap().getPoint();
90         Map<Float, Float> brightnessLimits = new HashMap<>();
91         for (NonNegativeFloatToFloatPoint point: points) {
92             brightnessLimits.put(point.getFirst().floatValue(), point.getSecond().floatValue());
93         }
94 
95         return new HdrBrightnessData(brightnessLimits,
96                 hdrConfig.getBrightnessIncreaseDebounceMillis().longValue(),
97                 hdrConfig.getScreenBrightnessRampIncrease().floatValue(),
98                 hdrConfig.getBrightnessDecreaseDebounceMillis().longValue(),
99                 hdrConfig.getScreenBrightnessRampDecrease().floatValue());
100     }
101 }
102