summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/CompositionEngine/src/Display.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/surfaceflinger/CompositionEngine/src/Display.cpp')
-rw-r--r--services/surfaceflinger/CompositionEngine/src/Display.cpp140
1 files changed, 63 insertions, 77 deletions
diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp
index d201104810..2f2c686805 100644
--- a/services/surfaceflinger/CompositionEngine/src/Display.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp
@@ -50,34 +50,21 @@ std::shared_ptr<Display> createDisplay(
Display::~Display() = default;
void Display::setConfiguration(const compositionengine::DisplayCreationArgs& args) {
- mIsVirtual = !args.physical;
- mId = args.physical ? std::make_optional(args.physical->id) : std::nullopt;
+ mId = args.id;
+ mIsVirtual = !args.connectionType;
mPowerAdvisor = args.powerAdvisor;
-
editState().isSecure = args.isSecure;
-
+ editState().displaySpace.bounds = Rect(args.pixels);
setLayerStackFilter(args.layerStackId,
- args.physical ? args.physical->type == DisplayConnectionType::Internal
- : false);
+ args.connectionType == ui::DisplayConnectionType::Internal);
setName(args.name);
-
- if (!args.physical && args.useHwcVirtualDisplays) {
- mId = maybeAllocateDisplayIdForVirtualDisplay(args.pixels, args.pixelFormat);
- }
-}
-
-std::optional<DisplayId> Display::maybeAllocateDisplayIdForVirtualDisplay(
- ui::Size pixels, ui::PixelFormat pixelFormat) const {
- auto& hwc = getCompositionEngine().getHwComposer();
- return hwc.allocateVirtualDisplay(static_cast<uint32_t>(pixels.width),
- static_cast<uint32_t>(pixels.height), &pixelFormat);
}
bool Display::isValid() const {
return Output::isValid() && mPowerAdvisor;
}
-const std::optional<DisplayId>& Display::getId() const {
+DisplayId Display::getId() const {
return mId;
}
@@ -93,31 +80,29 @@ std::optional<DisplayId> Display::getDisplayId() const {
return mId;
}
-void Display::setDisplayIdForTesting(std::optional<DisplayId> displayId) {
- mId = displayId;
-}
-
void Display::disconnect() {
- if (!mId) {
+ if (mIsDisconnected) {
return;
}
- auto& hwc = getCompositionEngine().getHwComposer();
- hwc.disconnectDisplay(*mId);
- mId.reset();
+ mIsDisconnected = true;
+
+ if (const auto id = HalDisplayId::tryCast(mId)) {
+ getCompositionEngine().getHwComposer().disconnectDisplay(*id);
+ }
}
void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
Output::setColorTransform(args);
-
- if (!mId || CC_LIKELY(!args.colorTransformMatrix)) {
+ const auto halDisplayId = HalDisplayId::tryCast(mId);
+ if (mIsDisconnected || !halDisplayId || CC_LIKELY(!args.colorTransformMatrix)) {
return;
}
auto& hwc = getCompositionEngine().getHwComposer();
- status_t result = hwc.setColorTransform(*mId, *args.colorTransformMatrix);
+ status_t result = hwc.setColorTransform(*halDisplayId, *args.colorTransformMatrix);
ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
- mId ? to_string(*mId).c_str() : "", result);
+ to_string(mId).c_str(), result);
}
void Display::setColorProfile(const ColorProfile& colorProfile) {
@@ -139,8 +124,10 @@ void Display::setColorProfile(const ColorProfile& colorProfile) {
Output::setColorProfile(colorProfile);
- auto& hwc = getCompositionEngine().getHwComposer();
- hwc.setActiveColorMode(*mId, colorProfile.mode, colorProfile.renderIntent);
+ const auto physicalId = PhysicalDisplayId::tryCast(mId);
+ LOG_FATAL_IF(!physicalId);
+ getCompositionEngine().getHwComposer().setActiveColorMode(*physicalId, colorProfile.mode,
+ colorProfile.renderIntent);
}
void Display::dump(std::string& out) const {
@@ -149,14 +136,8 @@ void Display::dump(std::string& out) const {
StringAppendF(&out, " Composition Display State: [\"%s\"]", getName().c_str());
out.append("\n ");
-
dumpVal(out, "isVirtual", mIsVirtual);
- if (mId) {
- dumpVal(out, "hwcId", to_string(*mId));
- } else {
- StringAppendF(&out, "no hwcId, ");
- }
-
+ dumpVal(out, "DisplayId", to_string(mId));
out.append("\n");
Output::dumpBase(out);
@@ -177,31 +158,24 @@ void Display::createClientCompositionCache(uint32_t cacheSize) {
std::unique_ptr<compositionengine::OutputLayer> Display::createOutputLayer(
const sp<compositionengine::LayerFE>& layerFE) const {
- auto result = impl::createOutputLayer(*this, layerFE);
+ auto outputLayer = impl::createOutputLayer(*this, layerFE);
- if (result && mId) {
+ if (const auto halDisplayId = HalDisplayId::tryCast(mId);
+ outputLayer && !mIsDisconnected && halDisplayId) {
auto& hwc = getCompositionEngine().getHwComposer();
- auto displayId = *mId;
- // Note: For the moment we ensure it is safe to take a reference to the
- // HWComposer implementation by destroying all the OutputLayers (and
- // hence the HWC2::Layers they own) before setting a new HWComposer. See
- // for example SurfaceFlinger::updateVrFlinger().
- // TODO(b/121291683): Make this safer.
- auto hwcLayer = std::shared_ptr<HWC2::Layer>(hwc.createLayer(displayId),
- [&hwc, displayId](HWC2::Layer* layer) {
- hwc.destroyLayer(displayId, layer);
- });
+ auto hwcLayer = hwc.createLayer(*halDisplayId);
ALOGE_IF(!hwcLayer, "Failed to create a HWC layer for a HWC supported display %s",
getName().c_str());
- result->setHwcLayer(std::move(hwcLayer));
+ outputLayer->setHwcLayer(std::move(hwcLayer));
}
- return result;
+ return outputLayer;
}
void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs& refreshArgs) {
Output::setReleasedLayers(refreshArgs);
- if (!mId || refreshArgs.layersWithQueuedFrames.empty()) {
+ if (mIsDisconnected || GpuVirtualDisplayId::tryCast(mId) ||
+ refreshArgs.layersWithQueuedFrames.empty()) {
return;
}
@@ -237,19 +211,26 @@ void Display::chooseCompositionStrategy() {
ATRACE_CALL();
ALOGV(__FUNCTION__);
+ if (mIsDisconnected) {
+ return;
+ }
+
// Default to the base settings -- client composition only.
Output::chooseCompositionStrategy();
- // If we don't have a HWC display, then we are done
- if (!mId) {
+ // If we don't have a HWC display, then we are done.
+ const auto halDisplayId = HalDisplayId::tryCast(mId);
+ if (!halDisplayId) {
return;
}
// Get any composition changes requested by the HWC device, and apply them.
std::optional<android::HWComposer::DeviceRequestedChanges> changes;
auto& hwc = getCompositionEngine().getHwComposer();
- if (status_t result = hwc.getDeviceCompositionChanges(*mId, anyLayersRequireClientComposition(),
- &changes);
+ if (status_t result =
+ hwc.getDeviceCompositionChanges(*halDisplayId, anyLayersRequireClientComposition(),
+ getState().earliestPresentTime,
+ getState().previousPresentFence, &changes);
result != NO_ERROR) {
ALOGE("chooseCompositionStrategy failed for %s: %d (%s)", getName().c_str(), result,
strerror(-result));
@@ -270,8 +251,12 @@ void Display::chooseCompositionStrategy() {
bool Display::getSkipColorTransform() const {
const auto& hwc = getCompositionEngine().getHwComposer();
- return mId ? hwc.hasDisplayCapability(*mId, hal::DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM)
- : hwc.hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM);
+ if (const auto halDisplayId = HalDisplayId::tryCast(mId)) {
+ return hwc.hasDisplayCapability(*halDisplayId,
+ hal::DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM);
+ }
+
+ return hwc.hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM);
}
bool Display::anyLayersRequireClientComposition() const {
@@ -331,23 +316,25 @@ void Display::applyClientTargetRequests(const ClientTargetProperty& clientTarget
if (clientTargetProperty.dataspace == ui::Dataspace::UNKNOWN) {
return;
}
- auto outputState = editState();
- outputState.dataspace = clientTargetProperty.dataspace;
+
+ editState().dataspace = clientTargetProperty.dataspace;
getRenderSurface()->setBufferDataspace(clientTargetProperty.dataspace);
getRenderSurface()->setBufferPixelFormat(clientTargetProperty.pixelFormat);
}
compositionengine::Output::FrameFences Display::presentAndGetFrameFences() {
- auto result = impl::Output::presentAndGetFrameFences();
+ auto fences = impl::Output::presentAndGetFrameFences();
- if (!mId) {
- return result;
+ const auto halDisplayIdOpt = HalDisplayId::tryCast(mId);
+ if (mIsDisconnected || !halDisplayIdOpt) {
+ return fences;
}
auto& hwc = getCompositionEngine().getHwComposer();
- hwc.presentAndGetReleaseFences(*mId);
+ hwc.presentAndGetReleaseFences(*halDisplayIdOpt, getState().earliestPresentTime,
+ getState().previousPresentFence);
- result.presentFence = hwc.getPresentFence(*mId);
+ fences.presentFence = hwc.getPresentFence(*halDisplayIdOpt);
// TODO(b/121291683): Change HWComposer call to return entire map
for (const auto* layer : getOutputLayersOrderedByZ()) {
@@ -356,19 +343,19 @@ compositionengine::Output::FrameFences Display::presentAndGetFrameFences() {
continue;
}
- result.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*mId, hwcLayer));
+ fences.layerFences.emplace(hwcLayer, hwc.getLayerReleaseFence(*halDisplayIdOpt, hwcLayer));
}
- hwc.clearReleaseFences(*mId);
+ hwc.clearReleaseFences(*halDisplayIdOpt);
- return result;
+ return fences;
}
void Display::setExpensiveRenderingExpected(bool enabled) {
Output::setExpensiveRenderingExpected(enabled);
- if (mPowerAdvisor && mId) {
- mPowerAdvisor->setExpensiveRenderingExpected(*mId, enabled);
+ if (mPowerAdvisor && !GpuVirtualDisplayId::tryCast(mId)) {
+ mPowerAdvisor->setExpensiveRenderingExpected(mId, enabled);
}
}
@@ -377,11 +364,10 @@ void Display::finishFrame(const compositionengine::CompositionRefreshArgs& refre
// 1) It is being handled by hardware composer, which may need this to
// keep its virtual display state machine in sync, or
// 2) There is work to be done (the dirty region isn't empty)
- if (!mId) {
- if (getDirtyRegion(refreshArgs.repaintEverything).isEmpty()) {
- ALOGV("Skipping display composition");
- return;
- }
+ if (GpuVirtualDisplayId::tryCast(mId) &&
+ getDirtyRegion(refreshArgs.repaintEverything).isEmpty()) {
+ ALOGV("Skipping display composition");
+ return;
}
impl::Output::finishFrame(refreshArgs);