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