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