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
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 1db2ab6..57a0d50 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -332,6 +332,14 @@
     const DisplayDevice* getDisplayFromLayerStack(ui::LayerStack)
             REQUIRES(mStateLock, kMainThreadContext);
 
+    // TODO (b/259407931): Remove.
+    // TODO (b/281857977): This should be annotated with REQUIRES(kMainThreadContext), but this
+    // would require thread safety annotations throughout the frontend (in particular Layer and
+    // LayerFE).
+    static ui::Transform::RotationFlags getActiveDisplayRotationFlags() {
+        return sActiveDisplayRotationFlags;
+    }
+
 protected:
     // We're reference counted, never destroy SurfaceFlinger directly
     virtual ~SurfaceFlinger();
@@ -1364,6 +1372,10 @@
 
     std::atomic<ui::Transform::RotationFlags> mActiveDisplayTransformHint;
 
+    // Must only be accessed on the main thread.
+    // TODO (b/259407931): Remove.
+    static ui::Transform::RotationFlags sActiveDisplayRotationFlags;
+
     bool isRefreshRateOverlayEnabled() const REQUIRES(mStateLock) {
         return hasDisplay(
                 [](const auto& display) { return display.isRefreshRateOverlayEnabled(); });