blob: 1c99036b1b1db499fb165f1f78ceaf5f5bff8da9 [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 "HWC2On1Adapter.h"
51#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
57namespace android {
Jesse Hall5880cc52012-06-05 23:40:32 -070058
Jesse Hall72960512013-01-10 16:19:56 -080059#define MIN_HWC_HEADER_VERSION HWC_HEADER_VERSION
Jesse Hall9eb1eb52012-08-29 10:39:38 -070060
Mathias Agopiana350ff92010-08-10 17:14:02 -070061// ---------------------------------------------------------------------------
62
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -080063HWComposer::HWComposer(const sp<SurfaceFlinger>& flinger, bool useVrComposer)
Mathias Agopianc7d14e22011-08-01 16:32:21 -070064 : mFlinger(flinger),
Dan Stoza9e56aa02015-11-02 13:00:03 -080065 mAdapter(),
66 mHwcDevice(),
67 mDisplayData(2),
68 mFreeDisplaySlots(),
69 mHwcDisplaySlots(),
70 mCBContext(),
71 mEventHandler(nullptr),
72 mVSyncCounts(),
73 mRemainingHwcVirtualDisplays(0)
Mathias Agopiana350ff92010-08-10 17:14:02 -070074{
Mathias Agopianbef42c52013-08-21 17:45:46 -070075 for (size_t i=0 ; i<HWC_NUM_PHYSICAL_DISPLAY_TYPES ; i++) {
76 mLastHwVSync[i] = 0;
77 mVSyncCounts[i] = 0;
78 }
79
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -080080 loadHwcModule(useVrComposer);
Mathias Agopiana350ff92010-08-10 17:14:02 -070081}
82
Dan Stoza9e56aa02015-11-02 13:00:03 -080083HWComposer::~HWComposer() {}
84
85void HWComposer::setEventHandler(EventHandler* handler)
86{
87 if (handler == nullptr) {
88 ALOGE("setEventHandler: Rejected attempt to clear handler");
89 return;
Andy McFaddenbabba182012-09-12 13:14:51 -070090 }
Dan Stoza9e56aa02015-11-02 13:00:03 -080091
92 bool wasNull = (mEventHandler == nullptr);
93 mEventHandler = handler;
94
95 if (wasNull) {
96 auto hotplugHook = std::bind(&HWComposer::hotplug, this,
97 std::placeholders::_1, std::placeholders::_2);
98 mHwcDevice->registerHotplugCallback(hotplugHook);
99 auto invalidateHook = std::bind(&HWComposer::invalidate, this,
100 std::placeholders::_1);
101 mHwcDevice->registerRefreshCallback(invalidateHook);
102 auto vsyncHook = std::bind(&HWComposer::vsync, this,
103 std::placeholders::_1, std::placeholders::_2);
104 mHwcDevice->registerVsyncCallback(vsyncHook);
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700105 }
Mathias Agopiana350ff92010-08-10 17:14:02 -0700106}
107
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700108// Load and prepare the hardware composer module. Sets mHwc.
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800109void HWComposer::loadHwcModule(bool useVrComposer)
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700110{
Dan Stoza9e56aa02015-11-02 13:00:03 -0800111 ALOGV("loadHwcModule");
112
Chia-I Wuaab99f52016-10-05 12:59:58 +0800113#ifdef BYPASS_IHWC
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800114 (void)useVrComposer; // Silence unused parameter warning.
115
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700116 hw_module_t const* module;
117
118 if (hw_get_module(HWC_HARDWARE_MODULE_ID, &module) != 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800119 ALOGE("%s module not found, aborting", HWC_HARDWARE_MODULE_ID);
120 abort();
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700121 }
122
Dan Stoza355f6042016-04-14 14:30:41 -0700123 hw_device_t* device = nullptr;
124 int error = module->methods->open(module, HWC_HARDWARE_COMPOSER, &device);
125 if (error != 0) {
126 ALOGE("Failed to open HWC device (%s), aborting", strerror(-error));
127 abort();
128 }
129
130 uint32_t majorVersion = (device->version >> 24) & 0xF;
131 if (majorVersion == 2) {
132 mHwcDevice = std::make_unique<HWC2::Device>(
133 reinterpret_cast<hwc2_device_t*>(device));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800134 } else {
Dan Stoza355f6042016-04-14 14:30:41 -0700135 mAdapter = std::make_unique<HWC2On1Adapter>(
136 reinterpret_cast<hwc_composer_device_1_t*>(device));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800137 uint8_t minorVersion = mAdapter->getHwc1MinorVersion();
138 if (minorVersion < 1) {
139 ALOGE("Cannot adapt to HWC version %d.%d",
140 static_cast<int32_t>((minorVersion >> 8) & 0xF),
141 static_cast<int32_t>(minorVersion & 0xF));
142 abort();
143 }
144 mHwcDevice = std::make_unique<HWC2::Device>(
145 static_cast<hwc2_device_t*>(mAdapter.get()));
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700146 }
Chia-I Wuaab99f52016-10-05 12:59:58 +0800147#else
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800148 mHwcDevice = std::make_unique<HWC2::Device>(useVrComposer);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800149#endif
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700150
Dan Stoza9e56aa02015-11-02 13:00:03 -0800151 mRemainingHwcVirtualDisplays = mHwcDevice->getMaxVirtualDisplayCount();
152}
153
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700154bool HWComposer::hasCapability(HWC2::Capability capability) const
155{
156 return mHwcDevice->getCapabilities().count(capability) > 0;
157}
158
Dan Stoza9e56aa02015-11-02 13:00:03 -0800159bool HWComposer::isValidDisplay(int32_t displayId) const {
160 return static_cast<size_t>(displayId) < mDisplayData.size() &&
161 mDisplayData[displayId].hwcDisplay;
162}
163
164void HWComposer::validateChange(HWC2::Composition from, HWC2::Composition to) {
165 bool valid = true;
166 switch (from) {
167 case HWC2::Composition::Client:
168 valid = false;
169 break;
170 case HWC2::Composition::Device:
171 case HWC2::Composition::SolidColor:
172 valid = (to == HWC2::Composition::Client);
173 break;
174 case HWC2::Composition::Cursor:
175 case HWC2::Composition::Sideband:
176 valid = (to == HWC2::Composition::Client ||
177 to == HWC2::Composition::Device);
178 break;
179 default:
180 break;
181 }
182
183 if (!valid) {
184 ALOGE("Invalid layer type change: %s --> %s", to_string(from).c_str(),
185 to_string(to).c_str());
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700186 }
187}
188
Dan Stoza9e56aa02015-11-02 13:00:03 -0800189void HWComposer::hotplug(const std::shared_ptr<HWC2::Display>& display,
190 HWC2::Connection connected) {
191 ALOGV("hotplug: %" PRIu64 ", %s", display->getId(),
192 to_string(connected).c_str());
193 int32_t disp = 0;
194 if (!mDisplayData[0].hwcDisplay) {
195 ALOGE_IF(connected != HWC2::Connection::Connected, "Assumed primary"
196 " display would be connected");
197 mDisplayData[0].hwcDisplay = display;
198 mHwcDisplaySlots[display->getId()] = 0;
199 disp = DisplayDevice::DISPLAY_PRIMARY;
200 } else {
201 // Disconnect is handled through HWComposer::disconnectDisplay via
202 // SurfaceFlinger's onHotplugReceived callback handling
203 if (connected == HWC2::Connection::Connected) {
204 mDisplayData[1].hwcDisplay = display;
205 mHwcDisplaySlots[display->getId()] = 1;
206 }
207 disp = DisplayDevice::DISPLAY_EXTERNAL;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700208 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800209 mEventHandler->onHotplugReceived(disp,
210 connected == HWC2::Connection::Connected);
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700211}
212
Dan Stoza9e56aa02015-11-02 13:00:03 -0800213void HWComposer::invalidate(const std::shared_ptr<HWC2::Display>& /*display*/) {
Mathias Agopiane2c2f922011-10-05 15:00:22 -0700214 mFlinger->repaintEverything();
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700215}
216
Dan Stoza9e56aa02015-11-02 13:00:03 -0800217void HWComposer::vsync(const std::shared_ptr<HWC2::Display>& display,
218 int64_t timestamp) {
219 auto displayType = HWC2::DisplayType::Invalid;
220 auto error = display->getType(&displayType);
221 if (error != HWC2::Error::None) {
222 ALOGE("vsync: Failed to determine type of display %" PRIu64,
223 display->getId());
Jesse Hall1bd20e02012-08-29 10:47:52 -0700224 return;
225 }
Jesse Hall1bd20e02012-08-29 10:47:52 -0700226
Dan Stoza9e56aa02015-11-02 13:00:03 -0800227 if (displayType == HWC2::DisplayType::Virtual) {
228 ALOGE("Virtual display %" PRIu64 " passed to vsync callback",
229 display->getId());
230 return;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700231 }
232
Dan Stoza9e56aa02015-11-02 13:00:03 -0800233 if (mHwcDisplaySlots.count(display->getId()) == 0) {
234 ALOGE("Unknown physical display %" PRIu64 " passed to vsync callback",
235 display->getId());
236 return;
Jesse Hall1bd20e02012-08-29 10:47:52 -0700237 }
238
Dan Stoza9e56aa02015-11-02 13:00:03 -0800239 int32_t disp = mHwcDisplaySlots[display->getId()];
240 {
241 Mutex::Autolock _l(mLock);
Jesse Hall1bd20e02012-08-29 10:47:52 -0700242
Dan Stoza9e56aa02015-11-02 13:00:03 -0800243 // There have been reports of HWCs that signal several vsync events
244 // with the same timestamp when turning the display off and on. This
245 // is a bug in the HWC implementation, but filter the extra events
246 // out here so they don't cause havoc downstream.
247 if (timestamp == mLastHwVSync[disp]) {
248 ALOGW("Ignoring duplicate VSYNC event from HWC (t=%" PRId64 ")",
249 timestamp);
250 return;
251 }
252
253 mLastHwVSync[disp] = timestamp;
Jesse Hall1c569c42013-04-05 13:44:52 -0700254 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800255
256 char tag[16];
257 snprintf(tag, sizeof(tag), "HW_VSYNC_%1u", disp);
258 ATRACE_INT(tag, ++mVSyncCounts[disp] & 1);
259
260 mEventHandler->onVSyncReceived(disp, timestamp);
Jesse Hall1c569c42013-04-05 13:44:52 -0700261}
262
Dan Stoza9e56aa02015-11-02 13:00:03 -0800263status_t HWComposer::allocateVirtualDisplay(uint32_t width, uint32_t height,
Dan Stoza5cf424b2016-05-20 14:02:39 -0700264 android_pixel_format_t* format, int32_t *outId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800265 if (mRemainingHwcVirtualDisplays == 0) {
266 ALOGE("allocateVirtualDisplay: No remaining virtual displays");
Mathias Agopiane60b0682012-08-21 23:34:09 -0700267 return NO_MEMORY;
268 }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700269
Dan Stoza9e56aa02015-11-02 13:00:03 -0800270 std::shared_ptr<HWC2::Display> display;
Dan Stoza5cf424b2016-05-20 14:02:39 -0700271 auto error = mHwcDevice->createVirtualDisplay(width, height, format,
272 &display);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800273 if (error != HWC2::Error::None) {
274 ALOGE("allocateVirtualDisplay: Failed to create HWC virtual display");
275 return NO_MEMORY;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700276 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800277
278 size_t displaySlot = 0;
279 if (!mFreeDisplaySlots.empty()) {
280 displaySlot = *mFreeDisplaySlots.begin();
281 mFreeDisplaySlots.erase(displaySlot);
282 } else if (mDisplayData.size() < INT32_MAX) {
283 // Don't bother allocating a slot larger than we can return
284 displaySlot = mDisplayData.size();
285 mDisplayData.resize(displaySlot + 1);
286 } else {
287 ALOGE("allocateVirtualDisplay: Unable to allocate a display slot");
288 return NO_MEMORY;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700289 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800290
291 mDisplayData[displaySlot].hwcDisplay = display;
292
293 --mRemainingHwcVirtualDisplays;
294 *outId = static_cast<int32_t>(displaySlot);
295
Mathias Agopiane60b0682012-08-21 23:34:09 -0700296 return NO_ERROR;
297}
298
Dan Stoza9e56aa02015-11-02 13:00:03 -0800299std::shared_ptr<HWC2::Layer> HWComposer::createLayer(int32_t displayId) {
300 if (!isValidDisplay(displayId)) {
301 ALOGE("Failed to create layer on invalid display %d", displayId);
302 return nullptr;
303 }
304 auto display = mDisplayData[displayId].hwcDisplay;
305 std::shared_ptr<HWC2::Layer> layer;
306 auto error = display->createLayer(&layer);
307 if (error != HWC2::Error::None) {
308 ALOGE("Failed to create layer on display %d: %s (%d)", displayId,
309 to_string(error).c_str(), static_cast<int32_t>(error));
310 return nullptr;
311 }
312 return layer;
313}
314
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800315nsecs_t HWComposer::getRefreshTimestamp(int32_t displayId) const {
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700316 // this returns the last refresh timestamp.
317 // if the last one is not available, we estimate it based on
318 // the refresh period and whatever closest timestamp we have.
319 Mutex::Autolock _l(mLock);
320 nsecs_t now = systemTime(CLOCK_MONOTONIC);
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800321 auto vsyncPeriod = getActiveConfig(displayId)->getVsyncPeriod();
322 return now - ((now - mLastHwVSync[displayId]) % vsyncPeriod);
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700323}
324
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800325bool HWComposer::isConnected(int32_t displayId) const {
326 if (!isValidDisplay(displayId)) {
327 ALOGE("isConnected: Attempted to access invalid display %d", displayId);
Mathias Agopiane60b0682012-08-21 23:34:09 -0700328 return false;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800329 }
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800330 return mDisplayData[displayId].hwcDisplay->isConnected();
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700331}
332
Dan Stoza9e56aa02015-11-02 13:00:03 -0800333std::vector<std::shared_ptr<const HWC2::Display::Config>>
334 HWComposer::getConfigs(int32_t displayId) const {
335 if (!isValidDisplay(displayId)) {
336 ALOGE("getConfigs: Attempted to access invalid display %d", displayId);
337 return {};
338 }
339 auto& displayData = mDisplayData[displayId];
340 auto configs = mDisplayData[displayId].hwcDisplay->getConfigs();
341 if (displayData.configMap.empty()) {
342 for (size_t i = 0; i < configs.size(); ++i) {
343 displayData.configMap[i] = configs[i];
Mathias Agopianda27af92012-09-13 18:17:13 -0700344 }
345 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800346 return configs;
Mathias Agopianda27af92012-09-13 18:17:13 -0700347}
348
Dan Stoza9e56aa02015-11-02 13:00:03 -0800349std::shared_ptr<const HWC2::Display::Config>
350 HWComposer::getActiveConfig(int32_t displayId) const {
351 if (!isValidDisplay(displayId)) {
Fabien Sanglardb7432cc2016-11-11 09:40:27 -0800352 ALOGV("getActiveConfigs: Attempted to access invalid display %d",
Dan Stoza9e56aa02015-11-02 13:00:03 -0800353 displayId);
354 return nullptr;
Mathias Agopian58959342010-10-07 14:57:04 -0700355 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800356 std::shared_ptr<const HWC2::Display::Config> config;
357 auto error = mDisplayData[displayId].hwcDisplay->getActiveConfig(&config);
358 if (error == HWC2::Error::BadConfig) {
Fabien Sanglardb7432cc2016-11-11 09:40:27 -0800359 ALOGE("getActiveConfig: No config active, returning null");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800360 return nullptr;
361 } else if (error != HWC2::Error::None) {
362 ALOGE("getActiveConfig failed for display %d: %s (%d)", displayId,
363 to_string(error).c_str(), static_cast<int32_t>(error));
364 return nullptr;
365 } else if (!config) {
366 ALOGE("getActiveConfig returned an unknown config for display %d",
367 displayId);
368 return nullptr;
369 }
370
371 return config;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700372}
373
Michael Wright28f24d02016-07-12 13:30:53 -0700374std::vector<android_color_mode_t> HWComposer::getColorModes(int32_t displayId) const {
375 std::vector<android_color_mode_t> modes;
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600376
377 if (!isValidDisplay(displayId)) {
378 ALOGE("getColorModes: Attempted to access invalid display %d",
379 displayId);
380 return modes;
381 }
382 const std::shared_ptr<HWC2::Display>& hwcDisplay =
383 mDisplayData[displayId].hwcDisplay;
384
385 auto error = hwcDisplay->getColorModes(&modes);
386 if (error != HWC2::Error::None) {
387 ALOGE("getColorModes failed for display %d: %s (%d)", displayId,
388 to_string(error).c_str(), static_cast<int32_t>(error));
Michael Wright28f24d02016-07-12 13:30:53 -0700389 return std::vector<android_color_mode_t>();
Courtney Goeltzenleuchterfad9d8c2016-06-23 11:49:50 -0600390 }
391
392 return modes;
393}
394
Michael Wright28f24d02016-07-12 13:30:53 -0700395status_t HWComposer::setActiveColorMode(int32_t displayId, android_color_mode_t mode) {
396 if (!isValidDisplay(displayId)) {
397 ALOGE("setActiveColorMode: Display %d is not valid", displayId);
398 return BAD_INDEX;
399 }
400
401 auto& displayData = mDisplayData[displayId];
402 auto error = displayData.hwcDisplay->setColorMode(mode);
403 if (error != HWC2::Error::None) {
404 ALOGE("setActiveConfig: Failed to set color mode %d on display %d: "
405 "%s (%d)", mode, displayId, to_string(error).c_str(),
406 static_cast<int32_t>(error));
407 return UNKNOWN_ERROR;
408 }
409
410 return NO_ERROR;
411}
412
413
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800414void HWComposer::setVsyncEnabled(int32_t displayId, HWC2::Vsync enabled) {
415 if (displayId < 0 || displayId >= HWC_DISPLAY_VIRTUAL) {
416 ALOGD("setVsyncEnabled: Ignoring for virtual display %d", displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800417 return;
418 }
419
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800420 if (!isValidDisplay(displayId)) {
421 ALOGE("setVsyncEnabled: Attempted to access invalid display %d",
422 displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800423 return;
424 }
425
426 // NOTE: we use our own internal lock here because we have to call
427 // into the HWC with the lock held, and we want to make sure
428 // that even if HWC blocks (which it shouldn't), it won't
429 // affect other threads.
430 Mutex::Autolock _l(mVsyncLock);
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800431 auto& displayData = mDisplayData[displayId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800432 if (enabled != displayData.vsyncEnabled) {
433 ATRACE_CALL();
434 auto error = displayData.hwcDisplay->setVsyncEnabled(enabled);
435 if (error == HWC2::Error::None) {
436 displayData.vsyncEnabled = enabled;
437
438 char tag[16];
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800439 snprintf(tag, sizeof(tag), "HW_VSYNC_ON_%1u", displayId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800440 ATRACE_INT(tag, enabled == HWC2::Vsync::Enable ? 1 : 0);
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700441 } else {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800442 ALOGE("setVsyncEnabled: Failed to set vsync to %s on %d/%" PRIu64
Fabien Sanglarddf0b7052016-11-30 15:51:53 -0800443 ": %s (%d)", to_string(enabled).c_str(), displayId,
444 mDisplayData[displayId].hwcDisplay->getId(),
Dan Stoza9e56aa02015-11-02 13:00:03 -0800445 to_string(error).c_str(), static_cast<int32_t>(error));
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700446 }
Colin Cross10fbdb62012-07-12 17:56:34 -0700447 }
Colin Cross10fbdb62012-07-12 17:56:34 -0700448}
449
Chia-I Wu06d63de2017-01-04 14:58:51 +0800450status_t HWComposer::setClientTarget(int32_t displayId, uint32_t slot,
Dan Stoza9e56aa02015-11-02 13:00:03 -0800451 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target,
452 android_dataspace_t dataspace) {
453 if (!isValidDisplay(displayId)) {
Jesse Hall851cfe82013-03-20 13:44:00 -0700454 return BAD_INDEX;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800455 }
Jesse Hall851cfe82013-03-20 13:44:00 -0700456
Dan Stoza9e56aa02015-11-02 13:00:03 -0800457 ALOGV("setClientTarget for display %d", displayId);
458 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
459 buffer_handle_t handle = nullptr;
460 if ((target != nullptr) && target->getNativeBuffer()) {
461 handle = target->getNativeBuffer()->handle;
462 }
Chia-I Wu06d63de2017-01-04 14:58:51 +0800463 auto error = hwcDisplay->setClientTarget(slot, handle,
464 acquireFence, dataspace);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800465 if (error != HWC2::Error::None) {
466 ALOGE("Failed to set client target for display %d: %s (%d)", displayId,
467 to_string(error).c_str(), static_cast<int32_t>(error));
468 return BAD_VALUE;
469 }
470
Jesse Hall851cfe82013-03-20 13:44:00 -0700471 return NO_ERROR;
472}
473
Dan Stoza9e56aa02015-11-02 13:00:03 -0800474status_t HWComposer::prepare(DisplayDevice& displayDevice) {
475 ATRACE_CALL();
476
477 Mutex::Autolock _l(mDisplayLock);
478 auto displayId = displayDevice.getHwcDisplayId();
Dan Stozaec0f7172016-07-21 11:09:40 -0700479 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
480 ALOGV("Skipping HWComposer prepare for non-HWC display");
481 return NO_ERROR;
482 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800483 if (!isValidDisplay(displayId)) {
484 return BAD_INDEX;
485 }
486
487 auto& displayData = mDisplayData[displayId];
488 auto& hwcDisplay = displayData.hwcDisplay;
489 if (!hwcDisplay->isConnected()) {
490 return NO_ERROR;
491 }
492
493 uint32_t numTypes = 0;
494 uint32_t numRequests = 0;
495 auto error = hwcDisplay->validate(&numTypes, &numRequests);
496 if (error != HWC2::Error::None && error != HWC2::Error::HasChanges) {
497 ALOGE("prepare: validate failed for display %d: %s (%d)", displayId,
498 to_string(error).c_str(), static_cast<int32_t>(error));
499 return BAD_INDEX;
500 }
501
502 std::unordered_map<std::shared_ptr<HWC2::Layer>, HWC2::Composition>
503 changedTypes;
504 changedTypes.reserve(numTypes);
505 error = hwcDisplay->getChangedCompositionTypes(&changedTypes);
506 if (error != HWC2::Error::None) {
507 ALOGE("prepare: getChangedCompositionTypes failed on display %d: "
508 "%s (%d)", displayId, to_string(error).c_str(),
509 static_cast<int32_t>(error));
510 return BAD_INDEX;
511 }
512
513
514 displayData.displayRequests = static_cast<HWC2::DisplayRequest>(0);
515 std::unordered_map<std::shared_ptr<HWC2::Layer>, HWC2::LayerRequest>
516 layerRequests;
517 layerRequests.reserve(numRequests);
518 error = hwcDisplay->getRequests(&displayData.displayRequests,
519 &layerRequests);
520 if (error != HWC2::Error::None) {
521 ALOGE("prepare: getRequests failed on display %d: %s (%d)", displayId,
522 to_string(error).c_str(), static_cast<int32_t>(error));
523 return BAD_INDEX;
524 }
525
526 displayData.hasClientComposition = false;
527 displayData.hasDeviceComposition = false;
528 for (auto& layer : displayDevice.getVisibleLayersSortedByZ()) {
529 auto hwcLayer = layer->getHwcLayer(displayId);
530
531 if (changedTypes.count(hwcLayer) != 0) {
532 // We pass false so we only update our state and don't call back
533 // into the HWC device
534 validateChange(layer->getCompositionType(displayId),
535 changedTypes[hwcLayer]);
536 layer->setCompositionType(displayId, changedTypes[hwcLayer], false);
537 }
538
539 switch (layer->getCompositionType(displayId)) {
540 case HWC2::Composition::Client:
541 displayData.hasClientComposition = true;
542 break;
543 case HWC2::Composition::Device:
544 case HWC2::Composition::SolidColor:
545 case HWC2::Composition::Cursor:
546 case HWC2::Composition::Sideband:
547 displayData.hasDeviceComposition = true;
548 break;
549 default:
550 break;
551 }
552
553 if (layerRequests.count(hwcLayer) != 0 &&
554 layerRequests[hwcLayer] ==
555 HWC2::LayerRequest::ClearClientTarget) {
556 layer->setClearClientTarget(displayId, true);
557 } else {
558 if (layerRequests.count(hwcLayer) != 0) {
559 ALOGE("prepare: Unknown layer request: %s",
560 to_string(layerRequests[hwcLayer]).c_str());
561 }
562 layer->setClearClientTarget(displayId, false);
563 }
564 }
565
566 error = hwcDisplay->acceptChanges();
567 if (error != HWC2::Error::None) {
568 ALOGE("prepare: acceptChanges failed: %s", to_string(error).c_str());
569 return BAD_INDEX;
570 }
571
572 return NO_ERROR;
573}
574
575bool HWComposer::hasDeviceComposition(int32_t displayId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700576 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
577 // Displays without a corresponding HWC display are never composed by
578 // the device
579 return false;
580 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800581 if (!isValidDisplay(displayId)) {
582 ALOGE("hasDeviceComposition: Invalid display %d", displayId);
583 return false;
584 }
585 return mDisplayData[displayId].hasDeviceComposition;
586}
587
588bool HWComposer::hasClientComposition(int32_t displayId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700589 if (displayId == DisplayDevice::DISPLAY_ID_INVALID) {
590 // Displays without a corresponding HWC display are always composed by
591 // the client
592 return true;
593 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800594 if (!isValidDisplay(displayId)) {
595 ALOGE("hasClientComposition: Invalid display %d", displayId);
596 return true;
597 }
598 return mDisplayData[displayId].hasClientComposition;
599}
600
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800601sp<Fence> HWComposer::getPresentFence(int32_t displayId) const {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800602 if (!isValidDisplay(displayId)) {
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800603 ALOGE("getPresentFence failed for invalid display %d", displayId);
Jesse Hall851cfe82013-03-20 13:44:00 -0700604 return Fence::NO_FENCE;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800605 }
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800606 return mDisplayData[displayId].lastPresentFence;
Jesse Hall851cfe82013-03-20 13:44:00 -0700607}
608
Brian Anderson3d4039d2016-09-23 16:31:30 -0700609bool HWComposer::presentFenceRepresentsStartOfScanout() const {
Brian Anderson069b3652016-07-22 10:32:47 -0700610 return mAdapter ? false : true;
611}
612
Dan Stoza9e56aa02015-11-02 13:00:03 -0800613sp<Fence> HWComposer::getLayerReleaseFence(int32_t displayId,
614 const std::shared_ptr<HWC2::Layer>& layer) const {
615 if (!isValidDisplay(displayId)) {
616 ALOGE("getLayerReleaseFence: Invalid display");
617 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700618 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800619 auto displayFences = mDisplayData[displayId].releaseFences;
620 if (displayFences.count(layer) == 0) {
621 ALOGV("getLayerReleaseFence: Release fence not found");
622 return Fence::NO_FENCE;
Riley Andrews03414a12014-07-01 14:22:59 -0700623 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800624 return displayFences[layer];
Riley Andrews03414a12014-07-01 14:22:59 -0700625}
626
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800627status_t HWComposer::presentAndGetReleaseFences(int32_t displayId) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800628 ATRACE_CALL();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700629
Dan Stoza9e56aa02015-11-02 13:00:03 -0800630 if (!isValidDisplay(displayId)) {
631 return BAD_INDEX;
Mathias Agopianc3973602012-08-31 17:51:25 -0700632 }
Pablo Ceballosd814cf22015-09-11 14:37:39 -0700633
Dan Stoza9e56aa02015-11-02 13:00:03 -0800634 auto& displayData = mDisplayData[displayId];
635 auto& hwcDisplay = displayData.hwcDisplay;
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800636 auto error = hwcDisplay->present(&displayData.lastPresentFence);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800637 if (error != HWC2::Error::None) {
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800638 ALOGE("presentAndGetReleaseFences: failed for display %d: %s (%d)",
639 displayId, to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800640 return UNKNOWN_ERROR;
641 }
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700642
Dan Stoza9e56aa02015-11-02 13:00:03 -0800643 std::unordered_map<std::shared_ptr<HWC2::Layer>, sp<Fence>> releaseFences;
644 error = hwcDisplay->getReleaseFences(&releaseFences);
645 if (error != HWC2::Error::None) {
Fabien Sanglarda87aa7b2016-11-30 16:27:22 -0800646 ALOGE("presentAndGetReleaseFences: Failed to get release fences "
647 "for display %d: %s (%d)",
Dan Stoza9e56aa02015-11-02 13:00:03 -0800648 displayId, to_string(error).c_str(),
649 static_cast<int32_t>(error));
650 return UNKNOWN_ERROR;
Mathias Agopianf4358632012-08-22 17:16:19 -0700651 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800652
653 displayData.releaseFences = std::move(releaseFences);
654
655 return NO_ERROR;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700656}
657
Dan Stoza9e56aa02015-11-02 13:00:03 -0800658status_t HWComposer::setPowerMode(int32_t displayId, int32_t intMode) {
659 ALOGV("setPowerMode(%d, %d)", displayId, intMode);
660 if (!isValidDisplay(displayId)) {
661 ALOGE("setPowerMode: Bad display");
662 return BAD_INDEX;
663 }
664 if (displayId >= VIRTUAL_DISPLAY_ID_BASE) {
665 ALOGE("setPowerMode: Virtual display %d passed in, returning",
666 displayId);
667 return BAD_INDEX;
668 }
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700669
Dan Stoza9e56aa02015-11-02 13:00:03 -0800670 auto mode = static_cast<HWC2::PowerMode>(intMode);
671 if (mode == HWC2::PowerMode::Off) {
672 setVsyncEnabled(displayId, HWC2::Vsync::Disable);
673 }
674
675 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
676 switch (mode) {
677 case HWC2::PowerMode::Off:
678 case HWC2::PowerMode::On:
679 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
680 {
681 auto error = hwcDisplay->setPowerMode(mode);
682 if (error != HWC2::Error::None) {
683 ALOGE("setPowerMode: Unable to set power mode %s for "
684 "display %d: %s (%d)", to_string(mode).c_str(),
685 displayId, to_string(error).c_str(),
686 static_cast<int32_t>(error));
Mathias Agopianda27af92012-09-13 18:17:13 -0700687 }
688 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800689 break;
690 case HWC2::PowerMode::Doze:
691 case HWC2::PowerMode::DozeSuspend:
692 ALOGV("setPowerMode: Calling HWC %s", to_string(mode).c_str());
693 {
694 bool supportsDoze = false;
695 auto error = hwcDisplay->supportsDoze(&supportsDoze);
696 if (error != HWC2::Error::None) {
697 ALOGE("setPowerMode: Unable to query doze support for "
698 "display %d: %s (%d)", displayId,
699 to_string(error).c_str(),
700 static_cast<int32_t>(error));
701 }
702 if (!supportsDoze) {
703 mode = HWC2::PowerMode::On;
704 }
705
706 error = hwcDisplay->setPowerMode(mode);
707 if (error != HWC2::Error::None) {
708 ALOGE("setPowerMode: Unable to set power mode %s for "
709 "display %d: %s (%d)", to_string(mode).c_str(),
710 displayId, to_string(error).c_str(),
711 static_cast<int32_t>(error));
712 }
713 }
714 break;
715 default:
716 ALOGV("setPowerMode: Not calling HWC");
717 break;
Mathias Agopianda27af92012-09-13 18:17:13 -0700718 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800719
720 return NO_ERROR;
721}
722
723status_t HWComposer::setActiveConfig(int32_t displayId, size_t configId) {
724 if (!isValidDisplay(displayId)) {
725 ALOGE("setActiveConfig: Display %d is not valid", displayId);
726 return BAD_INDEX;
727 }
728
729 auto& displayData = mDisplayData[displayId];
730 if (displayData.configMap.count(configId) == 0) {
731 ALOGE("setActiveConfig: Invalid config %zd", configId);
732 return BAD_INDEX;
733 }
734
735 auto error = displayData.hwcDisplay->setActiveConfig(
736 displayData.configMap[configId]);
737 if (error != HWC2::Error::None) {
738 ALOGE("setActiveConfig: Failed to set config %zu on display %d: "
739 "%s (%d)", configId, displayId, to_string(error).c_str(),
740 static_cast<int32_t>(error));
741 return UNKNOWN_ERROR;
742 }
743
744 return NO_ERROR;
745}
746
Dan Stoza9f26a9c2016-06-22 14:51:09 -0700747status_t HWComposer::setColorTransform(int32_t displayId,
748 const mat4& transform) {
749 if (!isValidDisplay(displayId)) {
750 ALOGE("setColorTransform: Display %d is not valid", displayId);
751 return BAD_INDEX;
752 }
753
754 auto& displayData = mDisplayData[displayId];
755 bool isIdentity = transform == mat4();
756 auto error = displayData.hwcDisplay->setColorTransform(transform,
757 isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY :
758 HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX);
759 if (error != HWC2::Error::None) {
760 ALOGE("setColorTransform: Failed to set transform on display %d: "
761 "%s (%d)", displayId, to_string(error).c_str(),
762 static_cast<int32_t>(error));
763 return UNKNOWN_ERROR;
764 }
765
766 return NO_ERROR;
767}
768
Dan Stoza9e56aa02015-11-02 13:00:03 -0800769void HWComposer::disconnectDisplay(int displayId) {
770 LOG_ALWAYS_FATAL_IF(displayId < 0);
771 auto& displayData = mDisplayData[displayId];
772
773 auto displayType = HWC2::DisplayType::Invalid;
774 auto error = displayData.hwcDisplay->getType(&displayType);
775 if (error != HWC2::Error::None) {
776 ALOGE("disconnectDisplay: Failed to determine type of display %d",
777 displayId);
778 return;
779 }
780
781 // If this was a virtual display, add its slot back for reuse by future
782 // virtual displays
783 if (displayType == HWC2::DisplayType::Virtual) {
784 mFreeDisplaySlots.insert(displayId);
785 ++mRemainingHwcVirtualDisplays;
786 }
787
788 auto hwcId = displayData.hwcDisplay->getId();
789 mHwcDisplaySlots.erase(hwcId);
790 displayData.reset();
791}
792
793status_t HWComposer::setOutputBuffer(int32_t displayId,
794 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buffer) {
795 if (!isValidDisplay(displayId)) {
796 ALOGE("setOutputBuffer: Display %d is not valid", displayId);
797 return BAD_INDEX;
798 }
799
800 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
801 auto displayType = HWC2::DisplayType::Invalid;
802 auto error = hwcDisplay->getType(&displayType);
803 if (error != HWC2::Error::None) {
804 ALOGE("setOutputBuffer: Failed to determine type of display %d",
805 displayId);
806 return NAME_NOT_FOUND;
807 }
808
809 if (displayType != HWC2::DisplayType::Virtual) {
810 ALOGE("setOutputBuffer: Display %d is not virtual", displayId);
811 return INVALID_OPERATION;
812 }
813
814 error = hwcDisplay->setOutputBuffer(buffer, acquireFence);
815 if (error != HWC2::Error::None) {
816 ALOGE("setOutputBuffer: Failed to set buffer on display %d: %s (%d)",
817 displayId, to_string(error).c_str(),
818 static_cast<int32_t>(error));
819 return UNKNOWN_ERROR;
820 }
821
822 return NO_ERROR;
823}
824
825void HWComposer::clearReleaseFences(int32_t displayId) {
826 if (!isValidDisplay(displayId)) {
827 ALOGE("clearReleaseFences: Display %d is not valid", displayId);
828 return;
829 }
830 mDisplayData[displayId].releaseFences.clear();
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700831}
832
Dan Stozac4f471e2016-03-24 09:31:08 -0700833std::unique_ptr<HdrCapabilities> HWComposer::getHdrCapabilities(
834 int32_t displayId) {
835 if (!isValidDisplay(displayId)) {
836 ALOGE("getHdrCapabilities: Display %d is not valid", displayId);
837 return nullptr;
838 }
839
840 auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
841 std::unique_ptr<HdrCapabilities> capabilities;
842 auto error = hwcDisplay->getHdrCapabilities(&capabilities);
843 if (error != HWC2::Error::None) {
844 ALOGE("getOutputCapabilities: Failed to get capabilities on display %d:"
845 " %s (%d)", displayId, to_string(error).c_str(),
846 static_cast<int32_t>(error));
847 return nullptr;
848 }
849
850 return capabilities;
851}
852
Andy McFadden4df87bd2014-04-21 18:08:54 -0700853// Converts a PixelFormat to a human-readable string. Max 11 chars.
854// (Could use a table of prefab String8 objects.)
Dan Stoza9e56aa02015-11-02 13:00:03 -0800855/*
Andy McFadden4df87bd2014-04-21 18:08:54 -0700856static String8 getFormatStr(PixelFormat format) {
857 switch (format) {
858 case PIXEL_FORMAT_RGBA_8888: return String8("RGBA_8888");
859 case PIXEL_FORMAT_RGBX_8888: return String8("RGBx_8888");
860 case PIXEL_FORMAT_RGB_888: return String8("RGB_888");
861 case PIXEL_FORMAT_RGB_565: return String8("RGB_565");
862 case PIXEL_FORMAT_BGRA_8888: return String8("BGRA_8888");
Andy McFaddenf0058ca2014-05-20 13:28:50 -0700863 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
864 return String8("ImplDef");
Andy McFadden4df87bd2014-04-21 18:08:54 -0700865 default:
866 String8 result;
867 result.appendFormat("? %08x", format);
868 return result;
869 }
870}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800871*/
Andy McFadden4df87bd2014-04-21 18:08:54 -0700872
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800873bool HWComposer::isUsingVrComposer() const {
874#ifdef BYPASS_IHWC
875 return false;
876#else
877 return getComposer()->isUsingVrComposer();
878#endif
879}
880
Mathias Agopian74d211a2013-04-22 16:55:35 +0200881void HWComposer::dump(String8& result) const {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800882 // TODO: In order to provide a dump equivalent to HWC1, we need to shadow
883 // all the state going into the layers. This is probably better done in
884 // Layer itself, but it's going to take a bit of work to get there.
885 result.append(mHwcDevice->dump().c_str());
Mathias Agopian83727852010-09-23 18:13:21 -0700886}
887
Mathias Agopiana350ff92010-08-10 17:14:02 -0700888// ---------------------------------------------------------------------------
Mathias Agopian2965b262012-04-08 15:13:32 -0700889
Jesse Halla9a1b002013-02-27 16:39:25 -0800890HWComposer::DisplayData::DisplayData()
Dan Stoza9e56aa02015-11-02 13:00:03 -0800891 : hasClientComposition(false),
892 hasDeviceComposition(false),
893 hwcDisplay(),
Fabien Sanglard11d0fc32016-12-01 15:43:01 -0800894 lastPresentFence(Fence::NO_FENCE),
Dan Stoza9e56aa02015-11-02 13:00:03 -0800895 outbufHandle(nullptr),
896 outbufAcquireFence(Fence::NO_FENCE),
897 vsyncEnabled(HWC2::Vsync::Disable) {
898 ALOGV("Created new DisplayData");
899}
Jesse Halla9a1b002013-02-27 16:39:25 -0800900
901HWComposer::DisplayData::~DisplayData() {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800902}
903
904void HWComposer::DisplayData::reset() {
905 ALOGV("DisplayData reset");
906 *this = DisplayData();
Jesse Halla9a1b002013-02-27 16:39:25 -0800907}
908
Chia-I Wu06d63de2017-01-04 14:58:51 +0800909void HWComposerBufferCache::clear()
910{
911 mBuffers.clear();
912}
913
914void HWComposerBufferCache::getHwcBuffer(int slot,
915 const sp<GraphicBuffer>& buffer,
916 uint32_t* outSlot, sp<GraphicBuffer>* outBuffer)
917{
918 if (slot == BufferQueue::INVALID_BUFFER_SLOT || slot < 0) {
919 // default to slot 0
920 slot = 0;
921 }
922
923 if (static_cast<size_t>(slot) >= mBuffers.size()) {
924 mBuffers.resize(slot + 1);
925 }
926
927 *outSlot = slot;
928
929 if (mBuffers[slot] == buffer) {
930 // already cached in HWC, skip sending the buffer
931 *outBuffer = nullptr;
932 } else {
933 *outBuffer = buffer;
934
935 // update cache
936 mBuffers[slot] = buffer;
937 }
938}
939
Mathias Agopian2965b262012-04-08 15:13:32 -0700940// ---------------------------------------------------------------------------
Mathias Agopiana350ff92010-08-10 17:14:02 -0700941}; // namespace android