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