Remove rotation and use flag useIdentityTransform for screenshots.

There's a lot of confusing logic where 90 and 270 rotation values need
to be flipped to ensure the screenshot is taken the correct orientation.
There's also confusion what useIdentityTransform means, especially if a
non 0 rotation value is sent.

The cases screenshot cares about is the following:
1. Take screenshot in current display orientation
2. Take screenshot with 0 rotation so the caller can handle rotating the
screenshot themselves.

With these two cases in mind, remove the rotation value passed in for
screenshots. If useIdentityTransform is true, it will rotate the
screenshot so it's in the 0 orientation. If useIdentityTransform is
false, it will use the current display rotation.

This simplifies the logic in DisplayRenderArea since it only needs to
compute the rotation when useIdentityTransform is set. It also
simplifies the caller logic since they no longer have to find the
current display rotation to ensure the screenshot is taken in the
current rotation. The callers can just request the screenshot with
useIdentityTransform set to false.

Test: adb shell screencap
Test: Power + volume screenshot
Test: Screen rotation
Test: SurfaceFlinger_test
Test: libsurfaceflinger_unittest
Fixes: 135942984
Change-Id: I1da025c7340a11a719d4630da2469b281bddc6e9
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index b215756..9c0ad9d 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -530,23 +530,17 @@
     status |= output.writeStrongBinder(displayToken) ?:
         output.writeUint32(width) ?:
         output.writeUint32(height) ?:
-        output.writeBool(useIdentityTransform) ?:
-        output.writeInt32(static_cast<int32_t>(rotation));
+        output.writeBool(useIdentityTransform);
     return status;
 }
 
 status_t DisplayCaptureArgs::read(const Parcel& input) {
     status_t status = CaptureArgs::read(input);
 
-    int32_t rotationInt = 0;
-
     status |= input.readStrongBinder(&displayToken) ?:
         input.readUint32(&width) ?:
         input.readUint32(&height) ?:
-        input.readBool(&useIdentityTransform) ?:
-        input.readInt32(&rotationInt);
-
-    rotation = ui::toRotation(rotationInt);
+        input.readBool(&useIdentityTransform);
     return status;
 }
 
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index 5e1066b..bbf827f 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -330,7 +330,6 @@
     uint32_t width{0};
     uint32_t height{0};
     bool useIdentityTransform{false};
-    ui::Rotation rotation{ui::ROTATION_0};
 
     status_t write(Parcel& output) const override;
     status_t read(const Parcel& input) override;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h
index 6cc90cb..5c7f12d 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h
@@ -80,10 +80,6 @@
         // The clip region, or visible region that is being rendered to
         const Region& clip;
 
-        // If true, the layer should use an identity transform for its position
-        // transform. Used only by the captureScreen API call.
-        const bool useIdentityTransform;
-
         // If set to true, the layer should enable filtering when rendering.
         const bool needsFiltering;
 
