Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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; |
| 18 | |
Adrian Roos | 30f5321 | 2018-01-05 16:14:34 +0100 | [diff] [blame] | 19 | import android.app.ActivityThread; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 21 | import android.content.res.Resources; |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 22 | import android.hardware.sidekick.SidekickInternal; |
Griff Hazen | d3c454d | 2016-03-25 07:30:34 -0700 | [diff] [blame] | 23 | import android.os.Build; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 25 | import android.os.IBinder; |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 26 | import android.os.Looper; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 27 | import android.os.PowerManager; |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 28 | import android.os.SystemProperties; |
Jeff Brown | 3edf527 | 2014-08-14 19:25:14 -0700 | [diff] [blame] | 29 | import android.os.Trace; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 30 | import android.util.LongSparseArray; |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 31 | import android.util.Slog; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 32 | import android.util.SparseArray; |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 33 | import android.util.Spline; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 34 | import android.view.Display; |
Dominik Laskowski | db84596 | 2019-01-27 21:20:00 -0800 | [diff] [blame] | 35 | import android.view.DisplayAddress; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 36 | import android.view.DisplayCutout; |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 37 | import android.view.DisplayEventReceiver; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 38 | import android.view.SurfaceControl; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 39 | |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 40 | import com.android.internal.BrightnessSynchronizer; |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 41 | import com.android.internal.os.BackgroundThread; |
Riddle Hsu | 8b37bc0 | 2019-11-23 00:39:14 +0800 | [diff] [blame] | 42 | import com.android.internal.util.function.pooled.PooledLambda; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 43 | import com.android.server.LocalServices; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 44 | import com.android.server.lights.LightsManager; |
Ivailo Karamanolev | f773e10 | 2020-01-16 16:10:42 +0100 | [diff] [blame] | 45 | import com.android.server.lights.LogicalLight; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 46 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 47 | import java.io.PrintWriter; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 48 | import java.util.ArrayList; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 49 | import java.util.Arrays; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 50 | import java.util.Collections; |
| 51 | import java.util.List; |
Marin Shalamanov | 677d3a7 | 2020-01-07 13:45:55 +0100 | [diff] [blame] | 52 | import java.util.Objects; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 53 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 54 | /** |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 55 | * A display adapter for the local displays managed by SurfaceFlinger. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 56 | * <p> |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 57 | * Display adapters are guarded by the {@link DisplayManagerService.SyncRoot} lock. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 58 | * </p> |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 59 | */ |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 60 | final class LocalDisplayAdapter extends DisplayAdapter { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 61 | private static final String TAG = "LocalDisplayAdapter"; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 62 | private static final boolean DEBUG = false; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 63 | |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 64 | private static final String UNIQUE_ID_PREFIX = "local:"; |
| 65 | |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 66 | private static final String PROPERTY_EMULATOR_CIRCULAR = "ro.emulator.circular"; |
| 67 | |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 68 | private static final int NO_DISPLAY_MODE_ID = 0; |
| 69 | |
| 70 | private final LongSparseArray<LocalDisplayDevice> mDevices = new LongSparseArray<>(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 71 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 72 | @SuppressWarnings("unused") // Becomes active at instantiation time. |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 73 | private PhysicalDisplayEventReceiver mPhysicalDisplayEventReceiver; |
| 74 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 75 | |
Jeff Brown | 6669250 | 2012-10-18 16:13:44 -0700 | [diff] [blame] | 76 | // Called with SyncRoot lock held. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 77 | public LocalDisplayAdapter(DisplayManagerService.SyncRoot syncRoot, |
| 78 | Context context, Handler handler, Listener listener) { |
| 79 | super(syncRoot, context, handler, listener, TAG); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 83 | public void registerLocked() { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 84 | super.registerLocked(); |
Jeff Brown | 6669250 | 2012-10-18 16:13:44 -0700 | [diff] [blame] | 85 | |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 86 | mPhysicalDisplayEventReceiver = new PhysicalDisplayEventReceiver(getHandler().getLooper()); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 87 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 88 | for (long physicalDisplayId : SurfaceControl.getPhysicalDisplayIds()) { |
| 89 | tryConnectDisplayLocked(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 90 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 93 | private void tryConnectDisplayLocked(long physicalDisplayId) { |
| 94 | final IBinder displayToken = SurfaceControl.getPhysicalDisplayToken(physicalDisplayId); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 95 | if (displayToken != null) { |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 96 | SurfaceControl.DisplayInfo info = SurfaceControl.getDisplayInfo(displayToken); |
| 97 | if (info == null) { |
| 98 | Slog.w(TAG, "No valid info found for display device " + physicalDisplayId); |
| 99 | return; |
| 100 | } |
| 101 | SurfaceControl.DisplayConfig[] configs = SurfaceControl.getDisplayConfigs(displayToken); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 102 | if (configs == null) { |
| 103 | // There are no valid configs for this device, so we can't use it |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 104 | Slog.w(TAG, "No valid configs found for display device " + physicalDisplayId); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 105 | return; |
| 106 | } |
| 107 | int activeConfig = SurfaceControl.getActiveConfig(displayToken); |
| 108 | if (activeConfig < 0) { |
| 109 | // There is no active config, and for now we don't have the |
| 110 | // policy to set one. |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 111 | Slog.w(TAG, "No active config found for display device " + physicalDisplayId); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 112 | return; |
| 113 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 114 | int activeColorMode = SurfaceControl.getActiveColorMode(displayToken); |
| 115 | if (activeColorMode < 0) { |
| 116 | // We failed to get the active color mode. We don't bail out here since on the next |
| 117 | // configuration pass we'll go ahead and set it to whatever it was set to last (or |
| 118 | // COLOR_MODE_NATIVE if this is the first configuration). |
| 119 | Slog.w(TAG, "Unable to get active color mode for display device " + |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 120 | physicalDisplayId); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 121 | activeColorMode = Display.COLOR_MODE_INVALID; |
| 122 | } |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 123 | SurfaceControl.DesiredDisplayConfigSpecs configSpecs = |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 124 | SurfaceControl.getDesiredDisplayConfigSpecs(displayToken); |
Marin Shalamanov | 677d3a7 | 2020-01-07 13:45:55 +0100 | [diff] [blame] | 125 | int[] colorModes = SurfaceControl.getDisplayColorModes(displayToken); |
| 126 | Display.HdrCapabilities hdrCapabilities = |
| 127 | SurfaceControl.getHdrCapabilities(displayToken); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 128 | LocalDisplayDevice device = mDevices.get(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 129 | if (device == null) { |
| 130 | // Display was added. |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 131 | final boolean isDefaultDisplay = mDevices.size() == 0; |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 132 | device = new LocalDisplayDevice(displayToken, physicalDisplayId, info, |
| 133 | configs, activeConfig, configSpecs, colorModes, activeColorMode, |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 134 | hdrCapabilities, isDefaultDisplay); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 135 | mDevices.put(physicalDisplayId, device); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 136 | sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_ADDED); |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 137 | } else if (device.updateDisplayProperties(configs, activeConfig, |
| 138 | configSpecs, colorModes, activeColorMode, hdrCapabilities)) { |
| 139 | sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_CHANGED); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 140 | } |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 141 | } else { |
| 142 | // The display is no longer available. Ignore the attempt to add it. |
| 143 | // If it was connected but has already been disconnected, we'll get a |
| 144 | // disconnect event that will remove it from mDevices. |
| 145 | } |
| 146 | } |
| 147 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 148 | private void tryDisconnectDisplayLocked(long physicalDisplayId) { |
| 149 | LocalDisplayDevice device = mDevices.get(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 150 | if (device != null) { |
| 151 | // Display was removed. |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 152 | mDevices.remove(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 153 | sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_REMOVED); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 154 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 157 | static int getPowerModeForState(int state) { |
| 158 | switch (state) { |
| 159 | case Display.STATE_OFF: |
| 160 | return SurfaceControl.POWER_MODE_OFF; |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 161 | case Display.STATE_DOZE: |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 162 | return SurfaceControl.POWER_MODE_DOZE; |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 163 | case Display.STATE_DOZE_SUSPEND: |
| 164 | return SurfaceControl.POWER_MODE_DOZE_SUSPEND; |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 165 | case Display.STATE_ON_SUSPEND: |
| 166 | return SurfaceControl.POWER_MODE_ON_SUSPEND; |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 167 | default: |
| 168 | return SurfaceControl.POWER_MODE_NORMAL; |
| 169 | } |
Jeff Brown | 44b1f76 | 2014-04-22 18:07:24 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 172 | private final class LocalDisplayDevice extends DisplayDevice { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 173 | private final long mPhysicalDisplayId; |
Ivailo Karamanolev | f773e10 | 2020-01-16 16:10:42 +0100 | [diff] [blame] | 174 | private final LogicalLight mBacklight; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 175 | private final SparseArray<DisplayModeRecord> mSupportedModes = new SparseArray<>(); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 176 | private final ArrayList<Integer> mSupportedColorModes = new ArrayList<>(); |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 177 | private final boolean mIsDefaultDisplay; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 178 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 179 | private DisplayDeviceInfo mInfo; |
| 180 | private boolean mHavePendingChanges; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 181 | private int mState = Display.STATE_UNKNOWN; |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 182 | private float mBrightnessState = PowerManager.BRIGHTNESS_INVALID_FLOAT; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 183 | private int mDefaultModeId; |
Ady Abraham | 8a5e391 | 2020-02-18 17:28:26 -0800 | [diff] [blame] | 184 | private int mDefaultConfigGroup; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 185 | private int mActiveModeId; |
| 186 | private boolean mActiveModeInvalid; |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 187 | private DisplayModeDirector.DesiredDisplayModeSpecs mDisplayModeSpecs = |
| 188 | new DisplayModeDirector.DesiredDisplayModeSpecs(); |
| 189 | private boolean mDisplayModeSpecsInvalid; |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 190 | private int mActiveConfigId; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 191 | private int mActiveColorMode; |
| 192 | private boolean mActiveColorModeInvalid; |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 193 | private Display.HdrCapabilities mHdrCapabilities; |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 194 | private boolean mAllmSupported; |
| 195 | private boolean mGameContentTypeSupported; |
| 196 | private boolean mAllmRequested; |
| 197 | private boolean mGameContentTypeRequested; |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 198 | private boolean mSidekickActive; |
| 199 | private SidekickInternal mSidekickInternal; |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 200 | private SurfaceControl.DisplayInfo mDisplayInfo; |
| 201 | private SurfaceControl.DisplayConfig[] mDisplayConfigs; |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 202 | private Spline mSystemBrightnessToNits; |
| 203 | private Spline mNitsToHalBrightness; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 204 | |
Fiona Campbell | 172fd4a | 2020-03-13 16:34:30 +0000 | [diff] [blame] | 205 | private DisplayDeviceConfig mDisplayDeviceConfig; |
| 206 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 207 | LocalDisplayDevice(IBinder displayToken, long physicalDisplayId, |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 208 | SurfaceControl.DisplayInfo info, SurfaceControl.DisplayConfig[] configs, |
| 209 | int activeConfigId, SurfaceControl.DesiredDisplayConfigSpecs configSpecs, |
Marin Shalamanov | 677d3a7 | 2020-01-07 13:45:55 +0100 | [diff] [blame] | 210 | int[] colorModes, int activeColorMode, Display.HdrCapabilities hdrCapabilities, |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 211 | boolean isDefaultDisplay) { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 212 | super(LocalDisplayAdapter.this, displayToken, UNIQUE_ID_PREFIX + physicalDisplayId); |
| 213 | mPhysicalDisplayId = physicalDisplayId; |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 214 | mIsDefaultDisplay = isDefaultDisplay; |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 215 | mDisplayInfo = info; |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 216 | updateDisplayProperties(configs, activeConfigId, configSpecs, colorModes, |
| 217 | activeColorMode, hdrCapabilities); |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 218 | mSidekickInternal = LocalServices.getService(SidekickInternal.class); |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 219 | if (mIsDefaultDisplay) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 220 | LightsManager lights = LocalServices.getService(LightsManager.class); |
| 221 | mBacklight = lights.getLight(LightsManager.LIGHT_ID_BACKLIGHT); |
| 222 | } else { |
| 223 | mBacklight = null; |
| 224 | } |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 225 | mAllmSupported = SurfaceControl.getAutoLowLatencyModeSupport(displayToken); |
| 226 | mGameContentTypeSupported = SurfaceControl.getGameContentTypeSupport(displayToken); |
Fiona Campbell | 172fd4a | 2020-03-13 16:34:30 +0000 | [diff] [blame] | 227 | mDisplayDeviceConfig = null; |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 228 | // Defer configuration file loading |
| 229 | BackgroundThread.getHandler().sendMessage(PooledLambda.obtainMessage( |
| 230 | LocalDisplayDevice::loadDisplayConfigurationBrightnessMapping, this)); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 233 | @Override |
| 234 | public boolean hasStableUniqueId() { |
| 235 | return true; |
| 236 | } |
| 237 | |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 238 | /** |
| 239 | * Returns true if there is a change. |
| 240 | **/ |
| 241 | public boolean updateDisplayProperties(SurfaceControl.DisplayConfig[] configs, |
| 242 | int activeConfigId, SurfaceControl.DesiredDisplayConfigSpecs configSpecs, |
| 243 | int[] colorModes, int activeColorMode, Display.HdrCapabilities hdrCapabilities) { |
| 244 | boolean changed = updateDisplayConfigsLocked(configs, activeConfigId, configSpecs); |
| 245 | changed |= updateColorModesLocked(colorModes, activeColorMode); |
| 246 | changed |= updateHdrCapabilitiesLocked(hdrCapabilities); |
| 247 | return changed; |
| 248 | } |
| 249 | |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 250 | public boolean updateDisplayConfigsLocked( |
| 251 | SurfaceControl.DisplayConfig[] configs, int activeConfigId, |
Marin Shalamanov | 677d3a7 | 2020-01-07 13:45:55 +0100 | [diff] [blame] | 252 | SurfaceControl.DesiredDisplayConfigSpecs configSpecs) { |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 253 | mDisplayConfigs = Arrays.copyOf(configs, configs.length); |
| 254 | mActiveConfigId = activeConfigId; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 255 | // Build an updated list of all existing modes. |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 256 | ArrayList<DisplayModeRecord> records = new ArrayList<>(); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 257 | boolean modesAdded = false; |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 258 | for (int i = 0; i < configs.length; i++) { |
| 259 | SurfaceControl.DisplayConfig config = configs[i]; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 260 | // First, check to see if we've already added a matching mode. Since not all |
| 261 | // configuration options are exposed via Display.Mode, it's possible that we have |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 262 | // multiple DisplayConfigs that would generate the same Display.Mode. |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 263 | boolean existingMode = false; |
| 264 | for (int j = 0; j < records.size(); j++) { |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 265 | if (records.get(j).hasMatchingMode(config)) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 266 | existingMode = true; |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | if (existingMode) { |
| 271 | continue; |
| 272 | } |
| 273 | // If we haven't already added a mode for this configuration to the new set of |
| 274 | // supported modes then check to see if we have one in the prior set of supported |
| 275 | // modes to reuse. |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 276 | DisplayModeRecord record = findDisplayModeRecord(config); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 277 | if (record == null) { |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 278 | record = new DisplayModeRecord(config); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 279 | modesAdded = true; |
| 280 | } |
| 281 | records.add(record); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | // Get the currently active mode |
| 285 | DisplayModeRecord activeRecord = null; |
| 286 | for (int i = 0; i < records.size(); i++) { |
| 287 | DisplayModeRecord record = records.get(i); |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 288 | if (record.hasMatchingMode(configs[activeConfigId])) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 289 | activeRecord = record; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 290 | break; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 291 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 292 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 293 | |
| 294 | // Check whether surface flinger spontaneously changed modes out from under us. |
| 295 | // Schedule traversals to ensure that the correct state is reapplied if necessary. |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 296 | if (mActiveModeId != NO_DISPLAY_MODE_ID |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 297 | && mActiveModeId != activeRecord.mMode.getModeId()) { |
| 298 | mActiveModeInvalid = true; |
| 299 | sendTraversalRequestLocked(); |
| 300 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 301 | |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 302 | // Check whether surface flinger spontaneously changed display config specs out from |
| 303 | // under us. If so, schedule a traversal to reapply our display config specs. |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 304 | if (mDisplayModeSpecs.baseModeId != NO_DISPLAY_MODE_ID) { |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 305 | int activeBaseMode = findMatchingModeIdLocked(configSpecs.defaultConfig); |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 306 | // If we can't map the defaultConfig index to a mode, then the physical display |
| 307 | // configs must have changed, and the code below for handling changes to the |
| 308 | // list of available modes will take care of updating display config specs. |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 309 | if (activeBaseMode != NO_DISPLAY_MODE_ID) { |
Steven Thomas | ec16194 | 2020-01-03 12:46:28 -0800 | [diff] [blame] | 310 | if (mDisplayModeSpecs.baseModeId != activeBaseMode |
Steven Thomas | 305a57c | 2020-04-17 12:28:36 -0700 | [diff] [blame] | 311 | || mDisplayModeSpecs.primaryRefreshRateRange.min |
| 312 | != configSpecs.primaryRefreshRateMin |
| 313 | || mDisplayModeSpecs.primaryRefreshRateRange.max |
| 314 | != configSpecs.primaryRefreshRateMax |
| 315 | || mDisplayModeSpecs.appRequestRefreshRateRange.min |
| 316 | != configSpecs.appRequestRefreshRateMin |
| 317 | || mDisplayModeSpecs.appRequestRefreshRateRange.max |
| 318 | != configSpecs.appRequestRefreshRateMax) { |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 319 | mDisplayModeSpecsInvalid = true; |
| 320 | sendTraversalRequestLocked(); |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 325 | boolean recordsChanged = records.size() != mSupportedModes.size() || modesAdded; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 326 | // If the records haven't changed then we're done here. |
| 327 | if (!recordsChanged) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 328 | return false; |
| 329 | } |
| 330 | // Update the index of modes. |
| 331 | mHavePendingChanges = true; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 332 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 333 | mSupportedModes.clear(); |
| 334 | for (DisplayModeRecord record : records) { |
| 335 | mSupportedModes.put(record.mMode.getModeId(), record); |
| 336 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 337 | |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 338 | // For a new display, we need to initialize the default mode ID. |
| 339 | if (mDefaultModeId == NO_DISPLAY_MODE_ID) { |
| 340 | mDefaultModeId = activeRecord.mMode.getModeId(); |
Ady Abraham | 8a5e391 | 2020-02-18 17:28:26 -0800 | [diff] [blame] | 341 | mDefaultConfigGroup = configs[activeConfigId].configGroup; |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 342 | } else if (modesAdded && mActiveModeId != activeRecord.mMode.getModeId()) { |
| 343 | Slog.d(TAG, "New display modes are added and the active mode has changed, " |
| 344 | + "use active mode as default mode."); |
| 345 | mActiveModeId = activeRecord.mMode.getModeId(); |
| 346 | mDefaultModeId = activeRecord.mMode.getModeId(); |
Ady Abraham | 8a5e391 | 2020-02-18 17:28:26 -0800 | [diff] [blame] | 347 | mDefaultConfigGroup = configs[activeConfigId].configGroup; |
| 348 | } else if (findDisplayConfigIdLocked(mDefaultModeId, mDefaultConfigGroup) < 0) { |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 349 | Slog.w(TAG, "Default display mode no longer available, using currently" |
| 350 | + " active mode as default."); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 351 | mDefaultModeId = activeRecord.mMode.getModeId(); |
Ady Abraham | 8a5e391 | 2020-02-18 17:28:26 -0800 | [diff] [blame] | 352 | mDefaultConfigGroup = configs[activeConfigId].configGroup; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 353 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 354 | |
Steven Thomas | ec16194 | 2020-01-03 12:46:28 -0800 | [diff] [blame] | 355 | // Determine whether the display mode specs' base mode is still there. |
| 356 | if (mSupportedModes.indexOfKey(mDisplayModeSpecs.baseModeId) < 0) { |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 357 | if (mDisplayModeSpecs.baseModeId != NO_DISPLAY_MODE_ID) { |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 358 | Slog.w(TAG, |
Steven Thomas | ec16194 | 2020-01-03 12:46:28 -0800 | [diff] [blame] | 359 | "DisplayModeSpecs base mode no longer available, using currently" |
| 360 | + " active mode."); |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 361 | } |
Steven Thomas | ec16194 | 2020-01-03 12:46:28 -0800 | [diff] [blame] | 362 | mDisplayModeSpecs.baseModeId = activeRecord.mMode.getModeId(); |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 363 | mDisplayModeSpecsInvalid = true; |
| 364 | } |
| 365 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 366 | // Determine whether the active mode is still there. |
| 367 | if (mSupportedModes.indexOfKey(mActiveModeId) < 0) { |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 368 | if (mActiveModeId != NO_DISPLAY_MODE_ID) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 369 | Slog.w(TAG, "Active display mode no longer available, reverting to default" |
| 370 | + " mode."); |
| 371 | } |
| 372 | mActiveModeId = mDefaultModeId; |
| 373 | mActiveModeInvalid = true; |
| 374 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 375 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 376 | // Schedule traversals so that we apply pending changes. |
| 377 | sendTraversalRequestLocked(); |
| 378 | return true; |
| 379 | } |
| 380 | |
Fiona Campbell | 172fd4a | 2020-03-13 16:34:30 +0000 | [diff] [blame] | 381 | @Override |
| 382 | public DisplayDeviceConfig getDisplayDeviceConfig() { |
| 383 | return mDisplayDeviceConfig; |
| 384 | } |
| 385 | |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 386 | private void loadDisplayConfigurationBrightnessMapping() { |
| 387 | Spline nitsToHal = null; |
| 388 | Spline sysToNits = null; |
| 389 | |
| 390 | // Load the mapping from nits to HAL brightness range (display-device-config.xml) |
| 391 | DisplayDeviceConfig config = DisplayDeviceConfig.create(mPhysicalDisplayId); |
Fiona Campbell | 172fd4a | 2020-03-13 16:34:30 +0000 | [diff] [blame] | 392 | mDisplayDeviceConfig = config; |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 393 | if (config == null) { |
| 394 | return; |
| 395 | } |
Fiona Campbell | 172fd4a | 2020-03-13 16:34:30 +0000 | [diff] [blame] | 396 | final float[] halNits = mDisplayDeviceConfig.getNits(); |
| 397 | final float[] halBrightness = mDisplayDeviceConfig.getBrightness(); |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 398 | if (halNits == null || halBrightness == null) { |
| 399 | return; |
| 400 | } |
| 401 | nitsToHal = Spline.createSpline(halNits, halBrightness); |
| 402 | |
| 403 | // Load the mapping from system brightness range to nits (config.xml) |
| 404 | final Resources res = getOverlayContext().getResources(); |
| 405 | final float[] sysNits = BrightnessMappingStrategy.getFloatArray(res.obtainTypedArray( |
| 406 | com.android.internal.R.array.config_screenBrightnessNits)); |
| 407 | final int[] sysBrightness = res.getIntArray( |
| 408 | com.android.internal.R.array.config_screenBrightnessBacklight); |
| 409 | if (sysNits.length == 0 || sysBrightness.length != sysNits.length) { |
| 410 | return; |
| 411 | } |
| 412 | final float[] sysBrightnessFloat = new float[sysBrightness.length]; |
| 413 | for (int i = 0; i < sysBrightness.length; i++) { |
| 414 | sysBrightnessFloat[i] = sysBrightness[i]; |
| 415 | } |
| 416 | sysToNits = Spline.createSpline(sysBrightnessFloat, sysNits); |
| 417 | |
| 418 | mNitsToHalBrightness = nitsToHal; |
| 419 | mSystemBrightnessToNits = sysToNits; |
| 420 | } |
| 421 | |
Marin Shalamanov | 677d3a7 | 2020-01-07 13:45:55 +0100 | [diff] [blame] | 422 | private boolean updateColorModesLocked(int[] colorModes, int activeColorMode) { |
| 423 | if (colorModes == null) { |
| 424 | return false; |
| 425 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 426 | |
Marin Shalamanov | 677d3a7 | 2020-01-07 13:45:55 +0100 | [diff] [blame] | 427 | List<Integer> pendingColorModes = new ArrayList<>(); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 428 | // Build an updated list of all existing color modes. |
| 429 | boolean colorModesAdded = false; |
Marin Shalamanov | 677d3a7 | 2020-01-07 13:45:55 +0100 | [diff] [blame] | 430 | for (int colorMode : colorModes) { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 431 | if (!mSupportedColorModes.contains(colorMode)) { |
| 432 | colorModesAdded = true; |
| 433 | } |
| 434 | pendingColorModes.add(colorMode); |
| 435 | } |
| 436 | |
| 437 | boolean colorModesChanged = |
| 438 | pendingColorModes.size() != mSupportedColorModes.size() |
| 439 | || colorModesAdded; |
| 440 | |
| 441 | // If the supported color modes haven't changed then we're done here. |
| 442 | if (!colorModesChanged) { |
| 443 | return false; |
| 444 | } |
| 445 | |
| 446 | mHavePendingChanges = true; |
| 447 | |
| 448 | mSupportedColorModes.clear(); |
| 449 | mSupportedColorModes.addAll(pendingColorModes); |
| 450 | Collections.sort(mSupportedColorModes); |
| 451 | |
| 452 | // Determine whether the active color mode is still there. |
| 453 | if (!mSupportedColorModes.contains(mActiveColorMode)) { |
| 454 | if (mActiveColorMode != 0) { |
| 455 | Slog.w(TAG, "Active color mode no longer available, reverting" |
| 456 | + " to default mode."); |
| 457 | mActiveColorMode = Display.COLOR_MODE_DEFAULT; |
| 458 | mActiveColorModeInvalid = true; |
| 459 | } else { |
| 460 | if (!mSupportedColorModes.isEmpty()) { |
| 461 | // This should never happen. |
| 462 | Slog.e(TAG, "Default and active color mode is no longer available!" |
| 463 | + " Reverting to first available mode."); |
| 464 | mActiveColorMode = mSupportedColorModes.get(0); |
| 465 | mActiveColorModeInvalid = true; |
| 466 | } else { |
| 467 | // This should really never happen. |
| 468 | Slog.e(TAG, "No color modes available!"); |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | return true; |
| 473 | } |
| 474 | |
Marin Shalamanov | 677d3a7 | 2020-01-07 13:45:55 +0100 | [diff] [blame] | 475 | private boolean updateHdrCapabilitiesLocked(Display.HdrCapabilities newHdrCapabilities) { |
| 476 | // If the HDR capabilities haven't changed, then we're done here. |
| 477 | if (Objects.equals(mHdrCapabilities, newHdrCapabilities)) { |
| 478 | return false; |
| 479 | } |
| 480 | mHdrCapabilities = newHdrCapabilities; |
| 481 | return true; |
| 482 | } |
| 483 | |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 484 | private DisplayModeRecord findDisplayModeRecord(SurfaceControl.DisplayConfig config) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 485 | for (int i = 0; i < mSupportedModes.size(); i++) { |
| 486 | DisplayModeRecord record = mSupportedModes.valueAt(i); |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 487 | if (record.hasMatchingMode(config)) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 488 | return record; |
| 489 | } |
| 490 | } |
| 491 | return null; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 495 | public void applyPendingDisplayDeviceInfoChangesLocked() { |
| 496 | if (mHavePendingChanges) { |
| 497 | mInfo = null; |
| 498 | mHavePendingChanges = false; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 499 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 500 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 501 | |
| 502 | @Override |
| 503 | public DisplayDeviceInfo getDisplayDeviceInfoLocked() { |
| 504 | if (mInfo == null) { |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 505 | SurfaceControl.DisplayConfig config = mDisplayConfigs[mActiveConfigId]; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 506 | mInfo = new DisplayDeviceInfo(); |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 507 | mInfo.width = config.width; |
| 508 | mInfo.height = config.height; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 509 | mInfo.modeId = mActiveModeId; |
| 510 | mInfo.defaultModeId = mDefaultModeId; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 511 | mInfo.supportedModes = getDisplayModes(mSupportedModes); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 512 | mInfo.colorMode = mActiveColorMode; |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 513 | mInfo.allmSupported = mAllmSupported; |
| 514 | mInfo.gameContentTypeSupported = mGameContentTypeSupported; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 515 | mInfo.supportedColorModes = |
| 516 | new int[mSupportedColorModes.size()]; |
| 517 | for (int i = 0; i < mSupportedColorModes.size(); i++) { |
| 518 | mInfo.supportedColorModes[i] = mSupportedColorModes.get(i); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 519 | } |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 520 | mInfo.hdrCapabilities = mHdrCapabilities; |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 521 | mInfo.appVsyncOffsetNanos = config.appVsyncOffsetNanos; |
| 522 | mInfo.presentationDeadlineNanos = config.presentationDeadlineNanos; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 523 | mInfo.state = mState; |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 524 | mInfo.uniqueId = getUniqueId(); |
Keun young Park | abf38e3 | 2019-04-23 19:18:34 -0700 | [diff] [blame] | 525 | final DisplayAddress.Physical physicalAddress = |
| 526 | DisplayAddress.fromPhysicalDisplayId(mPhysicalDisplayId); |
| 527 | mInfo.address = physicalAddress; |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 528 | mInfo.densityDpi = (int) (mDisplayInfo.density * 160 + 0.5f); |
| 529 | mInfo.xDpi = config.xDpi; |
| 530 | mInfo.yDpi = config.yDpi; |
Marin Shalamanov | 98af159 | 2019-10-08 10:48:08 +0200 | [diff] [blame] | 531 | mInfo.deviceProductInfo = mDisplayInfo.deviceProductInfo; |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 532 | |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 533 | // Assume that all built-in displays that have secure output (eg. HDCP) also |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 534 | // support compositing from gralloc protected buffers. |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 535 | if (mDisplayInfo.secure) { |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 536 | mInfo.flags = DisplayDeviceInfo.FLAG_SECURE |
| 537 | | DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS; |
| 538 | } |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 539 | |
Adrian Roos | 30f5321 | 2018-01-05 16:14:34 +0100 | [diff] [blame] | 540 | final Resources res = getOverlayContext().getResources(); |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 541 | |
| 542 | if (mIsDefaultDisplay) { |
| 543 | mInfo.flags |= DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY; |
| 544 | |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 545 | if (res.getBoolean(com.android.internal.R.bool.config_mainBuiltInDisplayIsRound) |
Griff Hazen | d3c454d | 2016-03-25 07:30:34 -0700 | [diff] [blame] | 546 | || (Build.IS_EMULATOR |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 547 | && SystemProperties.getBoolean(PROPERTY_EMULATOR_CIRCULAR, false))) { |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 548 | mInfo.flags |= DisplayDeviceInfo.FLAG_ROUND; |
| 549 | } |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 550 | if (res.getBoolean( |
| 551 | com.android.internal.R.bool.config_maskMainBuiltInDisplayCutout)) { |
| 552 | mInfo.flags |= DisplayDeviceInfo.FLAG_MASK_DISPLAY_CUTOUT; |
| 553 | } |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 554 | mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res, |
| 555 | mInfo.width, mInfo.height); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 556 | } else { |
Michael Wright | 4b0fa17 | 2016-03-11 17:15:24 -0800 | [diff] [blame] | 557 | if (!res.getBoolean( |
| 558 | com.android.internal.R.bool.config_localDisplaysMirrorContent)) { |
| 559 | mInfo.flags |= DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY; |
| 560 | } |
Pavel Maltsev | a6fec7b | 2018-04-04 10:14:55 -0700 | [diff] [blame] | 561 | |
Keun young Park | abf38e3 | 2019-04-23 19:18:34 -0700 | [diff] [blame] | 562 | if (isDisplayPrivate(physicalAddress)) { |
Pavel Maltsev | a6fec7b | 2018-04-04 10:14:55 -0700 | [diff] [blame] | 563 | mInfo.flags |= DisplayDeviceInfo.FLAG_PRIVATE; |
| 564 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 565 | } |
Dominik Laskowski | 26290bb | 2020-01-15 16:09:55 -0800 | [diff] [blame] | 566 | |
| 567 | if (mDisplayInfo.isInternal) { |
| 568 | mInfo.type = Display.TYPE_INTERNAL; |
| 569 | mInfo.touch = DisplayDeviceInfo.TOUCH_INTERNAL; |
| 570 | mInfo.flags |= DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT; |
| 571 | mInfo.name = res.getString( |
| 572 | com.android.internal.R.string.display_manager_built_in_display_name); |
| 573 | } else { |
| 574 | mInfo.type = Display.TYPE_EXTERNAL; |
| 575 | mInfo.touch = DisplayDeviceInfo.TOUCH_EXTERNAL; |
| 576 | mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION; |
| 577 | mInfo.name = getContext().getResources().getString( |
| 578 | com.android.internal.R.string.display_manager_hdmi_display_name); |
| 579 | } |
Charles Chen | b28fb72 | 2020-05-21 17:19:32 +0800 | [diff] [blame] | 580 | // The display is trusted since it is created by system. |
| 581 | mInfo.flags |= DisplayDeviceInfo.FLAG_TRUSTED; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 582 | } |
| 583 | return mInfo; |
| 584 | } |
| 585 | |
| 586 | @Override |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 587 | public Runnable requestDisplayStateLocked(final int state, final float brightnessState) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 588 | // Assume that the brightness is off if the display is being turned off. |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 589 | assert state != Display.STATE_OFF || BrightnessSynchronizer.floatEquals( |
| 590 | brightnessState, PowerManager.BRIGHTNESS_OFF_FLOAT); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 591 | final boolean stateChanged = (mState != state); |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 592 | final boolean brightnessChanged = (!BrightnessSynchronizer.floatEquals( |
| 593 | mBrightnessState, brightnessState)) |
| 594 | && mBacklight != null; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 595 | if (stateChanged || brightnessChanged) { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 596 | final long physicalDisplayId = mPhysicalDisplayId; |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 597 | final IBinder token = getDisplayTokenLocked(); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 598 | final int oldState = mState; |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 599 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 600 | if (stateChanged) { |
| 601 | mState = state; |
| 602 | updateDeviceInfoLocked(); |
| 603 | } |
| 604 | |
| 605 | if (brightnessChanged) { |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 606 | mBrightnessState = brightnessState; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | // Defer actually setting the display state until after we have exited |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 610 | // the critical section since it can take hundreds of milliseconds |
| 611 | // to complete. |
| 612 | return new Runnable() { |
| 613 | @Override |
| 614 | public void run() { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 615 | // Exit a suspended state before making any changes. |
| 616 | int currentState = oldState; |
| 617 | if (Display.isSuspendedState(oldState) |
| 618 | || oldState == Display.STATE_UNKNOWN) { |
| 619 | if (!Display.isSuspendedState(state)) { |
| 620 | setDisplayState(state); |
| 621 | currentState = state; |
| 622 | } else if (state == Display.STATE_DOZE_SUSPEND |
| 623 | || oldState == Display.STATE_DOZE_SUSPEND) { |
| 624 | setDisplayState(Display.STATE_DOZE); |
| 625 | currentState = Display.STATE_DOZE; |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 626 | } else if (state == Display.STATE_ON_SUSPEND |
| 627 | || oldState == Display.STATE_ON_SUSPEND) { |
| 628 | setDisplayState(Display.STATE_ON); |
| 629 | currentState = Display.STATE_ON; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 630 | } else { |
| 631 | return; // old state and new state is off |
| 632 | } |
| 633 | } |
| 634 | |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 635 | // If the state change was from or to VR, then we need to tell the light |
Karthik Ravi Shankar | 6685531 | 2017-10-04 13:30:13 -0700 | [diff] [blame] | 636 | // so that it can apply appropriate VR brightness settings. Also, update the |
| 637 | // brightness so the state is propogated to light. |
| 638 | boolean vrModeChange = false; |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 639 | if ((state == Display.STATE_VR || currentState == Display.STATE_VR) && |
| 640 | currentState != state) { |
| 641 | setVrMode(state == Display.STATE_VR); |
Karthik Ravi Shankar | 6685531 | 2017-10-04 13:30:13 -0700 | [diff] [blame] | 642 | vrModeChange = true; |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 645 | // Apply brightness changes given that we are in a non-suspended state. |
Karthik Ravi Shankar | 6685531 | 2017-10-04 13:30:13 -0700 | [diff] [blame] | 646 | if (brightnessChanged || vrModeChange) { |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 647 | setDisplayBrightness(brightnessState); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | // Enter the final desired state, possibly suspended. |
| 651 | if (state != currentState) { |
| 652 | setDisplayState(state); |
| 653 | } |
| 654 | } |
| 655 | |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 656 | private void setVrMode(boolean isVrEnabled) { |
| 657 | if (DEBUG) { |
| 658 | Slog.d(TAG, "setVrMode(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 659 | + "id=" + physicalDisplayId |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 660 | + ", state=" + Display.stateToString(state) + ")"); |
| 661 | } |
Robin Lee | b9e44e5 | 2020-02-07 04:18:20 +0100 | [diff] [blame] | 662 | if (mBacklight != null) { |
| 663 | mBacklight.setVrMode(isVrEnabled); |
| 664 | } |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 667 | private void setDisplayState(int state) { |
| 668 | if (DEBUG) { |
| 669 | Slog.d(TAG, "setDisplayState(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 670 | + "id=" + physicalDisplayId |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 671 | + ", state=" + Display.stateToString(state) + ")"); |
| 672 | } |
| 673 | |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 674 | // We must tell sidekick to stop controlling the display before we |
| 675 | // can change its power mode, so do that first. |
| 676 | if (mSidekickActive) { |
| 677 | Trace.traceBegin(Trace.TRACE_TAG_POWER, |
| 678 | "SidekickInternal#endDisplayControl"); |
| 679 | try { |
| 680 | mSidekickInternal.endDisplayControl(); |
| 681 | } finally { |
| 682 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 683 | } |
| 684 | mSidekickActive = false; |
| 685 | } |
| 686 | final int mode = getPowerModeForState(state); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 687 | Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayState(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 688 | + "id=" + physicalDisplayId |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 689 | + ", state=" + Display.stateToString(state) + ")"); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 690 | try { |
| 691 | SurfaceControl.setDisplayPowerMode(token, mode); |
Michael Wright | c3e6af8 | 2017-07-25 22:31:03 +0100 | [diff] [blame] | 692 | Trace.traceCounter(Trace.TRACE_TAG_POWER, "DisplayPowerMode", mode); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 693 | } finally { |
| 694 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 695 | } |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 696 | // If we're entering a suspended (but not OFF) power state and we |
| 697 | // have a sidekick available, tell it now that it can take control. |
| 698 | if (Display.isSuspendedState(state) && state != Display.STATE_OFF |
| 699 | && mSidekickInternal != null && !mSidekickActive) { |
| 700 | Trace.traceBegin(Trace.TRACE_TAG_POWER, |
| 701 | "SidekickInternal#startDisplayControl"); |
| 702 | try { |
| 703 | mSidekickActive = mSidekickInternal.startDisplayControl(state); |
| 704 | } finally { |
| 705 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 706 | } |
| 707 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 708 | } |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 709 | |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 710 | private void setDisplayBrightness(float brightness) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 711 | if (DEBUG) { |
| 712 | Slog.d(TAG, "setDisplayBrightness(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 713 | + "id=" + physicalDisplayId |
| 714 | + ", brightness=" + brightness + ")"); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayBrightness(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 718 | + "id=" + physicalDisplayId + ", brightness=" + brightness + ")"); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 719 | try { |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 720 | if (isHalBrightnessRangeSpecified()) { |
| 721 | brightness = displayBrightnessToHalBrightness( |
Santos Cordon | ed5a8fe | 2020-05-13 18:25:21 +0100 | [diff] [blame] | 722 | BrightnessSynchronizer.brightnessFloatToIntRange( |
| 723 | getContext(), brightness)); |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 724 | } |
Robin Lee | b9e44e5 | 2020-02-07 04:18:20 +0100 | [diff] [blame] | 725 | if (mBacklight != null) { |
| 726 | mBacklight.setBrightness(brightness); |
| 727 | } |
Michael Wright | c3e6af8 | 2017-07-25 22:31:03 +0100 | [diff] [blame] | 728 | Trace.traceCounter(Trace.TRACE_TAG_POWER, |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 729 | "ScreenBrightness", |
| 730 | BrightnessSynchronizer.brightnessFloatToInt( |
| 731 | getContext(), brightness)); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 732 | } finally { |
| 733 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 734 | } |
| 735 | } |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 736 | |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 737 | private boolean isHalBrightnessRangeSpecified() { |
| 738 | return !(mSystemBrightnessToNits == null || mNitsToHalBrightness == null); |
| 739 | } |
| 740 | |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 741 | /** |
| 742 | * Converts brightness range from the framework's brightness space to the |
| 743 | * Hal brightness space if the HAL brightness space has been provided via |
| 744 | * a display device configuration file. |
| 745 | */ |
Santos Cordon | ed5a8fe | 2020-05-13 18:25:21 +0100 | [diff] [blame] | 746 | private float displayBrightnessToHalBrightness(float brightness) { |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 747 | if (!isHalBrightnessRangeSpecified()) { |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 748 | return PowerManager.BRIGHTNESS_INVALID_FLOAT; |
| 749 | } |
| 750 | |
Santos Cordon | ed5a8fe | 2020-05-13 18:25:21 +0100 | [diff] [blame] | 751 | if (BrightnessSynchronizer.floatEquals( |
| 752 | brightness, PowerManager.BRIGHTNESS_OFF)) { |
Santos Cordon | 4505e5e | 2020-01-17 15:18:10 +0000 | [diff] [blame] | 753 | return PowerManager.BRIGHTNESS_OFF_FLOAT; |
| 754 | } |
| 755 | |
| 756 | final float nits = mSystemBrightnessToNits.interpolate(brightness); |
| 757 | final float halBrightness = mNitsToHalBrightness.interpolate(nits); |
| 758 | return halBrightness; |
| 759 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 760 | }; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 761 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 762 | return null; |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | @Override |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 766 | public void setRequestedColorModeLocked(int colorMode) { |
Riddle Hsu | 8b37bc0 | 2019-11-23 00:39:14 +0800 | [diff] [blame] | 767 | requestColorModeLocked(colorMode); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Adrian Roos | 898ec38 | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 770 | @Override |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 771 | public void setDesiredDisplayModeSpecsLocked( |
| 772 | DisplayModeDirector.DesiredDisplayModeSpecs displayModeSpecs) { |
Steven Thomas | ec16194 | 2020-01-03 12:46:28 -0800 | [diff] [blame] | 773 | if (displayModeSpecs.baseModeId == 0) { |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 774 | // Bail if the caller is requesting a null mode. We'll get called again shortly with |
| 775 | // a valid mode. |
| 776 | return; |
| 777 | } |
Ady Abraham | 8a5e391 | 2020-02-18 17:28:26 -0800 | [diff] [blame] | 778 | |
| 779 | // Find the config Id based on the desired mode specs. In case there is more than one |
| 780 | // config matching the mode spec, prefer the one that is in the default config group. |
| 781 | // For now the default config group is taken from the active config when we got the |
| 782 | // hotplug event for the display. In the future we might want to change the default |
| 783 | // config based on vendor requirements. |
| 784 | // Note: We prefer the default config group over the current one as this is the config |
| 785 | // group the vendor prefers. |
| 786 | int baseConfigId = findDisplayConfigIdLocked(displayModeSpecs.baseModeId, |
| 787 | mDefaultConfigGroup); |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 788 | if (baseConfigId < 0) { |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 789 | // When a display is hotplugged, it's possible for a mode to be removed that was |
| 790 | // previously valid. Because of the way display changes are propagated through the |
| 791 | // framework, and the caching of the display mode specs in LogicalDisplay, it's |
| 792 | // possible we'll get called with a stale mode id that no longer represents a valid |
| 793 | // mode. This should only happen in extremely rare cases. A followup call will |
| 794 | // contain a valid mode id. |
| 795 | Slog.w(TAG, |
Steven Thomas | ec16194 | 2020-01-03 12:46:28 -0800 | [diff] [blame] | 796 | "Ignoring request for invalid base mode id " + displayModeSpecs.baseModeId); |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 797 | updateDeviceInfoLocked(); |
| 798 | return; |
| 799 | } |
| 800 | if (mDisplayModeSpecsInvalid || !displayModeSpecs.equals(mDisplayModeSpecs)) { |
| 801 | mDisplayModeSpecsInvalid = false; |
| 802 | mDisplayModeSpecs.copyFrom(displayModeSpecs); |
Riddle Hsu | 8b37bc0 | 2019-11-23 00:39:14 +0800 | [diff] [blame] | 803 | getHandler().sendMessage(PooledLambda.obtainMessage( |
| 804 | LocalDisplayDevice::setDesiredDisplayModeSpecsAsync, this, |
| 805 | getDisplayTokenLocked(), |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 806 | new SurfaceControl.DesiredDisplayConfigSpecs(baseConfigId, |
Steven Thomas | 305a57c | 2020-04-17 12:28:36 -0700 | [diff] [blame] | 807 | mDisplayModeSpecs.primaryRefreshRateRange.min, |
| 808 | mDisplayModeSpecs.primaryRefreshRateRange.max, |
| 809 | mDisplayModeSpecs.appRequestRefreshRateRange.min, |
| 810 | mDisplayModeSpecs.appRequestRefreshRateRange.max))); |
Riddle Hsu | 8b37bc0 | 2019-11-23 00:39:14 +0800 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
| 814 | private void setDesiredDisplayModeSpecsAsync(IBinder displayToken, |
| 815 | SurfaceControl.DesiredDisplayConfigSpecs configSpecs) { |
| 816 | // Do not lock when calling these SurfaceControl methods because they are sync |
| 817 | // operations that may block for a while when setting display power mode. |
| 818 | SurfaceControl.setDesiredDisplayConfigSpecs(displayToken, configSpecs); |
| 819 | final int activePhysIndex = SurfaceControl.getActiveConfig(displayToken); |
| 820 | synchronized (getSyncRoot()) { |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 821 | if (updateActiveModeLocked(activePhysIndex)) { |
| 822 | updateDeviceInfoLocked(); |
| 823 | } |
| 824 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | @Override |
Adrian Roos | 898ec38 | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 828 | public void onOverlayChangedLocked() { |
| 829 | updateDeviceInfoLocked(); |
| 830 | } |
| 831 | |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 832 | public void onActiveDisplayConfigChangedLocked(int configId) { |
| 833 | if (updateActiveModeLocked(configId)) { |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 834 | updateDeviceInfoLocked(); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 835 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 836 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 837 | |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 838 | public boolean updateActiveModeLocked(int activeConfigId) { |
| 839 | if (mActiveConfigId == activeConfigId) { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 840 | return false; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 841 | } |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 842 | mActiveConfigId = activeConfigId; |
| 843 | mActiveModeId = findMatchingModeIdLocked(activeConfigId); |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 844 | mActiveModeInvalid = mActiveModeId == NO_DISPLAY_MODE_ID; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 845 | if (mActiveModeInvalid) { |
| 846 | Slog.w(TAG, "In unknown mode after setting allowed configs" |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 847 | + ", activeConfigId=" + mActiveConfigId); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 848 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 849 | return true; |
| 850 | } |
| 851 | |
Riddle Hsu | 8b37bc0 | 2019-11-23 00:39:14 +0800 | [diff] [blame] | 852 | public void requestColorModeLocked(int colorMode) { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 853 | if (mActiveColorMode == colorMode) { |
Riddle Hsu | 8b37bc0 | 2019-11-23 00:39:14 +0800 | [diff] [blame] | 854 | return; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 855 | } |
| 856 | if (!mSupportedColorModes.contains(colorMode)) { |
| 857 | Slog.w(TAG, "Unable to find color mode " + colorMode |
| 858 | + ", ignoring request."); |
Riddle Hsu | 8b37bc0 | 2019-11-23 00:39:14 +0800 | [diff] [blame] | 859 | return; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 860 | } |
Riddle Hsu | 8b37bc0 | 2019-11-23 00:39:14 +0800 | [diff] [blame] | 861 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 862 | mActiveColorMode = colorMode; |
| 863 | mActiveColorModeInvalid = false; |
Riddle Hsu | 8b37bc0 | 2019-11-23 00:39:14 +0800 | [diff] [blame] | 864 | getHandler().sendMessage(PooledLambda.obtainMessage( |
| 865 | LocalDisplayDevice::requestColorModeAsync, this, |
| 866 | getDisplayTokenLocked(), colorMode)); |
| 867 | } |
| 868 | |
| 869 | private void requestColorModeAsync(IBinder displayToken, int colorMode) { |
| 870 | // Do not lock when calling this SurfaceControl method because it is a sync operation |
| 871 | // that may block for a while when setting display power mode. |
| 872 | SurfaceControl.setActiveColorMode(displayToken, colorMode); |
| 873 | synchronized (getSyncRoot()) { |
| 874 | updateDeviceInfoLocked(); |
| 875 | } |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | @Override |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 879 | public void setAutoLowLatencyModeLocked(boolean on) { |
| 880 | if (mAllmRequested == on) { |
| 881 | return; |
| 882 | } |
| 883 | |
| 884 | mAllmRequested = on; |
| 885 | |
| 886 | if (!mAllmSupported) { |
| 887 | Slog.d(TAG, "Unable to set ALLM because the connected display " |
| 888 | + "does not support ALLM."); |
| 889 | return; |
| 890 | } |
| 891 | |
| 892 | SurfaceControl.setAutoLowLatencyMode(getDisplayTokenLocked(), on); |
| 893 | } |
| 894 | |
| 895 | @Override |
| 896 | public void setGameContentTypeLocked(boolean on) { |
| 897 | if (mGameContentTypeRequested == on) { |
| 898 | return; |
| 899 | } |
| 900 | |
| 901 | mGameContentTypeRequested = on; |
| 902 | |
| 903 | if (!mGameContentTypeSupported) { |
| 904 | Slog.d(TAG, "Unable to set game content type because the connected " |
| 905 | + "display does not support game content type."); |
| 906 | return; |
| 907 | } |
| 908 | |
| 909 | SurfaceControl.setGameContentType(getDisplayTokenLocked(), on); |
| 910 | } |
| 911 | |
| 912 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 913 | public void dumpLocked(PrintWriter pw) { |
| 914 | super.dumpLocked(pw); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 915 | pw.println("mPhysicalDisplayId=" + mPhysicalDisplayId); |
Ana Krulec | a74a864 | 2019-11-14 00:51:00 +0100 | [diff] [blame] | 916 | pw.println("mDisplayModeSpecs={" + mDisplayModeSpecs + "}"); |
| 917 | pw.println("mDisplayModeSpecsInvalid=" + mDisplayModeSpecsInvalid); |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 918 | pw.println("mActiveConfigId=" + mActiveConfigId); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 919 | pw.println("mActiveModeId=" + mActiveModeId); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 920 | pw.println("mActiveColorMode=" + mActiveColorMode); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 921 | pw.println("mDefaultModeId=" + mDefaultModeId); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 922 | pw.println("mState=" + Display.stateToString(mState)); |
Fiona Campbell | d4eb295 | 2019-11-04 17:19:56 +0000 | [diff] [blame] | 923 | pw.println("mBrightnessState=" + mBrightnessState); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 924 | pw.println("mBacklight=" + mBacklight); |
Galia Peycheva | 056b3ee | 2019-06-26 14:05:12 +0200 | [diff] [blame] | 925 | pw.println("mAllmSupported=" + mAllmSupported); |
| 926 | pw.println("mAllmRequested=" + mAllmRequested); |
Marin Shalamanov | 98af159 | 2019-10-08 10:48:08 +0200 | [diff] [blame] | 927 | pw.println("mGameContentTypeSupported=" + mGameContentTypeSupported); |
| 928 | pw.println("mGameContentTypeRequested=" + mGameContentTypeRequested); |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 929 | pw.println("mDisplayInfo=" + mDisplayInfo); |
| 930 | pw.println("mDisplayConfigs="); |
| 931 | for (int i = 0; i < mDisplayConfigs.length; i++) { |
| 932 | pw.println(" " + mDisplayConfigs[i]); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 933 | } |
| 934 | pw.println("mSupportedModes="); |
| 935 | for (int i = 0; i < mSupportedModes.size(); i++) { |
| 936 | pw.println(" " + mSupportedModes.valueAt(i)); |
| 937 | } |
Marin Shalamanov | 98af159 | 2019-10-08 10:48:08 +0200 | [diff] [blame] | 938 | pw.print("mSupportedColorModes=" + mSupportedColorModes.toString()); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 939 | } |
| 940 | |
Ady Abraham | 8a5e391 | 2020-02-18 17:28:26 -0800 | [diff] [blame] | 941 | private int findDisplayConfigIdLocked(int modeId, int configGroup) { |
| 942 | int matchingConfigId = SurfaceControl.DisplayConfig.INVALID_DISPLAY_CONFIG_ID; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 943 | DisplayModeRecord record = mSupportedModes.get(modeId); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 944 | if (record != null) { |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 945 | for (int i = 0; i < mDisplayConfigs.length; i++) { |
| 946 | SurfaceControl.DisplayConfig config = mDisplayConfigs[i]; |
| 947 | if (record.hasMatchingMode(config)) { |
Ady Abraham | 8a5e391 | 2020-02-18 17:28:26 -0800 | [diff] [blame] | 948 | if (matchingConfigId |
| 949 | == SurfaceControl.DisplayConfig.INVALID_DISPLAY_CONFIG_ID) { |
| 950 | matchingConfigId = i; |
| 951 | } |
| 952 | |
| 953 | // Prefer to return a config that matches the configGroup |
| 954 | if (config.configGroup == configGroup) { |
| 955 | return i; |
| 956 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | } |
Ady Abraham | 8a5e391 | 2020-02-18 17:28:26 -0800 | [diff] [blame] | 960 | return matchingConfigId; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 963 | private int findMatchingModeIdLocked(int configId) { |
| 964 | SurfaceControl.DisplayConfig config = mDisplayConfigs[configId]; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 965 | for (int i = 0; i < mSupportedModes.size(); i++) { |
| 966 | DisplayModeRecord record = mSupportedModes.valueAt(i); |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 967 | if (record.hasMatchingMode(config)) { |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 968 | return record.mMode.getModeId(); |
| 969 | } |
| 970 | } |
Marin Shalamanov | cdf7bb6 | 2020-01-07 14:19:50 +0100 | [diff] [blame] | 971 | return NO_DISPLAY_MODE_ID; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 974 | private void updateDeviceInfoLocked() { |
| 975 | mInfo = null; |
| 976 | sendDisplayDeviceEventLocked(this, DISPLAY_DEVICE_EVENT_CHANGED); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 977 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 978 | |
| 979 | private Display.Mode[] getDisplayModes(SparseArray<DisplayModeRecord> records) { |
| 980 | final int size = records.size(); |
| 981 | Display.Mode[] modes = new Display.Mode[size]; |
| 982 | for (int i = 0; i < size; i++) { |
| 983 | DisplayModeRecord record = records.valueAt(i); |
| 984 | modes[i] = record.mMode; |
| 985 | } |
| 986 | return modes; |
| 987 | } |
Keun young Park | abf38e3 | 2019-04-23 19:18:34 -0700 | [diff] [blame] | 988 | |
| 989 | private boolean isDisplayPrivate(DisplayAddress.Physical physicalAddress) { |
| 990 | if (physicalAddress == null) { |
| 991 | return false; |
| 992 | } |
| 993 | final Resources res = getOverlayContext().getResources(); |
| 994 | int[] ports = res.getIntArray( |
| 995 | com.android.internal.R.array.config_localPrivateDisplayPorts); |
| 996 | if (ports != null) { |
Dominik Laskowski | 67cc7f8 | 2019-11-08 17:09:29 -0800 | [diff] [blame] | 997 | int port = Byte.toUnsignedInt(physicalAddress.getPort()); |
Keun young Park | abf38e3 | 2019-04-23 19:18:34 -0700 | [diff] [blame] | 998 | for (int p : ports) { |
| 999 | if (p == port) { |
| 1000 | return true; |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | return false; |
| 1005 | } |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1006 | } |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1007 | |
Adrian Roos | 30f5321 | 2018-01-05 16:14:34 +0100 | [diff] [blame] | 1008 | /** Supplies a context whose Resources apply runtime-overlays */ |
| 1009 | Context getOverlayContext() { |
| 1010 | return ActivityThread.currentActivityThread().getSystemUiContext(); |
| 1011 | } |
| 1012 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1013 | /** |
| 1014 | * Keeps track of a display configuration. |
| 1015 | */ |
| 1016 | private static final class DisplayModeRecord { |
| 1017 | public final Display.Mode mMode; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1018 | |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 1019 | DisplayModeRecord(SurfaceControl.DisplayConfig config) { |
| 1020 | mMode = createMode(config.width, config.height, config.refreshRate); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | /** |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 1024 | * Returns whether the mode generated by the given DisplayConfig matches the mode |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1025 | * contained by the record modulo mode ID. |
| 1026 | * |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 1027 | * Note that this doesn't necessarily mean that the DisplayConfigs are identical, just |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1028 | * that they generate identical modes. |
| 1029 | */ |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 1030 | public boolean hasMatchingMode(SurfaceControl.DisplayConfig config) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1031 | int modeRefreshRate = Float.floatToIntBits(mMode.getRefreshRate()); |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 1032 | int configRefreshRate = Float.floatToIntBits(config.refreshRate); |
| 1033 | return mMode.getPhysicalWidth() == config.width |
| 1034 | && mMode.getPhysicalHeight() == config.height |
| 1035 | && modeRefreshRate == configRefreshRate; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | public String toString() { |
| 1039 | return "DisplayModeRecord{mMode=" + mMode + "}"; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 1040 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 1041 | } |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 1042 | |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 1043 | private final class PhysicalDisplayEventReceiver extends DisplayEventReceiver { |
| 1044 | PhysicalDisplayEventReceiver(Looper looper) { |
Ady Abraham | 9c501aa | 2019-06-04 16:07:44 -0700 | [diff] [blame] | 1045 | super(looper, VSYNC_SOURCE_APP, CONFIG_CHANGED_EVENT_DISPATCH); |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | @Override |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 1049 | public void onHotplug(long timestampNanos, long physicalDisplayId, boolean connected) { |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 1050 | synchronized (getSyncRoot()) { |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 1051 | if (connected) { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 1052 | tryConnectDisplayLocked(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 1053 | } else { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 1054 | tryDisconnectDisplayLocked(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 1055 | } |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 1056 | } |
| 1057 | } |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 1058 | |
| 1059 | @Override |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 1060 | public void onConfigChanged(long timestampNanos, long physicalDisplayId, int configId) { |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 1061 | if (DEBUG) { |
| 1062 | Slog.d(TAG, "onConfigChanged(" |
| 1063 | + "timestampNanos=" + timestampNanos |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 1064 | + ", physicalDisplayId=" + physicalDisplayId |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 1065 | + ", configId=" + configId + ")"); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 1066 | } |
| 1067 | synchronized (getSyncRoot()) { |
| 1068 | LocalDisplayDevice device = mDevices.get(physicalDisplayId); |
| 1069 | if (device == null) { |
| 1070 | if (DEBUG) { |
| 1071 | Slog.d(TAG, "Received config change for unhandled physical display: " |
| 1072 | + "physicalDisplayId=" + physicalDisplayId); |
| 1073 | } |
| 1074 | return; |
| 1075 | } |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 1076 | device.onActiveDisplayConfigChangedLocked(configId); |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 1077 | } |
| 1078 | } |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 1079 | } |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 1080 | } |