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