@@ -148,7 +144,6 @@
 static inline bool operator==(const LayerFE::ClientCompositionTargetSettings& lhs,
                               const LayerFE::ClientCompositionTargetSettings& rhs) {
     return lhs.clip.hasSameRects(rhs.clip) &&
-            lhs.useIdentityTransform == rhs.useIdentityTransform &&
             lhs.needsFiltering == rhs.needsFiltering && lhs.isSecure == rhs.isSecure &&
             lhs.supportsProtectedContent == rhs.supportsProtectedContent &&
             lhs.clearRegion.hasSameRects(rhs.clearRegion) && lhs.viewport == rhs.viewport &&
@@ -170,7 +165,6 @@
     *os << "ClientCompositionTargetSettings{";
     *os << "\n    .clip = \n";
     PrintTo(settings.clip, os);
-    *os << "\n    .useIdentityTransform = " << settings.useIdentityTransform;
     *os << "\n    .needsFiltering = " << settings.needsFiltering;
     *os << "\n    .isSecure = " << settings.isSecure;
     *os << "\n    .supportsProtectedContent = " << settings.supportsProtectedContent;
diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp
index 09b3dd7..670b969 100644
--- a/services/surfaceflinger/CompositionEngine/src/Output.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp
@@ -946,7 +946,6 @@
 
     const auto& outputState = getState();
     const Region viewportRegion(outputState.viewport);
-    const bool useIdentityTransform = false;
     bool firstLayer = true;
     // Used when a layer clears part of the buffer.
     Region stubRegion;
@@ -984,7 +983,6 @@
         if (clientComposition || clearClientComposition) {
             compositionengine::LayerFE::ClientCompositionTargetSettings targetSettings{
                     clip,
-                    useIdentityTransform,
                     layer->needsFiltering() || outputState.needsFiltering,
                     outputState.isSecure,
                     supportsProtectedContent,
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
index 6ba06a6..fdaf907 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
@@ -3579,7 +3579,6 @@
 
     compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
             Region(kDisplayFrame),
-            false,      /* identity transform */
             false,      /* needs filtering */
             false,      /* secure */
             false,      /* supports protected content */
@@ -3591,7 +3590,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             false, /* needs filtering */
             false, /* secure */
             false, /* supports protected content */
@@ -3635,7 +3633,6 @@
 
     compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
             Region(Rect(10, 10, 20, 20)),
-            false, /* identity transform */
             false, /* needs filtering */
             false, /* secure */
             false, /* supports protected content */
@@ -3647,7 +3644,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
             Region(Rect(0, 0, 30, 30)),
-            false, /* identity transform */
             false, /* needs filtering */
             false, /* secure */
             false, /* supports protected content */
@@ -3659,7 +3655,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
             Region(Rect(0, 0, 40, 201)),
-            false, /* identity transform */
             false, /* needs filtering */
             false, /* secure */
             false, /* supports protected content */
@@ -3691,7 +3686,6 @@
 
     compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             true,  /* needs filtering */
             false, /* secure */
             false, /* supports protected content */
@@ -3703,7 +3697,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             false, /* needs filtering */
             false, /* secure */
             false, /* supports protected content */
@@ -3715,7 +3708,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             false, /* needs filtering */
             false, /* secure */
             false, /* supports protected content */
@@ -3747,7 +3739,6 @@
 
     compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             true,  /* needs filtering */
             false, /* secure */
             false, /* supports protected content */
@@ -3760,7 +3751,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             true,  /* needs filtering */
             false, /* secure */
             false, /* supports protected content */
@@ -3772,7 +3762,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             true,  /* needs filtering */
             false, /* secure */
             false, /* supports protected content */
@@ -3803,7 +3792,6 @@
 
     compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             false, /* needs filtering */
             true,  /* secure */
             false, /* supports protected content */
@@ -3815,7 +3803,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             false, /* needs filtering */
             true,  /* secure */
             false, /* supports protected content */
@@ -3827,7 +3814,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             false, /* needs filtering */
             true,  /* secure */
             false, /* supports protected content */
@@ -3856,7 +3842,6 @@
 
     compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             false, /* needs filtering */
             false, /* secure */
             true,  /* supports protected content */
@@ -3868,7 +3853,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             false, /* needs filtering */
             false, /* secure */
             true,  /* supports protected content */
@@ -3880,7 +3864,6 @@
     };
     compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
             Region(kDisplayFrame),
-            false, /* identity transform */
             false, /* needs filtering */
             false, /* secure */
             true,  /* supports protected content */
@@ -3972,7 +3955,6 @@
 
     compositionengine::LayerFE::ClientCompositionTargetSettings leftLayerSettings{
             Region(Rect(0, 0, 1000, 1000)),
-            false, /* identity transform */
             false, /* needs filtering */
             true,  /* secure */
             true,  /* supports protected content */
@@ -3990,7 +3972,6 @@
 
     compositionengine::LayerFE::ClientCompositionTargetSettings rightLayerSettings{
             Region(Rect(1000, 0, 2000, 1000)),
-            false, /* identity transform */
             false, /* needs filtering */
             true,  /* secure */
             true,  /* supports protected content */
@@ -4024,7 +4005,6 @@
     Region accumClearRegion(Rect(10, 11, 12, 13));
     compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{
             Region(Rect(60, 40, 70, 80)).merge(Rect(40, 80, 70, 90)), /* visible region */
-            false,                                                    /* identity transform */
             false,                                                    /* needs filtering */
             false,                                                    /* secure */
             false, /* supports protected content */
@@ -4070,7 +4050,6 @@
     Region accumClearRegion(Rect(10, 11, 12, 13));
     compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{
             Region(Rect(50, 40, 70, 80)).merge(Rect(40, 80, 70, 90)), /* visible region */
-            false,                                                    /* identity transform */
             false,                                                    /* needs filtering */
             false,                                                    /* secure */
             false, /* supports protected content */
diff --git a/services/surfaceflinger/DisplayRenderArea.cpp b/services/surfaceflinger/DisplayRenderArea.cpp
index 4bae669..d7157b1 100644
--- a/services/surfaceflinger/DisplayRenderArea.cpp
+++ b/services/surfaceflinger/DisplayRenderArea.cpp
@@ -20,49 +20,14 @@
 namespace android {
 namespace {
 
-RenderArea::RotationFlags applyDeviceOrientation(RenderArea::RotationFlags rotation,
+RenderArea::RotationFlags applyDeviceOrientation(bool useIdentityTransform,
                                                  const DisplayDevice& display) {
-    uint32_t inverseRotate90 = 0;
-    uint32_t inverseReflect = 0;
-
-    // Reverse the logical orientation.
-    ui::Rotation logicalOrientation = display.getOrientation();
-    if (logicalOrientation == ui::Rotation::Rotation90) {
-        logicalOrientation = ui::Rotation::Rotation270;
-    } else if (logicalOrientation == ui::Rotation::Rotation270) {
-        logicalOrientation = ui::Rotation::Rotation90;
+    if (!useIdentityTransform) {
+        return RenderArea::RotationFlags::ROT_0;
     }
 
-    const ui::Rotation orientation = display.getPhysicalOrientation() + logicalOrientation;
-
-    switch (orientation) {
-        case ui::ROTATION_0:
-            return rotation;
-
-        case ui::ROTATION_90:
-            inverseRotate90 = ui::Transform::ROT_90;
-            inverseReflect = ui::Transform::ROT_180;
-            break;
-
-        case ui::ROTATION_180:
-            inverseReflect = ui::Transform::ROT_180;
-            break;
-
-        case ui::ROTATION_270:
-            inverseRotate90 = ui::Transform::ROT_90;
-            break;
-    }
-
-    const uint32_t rotate90 = rotation & ui::Transform::ROT_90;
-    uint32_t reflect = rotation & ui::Transform::ROT_180;
-
-    // Apply reflection for double rotation.
-    if (rotate90 & inverseRotate90) {
-        reflect = ~reflect & ui::Transform::ROT_180;
-    }
-
-    return static_cast<RenderArea::RotationFlags>((rotate90 ^ inverseRotate90) |
-                                                  (reflect ^ inverseReflect));
+    const ui::Rotation orientation = display.getPhysicalOrientation() + display.getOrientation();
+    return ui::Transform::toRotationFlags(orientation);
 }
 
 } // namespace
@@ -70,22 +35,22 @@
 std::unique_ptr<RenderArea> DisplayRenderArea::create(wp<const DisplayDevice> displayWeak,
                                                       const Rect& sourceCrop, ui::Size reqSize,
                                                       ui::Dataspace reqDataSpace,
-                                                      RotationFlags rotation,
+                                                      bool useIdentityTransform,
                                                       bool allowSecureLayers) {
     if (auto display = displayWeak.promote()) {
         // Using new to access a private constructor.
         return std::unique_ptr<DisplayRenderArea>(
                 new DisplayRenderArea(std::move(display), sourceCrop, reqSize, reqDataSpace,
-                                      rotation, allowSecureLayers));
+                                      useIdentityTransform, allowSecureLayers));
     }
     return nullptr;
 }
 
 DisplayRenderArea::DisplayRenderArea(sp<const DisplayDevice> display, const Rect& sourceCrop,
                                      ui::Size reqSize, ui::Dataspace reqDataSpace,
-                                     RotationFlags rotation, bool allowSecureLayers)
+                                     bool useIdentityTransform, bool allowSecureLayers)
       : RenderArea(reqSize, CaptureFill::OPAQUE, reqDataSpace, display->getViewport(),
-                   allowSecureLayers, applyDeviceOrientation(rotation, *display)),
+                   allowSecureLayers, applyDeviceOrientation(useIdentityTransform, *display)),
         mDisplay(std::move(display)),
         mSourceCrop(sourceCrop) {}
 
@@ -131,18 +96,11 @@
         return mDisplay->getViewport();
     }
 
-    // If there is a source crop provided then it is assumed that the device
-    // was in portrait orientation. This may not logically be true, so
-    // correct for the orientation error by undoing the rotation
-
-    ui::Rotation logicalOrientation = mDisplay->getOrientation();
-    if (logicalOrientation == ui::Rotation::Rotation90) {
-        logicalOrientation = ui::Rotation::Rotation270;
-    } else if (logicalOrientation == ui::Rotation::Rotation270) {
-        logicalOrientation = ui::Rotation::Rotation90;
-    }
-
-    const auto flags = ui::Transform::toRotationFlags(logicalOrientation);
+    // Correct for the orientation when the screen capture request contained
+    // useIdentityTransform. This will cause the rotation flag to be non 0 since
+    // it needs to rotate based on the screen orientation to allow the screenshot
+    // to be taken in the ROT_0 orientation
+    const auto flags = getRotationFlags();
     int width = mDisplay->getViewport().getWidth();
     int height = mDisplay->getViewport().getHeight();
     ui::Transform rotation;
diff --git a/services/surfaceflinger/DisplayRenderArea.h b/services/surfaceflinger/DisplayRenderArea.h
index 8840973..3478fc1 100644
--- a/services/surfaceflinger/DisplayRenderArea.h
+++ b/services/surfaceflinger/DisplayRenderArea.h
@@ -29,7 +29,7 @@
 public:
     static std::unique_ptr<RenderArea> create(wp<const DisplayDevice>, const Rect& sourceCrop,
                                               ui::Size reqSize, ui::Dataspace,
-                                              RotationFlags rotation,
+                                              bool useIdentityTransform,
                                               bool allowSecureLayers = true);
 
     const ui::Transform& getTransform() const override;
@@ -43,7 +43,7 @@
 
 private:
     DisplayRenderArea(sp<const DisplayDevice>, const Rect& sourceCrop, ui::Size reqSize,
-                      ui::Dataspace, RotationFlags rotation, bool allowSecureLayers = true);
+                      ui::Dataspace, bool useIdentityTransform, bool allowSecureLayers = true);
 
     const sp<const DisplayDevice> mDisplay;
     const Rect mSourceCrop;
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 89c95d2..001eab7 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -611,7 +611,7 @@
 // ---------------------------------------------------------------------------
 
 std::optional<compositionengine::LayerFE::LayerSettings> Layer::prepareClientComposition(
-        compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) {
+        compositionengine::LayerFE::ClientCompositionTargetSettings& /* targetSettings */) {
     if (!getCompositionState()) {
         return {};
     }
@@ -621,11 +621,7 @@
 
     compositionengine::LayerFE::LayerSettings layerSettings;
     layerSettings.geometry.boundaries = bounds;
-    if (targetSettings.useIdentityTransform) {
-        layerSettings.geometry.positionTransform = mat4();
-    } else {
-        layerSettings.geometry.positionTransform = getTransform().asMatrix4();
-    }
+    layerSettings.geometry.positionTransform = getTransform().asMatrix4();
 
     if (hasColorTransform()) {
         layerSettings.colorTransform = getColorTransform();
diff --git a/services/surfaceflinger/RegionSamplingThread.cpp b/services/surfaceflinger/RegionSamplingThread.cpp
index 17daadb..255a1f2 100644
--- a/services/surfaceflinger/RegionSamplingThread.cpp
+++ b/services/surfaceflinger/RegionSamplingThread.cpp
@@ -444,8 +444,7 @@
 
     ScreenCaptureResults captureResults;
     mFlinger.captureScreenCommon(std::move(renderAreaFuture), traverseLayers, buffer,
-                                 false /* identityTransform */, true /* regionSampling */,
-                                 captureResults);
+                                 true /* regionSampling */, captureResults);
 
     std::vector<Descriptor> activeDescriptors;
     for (const auto& descriptor : descriptors) {
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 9d9a4cf..9ff57df 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -5440,12 +5440,6 @@
 
     if (!args.displayToken) return BAD_VALUE;
 
-    auto renderAreaRotation = ui::Transform::toRotationFlags(args.rotation);
-    if (renderAreaRotation == ui::Transform::ROT_INVALID) {
-        ALOGE("%s: Invalid rotation: %s", __FUNCTION__, toCString(args.rotation));
-        renderAreaRotation = ui::Transform::ROT_0;
-    }
-
     wp<DisplayDevice> displayWeak;
     ui::LayerStack layerStack;
     ui::Size reqSize(args.width, args.height);
@@ -5469,14 +5463,14 @@
 
     RenderAreaFuture renderAreaFuture = promise::defer([=] {
         return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, dataspace,
-                                         renderAreaRotation, args.captureSecureLayers);
+                                         args.useIdentityTransform, args.captureSecureLayers);
     });
 
     auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) {
         traverseLayersInLayerStack(layerStack, visitor);
     };
     return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, reqSize,
-                               args.pixelFormat, args.useIdentityTransform, captureResults);
+                               args.pixelFormat, captureResults);
 }
 
 status_t SurfaceFlinger::setSchedFifo(bool enabled) {
@@ -5523,7 +5517,6 @@
     ui::LayerStack layerStack;
     wp<DisplayDevice> displayWeak;
     ui::Size size;
-    ui::Transform::RotationFlags captureOrientation;
     ui::Dataspace dataspace;
     {
         Mutex::Autolock lock(mStateLock);
@@ -5536,33 +5529,14 @@
 
         size = display->getViewport().getSize();
 
-        const auto orientation = display->getOrientation();
-        captureOrientation = ui::Transform::toRotationFlags(orientation);
-
-        switch (captureOrientation) {
-            case ui::Transform::ROT_90:
-                captureOrientation = ui::Transform::ROT_270;
-                break;
-
-            case ui::Transform::ROT_270:
-                captureOrientation = ui::Transform::ROT_90;
-                break;
-
-            case ui::Transform::ROT_INVALID:
-                ALOGE("%s: Invalid orientation: %s", __FUNCTION__, toCString(orientation));
-                captureOrientation = ui::Transform::ROT_0;
-                break;
-
-            default:
-                break;
-        }
         dataspace =
                 pickDataspaceFromColorMode(display->getCompositionDisplay()->getState().colorMode);
     }
 
     RenderAreaFuture renderAreaFuture = promise::defer([=] {
         return DisplayRenderArea::create(displayWeak, Rect(), size,
-                                         captureResults.capturedDataspace, captureOrientation,
+                                         captureResults.capturedDataspace,
+                                         false /* useIdentityTransform */,
                                          false /* captureSecureLayers */);
     });
 
@@ -5571,8 +5545,7 @@
     };
 
     return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, size,
