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