Revert "[SF] Introduce VirtualDisplayId"
Revert "CE-ARC: Track changes to DisplayId conversions"
Revert submission 12319471-virtual-display-id
Reason for revert: Breaks build on crosshatch-userdebug
Reverted Changes:
I7d9a3062c:CE-ARC: Track changes to DisplayId conversions
I550b1f471:[SF] Introduce VirtualDisplayId
Change-Id: Ife6b6b51babdc0566801f1c7d2db6239f6f926bd
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index b4868a9..9bfc63a 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -717,8 +717,7 @@
processDisplayHotplugEventsLocked();
const auto display = getDefaultDisplayDeviceLocked();
LOG_ALWAYS_FATAL_IF(!display, "Missing internal display after registering composer callback.");
- const auto displayId = display->getPhysicalId();
- LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(displayId),
+ LOG_ALWAYS_FATAL_IF(!getHwComposer().isConnected(*display->getId()),
"Internal display is disconnected.");
// initialize our drawing state
@@ -1079,8 +1078,8 @@
const nsecs_t vsyncPeriod =
mRefreshRateConfigs->getRefreshRateFromConfigId(mUpcomingActiveConfig.configId)
.getVsyncPeriod();
- const auto physicalId = display->getPhysicalId();
- mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, physicalId,
+ mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle,
+ static_cast<PhysicalDisplayId>(*display->getId()),
mUpcomingActiveConfig.configId, vsyncPeriod);
}
}
@@ -1129,7 +1128,8 @@
}
mUpcomingActiveConfig = *desiredActiveConfig;
- const auto displayId = display->getPhysicalId();
+ const auto displayId = display->getId();
+ LOG_ALWAYS_FATAL_IF(!displayId);
ATRACE_INT("ActiveConfigFPS_HWC", refreshRate.getFps());
@@ -1140,7 +1140,7 @@
hal::VsyncPeriodChangeTimeline outTimeline;
auto status =
- getHwComposer().setActiveConfigWithConstraints(displayId,
+ getHwComposer().setActiveConfigWithConstraints(*displayId,
mUpcomingActiveConfig.configId.value(),
constraints, &outTimeline);
if (status != NO_ERROR) {
@@ -1665,7 +1665,7 @@
if (const auto display = getDefaultDisplayDeviceLocked();
display && display->isPoweredOn()) {
- getHwComposer().setVsyncEnabled(display->getPhysicalId(), mHWCVsyncPendingState);
+ getHwComposer().setVsyncEnabled(*display->getId(), mHWCVsyncPendingState);
}
}));
}
@@ -2120,7 +2120,7 @@
getBE().mDisplayTimeline.updateSignalTimes();
mPreviousPresentFences[1] = mPreviousPresentFences[0];
mPreviousPresentFences[0] =
- display ? getHwComposer().getPresentFence(display->getPhysicalId()) : Fence::NO_FENCE;
+ display ? getHwComposer().getPresentFence(*display->getId()) : Fence::NO_FENCE;
auto presentFenceTime = std::make_shared<FenceTime>(mPreviousPresentFences[0]);
getBE().mDisplayTimeline.push(presentFenceTime);
@@ -2154,8 +2154,7 @@
mScheduler->addPresentFence(presentFenceTime);
}
- const bool isDisplayConnected =
- display && getHwComposer().isConnected(display->getPhysicalId());
+ const bool isDisplayConnected = display && getHwComposer().isConnected(*display->getId());
if (!hasSyncFramework) {
if (isDisplayConnected && display->isPoweredOn()) {
@@ -2172,8 +2171,7 @@
} else if (isDisplayConnected) {
// The HWC doesn't support present fences, so use the refresh
// timestamp instead.
- const nsecs_t presentTime =
- getHwComposer().getRefreshTimestamp(display->getPhysicalId());
+ const nsecs_t presentTime = getHwComposer().getRefreshTimestamp(*display->getId());
mAnimFrameTracker.setActualPresentTime(presentTime);
}
mAnimFrameTracker.advanceFrame();
@@ -2275,7 +2273,7 @@
void SurfaceFlinger::postFrame() {
const auto display = ON_MAIN_THREAD(getDefaultDisplayDeviceLocked());
- if (display && getHwComposer().isConnected(display->getPhysicalId())) {
+ if (display && getHwComposer().isConnected(*display->getId())) {
uint32_t flipCount = display->getPageFlipCount();
if (flipCount % LOG_FRAME_STATS_PERIOD == 0) {
logFrameStats();
@@ -2380,6 +2378,7 @@
const DisplayDeviceState& state,
const sp<compositionengine::DisplaySurface>& displaySurface,
const sp<IGraphicBufferProducer>& producer) {
+ auto displayId = compositionDisplay->getDisplayId();
DisplayDeviceCreationArgs creationArgs(this, displayToken, compositionDisplay);
creationArgs.sequenceId = state.sequenceId;
creationArgs.isSecure = state.isSecure;
@@ -2391,26 +2390,26 @@
creationArgs.connectionType = physical->type;
}
- if (const auto id = PhysicalDisplayId::tryCast(compositionDisplay->getId())) {
- creationArgs.isPrimary = id == getInternalDisplayIdLocked();
+ const bool isInternalDisplay = displayId && displayId == getInternalDisplayIdLocked();
+ creationArgs.isPrimary = isInternalDisplay;
- if (useColorManagement) {
- std::vector<ColorMode> modes = getHwComposer().getColorModes(*id);
- for (ColorMode colorMode : modes) {
- if (isWideColorMode(colorMode)) {
- creationArgs.hasWideColorGamut = true;
- }
-
- std::vector<RenderIntent> renderIntents =
- getHwComposer().getRenderIntents(*id, colorMode);
- creationArgs.hwcColorModes.emplace(colorMode, renderIntents);
+ if (useColorManagement && displayId) {
+ std::vector<ColorMode> modes = getHwComposer().getColorModes(*displayId);
+ for (ColorMode colorMode : modes) {
+ if (isWideColorMode(colorMode)) {
+ creationArgs.hasWideColorGamut = true;
}
+
+ std::vector<RenderIntent> renderIntents =
+ getHwComposer().getRenderIntents(*displayId, colorMode);
+ creationArgs.hwcColorModes.emplace(colorMode, renderIntents);
}
}
- if (const auto id = HalDisplayId::tryCast(compositionDisplay->getId())) {
- getHwComposer().getHdrCapabilities(*id, &creationArgs.hdrCapabilities);
- creationArgs.supportedPerFrameMetadata = getHwComposer().getSupportedPerFrameMetadata(*id);
+ if (displayId) {
+ getHwComposer().getHdrCapabilities(*displayId, &creationArgs.hdrCapabilities);
+ creationArgs.supportedPerFrameMetadata =
+ getHwComposer().getSupportedPerFrameMetadata(*displayId);
}
auto nativeWindowSurface = getFactory().createNativeWindowSurface(producer);
@@ -2425,7 +2424,7 @@
}
creationArgs.physicalOrientation =
- creationArgs.isPrimary ? internalDisplayOrientation : ui::ROTATION_0;
+ isInternalDisplay ? internalDisplayOrientation : ui::ROTATION_0;
// virtual displays are always considered enabled
creationArgs.initialPowerMode = state.isVirtual() ? hal::PowerMode::ON : hal::PowerMode::OFF;
@@ -2447,8 +2446,8 @@
RenderIntent::COLORIMETRIC,
Dataspace::UNKNOWN});
if (!state.isVirtual()) {
- const auto physicalId = display->getPhysicalId();
- auto activeConfigId = HwcConfigIndexType(getHwComposer().getActiveConfigIndex(physicalId));
+ LOG_ALWAYS_FATAL_IF(!displayId);
+ auto activeConfigId = HwcConfigIndexType(getHwComposer().getActiveConfigIndex(*displayId));
display->setActiveConfig(activeConfigId);
display->setDeviceProductInfo(state.physical->deviceProductInfo);
}
@@ -2498,7 +2497,6 @@
builder.setLayerStackId(state.layerStack);
builder.setPowerAdvisor(&mPowerAdvisor);
builder.setUseHwcVirtualDisplays(mUseHwcVirtualDisplays);
- builder.setGpuVirtualDisplayIdGenerator(mGpuVirtualDisplayIdGenerator);
builder.setName(state.displayName);
const auto compositionDisplay = getCompositionEngine().createDisplay(builder.build());
@@ -2508,13 +2506,11 @@
sp<IGraphicBufferConsumer> bqConsumer;
getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false);
- DisplayId displayId = compositionDisplay->getId();
+ std::optional<DisplayId> displayId = compositionDisplay->getId();
if (state.isVirtual()) {
- const auto virtualId = VirtualDisplayId::tryCast(displayId);
- LOG_FATAL_IF(!virtualId);
sp<VirtualDisplaySurface> vds =
- new VirtualDisplaySurface(getHwComposer(), *virtualId, state.surface, bqProducer,
+ new VirtualDisplaySurface(getHwComposer(), displayId, state.surface, bqProducer,
bqConsumer, state.displayName);
displaySurface = vds;
@@ -2524,9 +2520,9 @@
"adding a supported display, but rendering "
"surface is provided (%p), ignoring it",
state.surface.get());
- const auto physicalId = PhysicalDisplayId::tryCast(displayId);
- LOG_FATAL_IF(!physicalId);
- displaySurface = new FramebufferSurface(getHwComposer(), *physicalId, bqConsumer,
+
+ LOG_ALWAYS_FATAL_IF(!displayId);
+ displaySurface = new FramebufferSurface(getHwComposer(), *displayId, bqConsumer,
maxGraphicsWidth, maxGraphicsHeight);
producer = bqProducer;
}
@@ -2536,7 +2532,8 @@
displaySurface, producer);
mDisplays.emplace(displayToken, display);
if (!state.isVirtual()) {
- dispatchDisplayHotplugEvent(display->getPhysicalId(), true);
+ LOG_FATAL_IF(!displayId);
+ dispatchDisplayHotplugEvent(static_cast<PhysicalDisplayId>(*displayId), true);
}
if (display->isPrimary()) {
@@ -2546,9 +2543,13 @@
void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) {
if (const auto display = getDisplayDeviceLocked(displayToken)) {
+ // Save display ID before disconnecting.
+ const auto displayId = display->getId();
display->disconnect();
+
if (!display->isVirtual()) {
- dispatchDisplayHotplugEvent(display->getPhysicalId(), false);
+ LOG_FATAL_IF(!displayId);
+ dispatchDisplayHotplugEvent(static_cast<PhysicalDisplayId>(*displayId), false);
}
}
@@ -2824,7 +2825,7 @@
void SurfaceFlinger::updateCursorAsync() {
compositionengine::CompositionRefreshArgs refreshArgs;
for (const auto& [_, display] : ON_MAIN_THREAD(mDisplays)) {
- if (HalDisplayId::tryCast(display->getId())) {
+ if (display->getId()) {
refreshArgs.outputs.push_back(display->getCompositionDisplay());
}
}
@@ -4110,8 +4111,10 @@
return;
}
- const auto displayId = display->getPhysicalId();
- ALOGD("Setting power mode %d on display %s", mode, to_string(displayId).c_str());
+ const auto displayId = display->getId();
+ LOG_ALWAYS_FATAL_IF(!displayId);
+
+ ALOGD("Setting power mode %d on display %s", mode, to_string(*displayId).c_str());
const hal::PowerMode currentMode = display->getPowerMode();
if (mode == currentMode) {
@@ -4128,9 +4131,9 @@
if (SurfaceFlinger::setSchedFifo(true) != NO_ERROR) {
ALOGW("Couldn't set SCHED_FIFO on display on: %s\n", strerror(errno));
}
- getHwComposer().setPowerMode(displayId, mode);
+ getHwComposer().setPowerMode(*displayId, mode);
if (display->isPrimary() && mode != hal::PowerMode::DOZE_SUSPEND) {
- getHwComposer().setVsyncEnabled(displayId, mHWCVsyncPendingState);
+ getHwComposer().setVsyncEnabled(*displayId, mHWCVsyncPendingState);
mScheduler->onScreenAcquired(mAppConnectionHandle);
mScheduler->resyncToHardwareVsync(true, vsyncPeriod);
}
@@ -4149,14 +4152,14 @@
}
// Make sure HWVsync is disabled before turning off the display
- getHwComposer().setVsyncEnabled(displayId, hal::Vsync::DISABLE);
+ getHwComposer().setVsyncEnabled(*displayId, hal::Vsync::DISABLE);
- getHwComposer().setPowerMode(displayId, mode);
+ getHwComposer().setPowerMode(*displayId, mode);
mVisibleRegionsDirty = true;
// from this point on, SF will stop drawing on this display
} else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) {
// Update display while dozing
- getHwComposer().setPowerMode(displayId, mode);
+ getHwComposer().setPowerMode(*displayId, mode);
if (display->isPrimary() && currentMode == hal::PowerMode::DOZE_SUSPEND) {
mScheduler->onScreenAcquired(mAppConnectionHandle);
mScheduler->resyncToHardwareVsync(true, vsyncPeriod);
@@ -4167,10 +4170,10 @@
mScheduler->disableHardwareVsync(true);
mScheduler->onScreenReleased(mAppConnectionHandle);
}
- getHwComposer().setPowerMode(displayId, mode);
+ getHwComposer().setPowerMode(*displayId, mode);
} else {
ALOGE("Attempting to set unknown power mode: %d\n", mode);
- getHwComposer().setPowerMode(displayId, mode);
+ getHwComposer().setPowerMode(*displayId, mode);
}
if (display->isPrimary()) {
@@ -4179,7 +4182,7 @@
mScheduler->setDisplayPowerState(mode == hal::PowerMode::ON);
}
- ALOGD("Finished setting power mode %d on display %s", mode, to_string(displayId).c_str());
+ ALOGD("Finished setting power mode %d on display %s", mode, to_string(*displayId).c_str());
}
void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) {
@@ -4438,11 +4441,12 @@
void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const {
for (const auto& [token, display] : mDisplays) {
- const auto displayId = PhysicalDisplayId::tryCast(display->getId());
+ const auto displayId = display->getId();
if (!displayId) {
continue;
}
- const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId);
+ const auto hwcDisplayId =
+ getHwComposer().fromPhysicalDisplayId(static_cast<PhysicalDisplayId>(*displayId));
if (!hwcDisplayId) {
continue;
}
@@ -4495,7 +4499,7 @@
// TODO: print out if wide-color mode is active or not
for (const auto& [token, display] : mDisplays) {
- const auto displayId = PhysicalDisplayId::tryCast(display->getId());
+ const auto displayId = display->getId();
if (!displayId) {
continue;
}
@@ -4709,7 +4713,7 @@
* HWC layer minidump
*/
for (const auto& [token, display] : mDisplays) {
- const auto displayId = HalDisplayId::tryCast(display->getId());
+ const auto displayId = display->getId();
if (!displayId) {
continue;
}
@@ -5228,12 +5232,18 @@
// Inject a hotplug connected event for the primary display. This will deallocate and
// reallocate the display state including framebuffers.
case 1037: {
- std::optional<hal::HWDisplayId> hwcId;
+ const auto token = getInternalDisplayToken();
+
+ sp<DisplayDevice> display;
{
Mutex::Autolock lock(mStateLock);
- hwcId = getHwComposer().getInternalHwcDisplayId();
+ display = getDisplayDeviceLocked(token);
}
+ const auto hwcId =
+ getHwComposer().fromPhysicalDisplayId(PhysicalDisplayId(*display->getId()));
+
onHotplugReceived(getBE().mComposerSequenceId, *hwcId, hal::Connection::CONNECTED);
+
return NO_ERROR;
}
}
@@ -5840,14 +5850,16 @@
// as well. For now, just call directly to setActiveConfigWithConstraints but ideally
// it should go thru setDesiredActiveConfig, similar to primary display.
ALOGV("setAllowedDisplayConfigsInternal for non-primary display");
- const auto displayId = display->getPhysicalId();
+ const auto displayId = display->getId();
+ LOG_ALWAYS_FATAL_IF(!displayId);
hal::VsyncPeriodChangeConstraints constraints;
constraints.desiredTimeNanos = systemTime();
constraints.seamlessRequired = false;
hal::VsyncPeriodChangeTimeline timeline = {0, 0, 0};
- if (getHwComposer().setActiveConfigWithConstraints(displayId, policy->defaultConfig.value(),
+ if (getHwComposer().setActiveConfigWithConstraints(*displayId,
+ policy->defaultConfig.value(),
constraints, &timeline) < 0) {
return BAD_VALUE;
}
@@ -5857,9 +5869,11 @@
display->setActiveConfig(policy->defaultConfig);
const nsecs_t vsyncPeriod = getHwComposer()
- .getConfigs(displayId)[policy->defaultConfig.value()]
+ .getConfigs(*displayId)[policy->defaultConfig.value()]
->getVsyncPeriod();
- mScheduler->onNonPrimaryDisplayConfigChanged(mAppConnectionHandle, displayId,
+ mScheduler->onNonPrimaryDisplayConfigChanged(mAppConnectionHandle,
+ static_cast<PhysicalDisplayId>(
+ *display->getId()),
policy->defaultConfig, vsyncPeriod);
return NO_ERROR;
}
@@ -5891,8 +5905,8 @@
const nsecs_t vsyncPeriod =
mRefreshRateConfigs->getRefreshRateFromConfigId(display->getActiveConfig())
.getVsyncPeriod();
- const auto physicalId = display->getPhysicalId();
- mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, physicalId,
+ mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle,
+ static_cast<PhysicalDisplayId>(*display->getId()),
display->getActiveConfig(), vsyncPeriod);
toggleKernelIdleTimer();
@@ -5983,9 +5997,11 @@
} else if (display->isVirtual()) {
return INVALID_OPERATION;
} else {
- const auto displayId = display->getPhysicalId();
- *outDefaultConfig = getHwComposer().getActiveConfigIndex(displayId);
- auto vsyncPeriod = getHwComposer().getActiveConfig(displayId)->getVsyncPeriod();
+ const auto displayId = display->getId();
+ LOG_FATAL_IF(!displayId);
+
+ *outDefaultConfig = getHwComposer().getActiveConfigIndex(*displayId);
+ auto vsyncPeriod = getHwComposer().getActiveConfig(*displayId)->getVsyncPeriod();
*outPrimaryRefreshRateMin = 1e9f / vsyncPeriod;
*outPrimaryRefreshRateMax = 1e9f / vsyncPeriod;
*outAppRequestRefreshRateMin = 1e9f / vsyncPeriod;