-                               ui::PixelFormat::RGBA_8888, false /* useIdentityTransform */,
-                               captureResults);
+                               ui::PixelFormat::RGBA_8888, captureResults);
 }
 
 status_t SurfaceFlinger::captureLayers(const LayerCaptureArgs& args,
@@ -5681,13 +5654,12 @@
     };
 
     return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, reqSize,
-                               args.pixelFormat, false, captureResults);
+                               args.pixelFormat, captureResults);
 }
 
 status_t SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture,
                                              TraverseLayersFunction traverseLayers,
                                              ui::Size bufferSize, ui::PixelFormat reqPixelFormat,
-                                             bool useIdentityTransform,
                                              ScreenCaptureResults& captureResults) {
     ATRACE_CALL();
 
@@ -5700,13 +5672,12 @@
                                              1 /* layerCount */, usage, "screenshot");
 
     return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, buffer,
-                               useIdentityTransform, false /* regionSampling */, captureResults);
+                               false /* regionSampling */, captureResults);
 }
 
 status_t SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture,
                                              TraverseLayersFunction traverseLayers,
-                                             const sp<GraphicBuffer>& buffer,
-                                             bool useIdentityTransform, bool regionSampling,
+                                             const sp<GraphicBuffer>& buffer, bool regionSampling,
                                              ScreenCaptureResults& captureResults) {
     const int uid = IPCThreadState::self()->getCallingUid();
     const bool forSystem = uid == AID_GRAPHICS || uid == AID_SYSTEM;
@@ -5733,8 +5704,8 @@
                     Mutex::Autolock lock(mStateLock);
                     renderArea->render([&] {
                         result = renderScreenImplLocked(*renderArea, traverseLayers, buffer.get(),
-                                                        useIdentityTransform, forSystem, &fd,
-                                                        regionSampling, captureResults);
+                                                        forSystem, &fd, regionSampling,
+                                                        captureResults);
                     });
 
                     return {result, fd};
