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; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 33 | import android.view.Display; |
Dominik Laskowski | db84596 | 2019-01-27 21:20:00 -0800 | [diff] [blame] | 34 | import android.view.DisplayAddress; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 35 | import android.view.DisplayCutout; |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 36 | import android.view.DisplayEventReceiver; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 37 | import android.view.Surface; |
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 | |
| 40 | import com.android.server.LocalServices; |
| 41 | import com.android.server.lights.Light; |
| 42 | import com.android.server.lights.LightsManager; |
| 43 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 44 | import java.io.PrintWriter; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 45 | import java.util.ArrayList; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 46 | import java.util.Arrays; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 47 | import java.util.Collections; |
| 48 | import java.util.List; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 49 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 50 | /** |
| 51 | * A display adapter for the local displays managed by Surface Flinger. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 52 | * <p> |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 53 | * Display adapters are guarded by the {@link DisplayManagerService.SyncRoot} lock. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 54 | * </p> |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 55 | */ |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 56 | final class LocalDisplayAdapter extends DisplayAdapter { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 57 | private static final String TAG = "LocalDisplayAdapter"; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 58 | private static final boolean DEBUG = false; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 59 | |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 60 | private static final String UNIQUE_ID_PREFIX = "local:"; |
| 61 | |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 62 | private static final String PROPERTY_EMULATOR_CIRCULAR = "ro.emulator.circular"; |
| 63 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 64 | private final LongSparseArray<LocalDisplayDevice> mDevices = |
| 65 | new LongSparseArray<LocalDisplayDevice>(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 66 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 67 | @SuppressWarnings("unused") // Becomes active at instantiation time. |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 68 | private PhysicalDisplayEventReceiver mPhysicalDisplayEventReceiver; |
| 69 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 70 | |
Jeff Brown | 6669250 | 2012-10-18 16:13:44 -0700 | [diff] [blame] | 71 | // Called with SyncRoot lock held. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 72 | public LocalDisplayAdapter(DisplayManagerService.SyncRoot syncRoot, |
| 73 | Context context, Handler handler, Listener listener) { |
| 74 | super(syncRoot, context, handler, listener, TAG); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 78 | public void registerLocked() { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 79 | super.registerLocked(); |
Jeff Brown | 6669250 | 2012-10-18 16:13:44 -0700 | [diff] [blame] | 80 | |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 81 | mPhysicalDisplayEventReceiver = new PhysicalDisplayEventReceiver(getHandler().getLooper()); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 82 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 83 | for (long physicalDisplayId : SurfaceControl.getPhysicalDisplayIds()) { |
| 84 | tryConnectDisplayLocked(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 85 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 88 | private void tryConnectDisplayLocked(long physicalDisplayId) { |
| 89 | final IBinder displayToken = SurfaceControl.getPhysicalDisplayToken(physicalDisplayId); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 90 | if (displayToken != null) { |
| 91 | SurfaceControl.PhysicalDisplayInfo[] configs = |
| 92 | SurfaceControl.getDisplayConfigs(displayToken); |
| 93 | if (configs == null) { |
| 94 | // 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] | 95 | Slog.w(TAG, "No valid configs found for display device " + physicalDisplayId); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 96 | return; |
| 97 | } |
| 98 | int activeConfig = SurfaceControl.getActiveConfig(displayToken); |
| 99 | if (activeConfig < 0) { |
| 100 | // There is no active config, and for now we don't have the |
| 101 | // policy to set one. |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 102 | Slog.w(TAG, "No active config found for display device " + physicalDisplayId); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 103 | return; |
| 104 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 105 | int activeColorMode = SurfaceControl.getActiveColorMode(displayToken); |
| 106 | if (activeColorMode < 0) { |
| 107 | // We failed to get the active color mode. We don't bail out here since on the next |
| 108 | // configuration pass we'll go ahead and set it to whatever it was set to last (or |
| 109 | // COLOR_MODE_NATIVE if this is the first configuration). |
| 110 | Slog.w(TAG, "Unable to get active color mode for display device " + |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 111 | physicalDisplayId); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 112 | activeColorMode = Display.COLOR_MODE_INVALID; |
| 113 | } |
| 114 | int[] colorModes = SurfaceControl.getDisplayColorModes(displayToken); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 115 | int[] allowedConfigs = SurfaceControl.getAllowedDisplayConfigs(displayToken); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 116 | LocalDisplayDevice device = mDevices.get(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 117 | if (device == null) { |
| 118 | // Display was added. |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 119 | final boolean isInternal = mDevices.size() == 0; |
| 120 | device = new LocalDisplayDevice(displayToken, physicalDisplayId, |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 121 | configs, activeConfig, allowedConfigs, colorModes, activeColorMode, |
| 122 | isInternal); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 123 | mDevices.put(physicalDisplayId, device); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 124 | sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_ADDED); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 125 | } else if (device.updatePhysicalDisplayInfoLocked(configs, activeConfig, |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 126 | allowedConfigs, colorModes, activeColorMode)) { |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 127 | // Display properties changed. |
| 128 | sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_CHANGED); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 129 | } |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 130 | } else { |
| 131 | // The display is no longer available. Ignore the attempt to add it. |
| 132 | // If it was connected but has already been disconnected, we'll get a |
| 133 | // disconnect event that will remove it from mDevices. |
| 134 | } |
| 135 | } |
| 136 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 137 | private void tryDisconnectDisplayLocked(long physicalDisplayId) { |
| 138 | LocalDisplayDevice device = mDevices.get(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 139 | if (device != null) { |
| 140 | // Display was removed. |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 141 | mDevices.remove(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 142 | sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_REMOVED); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 143 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 146 | static int getPowerModeForState(int state) { |
| 147 | switch (state) { |
| 148 | case Display.STATE_OFF: |
| 149 | return SurfaceControl.POWER_MODE_OFF; |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 150 | case Display.STATE_DOZE: |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 151 | return SurfaceControl.POWER_MODE_DOZE; |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 152 | case Display.STATE_DOZE_SUSPEND: |
| 153 | return SurfaceControl.POWER_MODE_DOZE_SUSPEND; |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 154 | case Display.STATE_ON_SUSPEND: |
| 155 | return SurfaceControl.POWER_MODE_ON_SUSPEND; |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 156 | default: |
| 157 | return SurfaceControl.POWER_MODE_NORMAL; |
| 158 | } |
Jeff Brown | 44b1f76 | 2014-04-22 18:07:24 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 161 | private final class LocalDisplayDevice extends DisplayDevice { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 162 | private final long mPhysicalDisplayId; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 163 | private final Light mBacklight; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 164 | private final SparseArray<DisplayModeRecord> mSupportedModes = new SparseArray<>(); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 165 | private final ArrayList<Integer> mSupportedColorModes = new ArrayList<>(); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 166 | private final boolean mIsInternal; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 167 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 168 | private DisplayDeviceInfo mInfo; |
| 169 | private boolean mHavePendingChanges; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 170 | private int mState = Display.STATE_UNKNOWN; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 171 | private int mBrightness = PowerManager.BRIGHTNESS_DEFAULT; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 172 | private int mDefaultModeId; |
| 173 | private int mActiveModeId; |
| 174 | private boolean mActiveModeInvalid; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 175 | private int[] mAllowedModeIds; |
| 176 | private boolean mAllowedModeIdsInvalid; |
| 177 | private int mActivePhysIndex; |
| 178 | private int[] mAllowedPhysIndexes; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 179 | private int mActiveColorMode; |
| 180 | private boolean mActiveColorModeInvalid; |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 181 | private Display.HdrCapabilities mHdrCapabilities; |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 182 | private boolean mSidekickActive; |
| 183 | private SidekickInternal mSidekickInternal; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 184 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 185 | private SurfaceControl.PhysicalDisplayInfo[] mDisplayInfos; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 186 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 187 | LocalDisplayDevice(IBinder displayToken, long physicalDisplayId, |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 188 | SurfaceControl.PhysicalDisplayInfo[] physicalDisplayInfos, int activeDisplayInfo, |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 189 | int[] allowedDisplayInfos, int[] colorModes, int activeColorMode, |
| 190 | boolean isInternal) { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 191 | super(LocalDisplayAdapter.this, displayToken, UNIQUE_ID_PREFIX + physicalDisplayId); |
| 192 | mPhysicalDisplayId = physicalDisplayId; |
| 193 | mIsInternal = isInternal; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 194 | updatePhysicalDisplayInfoLocked(physicalDisplayInfos, activeDisplayInfo, |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 195 | allowedDisplayInfos, colorModes, activeColorMode); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 196 | updateColorModesLocked(colorModes, activeColorMode); |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 197 | mSidekickInternal = LocalServices.getService(SidekickInternal.class); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 198 | if (mIsInternal) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 199 | LightsManager lights = LocalServices.getService(LightsManager.class); |
| 200 | mBacklight = lights.getLight(LightsManager.LIGHT_ID_BACKLIGHT); |
| 201 | } else { |
| 202 | mBacklight = null; |
| 203 | } |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 204 | mHdrCapabilities = SurfaceControl.getHdrCapabilities(displayToken); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 207 | @Override |
| 208 | public boolean hasStableUniqueId() { |
| 209 | return true; |
| 210 | } |
| 211 | |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 212 | public boolean updatePhysicalDisplayInfoLocked( |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 213 | SurfaceControl.PhysicalDisplayInfo[] physicalDisplayInfos, int activeDisplayInfo, |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 214 | int[] allowedDisplayInfos, int[] colorModes, int activeColorMode) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 215 | mDisplayInfos = Arrays.copyOf(physicalDisplayInfos, physicalDisplayInfos.length); |
| 216 | mActivePhysIndex = activeDisplayInfo; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 217 | mAllowedPhysIndexes = Arrays.copyOf(allowedDisplayInfos, allowedDisplayInfos.length); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 218 | // Build an updated list of all existing modes. |
| 219 | ArrayList<DisplayModeRecord> records = new ArrayList<DisplayModeRecord>(); |
| 220 | boolean modesAdded = false; |
| 221 | for (int i = 0; i < physicalDisplayInfos.length; i++) { |
| 222 | SurfaceControl.PhysicalDisplayInfo info = physicalDisplayInfos[i]; |
| 223 | // First, check to see if we've already added a matching mode. Since not all |
| 224 | // configuration options are exposed via Display.Mode, it's possible that we have |
| 225 | // multiple PhysicalDisplayInfos that would generate the same Display.Mode. |
| 226 | boolean existingMode = false; |
| 227 | for (int j = 0; j < records.size(); j++) { |
| 228 | if (records.get(j).hasMatchingMode(info)) { |
| 229 | existingMode = true; |
| 230 | break; |
| 231 | } |
| 232 | } |
| 233 | if (existingMode) { |
| 234 | continue; |
| 235 | } |
| 236 | // If we haven't already added a mode for this configuration to the new set of |
| 237 | // supported modes then check to see if we have one in the prior set of supported |
| 238 | // modes to reuse. |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 239 | DisplayModeRecord record = findDisplayModeRecord(info); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 240 | if (record == null) { |
| 241 | record = new DisplayModeRecord(info); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 242 | modesAdded = true; |
| 243 | } |
| 244 | records.add(record); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | // Get the currently active mode |
| 248 | DisplayModeRecord activeRecord = null; |
| 249 | for (int i = 0; i < records.size(); i++) { |
| 250 | DisplayModeRecord record = records.get(i); |
| 251 | if (record.hasMatchingMode(physicalDisplayInfos[activeDisplayInfo])){ |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 252 | activeRecord = record; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 253 | break; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 254 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 255 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 256 | |
| 257 | // Check whether surface flinger spontaneously changed modes out from under us. |
| 258 | // Schedule traversals to ensure that the correct state is reapplied if necessary. |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 259 | if (mActiveModeId != 0 |
| 260 | && mActiveModeId != activeRecord.mMode.getModeId()) { |
| 261 | mActiveModeInvalid = true; |
| 262 | sendTraversalRequestLocked(); |
| 263 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 264 | |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 265 | boolean recordsChanged = records.size() != mSupportedModes.size() || modesAdded; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 266 | // If the records haven't changed then we're done here. |
| 267 | if (!recordsChanged) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 268 | return false; |
| 269 | } |
| 270 | // Update the index of modes. |
| 271 | mHavePendingChanges = true; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 272 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 273 | mSupportedModes.clear(); |
| 274 | for (DisplayModeRecord record : records) { |
| 275 | mSupportedModes.put(record.mMode.getModeId(), record); |
| 276 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 277 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 278 | // Update the default mode, if needed. |
| 279 | if (findDisplayInfoIndexLocked(mDefaultModeId) < 0) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 280 | if (mDefaultModeId != 0) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 281 | Slog.w(TAG, "Default display mode no longer available, using currently" |
| 282 | + " active mode as default."); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 283 | } |
| 284 | mDefaultModeId = activeRecord.mMode.getModeId(); |
| 285 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 286 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 287 | // Determine whether the active mode is still there. |
| 288 | if (mSupportedModes.indexOfKey(mActiveModeId) < 0) { |
| 289 | if (mActiveModeId != 0) { |
| 290 | Slog.w(TAG, "Active display mode no longer available, reverting to default" |
| 291 | + " mode."); |
| 292 | } |
| 293 | mActiveModeId = mDefaultModeId; |
| 294 | mActiveModeInvalid = true; |
| 295 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 296 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 297 | // Determine what the currently allowed modes are |
| 298 | mAllowedModeIds = new int[] { mActiveModeId }; |
| 299 | int[] allowedModeIds = new int[mAllowedPhysIndexes.length]; |
| 300 | int size = 0; |
| 301 | for (int physIndex : mAllowedPhysIndexes) { |
| 302 | int modeId = findMatchingModeIdLocked(physIndex); |
| 303 | if (modeId > 0) { |
| 304 | allowedModeIds[size++] = modeId; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // If this is different from our desired allowed modes, then mark our current set as |
| 309 | // invalid so we correct this on the next traversal. |
| 310 | mAllowedModeIdsInvalid = !Arrays.equals(allowedModeIds, mAllowedModeIds); |
| 311 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 312 | // Schedule traversals so that we apply pending changes. |
| 313 | sendTraversalRequestLocked(); |
| 314 | return true; |
| 315 | } |
| 316 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 317 | private boolean updateColorModesLocked(int[] colorModes, |
| 318 | int activeColorMode) { |
| 319 | List<Integer> pendingColorModes = new ArrayList<>(); |
| 320 | |
thecrazyskull | b34c8104 | 2016-12-18 12:48:20 -0500 | [diff] [blame] | 321 | if (colorModes == null) return false; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 322 | // Build an updated list of all existing color modes. |
| 323 | boolean colorModesAdded = false; |
| 324 | for (int colorMode: colorModes) { |
| 325 | if (!mSupportedColorModes.contains(colorMode)) { |
| 326 | colorModesAdded = true; |
| 327 | } |
| 328 | pendingColorModes.add(colorMode); |
| 329 | } |
| 330 | |
| 331 | boolean colorModesChanged = |
| 332 | pendingColorModes.size() != mSupportedColorModes.size() |
| 333 | || colorModesAdded; |
| 334 | |
| 335 | // If the supported color modes haven't changed then we're done here. |
| 336 | if (!colorModesChanged) { |
| 337 | return false; |
| 338 | } |
| 339 | |
| 340 | mHavePendingChanges = true; |
| 341 | |
| 342 | mSupportedColorModes.clear(); |
| 343 | mSupportedColorModes.addAll(pendingColorModes); |
| 344 | Collections.sort(mSupportedColorModes); |
| 345 | |
| 346 | // Determine whether the active color mode is still there. |
| 347 | if (!mSupportedColorModes.contains(mActiveColorMode)) { |
| 348 | if (mActiveColorMode != 0) { |
| 349 | Slog.w(TAG, "Active color mode no longer available, reverting" |
| 350 | + " to default mode."); |
| 351 | mActiveColorMode = Display.COLOR_MODE_DEFAULT; |
| 352 | mActiveColorModeInvalid = true; |
| 353 | } else { |
| 354 | if (!mSupportedColorModes.isEmpty()) { |
| 355 | // This should never happen. |
| 356 | Slog.e(TAG, "Default and active color mode is no longer available!" |
| 357 | + " Reverting to first available mode."); |
| 358 | mActiveColorMode = mSupportedColorModes.get(0); |
| 359 | mActiveColorModeInvalid = true; |
| 360 | } else { |
| 361 | // This should really never happen. |
| 362 | Slog.e(TAG, "No color modes available!"); |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | return true; |
| 367 | } |
| 368 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 369 | private DisplayModeRecord findDisplayModeRecord(SurfaceControl.PhysicalDisplayInfo info) { |
| 370 | for (int i = 0; i < mSupportedModes.size(); i++) { |
| 371 | DisplayModeRecord record = mSupportedModes.valueAt(i); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 372 | if (record.hasMatchingMode(info)) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 373 | return record; |
| 374 | } |
| 375 | } |
| 376 | return null; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 380 | public void applyPendingDisplayDeviceInfoChangesLocked() { |
| 381 | if (mHavePendingChanges) { |
| 382 | mInfo = null; |
| 383 | mHavePendingChanges = false; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 384 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 385 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 386 | |
| 387 | @Override |
| 388 | public DisplayDeviceInfo getDisplayDeviceInfoLocked() { |
| 389 | if (mInfo == null) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 390 | SurfaceControl.PhysicalDisplayInfo phys = mDisplayInfos[mActivePhysIndex]; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 391 | mInfo = new DisplayDeviceInfo(); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 392 | mInfo.width = phys.width; |
| 393 | mInfo.height = phys.height; |
| 394 | mInfo.modeId = mActiveModeId; |
| 395 | mInfo.defaultModeId = mDefaultModeId; |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 396 | mInfo.supportedModes = getDisplayModes(mSupportedModes); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 397 | mInfo.colorMode = mActiveColorMode; |
| 398 | mInfo.supportedColorModes = |
| 399 | new int[mSupportedColorModes.size()]; |
| 400 | for (int i = 0; i < mSupportedColorModes.size(); i++) { |
| 401 | mInfo.supportedColorModes[i] = mSupportedColorModes.get(i); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 402 | } |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 403 | mInfo.hdrCapabilities = mHdrCapabilities; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 404 | mInfo.appVsyncOffsetNanos = phys.appVsyncOffsetNanos; |
| 405 | mInfo.presentationDeadlineNanos = phys.presentationDeadlineNanos; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 406 | mInfo.state = mState; |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 407 | mInfo.uniqueId = getUniqueId(); |
Keun young Park | abf38e3 | 2019-04-23 19:18:34 -0700 | [diff] [blame] | 408 | final DisplayAddress.Physical physicalAddress = |
| 409 | DisplayAddress.fromPhysicalDisplayId(mPhysicalDisplayId); |
| 410 | mInfo.address = physicalAddress; |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 411 | |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 412 | // 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] | 413 | // support compositing from gralloc protected buffers. |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 414 | if (phys.secure) { |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 415 | mInfo.flags = DisplayDeviceInfo.FLAG_SECURE |
| 416 | | DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS; |
| 417 | } |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 418 | |
Adrian Roos | 30f5321 | 2018-01-05 16:14:34 +0100 | [diff] [blame] | 419 | final Resources res = getOverlayContext().getResources(); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 420 | if (mIsInternal) { |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 421 | mInfo.name = res.getString( |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 422 | com.android.internal.R.string.display_manager_built_in_display_name); |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 423 | mInfo.flags |= DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 424 | | DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT; |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 425 | if (res.getBoolean(com.android.internal.R.bool.config_mainBuiltInDisplayIsRound) |
Griff Hazen | d3c454d | 2016-03-25 07:30:34 -0700 | [diff] [blame] | 426 | || (Build.IS_EMULATOR |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 427 | && SystemProperties.getBoolean(PROPERTY_EMULATOR_CIRCULAR, false))) { |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 428 | mInfo.flags |= DisplayDeviceInfo.FLAG_ROUND; |
| 429 | } |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 430 | if (res.getBoolean( |
| 431 | com.android.internal.R.bool.config_maskMainBuiltInDisplayCutout)) { |
| 432 | mInfo.flags |= DisplayDeviceInfo.FLAG_MASK_DISPLAY_CUTOUT; |
| 433 | } |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 434 | mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res, |
| 435 | mInfo.width, mInfo.height); |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 436 | mInfo.type = Display.TYPE_BUILT_IN; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 437 | mInfo.densityDpi = (int)(phys.density * 160 + 0.5f); |
| 438 | mInfo.xDpi = phys.xDpi; |
| 439 | mInfo.yDpi = phys.yDpi; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 440 | mInfo.touch = DisplayDeviceInfo.TOUCH_INTERNAL; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 441 | } else { |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 442 | mInfo.displayCutout = null; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 443 | mInfo.type = Display.TYPE_HDMI; |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 444 | mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 445 | mInfo.name = getContext().getResources().getString( |
| 446 | com.android.internal.R.string.display_manager_hdmi_display_name); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 447 | mInfo.touch = DisplayDeviceInfo.TOUCH_EXTERNAL; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 448 | mInfo.setAssumedDensityForExternalDisplay(phys.width, phys.height); |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 449 | |
| 450 | // For demonstration purposes, allow rotation of the external display. |
| 451 | // In the future we might allow the user to configure this directly. |
| 452 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
| 453 | mInfo.rotation = Surface.ROTATION_270; |
| 454 | } |
Scott Anderson | 8786ed9 | 2013-11-01 13:27:39 -0700 | [diff] [blame] | 455 | |
| 456 | // For demonstration purposes, allow rotation of the external display |
| 457 | // to follow the built-in display. |
| 458 | if (SystemProperties.getBoolean("persist.demo.hdmirotates", false)) { |
| 459 | mInfo.flags |= DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT; |
| 460 | } |
Michael Wright | 4b0fa17 | 2016-03-11 17:15:24 -0800 | [diff] [blame] | 461 | |
| 462 | if (!res.getBoolean( |
| 463 | com.android.internal.R.bool.config_localDisplaysMirrorContent)) { |
| 464 | mInfo.flags |= DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY; |
| 465 | } |
Pavel Maltsev | a6fec7b | 2018-04-04 10:14:55 -0700 | [diff] [blame] | 466 | |
Keun young Park | abf38e3 | 2019-04-23 19:18:34 -0700 | [diff] [blame] | 467 | if (isDisplayPrivate(physicalAddress)) { |
Pavel Maltsev | a6fec7b | 2018-04-04 10:14:55 -0700 | [diff] [blame] | 468 | mInfo.flags |= DisplayDeviceInfo.FLAG_PRIVATE; |
| 469 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | return mInfo; |
| 473 | } |
| 474 | |
| 475 | @Override |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 476 | public Runnable requestDisplayStateLocked(final int state, final int brightness) { |
| 477 | // Assume that the brightness is off if the display is being turned off. |
| 478 | assert state != Display.STATE_OFF || brightness == PowerManager.BRIGHTNESS_OFF; |
| 479 | |
| 480 | final boolean stateChanged = (mState != state); |
| 481 | final boolean brightnessChanged = (mBrightness != brightness) && mBacklight != null; |
| 482 | if (stateChanged || brightnessChanged) { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 483 | final long physicalDisplayId = mPhysicalDisplayId; |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 484 | final IBinder token = getDisplayTokenLocked(); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 485 | final int oldState = mState; |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 486 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 487 | if (stateChanged) { |
| 488 | mState = state; |
| 489 | updateDeviceInfoLocked(); |
| 490 | } |
| 491 | |
| 492 | if (brightnessChanged) { |
| 493 | mBrightness = brightness; |
| 494 | } |
| 495 | |
| 496 | // Defer actually setting the display state until after we have exited |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 497 | // the critical section since it can take hundreds of milliseconds |
| 498 | // to complete. |
| 499 | return new Runnable() { |
| 500 | @Override |
| 501 | public void run() { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 502 | // Exit a suspended state before making any changes. |
| 503 | int currentState = oldState; |
| 504 | if (Display.isSuspendedState(oldState) |
| 505 | || oldState == Display.STATE_UNKNOWN) { |
| 506 | if (!Display.isSuspendedState(state)) { |
| 507 | setDisplayState(state); |
| 508 | currentState = state; |
| 509 | } else if (state == Display.STATE_DOZE_SUSPEND |
| 510 | || oldState == Display.STATE_DOZE_SUSPEND) { |
| 511 | setDisplayState(Display.STATE_DOZE); |
| 512 | currentState = Display.STATE_DOZE; |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 513 | } else if (state == Display.STATE_ON_SUSPEND |
| 514 | || oldState == Display.STATE_ON_SUSPEND) { |
| 515 | setDisplayState(Display.STATE_ON); |
| 516 | currentState = Display.STATE_ON; |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 517 | } else { |
| 518 | return; // old state and new state is off |
| 519 | } |
| 520 | } |
| 521 | |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 522 | // 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] | 523 | // so that it can apply appropriate VR brightness settings. Also, update the |
| 524 | // brightness so the state is propogated to light. |
| 525 | boolean vrModeChange = false; |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 526 | if ((state == Display.STATE_VR || currentState == Display.STATE_VR) && |
| 527 | currentState != state) { |
| 528 | setVrMode(state == Display.STATE_VR); |
Karthik Ravi Shankar | 6685531 | 2017-10-04 13:30:13 -0700 | [diff] [blame] | 529 | vrModeChange = true; |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 533 | // 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] | 534 | if (brightnessChanged || vrModeChange) { |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 535 | setDisplayBrightness(brightness); |
| 536 | } |
| 537 | |
| 538 | // Enter the final desired state, possibly suspended. |
| 539 | if (state != currentState) { |
| 540 | setDisplayState(state); |
| 541 | } |
| 542 | } |
| 543 | |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 544 | private void setVrMode(boolean isVrEnabled) { |
| 545 | if (DEBUG) { |
| 546 | Slog.d(TAG, "setVrMode(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 547 | + "id=" + physicalDisplayId |
Santos Cordon | d6a5660 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 548 | + ", state=" + Display.stateToString(state) + ")"); |
| 549 | } |
| 550 | mBacklight.setVrMode(isVrEnabled); |
| 551 | } |
| 552 | |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 553 | private void setDisplayState(int state) { |
| 554 | if (DEBUG) { |
| 555 | Slog.d(TAG, "setDisplayState(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 556 | + "id=" + physicalDisplayId |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 557 | + ", state=" + Display.stateToString(state) + ")"); |
| 558 | } |
| 559 | |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 560 | // We must tell sidekick to stop controlling the display before we |
| 561 | // can change its power mode, so do that first. |
| 562 | if (mSidekickActive) { |
| 563 | Trace.traceBegin(Trace.TRACE_TAG_POWER, |
| 564 | "SidekickInternal#endDisplayControl"); |
| 565 | try { |
| 566 | mSidekickInternal.endDisplayControl(); |
| 567 | } finally { |
| 568 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 569 | } |
| 570 | mSidekickActive = false; |
| 571 | } |
| 572 | final int mode = getPowerModeForState(state); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 573 | Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayState(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 574 | + "id=" + physicalDisplayId |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 575 | + ", state=" + Display.stateToString(state) + ")"); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 576 | try { |
| 577 | SurfaceControl.setDisplayPowerMode(token, mode); |
Michael Wright | c3e6af8 | 2017-07-25 22:31:03 +0100 | [diff] [blame] | 578 | Trace.traceCounter(Trace.TRACE_TAG_POWER, "DisplayPowerMode", mode); |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 579 | } finally { |
| 580 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 581 | } |
Chris Phoenix | bc839a3 | 2017-10-21 14:46:15 -0700 | [diff] [blame] | 582 | // If we're entering a suspended (but not OFF) power state and we |
| 583 | // have a sidekick available, tell it now that it can take control. |
| 584 | if (Display.isSuspendedState(state) && state != Display.STATE_OFF |
| 585 | && mSidekickInternal != null && !mSidekickActive) { |
| 586 | Trace.traceBegin(Trace.TRACE_TAG_POWER, |
| 587 | "SidekickInternal#startDisplayControl"); |
| 588 | try { |
| 589 | mSidekickActive = mSidekickInternal.startDisplayControl(state); |
| 590 | } finally { |
| 591 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 592 | } |
| 593 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 594 | } |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 595 | |
| 596 | private void setDisplayBrightness(int brightness) { |
| 597 | if (DEBUG) { |
| 598 | Slog.d(TAG, "setDisplayBrightness(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 599 | + "id=" + physicalDisplayId |
| 600 | + ", brightness=" + brightness + ")"); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayBrightness(" |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 604 | + "id=" + physicalDisplayId + ", brightness=" + brightness + ")"); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 605 | try { |
| 606 | mBacklight.setBrightness(brightness); |
Michael Wright | c3e6af8 | 2017-07-25 22:31:03 +0100 | [diff] [blame] | 607 | Trace.traceCounter(Trace.TRACE_TAG_POWER, |
Michael Wright | a9f37ab | 2017-08-15 17:14:20 +0100 | [diff] [blame] | 608 | "ScreenBrightness", brightness); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 609 | } finally { |
| 610 | Trace.traceEnd(Trace.TRACE_TAG_POWER); |
| 611 | } |
| 612 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 613 | }; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 614 | } |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 615 | return null; |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | @Override |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 619 | public void setRequestedColorModeLocked(int colorMode) { |
| 620 | if (requestColorModeLocked(colorMode)) { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 621 | updateDeviceInfoLocked(); |
| 622 | } |
| 623 | } |
| 624 | |
Adrian Roos | 898ec38 | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 625 | @Override |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 626 | public void setAllowedDisplayModesLocked(int[] modes) { |
| 627 | updateAllowedModesLocked(modes); |
| 628 | } |
| 629 | |
| 630 | @Override |
Adrian Roos | 898ec38 | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 631 | public void onOverlayChangedLocked() { |
| 632 | updateDeviceInfoLocked(); |
| 633 | } |
| 634 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 635 | public void onActivePhysicalDisplayModeChangedLocked(int physIndex) { |
| 636 | if (updateActiveModeLocked(physIndex)) { |
| 637 | updateDeviceInfoLocked(); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 638 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 639 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 640 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 641 | public boolean updateActiveModeLocked(int activePhysIndex) { |
| 642 | if (mActivePhysIndex == activePhysIndex) { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 643 | return false; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 644 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 645 | mActivePhysIndex = activePhysIndex; |
| 646 | mActiveModeId = findMatchingModeIdLocked(activePhysIndex); |
| 647 | mActiveModeInvalid = mActiveModeId == 0; |
| 648 | if (mActiveModeInvalid) { |
| 649 | Slog.w(TAG, "In unknown mode after setting allowed configs" |
| 650 | + ": allowedPhysIndexes=" + mAllowedPhysIndexes |
| 651 | + ", activePhysIndex=" + mActivePhysIndex); |
| 652 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 653 | return true; |
| 654 | } |
| 655 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 656 | public void updateAllowedModesLocked(int[] allowedModes) { |
| 657 | if (Arrays.equals(allowedModes, mAllowedModeIds) && !mAllowedModeIdsInvalid) { |
| 658 | return; |
| 659 | } |
| 660 | if (updateAllowedModesInternalLocked(allowedModes)) { |
| 661 | updateDeviceInfoLocked(); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | public boolean updateAllowedModesInternalLocked(int[] allowedModes) { |
| 666 | if (DEBUG) { |
| 667 | Slog.w(TAG, "updateAllowedModesInternalLocked(allowedModes=" |
| 668 | + Arrays.toString(allowedModes) + ")"); |
| 669 | } |
| 670 | int[] allowedPhysIndexes = new int[allowedModes.length]; |
| 671 | int size = 0; |
| 672 | for (int modeId : allowedModes) { |
| 673 | int physIndex = findDisplayInfoIndexLocked(modeId); |
| 674 | if (physIndex < 0) { |
| 675 | Slog.w(TAG, "Requested mode ID " + modeId + " not available," |
| 676 | + " dropping from allowed set."); |
| 677 | } else { |
| 678 | allowedPhysIndexes[size++] = physIndex; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | // If we couldn't find one or more of the suggested allowed modes then we need to |
| 683 | // shrink the array to its actual size. |
| 684 | if (size != allowedModes.length) { |
| 685 | allowedPhysIndexes = Arrays.copyOf(allowedPhysIndexes, size); |
| 686 | } |
| 687 | |
| 688 | // If we found no suitable modes, then we try again with the default mode which we |
| 689 | // assume has a suitable physical config. |
| 690 | if (size == 0) { |
| 691 | if (DEBUG) { |
| 692 | Slog.w(TAG, "No valid modes allowed, falling back to default mode (id=" |
| 693 | + mDefaultModeId + ")"); |
| 694 | } |
| 695 | allowedModes = new int[] { mDefaultModeId }; |
| 696 | allowedPhysIndexes = new int[] { findDisplayInfoIndexLocked(mDefaultModeId) }; |
| 697 | } |
| 698 | |
| 699 | mAllowedModeIds = allowedModes; |
| 700 | mAllowedModeIdsInvalid = false; |
| 701 | |
| 702 | if (Arrays.equals(mAllowedPhysIndexes, allowedPhysIndexes)) { |
| 703 | return false; |
| 704 | } |
| 705 | mAllowedPhysIndexes = allowedPhysIndexes; |
| 706 | |
| 707 | if (DEBUG) { |
| 708 | Slog.w(TAG, "Setting allowed physical configs: allowedPhysIndexes=" |
| 709 | + Arrays.toString(allowedPhysIndexes)); |
| 710 | } |
| 711 | |
| 712 | SurfaceControl.setAllowedDisplayConfigs(getDisplayTokenLocked(), allowedPhysIndexes); |
| 713 | int activePhysIndex = SurfaceControl.getActiveConfig(getDisplayTokenLocked()); |
| 714 | return updateActiveModeLocked(activePhysIndex); |
| 715 | } |
| 716 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 717 | public boolean requestColorModeLocked(int colorMode) { |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 718 | if (mActiveColorMode == colorMode) { |
| 719 | return false; |
| 720 | } |
| 721 | if (!mSupportedColorModes.contains(colorMode)) { |
| 722 | Slog.w(TAG, "Unable to find color mode " + colorMode |
| 723 | + ", ignoring request."); |
| 724 | return false; |
| 725 | } |
| 726 | SurfaceControl.setActiveColorMode(getDisplayTokenLocked(), colorMode); |
| 727 | mActiveColorMode = colorMode; |
| 728 | mActiveColorModeInvalid = false; |
| 729 | return true; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 733 | public void dumpLocked(PrintWriter pw) { |
| 734 | super.dumpLocked(pw); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 735 | pw.println("mPhysicalDisplayId=" + mPhysicalDisplayId); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 736 | pw.println("mAllowedPhysIndexes=" + Arrays.toString(mAllowedPhysIndexes)); |
| 737 | pw.println("mAllowedModeIds=" + Arrays.toString(mAllowedModeIds)); |
| 738 | pw.println("mAllowedModeIdsInvalid=" + mAllowedModeIdsInvalid); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 739 | pw.println("mActivePhysIndex=" + mActivePhysIndex); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 740 | pw.println("mActiveModeId=" + mActiveModeId); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 741 | pw.println("mActiveColorMode=" + mActiveColorMode); |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 742 | pw.println("mDefaultModeId=" + mDefaultModeId); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 743 | pw.println("mState=" + Display.stateToString(mState)); |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 744 | pw.println("mBrightness=" + mBrightness); |
| 745 | pw.println("mBacklight=" + mBacklight); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 746 | pw.println("mDisplayInfos="); |
| 747 | for (int i = 0; i < mDisplayInfos.length; i++) { |
| 748 | pw.println(" " + mDisplayInfos[i]); |
| 749 | } |
| 750 | pw.println("mSupportedModes="); |
| 751 | for (int i = 0; i < mSupportedModes.size(); i++) { |
| 752 | pw.println(" " + mSupportedModes.valueAt(i)); |
| 753 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 754 | pw.print("mSupportedColorModes=["); |
| 755 | for (int i = 0; i < mSupportedColorModes.size(); i++) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 756 | if (i != 0) { |
| 757 | pw.print(", "); |
| 758 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 759 | pw.print(mSupportedColorModes.get(i)); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 760 | } |
| 761 | pw.println("]"); |
| 762 | } |
| 763 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 764 | private int findDisplayInfoIndexLocked(int modeId) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 765 | DisplayModeRecord record = mSupportedModes.get(modeId); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 766 | if (record != null) { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 767 | for (int i = 0; i < mDisplayInfos.length; i++) { |
| 768 | SurfaceControl.PhysicalDisplayInfo info = mDisplayInfos[i]; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 769 | if (record.hasMatchingMode(info)){ |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 770 | return i; |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | return -1; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 777 | private int findMatchingModeIdLocked(int physIndex) { |
| 778 | SurfaceControl.PhysicalDisplayInfo info = mDisplayInfos[physIndex]; |
| 779 | for (int i = 0; i < mSupportedModes.size(); i++) { |
| 780 | DisplayModeRecord record = mSupportedModes.valueAt(i); |
| 781 | if (record.hasMatchingMode(info)) { |
| 782 | return record.mMode.getModeId(); |
| 783 | } |
| 784 | } |
| 785 | return 0; |
| 786 | } |
| 787 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 788 | private void updateDeviceInfoLocked() { |
| 789 | mInfo = null; |
| 790 | sendDisplayDeviceEventLocked(this, DISPLAY_DEVICE_EVENT_CHANGED); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 791 | } |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 792 | |
| 793 | private Display.Mode[] getDisplayModes(SparseArray<DisplayModeRecord> records) { |
| 794 | final int size = records.size(); |
| 795 | Display.Mode[] modes = new Display.Mode[size]; |
| 796 | for (int i = 0; i < size; i++) { |
| 797 | DisplayModeRecord record = records.valueAt(i); |
| 798 | modes[i] = record.mMode; |
| 799 | } |
| 800 | return modes; |
| 801 | } |
Keun young Park | abf38e3 | 2019-04-23 19:18:34 -0700 | [diff] [blame] | 802 | |
| 803 | private boolean isDisplayPrivate(DisplayAddress.Physical physicalAddress) { |
| 804 | if (physicalAddress == null) { |
| 805 | return false; |
| 806 | } |
| 807 | final Resources res = getOverlayContext().getResources(); |
| 808 | int[] ports = res.getIntArray( |
| 809 | com.android.internal.R.array.config_localPrivateDisplayPorts); |
| 810 | if (ports != null) { |
| 811 | int port = physicalAddress.getPort(); |
| 812 | for (int p : ports) { |
| 813 | if (p == port) { |
| 814 | return true; |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | return false; |
| 819 | } |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 820 | } |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 821 | |
Adrian Roos | 30f5321 | 2018-01-05 16:14:34 +0100 | [diff] [blame] | 822 | /** Supplies a context whose Resources apply runtime-overlays */ |
| 823 | Context getOverlayContext() { |
| 824 | return ActivityThread.currentActivityThread().getSystemUiContext(); |
| 825 | } |
| 826 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 827 | /** |
| 828 | * Keeps track of a display configuration. |
| 829 | */ |
| 830 | private static final class DisplayModeRecord { |
| 831 | public final Display.Mode mMode; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 832 | |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 833 | public DisplayModeRecord(SurfaceControl.PhysicalDisplayInfo phys) { |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 834 | mMode = createMode(phys.width, phys.height, phys.refreshRate); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /** |
| 838 | * Returns whether the mode generated by the given PhysicalDisplayInfo matches the mode |
| 839 | * contained by the record modulo mode ID. |
| 840 | * |
| 841 | * Note that this doesn't necessarily mean the the PhysicalDisplayInfos are identical, just |
| 842 | * that they generate identical modes. |
| 843 | */ |
| 844 | public boolean hasMatchingMode(SurfaceControl.PhysicalDisplayInfo info) { |
| 845 | int modeRefreshRate = Float.floatToIntBits(mMode.getRefreshRate()); |
| 846 | int displayInfoRefreshRate = Float.floatToIntBits(info.refreshRate); |
| 847 | return mMode.getPhysicalWidth() == info.width |
| 848 | && mMode.getPhysicalHeight() == info.height |
| 849 | && modeRefreshRate == displayInfoRefreshRate; |
| 850 | } |
| 851 | |
| 852 | public String toString() { |
| 853 | return "DisplayModeRecord{mMode=" + mMode + "}"; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 854 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 855 | } |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 856 | |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 857 | private final class PhysicalDisplayEventReceiver extends DisplayEventReceiver { |
| 858 | PhysicalDisplayEventReceiver(Looper looper) { |
Jorim Jaggi | 34a0cdb | 2017-06-08 15:40:38 -0700 | [diff] [blame] | 859 | super(looper, VSYNC_SOURCE_APP); |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | @Override |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 863 | public void onHotplug(long timestampNanos, long physicalDisplayId, boolean connected) { |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 864 | synchronized (getSyncRoot()) { |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 865 | if (connected) { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 866 | tryConnectDisplayLocked(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 867 | } else { |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 868 | tryDisconnectDisplayLocked(physicalDisplayId); |
Jesse Hall | e244db4 | 2012-11-08 11:55:14 -0800 | [diff] [blame] | 869 | } |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 870 | } |
| 871 | } |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 872 | |
| 873 | @Override |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 874 | public void onConfigChanged(long timestampNanos, long physicalDisplayId, int physIndex) { |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 875 | if (DEBUG) { |
| 876 | Slog.d(TAG, "onConfigChanged(" |
| 877 | + "timestampNanos=" + timestampNanos |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 878 | + ", physicalDisplayId=" + physicalDisplayId |
| 879 | + ", physIndex=" + physIndex + ")"); |
| 880 | } |
| 881 | synchronized (getSyncRoot()) { |
| 882 | LocalDisplayDevice device = mDevices.get(physicalDisplayId); |
| 883 | if (device == null) { |
| 884 | if (DEBUG) { |
| 885 | Slog.d(TAG, "Received config change for unhandled physical display: " |
| 886 | + "physicalDisplayId=" + physicalDisplayId); |
| 887 | } |
| 888 | return; |
| 889 | } |
| 890 | device.onActivePhysicalDisplayModeChangedLocked(physIndex); |
Ady Abraham | a5a21f7 | 2019-02-13 16:41:59 -0800 | [diff] [blame] | 891 | } |
| 892 | } |
Jeff Brown | e87bf03 | 2012-09-20 18:30:13 -0700 | [diff] [blame] | 893 | } |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 894 | } |