Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 19 | #undef LOG_TAG |
| 20 | #define LOG_TAG "HWComposer" |
Mathias Agopian | 2965b26 | 2012-04-08 15:13:32 -0700 | [diff] [blame] | 21 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 22 | |
Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 23 | #include <inttypes.h> |
| 24 | #include <math.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 25 | #include <stdint.h> |
Mathias Agopian | f1352df | 2010-08-11 17:31:33 -0700 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 29 | #include <sys/types.h> |
| 30 | |
| 31 | #include <utils/Errors.h> |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 32 | #include <utils/misc.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 33 | #include <utils/NativeHandle.h> |
Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 34 | #include <utils/String8.h> |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 35 | #include <utils/Thread.h> |
Mathias Agopian | 2965b26 | 2012-04-08 15:13:32 -0700 | [diff] [blame] | 36 | #include <utils/Trace.h> |
Mathias Agopian | 22da60c | 2011-09-09 00:49:11 -0700 | [diff] [blame] | 37 | #include <utils/Vector.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 38 | |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 39 | #include <ui/DebugUtils.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 40 | #include <ui/GraphicBuffer.h> |
| 41 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 42 | #include <hardware/hardware.h> |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 43 | #include <hardware/hwcomposer.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 44 | |
Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 45 | #include <android/configuration.h> |
| 46 | |
Mathias Agopian | e2c4f4e | 2012-04-10 18:25:31 -0700 | [diff] [blame] | 47 | #include <cutils/properties.h> |
Mark Salyzyn | 7823e12 | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 48 | #include <log/log.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 49 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 50 | #include "HWComposer.h" |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 51 | #include "HWC2.h" |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 52 | #include "ComposerHal.h" |
Mathias Agopian | 33ceeb3 | 2013-04-01 16:54:58 -0700 | [diff] [blame] | 53 | |
| 54 | #include "../Layer.h" // needed only for debugging |
| 55 | #include "../SurfaceFlinger.h" |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 56 | |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 57 | #define LOG_HWC_DISPLAY_ERROR(hwcDisplayId, msg) \ |
| 58 | ALOGE("%s failed for HWC display %" PRIu64 ": %s", __FUNCTION__, hwcDisplayId, msg) |
| 59 | |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 60 | #define LOG_DISPLAY_ERROR(displayId, msg) \ |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame^] | 61 | ALOGE("%s failed for display %s: %s", __FUNCTION__, to_string(displayId).c_str(), msg) |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 62 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame^] | 63 | #define LOG_HWC_ERROR(what, error, displayId) \ |
| 64 | ALOGE("%s: %s failed for display %s: %s (%d)", __FUNCTION__, what, \ |
| 65 | to_string(displayId).c_str(), to_string(error).c_str(), static_cast<int32_t>(error)) |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 66 | |
| 67 | #define RETURN_IF_INVALID_DISPLAY(displayId, ...) \ |
| 68 | do { \ |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 69 | if (mDisplayData.count(displayId) == 0) { \ |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 70 | LOG_DISPLAY_ERROR(displayId, "Invalid display"); \ |
| 71 | return __VA_ARGS__; \ |
| 72 | } \ |
| 73 | } while (false) |
| 74 | |
| 75 | #define RETURN_IF_HWC_ERROR_FOR(what, error, displayId, ...) \ |
| 76 | do { \ |
| 77 | if (error != HWC2::Error::None) { \ |
| 78 | LOG_HWC_ERROR(what, error, displayId); \ |
| 79 | return __VA_ARGS__; \ |
| 80 | } \ |
| 81 | } while (false) |
| 82 | |
| 83 | #define RETURN_IF_HWC_ERROR(error, displayId, ...) \ |
| 84 | RETURN_IF_HWC_ERROR_FOR(__FUNCTION__, error, displayId, __VA_ARGS__) |
| 85 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 86 | namespace android { |
Jesse Hall | 5880cc5 | 2012-06-05 23:40:32 -0700 | [diff] [blame] | 87 | |
Jesse Hall | 7296051 | 2013-01-10 16:19:56 -0800 | [diff] [blame] | 88 | #define MIN_HWC_HEADER_VERSION HWC_HEADER_VERSION |
Jesse Hall | 9eb1eb5 | 2012-08-29 10:39:38 -0700 | [diff] [blame] | 89 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 90 | // --------------------------------------------------------------------------- |
| 91 | |
Lloyd Pique | a822d52 | 2017-12-20 16:42:57 -0800 | [diff] [blame] | 92 | HWComposer::HWComposer(std::unique_ptr<android::Hwc2::Composer> composer) |
| 93 | : mHwcDevice(std::make_unique<HWC2::Device>(std::move(composer))) {} |
Mathias Agopian | bef42c5 | 2013-08-21 17:45:46 -0700 | [diff] [blame] | 94 | |
Dominik Laskowski | b04f98a | 2018-11-07 21:07:16 -0800 | [diff] [blame] | 95 | HWComposer::~HWComposer() { |
| 96 | mDisplayData.clear(); |
| 97 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 98 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 99 | void HWComposer::registerCallback(HWC2::ComposerCallback* callback, |
| 100 | int32_t sequenceId) { |
| 101 | mHwcDevice->registerCallback(callback, sequenceId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Dominik Laskowski | a2edf61 | 2018-06-01 13:15:16 -0700 | [diff] [blame] | 104 | bool HWComposer::getDisplayIdentificationData(hwc2_display_t hwcDisplayId, uint8_t* outPort, |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 105 | DisplayIdentificationData* outData) const { |
Dominik Laskowski | 0954b1d | 2018-06-13 14:58:49 -0700 | [diff] [blame] | 106 | const auto error = mHwcDevice->getDisplayIdentificationData(hwcDisplayId, outPort, outData); |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 107 | if (error != HWC2::Error::None) { |
Chia-I Wu | d0aff9d | 2018-06-21 13:39:09 +0800 | [diff] [blame] | 108 | if (error != HWC2::Error::Unsupported) { |
| 109 | LOG_HWC_DISPLAY_ERROR(hwcDisplayId, to_string(error).c_str()); |
| 110 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 111 | return false; |
| 112 | } |
| 113 | return true; |
| 114 | } |
| 115 | |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 116 | bool HWComposer::hasCapability(HWC2::Capability capability) const |
| 117 | { |
| 118 | return mHwcDevice->getCapabilities().count(capability) > 0; |
| 119 | } |
| 120 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 121 | void HWComposer::validateChange(HWC2::Composition from, HWC2::Composition to) { |
| 122 | bool valid = true; |
| 123 | switch (from) { |
| 124 | case HWC2::Composition::Client: |
| 125 | valid = false; |
| 126 | break; |
| 127 | case HWC2::Composition::Device: |
| 128 | case HWC2::Composition::SolidColor: |
| 129 | valid = (to == HWC2::Composition::Client); |
| 130 | break; |
| 131 | case HWC2::Composition::Cursor: |
| 132 | case HWC2::Composition::Sideband: |
| 133 | valid = (to == HWC2::Composition::Client || |
| 134 | to == HWC2::Composition::Device); |
| 135 | break; |
| 136 | default: |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | if (!valid) { |
| 141 | ALOGE("Invalid layer type change: %s --> %s", to_string(from).c_str(), |
| 142 | to_string(to).c_str()); |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 146 | std::optional<DisplayIdentificationInfo> HWComposer::onHotplug(hwc2_display_t hwcDisplayId, |
| 147 | HWC2::Connection connection) { |
| 148 | std::optional<DisplayIdentificationInfo> info; |
Lloyd Pique | 715a2c1 | 2017-12-14 17:18:08 -0800 | [diff] [blame] | 149 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 150 | if (const auto displayId = toPhysicalDisplayId(hwcDisplayId)) { |
| 151 | info = DisplayIdentificationInfo{*displayId, std::string()}; |
| 152 | } else { |
| 153 | if (connection == HWC2::Connection::Disconnected) { |
| 154 | ALOGE("Ignoring disconnection of invalid HWC display %" PRIu64, hwcDisplayId); |
| 155 | return {}; |
Lloyd Pique | 438e9e7 | 2018-09-04 18:06:08 -0700 | [diff] [blame] | 156 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 157 | |
| 158 | info = onHotplugConnect(hwcDisplayId); |
| 159 | if (!info) return {}; |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame^] | 162 | ALOGV("%s: %s %s display %s with HWC ID %" PRIu64, __FUNCTION__, to_string(connection).c_str(), |
| 163 | hwcDisplayId == mInternalHwcDisplayId ? "internal" : "external", |
| 164 | to_string(info->id).c_str(), hwcDisplayId); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 165 | |
| 166 | mHwcDevice->onHotplug(hwcDisplayId, connection); |
| 167 | |
Lloyd Pique | 715a2c1 | 2017-12-14 17:18:08 -0800 | [diff] [blame] | 168 | // Disconnect is handled through HWComposer::disconnectDisplay via |
| 169 | // SurfaceFlinger's onHotplugReceived callback handling |
| 170 | if (connection == HWC2::Connection::Connected) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 171 | mDisplayData[info->id].hwcDisplay = mHwcDevice->getDisplayById(hwcDisplayId); |
| 172 | mPhysicalDisplayIdMap[hwcDisplayId] = info->id; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 173 | } |
Dominik Laskowski | e9ef7c4 | 2018-03-12 19:34:30 -0700 | [diff] [blame] | 174 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 175 | return info; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 178 | bool HWComposer::onVsync(hwc2_display_t hwcDisplayId, int64_t timestamp) { |
| 179 | const auto displayId = toPhysicalDisplayId(hwcDisplayId); |
| 180 | if (!displayId) { |
| 181 | LOG_HWC_DISPLAY_ERROR(hwcDisplayId, "Invalid HWC display"); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 182 | return false; |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 183 | } |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 184 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 185 | RETURN_IF_INVALID_DISPLAY(*displayId, false); |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 186 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 187 | const auto& displayData = mDisplayData[*displayId]; |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 188 | if (displayData.isVirtual) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 189 | LOG_DISPLAY_ERROR(*displayId, "Invalid operation on virtual display"); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 190 | return false; |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 193 | { |
| 194 | Mutex::Autolock _l(mLock); |
Jesse Hall | 1bd20e0 | 2012-08-29 10:47:52 -0700 | [diff] [blame] | 195 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 196 | // There have been reports of HWCs that signal several vsync events |
| 197 | // with the same timestamp when turning the display off and on. This |
| 198 | // is a bug in the HWC implementation, but filter the extra events |
| 199 | // out here so they don't cause havoc downstream. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 200 | if (timestamp == mLastHwVSync[*displayId]) { |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame^] | 201 | ALOGW("Ignoring duplicate VSYNC event from HWC for display %s (t=%" PRId64 ")", |
| 202 | to_string(*displayId).c_str(), timestamp); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 203 | return false; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 206 | mLastHwVSync[*displayId] = timestamp; |
Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 207 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 208 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame^] | 209 | const auto tag = "HW_VSYNC_" + to_string(*displayId); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 210 | ATRACE_INT(tag.c_str(), ++mVSyncCounts[*displayId] & 1); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 211 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 212 | return true; |
Jesse Hall | 1c569c4 | 2013-04-05 13:44:52 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 215 | std::optional<DisplayId> HWComposer::allocateVirtualDisplay(uint32_t width, uint32_t height, |
| 216 | ui::PixelFormat* format) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 217 | if (mRemainingHwcVirtualDisplays == 0) { |
Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 218 | ALOGE("%s: No remaining virtual displays", __FUNCTION__); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 219 | return {}; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 220 | } |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 221 | |
Fabien Sanglard | c8e387e | 2017-03-10 10:30:28 -0800 | [diff] [blame] | 222 | if (SurfaceFlinger::maxVirtualDisplaySize != 0 && |
| 223 | (width > SurfaceFlinger::maxVirtualDisplaySize || |
| 224 | height > SurfaceFlinger::maxVirtualDisplaySize)) { |
Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 225 | ALOGE("%s: Display size %ux%u exceeds maximum dimension of %" PRIu64, __FUNCTION__, width, |
| 226 | height, SurfaceFlinger::maxVirtualDisplaySize); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 227 | return {}; |
Fabien Sanglard | e29055f | 2017-03-08 11:36:46 -0800 | [diff] [blame] | 228 | } |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 229 | HWC2::Display* display; |
Dan Stoza | 5cf424b | 2016-05-20 14:02:39 -0700 | [diff] [blame] | 230 | auto error = mHwcDevice->createVirtualDisplay(width, height, format, |
| 231 | &display); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 232 | if (error != HWC2::Error::None) { |
Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 233 | ALOGE("%s: Failed to create HWC virtual display", __FUNCTION__); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 234 | return {}; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 235 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 236 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 237 | DisplayId displayId; |
| 238 | if (mFreeVirtualDisplayIds.empty()) { |
| 239 | displayId = getVirtualDisplayId(mNextVirtualDisplayId++); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 240 | } else { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 241 | displayId = *mFreeVirtualDisplayIds.begin(); |
| 242 | mFreeVirtualDisplayIds.erase(displayId); |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 243 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 244 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 245 | auto& displayData = mDisplayData[displayId]; |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 246 | displayData.hwcDisplay = display; |
| 247 | displayData.isVirtual = true; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 248 | |
| 249 | --mRemainingHwcVirtualDisplays; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 250 | return displayId; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 253 | HWC2::Layer* HWComposer::createLayer(DisplayId displayId) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 254 | RETURN_IF_INVALID_DISPLAY(displayId, nullptr); |
| 255 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 256 | auto display = mDisplayData[displayId].hwcDisplay; |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 257 | HWC2::Layer* layer; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 258 | auto error = display->createLayer(&layer); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 259 | RETURN_IF_HWC_ERROR(error, displayId, nullptr); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 260 | return layer; |
| 261 | } |
| 262 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 263 | void HWComposer::destroyLayer(DisplayId displayId, HWC2::Layer* layer) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 264 | RETURN_IF_INVALID_DISPLAY(displayId); |
| 265 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 266 | auto display = mDisplayData[displayId].hwcDisplay; |
| 267 | auto error = display->destroyLayer(layer); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 268 | RETURN_IF_HWC_ERROR(error, displayId); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 271 | nsecs_t HWComposer::getRefreshTimestamp(DisplayId displayId) const { |
| 272 | RETURN_IF_INVALID_DISPLAY(displayId, 0); |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 273 | // this returns the last refresh timestamp. |
| 274 | // if the last one is not available, we estimate it based on |
| 275 | // the refresh period and whatever closest timestamp we have. |
| 276 | Mutex::Autolock _l(mLock); |
| 277 | nsecs_t now = systemTime(CLOCK_MONOTONIC); |
Fabien Sanglard | df0b705 | 2016-11-30 15:51:53 -0800 | [diff] [blame] | 278 | auto vsyncPeriod = getActiveConfig(displayId)->getVsyncPeriod(); |
| 279 | return now - ((now - mLastHwVSync[displayId]) % vsyncPeriod); |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 282 | bool HWComposer::isConnected(DisplayId displayId) const { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 283 | RETURN_IF_INVALID_DISPLAY(displayId, false); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 284 | return mDisplayData.at(displayId).hwcDisplay->isConnected(); |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 287 | std::vector<std::shared_ptr<const HWC2::Display::Config>> HWComposer::getConfigs( |
| 288 | DisplayId displayId) const { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 289 | RETURN_IF_INVALID_DISPLAY(displayId, {}); |
| 290 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 291 | const auto& displayData = mDisplayData.at(displayId); |
| 292 | auto configs = displayData.hwcDisplay->getConfigs(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 293 | if (displayData.configMap.empty()) { |
| 294 | for (size_t i = 0; i < configs.size(); ++i) { |
| 295 | displayData.configMap[i] = configs[i]; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 298 | return configs; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 301 | std::shared_ptr<const HWC2::Display::Config> HWComposer::getActiveConfig( |
| 302 | DisplayId displayId) const { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 303 | RETURN_IF_INVALID_DISPLAY(displayId, nullptr); |
| 304 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 305 | std::shared_ptr<const HWC2::Display::Config> config; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 306 | auto error = mDisplayData.at(displayId).hwcDisplay->getActiveConfig(&config); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 307 | if (error == HWC2::Error::BadConfig) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 308 | LOG_DISPLAY_ERROR(displayId, "No active config"); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 309 | return nullptr; |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | RETURN_IF_HWC_ERROR(error, displayId, nullptr); |
| 313 | |
| 314 | if (!config) { |
| 315 | LOG_DISPLAY_ERROR(displayId, "Unknown config"); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 316 | return nullptr; |
| 317 | } |
| 318 | |
| 319 | return config; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 322 | int HWComposer::getActiveConfigIndex(DisplayId displayId) const { |
Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 323 | RETURN_IF_INVALID_DISPLAY(displayId, -1); |
| 324 | |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 325 | int index; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 326 | auto error = mDisplayData.at(displayId).hwcDisplay->getActiveConfigIndex(&index); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 327 | if (error == HWC2::Error::BadConfig) { |
Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 328 | LOG_DISPLAY_ERROR(displayId, "No active config"); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 329 | return -1; |
Dominik Laskowski | f3749f8 | 2018-06-13 15:49:25 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | RETURN_IF_HWC_ERROR(error, displayId, -1); |
| 333 | |
| 334 | if (index < 0) { |
| 335 | LOG_DISPLAY_ERROR(displayId, "Unknown config"); |
Lloyd Pique | 3c085a0 | 2018-05-09 19:38:32 -0700 | [diff] [blame] | 336 | return -1; |
| 337 | } |
| 338 | |
| 339 | return index; |
| 340 | } |
| 341 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 342 | std::vector<ui::ColorMode> HWComposer::getColorModes(DisplayId displayId) const { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 343 | RETURN_IF_INVALID_DISPLAY(displayId, {}); |
| 344 | |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 345 | std::vector<ui::ColorMode> modes; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 346 | auto error = mDisplayData.at(displayId).hwcDisplay->getColorModes(&modes); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 347 | RETURN_IF_HWC_ERROR(error, displayId, {}); |
Courtney Goeltzenleuchter | fad9d8c | 2016-06-23 11:49:50 -0600 | [diff] [blame] | 348 | return modes; |
| 349 | } |
| 350 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 351 | status_t HWComposer::setActiveColorMode(DisplayId displayId, ui::ColorMode mode, |
| 352 | ui::RenderIntent renderIntent) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 353 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 354 | |
| 355 | auto& displayData = mDisplayData[displayId]; |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 356 | auto error = displayData.hwcDisplay->setColorMode(mode, renderIntent); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 357 | RETURN_IF_HWC_ERROR_FOR(("setColorMode(" + decodeColorMode(mode) + ", " + |
| 358 | decodeRenderIntent(renderIntent) + ")") |
| 359 | .c_str(), |
| 360 | error, displayId, UNKNOWN_ERROR); |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 361 | |
| 362 | return NO_ERROR; |
| 363 | } |
| 364 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 365 | void HWComposer::setVsyncEnabled(DisplayId displayId, HWC2::Vsync enabled) { |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 366 | RETURN_IF_INVALID_DISPLAY(displayId); |
| 367 | auto& displayData = mDisplayData[displayId]; |
| 368 | |
| 369 | if (displayData.isVirtual) { |
| 370 | LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display"); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 371 | return; |
| 372 | } |
| 373 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 374 | // NOTE: we use our own internal lock here because we have to call |
| 375 | // into the HWC with the lock held, and we want to make sure |
| 376 | // that even if HWC blocks (which it shouldn't), it won't |
| 377 | // affect other threads. |
| 378 | Mutex::Autolock _l(mVsyncLock); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 379 | if (enabled != displayData.vsyncEnabled) { |
| 380 | ATRACE_CALL(); |
| 381 | auto error = displayData.hwcDisplay->setVsyncEnabled(enabled); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 382 | RETURN_IF_HWC_ERROR(error, displayId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 383 | |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 384 | displayData.vsyncEnabled = enabled; |
| 385 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame^] | 386 | const auto tag = "HW_VSYNC_ON_" + to_string(displayId); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 387 | ATRACE_INT(tag.c_str(), enabled == HWC2::Vsync::Enable ? 1 : 0); |
Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 388 | } |
Colin Cross | 10fbdb6 | 2012-07-12 17:56:34 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 391 | status_t HWComposer::setClientTarget(DisplayId displayId, uint32_t slot, |
| 392 | const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target, |
| 393 | ui::Dataspace dataspace) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 394 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 395 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame^] | 396 | ALOGV("%s for display %s", __FUNCTION__, to_string(displayId).c_str()); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 397 | auto& hwcDisplay = mDisplayData[displayId].hwcDisplay; |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame] | 398 | auto error = hwcDisplay->setClientTarget(slot, target, acquireFence, dataspace); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 399 | RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE); |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 400 | return NO_ERROR; |
| 401 | } |
| 402 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 403 | status_t HWComposer::prepare(DisplayId displayId, std::vector<CompositionInfo>& compositionData) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 404 | ATRACE_CALL(); |
| 405 | |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 406 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 407 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 408 | Mutex::Autolock _l(mDisplayLock); |
| 409 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 410 | auto& displayData = mDisplayData[displayId]; |
| 411 | auto& hwcDisplay = displayData.hwcDisplay; |
| 412 | if (!hwcDisplay->isConnected()) { |
| 413 | return NO_ERROR; |
| 414 | } |
| 415 | |
| 416 | uint32_t numTypes = 0; |
| 417 | uint32_t numRequests = 0; |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 418 | |
| 419 | HWC2::Error error = HWC2::Error::None; |
| 420 | |
Chia-I Wu | 41b98d4 | 2017-12-11 11:04:36 -0800 | [diff] [blame] | 421 | // First try to skip validate altogether when there is no client |
| 422 | // composition. When there is client composition, since we haven't |
| 423 | // rendered to the client target yet, we should not attempt to skip |
| 424 | // validate. |
| 425 | // |
| 426 | // displayData.hasClientComposition hasn't been updated for this frame. |
| 427 | // The check below is incorrect. We actually rely on HWC here to fall |
| 428 | // back to validate when there is any client layer. |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 429 | displayData.validateWasSkipped = false; |
Chia-I Wu | 41b98d4 | 2017-12-11 11:04:36 -0800 | [diff] [blame] | 430 | if (!displayData.hasClientComposition) { |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 431 | sp<android::Fence> outPresentFence; |
| 432 | uint32_t state = UINT32_MAX; |
| 433 | error = hwcDisplay->presentOrValidate(&numTypes, &numRequests, &outPresentFence , &state); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 434 | if (error != HWC2::Error::HasChanges) { |
| 435 | RETURN_IF_HWC_ERROR_FOR("presentOrValidate", error, displayId, UNKNOWN_ERROR); |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 436 | } |
| 437 | if (state == 1) { //Present Succeeded. |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 438 | std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 439 | error = hwcDisplay->getReleaseFences(&releaseFences); |
| 440 | displayData.releaseFences = std::move(releaseFences); |
| 441 | displayData.lastPresentFence = outPresentFence; |
| 442 | displayData.validateWasSkipped = true; |
| 443 | displayData.presentError = error; |
| 444 | return NO_ERROR; |
| 445 | } |
| 446 | // Present failed but Validate ran. |
| 447 | } else { |
| 448 | error = hwcDisplay->validate(&numTypes, &numRequests); |
| 449 | } |
| 450 | ALOGV("SkipValidate failed, Falling back to SLOW validate/present"); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 451 | if (error != HWC2::Error::HasChanges) { |
| 452 | RETURN_IF_HWC_ERROR_FOR("validate", error, displayId, BAD_INDEX); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 455 | std::unordered_map<HWC2::Layer*, HWC2::Composition> changedTypes; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 456 | changedTypes.reserve(numTypes); |
| 457 | error = hwcDisplay->getChangedCompositionTypes(&changedTypes); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 458 | RETURN_IF_HWC_ERROR_FOR("getChangedCompositionTypes", error, displayId, BAD_INDEX); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 459 | |
| 460 | displayData.displayRequests = static_cast<HWC2::DisplayRequest>(0); |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 461 | std::unordered_map<HWC2::Layer*, HWC2::LayerRequest> layerRequests; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 462 | layerRequests.reserve(numRequests); |
| 463 | error = hwcDisplay->getRequests(&displayData.displayRequests, |
| 464 | &layerRequests); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 465 | RETURN_IF_HWC_ERROR_FOR("getRequests", error, displayId, BAD_INDEX); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 466 | |
| 467 | displayData.hasClientComposition = false; |
| 468 | displayData.hasDeviceComposition = false; |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 469 | for (auto& compositionInfo : compositionData) { |
| 470 | auto hwcLayer = compositionInfo.hwc.hwcLayer; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 471 | |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 472 | if (changedTypes.count(&*hwcLayer) != 0) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 473 | // We pass false so we only update our state and don't call back |
| 474 | // into the HWC device |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 475 | validateChange(compositionInfo.compositionType, |
| 476 | changedTypes[&*hwcLayer]); |
| 477 | compositionInfo.compositionType = changedTypes[&*hwcLayer]; |
David Sodman | c1498e6 | 2018-09-12 14:36:26 -0700 | [diff] [blame] | 478 | compositionInfo.layer->mLayer->setCompositionType(displayId, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 479 | compositionInfo.compositionType, |
| 480 | false); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 481 | } |
| 482 | |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 483 | switch (compositionInfo.compositionType) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 484 | case HWC2::Composition::Client: |
| 485 | displayData.hasClientComposition = true; |
| 486 | break; |
| 487 | case HWC2::Composition::Device: |
| 488 | case HWC2::Composition::SolidColor: |
| 489 | case HWC2::Composition::Cursor: |
| 490 | case HWC2::Composition::Sideband: |
| 491 | displayData.hasDeviceComposition = true; |
| 492 | break; |
| 493 | default: |
| 494 | break; |
| 495 | } |
| 496 | |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 497 | if (layerRequests.count(&*hwcLayer) != 0 && |
| 498 | layerRequests[&*hwcLayer] == |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 499 | HWC2::LayerRequest::ClearClientTarget) { |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 500 | compositionInfo.hwc.clearClientTarget = true; |
David Sodman | c1498e6 | 2018-09-12 14:36:26 -0700 | [diff] [blame] | 501 | compositionInfo.layer->mLayer->setClearClientTarget(displayId, true); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 502 | } else { |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 503 | if (layerRequests.count(&*hwcLayer) != 0) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 504 | LOG_DISPLAY_ERROR(displayId, |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 505 | ("Unknown layer request " + to_string(layerRequests[&*hwcLayer])) |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 506 | .c_str()); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 507 | } |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 508 | compositionInfo.hwc.clearClientTarget = false; |
David Sodman | c1498e6 | 2018-09-12 14:36:26 -0700 | [diff] [blame] | 509 | compositionInfo.layer->mLayer->setClearClientTarget(displayId, false); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | error = hwcDisplay->acceptChanges(); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 514 | RETURN_IF_HWC_ERROR_FOR("acceptChanges", error, displayId, BAD_INDEX); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 515 | |
| 516 | return NO_ERROR; |
| 517 | } |
| 518 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 519 | bool HWComposer::hasDeviceComposition(const std::optional<DisplayId>& displayId) const { |
| 520 | if (!displayId) { |
Dan Stoza | ec0f717 | 2016-07-21 11:09:40 -0700 | [diff] [blame] | 521 | // Displays without a corresponding HWC display are never composed by |
| 522 | // the device |
| 523 | return false; |
| 524 | } |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 525 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 526 | RETURN_IF_INVALID_DISPLAY(*displayId, false); |
| 527 | return mDisplayData.at(*displayId).hasDeviceComposition; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 530 | bool HWComposer::hasFlipClientTargetRequest(const std::optional<DisplayId>& displayId) const { |
| 531 | if (!displayId) { |
Madhuri Athota | 88a905b | 2017-05-04 16:58:15 +0530 | [diff] [blame] | 532 | // Displays without a corresponding HWC display are never composed by |
| 533 | // the device |
| 534 | return false; |
| 535 | } |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 536 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 537 | RETURN_IF_INVALID_DISPLAY(*displayId, false); |
| 538 | return ((static_cast<uint32_t>(mDisplayData.at(*displayId).displayRequests) & |
Madhuri Athota | 88a905b | 2017-05-04 16:58:15 +0530 | [diff] [blame] | 539 | static_cast<uint32_t>(HWC2::DisplayRequest::FlipClientTarget)) != 0); |
| 540 | } |
| 541 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 542 | bool HWComposer::hasClientComposition(const std::optional<DisplayId>& displayId) const { |
| 543 | if (!displayId) { |
Dan Stoza | ec0f717 | 2016-07-21 11:09:40 -0700 | [diff] [blame] | 544 | // Displays without a corresponding HWC display are always composed by |
| 545 | // the client |
| 546 | return true; |
| 547 | } |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 548 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 549 | RETURN_IF_INVALID_DISPLAY(*displayId, true); |
| 550 | return mDisplayData.at(*displayId).hasClientComposition; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 551 | } |
| 552 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 553 | sp<Fence> HWComposer::getPresentFence(DisplayId displayId) const { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 554 | RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 555 | return mDisplayData.at(displayId).lastPresentFence; |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 558 | sp<Fence> HWComposer::getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 559 | RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 560 | auto displayFences = mDisplayData.at(displayId).releaseFences; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 561 | if (displayFences.count(layer) == 0) { |
| 562 | ALOGV("getLayerReleaseFence: Release fence not found"); |
| 563 | return Fence::NO_FENCE; |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 564 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 565 | return displayFences[layer]; |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 568 | status_t HWComposer::presentAndGetReleaseFences(DisplayId displayId) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 569 | ATRACE_CALL(); |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 570 | |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 571 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Pablo Ceballos | d814cf2 | 2015-09-11 14:37:39 -0700 | [diff] [blame] | 572 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 573 | auto& displayData = mDisplayData[displayId]; |
| 574 | auto& hwcDisplay = displayData.hwcDisplay; |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 575 | |
| 576 | if (displayData.validateWasSkipped) { |
Chia-I Wu | ae5a6b8 | 2017-10-10 09:09:22 -0700 | [diff] [blame] | 577 | // explicitly flush all pending commands |
| 578 | auto error = mHwcDevice->flushCommands(); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 579 | RETURN_IF_HWC_ERROR_FOR("flushCommands", error, displayId, UNKNOWN_ERROR); |
| 580 | RETURN_IF_HWC_ERROR_FOR("present", displayData.presentError, displayId, UNKNOWN_ERROR); |
Fabien Sanglard | 249c0ae | 2017-06-19 19:22:36 -0700 | [diff] [blame] | 581 | return NO_ERROR; |
| 582 | } |
| 583 | |
Fabien Sanglard | 11d0fc3 | 2016-12-01 15:43:01 -0800 | [diff] [blame] | 584 | auto error = hwcDisplay->present(&displayData.lastPresentFence); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 585 | RETURN_IF_HWC_ERROR_FOR("present", error, displayId, UNKNOWN_ERROR); |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 586 | |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 587 | std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 588 | error = hwcDisplay->getReleaseFences(&releaseFences); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 589 | RETURN_IF_HWC_ERROR_FOR("getReleaseFences", error, displayId, UNKNOWN_ERROR); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 590 | |
| 591 | displayData.releaseFences = std::move(releaseFences); |
| 592 | |
| 593 | return NO_ERROR; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 596 | status_t HWComposer::setPowerMode(DisplayId displayId, int32_t intMode) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 597 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
| 598 | |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 599 | const auto& displayData = mDisplayData[displayId]; |
| 600 | if (displayData.isVirtual) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 601 | LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display"); |
| 602 | return INVALID_OPERATION; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 603 | } |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 604 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 605 | auto mode = static_cast<HWC2::PowerMode>(intMode); |
| 606 | if (mode == HWC2::PowerMode::Off) { |
| 607 | setVsyncEnabled(displayId, HWC2::Vsync::Disable); |
| 608 | } |
| 609 | |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 610 | auto& hwcDisplay = displayData.hwcDisplay; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 611 | switch (mode) { |
| 612 | case HWC2::PowerMode::Off: |
| 613 | case HWC2::PowerMode::On: |
| 614 | ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str()); |
| 615 | { |
| 616 | auto error = hwcDisplay->setPowerMode(mode); |
Peiyong Lin | 306e499 | 2018-05-07 16:18:22 -0700 | [diff] [blame] | 617 | if (error != HWC2::Error::None) { |
| 618 | LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), |
| 619 | error, displayId); |
| 620 | } |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 621 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 622 | break; |
| 623 | case HWC2::PowerMode::Doze: |
| 624 | case HWC2::PowerMode::DozeSuspend: |
| 625 | ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str()); |
| 626 | { |
| 627 | bool supportsDoze = false; |
| 628 | auto error = hwcDisplay->supportsDoze(&supportsDoze); |
Peiyong Lin | 306e499 | 2018-05-07 16:18:22 -0700 | [diff] [blame] | 629 | if (error != HWC2::Error::None) { |
| 630 | LOG_HWC_ERROR("supportsDoze", error, displayId); |
| 631 | } |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 632 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 633 | if (!supportsDoze) { |
| 634 | mode = HWC2::PowerMode::On; |
| 635 | } |
| 636 | |
| 637 | error = hwcDisplay->setPowerMode(mode); |
Peiyong Lin | 306e499 | 2018-05-07 16:18:22 -0700 | [diff] [blame] | 638 | if (error != HWC2::Error::None) { |
| 639 | LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), |
| 640 | error, displayId); |
| 641 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 642 | } |
| 643 | break; |
| 644 | default: |
| 645 | ALOGV("setPowerMode: Not calling HWC"); |
| 646 | break; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 647 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 648 | |
| 649 | return NO_ERROR; |
| 650 | } |
| 651 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 652 | status_t HWComposer::setActiveConfig(DisplayId displayId, size_t configId) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 653 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 654 | |
| 655 | auto& displayData = mDisplayData[displayId]; |
| 656 | if (displayData.configMap.count(configId) == 0) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 657 | LOG_DISPLAY_ERROR(displayId, ("Invalid config " + std::to_string(configId)).c_str()); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 658 | return BAD_INDEX; |
| 659 | } |
| 660 | |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 661 | auto error = displayData.hwcDisplay->setActiveConfig(displayData.configMap[configId]); |
| 662 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 663 | return NO_ERROR; |
| 664 | } |
| 665 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 666 | status_t HWComposer::setColorTransform(DisplayId displayId, const mat4& transform) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 667 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 668 | |
| 669 | auto& displayData = mDisplayData[displayId]; |
| 670 | bool isIdentity = transform == mat4(); |
| 671 | auto error = displayData.hwcDisplay->setColorTransform(transform, |
| 672 | isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : |
| 673 | HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 674 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 675 | return NO_ERROR; |
| 676 | } |
| 677 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 678 | void HWComposer::disconnectDisplay(DisplayId displayId) { |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 679 | RETURN_IF_INVALID_DISPLAY(displayId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 680 | auto& displayData = mDisplayData[displayId]; |
| 681 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 682 | // If this was a virtual display, add its slot back for reuse by future |
| 683 | // virtual displays |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 684 | if (displayData.isVirtual) { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 685 | mFreeVirtualDisplayIds.insert(displayId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 686 | ++mRemainingHwcVirtualDisplays; |
| 687 | } |
| 688 | |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 689 | const auto hwcDisplayId = displayData.hwcDisplay->getId(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 690 | mPhysicalDisplayIdMap.erase(hwcDisplayId); |
| 691 | mDisplayData.erase(displayId); |
| 692 | mVSyncCounts.erase(displayId); |
| 693 | |
| 694 | // TODO(b/74619554): Select internal/external display from remaining displays. |
| 695 | if (hwcDisplayId == mInternalHwcDisplayId) { |
| 696 | mInternalHwcDisplayId.reset(); |
| 697 | } else if (hwcDisplayId == mExternalHwcDisplayId) { |
| 698 | mExternalHwcDisplayId.reset(); |
| 699 | } |
Steven Thomas | 94e35b9 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 700 | |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 701 | mHwcDevice->destroyDisplay(hwcDisplayId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 702 | } |
| 703 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 704 | status_t HWComposer::setOutputBuffer(DisplayId displayId, const sp<Fence>& acquireFence, |
| 705 | const sp<GraphicBuffer>& buffer) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 706 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 707 | const auto& displayData = mDisplayData[displayId]; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 708 | |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 709 | if (!displayData.isVirtual) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 710 | LOG_DISPLAY_ERROR(displayId, "Invalid operation on physical display"); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 711 | return INVALID_OPERATION; |
| 712 | } |
| 713 | |
Dominik Laskowski | c1f18f6 | 2018-06-13 15:17:55 -0700 | [diff] [blame] | 714 | auto error = displayData.hwcDisplay->setOutputBuffer(buffer, acquireFence); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 715 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 716 | return NO_ERROR; |
| 717 | } |
| 718 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 719 | void HWComposer::clearReleaseFences(DisplayId displayId) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 720 | RETURN_IF_INVALID_DISPLAY(displayId); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 721 | mDisplayData[displayId].releaseFences.clear(); |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 724 | status_t HWComposer::getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 725 | RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX); |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 726 | |
| 727 | auto& hwcDisplay = mDisplayData[displayId].hwcDisplay; |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 728 | auto error = hwcDisplay->getHdrCapabilities(outCapabilities); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 729 | RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR); |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 730 | return NO_ERROR; |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 733 | int32_t HWComposer::getSupportedPerFrameMetadata(DisplayId displayId) const { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 734 | RETURN_IF_INVALID_DISPLAY(displayId, 0); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 735 | return mDisplayData.at(displayId).hwcDisplay->getSupportedPerFrameMetadata(); |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 738 | std::vector<ui::RenderIntent> HWComposer::getRenderIntents(DisplayId displayId, |
| 739 | ui::ColorMode colorMode) const { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 740 | RETURN_IF_INVALID_DISPLAY(displayId, {}); |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 741 | |
| 742 | std::vector<ui::RenderIntent> renderIntents; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 743 | auto error = mDisplayData.at(displayId).hwcDisplay->getRenderIntents(colorMode, &renderIntents); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 744 | RETURN_IF_HWC_ERROR(error, displayId, {}); |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 745 | return renderIntents; |
| 746 | } |
| 747 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 748 | mat4 HWComposer::getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) { |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 749 | RETURN_IF_INVALID_DISPLAY(displayId, {}); |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 750 | |
| 751 | mat4 matrix; |
| 752 | auto error = mDisplayData[displayId].hwcDisplay->getDataspaceSaturationMatrix(dataspace, |
| 753 | &matrix); |
Dominik Laskowski | fc2c032 | 2018-04-19 14:47:33 -0700 | [diff] [blame] | 754 | RETURN_IF_HWC_ERROR(error, displayId, {}); |
Peiyong Lin | 0e7a791 | 2018-04-05 14:36:36 -0700 | [diff] [blame] | 755 | return matrix; |
| 756 | } |
| 757 | |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 758 | // Converts a PixelFormat to a human-readable string. Max 11 chars. |
| 759 | // (Could use a table of prefab String8 objects.) |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 760 | /* |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 761 | static String8 getFormatStr(PixelFormat format) { |
| 762 | switch (format) { |
| 763 | case PIXEL_FORMAT_RGBA_8888: return String8("RGBA_8888"); |
| 764 | case PIXEL_FORMAT_RGBX_8888: return String8("RGBx_8888"); |
| 765 | case PIXEL_FORMAT_RGB_888: return String8("RGB_888"); |
| 766 | case PIXEL_FORMAT_RGB_565: return String8("RGB_565"); |
| 767 | case PIXEL_FORMAT_BGRA_8888: return String8("BGRA_8888"); |
Andy McFadden | f0058ca | 2014-05-20 13:28:50 -0700 | [diff] [blame] | 768 | case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: |
| 769 | return String8("ImplDef"); |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 770 | default: |
| 771 | String8 result; |
| 772 | result.appendFormat("? %08x", format); |
| 773 | return result; |
| 774 | } |
| 775 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 776 | */ |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 777 | |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 778 | bool HWComposer::isUsingVrComposer() const { |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 779 | return getComposer()->isUsingVrComposer(); |
Hendrik Wagenaar | 87670ff | 2017-02-01 12:10:46 -0800 | [diff] [blame] | 780 | } |
| 781 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 782 | void HWComposer::dump(String8& result) const { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 783 | // TODO: In order to provide a dump equivalent to HWC1, we need to shadow |
| 784 | // all the state going into the layers. This is probably better done in |
| 785 | // Layer itself, but it's going to take a bit of work to get there. |
| 786 | result.append(mHwcDevice->dump().c_str()); |
Mathias Agopian | 8372785 | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 789 | std::optional<DisplayId> HWComposer::toPhysicalDisplayId(hwc2_display_t hwcDisplayId) const { |
| 790 | if (const auto it = mPhysicalDisplayIdMap.find(hwcDisplayId); |
| 791 | it != mPhysicalDisplayIdMap.end()) { |
| 792 | return it->second; |
| 793 | } |
| 794 | return {}; |
| 795 | } |
| 796 | |
| 797 | std::optional<hwc2_display_t> HWComposer::fromPhysicalDisplayId(DisplayId displayId) const { |
| 798 | if (const auto it = mDisplayData.find(displayId); |
| 799 | it != mDisplayData.end() && !it->second.isVirtual) { |
| 800 | return it->second.hwcDisplay->getId(); |
| 801 | } |
| 802 | return {}; |
| 803 | } |
| 804 | |
| 805 | std::optional<DisplayIdentificationInfo> HWComposer::onHotplugConnect(hwc2_display_t hwcDisplayId) { |
| 806 | if (isUsingVrComposer() && mInternalHwcDisplayId) { |
| 807 | ALOGE("Ignoring connection of external display %" PRIu64 " in VR mode", hwcDisplayId); |
Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 808 | return {}; |
| 809 | } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 810 | |
| 811 | uint8_t port; |
| 812 | DisplayIdentificationData data; |
| 813 | const bool hasMultiDisplaySupport = getDisplayIdentificationData(hwcDisplayId, &port, &data); |
| 814 | |
| 815 | if (mPhysicalDisplayIdMap.empty()) { |
| 816 | mHasMultiDisplaySupport = hasMultiDisplaySupport; |
| 817 | ALOGI("Switching to %s multi-display mode", |
| 818 | hasMultiDisplaySupport ? "generalized" : "legacy"); |
| 819 | } else if (mHasMultiDisplaySupport && !hasMultiDisplaySupport) { |
| 820 | ALOGE("Ignoring connection of display %" PRIu64 " without identification data", |
| 821 | hwcDisplayId); |
| 822 | return {}; |
| 823 | } |
| 824 | |
| 825 | std::optional<DisplayIdentificationInfo> info; |
| 826 | |
| 827 | if (mHasMultiDisplaySupport) { |
| 828 | info = parseDisplayIdentificationData(port, data); |
| 829 | ALOGE_IF(!info, "Failed to parse identification data for display %" PRIu64, hwcDisplayId); |
| 830 | } else if (mInternalHwcDisplayId && mExternalHwcDisplayId) { |
| 831 | ALOGE("Ignoring connection of tertiary display %" PRIu64, hwcDisplayId); |
| 832 | return {}; |
| 833 | } else { |
| 834 | ALOGW_IF(hasMultiDisplaySupport, "Ignoring identification data for display %" PRIu64, |
| 835 | hwcDisplayId); |
| 836 | port = mInternalHwcDisplayId ? HWC_DISPLAY_EXTERNAL : HWC_DISPLAY_PRIMARY; |
| 837 | } |
| 838 | |
| 839 | if (!mInternalHwcDisplayId) { |
| 840 | mInternalHwcDisplayId = hwcDisplayId; |
| 841 | } else if (!mExternalHwcDisplayId) { |
| 842 | mExternalHwcDisplayId = hwcDisplayId; |
| 843 | } |
| 844 | |
| 845 | if (info) return info; |
| 846 | |
| 847 | return DisplayIdentificationInfo{getFallbackDisplayId(port), |
| 848 | hwcDisplayId == mInternalHwcDisplayId ? "Internal display" |
| 849 | : "External display"}; |
Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 850 | } |
| 851 | |
Dominik Laskowski | f9750f2 | 2018-06-06 12:24:53 -0700 | [diff] [blame] | 852 | } // namespace android |