blob: 8e54392738b4b2d43f8ab5ca4cab604f4da8cd13 [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 Laskowskifc2c0322018-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 Laskowskifc2c0322018-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
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -070099bool HWComposer::getDisplayIdentificationData(hwc2_display_t displayId, uint8_t* outPort,
100 DisplayIdentificationData* outData) const {
101 HWC2::Display* display = mHwcDevice->getDisplayById(displayId);
102 if (!display) {
103 ALOGE("getDisplayIdentificationData: Attempted to access invalid display %" PRIu64,
104 displayId);
105 return false;
106 }
107 const auto error = display->getIdentificationData(outPort, outData);
108 if (error != HWC2::Error::None) {
109 ALOGE("getDisplayIdentificationData failed for display %" PRIu64, displayId);
110 return false;
111 }
112 return true;
113}
114
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700115bool HWComposer::hasCapability(HWC2::Capability capability) const
116{
117 return mHwcDevice->getCapabilities().count(capability) > 0;
118}
119
Dan Stoza9e56aa02015-11-02 13:00:03 -0800120bool HWComposer::isValidDisplay(int32_t displayId) const {
121 return static_cast<size_t>(displayId) < mDisplayData.size() &&
122 mDisplayData[displayId].hwcDisplay;
123}
124
125void HWComposer::validateChange(HWC2::Composition from, HWC2::Composition to) {
126 bool valid = true;
127 switch (from) {
128 case HWC2::Composition::Client:
129 valid = false;
130 break;
131 case HWC2::Composition::Device:
132 case HWC2::Composition::SolidColor:
133 valid = (to == HWC2::Composition::Client);
134 break;
135 case HWC2::Composition::Cursor:
136 case HWC2::Composition::Sideband:
137 valid = (to == HWC2::Composition::Client ||
138 to == HWC2::Composition::Device);
139 break;
140 default:
141 break;
142 }
143
144 if (!valid) {
145 ALOGE("Invalid layer type change: %s --> %s", to_string(from).c_str(),
146 to_string(to).c_str());
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700147 }
148}
149
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700150std::optional<DisplayId> HWComposer::onHotplug(hwc2_display_t displayId, int32_t displayType,
151 HWC2::Connection connection) {
Lloyd Pique715a2c12017-12-14 17:18:08 -0800152 if (displayType >= HWC_NUM_PHYSICAL_DISPLAY_TYPES) {
153 ALOGE("Invalid display type of %d", displayType);
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700154 return {};
Lloyd Pique715a2c12017-12-14 17:18:08 -0800155 }
156
157 ALOGV("hotplug: %" PRIu64 ", %s %s", displayId,
158 displayType == DisplayDevice::DISPLAY_PRIMARY ? "primary" : "external",
Steven Thomas94e35b92017-07-26 18:48:28 -0700159 to_string(connection).c_str());
160 mHwcDevice->onHotplug(displayId, connection);
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700161
162 std::optional<DisplayId> stableId;
163
164 uint8_t port;
165 DisplayIdentificationData data;
166 if (getDisplayIdentificationData(displayId, &port, &data)) {
167 stableId = generateDisplayId(port, data);
168 ALOGE_IF(!stableId, "Failed to generate stable ID for display %" PRIu64, displayId);
169 }
170
Lloyd Pique715a2c12017-12-14 17:18:08 -0800171 // Disconnect is handled through HWComposer::disconnectDisplay via
172 // SurfaceFlinger's onHotplugReceived callback handling
173 if (connection == HWC2::Connection::Connected) {
174 mDisplayData[displayType].hwcDisplay = mHwcDevice->getDisplayById(displayId);
175 mHwcDisplaySlots[displayId] = displayType;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700176 }
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -0700177
178 return stableId;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700179}
180
Steven Thomas94e35b92017-07-26 18:48:28 -0700181bool HWComposer::onVsync(hwc2_display_t displayId, int64_t timestamp,
182 int32_t* outDisplay) {
183 auto display = mHwcDevice->getDisplayById(displayId);
184 if (!display) {
185 ALOGE("onVsync Failed to find display %" PRIu64, displayId);
186 return false;
187 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800188 auto displayType = HWC2::DisplayType::Invalid;
189 auto error = display->getType(&displayType);
190 if (error != HWC2::Error::None) {
Steven Thomas94e35b92017-07-26 18:48:28 -0700191 ALOGE("onVsync: Failed to determine type of display %" PRIu64,
Dan Stoza9e56aa02015-11-02 13:00:03 -0800192 display->getId());
Steven Thomas94e35b92017-07-26 18:48:28 -0700193 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700194 }
Jesse Hall1bd20e02012-08-29 10:47:52 -0700195
Dan Stoza9e56aa02015-11-02 13:00:03 -0800196 if (displayType == HWC2::DisplayType::Virtual) {
197 ALOGE("Virtual display %" PRIu64 " passed to vsync callback",
198 display->getId());
Steven Thomas94e35b92017-07-26 18:48:28 -0700199 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700200 }
201
Dan Stoza9e56aa02015-11-02 13:00:03 -0800202 if (mHwcDisplaySlots.count(display->getId()) == 0) {
203 ALOGE("Unknown physical display %" PRIu64 " passed to vsync callback",
204 display->getId());
Steven Thomas94e35b92017-07-26 18:48:28 -0700205 return false;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700206 }
207
Dan Stoza9e56aa02015-11-02 13:00:03 -0800208 int32_t disp = mHwcDisplaySlots[display->getId()];
209 {
210 Mutex::Autolock _l(mLock);
Jesse Hall1bd20e02012-08-29 10:47:52 -0700211
Dan Stoza9e56aa02015-11-02 13:00:03 -0800212 // There have been reports of HWCs that signal several vsync events
213 // with the same timestamp when turning the display off and on. This
214 // is a bug in the HWC implementation, but filter the extra events
215 // out here so they don't cause havoc downstream.
216 if (timestamp == mLastHwVSync[disp]) {
217 ALOGW("Ignoring duplicate VSYNC event from HWC (t=%" PRId64 ")",
218 timestamp);
Steven Thomas94e35b92017-07-26 18:48:28 -0700219 return false;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800220 }
221
222 mLastHwVSync[disp] = timestamp;
Jesse Hall1c569c42013-04-05 13:44:52 -0700223 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800224
Steven Thomas94e35b92017-07-26 18:48:28 -0700225 if (outDisplay) {
226 *outDisplay = disp;
227 }
228
Dan Stoza9e56aa02015-11-02 13:00:03 -0800229 char tag[16];
230 snprintf(tag, sizeof(tag), "HW_VSYNC_%1u", disp);
231 ATRACE_INT(tag, ++mVSyncCounts[disp] & 1);
232
Steven Thomas94e35b92017-07-26 18:48:28 -0700233 return true;
Jesse Hall1c569c42013-04-05 13:44:52 -0700234}
235
Dan Stoza9e56aa02015-11-02 13:00:03 -0800236status_t HWComposer::allocateVirtualDisplay(uint32_t width, uint32_t height,
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700237 ui::PixelFormat* format, int32_t *outId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800238 if (mRemainingHwcVirtualDisplays == 0) {
239 ALOGE("allocateVirtualDisplay: No remaining virtual displays");
Mathias Agopiane60b0682012-08-21 23:34:09 -0700240 return NO_MEMORY;
241 }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700242
Fabien Sanglardc8e387e2017-03-10 10:30:28 -0800243 if (SurfaceFlinger::maxVirtualDisplaySize != 0 &&
244 (width > SurfaceFlinger::maxVirtualDisplaySize ||
245 height > SurfaceFlinger::maxVirtualDisplaySize)) {
Fabien Sanglarde29055f2017-03-08 11:36:46 -0800246 ALOGE("createVirtualDisplay: Can't create a virtual display with"
Fabien Sanglardc8e387e2017-03-10 10:30:28 -0800247 " a dimension > %" PRIu64 " (tried %u x %u)",
248 SurfaceFlinger::maxVirtualDisplaySize, width, height);
Fabien Sanglarde29055f2017-03-08 11:36:46 -0800249 return INVALID_OPERATION;
250 }
251
Steven Thomas94e35b92017-07-26 18:48:28 -0700252 HWC2::Display* display;
Dan Stoza5cf424b2016-05-20 14:02:39 -0700253 auto error = mHwcDevice->createVirtualDisplay(width, height, format,
254 &display);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800255 if (error != HWC2::Error::None) {
256 ALOGE("allocateVirtualDisplay: Failed to create HWC virtual display");
257 return NO_MEMORY;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700258 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800259
260 size_t displaySlot = 0;
261 if (!mFreeDisplaySlots.empty()) {
262 displaySlot = *mFreeDisplaySlots.begin();
263 mFreeDisplaySlots.erase(displaySlot);
264 } else if (mDisplayData.size() < INT32_MAX) {
265 // Don't bother allocating a slot larger than we can return
266 displaySlot = mDisplayData.size();
267 mDisplayData.resize(displaySlot + 1);
268 } else {
269 ALOGE("allocateVirtualDisplay: Unable to allocate a display slot");
270 return NO_MEMORY;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700271 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800272
273 mDisplayData[displaySlot].hwcDisplay = display;
274
275 --mRemainingHwcVirtualDisplays;
276 *outId = static_cast<int32_t>(displaySlot);
277
Mathias Agopiane60b0682012-08-21 23:34:09 -0700278 return NO_ERROR;
279}
280
Steven Thomas94e35b92017-07-26 18:48:28 -0700281HWC2::Layer* HWComposer::createLayer(int32_t displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700282 RETURN_IF_INVALID_DISPLAY(displayId, nullptr);
283
Dan Stoza9e56aa02015-11-02 13:00:03 -0800284 auto display = mDisplayData[displayId].hwcDisplay;
Steven Thomas94e35b92017-07-26 18:48:28 -0700285 HWC2::Layer* layer;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800286 auto error = display->createLayer(&layer);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700287 RETURN_IF_HWC_ERROR(error, displayId, nullptr);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800288 return layer;
289}
290
Steven Thomas94e35b92017-07-26 18:48:28 -0700291void HWComposer::destroyLayer(int32_t displayId, HWC2::Layer* layer) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700292 RETURN_IF_INVALID_DISPLAY(displayId);
293
Steven Thomas94e35b92017-07-26 18:48:28 -0700294 auto display = mDisplayData[displayId].hwcDisplay;
295 auto error = display->destroyLayer(layer);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700296 RETURN_IF_HWC_ERROR(error, displayId);
Steven Thomas94e35b92017-07-26 18:48:28 -0700297}
298
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800299nsecs_t HWComposer::getRefreshTimestamp(int32_t displayId) const {
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700300 // this returns the last refresh timestamp.
301 // if the last one is not available, we estimate it based on
302 // the refresh period and whatever closest timestamp we have.
303 Mutex::Autolock _l(mLock);
304 nsecs_t now = systemTime(CLOCK_MONOTONIC);
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800305 auto vsyncPeriod = getActiveConfig(displayId)->getVsyncPeriod();
306 return now - ((now - mLastHwVSync[displayId]) % vsyncPeriod);
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700307}
308
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800309bool HWComposer::isConnected(int32_t displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700310 RETURN_IF_INVALID_DISPLAY(displayId, false);
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800311 return mDisplayData[displayId].hwcDisplay->isConnected();
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700312}
313
Dan Stoza9e56aa02015-11-02 13:00:03 -0800314std::vector<std::shared_ptr<const HWC2::Display::Config>>
315 HWComposer::getConfigs(int32_t displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700316 RETURN_IF_INVALID_DISPLAY(displayId, {});
317
Dan Stoza9e56aa02015-11-02 13:00:03 -0800318 auto& displayData = mDisplayData[displayId];
319 auto configs = mDisplayData[displayId].hwcDisplay->getConfigs();
320 if (displayData.configMap.empty()) {
321 for (size_t i = 0; i < configs.size(); ++i) {
322 displayData.configMap[i] = configs[i];
Mathias Agopianda27af92012-09-13 18:17:13 -0700323 }
324 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800325 return configs;
Mathias Agopianda27af92012-09-13 18:17:13 -0700326}
327
Dan Stoza9e56aa02015-11-02 13:00:03 -0800328std::shared_ptr<const HWC2::Display::Config>
329 HWComposer::getActiveConfig(int32_t displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700330 RETURN_IF_INVALID_DISPLAY(displayId, nullptr);
331
Dan Stoza9e56aa02015-11-02 13:00:03 -0800332 std::shared_ptr<const HWC2::Display::Config> config;
333 auto error = mDisplayData[displayId].hwcDisplay->getActiveConfig(&config);
334 if (error == HWC2::Error::BadConfig) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700335 LOG_DISPLAY_ERROR(displayId, "No active config");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800336 return nullptr;
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700337 }
338
339 RETURN_IF_HWC_ERROR(error, displayId, nullptr);
340
341 if (!config) {
342 LOG_DISPLAY_ERROR(displayId, "Unknown config");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800343 return nullptr;
344 }
345
346 return config;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700347}
348
Peiyong Linfd997e02018-03-28 15:29:00 -0700349std::vector<ui::ColorMode> HWComposer::getColorModes(int32_t displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700350 RETURN_IF_INVALID_DISPLAY(displayId, {});
351
Peiyong Linfd997e02018-03-28 15:29:00 -0700352 std::vector<ui::ColorMode> modes;
Steven Thomas94e35b92017-07-26 18:48:28 -0700353 auto error = mDisplayData[displayId].hwcDisplay->getColorModes(&modes);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700354 RETURN_IF_HWC_ERROR(error, displayId, {});
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600355 return modes;
356}
357
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700358status_t HWComposer::setActiveColorMode(int32_t displayId, ui::ColorMode mode,
359 ui::RenderIntent renderIntent) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700360 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Michael Wright28f24d02016-07-12 13:30:53 -0700361
362 auto& displayData = mDisplayData[displayId];
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700363 auto error = displayData.hwcDisplay->setColorMode(mode, renderIntent);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700364 RETURN_IF_HWC_ERROR_FOR(("setColorMode(" + decodeColorMode(mode) + ", " +
365 decodeRenderIntent(renderIntent) + ")")
366 .c_str(),
367 error, displayId, UNKNOWN_ERROR);
Michael Wright28f24d02016-07-12 13:30:53 -0700368
369 return NO_ERROR;
370}
371
372
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800373void HWComposer::setVsyncEnabled(int32_t displayId, HWC2::Vsync enabled) {
374 if (displayId < 0 || displayId >= HWC_DISPLAY_VIRTUAL) {
375 ALOGD("setVsyncEnabled: Ignoring for virtual display %d", displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800376 return;
377 }
378
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700379 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800380
381 // NOTE: we use our own internal lock here because we have to call
382 // into the HWC with the lock held, and we want to make sure
383 // that even if HWC blocks (which it shouldn't), it won't
384 // affect other threads.
385 Mutex::Autolock _l(mVsyncLock);
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800386 auto& displayData = mDisplayData[displayId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800387 if (enabled != displayData.vsyncEnabled) {
388 ATRACE_CALL();
389 auto error = displayData.hwcDisplay->setVsyncEnabled(enabled);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700390 RETURN_IF_HWC_ERROR(error, displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800391
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700392 displayData.vsyncEnabled = enabled;
393
394 char tag[16];
395 snprintf(tag, sizeof(tag), "HW_VSYNC_ON_%1u", displayId);
396 ATRACE_INT(tag, enabled == HWC2::Vsync::Enable ? 1 : 0);
Colin Cross10fbdb62012-07-12 17:56:34 -0700397 }
Colin Cross10fbdb62012-07-12 17:56:34 -0700398}
399
Chia-I Wu06d63de2017-01-04 14:58:51 +0800400status_t HWComposer::setClientTarget(int32_t displayId, uint32_t slot,
Dan Stoza9e56aa02015-11-02 13:00:03 -0800401 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700402 ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700403 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Jesse Hall851cfe82013-03-20 13:44:00 -0700404
Dan Stoza9e56aa02015-11-02 13:00:03 -0800405 ALOGV("setClientTarget for display %d", displayId);
406 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400407 auto error = hwcDisplay->setClientTarget(slot, target, acquireFence, dataspace);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700408 RETURN_IF_HWC_ERROR(error, displayId, BAD_VALUE);
Jesse Hall851cfe82013-03-20 13:44:00 -0700409 return NO_ERROR;
410}
411
Dan Stoza9e56aa02015-11-02 13:00:03 -0800412status_t HWComposer::prepare(DisplayDevice& displayDevice) {
413 ATRACE_CALL();
414
415 Mutex::Autolock _l(mDisplayLock);
416 auto displayId = displayDevice.getHwcDisplayId();
Dan Stozaec0f7172016-07-21 11:09:40 -0700417 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
418 ALOGV("Skipping HWComposer prepare for non-HWC display");
419 return NO_ERROR;
420 }
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700421
422 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800423
424 auto& displayData = mDisplayData[displayId];
425 auto& hwcDisplay = displayData.hwcDisplay;
426 if (!hwcDisplay->isConnected()) {
427 return NO_ERROR;
428 }
429
430 uint32_t numTypes = 0;
431 uint32_t numRequests = 0;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700432
433 HWC2::Error error = HWC2::Error::None;
434
Chia-I Wu41b98d42017-12-11 11:04:36 -0800435 // First try to skip validate altogether when there is no client
436 // composition. When there is client composition, since we haven't
437 // rendered to the client target yet, we should not attempt to skip
438 // validate.
439 //
440 // displayData.hasClientComposition hasn't been updated for this frame.
441 // The check below is incorrect. We actually rely on HWC here to fall
442 // back to validate when there is any client layer.
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700443 displayData.validateWasSkipped = false;
Chia-I Wu41b98d42017-12-11 11:04:36 -0800444 if (!displayData.hasClientComposition) {
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700445 sp<android::Fence> outPresentFence;
446 uint32_t state = UINT32_MAX;
447 error = hwcDisplay->presentOrValidate(&numTypes, &numRequests, &outPresentFence , &state);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700448 if (error != HWC2::Error::HasChanges) {
449 RETURN_IF_HWC_ERROR_FOR("presentOrValidate", error, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700450 }
451 if (state == 1) { //Present Succeeded.
Steven Thomas94e35b92017-07-26 18:48:28 -0700452 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700453 error = hwcDisplay->getReleaseFences(&releaseFences);
454 displayData.releaseFences = std::move(releaseFences);
455 displayData.lastPresentFence = outPresentFence;
456 displayData.validateWasSkipped = true;
457 displayData.presentError = error;
458 return NO_ERROR;
459 }
460 // Present failed but Validate ran.
461 } else {
462 error = hwcDisplay->validate(&numTypes, &numRequests);
463 }
464 ALOGV("SkipValidate failed, Falling back to SLOW validate/present");
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700465 if (error != HWC2::Error::HasChanges) {
466 RETURN_IF_HWC_ERROR_FOR("validate", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800467 }
468
Steven Thomas94e35b92017-07-26 18:48:28 -0700469 std::unordered_map<HWC2::Layer*, HWC2::Composition> changedTypes;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800470 changedTypes.reserve(numTypes);
471 error = hwcDisplay->getChangedCompositionTypes(&changedTypes);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700472 RETURN_IF_HWC_ERROR_FOR("getChangedCompositionTypes", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800473
474 displayData.displayRequests = static_cast<HWC2::DisplayRequest>(0);
Steven Thomas94e35b92017-07-26 18:48:28 -0700475 std::unordered_map<HWC2::Layer*, HWC2::LayerRequest> layerRequests;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800476 layerRequests.reserve(numRequests);
477 error = hwcDisplay->getRequests(&displayData.displayRequests,
478 &layerRequests);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700479 RETURN_IF_HWC_ERROR_FOR("getRequests", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800480
481 displayData.hasClientComposition = false;
482 displayData.hasDeviceComposition = false;
483 for (auto& layer : displayDevice.getVisibleLayersSortedByZ()) {
484 auto hwcLayer = layer->getHwcLayer(displayId);
485
486 if (changedTypes.count(hwcLayer) != 0) {
487 // We pass false so we only update our state and don't call back
488 // into the HWC device
489 validateChange(layer->getCompositionType(displayId),
490 changedTypes[hwcLayer]);
491 layer->setCompositionType(displayId, changedTypes[hwcLayer], false);
492 }
493
494 switch (layer->getCompositionType(displayId)) {
495 case HWC2::Composition::Client:
496 displayData.hasClientComposition = true;
497 break;
498 case HWC2::Composition::Device:
499 case HWC2::Composition::SolidColor:
500 case HWC2::Composition::Cursor:
501 case HWC2::Composition::Sideband:
502 displayData.hasDeviceComposition = true;
503 break;
504 default:
505 break;
506 }
507
508 if (layerRequests.count(hwcLayer) != 0 &&
509 layerRequests[hwcLayer] ==
510 HWC2::LayerRequest::ClearClientTarget) {
511 layer->setClearClientTarget(displayId, true);
512 } else {
513 if (layerRequests.count(hwcLayer) != 0) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700514 LOG_DISPLAY_ERROR(displayId,
515 ("Unknown layer request " + to_string(layerRequests[hwcLayer]))
516 .c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800517 }
518 layer->setClearClientTarget(displayId, false);
519 }
520 }
521
522 error = hwcDisplay->acceptChanges();
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700523 RETURN_IF_HWC_ERROR_FOR("acceptChanges", error, displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800524
525 return NO_ERROR;
526}
527
528bool HWComposer::hasDeviceComposition(int32_t displayId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700529 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
530 // Displays without a corresponding HWC display are never composed by
531 // the device
532 return false;
533 }
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700534
535 RETURN_IF_INVALID_DISPLAY(displayId, false);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800536 return mDisplayData[displayId].hasDeviceComposition;
537}
538
Madhuri Athota88a905b2017-05-04 16:58:15 +0530539bool HWComposer::hasFlipClientTargetRequest(int32_t displayId) const {
540 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
541 // Displays without a corresponding HWC display are never composed by
542 // the device
543 return false;
544 }
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700545
546 RETURN_IF_INVALID_DISPLAY(displayId, false);
Madhuri Athota88a905b2017-05-04 16:58:15 +0530547 return ((static_cast<uint32_t>(mDisplayData[displayId].displayRequests) &
548 static_cast<uint32_t>(HWC2::DisplayRequest::FlipClientTarget)) != 0);
549}
550
Dan Stoza9e56aa02015-11-02 13:00:03 -0800551bool HWComposer::hasClientComposition(int32_t displayId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700552 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
553 // Displays without a corresponding HWC display are always composed by
554 // the client
555 return true;
556 }
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700557
558 RETURN_IF_INVALID_DISPLAY(displayId, true);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800559 return mDisplayData[displayId].hasClientComposition;
560}
561
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800562sp<Fence> HWComposer::getPresentFence(int32_t displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700563 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800564 return mDisplayData[displayId].lastPresentFence;
Jesse Hall851cfe82013-03-20 13:44:00 -0700565}
566
Dan Stoza9e56aa02015-11-02 13:00:03 -0800567sp<Fence> HWComposer::getLayerReleaseFence(int32_t displayId,
Steven Thomas94e35b92017-07-26 18:48:28 -0700568 HWC2::Layer* layer) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700569 RETURN_IF_INVALID_DISPLAY(displayId, Fence::NO_FENCE);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800570 auto displayFences = mDisplayData[displayId].releaseFences;
571 if (displayFences.count(layer) == 0) {
572 ALOGV("getLayerReleaseFence: Release fence not found");
573 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700574 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800575 return displayFences[layer];
Riley Andrews03414a12014-07-01 14:22:59 -0700576}
577
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800578status_t HWComposer::presentAndGetReleaseFences(int32_t displayId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800579 ATRACE_CALL();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700580
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700581 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Pablo Ceballosd814cf22015-09-11 14:37:39 -0700582
Dan Stoza9e56aa02015-11-02 13:00:03 -0800583 auto& displayData = mDisplayData[displayId];
584 auto& hwcDisplay = displayData.hwcDisplay;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700585
586 if (displayData.validateWasSkipped) {
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700587 // explicitly flush all pending commands
588 auto error = mHwcDevice->flushCommands();
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700589 RETURN_IF_HWC_ERROR_FOR("flushCommands", error, displayId, UNKNOWN_ERROR);
590 RETURN_IF_HWC_ERROR_FOR("present", displayData.presentError, displayId, UNKNOWN_ERROR);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700591 return NO_ERROR;
592 }
593
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800594 auto error = hwcDisplay->present(&displayData.lastPresentFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700595 RETURN_IF_HWC_ERROR_FOR("present", error, displayId, UNKNOWN_ERROR);
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700596
Steven Thomas94e35b92017-07-26 18:48:28 -0700597 std::unordered_map<HWC2::Layer*, sp<Fence>> releaseFences;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800598 error = hwcDisplay->getReleaseFences(&releaseFences);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700599 RETURN_IF_HWC_ERROR_FOR("getReleaseFences", error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800600
601 displayData.releaseFences = std::move(releaseFences);
602
603 return NO_ERROR;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700604}
605
Dan Stoza9e56aa02015-11-02 13:00:03 -0800606status_t HWComposer::setPowerMode(int32_t displayId, int32_t intMode) {
607 ALOGV("setPowerMode(%d, %d)", displayId, intMode);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700608 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
609
Dan Stoza9e56aa02015-11-02 13:00:03 -0800610 if (displayId >= VIRTUAL_DISPLAY_ID_BASE) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700611 LOG_DISPLAY_ERROR(displayId, "Invalid operation on virtual display");
612 return INVALID_OPERATION;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800613 }
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700614
Dan Stoza9e56aa02015-11-02 13:00:03 -0800615 auto mode = static_cast<HWC2::PowerMode>(intMode);
616 if (mode == HWC2::PowerMode::Off) {
617 setVsyncEnabled(displayId, HWC2::Vsync::Disable);
618 }
619
620 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
621 switch (mode) {
622 case HWC2::PowerMode::Off:
623 case HWC2::PowerMode::On:
624 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
625 {
626 auto error = hwcDisplay->setPowerMode(mode);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700627 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error, displayId);
Mathias Agopianda27af92012-09-13 18:17:13 -0700628 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800629 break;
630 case HWC2::PowerMode::Doze:
631 case HWC2::PowerMode::DozeSuspend:
632 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
633 {
634 bool supportsDoze = false;
635 auto error = hwcDisplay->supportsDoze(&supportsDoze);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700636 LOG_HWC_ERROR("supportsDoze", error, displayId);
637
Dan Stoza9e56aa02015-11-02 13:00:03 -0800638 if (!supportsDoze) {
639 mode = HWC2::PowerMode::On;
640 }
641
642 error = hwcDisplay->setPowerMode(mode);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700643 LOG_HWC_ERROR(("setPowerMode(" + to_string(mode) + ")").c_str(), error, displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800644 }
645 break;
646 default:
647 ALOGV("setPowerMode: Not calling HWC");
648 break;
Mathias Agopianda27af92012-09-13 18:17:13 -0700649 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800650
651 return NO_ERROR;
652}
653
654status_t HWComposer::setActiveConfig(int32_t displayId, size_t configId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700655 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800656
657 auto& displayData = mDisplayData[displayId];
658 if (displayData.configMap.count(configId) == 0) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700659 LOG_DISPLAY_ERROR(displayId, ("Invalid config " + std::to_string(configId)).c_str());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800660 return BAD_INDEX;
661 }
662
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700663 auto error = displayData.hwcDisplay->setActiveConfig(displayData.configMap[configId]);
664 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800665 return NO_ERROR;
666}
667
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700668status_t HWComposer::setColorTransform(int32_t displayId,
669 const mat4& transform) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700670 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700671
672 auto& displayData = mDisplayData[displayId];
673 bool isIdentity = transform == mat4();
674 auto error = displayData.hwcDisplay->setColorTransform(transform,
675 isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY :
676 HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700677 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700678 return NO_ERROR;
679}
680
Dan Stoza9e56aa02015-11-02 13:00:03 -0800681void HWComposer::disconnectDisplay(int displayId) {
682 LOG_ALWAYS_FATAL_IF(displayId < 0);
683 auto& displayData = mDisplayData[displayId];
684
685 auto displayType = HWC2::DisplayType::Invalid;
686 auto error = displayData.hwcDisplay->getType(&displayType);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700687 RETURN_IF_HWC_ERROR_FOR("getType", error, displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800688
689 // If this was a virtual display, add its slot back for reuse by future
690 // virtual displays
691 if (displayType == HWC2::DisplayType::Virtual) {
692 mFreeDisplaySlots.insert(displayId);
693 ++mRemainingHwcVirtualDisplays;
694 }
695
696 auto hwcId = displayData.hwcDisplay->getId();
697 mHwcDisplaySlots.erase(hwcId);
698 displayData.reset();
Steven Thomas94e35b92017-07-26 18:48:28 -0700699
700 mHwcDevice->destroyDisplay(hwcId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800701}
702
703status_t HWComposer::setOutputBuffer(int32_t displayId,
704 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buffer) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700705 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800706
707 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
708 auto displayType = HWC2::DisplayType::Invalid;
709 auto error = hwcDisplay->getType(&displayType);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700710 RETURN_IF_HWC_ERROR_FOR("getType", error, displayId, NAME_NOT_FOUND);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800711
712 if (displayType != HWC2::DisplayType::Virtual) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700713 LOG_DISPLAY_ERROR(displayId, "Invalid operation on physical display");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800714 return INVALID_OPERATION;
715 }
716
717 error = hwcDisplay->setOutputBuffer(buffer, acquireFence);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700718 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800719 return NO_ERROR;
720}
721
722void HWComposer::clearReleaseFences(int32_t displayId) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700723 RETURN_IF_INVALID_DISPLAY(displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800724 mDisplayData[displayId].releaseFences.clear();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700725}
726
Peiyong Lin62665892018-04-16 11:07:44 -0700727status_t HWComposer::getHdrCapabilities(
728 int32_t displayId, HdrCapabilities* outCapabilities) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700729 RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
Dan Stozac4f471e2016-03-24 09:31:08 -0700730
731 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
Peiyong Lin62665892018-04-16 11:07:44 -0700732 auto error = hwcDisplay->getHdrCapabilities(outCapabilities);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700733 RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
Peiyong Lin62665892018-04-16 11:07:44 -0700734 return NO_ERROR;
Dan Stozac4f471e2016-03-24 09:31:08 -0700735}
736
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700737int32_t HWComposer::getSupportedPerFrameMetadata(int32_t displayId) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700738 RETURN_IF_INVALID_DISPLAY(displayId, 0);
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700739
740 int32_t supportedMetadata;
741 auto error = mDisplayData[displayId].hwcDisplay->getSupportedPerFrameMetadata(
742 &supportedMetadata);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700743 RETURN_IF_HWC_ERROR(error, displayId, 0);
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700744 return supportedMetadata;
745}
746
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700747std::vector<ui::RenderIntent> HWComposer::getRenderIntents(int32_t displayId,
748 ui::ColorMode colorMode) const {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700749 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700750
751 std::vector<ui::RenderIntent> renderIntents;
752 auto error = mDisplayData[displayId].hwcDisplay->getRenderIntents(colorMode, &renderIntents);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700753 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700754 return renderIntents;
755}
756
757mat4 HWComposer::getDataspaceSaturationMatrix(int32_t displayId, ui::Dataspace dataspace) {
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700758 RETURN_IF_INVALID_DISPLAY(displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700759
760 mat4 matrix;
761 auto error = mDisplayData[displayId].hwcDisplay->getDataspaceSaturationMatrix(dataspace,
762 &matrix);
Dominik Laskowskifc2c0322018-04-19 14:47:33 -0700763 RETURN_IF_HWC_ERROR(error, displayId, {});
Peiyong Lin0e7a7912018-04-05 14:36:36 -0700764 return matrix;
765}
766
Andy McFadden4df87bd2014-04-21 18:08:54 -0700767// Converts a PixelFormat to a human-readable string. Max 11 chars.
768// (Could use a table of prefab String8 objects.)
Dan Stoza9e56aa02015-11-02 13:00:03 -0800769/*
Andy McFadden4df87bd2014-04-21 18:08:54 -0700770static String8 getFormatStr(PixelFormat format) {
771 switch (format) {
772 case PIXEL_FORMAT_RGBA_8888: return String8("RGBA_8888");
773 case PIXEL_FORMAT_RGBX_8888: return String8("RGBx_8888");
774 case PIXEL_FORMAT_RGB_888: return String8("RGB_888");
775 case PIXEL_FORMAT_RGB_565: return String8("RGB_565");
776 case PIXEL_FORMAT_BGRA_8888: return String8("BGRA_8888");
Andy McFaddenf0058ca2014-05-20 13:28:50 -0700777 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
778 return String8("ImplDef");
Andy McFadden4df87bd2014-04-21 18:08:54 -0700779 default:
780 String8 result;
781 result.appendFormat("? %08x", format);
782 return result;
783 }
784}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800785*/
Andy McFadden4df87bd2014-04-21 18:08:54 -0700786
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800787bool HWComposer::isUsingVrComposer() const {
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800788 return getComposer()->isUsingVrComposer();
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800789}
790
Mathias Agopian74d211a2013-04-22 16:55:35 +0200791void HWComposer::dump(String8& result) const {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800792 // TODO: In order to provide a dump equivalent to HWC1, we need to shadow
793 // all the state going into the layers. This is probably better done in
794 // Layer itself, but it's going to take a bit of work to get there.
795 result.append(mHwcDevice->dump().c_str());
Mathias Agopian83727852010-09-23 18:13:21 -0700796}
797
Steven Thomas6e8f7062017-11-22 14:15:29 -0800798std::optional<hwc2_display_t>
799HWComposer::getHwcDisplayId(int32_t displayId) const {
800 if (!isValidDisplay(displayId)) {
801 return {};
802 }
803 return mDisplayData[displayId].hwcDisplay->getId();
804}
805
Mathias Agopiana350ff92010-08-10 17:14:02 -0700806// ---------------------------------------------------------------------------
Mathias Agopian2965b262012-04-08 15:13:32 -0700807
Jesse Halla9a1b002013-02-27 16:39:25 -0800808HWComposer::DisplayData::DisplayData()
Dan Stoza9e56aa02015-11-02 13:00:03 -0800809 : hasClientComposition(false),
810 hasDeviceComposition(false),
Steven Thomas94e35b92017-07-26 18:48:28 -0700811 hwcDisplay(nullptr),
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800812 lastPresentFence(Fence::NO_FENCE),
Dan Stoza9e56aa02015-11-02 13:00:03 -0800813 outbufHandle(nullptr),
814 outbufAcquireFence(Fence::NO_FENCE),
815 vsyncEnabled(HWC2::Vsync::Disable) {
816 ALOGV("Created new DisplayData");
817}
Jesse Halla9a1b002013-02-27 16:39:25 -0800818
819HWComposer::DisplayData::~DisplayData() {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800820}
821
822void HWComposer::DisplayData::reset() {
823 ALOGV("DisplayData reset");
824 *this = DisplayData();
Jesse Halla9a1b002013-02-27 16:39:25 -0800825}
826
Mathias Agopian2965b262012-04-08 15:13:32 -0700827// ---------------------------------------------------------------------------
Mathias Agopiana350ff92010-08-10 17:14:02 -0700828}; // namespace android