@@ -5751,8 +5722,7 @@
 
 status_t SurfaceFlinger::renderScreenImplLocked(const RenderArea& renderArea,
                                                 TraverseLayersFunction traverseLayers,
-                                                const sp<GraphicBuffer>& buffer,
-                                                bool useIdentityTransform, bool forSystem,
+                                                const sp<GraphicBuffer>& buffer, bool forSystem,
                                                 int* outSyncFd, bool regionSampling,
                                                 ScreenCaptureResults& captureResults) {
     ATRACE_CALL();
@@ -5810,7 +5780,6 @@
         Region clip(renderArea.getBounds());
         compositionengine::LayerFE::ClientCompositionTargetSettings targetSettings{
                 clip,
-                useIdentityTransform,
                 layer->needsFilteringForScreenshots(display.get(), transform) ||
                         renderArea.needsFiltering(),
                 renderArea.isSecure(),
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 6c00931..2e85c1b 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -719,15 +719,12 @@
 
     status_t renderScreenImplLocked(const RenderArea& renderArea,
                                     TraverseLayersFunction traverseLayers,
-                                    const sp<GraphicBuffer>& buffer, bool useIdentityTransform,
-                                    bool forSystem, int* outSyncFd, bool regionSampling,
-                                    ScreenCaptureResults& captureResults);
+                                    const sp<GraphicBuffer>& buffer, bool forSystem, int* outSyncFd,
+                                    bool regionSampling, ScreenCaptureResults& captureResults);
     status_t captureScreenCommon(RenderAreaFuture, TraverseLayersFunction, ui::Size bufferSize,
-                                 ui::PixelFormat, bool useIdentityTransform,
-                                 ScreenCaptureResults& captureResults);
+                                 ui::PixelFormat, ScreenCaptureResults& captureResults);
     status_t captureScreenCommon(RenderAreaFuture, TraverseLayersFunction, const sp<GraphicBuffer>&,
-                                 bool useIdentityTransform, bool regionSampling,
-                                 ScreenCaptureResults& captureResults);
+                                 bool regionSampling, ScreenCaptureResults& captureResults);
     sp<DisplayDevice> getDisplayByIdOrLayerStack(uint64_t displayOrLayerStack) REQUIRES(mStateLock);
     sp<DisplayDevice> getDisplayByLayerStack(uint64_t layerStack) REQUIRES(mStateLock);
 
