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> |
| 33 | #include <configstore/Utils.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include <cutils/properties.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 35 | #include <gui/Surface.h> |
| 36 | #include <hardware/gralloc.h> |
| 37 | #include <renderengine/RenderEngine.h> |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 38 | #include <ui/DebugUtils.h> |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 39 | #include <ui/DisplayInfo.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 40 | #include <ui/PixelFormat.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 41 | #include <utils/Log.h> |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 42 | #include <utils/RefBase.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 44 | #include "DisplayHardware/DisplaySurface.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 45 | #include "DisplayHardware/HWComposer.h" |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 46 | #include "DisplayHardware/HWC2.h" |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 47 | #include "SurfaceFlinger.h" |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 48 | #include "Layer.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 49 | |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 50 | namespace android { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 52 | // retrieve triple buffer setting from configstore |
| 53 | using namespace android::hardware::configstore; |
| 54 | using namespace android::hardware::configstore::V1_0; |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 55 | using android::ui::ColorMode; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 56 | using android::ui::Dataspace; |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 57 | using android::ui::Hdr; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 58 | using android::ui::RenderIntent; |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 59 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | /* |
| 61 | * Initialize the display to the specified values. |
| 62 | * |
| 63 | */ |
| 64 | |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 65 | uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0; |
| 66 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 67 | namespace { |
| 68 | |
| 69 | // ordered list of known SDR color modes |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 70 | const std::array<ColorMode, 3> sSdrColorModes = { |
| 71 | ColorMode::DISPLAY_BT2020, |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 72 | ColorMode::DISPLAY_P3, |
| 73 | ColorMode::SRGB, |
| 74 | }; |
| 75 | |
| 76 | // ordered list of known HDR color modes |
| 77 | const std::array<ColorMode, 2> sHdrColorModes = { |
| 78 | ColorMode::BT2100_PQ, |
| 79 | ColorMode::BT2100_HLG, |
| 80 | }; |
| 81 | |
| 82 | // ordered list of known SDR render intents |
| 83 | const std::array<RenderIntent, 2> sSdrRenderIntents = { |
| 84 | RenderIntent::ENHANCE, |
| 85 | RenderIntent::COLORIMETRIC, |
| 86 | }; |
| 87 | |
| 88 | // ordered list of known HDR render intents |
| 89 | const std::array<RenderIntent, 2> sHdrRenderIntents = { |
| 90 | RenderIntent::TONE_MAP_ENHANCE, |
| 91 | RenderIntent::TONE_MAP_COLORIMETRIC, |
| 92 | }; |
| 93 | |
| 94 | // map known color mode to dataspace |
| 95 | Dataspace colorModeToDataspace(ColorMode mode) { |
| 96 | switch (mode) { |
| 97 | case ColorMode::SRGB: |
| 98 | return Dataspace::SRGB; |
| 99 | case ColorMode::DISPLAY_P3: |
| 100 | return Dataspace::DISPLAY_P3; |
Valerie Hau | 9758ae0 | 2018-10-09 16:05:09 -0700 | [diff] [blame] | 101 | case ColorMode::DISPLAY_BT2020: |
| 102 | return Dataspace::DISPLAY_BT2020; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 103 | case ColorMode::BT2100_HLG: |
| 104 | return Dataspace::BT2020_HLG; |
| 105 | case ColorMode::BT2100_PQ: |
| 106 | return Dataspace::BT2020_PQ; |
| 107 | default: |
| 108 | return Dataspace::UNKNOWN; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // Return a list of candidate color modes. |
| 113 | std::vector<ColorMode> getColorModeCandidates(ColorMode mode) { |
| 114 | std::vector<ColorMode> candidates; |
| 115 | |
| 116 | // add mode itself |
| 117 | candidates.push_back(mode); |
| 118 | |
| 119 | // check if mode is HDR |
| 120 | bool isHdr = false; |
| 121 | for (auto hdrMode : sHdrColorModes) { |
| 122 | if (hdrMode == mode) { |
| 123 | isHdr = true; |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // add other HDR candidates when mode is HDR |
| 129 | if (isHdr) { |
| 130 | for (auto hdrMode : sHdrColorModes) { |
| 131 | if (hdrMode != mode) { |
| 132 | candidates.push_back(hdrMode); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // add other SDR candidates |
| 138 | for (auto sdrMode : sSdrColorModes) { |
| 139 | if (sdrMode != mode) { |
| 140 | candidates.push_back(sdrMode); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | return candidates; |
| 145 | } |
| 146 | |
| 147 | // Return a list of candidate render intents. |
| 148 | std::vector<RenderIntent> getRenderIntentCandidates(RenderIntent intent) { |
| 149 | std::vector<RenderIntent> candidates; |
| 150 | |
| 151 | // add intent itself |
| 152 | candidates.push_back(intent); |
| 153 | |
| 154 | // check if intent is HDR |
| 155 | bool isHdr = false; |
| 156 | for (auto hdrIntent : sHdrRenderIntents) { |
| 157 | if (hdrIntent == intent) { |
| 158 | isHdr = true; |
| 159 | break; |
| 160 | } |
| 161 | } |
| 162 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 163 | if (isHdr) { |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 164 | // add other HDR candidates when intent is HDR |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 165 | for (auto hdrIntent : sHdrRenderIntents) { |
| 166 | if (hdrIntent != intent) { |
| 167 | candidates.push_back(hdrIntent); |
| 168 | } |
| 169 | } |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 170 | } else { |
| 171 | // add other SDR candidates when intent is SDR |
| 172 | for (auto sdrIntent : sSdrRenderIntents) { |
| 173 | if (sdrIntent != intent) { |
| 174 | candidates.push_back(sdrIntent); |
| 175 | } |
| 176 | } |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | return candidates; |
| 180 | } |
| 181 | |
| 182 | // Return the best color mode supported by HWC. |
| 183 | ColorMode getHwcColorMode( |
| 184 | const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes, |
| 185 | ColorMode mode) { |
| 186 | std::vector<ColorMode> candidates = getColorModeCandidates(mode); |
| 187 | for (auto candidate : candidates) { |
| 188 | auto iter = hwcColorModes.find(candidate); |
| 189 | if (iter != hwcColorModes.end()) { |
| 190 | return candidate; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return ColorMode::NATIVE; |
| 195 | } |
| 196 | |
| 197 | // Return the best render intent supported by HWC. |
| 198 | RenderIntent getHwcRenderIntent(const std::vector<RenderIntent>& hwcIntents, RenderIntent intent) { |
| 199 | std::vector<RenderIntent> candidates = getRenderIntentCandidates(intent); |
| 200 | for (auto candidate : candidates) { |
| 201 | for (auto hwcIntent : hwcIntents) { |
| 202 | if (candidate == hwcIntent) { |
| 203 | return candidate; |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | return RenderIntent::COLORIMETRIC; |
| 209 | } |
| 210 | |
| 211 | } // anonymous namespace |
| 212 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 213 | DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger, |
| 214 | const wp<IBinder>& displayToken, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 215 | const std::optional<DisplayId>& displayId) |
| 216 | : flinger(flinger), displayToken(displayToken), displayId(displayId) {} |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 217 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 218 | DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args) |
| 219 | : lastCompositionHadVisibleLayers(false), |
| 220 | mFlinger(args.flinger), |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 221 | mDisplayToken(args.displayToken), |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 222 | mId(args.displayId), |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 223 | mNativeWindow(args.nativeWindow), |
| 224 | mDisplaySurface(args.displaySurface), |
| 225 | mSurface{std::move(args.renderSurface)}, |
| 226 | mDisplayWidth(args.displayWidth), |
| 227 | mDisplayHeight(args.displayHeight), |
| 228 | mDisplayInstallOrientation(args.displayInstallOrientation), |
| 229 | mPageFlipCount(0), |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 230 | mIsVirtual(args.isVirtual), |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 231 | mIsSecure(args.isSecure), |
| 232 | mLayerStack(NO_LAYER_STACK), |
| 233 | mOrientation(), |
| 234 | mViewport(Rect::INVALID_RECT), |
| 235 | mFrame(Rect::INVALID_RECT), |
| 236 | mPowerMode(args.initialPowerMode), |
| 237 | mActiveConfig(0), |
| 238 | mColorTransform(HAL_COLOR_TRANSFORM_IDENTITY), |
| 239 | mHasWideColorGamut(args.hasWideColorGamut), |
| 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 | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 245 | populateColorModes(args.hwcColorModes); |
| 246 | |
| 247 | ALOGE_IF(!mNativeWindow, "No native window was set for display"); |
| 248 | ALOGE_IF(!mDisplaySurface, "No display surface was set for display"); |
| 249 | ALOGE_IF(!mSurface, "No render surface was set for display"); |
| 250 | ALOGE_IF(mDisplayWidth <= 0 || mDisplayHeight <= 0, |
| 251 | "Invalid dimensions of %d x %d were set for display", mDisplayWidth, mDisplayHeight); |
| 252 | |
| 253 | std::vector<Hdr> types = args.hdrCapabilities.getSupportedHdrTypes(); |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 254 | for (Hdr hdrType : types) { |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 255 | switch (hdrType) { |
| 256 | case Hdr::HDR10: |
| 257 | mHasHdr10 = true; |
| 258 | break; |
| 259 | case Hdr::HLG: |
| 260 | mHasHLG = true; |
| 261 | break; |
| 262 | case Hdr::DOLBY_VISION: |
| 263 | mHasDolbyVision = true; |
| 264 | break; |
| 265 | default: |
| 266 | ALOGE("UNKNOWN HDR capability: %d", static_cast<int32_t>(hdrType)); |
| 267 | } |
| 268 | } |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 269 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 270 | float minLuminance = args.hdrCapabilities.getDesiredMinLuminance(); |
| 271 | float maxLuminance = args.hdrCapabilities.getDesiredMaxLuminance(); |
| 272 | float maxAverageLuminance = args.hdrCapabilities.getDesiredMaxAverageLuminance(); |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 273 | |
| 274 | minLuminance = minLuminance <= 0.0 ? sDefaultMinLumiance : minLuminance; |
| 275 | maxLuminance = maxLuminance <= 0.0 ? sDefaultMaxLumiance : maxLuminance; |
| 276 | maxAverageLuminance = maxAverageLuminance <= 0.0 ? sDefaultMaxLumiance : maxAverageLuminance; |
| 277 | if (this->hasWideColorGamut()) { |
| 278 | // insert HDR10/HLG as we will force client composition for HDR10/HLG |
| 279 | // layers |
| 280 | if (!hasHDR10Support()) { |
| 281 | types.push_back(Hdr::HDR10); |
| 282 | } |
| 283 | |
| 284 | if (!hasHLGSupport()) { |
| 285 | types.push_back(Hdr::HLG); |
| 286 | } |
| 287 | } |
| 288 | mHdrCapabilities = HdrCapabilities(types, maxLuminance, maxAverageLuminance, minLuminance); |
| 289 | |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 290 | // initialize the display orientation transform. |
| 291 | setProjection(DisplayState::eOrientationDefault, mViewport, mFrame); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 294 | DisplayDevice::~DisplayDevice() = default; |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 295 | |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 296 | void DisplayDevice::disconnect(HWComposer& hwc) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 297 | if (mId) { |
| 298 | hwc.disconnectDisplay(*mId); |
| 299 | mId.reset(); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 303 | int DisplayDevice::getWidth() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 304 | return mDisplayWidth; |
| 305 | } |
| 306 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 307 | int DisplayDevice::getHeight() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 308 | return mDisplayHeight; |
| 309 | } |
| 310 | |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 311 | void DisplayDevice::setDisplayName(const std::string& displayName) { |
| 312 | if (!displayName.empty()) { |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 313 | // never override the name with an empty name |
| 314 | mDisplayName = displayName; |
| 315 | } |
| 316 | } |
| 317 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 318 | uint32_t DisplayDevice::getPageFlipCount() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 319 | return mPageFlipCount; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Chia-I Wu | b02087d | 2017-11-09 10:19:54 -0800 | [diff] [blame] | 322 | void DisplayDevice::flip() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 324 | mFlinger->getRenderEngine().checkErrors(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 325 | mPageFlipCount++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 328 | status_t DisplayDevice::beginFrame(bool mustRecompose) const { |
| 329 | return mDisplaySurface->beginFrame(mustRecompose); |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 330 | } |
| 331 | |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 332 | status_t DisplayDevice::prepareFrame(HWComposer& hwc, |
| 333 | std::vector<CompositionInfo>& compositionData) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 334 | if (mId) { |
| 335 | status_t error = hwc.prepare(*mId, compositionData); |
| 336 | if (error != NO_ERROR) { |
| 337 | return error; |
| 338 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | DisplaySurface::CompositionType compositionType; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 342 | bool hasClient = hwc.hasClientComposition(mId); |
| 343 | bool hasDevice = hwc.hasDeviceComposition(mId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 344 | if (hasClient && hasDevice) { |
| 345 | compositionType = DisplaySurface::COMPOSITION_MIXED; |
| 346 | } else if (hasClient) { |
| 347 | compositionType = DisplaySurface::COMPOSITION_GLES; |
| 348 | } else if (hasDevice) { |
| 349 | compositionType = DisplaySurface::COMPOSITION_HWC; |
| 350 | } else { |
| 351 | // Nothing to do -- when turning the screen off we get a frame like |
| 352 | // this. Call it a HWC frame since we won't be doing any GLES work but |
| 353 | // will do a prepare/set cycle. |
| 354 | compositionType = DisplaySurface::COMPOSITION_HWC; |
| 355 | } |
| 356 | return mDisplaySurface->prepareFrame(compositionType); |
| 357 | } |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 358 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 359 | void DisplayDevice::swapBuffers(HWComposer& hwc) const { |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 360 | if (hwc.hasClientComposition(mId) || hwc.hasFlipClientTargetRequest(mId)) { |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 361 | mSurface->swapBuffers(); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 362 | } |
Mathias Agopian | 52e2148 | 2012-09-24 18:07:21 -0700 | [diff] [blame] | 363 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 364 | status_t result = mDisplaySurface->advanceFrame(); |
| 365 | if (result != NO_ERROR) { |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 366 | ALOGE("[%s] failed pushing new frame to HWC: %d", mDisplayName.c_str(), result); |
Mathias Agopian | 3234138 | 2012-09-25 19:16:28 -0700 | [diff] [blame] | 367 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 370 | void DisplayDevice::onSwapBuffersCompleted() const { |
| 371 | mDisplaySurface->onFrameCommitted(); |
| 372 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 373 | |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 374 | bool DisplayDevice::makeCurrent() const { |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 375 | bool success = mFlinger->getRenderEngine().setCurrentSurface(*mSurface); |
Mathias Agopian | 931bda1 | 2013-08-28 18:11:46 -0700 | [diff] [blame] | 376 | setViewportAndProjection(); |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 377 | return success; |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 380 | void DisplayDevice::setViewportAndProjection() const { |
| 381 | size_t w = mDisplayWidth; |
| 382 | size_t h = mDisplayHeight; |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 383 | Rect sourceCrop(0, 0, w, h); |
Chia-I Wu | 1be50b5 | 2018-08-29 10:44:48 -0700 | [diff] [blame] | 384 | mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, ui::Transform::ROT_0); |
Mathias Agopian | bae92d0 | 2012-09-28 01:00:47 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 387 | const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const { |
| 388 | return mDisplaySurface->getClientTargetAcquireFence(); |
| 389 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 390 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 391 | // ---------------------------------------------------------------------------- |
| 392 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 393 | void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 394 | mVisibleLayersSortedByZ = layers; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 397 | const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 398 | return mVisibleLayersSortedByZ; |
| 399 | } |
| 400 | |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 401 | void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) { |
| 402 | mLayersNeedingFences = layers; |
| 403 | } |
| 404 | |
| 405 | const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const { |
| 406 | return mLayersNeedingFences; |
| 407 | } |
| 408 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 409 | Region DisplayDevice::getDirtyRegion(bool repaintEverything) const { |
| 410 | Region dirty; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 411 | if (repaintEverything) { |
| 412 | dirty.set(getBounds()); |
| 413 | } else { |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 414 | const ui::Transform& planeTransform(mGlobalTransform); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 415 | dirty = planeTransform.transform(this->dirtyRegion); |
| 416 | dirty.andSelf(getBounds()); |
| 417 | } |
| 418 | return dirty; |
| 419 | } |
| 420 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 421 | // ---------------------------------------------------------------------------- |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 422 | void DisplayDevice::setPowerMode(int mode) { |
| 423 | mPowerMode = mode; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 426 | int DisplayDevice::getPowerMode() const { |
| 427 | return mPowerMode; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 430 | bool DisplayDevice::isPoweredOn() const { |
| 431 | return mPowerMode != HWC_POWER_MODE_OFF; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | // ---------------------------------------------------------------------------- |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 435 | void DisplayDevice::setActiveConfig(int mode) { |
| 436 | mActiveConfig = mode; |
| 437 | } |
| 438 | |
| 439 | int DisplayDevice::getActiveConfig() const { |
| 440 | return mActiveConfig; |
| 441 | } |
| 442 | |
| 443 | // ---------------------------------------------------------------------------- |
Peiyong Lin | a52f029 | 2018-03-14 17:26:31 -0700 | [diff] [blame] | 444 | void DisplayDevice::setActiveColorMode(ColorMode mode) { |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 445 | mActiveColorMode = mode; |
| 446 | } |
| 447 | |
Peiyong Lin | a52f029 | 2018-03-14 17:26:31 -0700 | [diff] [blame] | 448 | ColorMode DisplayDevice::getActiveColorMode() const { |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 449 | return mActiveColorMode; |
| 450 | } |
Courtney Goeltzenleuchter | 79d2724 | 2017-07-13 17:54:01 -0600 | [diff] [blame] | 451 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 452 | RenderIntent DisplayDevice::getActiveRenderIntent() const { |
| 453 | return mActiveRenderIntent; |
| 454 | } |
| 455 | |
| 456 | void DisplayDevice::setActiveRenderIntent(RenderIntent renderIntent) { |
| 457 | mActiveRenderIntent = renderIntent; |
| 458 | } |
| 459 | |
Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 460 | void DisplayDevice::setColorTransform(const mat4& transform) { |
| 461 | const bool isIdentity = (transform == mat4()); |
| 462 | mColorTransform = |
| 463 | isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX; |
| 464 | } |
| 465 | |
| 466 | android_color_transform_t DisplayDevice::getColorTransform() const { |
| 467 | return mColorTransform; |
| 468 | } |
| 469 | |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 470 | void DisplayDevice::setCompositionDataSpace(ui::Dataspace dataspace) { |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 471 | mCompositionDataSpace = dataspace; |
Courtney Goeltzenleuchter | 79d2724 | 2017-07-13 17:54:01 -0600 | [diff] [blame] | 472 | ANativeWindow* const window = mNativeWindow.get(); |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 473 | native_window_set_buffers_data_space(window, static_cast<android_dataspace>(dataspace)); |
Courtney Goeltzenleuchter | 79d2724 | 2017-07-13 17:54:01 -0600 | [diff] [blame] | 474 | } |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 475 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 476 | ui::Dataspace DisplayDevice::getCompositionDataSpace() const { |
| 477 | return mCompositionDataSpace; |
| 478 | } |
| 479 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 480 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 481 | |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 482 | void DisplayDevice::setLayerStack(uint32_t stack) { |
| 483 | mLayerStack = stack; |
| 484 | dirtyRegion.set(bounds()); |
| 485 | } |
| 486 | |
| 487 | // ---------------------------------------------------------------------------- |
| 488 | |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 489 | uint32_t DisplayDevice::getOrientationTransform() const { |
| 490 | uint32_t transform = 0; |
| 491 | switch (mOrientation) { |
| 492 | case DisplayState::eOrientationDefault: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 493 | transform = ui::Transform::ROT_0; |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 494 | break; |
| 495 | case DisplayState::eOrientation90: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 496 | transform = ui::Transform::ROT_90; |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 497 | break; |
| 498 | case DisplayState::eOrientation180: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 499 | transform = ui::Transform::ROT_180; |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 500 | break; |
| 501 | case DisplayState::eOrientation270: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 502 | transform = ui::Transform::ROT_270; |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 503 | break; |
| 504 | } |
| 505 | return transform; |
| 506 | } |
| 507 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 508 | status_t DisplayDevice::orientationToTransfrom( |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 509 | int orientation, int w, int h, ui::Transform* tr) |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 510 | { |
| 511 | uint32_t flags = 0; |
| 512 | switch (orientation) { |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 513 | case DisplayState::eOrientationDefault: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 514 | flags = ui::Transform::ROT_0; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 515 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 516 | case DisplayState::eOrientation90: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 517 | flags = ui::Transform::ROT_90; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 518 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 519 | case DisplayState::eOrientation180: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 520 | flags = ui::Transform::ROT_180; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 521 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 522 | case DisplayState::eOrientation270: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 523 | flags = ui::Transform::ROT_270; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 524 | break; |
| 525 | default: |
| 526 | return BAD_VALUE; |
| 527 | } |
| 528 | tr->set(flags, w, h); |
| 529 | return NO_ERROR; |
| 530 | } |
| 531 | |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 532 | void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) { |
| 533 | dirtyRegion.set(getBounds()); |
| 534 | |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 535 | mSurface->setNativeWindow(nullptr); |
Michael Lentine | f2568de | 2014-08-20 10:51:23 -0700 | [diff] [blame] | 536 | |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 537 | mDisplaySurface->resizeBuffers(newWidth, newHeight); |
| 538 | |
| 539 | ANativeWindow* const window = mNativeWindow.get(); |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 540 | mSurface->setNativeWindow(window); |
Alec Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame] | 541 | mDisplayWidth = mSurface->getWidth(); |
| 542 | mDisplayHeight = mSurface->getHeight(); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 543 | |
| 544 | LOG_FATAL_IF(mDisplayWidth != newWidth, |
| 545 | "Unable to set new width to %d", newWidth); |
| 546 | LOG_FATAL_IF(mDisplayHeight != newHeight, |
| 547 | "Unable to set new height to %d", newHeight); |
| 548 | } |
| 549 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 550 | void DisplayDevice::setProjection(int orientation, |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 551 | const Rect& newViewport, const Rect& newFrame) { |
| 552 | Rect viewport(newViewport); |
| 553 | Rect frame(newFrame); |
| 554 | |
| 555 | const int w = mDisplayWidth; |
| 556 | const int h = mDisplayHeight; |
| 557 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 558 | ui::Transform R; |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 559 | DisplayDevice::orientationToTransfrom(orientation, w, h, &R); |
| 560 | |
| 561 | if (!frame.isValid()) { |
| 562 | // the destination frame can be invalid if it has never been set, |
| 563 | // in that case we assume the whole display frame. |
| 564 | frame = Rect(w, h); |
| 565 | } |
| 566 | |
| 567 | if (viewport.isEmpty()) { |
| 568 | // viewport can be invalid if it has never been set, in that case |
| 569 | // we assume the whole display size. |
| 570 | // it's also invalid to have an empty viewport, so we handle that |
| 571 | // case in the same way. |
| 572 | viewport = Rect(w, h); |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 573 | if (R.getOrientation() & ui::Transform::ROT_90) { |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 574 | // viewport is always specified in the logical orientation |
| 575 | // of the display (ie: post-rotation). |
Peiyong Lin | 3db4234 | 2018-08-16 09:15:59 -0700 | [diff] [blame] | 576 | std::swap(viewport.right, viewport.bottom); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
| 580 | dirtyRegion.set(getBounds()); |
| 581 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 582 | ui::Transform TL, TP, S; |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 583 | float src_width = viewport.width(); |
| 584 | float src_height = viewport.height(); |
| 585 | float dst_width = frame.width(); |
| 586 | float dst_height = frame.height(); |
| 587 | if (src_width != dst_width || src_height != dst_height) { |
| 588 | float sx = dst_width / src_width; |
| 589 | float sy = dst_height / src_height; |
| 590 | S.set(sx, 0, 0, sy); |
| 591 | } |
| 592 | |
| 593 | float src_x = viewport.left; |
| 594 | float src_y = viewport.top; |
| 595 | float dst_x = frame.left; |
| 596 | float dst_y = frame.top; |
| 597 | TL.set(-src_x, -src_y); |
| 598 | TP.set(dst_x, dst_y); |
| 599 | |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 600 | // need to take care of primary display rotation for mGlobalTransform |
| 601 | // for case if the panel is not installed aligned with device orientation |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 602 | if (isPrimary()) { |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 603 | DisplayDevice::orientationToTransfrom( |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 604 | (orientation + mDisplayInstallOrientation) % (DisplayState::eOrientation270 + 1), |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 605 | w, h, &R); |
| 606 | } |
| 607 | |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 608 | // The viewport and frame are both in the logical orientation. |
| 609 | // Apply the logical translation, scale to physical size, apply the |
| 610 | // physical translation and finally rotate to the physical orientation. |
| 611 | mGlobalTransform = R * TP * S * TL; |
| 612 | |
| 613 | const uint8_t type = mGlobalTransform.getType(); |
| 614 | mNeedsFiltering = (!mGlobalTransform.preserveRects() || |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 615 | (type >= ui::Transform::SCALE)); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 616 | |
| 617 | mScissor = mGlobalTransform.transform(viewport); |
| 618 | if (mScissor.isEmpty()) { |
Mathias Agopian | 6c7f25a | 2013-05-09 20:37:10 -0700 | [diff] [blame] | 619 | mScissor = getBounds(); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 620 | } |
| 621 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 622 | mOrientation = orientation; |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 623 | if (isPrimary()) { |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 624 | uint32_t transform = 0; |
| 625 | switch (mOrientation) { |
| 626 | case DisplayState::eOrientationDefault: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 627 | transform = ui::Transform::ROT_0; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 628 | break; |
| 629 | case DisplayState::eOrientation90: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 630 | transform = ui::Transform::ROT_90; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 631 | break; |
| 632 | case DisplayState::eOrientation180: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 633 | transform = ui::Transform::ROT_180; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 634 | break; |
| 635 | case DisplayState::eOrientation270: |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 636 | transform = ui::Transform::ROT_270; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 637 | break; |
| 638 | } |
| 639 | sPrimaryDisplayOrientation = transform; |
| 640 | } |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 641 | mViewport = viewport; |
| 642 | mFrame = frame; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 643 | } |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 644 | |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 645 | uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() { |
| 646 | return sPrimaryDisplayOrientation; |
| 647 | } |
| 648 | |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 649 | std::string DisplayDevice::getDebugName() const { |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame^] | 650 | const auto id = mId ? to_string(*mId) + ", " : std::string(); |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 651 | return base::StringPrintf("DisplayDevice{%s%s%s\"%s\"}", id.c_str(), |
| 652 | isPrimary() ? "primary, " : "", isVirtual() ? "virtual, " : "", |
| 653 | mDisplayName.c_str()); |
| 654 | } |
| 655 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 656 | void DisplayDevice::dump(String8& result) const { |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 657 | const ui::Transform& tr(mGlobalTransform); |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 658 | ANativeWindow* const window = mNativeWindow.get(); |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 659 | result.appendFormat("+ %s\n", getDebugName().c_str()); |
| 660 | result.appendFormat(" layerStack=%u, (%4dx%4d), ANativeWindow=%p " |
Courtney Goeltzenleuchter | 0ebaac3 | 2017-04-13 12:17:03 -0600 | [diff] [blame] | 661 | "(%d:%d:%d:%d), orient=%2d (type=%08x), " |
| 662 | "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n", |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 663 | mLayerStack, mDisplayWidth, mDisplayHeight, window, |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 664 | mSurface->queryRedSize(), mSurface->queryGreenSize(), |
| 665 | mSurface->queryBlueSize(), mSurface->queryAlphaSize(), mOrientation, |
| 666 | tr.getType(), getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig, |
Courtney Goeltzenleuchter | 0ebaac3 | 2017-04-13 12:17:03 -0600 | [diff] [blame] | 667 | mVisibleLayersSortedByZ.size()); |
| 668 | result.appendFormat(" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d]," |
| 669 | "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n", |
| 670 | mViewport.left, mViewport.top, mViewport.right, mViewport.bottom, |
| 671 | mFrame.left, mFrame.top, mFrame.right, mFrame.bottom, mScissor.left, |
| 672 | mScissor.top, mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0], |
| 673 | tr[0][1], tr[1][1], tr[2][1], tr[0][2], tr[1][2], tr[2][2]); |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 674 | auto const surface = static_cast<Surface*>(window); |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 675 | ui::Dataspace dataspace = surface->getBuffersDataSpace(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 676 | result.appendFormat(" wideColorGamut=%d, hdr10=%d, colorMode=%s, dataspace: %s (%d)\n", |
| 677 | mHasWideColorGamut, mHasHdr10, |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 678 | decodeColorMode(mActiveColorMode).c_str(), |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 679 | dataspaceDetails(static_cast<android_dataspace>(dataspace)).c_str(), dataspace); |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 680 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 681 | String8 surfaceDump; |
Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 682 | mDisplaySurface->dumpAsString(surfaceDump); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 683 | result.append(surfaceDump); |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 684 | } |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 685 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 686 | // Map dataspace/intent to the best matched dataspace/colorMode/renderIntent |
| 687 | // supported by HWC. |
| 688 | void DisplayDevice::addColorMode( |
| 689 | const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes, |
| 690 | const ColorMode mode, const RenderIntent intent) { |
| 691 | // find the best color mode |
| 692 | const ColorMode hwcColorMode = getHwcColorMode(hwcColorModes, mode); |
| 693 | |
| 694 | // find the best render intent |
| 695 | auto iter = hwcColorModes.find(hwcColorMode); |
| 696 | const auto& hwcIntents = |
| 697 | iter != hwcColorModes.end() ? iter->second : std::vector<RenderIntent>(); |
| 698 | const RenderIntent hwcIntent = getHwcRenderIntent(hwcIntents, intent); |
| 699 | |
| 700 | const Dataspace dataspace = colorModeToDataspace(mode); |
| 701 | const Dataspace hwcDataspace = colorModeToDataspace(hwcColorMode); |
| 702 | |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 703 | 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] | 704 | dataspaceDetails(static_cast<android_dataspace_t>(dataspace)).c_str(), |
| 705 | decodeRenderIntent(intent).c_str(), |
| 706 | dataspaceDetails(static_cast<android_dataspace_t>(hwcDataspace)).c_str(), |
| 707 | decodeColorMode(hwcColorMode).c_str(), decodeRenderIntent(hwcIntent).c_str()); |
| 708 | |
| 709 | mColorModes[getColorModeKey(dataspace, intent)] = {hwcDataspace, hwcColorMode, hwcIntent}; |
| 710 | } |
| 711 | |
| 712 | void DisplayDevice::populateColorModes( |
| 713 | const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes) { |
| 714 | if (!hasWideColorGamut()) { |
| 715 | return; |
| 716 | } |
| 717 | |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 718 | // collect all known SDR render intents |
| 719 | std::unordered_set<RenderIntent> sdrRenderIntents(sSdrRenderIntents.begin(), |
| 720 | sSdrRenderIntents.end()); |
| 721 | auto iter = hwcColorModes.find(ColorMode::SRGB); |
| 722 | if (iter != hwcColorModes.end()) { |
| 723 | for (auto intent : iter->second) { |
| 724 | sdrRenderIntents.insert(intent); |
| 725 | } |
| 726 | } |
| 727 | |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 728 | // add all known SDR combinations |
Chia-I Wu | 0d71126 | 2018-05-21 15:19:35 -0700 | [diff] [blame] | 729 | for (auto intent : sdrRenderIntents) { |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 730 | for (auto mode : sSdrColorModes) { |
| 731 | addColorMode(hwcColorModes, mode, intent); |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 732 | } |
| 733 | } |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 734 | |
Chia-I Wu | c4b08bd | 2018-05-29 12:57:23 -0700 | [diff] [blame] | 735 | // collect all known HDR render intents |
| 736 | std::unordered_set<RenderIntent> hdrRenderIntents(sHdrRenderIntents.begin(), |
| 737 | sHdrRenderIntents.end()); |
| 738 | iter = hwcColorModes.find(ColorMode::BT2100_PQ); |
| 739 | if (iter != hwcColorModes.end()) { |
| 740 | for (auto intent : iter->second) { |
| 741 | hdrRenderIntents.insert(intent); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | // add all known HDR combinations |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 746 | for (auto intent : sHdrRenderIntents) { |
| 747 | for (auto mode : sHdrColorModes) { |
| 748 | addColorMode(hwcColorModes, mode, intent); |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | bool DisplayDevice::hasRenderIntent(RenderIntent intent) const { |
| 754 | // assume a render intent is supported when SRGB supports it; we should |
| 755 | // get rid of that assumption. |
| 756 | auto iter = mColorModes.find(getColorModeKey(Dataspace::SRGB, intent)); |
| 757 | return iter != mColorModes.end() && iter->second.renderIntent == intent; |
| 758 | } |
| 759 | |
Peiyong Lin | dfde511 | 2018-06-05 10:58:41 -0700 | [diff] [blame] | 760 | bool DisplayDevice::hasLegacyHdrSupport(Dataspace dataspace) const { |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 761 | if ((dataspace == Dataspace::BT2020_PQ && hasHDR10Support()) || |
| 762 | (dataspace == Dataspace::BT2020_HLG && hasHLGSupport())) { |
| 763 | auto iter = |
| 764 | mColorModes.find(getColorModeKey(dataspace, RenderIntent::TONE_MAP_COLORIMETRIC)); |
Peiyong Lin | dfde511 | 2018-06-05 10:58:41 -0700 | [diff] [blame] | 765 | return iter == mColorModes.end() || iter->second.dataspace != dataspace; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | return false; |
| 769 | } |
| 770 | |
| 771 | void DisplayDevice::getBestColorMode(Dataspace dataspace, RenderIntent intent, |
| 772 | Dataspace* outDataspace, ColorMode* outMode, |
| 773 | RenderIntent* outIntent) const { |
| 774 | auto iter = mColorModes.find(getColorModeKey(dataspace, intent)); |
| 775 | if (iter != mColorModes.end()) { |
| 776 | *outDataspace = iter->second.dataspace; |
| 777 | *outMode = iter->second.colorMode; |
| 778 | *outIntent = iter->second.renderIntent; |
| 779 | } else { |
Chia-I Wu | 6333af5 | 2018-10-16 13:46:36 -0700 | [diff] [blame] | 780 | // this is unexpected on a WCG display |
| 781 | if (hasWideColorGamut()) { |
| 782 | ALOGE("map unknown (%s)/(%s) to default color mode", |
| 783 | dataspaceDetails(static_cast<android_dataspace_t>(dataspace)).c_str(), |
| 784 | decodeRenderIntent(intent).c_str()); |
| 785 | } |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 786 | |
| 787 | *outDataspace = Dataspace::UNKNOWN; |
| 788 | *outMode = ColorMode::NATIVE; |
| 789 | *outIntent = RenderIntent::COLORIMETRIC; |
| 790 | } |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 793 | std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1); |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 794 | |
| 795 | } // namespace android |