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