diff --git a/services/surfaceflinger/tests/LayerState_test.cpp b/services/surfaceflinger/tests/LayerState_test.cpp
index 8a49e77..785c2c3 100644
--- a/services/surfaceflinger/tests/LayerState_test.cpp
+++ b/services/surfaceflinger/tests/LayerState_test.cpp
@@ -34,7 +34,6 @@
     args.width = 10;
     args.height = 20;
     args.useIdentityTransform = true;
-    args.rotation = ui::ROTATION_90;
 
     Parcel p;
     args.write(p);
@@ -51,7 +50,6 @@
     ASSERT_EQ(args.width, args2.width);
     ASSERT_EQ(args.height, args2.height);
     ASSERT_EQ(args.useIdentityTransform, args2.useIdentityTransform);
-    ASSERT_EQ(args.rotation, args2.rotation);
 }
 
 TEST(LayerStateTest, ParcellingLayerCaptureArgs) {
diff --git a/services/surfaceflinger/tests/unittests/CompositionTest.cpp b/services/surfaceflinger/tests/unittests/CompositionTest.cpp
index 48c4e18..6472428 100644
--- a/services/surfaceflinger/tests/unittests/CompositionTest.cpp
+++ b/services/surfaceflinger/tests/unittests/CompositionTest.cpp
@@ -233,7 +233,6 @@
     LayerCase::setupForScreenCapture(this);
 
     const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
-    constexpr bool useIdentityTransform = true;
     constexpr bool forSystem = true;
     constexpr bool regionSampling = false;
 
@@ -253,7 +252,7 @@
     int fd = -1;
     status_t result =
             mFlinger.renderScreenImplLocked(*renderArea, traverseLayers, mCaptureScreenBuffer.get(),
-                                            useIdentityTransform, forSystem, &fd, regionSampling);
+                                            forSystem, &fd, regionSampling);
     if (fd >= 0) {
         close(fd);
     }
diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
index 3941d42..345577d 100644
--- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
+++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
@@ -335,12 +335,11 @@
 
     auto renderScreenImplLocked(const RenderArea& renderArea,
                                 SurfaceFlinger::TraverseLayersFunction traverseLayers,
-                                const sp<GraphicBuffer>& buffer, bool useIdentityTransform,
-                                bool forSystem, int* outSyncFd, bool regionSampling) {
+                                const sp<GraphicBuffer>& buffer, bool forSystem, int* outSyncFd,
+                                bool regionSampling) {
         ScreenCaptureResults captureResults;
-        return mFlinger->renderScreenImplLocked(renderArea, traverseLayers, buffer,
-                                                useIdentityTransform, forSystem, outSyncFd,
-                                                regionSampling, captureResults);
+        return mFlinger->renderScreenImplLocked(renderArea, traverseLayers, buffer, forSystem,
+                                                outSyncFd, regionSampling, captureResults);
     }
 
     auto traverseLayersInLayerStack(ui::LayerStack layerStack,