blob: 1677b07c4d0300c45dcf29d6e8d240a2c31363df [file] [log] [blame]
Mathias Agopiana350ff92010-08-10 17:14:02 -07001/*
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 Stoza9e56aa02015-11-02 13:00:03 -080017// #define LOG_NDEBUG 0
18
19#undef LOG_TAG
20#define LOG_TAG "HWComposer"
Mathias Agopian2965b262012-04-08 15:13:32 -070021#define ATRACE_TAG ATRACE_TAG_GRAPHICS
22
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070023#include <inttypes.h>
24#include <math.h>
Mathias Agopiana350ff92010-08-10 17:14:02 -070025#include <stdint.h>
Mathias Agopianf1352df2010-08-11 17:31:33 -070026#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
Mathias Agopiana350ff92010-08-10 17:14:02 -070029#include <sys/types.h>
30
31#include <utils/Errors.h>
Mathias Agopianda27af92012-09-13 18:17:13 -070032#include <utils/misc.h>
Jesse Hall399184a2014-03-03 15:42:54 -080033#include <utils/NativeHandle.h>
Mathias Agopian83727852010-09-23 18:13:21 -070034#include <utils/String8.h>
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070035#include <utils/Thread.h>
Mathias Agopian2965b262012-04-08 15:13:32 -070036#include <utils/Trace.h>
Mathias Agopian22da60c2011-09-09 00:49:11 -070037#include <utils/Vector.h>
Mathias Agopiana350ff92010-08-10 17:14:02 -070038
Mathias Agopian921e6ac2012-07-23 23:11:29 -070039#include <ui/GraphicBuffer.h>
40
Mathias Agopiana350ff92010-08-10 17:14:02 -070041#include <hardware/hardware.h>
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070042#include <hardware/hwcomposer.h>
Mathias Agopiana350ff92010-08-10 17:14:02 -070043
Jesse Hall1c569c42013-04-05 13:44:52 -070044#include <android/configuration.h>
45
Mathias Agopiane2c4f4e2012-04-10 18:25:31 -070046#include <cutils/properties.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -070047#include <log/log.h>
Mathias Agopiana350ff92010-08-10 17:14:02 -070048
Mathias Agopiana350ff92010-08-10 17:14:02 -070049#include "HWComposer.h"
Dan Stoza9e56aa02015-11-02 13:00:03 -080050#include "HWC2.h"
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -080051#include "ComposerHal.h"
Mathias Agopian33ceeb32013-04-01 16:54:58 -070052
53#include "../Layer.h" // needed only for debugging
54#include "../SurfaceFlinger.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070055
56namespace android {
Jesse Hall5880cc52012-06-05 23:40:32 -070057
Jesse Hall72960512013-01-10 16:19:56 -080058#define MIN_HWC_HEADER_VERSION HWC_HEADER_VERSION
Jesse Hall9eb1eb52012-08-29 10:39:38 -070059
Mathias Agopiana350ff92010-08-10 17:14:02 -070060// ---------------------------------------------------------------------------
61
Kalle Raitaa099a242017-01-11 11:17:29 -080062HWComposer::HWComposer(const std::string& serviceName)
Logan Chien23429772017-05-16 10:18:17 +080063 : mHwcDevice(),
Dan Stoza9e56aa02015-11-02 13:00:03 -080064 mDisplayData(2),
65 mFreeDisplaySlots(),
66 mHwcDisplaySlots(),
67 mCBContext(),
Dan Stoza9e56aa02015-11-02 13:00:03 -080068 mVSyncCounts(),
Chia-I Wu15b27e02017-05-11 16:06:07 -070069 mRemainingHwcVirtualDisplays(0)
Mathias Agopiana350ff92010-08-10 17:14:02 -070070{
Mathias Agopianbef42c52013-08-21 17:45:46 -070071 for (size_t i=0 ; i<HWC_NUM_PHYSICAL_DISPLAY_TYPES ; i++) {
72 mLastHwVSync[i] = 0;
73 mVSyncCounts[i] = 0;
74 }
75
Steven Thomas94e35b92017-07-26 18:48:28 -070076 mHwcDevice = std::make_unique<HWC2::Device>(serviceName);
77 mRemainingHwcVirtualDisplays = mHwcDevice->getMaxVirtualDisplayCount();
Mathias Agopiana350ff92010-08-10 17:14:02 -070078}
79
Dan Stoza9e56aa02015-11-02 13:00:03 -080080HWComposer::~HWComposer() {}
81
Steven Thomas94e35b92017-07-26 18:48:28 -070082void HWComposer::registerCallback(HWC2::ComposerCallback* callback,
83 int32_t sequenceId) {
84 mHwcDevice->registerCallback(callback, sequenceId);
Dan Stoza9e56aa02015-11-02 13:00:03 -080085}
86
Dan Stoza9f26a9c2016-06-22 14:51:09 -070087bool HWComposer::hasCapability(HWC2::Capability capability) const
88{
89 return mHwcDevice->getCapabilities().count(capability) > 0;
90}
91
Dan Stoza9e56aa02015-11-02 13:00:03 -080092bool HWComposer::isValidDisplay(int32_t displayId) const {
93 return static_cast<size_t>(displayId) < mDisplayData.size() &&
94 mDisplayData[displayId].hwcDisplay;
95}
96
97void HWComposer::validateChange(HWC2::Composition from, HWC2::Composition to) {
98 bool valid = true;
99 switch (from) {
100 case HWC2::Composition::Client:
101 valid = false;
102 break;
103 case HWC2::Composition::Device:
104 case HWC2::Composition::SolidColor:
105 valid = (to == HWC2::Composition::Client);
106 break;
107 case HWC2::Composition::Cursor:
108 case HWC2::Composition::Sideband:
109 valid = (to == HWC2::Composition::Client ||
110 to == HWC2::Composition::Device);
111 break;
112 default:
113 break;
114 }
115
116 if (!valid) {
117 ALOGE("Invalid layer type change: %s --> %s", to_string(from).c_str(),
118 to_string(to).c_str());
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700119 }
120}
121
Lloyd Pique715a2c12017-12-14 17:18:08 -0800122void HWComposer::onHotplug(hwc2_display_t displayId, int32_t displayType,
Steven Thomas94e35b92017-07-26 18:48:28 -0700123 HWC2::Connection connection) {
Lloyd Pique715a2c12017-12-14 17:18:08 -0800124 if (displayType >= HWC_NUM_PHYSICAL_DISPLAY_TYPES) {
125 ALOGE("Invalid display type of %d", displayType);
126 return;
127 }
128
129 ALOGV("hotplug: %" PRIu64 ", %s %s", displayId,
130 displayType == DisplayDevice::DISPLAY_PRIMARY ? "primary" : "external",
Steven Thomas94e35b92017-07-26 18:48:28 -0700131 to_string(connection).c_str());
132 mHwcDevice->onHotplug(displayId, connection);
Lloyd Pique715a2c12017-12-14 17:18:08 -0800133 // Disconnect is handled through HWComposer::disconnectDisplay via
134 // SurfaceFlinger's onHotplugReceived callback handling
135 if (connection == HWC2::Connection::Connected) {
136 mDisplayData[displayType].hwcDisplay = mHwcDevice->getDisplayById(displayId);
137 mHwcDisplaySlots[displayId] = displayType;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700138 }
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700139}
140
Steven Thomas94e35b92017-07-26 18:48:28 -0700141bool HWComposer::onVsync(hwc2_display_t displayId, int64_t timestamp,
142 int32_t* outDisplay) {
143 auto display = mHwcDevice->getDisplayById(displayId);
144 if (!display) {
145 ALOGE("onVsync Failed to find display %" PRIu64, displayId);
146 return false;
147 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800148 auto displayType = HWC2::DisplayType::Invalid;
149 auto error = display->getType(&displayType);
150 if (error != HWC2::Error::None) {
Steven Thomas94e35b92017-07-26 18:48:28 -0700151 ALOGE("onVsync: Failed to determine type of display %" PRIu64,
Dan Stoza9e56aa02015-11-02 13:00:03 -0800152 display->getId());
Steven Thomas94e35b92017-07-26 18:48:28 -0700153 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700154 }
Jesse Hall1bd20e02012-08-29 10:47:52 -0700155
Dan Stoza9e56aa02015-11-02 13:00:03 -0800156 if (displayType == HWC2::DisplayType::Virtual) {
157 ALOGE("Virtual display %" PRIu64 " passed to vsync callback",
158 display->getId());
Steven Thomas94e35b92017-07-26 18:48:28 -0700159 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700160 }
161
Dan Stoza9e56aa02015-11-02 13:00:03 -0800162 if (mHwcDisplaySlots.count(display->getId()) == 0) {
163 ALOGE("Unknown physical display %" PRIu64 " passed to vsync callback",
164 display->getId());
Steven Thomas94e35b92017-07-26 18:48:28 -0700165 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700166 }
167
Dan Stoza9e56aa02015-11-02 13:00:03 -0800168 int32_t disp = mHwcDisplaySlots[display->getId()];
169 {
170 Mutex::Autolock _l(mLock);
Jesse Hall1bd20e02012-08-29 10:47:52 -0700171
Dan Stoza9e56aa02015-11-02 13:00:03 -0800172 // There have been reports of HWCs that signal several vsync events
173 // with the same timestamp when turning the display off and on. This
174 // is a bug in the HWC implementation, but filter the extra events
175 // out here so they don't cause havoc downstream.
176 if (timestamp == mLastHwVSync[disp]) {
177 ALOGW("Ignoring duplicate VSYNC event from HWC (t=%" PRId64 ")",
178 timestamp);
Steven Thomas94e35b92017-07-26 18:48:28 -0700179 return false;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800180 }
181
182 mLastHwVSync[disp] = timestamp;
Jesse Hall1c569c42013-04-05 13:44:52 -0700183 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800184
Steven Thomas94e35b92017-07-26 18:48:28 -0700185 if (outDisplay) {
186 *outDisplay = disp;
187 }
188
Dan Stoza9e56aa02015-11-02 13:00:03 -0800189 char tag[16];
190 snprintf(tag, sizeof(tag), "HW_VSYNC_%1u", disp);
191 ATRACE_INT(tag, ++mVSyncCounts[disp] & 1);
192
Steven Thomas94e35b92017-07-26 18:48:28 -0700193 return true;
Jesse Hall1c569c42013-04-05 13:44:52 -0700194}
195
Dan Stoza9e56aa02015-11-02 13:00:03 -0800196status_t HWComposer::allocateVirtualDisplay(uint32_t width, uint32_t height,
Dan Stoza5cf424b2016-05-20 14:02:39 -0700197 android_pixel_format_t* format, int32_t *outId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800198 if (mRemainingHwcVirtualDisplays == 0) {
199 ALOGE("allocateVirtualDisplay: No remaining virtual displays");
Mathias Agopiane60b0682012-08-21 23:34:09 -0700200 return NO_MEMORY;
201 }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700202
Fabien Sanglardc8e387e2017-03-10 10:30:28 -0800203 if (SurfaceFlinger::maxVirtualDisplaySize != 0 &&
204 (width > SurfaceFlinger::maxVirtualDisplaySize ||
205 height > SurfaceFlinger::maxVirtualDisplaySize)) {
Fabien Sanglarde29055f2017-03-08 11:36:46 -0800206 ALOGE("createVirtualDisplay: Can't create a virtual display with"
Fabien Sanglardc8e387e2017-03-10 10:30:28 -0800207 " a dimension > %" PRIu64 " (tried %u x %u)",
208 SurfaceFlinger::maxVirtualDisplaySize, width, height);
Fabien Sanglarde29055f2017-03-08 11:36:46 -0800209 return INVALID_OPERATION;
210 }
211
Steven Thomas94e35b92017-07-26 18:48:28 -0700212 HWC2::Display* display;
Dan Stoza5cf424b2016-05-20 14:02:39 -0700213 auto error = mHwcDevice->createVirtualDisplay(width, height, format,
214 &display);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800215 if (error != HWC2::Error::None) {
216 ALOGE("allocateVirtualDisplay: Failed to create HWC virtual display");
217 return NO_MEMORY;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700218 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800219
220 size_t displaySlot = 0;
221 if (!mFreeDisplaySlots.empty()) {
222 displaySlot = *mFreeDisplaySlots.begin();
223 mFreeDisplaySlots.erase(displaySlot);
224 } else if (mDisplayData.size() < INT32_MAX) {
225 // Don't bother allocating a slot larger than we can return
226 displaySlot = mDisplayData.size();
227 mDisplayData.resize(displaySlot + 1);
228 } else {
229 ALOGE("allocateVirtualDisplay: Unable to allocate a display slot");
230 return NO_MEMORY;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700231 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800232
233 mDisplayData[displaySlot].hwcDisplay = display;
234
235 --mRemainingHwcVirtualDisplays;
236 *outId = static_cast<int32_t>(displaySlot);
237
Mathias Agopiane60b0682012-08-21 23:34:09 -0700238 return NO_ERROR;
239}
240
Steven Thomas94e35b92017-07-26 18:48:28 -0700241HWC2::Layer* HWComposer::createLayer(int32_t displayId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800242 if (!isValidDisplay(displayId)) {
243 ALOGE("Failed to create layer on invalid display %d", displayId);
244 return nullptr;
245 }
246 auto display = mDisplayData[displayId].hwcDisplay;
Steven Thomas94e35b92017-07-26 18:48:28 -0700247 HWC2::Layer* layer;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800248 auto error = display->createLayer(&layer);
249 if (error != HWC2::Error::None) {
250 ALOGE("Failed to create layer on display %d: %s (%d)", displayId,
251 to_string(error).c_str(), static_cast<int32_t>(error));
252 return nullptr;
253 }
254 return layer;
255}
256
Steven Thomas94e35b92017-07-26 18:48:28 -0700257void HWComposer::destroyLayer(int32_t displayId, HWC2::Layer* layer) {
258 if (!isValidDisplay(displayId)) {
259 ALOGE("Failed to destroy layer on invalid display %d", displayId);
260 return;
261 }
262 auto display = mDisplayData[displayId].hwcDisplay;
263 auto error = display->destroyLayer(layer);
264 if (error != HWC2::Error::None) {
265 ALOGE("Failed to destroy layer on display %d: %s (%d)", displayId,
266 to_string(error).c_str(), static_cast<int32_t>(error));
267 }
268}
269
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800270nsecs_t HWComposer::getRefreshTimestamp(int32_t displayId) const {
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700271 // this returns the last refresh timestamp.
272 // if the last one is not available, we estimate it based on
273 // the refresh period and whatever closest timestamp we have.
274 Mutex::Autolock _l(mLock);
275 nsecs_t now = systemTime(CLOCK_MONOTONIC);
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800276 auto vsyncPeriod = getActiveConfig(displayId)->getVsyncPeriod();
277 return now - ((now - mLastHwVSync[displayId]) % vsyncPeriod);
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700278}
279
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800280bool HWComposer::isConnected(int32_t displayId) const {
281 if (!isValidDisplay(displayId)) {
282 ALOGE("isConnected: Attempted to access invalid display %d", displayId);
Mathias Agopiane60b0682012-08-21 23:34:09 -0700283 return false;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800284 }
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800285 return mDisplayData[displayId].hwcDisplay->isConnected();
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700286}
287
Dan Stoza9e56aa02015-11-02 13:00:03 -0800288std::vector<std::shared_ptr<const HWC2::Display::Config>>
289 HWComposer::getConfigs(int32_t displayId) const {
290 if (!isValidDisplay(displayId)) {
291 ALOGE("getConfigs: Attempted to access invalid display %d", displayId);
292 return {};
293 }
294 auto& displayData = mDisplayData[displayId];
295 auto configs = mDisplayData[displayId].hwcDisplay->getConfigs();
296 if (displayData.configMap.empty()) {
297 for (size_t i = 0; i < configs.size(); ++i) {
298 displayData.configMap[i] = configs[i];
Mathias Agopianda27af92012-09-13 18:17:13 -0700299 }
300 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800301 return configs;
Mathias Agopianda27af92012-09-13 18:17:13 -0700302}
303
Dan Stoza9e56aa02015-11-02 13:00:03 -0800304std::shared_ptr<const HWC2::Display::Config>
305 HWComposer::getActiveConfig(int32_t displayId) const {
306 if (!isValidDisplay(displayId)) {
Fabien Sanglardb7432cc2016-11-11 09:40:27 -0800307 ALOGV("getActiveConfigs: Attempted to access invalid display %d",
Dan Stoza9e56aa02015-11-02 13:00:03 -0800308 displayId);
309 return nullptr;
Mathias Agopian58959342010-10-07 14:57:04 -0700310 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800311 std::shared_ptr<const HWC2::Display::Config> config;
312 auto error = mDisplayData[displayId].hwcDisplay->getActiveConfig(&config);
313 if (error == HWC2::Error::BadConfig) {
Fabien Sanglardb7432cc2016-11-11 09:40:27 -0800314 ALOGE("getActiveConfig: No config active, returning null");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800315 return nullptr;
316 } else if (error != HWC2::Error::None) {
317 ALOGE("getActiveConfig failed for display %d: %s (%d)", displayId,
318 to_string(error).c_str(), static_cast<int32_t>(error));
319 return nullptr;
320 } else if (!config) {
321 ALOGE("getActiveConfig returned an unknown config for display %d",
322 displayId);
323 return nullptr;
324 }
325
326 return config;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700327}
328
Michael Wright28f24d02016-07-12 13:30:53 -0700329std::vector<android_color_mode_t> HWComposer::getColorModes(int32_t displayId) const {
330 std::vector<android_color_mode_t> modes;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600331
332 if (!isValidDisplay(displayId)) {
333 ALOGE("getColorModes: Attempted to access invalid display %d",
334 displayId);
335 return modes;
336 }
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600337
Steven Thomas94e35b92017-07-26 18:48:28 -0700338 auto error = mDisplayData[displayId].hwcDisplay->getColorModes(&modes);
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600339 if (error != HWC2::Error::None) {
340 ALOGE("getColorModes failed for display %d: %s (%d)", displayId,
341 to_string(error).c_str(), static_cast<int32_t>(error));
Michael Wright28f24d02016-07-12 13:30:53 -0700342 return std::vector<android_color_mode_t>();
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600343 }
344
345 return modes;
346}
347
Michael Wright28f24d02016-07-12 13:30:53 -0700348status_t HWComposer::setActiveColorMode(int32_t displayId, android_color_mode_t mode) {
349 if (!isValidDisplay(displayId)) {
350 ALOGE("setActiveColorMode: Display %d is not valid", displayId);
351 return BAD_INDEX;
352 }
353
354 auto& displayData = mDisplayData[displayId];
355 auto error = displayData.hwcDisplay->setColorMode(mode);
356 if (error != HWC2::Error::None) {
357 ALOGE("setActiveConfig: Failed to set color mode %d on display %d: "
358 "%s (%d)", mode, displayId, to_string(error).c_str(),
359 static_cast<int32_t>(error));
360 return UNKNOWN_ERROR;
361 }
362
363 return NO_ERROR;
364}
365
366
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800367void 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 Stoza9e56aa02015-11-02 13:00:03 -0800370 return;
371 }
372
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800373 if (!isValidDisplay(displayId)) {
374 ALOGE("setVsyncEnabled: Attempted to access invalid display %d",
375 displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800376 return;
377 }
378
379 // NOTE: we use our own internal lock here because we have to call
380 // into the HWC with the lock held, and we want to make sure
381 // that even if HWC blocks (which it shouldn't), it won't
382 // affect other threads.
383 Mutex::Autolock _l(mVsyncLock);
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800384 auto& displayData = mDisplayData[displayId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800385 if (enabled != displayData.vsyncEnabled) {
386 ATRACE_CALL();
387 auto error = displayData.hwcDisplay->setVsyncEnabled(enabled);
388 if (error == HWC2::Error::None) {
389 displayData.vsyncEnabled = enabled;
390
391 char tag[16];
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800392 snprintf(tag, sizeof(tag), "HW_VSYNC_ON_%1u", displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800393 ATRACE_INT(tag, enabled == HWC2::Vsync::Enable ? 1 : 0);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700394 } else {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800395 ALOGE("setVsyncEnabled: Failed to set vsync to %s on %d/%" PRIu64
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800396 ": %s (%d)", to_string(enabled).c_str(), displayId,
397 mDisplayData[displayId].hwcDisplay->getId(),
Dan Stoza9e56aa02015-11-02 13:00:03 -0800398 to_string(error).c_str(), static_cast<int32_t>(error));
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700399 }
Colin Cross10fbdb62012-07-12 17:56:34 -0700400 }
Colin Cross10fbdb62012-07-12 17:56:34 -0700401}
402
Chia-I Wu06d63de2017-01-04 14:58:51 +0800403status_t HWComposer::setClientTarget(int32_t displayId, uint32_t slot,
Dan Stoza9e56aa02015-11-02 13:00:03 -0800404 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
405 android_dataspace_t dataspace) {
406 if (!isValidDisplay(displayId)) {
Jesse Hall851cfe82013-03-20 13:44:00 -0700407 return BAD_INDEX;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800408 }
Jesse Hall851cfe82013-03-20 13:44:00 -0700409
Dan Stoza9e56aa02015-11-02 13:00:03 -0800410 ALOGV("setClientTarget for display %d", displayId);
411 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400412 auto error = hwcDisplay->setClientTarget(slot, target, acquireFence, dataspace);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800413 if (error != HWC2::Error::None) {
414 ALOGE("Failed to set client target for display %d: %s (%d)", displayId,
415 to_string(error).c_str(), static_cast<int32_t>(error));
416 return BAD_VALUE;
417 }
418
Jesse Hall851cfe82013-03-20 13:44:00 -0700419 return NO_ERROR;
420}
421
Dan Stoza9e56aa02015-11-02 13:00:03 -0800422status_t HWComposer::prepare(DisplayDevice& displayDevice) {
423 ATRACE_CALL();
424
425 Mutex::Autolock _l(mDisplayLock);
426 auto displayId = displayDevice.getHwcDisplayId();
Dan Stozaec0f7172016-07-21 11:09:40 -0700427 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
428 ALOGV("Skipping HWComposer prepare for non-HWC display");
429 return NO_ERROR;
430 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800431 if (!isValidDisplay(displayId)) {
432 return BAD_INDEX;
433 }
434
435 auto& displayData = mDisplayData[displayId];
436 auto& hwcDisplay = displayData.hwcDisplay;
437 if (!hwcDisplay->isConnected()) {
438 return NO_ERROR;
439 }
440
441 uint32_t numTypes = 0;
442 uint32_t numRequests = 0;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700443
444 HWC2::Error error = HWC2::Error::None;
445
Chia-I Wu41b98d42017-12-11 11:04:36 -0800446 // First try to skip validate altogether when there is no client
447 // composition. When there is client composition, since we haven't
448 // rendered to the client target yet, we should not attempt to skip
449 // validate.
450 //
451 // displayData.hasClientComposition hasn't been updated for this frame.
452 // The check below is incorrect. We actually rely on HWC here to fall
453 // back to validate when there is any client layer.
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700454 displayData.validateWasSkipped = false;
Chia-I Wu41b98d42017-12-11 11:04:36 -0800455 if (!displayData.hasClientComposition) {
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700456 sp<android::Fence> outPresentFence;
457 uint32_t state = UINT32_MAX;
458 error = hwcDisplay->presentOrValidate(&numTypes, &numRequests, &outPresentFence , &state);
459 if (error != HWC2::Error::None && error != HWC2::Error::HasChanges) {
460 ALOGV("skipValidate: Failed to Present or Validate");
461 return UNKNOWN_ERROR;
462 }
463 if (state == 1) { //Present Succeeded.
Steven Thomas94e35b92017-07-26 18:48:28 -0700464 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700465 error = hwcDisplay->getReleaseFences(&releaseFences);
466 displayData.releaseFences = std::move(releaseFences);
467 displayData.lastPresentFence = outPresentFence;
468 displayData.validateWasSkipped = true;
469 displayData.presentError = error;
470 return NO_ERROR;
471 }
472 // Present failed but Validate ran.
473 } else {
474 error = hwcDisplay->validate(&numTypes, &numRequests);
475 }
476 ALOGV("SkipValidate failed, Falling back to SLOW validate/present");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800477 if (error != HWC2::Error::None && error != HWC2::Error::HasChanges) {
478 ALOGE("prepare: validate failed for display %d: %s (%d)", displayId,
479 to_string(error).c_str(), static_cast<int32_t>(error));
480 return BAD_INDEX;
481 }
482
Steven Thomas94e35b92017-07-26 18:48:28 -0700483 std::unordered_map<HWC2::Layer*, HWC2::Composition> changedTypes;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800484 changedTypes.reserve(numTypes);
485 error = hwcDisplay->getChangedCompositionTypes(&changedTypes);
486 if (error != HWC2::Error::None) {
487 ALOGE("prepare: getChangedCompositionTypes failed on display %d: "
488 "%s (%d)", displayId, to_string(error).c_str(),
489 static_cast<int32_t>(error));
490 return BAD_INDEX;
491 }
492
493
494 displayData.displayRequests = static_cast<HWC2::DisplayRequest>(0);
Steven Thomas94e35b92017-07-26 18:48:28 -0700495 std::unordered_map<HWC2::Layer*, HWC2::LayerRequest> layerRequests;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800496 layerRequests.reserve(numRequests);
497 error = hwcDisplay->getRequests(&displayData.displayRequests,
498 &layerRequests);
499 if (error != HWC2::Error::None) {
500 ALOGE("prepare: getRequests failed on display %d: %s (%d)", displayId,
501 to_string(error).c_str(), static_cast<int32_t>(error));
502 return BAD_INDEX;
503 }
504
505 displayData.hasClientComposition = false;
506 displayData.hasDeviceComposition = false;
507 for (auto& layer : displayDevice.getVisibleLayersSortedByZ()) {
508 auto hwcLayer = layer->getHwcLayer(displayId);
509
510 if (changedTypes.count(hwcLayer) != 0) {
511 // We pass false so we only update our state and don't call back
512 // into the HWC device
513 validateChange(layer->getCompositionType(displayId),
514 changedTypes[hwcLayer]);
515 layer->setCompositionType(displayId, changedTypes[hwcLayer], false);
516 }
517
518 switch (layer->getCompositionType(displayId)) {
519 case HWC2::Composition::Client:
520 displayData.hasClientComposition = true;
521 break;
522 case HWC2::Composition::Device:
523 case HWC2::Composition::SolidColor:
524 case HWC2::Composition::Cursor:
525 case HWC2::Composition::Sideband:
526 displayData.hasDeviceComposition = true;
527 break;
528 default:
529 break;
530 }
531
532 if (layerRequests.count(hwcLayer) != 0 &&
533 layerRequests[hwcLayer] ==
534 HWC2::LayerRequest::ClearClientTarget) {
535 layer->setClearClientTarget(displayId, true);
536 } else {
537 if (layerRequests.count(hwcLayer) != 0) {
538 ALOGE("prepare: Unknown layer request: %s",
539 to_string(layerRequests[hwcLayer]).c_str());
540 }
541 layer->setClearClientTarget(displayId, false);
542 }
543 }
544
545 error = hwcDisplay->acceptChanges();
546 if (error != HWC2::Error::None) {
547 ALOGE("prepare: acceptChanges failed: %s", to_string(error).c_str());
548 return BAD_INDEX;
549 }
550
551 return NO_ERROR;
552}
553
554bool HWComposer::hasDeviceComposition(int32_t displayId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700555 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
556 // Displays without a corresponding HWC display are never composed by
557 // the device
558 return false;
559 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800560 if (!isValidDisplay(displayId)) {
561 ALOGE("hasDeviceComposition: Invalid display %d", displayId);
562 return false;
563 }
564 return mDisplayData[displayId].hasDeviceComposition;
565}
566
567bool HWComposer::hasClientComposition(int32_t displayId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700568 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
569 // Displays without a corresponding HWC display are always composed by
570 // the client
571 return true;
572 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800573 if (!isValidDisplay(displayId)) {
574 ALOGE("hasClientComposition: Invalid display %d", displayId);
575 return true;
576 }
577 return mDisplayData[displayId].hasClientComposition;
578}
579
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800580sp<Fence> HWComposer::getPresentFence(int32_t displayId) const {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800581 if (!isValidDisplay(displayId)) {
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800582 ALOGE("getPresentFence failed for invalid display %d", displayId);
Jesse Hall851cfe82013-03-20 13:44:00 -0700583 return Fence::NO_FENCE;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800584 }
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800585 return mDisplayData[displayId].lastPresentFence;
Jesse Hall851cfe82013-03-20 13:44:00 -0700586}
587
Dan Stoza9e56aa02015-11-02 13:00:03 -0800588sp<Fence> HWComposer::getLayerReleaseFence(int32_t displayId,
Steven Thomas94e35b92017-07-26 18:48:28 -0700589 HWC2::Layer* layer) const {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800590 if (!isValidDisplay(displayId)) {
591 ALOGE("getLayerReleaseFence: Invalid display");
592 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700593 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800594 auto displayFences = mDisplayData[displayId].releaseFences;
595 if (displayFences.count(layer) == 0) {
596 ALOGV("getLayerReleaseFence: Release fence not found");
597 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700598 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800599 return displayFences[layer];
Riley Andrews03414a12014-07-01 14:22:59 -0700600}
601
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800602status_t HWComposer::presentAndGetReleaseFences(int32_t displayId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800603 ATRACE_CALL();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700604
Dan Stoza9e56aa02015-11-02 13:00:03 -0800605 if (!isValidDisplay(displayId)) {
606 return BAD_INDEX;
Mathias Agopianc3973602012-08-31 17:51:25 -0700607 }
Pablo Ceballosd814cf22015-09-11 14:37:39 -0700608
Dan Stoza9e56aa02015-11-02 13:00:03 -0800609 auto& displayData = mDisplayData[displayId];
610 auto& hwcDisplay = displayData.hwcDisplay;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700611
612 if (displayData.validateWasSkipped) {
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700613 // explicitly flush all pending commands
614 auto error = mHwcDevice->flushCommands();
615 if (displayData.presentError != HWC2::Error::None) {
616 error = displayData.presentError;
617 }
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700618 if (error != HWC2::Error::None) {
619 ALOGE("skipValidate: failed for display %d: %s (%d)",
620 displayId, to_string(error).c_str(), static_cast<int32_t>(error));
621 return UNKNOWN_ERROR;
622 }
623 return NO_ERROR;
624 }
625
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800626 auto error = hwcDisplay->present(&displayData.lastPresentFence);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800627 if (error != HWC2::Error::None) {
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800628 ALOGE("presentAndGetReleaseFences: failed for display %d: %s (%d)",
629 displayId, to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800630 return UNKNOWN_ERROR;
631 }
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700632
Steven Thomas94e35b92017-07-26 18:48:28 -0700633 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800634 error = hwcDisplay->getReleaseFences(&releaseFences);
635 if (error != HWC2::Error::None) {
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800636 ALOGE("presentAndGetReleaseFences: Failed to get release fences "
637 "for display %d: %s (%d)",
Dan Stoza9e56aa02015-11-02 13:00:03 -0800638 displayId, to_string(error).c_str(),
639 static_cast<int32_t>(error));
640 return UNKNOWN_ERROR;
Mathias Agopianf4358632012-08-22 17:16:19 -0700641 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800642
643 displayData.releaseFences = std::move(releaseFences);
644
645 return NO_ERROR;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700646}
647
Dan Stoza9e56aa02015-11-02 13:00:03 -0800648status_t HWComposer::setPowerMode(int32_t displayId, int32_t intMode) {
649 ALOGV("setPowerMode(%d, %d)", displayId, intMode);
650 if (!isValidDisplay(displayId)) {
651 ALOGE("setPowerMode: Bad display");
652 return BAD_INDEX;
653 }
654 if (displayId >= VIRTUAL_DISPLAY_ID_BASE) {
655 ALOGE("setPowerMode: Virtual display %d passed in, returning",
656 displayId);
657 return BAD_INDEX;
658 }
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700659
Dan Stoza9e56aa02015-11-02 13:00:03 -0800660 auto mode = static_cast<HWC2::PowerMode>(intMode);
661 if (mode == HWC2::PowerMode::Off) {
662 setVsyncEnabled(displayId, HWC2::Vsync::Disable);
663 }
664
665 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
666 switch (mode) {
667 case HWC2::PowerMode::Off:
668 case HWC2::PowerMode::On:
669 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
670 {
671 auto error = hwcDisplay->setPowerMode(mode);
672 if (error != HWC2::Error::None) {
673 ALOGE("setPowerMode: Unable to set power mode %s for "
674 "display %d: %s (%d)", to_string(mode).c_str(),
675 displayId, to_string(error).c_str(),
676 static_cast<int32_t>(error));
Mathias Agopianda27af92012-09-13 18:17:13 -0700677 }
678 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800679 break;
680 case HWC2::PowerMode::Doze:
681 case HWC2::PowerMode::DozeSuspend:
682 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
683 {
684 bool supportsDoze = false;
685 auto error = hwcDisplay->supportsDoze(&supportsDoze);
686 if (error != HWC2::Error::None) {
687 ALOGE("setPowerMode: Unable to query doze support for "
688 "display %d: %s (%d)", displayId,
689 to_string(error).c_str(),
690 static_cast<int32_t>(error));
691 }
692 if (!supportsDoze) {
693 mode = HWC2::PowerMode::On;
694 }
695
696 error = hwcDisplay->setPowerMode(mode);
697 if (error != HWC2::Error::None) {
698 ALOGE("setPowerMode: Unable to set power mode %s for "
699 "display %d: %s (%d)", to_string(mode).c_str(),
700 displayId, to_string(error).c_str(),
701 static_cast<int32_t>(error));
702 }
703 }
704 break;
705 default:
706 ALOGV("setPowerMode: Not calling HWC");
707 break;
Mathias Agopianda27af92012-09-13 18:17:13 -0700708 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800709
710 return NO_ERROR;
711}
712
713status_t HWComposer::setActiveConfig(int32_t displayId, size_t configId) {
714 if (!isValidDisplay(displayId)) {
715 ALOGE("setActiveConfig: Display %d is not valid", displayId);
716 return BAD_INDEX;
717 }
718
719 auto& displayData = mDisplayData[displayId];
720 if (displayData.configMap.count(configId) == 0) {
721 ALOGE("setActiveConfig: Invalid config %zd", configId);
722 return BAD_INDEX;
723 }
724
725 auto error = displayData.hwcDisplay->setActiveConfig(
726 displayData.configMap[configId]);
727 if (error != HWC2::Error::None) {
728 ALOGE("setActiveConfig: Failed to set config %zu on display %d: "
729 "%s (%d)", configId, displayId, to_string(error).c_str(),
730 static_cast<int32_t>(error));
731 return UNKNOWN_ERROR;
732 }
733
734 return NO_ERROR;
735}
736
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700737status_t HWComposer::setColorTransform(int32_t displayId,
738 const mat4& transform) {
739 if (!isValidDisplay(displayId)) {
740 ALOGE("setColorTransform: Display %d is not valid", displayId);
741 return BAD_INDEX;
742 }
743
744 auto& displayData = mDisplayData[displayId];
745 bool isIdentity = transform == mat4();
746 auto error = displayData.hwcDisplay->setColorTransform(transform,
747 isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY :
748 HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX);
749 if (error != HWC2::Error::None) {
750 ALOGE("setColorTransform: Failed to set transform on display %d: "
751 "%s (%d)", displayId, to_string(error).c_str(),
752 static_cast<int32_t>(error));
753 return UNKNOWN_ERROR;
754 }
755
756 return NO_ERROR;
757}
758
Dan Stoza9e56aa02015-11-02 13:00:03 -0800759void HWComposer::disconnectDisplay(int displayId) {
760 LOG_ALWAYS_FATAL_IF(displayId < 0);
761 auto& displayData = mDisplayData[displayId];
762
763 auto displayType = HWC2::DisplayType::Invalid;
764 auto error = displayData.hwcDisplay->getType(&displayType);
765 if (error != HWC2::Error::None) {
766 ALOGE("disconnectDisplay: Failed to determine type of display %d",
767 displayId);
768 return;
769 }
770
771 // If this was a virtual display, add its slot back for reuse by future
772 // virtual displays
773 if (displayType == HWC2::DisplayType::Virtual) {
774 mFreeDisplaySlots.insert(displayId);
775 ++mRemainingHwcVirtualDisplays;
776 }
777
778 auto hwcId = displayData.hwcDisplay->getId();
779 mHwcDisplaySlots.erase(hwcId);
780 displayData.reset();
Steven Thomas94e35b92017-07-26 18:48:28 -0700781
782 mHwcDevice->destroyDisplay(hwcId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800783}
784
785status_t HWComposer::setOutputBuffer(int32_t displayId,
786 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buffer) {
787 if (!isValidDisplay(displayId)) {
788 ALOGE("setOutputBuffer: Display %d is not valid", displayId);
789 return BAD_INDEX;
790 }
791
792 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
793 auto displayType = HWC2::DisplayType::Invalid;
794 auto error = hwcDisplay->getType(&displayType);
795 if (error != HWC2::Error::None) {
796 ALOGE("setOutputBuffer: Failed to determine type of display %d",
797 displayId);
798 return NAME_NOT_FOUND;
799 }
800
801 if (displayType != HWC2::DisplayType::Virtual) {
802 ALOGE("setOutputBuffer: Display %d is not virtual", displayId);
803 return INVALID_OPERATION;
804 }
805
806 error = hwcDisplay->setOutputBuffer(buffer, acquireFence);
807 if (error != HWC2::Error::None) {
808 ALOGE("setOutputBuffer: Failed to set buffer on display %d: %s (%d)",
809 displayId, to_string(error).c_str(),
810 static_cast<int32_t>(error));
811 return UNKNOWN_ERROR;
812 }
813
814 return NO_ERROR;
815}
816
817void HWComposer::clearReleaseFences(int32_t displayId) {
818 if (!isValidDisplay(displayId)) {
819 ALOGE("clearReleaseFences: Display %d is not valid", displayId);
820 return;
821 }
822 mDisplayData[displayId].releaseFences.clear();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700823}
824
Dan Stozac4f471e2016-03-24 09:31:08 -0700825std::unique_ptr<HdrCapabilities> HWComposer::getHdrCapabilities(
826 int32_t displayId) {
827 if (!isValidDisplay(displayId)) {
828 ALOGE("getHdrCapabilities: Display %d is not valid", displayId);
829 return nullptr;
830 }
831
832 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
833 std::unique_ptr<HdrCapabilities> capabilities;
834 auto error = hwcDisplay->getHdrCapabilities(&capabilities);
835 if (error != HWC2::Error::None) {
836 ALOGE("getOutputCapabilities: Failed to get capabilities on display %d:"
837 " %s (%d)", displayId, to_string(error).c_str(),
838 static_cast<int32_t>(error));
839 return nullptr;
840 }
841
842 return capabilities;
843}
844
Andy McFadden4df87bd2014-04-21 18:08:54 -0700845// Converts a PixelFormat to a human-readable string. Max 11 chars.
846// (Could use a table of prefab String8 objects.)
Dan Stoza9e56aa02015-11-02 13:00:03 -0800847/*
Andy McFadden4df87bd2014-04-21 18:08:54 -0700848static String8 getFormatStr(PixelFormat format) {
849 switch (format) {
850 case PIXEL_FORMAT_RGBA_8888: return String8("RGBA_8888");
851 case PIXEL_FORMAT_RGBX_8888: return String8("RGBx_8888");
852 case PIXEL_FORMAT_RGB_888: return String8("RGB_888");
853 case PIXEL_FORMAT_RGB_565: return String8("RGB_565");
854 case PIXEL_FORMAT_BGRA_8888: return String8("BGRA_8888");
Andy McFaddenf0058ca2014-05-20 13:28:50 -0700855 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
856 return String8("ImplDef");
Andy McFadden4df87bd2014-04-21 18:08:54 -0700857 default:
858 String8 result;
859 result.appendFormat("? %08x", format);
860 return result;
861 }
862}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800863*/
Andy McFadden4df87bd2014-04-21 18:08:54 -0700864
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800865bool HWComposer::isUsingVrComposer() const {
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800866 return getComposer()->isUsingVrComposer();
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800867}
868
Mathias Agopian74d211a2013-04-22 16:55:35 +0200869void HWComposer::dump(String8& result) const {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800870 // TODO: In order to provide a dump equivalent to HWC1, we need to shadow
871 // all the state going into the layers. This is probably better done in
872 // Layer itself, but it's going to take a bit of work to get there.
873 result.append(mHwcDevice->dump().c_str());
Mathias Agopian83727852010-09-23 18:13:21 -0700874}
875
Steven Thomas6e8f7062017-11-22 14:15:29 -0800876std::optional<hwc2_display_t>
877HWComposer::getHwcDisplayId(int32_t displayId) const {
878 if (!isValidDisplay(displayId)) {
879 return {};
880 }
881 return mDisplayData[displayId].hwcDisplay->getId();
882}
883
Mathias Agopiana350ff92010-08-10 17:14:02 -0700884// ---------------------------------------------------------------------------
Mathias Agopian2965b262012-04-08 15:13:32 -0700885
Jesse Halla9a1b002013-02-27 16:39:25 -0800886HWComposer::DisplayData::DisplayData()
Dan Stoza9e56aa02015-11-02 13:00:03 -0800887 : hasClientComposition(false),
888 hasDeviceComposition(false),
Steven Thomas94e35b92017-07-26 18:48:28 -0700889 hwcDisplay(nullptr),
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800890 lastPresentFence(Fence::NO_FENCE),
Dan Stoza9e56aa02015-11-02 13:00:03 -0800891 outbufHandle(nullptr),
892 outbufAcquireFence(Fence::NO_FENCE),
893 vsyncEnabled(HWC2::Vsync::Disable) {
894 ALOGV("Created new DisplayData");
895}
Jesse Halla9a1b002013-02-27 16:39:25 -0800896
897HWComposer::DisplayData::~DisplayData() {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800898}
899
900void HWComposer::DisplayData::reset() {
901 ALOGV("DisplayData reset");
902 *this = DisplayData();
Jesse Halla9a1b002013-02-27 16:39:25 -0800903}
904
Mathias Agopian2965b262012-04-08 15:13:32 -0700905// ---------------------------------------------------------------------------
Mathias Agopiana350ff92010-08-10 17:14:02 -0700906}; // namespace android