blob: 96d691ce9cfd7316e4ef214359960794b16bc2aa [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
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -070039#include <ui/DebugUtils.h>
Mathias Agopian921e6ac2012-07-23 23:11:29 -070040#include <ui/GraphicBuffer.h>
41
Mathias Agopiana350ff92010-08-10 17:14:02 -070042#include <hardware/hardware.h>
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070043#include <hardware/hwcomposer.h>
Mathias Agopiana350ff92010-08-10 17:14:02 -070044
Jesse Hall1c569c42013-04-05 13:44:52 -070045#include <android/configuration.h>
46
Mathias Agopiane2c4f4e2012-04-10 18:25:31 -070047#include <cutils/properties.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -070048#include <log/log.h>
Mathias Agopiana350ff92010-08-10 17:14:02 -070049
Mathias Agopiana350ff92010-08-10 17:14:02 -070050#include "HWComposer.h"
Dan Stoza9e56aa02015-11-02 13:00:03 -080051#include "HWC2.h"
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -080052#include "ComposerHal.h"
Mathias Agopian33ceeb32013-04-01 16:54:58 -070053
54#include "../Layer.h" // needed only for debugging
55#include "../SurfaceFlinger.h"
Mathias Agopiana350ff92010-08-10 17:14:02 -070056
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -070057#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 Agopiana350ff92010-08-10 17:14:02 -070083namespace android {
Jesse Hall5880cc52012-06-05 23:40:32 -070084
Jesse Hall72960512013-01-10 16:19:56 -080085#define MIN_HWC_HEADER_VERSION HWC_HEADER_VERSION
Jesse Hall9eb1eb52012-08-29 10:39:38 -070086
Mathias Agopiana350ff92010-08-10 17:14:02 -070087// ---------------------------------------------------------------------------
88
Lloyd Piquea822d522017-12-20 16:42:57 -080089HWComposer::HWComposer(std::unique_ptr<android::Hwc2::Composer> composer)
90 : mHwcDevice(std::make_unique<HWC2::Device>(std::move(composer))) {}
Mathias Agopianbef42c52013-08-21 17:45:46 -070091
Lloyd Piquea822d522017-12-20 16:42:57 -080092HWComposer::~HWComposer() = default;
Dan Stoza9e56aa02015-11-02 13:00:03 -080093
Steven Thomas94e35b92017-07-26 18:48:28 -070094void HWComposer::registerCallback(HWC2::ComposerCallback* callback,
95 int32_t sequenceId) {
96 mHwcDevice->registerCallback(callback, sequenceId);
Dan Stoza9e56aa02015-11-02 13:00:03 -080097}
98
Dan Stoza9f26a9c2016-06-22 14:51:09 -070099bool HWComposer::hasCapability(HWC2::Capability capability) const
100{
101 return mHwcDevice->getCapabilities().count(capability) > 0;
102}
103
Dan Stoza9e56aa02015-11-02 13:00:03 -0800104bool HWComposer::isValidDisplay(int32_t displayId) const {
105 return static_cast<size_t>(displayId) < mDisplayData.size() &&
106 mDisplayData[displayId].hwcDisplay;
107}
108
109void 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 McFaddenb0d1dd32012-09-10 14:08:09 -0700131 }
132}
133
Lloyd Pique715a2c12017-12-14 17:18:08 -0800134void HWComposer::onHotplug(hwc2_display_t displayId, int32_t displayType,
Steven Thomas94e35b92017-07-26 18:48:28 -0700135 HWC2::Connection connection) {
Lloyd Pique715a2c12017-12-14 17:18:08 -0800136 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 Thomas94e35b92017-07-26 18:48:28 -0700143 to_string(connection).c_str());
144 mHwcDevice->onHotplug(displayId, connection);
Lloyd Pique715a2c12017-12-14 17:18:08 -0800145 // 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 McFaddenb0d1dd32012-09-10 14:08:09 -0700150 }
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700151}
152
Steven Thomas94e35b92017-07-26 18:48:28 -0700153bool 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 Stoza9e56aa02015-11-02 13:00:03 -0800160 auto displayType = HWC2::DisplayType::Invalid;
161 auto error = display->getType(&displayType);
162 if (error != HWC2::Error::None) {
Steven Thomas94e35b92017-07-26 18:48:28 -0700163 ALOGE("onVsync: Failed to determine type of display %" PRIu64,
Dan Stoza9e56aa02015-11-02 13:00:03 -0800164 display->getId());
Steven Thomas94e35b92017-07-26 18:48:28 -0700165 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700166 }
Jesse Hall1bd20e02012-08-29 10:47:52 -0700167
Dan Stoza9e56aa02015-11-02 13:00:03 -0800168 if (displayType == HWC2::DisplayType::Virtual) {
169 ALOGE("Virtual display %" PRIu64 " passed to vsync callback",
170 display->getId());
Steven Thomas94e35b92017-07-26 18:48:28 -0700171 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700172 }
173
Dan Stoza9e56aa02015-11-02 13:00:03 -0800174 if (mHwcDisplaySlots.count(display->getId()) == 0) {
175 ALOGE("Unknown physical display %" PRIu64 " passed to vsync callback",
176 display->getId());
Steven Thomas94e35b92017-07-26 18:48:28 -0700177 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700178 }
179
Dan Stoza9e56aa02015-11-02 13:00:03 -0800180 int32_t disp = mHwcDisplaySlots[display->getId()];
181 {
182 Mutex::Autolock _l(mLock);
Jesse Hall1bd20e02012-08-29 10:47:52 -0700183
Dan Stoza9e56aa02015-11-02 13:00:03 -0800184 // 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 Thomas94e35b92017-07-26 18:48:28 -0700191 return false;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800192 }
193
194 mLastHwVSync[disp] = timestamp;
Jesse Hall1c569c42013-04-05 13:44:52 -0700195 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800196
Steven Thomas94e35b92017-07-26 18:48:28 -0700197 if (outDisplay) {
198 *outDisplay = disp;
199 }
200
Dan Stoza9e56aa02015-11-02 13:00:03 -0800201 char tag[16];
202 snprintf(tag, sizeof(tag), "HW_VSYNC_%1u", disp);
203 ATRACE_INT(tag, ++mVSyncCounts[disp] & 1);
204
Steven Thomas94e35b92017-07-26 18:48:28 -0700205 return true;
Jesse Hall1c569c42013-04-05 13:44:52 -0700206}
207
Dan Stoza9e56aa02015-11-02 13:00:03 -0800208status_t HWComposer::allocateVirtualDisplay(uint32_t width, uint32_t height,
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700209 ui::PixelFormat* format, int32_t *outId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800210 if (mRemainingHwcVirtualDisplays == 0) {
211 ALOGE("allocateVirtualDisplay: No remaining virtual displays");
Mathias Agopiane60b0682012-08-21 23:34:09 -0700212 return NO_MEMORY;
213 }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700214
Fabien Sanglardc8e387e2017-03-10 10:30:28 -0800215 if (SurfaceFlinger::maxVirtualDisplaySize != 0 &&
216 (width > SurfaceFlinger::maxVirtualDisplaySize ||
217 height > SurfaceFlinger::maxVirtualDisplaySize)) {
Fabien Sanglarde29055f2017-03-08 11:36:46 -0800218 ALOGE("createVirtualDisplay: Can't create a virtual display with"
Fabien Sanglardc8e387e2017-03-10 10:30:28 -0800219 " a dimension > %" PRIu64 " (tried %u x %u)",
220 SurfaceFlinger::maxVirtualDisplaySize, width, height);
Fabien Sanglarde29055f2017-03-08 11:36:46 -0800221 return INVALID_OPERATION;
222 }
223
Steven Thomas94e35b92017-07-26 18:48:28 -0700224 HWC2::Display* display;
Dan Stoza5cf424b2016-05-20 14:02:39 -0700225 auto error = mHwcDevice->createVirtualDisplay(width, height, format,
226 &display);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800227 if (error != HWC2::Error::None) {
228 ALOGE("allocateVirtualDisplay: Failed to create HWC virtual display");
229 return NO_MEMORY;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700230 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800231
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 Agopiane60b0682012-08-21 23:34:09 -0700243 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800244
245 mDisplayData[displaySlot].hwcDisplay = display;
246
247 --mRemainingHwcVirtualDisplays;
248 *outId = static_cast<int32_t>(displaySlot);
249
Mathias Agopiane60b0682012-08-21 23:34:09 -0700250 return NO_ERROR;
251}
252
Steven Thomas94e35b92017-07-26 18:48:28 -0700253HWC2::Layer* HWComposer::createLayer(int32_t displayId) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700254 RETURN_IF_INVALID_DISPLAY(displayId, nullptr);
255
Dan Stoza9e56aa02015-11-02 13:00:03 -0800256 auto display = mDisplayData[displayId].hwcDisplay;
Steven Thomas94e35b92017-07-26 18:48:28 -0700257 HWC2::Layer* layer;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800258 auto error = display->createLayer(&layer);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700259 RETURN_IF_HWC_ERROR(error, displayId, nullptr);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800260 return layer;
261}
262
Steven Thomas94e35b92017-07-26 18:48:28 -0700263void HWComposer::destroyLayer(int32_t displayId, HWC2::Layer* layer) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700264 RETURN_IF_INVALID_DISPLAY(displayId);
265
Steven Thomas94e35b92017-07-26 18:48:28 -0700266 auto display = mDisplayData[displayId].hwcDisplay;
267 auto error = display->destroyLayer(layer);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700268 RETURN_IF_HWC_ERROR(error, displayId);
Steven Thomas94e35b92017-07-26 18:48:28 -0700269}
270
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800271nsecs_t HWComposer::getRefreshTimestamp(int32_t displayId) const {
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700272 // 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 Sanglarddf0b7052016-11-30 15:51:53 -0800277 auto vsyncPeriod = getActiveConfig(displayId)->getVsyncPeriod();
278 return now - ((now - mLastHwVSync[displayId]) % vsyncPeriod);
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700279}
280
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800281bool HWComposer::isConnected(int32_t displayId) const {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700282 RETURN_IF_INVALID_DISPLAY(displayId, false);
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800283 return mDisplayData[displayId].hwcDisplay->isConnected();
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700284}
285
Dan Stoza9e56aa02015-11-02 13:00:03 -0800286std::vector<std::shared_ptr<const HWC2::Display::Config>>
287 HWComposer::getConfigs(int32_t displayId) const {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700288 RETURN_IF_INVALID_DISPLAY(displayId, {});
289
Dan Stoza9e56aa02015-11-02 13:00:03 -0800290 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 Agopianda27af92012-09-13 18:17:13 -0700295 }
296 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800297 return configs;
Mathias Agopianda27af92012-09-13 18:17:13 -0700298}
299
Dan Stoza9e56aa02015-11-02 13:00:03 -0800300std::shared_ptr<const HWC2::Display::Config>
301 HWComposer::getActiveConfig(int32_t displayId) const {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700302 RETURN_IF_INVALID_DISPLAY(displayId, nullptr);
303
Dan Stoza9e56aa02015-11-02 13:00:03 -0800304 std::shared_ptr<const HWC2::Display::Config> config;
305 auto error = mDisplayData[displayId].hwcDisplay->getActiveConfig(&config);
306 if (error == HWC2::Error::BadConfig) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700307 LOG_DISPLAY_ERROR(displayId, "No active config");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800308 return nullptr;
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700309 }
310
311 RETURN_IF_HWC_ERROR(error, displayId, nullptr);
312
313 if (!config) {
314 LOG_DISPLAY_ERROR(displayId, "Unknown config");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800315 return nullptr;
316 }
317
318 return config;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700319}
320
Peiyong Linfd997e02018-03-28 15:29:00 -0700321std::vector<ui::ColorMode> HWComposer::getColorModes(int32_t displayId) const {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700322 RETURN_IF_INVALID_DISPLAY(displayId, {});
323
Peiyong Linfd997e02018-03-28 15:29:00 -0700324 std::vector<ui::ColorMode> modes;
Steven Thomas94e35b92017-07-26 18:48:28 -0700325 auto error = mDisplayData[displayId].hwcDisplay->getColorModes(&modes);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700326 RETURN_IF_HWC_ERROR(error, displayId, {});
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600327 return modes;
328}
329
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700330status_t HWComposer::setActiveColorMode(int32_t displayId, ui::ColorMode mode,
331 ui::RenderIntent renderIntent) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700332 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Michael Wright28f24d02016-07-12 13:30:53 -0700333
334 auto& displayData = mDisplayData[displayId];
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700335 auto error = displayData.hwcDisplay->setColorMode(mode, renderIntent);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700336 RETURN_IF_HWC_ERROR_FOR(("setColorMode(" + decodeColorMode(mode) + ", " +
337 decodeRenderIntent(renderIntent) + ")")
338 .c_str(),
339 error, displayId, UNKNOWN_ERROR);
Michael Wright28f24d02016-07-12 13:30:53 -0700340
341 return NO_ERROR;
342}
343
344
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800345void HWComposer::setVsyncEnabled(int32_t displayId, HWC2::Vsync enabled) {
346 if (displayId < 0 || displayId >= HWC_DISPLAY_VIRTUAL) {
347 ALOGD("setVsyncEnabled: Ignoring for virtual display %d", displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800348 return;
349 }
350
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700351 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800352
353 // NOTE: we use our own internal lock here because we have to call
354 // into the HWC with the lock held, and we want to make sure
355 // that even if HWC blocks (which it shouldn't), it won't
356 // affect other threads.
357 Mutex::Autolock _l(mVsyncLock);
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800358 auto& displayData = mDisplayData[displayId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800359 if (enabled != displayData.vsyncEnabled) {
360 ATRACE_CALL();
361 auto error = displayData.hwcDisplay->setVsyncEnabled(enabled);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700362 RETURN_IF_HWC_ERROR(error, displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800363
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700364 displayData.vsyncEnabled = enabled;
365
366 char tag[16];
367 snprintf(tag, sizeof(tag), "HW_VSYNC_ON_%1u", displayId);
368 ATRACE_INT(tag, enabled == HWC2::Vsync::Enable ? 1 : 0);
Colin Cross10fbdb62012-07-12 17:56:34 -0700369 }
Colin Cross10fbdb62012-07-12 17:56:34 -0700370}
371
Chia-I Wu06d63de2017-01-04 14:58:51 +0800372status_t HWComposer::setClientTarget(int32_t displayId, uint32_t slot,
Dan Stoza9e56aa02015-11-02 13:00:03 -0800373 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700374 ui::Dataspace dataspace) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700375 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Jesse Hall851cfe82013-03-20 13:44:00 -0700376
Dan Stoza9e56aa02015-11-02 13:00:03 -0800377 ALOGV("setClientTarget for display %d", displayId);
378 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400379 auto error = hwcDisplay->setClientTarget(slot, target, acquireFence, dataspace);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700380 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Jesse Hall851cfe82013-03-20 13:44:00 -0700381 return NO_ERROR;
382}
383
Dan Stoza9e56aa02015-11-02 13:00:03 -0800384status_t HWComposer::prepare(DisplayDevice& displayDevice) {
385 ATRACE_CALL();
386
387 Mutex::Autolock _l(mDisplayLock);
388 auto displayId = displayDevice.getHwcDisplayId();
Dan Stozaec0f7172016-07-21 11:09:40 -0700389 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
390 ALOGV("Skipping HWComposer prepare for non-HWC display");
391 return NO_ERROR;
392 }
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700393
394 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800395
396 auto& displayData = mDisplayData[displayId];
397 auto& hwcDisplay = displayData.hwcDisplay;
398 if (!hwcDisplay->isConnected()) {
399 return NO_ERROR;
400 }
401
402 uint32_t numTypes = 0;
403 uint32_t numRequests = 0;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700404
405 HWC2::Error error = HWC2::Error::None;
406
Chia-I Wu41b98d42017-12-11 11:04:36 -0800407 // First try to skip validate altogether when there is no client
408 // composition. When there is client composition, since we haven't
409 // rendered to the client target yet, we should not attempt to skip
410 // validate.
411 //
412 // displayData.hasClientComposition hasn't been updated for this frame.
413 // The check below is incorrect. We actually rely on HWC here to fall
414 // back to validate when there is any client layer.
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700415 displayData.validateWasSkipped = false;
Chia-I Wu41b98d42017-12-11 11:04:36 -0800416 if (!displayData.hasClientComposition) {
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700417 sp<android::Fence> outPresentFence;
418 uint32_t state = UINT32_MAX;
419 error = hwcDisplay->presentOrValidate(&numTypes, &numRequests, &outPresentFence , &state);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700420 if (error != HWC2::Error::HasChanges) {
421 RETURN_IF_HWC_ERROR_FOR("presentOrValidate", error, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700422 }
423 if (state == 1) { //Present Succeeded.
Steven Thomas94e35b92017-07-26 18:48:28 -0700424 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700425 error = hwcDisplay->getReleaseFences(&releaseFences);
426 displayData.releaseFences = std::move(releaseFences);
427 displayData.lastPresentFence = outPresentFence;
428 displayData.validateWasSkipped = true;
429 displayData.presentError = error;
430 return NO_ERROR;
431 }
432 // Present failed but Validate ran.
433 } else {
434 error = hwcDisplay->validate(&numTypes, &numRequests);
435 }
436 ALOGV("SkipValidate failed, Falling back to SLOW validate/present");
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700437 if (error != HWC2::Error::HasChanges) {
438 RETURN_IF_HWC_ERROR_FOR("validate", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800439 }
440
Steven Thomas94e35b92017-07-26 18:48:28 -0700441 std::unordered_map<HWC2::Layer*, HWC2::Composition> changedTypes;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800442 changedTypes.reserve(numTypes);
443 error = hwcDisplay->getChangedCompositionTypes(&changedTypes);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700444 RETURN_IF_HWC_ERROR_FOR("getChangedCompositionTypes", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800445
446 displayData.displayRequests = static_cast<HWC2::DisplayRequest>(0);
Steven Thomas94e35b92017-07-26 18:48:28 -0700447 std::unordered_map<HWC2::Layer*, HWC2::LayerRequest> layerRequests;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800448 layerRequests.reserve(numRequests);
449 error = hwcDisplay->getRequests(&displayData.displayRequests,
450 &layerRequests);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700451 RETURN_IF_HWC_ERROR_FOR("getRequests", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800452
453 displayData.hasClientComposition = false;
454 displayData.hasDeviceComposition = false;
455 for (auto& layer : displayDevice.getVisibleLayersSortedByZ()) {
456 auto hwcLayer = layer->getHwcLayer(displayId);
457
458 if (changedTypes.count(hwcLayer) != 0) {
459 // We pass false so we only update our state and don't call back
460 // into the HWC device
461 validateChange(layer->getCompositionType(displayId),
462 changedTypes[hwcLayer]);
463 layer->setCompositionType(displayId, changedTypes[hwcLayer], false);
464 }
465
466 switch (layer->getCompositionType(displayId)) {
467 case HWC2::Composition::Client:
468 displayData.hasClientComposition = true;
469 break;
470 case HWC2::Composition::Device:
471 case HWC2::Composition::SolidColor:
472 case HWC2::Composition::Cursor:
473 case HWC2::Composition::Sideband:
474 displayData.hasDeviceComposition = true;
475 break;
476 default:
477 break;
478 }
479
480 if (layerRequests.count(hwcLayer) != 0 &&
481 layerRequests[hwcLayer] ==
482 HWC2::LayerRequest::ClearClientTarget) {
483 layer->setClearClientTarget(displayId, true);
484 } else {
485 if (layerRequests.count(hwcLayer) != 0) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700486 LOG_DISPLAY_ERROR(displayId,
487 ("Unknown layer request " + to_string(layerRequests[hwcLayer]))
488 .c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800489 }
490 layer->setClearClientTarget(displayId, false);
491 }
492 }
493
494 error = hwcDisplay->acceptChanges();
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700495 RETURN_IF_HWC_ERROR_FOR("acceptChanges", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800496
497 return NO_ERROR;
498}
499
500bool HWComposer::hasDeviceComposition(int32_t displayId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700501 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
502 // Displays without a corresponding HWC display are never composed by
503 // the device
504 return false;
505 }
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700506
507 RETURN_IF_INVALID_DISPLAY(displayId, false);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800508 return mDisplayData[displayId].hasDeviceComposition;
509}
510
Madhuri Athota88a905b2017-05-04 16:58:15 +0530511bool HWComposer::hasFlipClientTargetRequest(int32_t displayId) const {
512 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
513 // Displays without a corresponding HWC display are never composed by
514 // the device
515 return false;
516 }
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700517
518 RETURN_IF_INVALID_DISPLAY(displayId, false);
Madhuri Athota88a905b2017-05-04 16:58:15 +0530519 return ((static_cast<uint32_t>(mDisplayData[displayId].displayRequests) &
520 static_cast<uint32_t>(HWC2::DisplayRequest::FlipClientTarget)) != 0);
521}
522
Dan Stoza9e56aa02015-11-02 13:00:03 -0800523bool HWComposer::hasClientComposition(int32_t displayId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700524 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
525 // Displays without a corresponding HWC display are always composed by
526 // the client
527 return true;
528 }
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700529
530 RETURN_IF_INVALID_DISPLAY(displayId, true);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800531 return mDisplayData[displayId].hasClientComposition;
532}
533
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800534sp<Fence> HWComposer::getPresentFence(int32_t displayId) const {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700535 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800536 return mDisplayData[displayId].lastPresentFence;
Jesse Hall851cfe82013-03-20 13:44:00 -0700537}
538
Dan Stoza9e56aa02015-11-02 13:00:03 -0800539sp<Fence> HWComposer::getLayerReleaseFence(int32_t displayId,
Steven Thomas94e35b92017-07-26 18:48:28 -0700540 HWC2::Layer* layer) const {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700541 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800542 auto displayFences = mDisplayData[displayId].releaseFences;
543 if (displayFences.count(layer) == 0) {
544 ALOGV("getLayerReleaseFence: Release fence not found");
545 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700546 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800547 return displayFences[layer];
Riley Andrews03414a12014-07-01 14:22:59 -0700548}
549
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800550status_t HWComposer::presentAndGetReleaseFences(int32_t displayId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800551 ATRACE_CALL();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700552
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700553 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Pablo Ceballosd814cf22015-09-11 14:37:39 -0700554
Dan Stoza9e56aa02015-11-02 13:00:03 -0800555 auto& displayData = mDisplayData[displayId];
556 auto& hwcDisplay = displayData.hwcDisplay;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700557
558 if (displayData.validateWasSkipped) {
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700559 // explicitly flush all pending commands
560 auto error = mHwcDevice->flushCommands();
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700561 RETURN_IF_HWC_ERROR_FOR("flushCommands", error, displayId, UNKNOWN_ERROR);
562 RETURN_IF_HWC_ERROR_FOR("present", displayData.presentError, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700563 return NO_ERROR;
564 }
565
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800566 auto error = hwcDisplay->present(&displayData.lastPresentFence);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700567 RETURN_IF_HWC_ERROR_FOR("present", error, displayId, UNKNOWN_ERROR);
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700568
Steven Thomas94e35b92017-07-26 18:48:28 -0700569 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800570 error = hwcDisplay->getReleaseFences(&releaseFences);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700571 RETURN_IF_HWC_ERROR_FOR("getReleaseFences", error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800572
573 displayData.releaseFences = std::move(releaseFences);
574
575 return NO_ERROR;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700576}
577
Dan Stoza9e56aa02015-11-02 13:00:03 -0800578status_t HWComposer::setPowerMode(int32_t displayId, int32_t intMode) {
579 ALOGV("setPowerMode(%d, %d)", displayId, intMode);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700580 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
581
Dan Stoza9e56aa02015-11-02 13:00:03 -0800582 if (displayId >= VIRTUAL_DISPLAY_ID_BASE) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700583 LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display");
584 return INVALID_OPERATION;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800585 }
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700586
Dan Stoza9e56aa02015-11-02 13:00:03 -0800587 auto mode = static_cast<HWC2::PowerMode>(intMode);
588 if (mode == HWC2::PowerMode::Off) {
589 setVsyncEnabled(displayId, HWC2::Vsync::Disable);
590 }
591
592 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
593 switch (mode) {
594 case HWC2::PowerMode::Off:
595 case HWC2::PowerMode::On:
596 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
597 {
598 auto error = hwcDisplay->setPowerMode(mode);
Peiyong Lin306e4992018-05-07 16:18:22 -0700599 if (error != HWC2::Error::None) {
600 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(),
601 error, displayId);
602 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700603 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800604 break;
605 case HWC2::PowerMode::Doze:
606 case HWC2::PowerMode::DozeSuspend:
607 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
608 {
609 bool supportsDoze = false;
610 auto error = hwcDisplay->supportsDoze(&supportsDoze);
Peiyong Lin306e4992018-05-07 16:18:22 -0700611 if (error != HWC2::Error::None) {
612 LOG_HWC_ERROR("supportsDoze", error, displayId);
613 }
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700614
Dan Stoza9e56aa02015-11-02 13:00:03 -0800615 if (!supportsDoze) {
616 mode = HWC2::PowerMode::On;
617 }
618
619 error = hwcDisplay->setPowerMode(mode);
Peiyong Lin306e4992018-05-07 16:18:22 -0700620 if (error != HWC2::Error::None) {
621 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(),
622 error, displayId);
623 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800624 }
625 break;
626 default:
627 ALOGV("setPowerMode: Not calling HWC");
628 break;
Mathias Agopianda27af92012-09-13 18:17:13 -0700629 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800630
631 return NO_ERROR;
632}
633
634status_t HWComposer::setActiveConfig(int32_t displayId, size_t configId) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700635 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800636
637 auto& displayData = mDisplayData[displayId];
638 if (displayData.configMap.count(configId) == 0) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700639 LOG_DISPLAY_ERROR(displayId, ("Invalid config " + std::to_string(configId)).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800640 return BAD_INDEX;
641 }
642
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700643 auto error = displayData.hwcDisplay->setActiveConfig(displayData.configMap[configId]);
644 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800645 return NO_ERROR;
646}
647
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700648status_t HWComposer::setColorTransform(int32_t displayId,
649 const mat4& transform) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700650 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700651
652 auto& displayData = mDisplayData[displayId];
653 bool isIdentity = transform == mat4();
654 auto error = displayData.hwcDisplay->setColorTransform(transform,
655 isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY :
656 HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700657 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700658 return NO_ERROR;
659}
660
Dan Stoza9e56aa02015-11-02 13:00:03 -0800661void HWComposer::disconnectDisplay(int displayId) {
662 LOG_ALWAYS_FATAL_IF(displayId < 0);
663 auto& displayData = mDisplayData[displayId];
664
665 auto displayType = HWC2::DisplayType::Invalid;
666 auto error = displayData.hwcDisplay->getType(&displayType);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700667 RETURN_IF_HWC_ERROR_FOR("getType", error, displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800668
669 // If this was a virtual display, add its slot back for reuse by future
670 // virtual displays
671 if (displayType == HWC2::DisplayType::Virtual) {
672 mFreeDisplaySlots.insert(displayId);
673 ++mRemainingHwcVirtualDisplays;
674 }
675
676 auto hwcId = displayData.hwcDisplay->getId();
677 mHwcDisplaySlots.erase(hwcId);
678 displayData.reset();
Steven Thomas94e35b92017-07-26 18:48:28 -0700679
680 mHwcDevice->destroyDisplay(hwcId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800681}
682
683status_t HWComposer::setOutputBuffer(int32_t displayId,
684 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buffer) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700685 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800686
687 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
688 auto displayType = HWC2::DisplayType::Invalid;
689 auto error = hwcDisplay->getType(&displayType);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700690 RETURN_IF_HWC_ERROR_FOR("getType", error, displayId, NAME_NOT_FOUND);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800691
692 if (displayType != HWC2::DisplayType::Virtual) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700693 LOG_DISPLAY_ERROR(displayId, "Invalid operation on physical display");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800694 return INVALID_OPERATION;
695 }
696
697 error = hwcDisplay->setOutputBuffer(buffer, acquireFence);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700698 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800699 return NO_ERROR;
700}
701
702void HWComposer::clearReleaseFences(int32_t displayId) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700703 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800704 mDisplayData[displayId].releaseFences.clear();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700705}
706
Peiyong Lin62665892018-04-16 11:07:44 -0700707status_t HWComposer::getHdrCapabilities(
708 int32_t displayId, HdrCapabilities* outCapabilities) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700709 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stozac4f471e2016-03-24 09:31:08 -0700710
711 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Peiyong Lin62665892018-04-16 11:07:44 -0700712 auto error = hwcDisplay->getHdrCapabilities(outCapabilities);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700713 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Peiyong Lin62665892018-04-16 11:07:44 -0700714 return NO_ERROR;
Dan Stozac4f471e2016-03-24 09:31:08 -0700715}
716
Peiyong Lin2c327ac2018-04-19 22:06:34 -0700717int32_t HWComposer::getSupportedPerFrameMetadata(int32_t displayId) const {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700718 RETURN_IF_INVALID_DISPLAY(displayId, 0);
Peiyong Lin2c327ac2018-04-19 22:06:34 -0700719
720 int32_t supportedMetadata;
721 auto error = mDisplayData[displayId].hwcDisplay->getSupportedPerFrameMetadata(
722 &supportedMetadata);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700723 RETURN_IF_HWC_ERROR(error, displayId, 0);
Peiyong Lin2c327ac2018-04-19 22:06:34 -0700724 return supportedMetadata;
725}
726
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700727std::vector<ui::RenderIntent> HWComposer::getRenderIntents(int32_t displayId,
728 ui::ColorMode colorMode) const {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700729 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700730
731 std::vector<ui::RenderIntent> renderIntents;
732 auto error = mDisplayData[displayId].hwcDisplay->getRenderIntents(colorMode, &renderIntents);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700733 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700734 return renderIntents;
735}
736
737mat4 HWComposer::getDataspaceSaturationMatrix(int32_t displayId, ui::Dataspace dataspace) {
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700738 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700739
740 mat4 matrix;
741 auto error = mDisplayData[displayId].hwcDisplay->getDataspaceSaturationMatrix(dataspace,
742 &matrix);
Dominik Laskowski56a9e5d2018-04-19 14:47:33 -0700743 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700744 return matrix;
745}
746
Andy McFadden4df87bd2014-04-21 18:08:54 -0700747// Converts a PixelFormat to a human-readable string. Max 11 chars.
748// (Could use a table of prefab String8 objects.)
Dan Stoza9e56aa02015-11-02 13:00:03 -0800749/*
Andy McFadden4df87bd2014-04-21 18:08:54 -0700750static String8 getFormatStr(PixelFormat format) {
751 switch (format) {
752 case PIXEL_FORMAT_RGBA_8888: return String8("RGBA_8888");
753 case PIXEL_FORMAT_RGBX_8888: return String8("RGBx_8888");
754 case PIXEL_FORMAT_RGB_888: return String8("RGB_888");
755 case PIXEL_FORMAT_RGB_565: return String8("RGB_565");
756 case PIXEL_FORMAT_BGRA_8888: return String8("BGRA_8888");
Andy McFaddenf0058ca2014-05-20 13:28:50 -0700757 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
758 return String8("ImplDef");
Andy McFadden4df87bd2014-04-21 18:08:54 -0700759 default:
760 String8 result;
761 result.appendFormat("? %08x", format);
762 return result;
763 }
764}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800765*/
Andy McFadden4df87bd2014-04-21 18:08:54 -0700766
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800767bool HWComposer::isUsingVrComposer() const {
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800768 return getComposer()->isUsingVrComposer();
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800769}
770
Mathias Agopian74d211a2013-04-22 16:55:35 +0200771void HWComposer::dump(String8& result) const {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800772 // TODO: In order to provide a dump equivalent to HWC1, we need to shadow
773 // all the state going into the layers. This is probably better done in
774 // Layer itself, but it's going to take a bit of work to get there.
775 result.append(mHwcDevice->dump().c_str());
Mathias Agopian83727852010-09-23 18:13:21 -0700776}
777
Steven Thomas6e8f7062017-11-22 14:15:29 -0800778std::optional<hwc2_display_t>
779HWComposer::getHwcDisplayId(int32_t displayId) const {
780 if (!isValidDisplay(displayId)) {
781 return {};
782 }
783 return mDisplayData[displayId].hwcDisplay->getId();
784}
785
Mathias Agopiana350ff92010-08-10 17:14:02 -0700786// ---------------------------------------------------------------------------
Mathias Agopian2965b262012-04-08 15:13:32 -0700787
Jesse Halla9a1b002013-02-27 16:39:25 -0800788HWComposer::DisplayData::DisplayData()
Dan Stoza9e56aa02015-11-02 13:00:03 -0800789 : hasClientComposition(false),
790 hasDeviceComposition(false),
Steven Thomas94e35b92017-07-26 18:48:28 -0700791 hwcDisplay(nullptr),
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800792 lastPresentFence(Fence::NO_FENCE),
Dan Stoza9e56aa02015-11-02 13:00:03 -0800793 outbufHandle(nullptr),
794 outbufAcquireFence(Fence::NO_FENCE),
795 vsyncEnabled(HWC2::Vsync::Disable) {
796 ALOGV("Created new DisplayData");
797}
Jesse Halla9a1b002013-02-27 16:39:25 -0800798
799HWComposer::DisplayData::~DisplayData() {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800800}
801
802void HWComposer::DisplayData::reset() {
803 ALOGV("DisplayData reset");
804 *this = DisplayData();
Jesse Halla9a1b002013-02-27 16:39:25 -0800805}
806
Mathias Agopian2965b262012-04-08 15:13:32 -0700807// ---------------------------------------------------------------------------
Mathias Agopiana350ff92010-08-10 17:14:02 -0700808}; // namespace android