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