The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 17 | // #define LOG_NDEBUG 0 |
| 18 | #undef LOG_TAG |
| 19 | #define LOG_TAG "DisplayDevice" |
| 20 | |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 21 | #include "DisplayDevice.h" |
| 22 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 23 | #include <array> |
| 24 | #include <unordered_set> |
| 25 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include <stdlib.h> |
| 27 | #include <stdio.h> |
| 28 | #include <string.h> |
| 29 | #include <math.h> |
| 30 | |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 31 | #include <android-base/stringprintf.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 32 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 33 | #include <compositionengine/CompositionEngine.h> |
| 34 | #include <compositionengine/Display.h> |
| 35 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 36 | #include <compositionengine/DisplaySurface.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 37 | #include <compositionengine/RenderSurface.h> |
| 38 | #include <compositionengine/RenderSurfaceCreationArgs.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 39 | #include <compositionengine/impl/OutputCompositionState.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 40 | #include <configstore/Utils.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | #include <cutils/properties.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 42 | #include <gui/Surface.h> |
| 43 | #include <hardware/gralloc.h> |
| 44 | #include <renderengine/RenderEngine.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 45 | #include <sync/sync.h> |
| 46 | #include <system/window.h> |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 47 | #include <ui/DebugUtils.h> |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 48 | #include <ui/DisplayInfo.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 49 | #include <ui/PixelFormat.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 50 | #include <utils/Log.h> |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 51 | #include <utils/RefBase.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 53 | #include "DisplayHardware/HWComposer.h" |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 54 | #include "DisplayHardware/HWC2.h" |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 55 | #include "SurfaceFlinger.h" |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 56 | #include "Layer.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 57 | |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 58 | namespace android { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 60 | // retrieve triple buffer setting from configstore |
| 61 | using namespace android::hardware::configstore; |
| 62 | using namespace android::hardware::configstore::V1_0; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 63 | using android::base::StringAppendF; |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 64 | using android::ui::ColorMode; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 65 | using android::ui::Dataspace; |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 66 | using android::ui::Hdr; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 67 | using android::ui::RenderIntent; |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 68 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | /* |
| 70 | * Initialize the display to the specified values. |
| 71 | * |
| 72 | */ |
| 73 | |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 74 | uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0; |
| 75 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 76 | namespace { |
| 77 | |
| 78 | // ordered list of known SDR color modes |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 79 | const std::array<ColorMode, 3> sSdrColorModes = { |
| 80 | ColorMode::DISPLAY_BT2020, |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 81 | ColorMode::DISPLAY_P3, |
| 82 | ColorMode::SRGB, |
| 83 | }; |
| 84 | |
| 85 | // ordered list of known HDR color modes |
| 86 | const std::array<ColorMode, 2> sHdrColorModes = { |
| 87 | ColorMode::BT2100_PQ, |
| 88 | ColorMode::BT2100_HLG, |
| 89 | }; |
| 90 | |
| 91 | // ordered list of known SDR render intents |
| 92 | const std::array<RenderIntent, 2> sSdrRenderIntents = { |
| 93 | RenderIntent::ENHANCE, |
| 94 | RenderIntent::COLORIMETRIC, |
| 95 | }; |
| 96 | |
| 97 | // ordered list of known HDR render intents |
| 98 | const std::array<RenderIntent, 2> sHdrRenderIntents = { |
| 99 | RenderIntent::TONE_MAP_ENHANCE, |
| 100 | RenderIntent::TONE_MAP_COLORIMETRIC, |
| 101 | }; |
| 102 | |
| 103 | // map known color mode to dataspace |
| 104 | Dataspace colorModeToDataspace(ColorMode mode) { |
| 105 | switch (mode) { |
| 106 | case ColorMode::SRGB: |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 107 | return Dataspace::V0_SRGB; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 108 | case ColorMode::DISPLAY_P3: |
| 109 | return Dataspace::DISPLAY_P3; |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 110 | case ColorMode::DISPLAY_BT2020: |
| 111 | return Dataspace::DISPLAY_BT2020; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 112 | case ColorMode::BT2100_HLG: |
| 113 | return Dataspace::BT2020_HLG; |
| 114 | case ColorMode::BT2100_PQ: |
| 115 | return Dataspace::BT2020_PQ; |
| 116 | default: |
| 117 | return Dataspace::UNKNOWN; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // Return a list of candidate color modes. |
| 122 | std::vector<ColorMode> getColorModeCandidates(ColorMode mode) { |
| 123 | std::vector<ColorMode> candidates; |
| 124 | |
| 125 | // add mode itself |
| 126 | candidates.push_back(mode); |
| 127 | |
| 128 | // check if mode is HDR |
| 129 | bool isHdr = false; |
| 130 | for (auto hdrMode : sHdrColorModes) { |
| 131 | if (hdrMode == mode) { |
| 132 | isHdr = true; |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // add other HDR candidates when mode is HDR |
| 138 | if (isHdr) { |
| 139 | for (auto hdrMode : sHdrColorModes) { |
| 140 | if (hdrMode != mode) { |
| 141 | candidates.push_back(hdrMode); |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // add other SDR candidates |
| 147 | for (auto sdrMode : sSdrColorModes) { |
| 148 | if (sdrMode != mode) { |
| 149 | candidates.push_back(sdrMode); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | return candidates; |
| 154 | } |
| 155 | |
| 156 | // Return a list of candidate render intents. |
| 157 | std::vector<RenderIntent> getRenderIntentCandidates(RenderIntent intent) { |
| 158 | std::vector<RenderIntent> candidates; |
| 159 | |
| 160 | // add intent itself |
| 161 | candidates.push_back(intent); |
| 162 | |
| 163 | // check if intent is HDR |
| 164 | bool isHdr = false; |
| 165 | for (auto hdrIntent : sHdrRenderIntents) { |
| 166 | if (hdrIntent == intent) { |
| 167 | isHdr = true; |
| 168 | break; |
| 169 | } |
| 170 | } |
| 171 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 172 | if (isHdr) { |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 173 | // add other HDR candidates when intent is HDR |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 174 | for (auto hdrIntent : sHdrRenderIntents) { |
| 175 | if (hdrIntent != intent) { |
| 176 | candidates.push_back(hdrIntent); |
| 177 | } |
| 178 | } |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 179 | } else { |
| 180 | // add other SDR candidates when intent is SDR |
| 181 | for (auto sdrIntent : sSdrRenderIntents) { |
| 182 | if (sdrIntent != intent) { |
| 183 | candidates.push_back(sdrIntent); |
| 184 | } |
| 185 | } |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | return candidates; |
| 189 | } |
| 190 | |
| 191 | // Return the best color mode supported by HWC. |
| 192 | ColorMode getHwcColorMode( |
| 193 | const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes, |
| 194 | ColorMode mode) { |
| 195 | std::vector<ColorMode> candidates = getColorModeCandidates(mode); |
| 196 | for (auto candidate : candidates) { |
| 197 | auto iter = hwcColorModes.find(candidate); |
| 198 | if (iter != hwcColorModes.end()) { |
| 199 | return candidate; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | return ColorMode::NATIVE; |
| 204 | } |
| 205 | |
| 206 | // Return the best render intent supported by HWC. |
| 207 | RenderIntent getHwcRenderIntent(const std::vector<RenderIntent>& hwcIntents, RenderIntent intent) { |
| 208 | std::vector<RenderIntent> candidates = getRenderIntentCandidates(intent); |
| 209 | for (auto candidate : candidates) { |
| 210 | for (auto hwcIntent : hwcIntents) { |
| 211 | if (candidate == hwcIntent) { |
| 212 | return candidate; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | return RenderIntent::COLORIMETRIC; |
| 218 | } |
| 219 | |
| 220 | } // anonymous namespace |
| 221 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 222 | DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger, |
| 223 | const wp<IBinder>& displayToken, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 224 | const std::optional<DisplayId>& displayId) |
| 225 | : flinger(flinger), displayToken(displayToken), displayId(displayId) {} |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 226 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 227 | DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args) |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 228 | : mFlinger(args.flinger), |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 229 | mDisplayToken(args.displayToken), |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 230 | mSequenceId(args.sequenceId), |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 231 | mDisplayInstallOrientation(args.displayInstallOrientation), |
| 232 | mCompositionDisplay{mFlinger->getCompositionEngine().createDisplay( |
| 233 | compositionengine::DisplayCreationArgs{args.isSecure, args.isVirtual, |
| 234 | args.displayId})}, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 235 | mIsVirtual(args.isVirtual), |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 236 | mOrientation(), |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 237 | mActiveConfig(0), |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 238 | mHasWideColorGamut(args.hasWideColorGamut), |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 239 | mHasHdr10Plus(false), |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 240 | mHasHdr10(false), |
| 241 | mHasHLG(false), |
| 242 | mHasDolbyVision(false), |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 243 | mSupportedPerFrameMetadata(args.supportedPerFrameMetadata), |
| 244 | mIsPrimary(args.isPrimary) { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 245 | mCompositionDisplay->createRenderSurface( |
| 246 | compositionengine::RenderSurfaceCreationArgs{ANativeWindow_getWidth( |
| 247 | args.nativeWindow.get()), |
| 248 | ANativeWindow_getHeight( |
| 249 | args.nativeWindow.get()), |
| 250 | args.nativeWindow, args.displaySurface}); |
| 251 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 252 | if (!mCompositionDisplay->isValid()) { |
| 253 | ALOGE("Composition Display did not validate!"); |
| 254 | } |
| 255 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 256 | mCompositionDisplay->getRenderSurface()->initialize(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 257 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 258 | populateColorModes(args.hwcColorModes); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 259 | |
| 260 | std::vector<Hdr> types = args.hdrCapabilities.getSupportedHdrTypes(); |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 261 | for (Hdr hdrType : types) { |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 262 | switch (hdrType) { |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 263 | case Hdr::HDR10_PLUS: |
| 264 | mHasHdr10Plus = true; |
| 265 | break; |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 266 | case Hdr::HDR10: |
| 267 | mHasHdr10 = true; |
| 268 | break; |
| 269 | case Hdr::HLG: |
| 270 | mHasHLG = true; |
| 271 | break; |
| 272 | case Hdr::DOLBY_VISION: |
| 273 | mHasDolbyVision = true; |
| 274 | break; |
| 275 | default: |
| 276 | ALOGE("UNKNOWN HDR capability: %d", static_cast<int32_t>(hdrType)); |
| 277 | } |
| 278 | } |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 279 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 280 | float minLuminance = args.hdrCapabilities.getDesiredMinLuminance(); |
| 281 | float maxLuminance = args.hdrCapabilities.getDesiredMaxLuminance(); |
| 282 | float maxAverageLuminance = args.hdrCapabilities.getDesiredMaxAverageLuminance(); |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 283 | |
| 284 | minLuminance = minLuminance <= 0.0 ? sDefaultMinLumiance : minLuminance; |
| 285 | maxLuminance = maxLuminance <= 0.0 ? sDefaultMaxLumiance : maxLuminance; |
| 286 | maxAverageLuminance = maxAverageLuminance <= 0.0 ? sDefaultMaxLumiance : maxAverageLuminance; |
| 287 | if (this->hasWideColorGamut()) { |
| 288 | // insert HDR10/HLG as we will force client composition for HDR10/HLG |
| 289 | // layers |
| 290 | if (!hasHDR10Support()) { |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 291 | types.push_back(Hdr::HDR10); |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | if (!hasHLGSupport()) { |
Valerie Hau | e9e843a | 2018-12-18 13:39:23 -0800 | [diff] [blame] | 295 | types.push_back(Hdr::HLG); |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | mHdrCapabilities = HdrCapabilities(types, maxLuminance, maxAverageLuminance, minLuminance); |
| 299 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 300 | setPowerMode(args.initialPowerMode); |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 301 | |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 302 | // initialize the display orientation transform. |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 303 | setProjection(DisplayState::eOrientationDefault, Rect::INVALID_RECT, Rect::INVALID_RECT); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 306 | DisplayDevice::~DisplayDevice() = default; |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 307 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 308 | void DisplayDevice::disconnect() { |
| 309 | mCompositionDisplay->disconnect(); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 312 | int DisplayDevice::getWidth() const { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 313 | return mCompositionDisplay->getState().bounds.getWidth(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 316 | int DisplayDevice::getHeight() const { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 317 | return mCompositionDisplay->getState().bounds.getHeight(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 320 | void DisplayDevice::setDisplayName(const std::string& displayName) { |
| 321 | if (!displayName.empty()) { |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 322 | // never override the name with an empty name |
| 323 | mDisplayName = displayName; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 324 | mCompositionDisplay->setName(displayName); |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 328 | uint32_t DisplayDevice::getPageFlipCount() const { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 329 | return mCompositionDisplay->getRenderSurface()->getPageFlipCount(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 330 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 331 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 332 | // ---------------------------------------------------------------------------- |
| 333 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 334 | void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 335 | mVisibleLayersSortedByZ = layers; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 338 | const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 339 | return mVisibleLayersSortedByZ; |
| 340 | } |
| 341 | |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 342 | void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) { |
| 343 | mLayersNeedingFences = layers; |
| 344 | } |
| 345 | |
| 346 | const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const { |
| 347 | return mLayersNeedingFences; |
| 348 | } |
| 349 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 350 | // ---------------------------------------------------------------------------- |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 351 | void DisplayDevice::setPowerMode(int mode) { |
| 352 | mPowerMode = mode; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 353 | getCompositionDisplay()->setCompositionEnabled(mPowerMode != HWC_POWER_MODE_OFF); |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 356 | int DisplayDevice::getPowerMode() const { |
| 357 | return mPowerMode; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 360 | bool DisplayDevice::isPoweredOn() const { |
| 361 | return mPowerMode != HWC_POWER_MODE_OFF; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | // ---------------------------------------------------------------------------- |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 365 | void DisplayDevice::setActiveConfig(int mode) { |
| 366 | mActiveConfig = mode; |
| 367 | } |
| 368 | |
| 369 | int DisplayDevice::getActiveConfig() const { |
| 370 | return mActiveConfig; |
| 371 | } |
| 372 | |
| 373 | // ---------------------------------------------------------------------------- |
Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 374 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 375 | ui::Dataspace DisplayDevice::getCompositionDataSpace() const { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 376 | return mCompositionDisplay->getState().dataspace; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 379 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 380 | |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 381 | void DisplayDevice::setLayerStack(uint32_t stack) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 382 | mCompositionDisplay->setLayerStackFilter(!isPrimary(), stack); |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | // ---------------------------------------------------------------------------- |
| 386 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 387 | uint32_t DisplayDevice::displayStateOrientationToTransformOrientation(int orientation) { |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 388 | switch (orientation) { |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 389 | case DisplayState::eOrientationDefault: |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 390 | return ui::Transform::ROT_0; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 391 | case DisplayState::eOrientation90: |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 392 | return ui::Transform::ROT_90; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 393 | case DisplayState::eOrientation180: |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 394 | return ui::Transform::ROT_180; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 395 | case DisplayState::eOrientation270: |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 396 | return ui::Transform::ROT_270; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 397 | default: |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 398 | return ui::Transform::ROT_INVALID; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | status_t DisplayDevice::orientationToTransfrom(int orientation, int w, int h, ui::Transform* tr) { |
| 403 | uint32_t flags = displayStateOrientationToTransformOrientation(orientation); |
| 404 | if (flags == ui::Transform::ROT_INVALID) { |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 405 | return BAD_VALUE; |
| 406 | } |
| 407 | tr->set(flags, w, h); |
| 408 | return NO_ERROR; |
| 409 | } |
| 410 | |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 411 | void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 412 | mCompositionDisplay->setBounds(ui::Size(newWidth, newHeight)); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 415 | void DisplayDevice::setProjection(int orientation, |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 416 | const Rect& newViewport, const Rect& newFrame) { |
| 417 | Rect viewport(newViewport); |
| 418 | Rect frame(newFrame); |
| 419 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 420 | mOrientation = orientation; |
| 421 | |
| 422 | const Rect& displayBounds = getCompositionDisplay()->getState().bounds; |
| 423 | const int w = displayBounds.width(); |
| 424 | const int h = displayBounds.height(); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 425 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 426 | ui::Transform R; |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 427 | DisplayDevice::orientationToTransfrom(orientation, w, h, &R); |
| 428 | |
| 429 | if (!frame.isValid()) { |
| 430 | // the destination frame can be invalid if it has never been set, |
| 431 | // in that case we assume the whole display frame. |
| 432 | frame = Rect(w, h); |
| 433 | } |
| 434 | |
| 435 | if (viewport.isEmpty()) { |
| 436 | // viewport can be invalid if it has never been set, in that case |
| 437 | // we assume the whole display size. |
| 438 | // it's also invalid to have an empty viewport, so we handle that |
| 439 | // case in the same way. |
| 440 | viewport = Rect(w, h); |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 441 | if (R.getOrientation() & ui::Transform::ROT_90) { |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 442 | // viewport is always specified in the logical orientation |
| 443 | // of the display (ie: post-rotation). |
Peiyong Lin | 3db4234 | 2018-08-16 09:15:59 -0700 | [diff] [blame] | 444 | std::swap(viewport.right, viewport.bottom); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 448 | ui::Transform TL, TP, S; |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 449 | float src_width = viewport.width(); |
| 450 | float src_height = viewport.height(); |
| 451 | float dst_width = frame.width(); |
| 452 | float dst_height = frame.height(); |
| 453 | if (src_width != dst_width || src_height != dst_height) { |
| 454 | float sx = dst_width / src_width; |
| 455 | float sy = dst_height / src_height; |
| 456 | S.set(sx, 0, 0, sy); |
| 457 | } |
| 458 | |
| 459 | float src_x = viewport.left; |
| 460 | float src_y = viewport.top; |
| 461 | float dst_x = frame.left; |
| 462 | float dst_y = frame.top; |
| 463 | TL.set(-src_x, -src_y); |
| 464 | TP.set(dst_x, dst_y); |
| 465 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 466 | // need to take care of primary display rotation for globalTransform |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 467 | // for case if the panel is not installed aligned with device orientation |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 468 | if (isPrimary()) { |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 469 | DisplayDevice::orientationToTransfrom( |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 470 | (orientation + mDisplayInstallOrientation) % (DisplayState::eOrientation270 + 1), |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 471 | w, h, &R); |
| 472 | } |
| 473 | |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 474 | // The viewport and frame are both in the logical orientation. |
| 475 | // Apply the logical translation, scale to physical size, apply the |
| 476 | // physical translation and finally rotate to the physical orientation. |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 477 | ui::Transform globalTransform = R * TP * S * TL; |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 478 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 479 | const uint8_t type = globalTransform.getType(); |
| 480 | const bool needsFiltering = |
| 481 | (!globalTransform.preserveRects() || (type >= ui::Transform::SCALE)); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 482 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 483 | Rect scissor = globalTransform.transform(viewport); |
| 484 | if (scissor.isEmpty()) { |
| 485 | scissor = displayBounds; |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 486 | } |
| 487 | |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 488 | if (isPrimary()) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 489 | sPrimaryDisplayOrientation = displayStateOrientationToTransformOrientation(orientation); |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 490 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 491 | |
| 492 | getCompositionDisplay()->setProjection(globalTransform, |
| 493 | displayStateOrientationToTransformOrientation( |
| 494 | orientation), |
| 495 | frame, viewport, scissor, needsFiltering); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 496 | } |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 497 | |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 498 | uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() { |
| 499 | return sPrimaryDisplayOrientation; |
| 500 | } |
| 501 | |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 502 | std::string DisplayDevice::getDebugName() const { |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 503 | const auto id = getId() ? to_string(*getId()) + ", " : std::string(); |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 504 | return base::StringPrintf("DisplayDevice{%s%s%s\"%s\"}", id.c_str(), |
| 505 | isPrimary() ? "primary, " : "", isVirtual() ? "virtual, " : "", |
| 506 | mDisplayName.c_str()); |
| 507 | } |
| 508 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 509 | void DisplayDevice::dump(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 510 | StringAppendF(&result, "+ %s\n", getDebugName().c_str()); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 511 | |
| 512 | result.append(" "); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 513 | StringAppendF(&result, "powerMode=%d, ", mPowerMode); |
| 514 | StringAppendF(&result, "activeConfig=%d, ", mActiveConfig); |
| 515 | StringAppendF(&result, "numLayers=%zu\n", mVisibleLayersSortedByZ.size()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 516 | StringAppendF(&result, "wideColorGamut=%d, ", mHasWideColorGamut); |
| 517 | StringAppendF(&result, "hdr10plus=%d\n", mHasHdr10Plus); |
| 518 | StringAppendF(&result, "hdr10=%d\n", mHasHdr10); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 519 | getCompositionDisplay()->dump(result); |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 520 | } |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 521 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 522 | // Map dataspace/intent to the best matched dataspace/colorMode/renderIntent |
| 523 | // supported by HWC. |
| 524 | void DisplayDevice::addColorMode( |
| 525 | const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes, |
| 526 | const ColorMode mode, const RenderIntent intent) { |
| 527 | // find the best color mode |
| 528 | const ColorMode hwcColorMode = getHwcColorMode(hwcColorModes, mode); |
| 529 | |
| 530 | // find the best render intent |
| 531 | auto iter = hwcColorModes.find(hwcColorMode); |
| 532 | const auto& hwcIntents = |
| 533 | iter != hwcColorModes.end() ? iter->second : std::vector<RenderIntent>(); |
| 534 | const RenderIntent hwcIntent = getHwcRenderIntent(hwcIntents, intent); |
| 535 | |
| 536 | const Dataspace dataspace = colorModeToDataspace(mode); |
| 537 | const Dataspace hwcDataspace = colorModeToDataspace(hwcColorMode); |
| 538 | |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 539 | ALOGV("%s: map (%s, %s) to (%s, %s, %s)", getDebugName().c_str(), |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 540 | dataspaceDetails(static_cast<android_dataspace_t>(dataspace)).c_str(), |
| 541 | decodeRenderIntent(intent).c_str(), |
| 542 | dataspaceDetails(static_cast<android_dataspace_t>(hwcDataspace)).c_str(), |
| 543 | decodeColorMode(hwcColorMode).c_str(), decodeRenderIntent(hwcIntent).c_str()); |
| 544 | |
| 545 | mColorModes[getColorModeKey(dataspace, intent)] = {hwcDataspace, hwcColorMode, hwcIntent}; |
| 546 | } |
| 547 | |
| 548 | void DisplayDevice::populateColorModes( |
| 549 | const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes) { |
| 550 | if (!hasWideColorGamut()) { |
| 551 | return; |
| 552 | } |
| 553 | |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 554 | // collect all known SDR render intents |
| 555 | std::unordered_set<RenderIntent> sdrRenderIntents(sSdrRenderIntents.begin(), |
| 556 | sSdrRenderIntents.end()); |
| 557 | auto iter = hwcColorModes.find(ColorMode::SRGB); |
| 558 | if (iter != hwcColorModes.end()) { |
| 559 | for (auto intent : iter->second) { |
| 560 | sdrRenderIntents.insert(intent); |
| 561 | } |
| 562 | } |
| 563 | |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 564 | // add all known SDR combinations |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 565 | for (auto intent : sdrRenderIntents) { |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 566 | for (auto mode : sSdrColorModes) { |
| 567 | addColorMode(hwcColorModes, mode, intent); |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 568 | } |
| 569 | } |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 570 | |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 571 | // collect all known HDR render intents |
| 572 | std::unordered_set<RenderIntent> hdrRenderIntents(sHdrRenderIntents.begin(), |
| 573 | sHdrRenderIntents.end()); |
| 574 | iter = hwcColorModes.find(ColorMode::BT2100_PQ); |
| 575 | if (iter != hwcColorModes.end()) { |
| 576 | for (auto intent : iter->second) { |
| 577 | hdrRenderIntents.insert(intent); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | // add all known HDR combinations |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 582 | for (auto intent : sHdrRenderIntents) { |
| 583 | for (auto mode : sHdrColorModes) { |
| 584 | addColorMode(hwcColorModes, mode, intent); |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | bool DisplayDevice::hasRenderIntent(RenderIntent intent) const { |
| 590 | // assume a render intent is supported when SRGB supports it; we should |
| 591 | // get rid of that assumption. |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 592 | auto iter = mColorModes.find(getColorModeKey(Dataspace::V0_SRGB, intent)); |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 593 | return iter != mColorModes.end() && iter->second.renderIntent == intent; |
| 594 | } |
| 595 | |
Peiyong Lin | dfde511 | 2018-06-05 10:58:41 -0700 | [diff] [blame] | 596 | bool DisplayDevice::hasLegacyHdrSupport(Dataspace dataspace) const { |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 597 | if ((dataspace == Dataspace::BT2020_PQ && hasHDR10Support()) || |
| 598 | (dataspace == Dataspace::BT2020_HLG && hasHLGSupport())) { |
| 599 | auto iter = |
| 600 | mColorModes.find(getColorModeKey(dataspace, RenderIntent::TONE_MAP_COLORIMETRIC)); |
Peiyong Lin | dfde511 | 2018-06-05 10:58:41 -0700 | [diff] [blame] | 601 | return iter == mColorModes.end() || iter->second.dataspace != dataspace; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | void DisplayDevice::getBestColorMode(Dataspace dataspace, RenderIntent intent, |
| 608 | Dataspace* outDataspace, ColorMode* outMode, |
| 609 | RenderIntent* outIntent) const { |
| 610 | auto iter = mColorModes.find(getColorModeKey(dataspace, intent)); |
| 611 | if (iter != mColorModes.end()) { |
| 612 | *outDataspace = iter->second.dataspace; |
| 613 | *outMode = iter->second.colorMode; |
| 614 | *outIntent = iter->second.renderIntent; |
| 615 | } else { |
Chia-I Wu | 6333af5 | 2018-10-16 13:46:36 -0700 | [diff] [blame] | 616 | // this is unexpected on a WCG display |
| 617 | if (hasWideColorGamut()) { |
| 618 | ALOGE("map unknown (%s)/(%s) to default color mode", |
| 619 | dataspaceDetails(static_cast<android_dataspace_t>(dataspace)).c_str(), |
| 620 | decodeRenderIntent(intent).c_str()); |
| 621 | } |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 622 | |
| 623 | *outDataspace = Dataspace::UNKNOWN; |
| 624 | *outMode = ColorMode::NATIVE; |
| 625 | *outIntent = RenderIntent::COLORIMETRIC; |
| 626 | } |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 629 | // ---------------------------------------------------------------------------- |
| 630 | |
| 631 | const std::optional<DisplayId>& DisplayDevice::getId() const { |
| 632 | return mCompositionDisplay->getId(); |
| 633 | } |
| 634 | |
| 635 | bool DisplayDevice::isSecure() const { |
| 636 | return mCompositionDisplay->isSecure(); |
| 637 | } |
| 638 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 639 | const Rect& DisplayDevice::getBounds() const { |
| 640 | return mCompositionDisplay->getState().bounds; |
| 641 | } |
| 642 | |
| 643 | const Region& DisplayDevice::getUndefinedRegion() const { |
| 644 | return mCompositionDisplay->getState().undefinedRegion; |
| 645 | } |
| 646 | |
| 647 | bool DisplayDevice::needsFiltering() const { |
| 648 | return mCompositionDisplay->getState().needsFiltering; |
| 649 | } |
| 650 | |
| 651 | uint32_t DisplayDevice::getLayerStack() const { |
| 652 | return mCompositionDisplay->getState().singleLayerStackId; |
| 653 | } |
| 654 | |
| 655 | const ui::Transform& DisplayDevice::getTransform() const { |
| 656 | return mCompositionDisplay->getState().transform; |
| 657 | } |
| 658 | |
| 659 | const Rect& DisplayDevice::getViewport() const { |
| 660 | return mCompositionDisplay->getState().viewport; |
| 661 | } |
| 662 | |
| 663 | const Rect& DisplayDevice::getFrame() const { |
| 664 | return mCompositionDisplay->getState().frame; |
| 665 | } |
| 666 | |
| 667 | const Rect& DisplayDevice::getScissor() const { |
| 668 | return mCompositionDisplay->getState().scissor; |
| 669 | } |
| 670 | |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 671 | std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1); |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 672 | |
| 673 | } // namespace android |