From 9550c0945ee72bdda05972f70255e7a6b5c46c29 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Tue, 9 May 2023 13:58:18 -0400 Subject: Move rotation flags to SF The rotation flags are typically only used for a camera preview, which wants to avoid changing its orientation and flicker during rotation. Prior to this CL, the rotation flags were tied to the primary display, meaning that if the camera preview was on another display, the rotation flags may not be up to date. For example, if the primary display is off, its flags will not be updated on rotation. Ideally, the flags should be based on the display where the preview will be shown, but this is a much larger architectural change, tracked in b/259407931. As a temporary workaround, associate the flags with the active display. Store the flags in SurfaceFlinger, which knows when the active display changes. Update when the active display switches to a different display or when the active display rotates, matching the behavior of mActiveDisplayTransformHint, which seems similar but is different. Store the flags as a static variable so that LayerFE can access it. LayerFE does not have a way to access the actual SurfaceFlinger object, and it should not. Access to the new flags is safe because it is only read or written from the main thread. Bug: 269685949 Bug: 259407931 Test: ActiveDisplayRotationFlagsTest Change-Id: I5532e140a603be222cb3ea1ae563638317c1d745 Merged-In: I5532e140a603be222cb3ea1ae563638317c1d745 --- services/surfaceflinger/SurfaceFlinger.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'services/surfaceflinger/SurfaceFlinger.cpp') diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 06ac8cb5af..799e646cc8 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -356,6 +356,8 @@ bool callingThreadHasPermission(const String16& permission) { PermissionCache::checkPermission(permission, pid, uid); } +ui::Transform::RotationFlags SurfaceFlinger::sActiveDisplayRotationFlags = ui::Transform::ROT_0; + SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) : mFactory(factory), mPid(getpid()), @@ -2619,7 +2621,7 @@ void SurfaceFlinger::composite(TimePoint frameTime, VsyncId vsyncId) refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || mVisibleRegionsDirty; - refreshArgs.internalDisplayRotationFlags = DisplayDevice::getPrimaryDisplayRotationFlags(); + refreshArgs.internalDisplayRotationFlags = getActiveDisplayRotationFlags(); if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) { refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix; @@ -3563,6 +3565,8 @@ void SurfaceFlinger::processDisplayChanged(const wp& displayToken, currentState.orientedDisplaySpaceRect); if (display->getId() == mActiveDisplayId) { mActiveDisplayTransformHint = display->getTransformHint(); + sActiveDisplayRotationFlags = + ui::Transform::toRotationFlags(display->getOrientation()); } } if (currentState.width != drawingState.width || @@ -7954,6 +7958,7 @@ void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveD onActiveDisplaySizeChanged(activeDisplay); mActiveDisplayTransformHint = activeDisplay.getTransformHint(); + sActiveDisplayRotationFlags = ui::Transform::toRotationFlags(activeDisplay.getOrientation()); // The policy of the new active/pacesetter display may have changed while it was inactive. In // that case, its preferred mode has not been propagated to HWC (via setDesiredActiveMode). In -- cgit v1.2.3-59-g8ed1b