From 1c8d84257c3a380750bbb44816793612c6b5322f Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Thu, 6 Jul 2023 11:23:17 -0500 Subject: Fix captureDisplay when the display is rotated Bug: 288824234 Test: manual screenshots with temporary changes to use captureDisplay Test: ScreenCaptureTest Change-Id: I31591d6111303518776308a0dfaa195082a7950a --- services/surfaceflinger/ScreenCaptureOutput.cpp | 26 +++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'services/surfaceflinger/ScreenCaptureOutput.cpp') diff --git a/services/surfaceflinger/ScreenCaptureOutput.cpp b/services/surfaceflinger/ScreenCaptureOutput.cpp index 09dac23410..b3459134cc 100644 --- a/services/surfaceflinger/ScreenCaptureOutput.cpp +++ b/services/surfaceflinger/ScreenCaptureOutput.cpp @@ -24,6 +24,24 @@ namespace android { +namespace { + +ui::Size getDisplaySize(ui::Rotation orientation, const Rect& sourceCrop) { + if (orientation == ui::Rotation::Rotation90 || orientation == ui::Rotation::Rotation270) { + return {sourceCrop.getHeight(), sourceCrop.getWidth()}; + } + return {sourceCrop.getWidth(), sourceCrop.getHeight()}; +} + +Rect getOrientedDisplaySpaceRect(ui::Rotation orientation, int reqWidth, int reqHeight) { + if (orientation == ui::Rotation::Rotation90 || orientation == ui::Rotation::Rotation270) { + return {reqHeight, reqWidth}; + } + return {reqWidth, reqHeight}; +} + +} // namespace + std::shared_ptr createScreenCaptureOutput(ScreenCaptureOutputArgs args) { std::shared_ptr output = compositionengine::impl::createOutputTemplated< ScreenCaptureOutput, compositionengine::CompositionEngine, const RenderArea&, @@ -45,10 +63,10 @@ std::shared_ptr createScreenCaptureOutput(ScreenCaptureOutp const Rect& sourceCrop = args.renderArea.getSourceCrop(); const ui::Rotation orientation = ui::Transform::toRotation(args.renderArea.getRotationFlags()); - const Rect orientedDisplaySpaceRect{args.renderArea.getReqWidth(), - args.renderArea.getReqHeight()}; - output->setProjection(orientation, sourceCrop, orientedDisplaySpaceRect); - output->setDisplaySize({sourceCrop.getWidth(), sourceCrop.getHeight()}); + output->setDisplaySize(getDisplaySize(orientation, sourceCrop)); + output->setProjection(orientation, sourceCrop, + getOrientedDisplaySpaceRect(orientation, args.renderArea.getReqWidth(), + args.renderArea.getReqHeight())); { std::string name = args.regionSampling ? "RegionSampling" : "ScreenCaptureOutput"; -- cgit v1.2.3-59-g8ed1b