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