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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
| 23 | #include <string.h> |
| 24 | #include <math.h> |
| 25 | |
| 26 | #include <cutils/properties.h> |
| 27 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <utils/Log.h> |
| 30 | |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 31 | #include <ui/DebugUtils.h> |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 32 | #include <ui/DisplayInfo.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 33 | #include <ui/PixelFormat.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 35 | #include <gui/Surface.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 36 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 37 | #include <hardware/gralloc.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 39 | #include "DisplayHardware/DisplaySurface.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 40 | #include "DisplayHardware/HWComposer.h" |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 41 | #include "DisplayHardware/HWC2.h" |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 42 | #include "RenderEngine/RenderEngine.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 43 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 44 | #include "clz.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 45 | #include "DisplayDevice.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 | |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 49 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 50 | #include <configstore/Utils.h> |
| 51 | |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 52 | namespace android { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 54 | // retrieve triple buffer setting from configstore |
| 55 | using namespace android::hardware::configstore; |
| 56 | using namespace android::hardware::configstore::V1_0; |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 57 | using android::ui::ColorMode; |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 58 | using android::ui::Hdr; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 59 | using android::ui::RenderIntent; |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 60 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | /* |
| 62 | * Initialize the display to the specified values. |
| 63 | * |
| 64 | */ |
| 65 | |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 66 | uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0; |
| 67 | |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 68 | // clang-format off |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 69 | DisplayDevice::DisplayDevice( |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | const sp<SurfaceFlinger>& flinger, |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 71 | DisplayType type, |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 72 | int32_t hwcId, |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 73 | bool isSecure, |
| 74 | const wp<IBinder>& displayToken, |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 75 | const sp<ANativeWindow>& nativeWindow, |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 76 | const sp<DisplaySurface>& displaySurface, |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 77 | std::unique_ptr<RE::Surface> renderSurface, |
| 78 | int displayWidth, |
| 79 | int displayHeight, |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 80 | bool hasWideColorGamut, |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 81 | const HdrCapabilities& hdrCapabilities, |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 82 | const int32_t supportedPerFrameMetadata, |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 83 | const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hdrAndRenderIntents, |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 84 | int initialPowerMode) |
Jesse Hall | b7a0549 | 2014-08-14 15:45:06 -0700 | [diff] [blame] | 85 | : lastCompositionHadVisibleLayers(false), |
| 86 | mFlinger(flinger), |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 87 | mType(type), |
| 88 | mHwcDisplayId(hwcId), |
Chih-Wei Huang | 27e2562 | 2013-01-07 17:33:56 +0800 | [diff] [blame] | 89 | mDisplayToken(displayToken), |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 90 | mNativeWindow(nativeWindow), |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 91 | mDisplaySurface(displaySurface), |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 92 | mSurface{std::move(renderSurface)}, |
| 93 | mDisplayWidth(displayWidth), |
| 94 | mDisplayHeight(displayHeight), |
| 95 | mPageFlipCount(0), |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 96 | mIsSecure(isSecure), |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 97 | mLayerStack(NO_LAYER_STACK), |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 98 | mOrientation(), |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 99 | mViewport(Rect::INVALID_RECT), |
| 100 | mFrame(Rect::INVALID_RECT), |
| 101 | mPowerMode(initialPowerMode), |
| 102 | mActiveConfig(0), |
Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 103 | mColorTransform(HAL_COLOR_TRANSFORM_IDENTITY), |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 104 | mHasWideColorGamut(hasWideColorGamut), |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 105 | mHasHdr10(false), |
| 106 | mHasHLG(false), |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 107 | mHasDolbyVision(false), |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 108 | mSupportedPerFrameMetadata(supportedPerFrameMetadata), |
| 109 | mHasBT2100PQColorimetric(false), |
| 110 | mHasBT2100PQEnhance(false), |
| 111 | mHasBT2100HLGColorimetric(false), |
| 112 | mHasBT2100HLGEnhance(false) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | { |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 114 | // clang-format on |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 115 | std::vector<Hdr> types = hdrCapabilities.getSupportedHdrTypes(); |
| 116 | for (Hdr hdrType : types) { |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 117 | switch (hdrType) { |
| 118 | case Hdr::HDR10: |
| 119 | mHasHdr10 = true; |
| 120 | break; |
| 121 | case Hdr::HLG: |
| 122 | mHasHLG = true; |
| 123 | break; |
| 124 | case Hdr::DOLBY_VISION: |
| 125 | mHasDolbyVision = true; |
| 126 | break; |
| 127 | default: |
| 128 | ALOGE("UNKNOWN HDR capability: %d", static_cast<int32_t>(hdrType)); |
| 129 | } |
| 130 | } |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 131 | |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 132 | float minLuminance = hdrCapabilities.getDesiredMinLuminance(); |
| 133 | float maxLuminance = hdrCapabilities.getDesiredMaxLuminance(); |
| 134 | float maxAverageLuminance = hdrCapabilities.getDesiredMaxAverageLuminance(); |
| 135 | |
| 136 | minLuminance = minLuminance <= 0.0 ? sDefaultMinLumiance : minLuminance; |
| 137 | maxLuminance = maxLuminance <= 0.0 ? sDefaultMaxLumiance : maxLuminance; |
| 138 | maxAverageLuminance = maxAverageLuminance <= 0.0 ? sDefaultMaxLumiance : maxAverageLuminance; |
| 139 | if (this->hasWideColorGamut()) { |
| 140 | // insert HDR10/HLG as we will force client composition for HDR10/HLG |
| 141 | // layers |
| 142 | if (!hasHDR10Support()) { |
| 143 | types.push_back(Hdr::HDR10); |
| 144 | } |
| 145 | |
| 146 | if (!hasHLGSupport()) { |
| 147 | types.push_back(Hdr::HLG); |
| 148 | } |
| 149 | } |
| 150 | mHdrCapabilities = HdrCapabilities(types, maxLuminance, maxAverageLuminance, minLuminance); |
| 151 | |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 152 | auto iter = hdrAndRenderIntents.find(ColorMode::BT2100_PQ); |
| 153 | if (iter != hdrAndRenderIntents.end()) { |
| 154 | hasToneMapping(iter->second, |
| 155 | &mHasBT2100PQColorimetric, &mHasBT2100PQEnhance); |
| 156 | } |
| 157 | |
| 158 | iter = hdrAndRenderIntents.find(ColorMode::BT2100_HLG); |
| 159 | if (iter != hdrAndRenderIntents.end()) { |
| 160 | hasToneMapping(iter->second, |
| 161 | &mHasBT2100HLGColorimetric, &mHasBT2100HLGEnhance); |
| 162 | } |
| 163 | |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 164 | // initialize the display orientation transform. |
| 165 | setProjection(DisplayState::eOrientationDefault, mViewport, mFrame); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 168 | DisplayDevice::~DisplayDevice() = default; |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 169 | |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 170 | void DisplayDevice::disconnect(HWComposer& hwc) { |
| 171 | if (mHwcDisplayId >= 0) { |
| 172 | hwc.disconnectDisplay(mHwcDisplayId); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 173 | mHwcDisplayId = -1; |
| 174 | } |
| 175 | } |
| 176 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 177 | bool DisplayDevice::isValid() const { |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 178 | return mFlinger != nullptr; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 181 | int DisplayDevice::getWidth() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 182 | return mDisplayWidth; |
| 183 | } |
| 184 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 185 | int DisplayDevice::getHeight() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 186 | return mDisplayHeight; |
| 187 | } |
| 188 | |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 189 | void DisplayDevice::setDisplayName(const std::string& displayName) { |
| 190 | if (!displayName.empty()) { |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 191 | // never override the name with an empty name |
| 192 | mDisplayName = displayName; |
| 193 | } |
| 194 | } |
| 195 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 196 | uint32_t DisplayDevice::getPageFlipCount() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 197 | return mPageFlipCount; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Chia-I Wu | b02087d | 2017-11-09 10:19:54 -0800 | [diff] [blame] | 200 | void DisplayDevice::flip() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 202 | mFlinger->getRenderEngine().checkErrors(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 203 | mPageFlipCount++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 206 | status_t DisplayDevice::beginFrame(bool mustRecompose) const { |
| 207 | return mDisplaySurface->beginFrame(mustRecompose); |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 210 | status_t DisplayDevice::prepareFrame(HWComposer& hwc) { |
| 211 | status_t error = hwc.prepare(*this); |
| 212 | if (error != NO_ERROR) { |
| 213 | return error; |
| 214 | } |
| 215 | |
| 216 | DisplaySurface::CompositionType compositionType; |
| 217 | bool hasClient = hwc.hasClientComposition(mHwcDisplayId); |
| 218 | bool hasDevice = hwc.hasDeviceComposition(mHwcDisplayId); |
| 219 | if (hasClient && hasDevice) { |
| 220 | compositionType = DisplaySurface::COMPOSITION_MIXED; |
| 221 | } else if (hasClient) { |
| 222 | compositionType = DisplaySurface::COMPOSITION_GLES; |
| 223 | } else if (hasDevice) { |
| 224 | compositionType = DisplaySurface::COMPOSITION_HWC; |
| 225 | } else { |
| 226 | // Nothing to do -- when turning the screen off we get a frame like |
| 227 | // this. Call it a HWC frame since we won't be doing any GLES work but |
| 228 | // will do a prepare/set cycle. |
| 229 | compositionType = DisplaySurface::COMPOSITION_HWC; |
| 230 | } |
| 231 | return mDisplaySurface->prepareFrame(compositionType); |
| 232 | } |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 233 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 234 | void DisplayDevice::swapBuffers(HWComposer& hwc) const { |
Madhuri Athota | 88a905b | 2017-05-04 16:58:15 +0530 | [diff] [blame] | 235 | if (hwc.hasClientComposition(mHwcDisplayId) || hwc.hasFlipClientTargetRequest(mHwcDisplayId)) { |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 236 | mSurface->swapBuffers(); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 237 | } |
Mathias Agopian | 52e2148 | 2012-09-24 18:07:21 -0700 | [diff] [blame] | 238 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 239 | status_t result = mDisplaySurface->advanceFrame(); |
| 240 | if (result != NO_ERROR) { |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 241 | 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] | 242 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 245 | void DisplayDevice::onSwapBuffersCompleted() const { |
| 246 | mDisplaySurface->onFrameCommitted(); |
| 247 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 248 | |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 249 | bool DisplayDevice::makeCurrent() const { |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 250 | bool success = mFlinger->getRenderEngine().setCurrentSurface(*mSurface); |
Mathias Agopian | 931bda1 | 2013-08-28 18:11:46 -0700 | [diff] [blame] | 251 | setViewportAndProjection(); |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 252 | return success; |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 255 | void DisplayDevice::setViewportAndProjection() const { |
| 256 | size_t w = mDisplayWidth; |
| 257 | size_t h = mDisplayHeight; |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 258 | Rect sourceCrop(0, 0, w, h); |
Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 259 | mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, h, |
| 260 | false, Transform::ROT_0); |
Mathias Agopian | bae92d0 | 2012-09-28 01:00:47 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 263 | const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const { |
| 264 | return mDisplaySurface->getClientTargetAcquireFence(); |
| 265 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 266 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 267 | // ---------------------------------------------------------------------------- |
| 268 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 269 | void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 270 | mVisibleLayersSortedByZ = layers; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 273 | const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 274 | return mVisibleLayersSortedByZ; |
| 275 | } |
| 276 | |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 277 | void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) { |
| 278 | mLayersNeedingFences = layers; |
| 279 | } |
| 280 | |
| 281 | const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const { |
| 282 | return mLayersNeedingFences; |
| 283 | } |
| 284 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 285 | Region DisplayDevice::getDirtyRegion(bool repaintEverything) const { |
| 286 | Region dirty; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 287 | if (repaintEverything) { |
| 288 | dirty.set(getBounds()); |
| 289 | } else { |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 290 | const Transform& planeTransform(mGlobalTransform); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 291 | dirty = planeTransform.transform(this->dirtyRegion); |
| 292 | dirty.andSelf(getBounds()); |
| 293 | } |
| 294 | return dirty; |
| 295 | } |
| 296 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 297 | // ---------------------------------------------------------------------------- |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 298 | void DisplayDevice::setPowerMode(int mode) { |
| 299 | mPowerMode = mode; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 302 | int DisplayDevice::getPowerMode() const { |
| 303 | return mPowerMode; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 306 | bool DisplayDevice::isDisplayOn() const { |
| 307 | return (mPowerMode != HWC_POWER_MODE_OFF); |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | // ---------------------------------------------------------------------------- |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 311 | void DisplayDevice::setActiveConfig(int mode) { |
| 312 | mActiveConfig = mode; |
| 313 | } |
| 314 | |
| 315 | int DisplayDevice::getActiveConfig() const { |
| 316 | return mActiveConfig; |
| 317 | } |
| 318 | |
| 319 | // ---------------------------------------------------------------------------- |
Peiyong Lin | a52f029 | 2018-03-14 17:26:31 -0700 | [diff] [blame] | 320 | void DisplayDevice::setActiveColorMode(ColorMode mode) { |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 321 | mActiveColorMode = mode; |
| 322 | } |
| 323 | |
Peiyong Lin | a52f029 | 2018-03-14 17:26:31 -0700 | [diff] [blame] | 324 | ColorMode DisplayDevice::getActiveColorMode() const { |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 325 | return mActiveColorMode; |
| 326 | } |
Courtney Goeltzenleuchter | 79d2724 | 2017-07-13 17:54:01 -0600 | [diff] [blame] | 327 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 328 | RenderIntent DisplayDevice::getActiveRenderIntent() const { |
| 329 | return mActiveRenderIntent; |
| 330 | } |
| 331 | |
| 332 | void DisplayDevice::setActiveRenderIntent(RenderIntent renderIntent) { |
| 333 | mActiveRenderIntent = renderIntent; |
| 334 | } |
| 335 | |
Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 336 | void DisplayDevice::setColorTransform(const mat4& transform) { |
| 337 | const bool isIdentity = (transform == mat4()); |
| 338 | mColorTransform = |
| 339 | isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX; |
| 340 | } |
| 341 | |
| 342 | android_color_transform_t DisplayDevice::getColorTransform() const { |
| 343 | return mColorTransform; |
| 344 | } |
| 345 | |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 346 | void DisplayDevice::setCompositionDataSpace(ui::Dataspace dataspace) { |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 347 | mCompositionDataSpace = dataspace; |
Courtney Goeltzenleuchter | 79d2724 | 2017-07-13 17:54:01 -0600 | [diff] [blame] | 348 | ANativeWindow* const window = mNativeWindow.get(); |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 349 | native_window_set_buffers_data_space(window, static_cast<android_dataspace>(dataspace)); |
Courtney Goeltzenleuchter | 79d2724 | 2017-07-13 17:54:01 -0600 | [diff] [blame] | 350 | } |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 351 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 352 | ui::Dataspace DisplayDevice::getCompositionDataSpace() const { |
| 353 | return mCompositionDataSpace; |
| 354 | } |
| 355 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 356 | // ---------------------------------------------------------------------------- |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 357 | |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 358 | void DisplayDevice::setLayerStack(uint32_t stack) { |
| 359 | mLayerStack = stack; |
| 360 | dirtyRegion.set(bounds()); |
| 361 | } |
| 362 | |
| 363 | // ---------------------------------------------------------------------------- |
| 364 | |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 365 | uint32_t DisplayDevice::getOrientationTransform() const { |
| 366 | uint32_t transform = 0; |
| 367 | switch (mOrientation) { |
| 368 | case DisplayState::eOrientationDefault: |
| 369 | transform = Transform::ROT_0; |
| 370 | break; |
| 371 | case DisplayState::eOrientation90: |
| 372 | transform = Transform::ROT_90; |
| 373 | break; |
| 374 | case DisplayState::eOrientation180: |
| 375 | transform = Transform::ROT_180; |
| 376 | break; |
| 377 | case DisplayState::eOrientation270: |
| 378 | transform = Transform::ROT_270; |
| 379 | break; |
| 380 | } |
| 381 | return transform; |
| 382 | } |
| 383 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 384 | status_t DisplayDevice::orientationToTransfrom( |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 385 | int orientation, int w, int h, Transform* tr) |
| 386 | { |
| 387 | uint32_t flags = 0; |
| 388 | switch (orientation) { |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 389 | case DisplayState::eOrientationDefault: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 390 | flags = Transform::ROT_0; |
| 391 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 392 | case DisplayState::eOrientation90: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 393 | flags = Transform::ROT_90; |
| 394 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 395 | case DisplayState::eOrientation180: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 396 | flags = Transform::ROT_180; |
| 397 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 398 | case DisplayState::eOrientation270: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 399 | flags = Transform::ROT_270; |
| 400 | break; |
| 401 | default: |
| 402 | return BAD_VALUE; |
| 403 | } |
| 404 | tr->set(flags, w, h); |
| 405 | return NO_ERROR; |
| 406 | } |
| 407 | |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 408 | void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) { |
| 409 | dirtyRegion.set(getBounds()); |
| 410 | |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 411 | mSurface->setNativeWindow(nullptr); |
Michael Lentine | f2568de | 2014-08-20 10:51:23 -0700 | [diff] [blame] | 412 | |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 413 | mDisplaySurface->resizeBuffers(newWidth, newHeight); |
| 414 | |
| 415 | ANativeWindow* const window = mNativeWindow.get(); |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 416 | mSurface->setNativeWindow(window); |
| 417 | mDisplayWidth = mSurface->queryWidth(); |
| 418 | mDisplayHeight = mSurface->queryHeight(); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 419 | |
| 420 | LOG_FATAL_IF(mDisplayWidth != newWidth, |
| 421 | "Unable to set new width to %d", newWidth); |
| 422 | LOG_FATAL_IF(mDisplayHeight != newHeight, |
| 423 | "Unable to set new height to %d", newHeight); |
| 424 | } |
| 425 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 426 | void DisplayDevice::setProjection(int orientation, |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 427 | const Rect& newViewport, const Rect& newFrame) { |
| 428 | Rect viewport(newViewport); |
| 429 | Rect frame(newFrame); |
| 430 | |
| 431 | const int w = mDisplayWidth; |
| 432 | const int h = mDisplayHeight; |
| 433 | |
| 434 | Transform R; |
| 435 | DisplayDevice::orientationToTransfrom(orientation, w, h, &R); |
| 436 | |
| 437 | if (!frame.isValid()) { |
| 438 | // the destination frame can be invalid if it has never been set, |
| 439 | // in that case we assume the whole display frame. |
| 440 | frame = Rect(w, h); |
| 441 | } |
| 442 | |
| 443 | if (viewport.isEmpty()) { |
| 444 | // viewport can be invalid if it has never been set, in that case |
| 445 | // we assume the whole display size. |
| 446 | // it's also invalid to have an empty viewport, so we handle that |
| 447 | // case in the same way. |
| 448 | viewport = Rect(w, h); |
| 449 | if (R.getOrientation() & Transform::ROT_90) { |
| 450 | // viewport is always specified in the logical orientation |
| 451 | // of the display (ie: post-rotation). |
| 452 | swap(viewport.right, viewport.bottom); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | dirtyRegion.set(getBounds()); |
| 457 | |
| 458 | Transform TL, TP, S; |
| 459 | float src_width = viewport.width(); |
| 460 | float src_height = viewport.height(); |
| 461 | float dst_width = frame.width(); |
| 462 | float dst_height = frame.height(); |
| 463 | if (src_width != dst_width || src_height != dst_height) { |
| 464 | float sx = dst_width / src_width; |
| 465 | float sy = dst_height / src_height; |
| 466 | S.set(sx, 0, 0, sy); |
| 467 | } |
| 468 | |
| 469 | float src_x = viewport.left; |
| 470 | float src_y = viewport.top; |
| 471 | float dst_x = frame.left; |
| 472 | float dst_y = frame.top; |
| 473 | TL.set(-src_x, -src_y); |
| 474 | TP.set(dst_x, dst_y); |
| 475 | |
| 476 | // The viewport and frame are both in the logical orientation. |
| 477 | // Apply the logical translation, scale to physical size, apply the |
| 478 | // physical translation and finally rotate to the physical orientation. |
| 479 | mGlobalTransform = R * TP * S * TL; |
| 480 | |
| 481 | const uint8_t type = mGlobalTransform.getType(); |
| 482 | mNeedsFiltering = (!mGlobalTransform.preserveRects() || |
| 483 | (type >= Transform::SCALE)); |
| 484 | |
| 485 | mScissor = mGlobalTransform.transform(viewport); |
| 486 | if (mScissor.isEmpty()) { |
Mathias Agopian | 6c7f25a | 2013-05-09 20:37:10 -0700 | [diff] [blame] | 487 | mScissor = getBounds(); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 488 | } |
| 489 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 490 | mOrientation = orientation; |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 491 | if (isPrimary()) { |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 492 | uint32_t transform = 0; |
| 493 | switch (mOrientation) { |
| 494 | case DisplayState::eOrientationDefault: |
| 495 | transform = Transform::ROT_0; |
| 496 | break; |
| 497 | case DisplayState::eOrientation90: |
| 498 | transform = Transform::ROT_90; |
| 499 | break; |
| 500 | case DisplayState::eOrientation180: |
| 501 | transform = Transform::ROT_180; |
| 502 | break; |
| 503 | case DisplayState::eOrientation270: |
| 504 | transform = Transform::ROT_270; |
| 505 | break; |
| 506 | } |
| 507 | sPrimaryDisplayOrientation = transform; |
| 508 | } |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 509 | mViewport = viewport; |
| 510 | mFrame = frame; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 511 | } |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 512 | |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 513 | uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() { |
| 514 | return sPrimaryDisplayOrientation; |
| 515 | } |
| 516 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 517 | void DisplayDevice::dump(String8& result) const { |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 518 | const Transform& tr(mGlobalTransform); |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 519 | ANativeWindow* const window = mNativeWindow.get(); |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 520 | result.appendFormat("+ DisplayDevice: %s\n", mDisplayName.c_str()); |
Courtney Goeltzenleuchter | 0ebaac3 | 2017-04-13 12:17:03 -0600 | [diff] [blame] | 521 | result.appendFormat(" type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p " |
| 522 | "(%d:%d:%d:%d), orient=%2d (type=%08x), " |
| 523 | "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n", |
Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 524 | mType, mHwcDisplayId, mLayerStack, mDisplayWidth, mDisplayHeight, window, |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 525 | mSurface->queryRedSize(), mSurface->queryGreenSize(), |
| 526 | mSurface->queryBlueSize(), mSurface->queryAlphaSize(), mOrientation, |
| 527 | tr.getType(), getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig, |
Courtney Goeltzenleuchter | 0ebaac3 | 2017-04-13 12:17:03 -0600 | [diff] [blame] | 528 | mVisibleLayersSortedByZ.size()); |
| 529 | result.appendFormat(" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d]," |
| 530 | "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n", |
| 531 | mViewport.left, mViewport.top, mViewport.right, mViewport.bottom, |
| 532 | mFrame.left, mFrame.top, mFrame.right, mFrame.bottom, mScissor.left, |
| 533 | mScissor.top, mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0], |
| 534 | 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] | 535 | auto const surface = static_cast<Surface*>(window); |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 536 | ui::Dataspace dataspace = surface->getBuffersDataSpace(); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 537 | result.appendFormat(" wideColorGamut=%d, hdr10=%d, colorMode=%s, dataspace: %s (%d)\n", |
| 538 | mHasWideColorGamut, mHasHdr10, |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 539 | decodeColorMode(mActiveColorMode).c_str(), |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 540 | dataspaceDetails(static_cast<android_dataspace>(dataspace)).c_str(), dataspace); |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 541 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 542 | String8 surfaceDump; |
Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 543 | mDisplaySurface->dumpAsString(surfaceDump); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 544 | result.append(surfaceDump); |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 545 | } |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 546 | |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 547 | void DisplayDevice::hasToneMapping(const std::vector<RenderIntent>& renderIntents, |
| 548 | bool* outColorimetric, bool *outEnhance) { |
| 549 | for (auto intent : renderIntents) { |
| 550 | switch (intent) { |
| 551 | case RenderIntent::TONE_MAP_COLORIMETRIC: |
| 552 | *outColorimetric = true; |
| 553 | break; |
| 554 | case RenderIntent::TONE_MAP_ENHANCE: |
| 555 | *outEnhance = true; |
| 556 | break; |
| 557 | default: |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 563 | std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1); |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 564 | |
| 565 | } // namespace android |