SF: Remove *DisplayId::tryCast and DisplayId::isVirtual()
Work towards DisplayId opaqueness by eliminating call-sites to APIs that
parse the display ID values directly.
This CL removes *DisplayId::tryCast from the DislayId interface entirely
and replaces it with SF APIs that check for the existence of the
displays before casting. This removes direct dependency on ID value
bits. It also removes DisplayId::isVirtual().
Flag: com.android.graphics.surfaceflinger.flags.stable_edid_ids
Bug: 390690584
Bug: 390689313
Test: libsurfaceflinger_unittest
Change-Id: I918a6b361784e41165837234b82eed027dc46673
diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h
index b4667c9..7d7c8ad 100644
--- a/services/surfaceflinger/DisplayDevice.h
+++ b/services/surfaceflinger/DisplayDevice.h
@@ -82,7 +82,7 @@
return mCompositionDisplay;
}
- bool isVirtual() const { return getId().isVirtual(); }
+ bool isVirtual() const;
bool isPrimary() const { return mIsPrimary; }
// isSecure indicates whether this display can be trusted to display
@@ -126,17 +126,24 @@
return *idVariant;
}
+ std::optional<VirtualDisplayIdVariant> getVirtualDisplayIdVariant() const {
+ return ftl::match(
+ getDisplayIdVariant(),
+ [](PhysicalDisplayId) { return std::optional<VirtualDisplayIdVariant>(); },
+ [](auto id) { return std::optional<VirtualDisplayIdVariant>(id); });
+ }
+
// Shorthand to upcast the ID of a display whose type is known as a precondition.
PhysicalDisplayId getPhysicalId() const {
- const auto id = PhysicalDisplayId::tryCast(getId());
- LOG_FATAL_IF(!id);
- return *id;
+ const auto physicalDisplayId = asPhysicalDisplayId(getDisplayIdVariant());
+ LOG_FATAL_IF(!physicalDisplayId);
+ return *physicalDisplayId;
}
VirtualDisplayId getVirtualId() const {
- const auto id = VirtualDisplayId::tryCast(getId());
- LOG_FATAL_IF(!id);
- return *id;
+ const auto virtualDisplayId = asVirtualDisplayId(getDisplayIdVariant());
+ LOG_FATAL_IF(!virtualDisplayId);
+ return *virtualDisplayId;
}
const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }