From ccf3e8b9f965b7d60e5d0a23ca1396f681ce252d Mon Sep 17 00:00:00 2001 From: chaviw Date: Thu, 25 Mar 2021 15:28:44 -0500 Subject: [PATCH] Updated native SurfaceControl APIs to reflect their behavior. Updated setPosition, setCrop, setBufferTransform, and added setScale to native SurfaceControl API. The new functions should be pass through calls to SurfaceComposerClient that sends it to SurfaceFlinger. Test: ASurfaceControlTest Bug: 170765639 Change-Id: I214c5ae998d8f896200f3010cf2de6754d1e8510 --- native/android/libandroid.map.txt | 5 +++-- native/android/surface_control.cpp | 36 +++++++++++++++++++----------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/native/android/libandroid.map.txt b/native/android/libandroid.map.txt index 4d137e0e1acc..9729524b47b2 100644 --- a/native/android/libandroid.map.txt +++ b/native/android/libandroid.map.txt @@ -260,8 +260,9 @@ LIBANDROID { ASurfaceTransaction_setHdrMetadata_smpte2086; # introduced=29 ASurfaceTransaction_setOnComplete; # introduced=29 ASurfaceTransaction_setPosition; # introduced=31 - ASurfaceTransaction_setSourceRect; # introduced=31 - ASurfaceTransaction_setTransform; # introduced=31 + ASurfaceTransaction_setCrop; # introduced=31 + ASurfaceTransaction_setBufferTransform; # introduced=31 + ASurfaceTransaction_setScale; # introduced=31 ASurfaceTransaction_setVisibility; # introduced=29 ASurfaceTransaction_setZOrder; # introduced=29 ASystemFontIterator_open; # introduced=29 diff --git a/native/android/surface_control.cpp b/native/android/surface_control.cpp index 7433cf970566..3d14c425ed4d 100644 --- a/native/android/surface_control.cpp +++ b/native/android/surface_control.cpp @@ -459,34 +459,31 @@ void ASurfaceTransaction_setGeometry(ASurfaceTransaction* aSurfaceTransaction, transaction->setTransformToDisplayInverse(surfaceControl, transformToInverseDisplay); } -void ASurfaceTransaction_setSourceRect(ASurfaceTransaction* aSurfaceTransaction, - ASurfaceControl* aSurfaceControl, const ARect& source) { +void ASurfaceTransaction_setCrop(ASurfaceTransaction* aSurfaceTransaction, + ASurfaceControl* aSurfaceControl, const ARect& crop) { CHECK_NOT_NULL(aSurfaceTransaction); CHECK_NOT_NULL(aSurfaceControl); - CHECK_VALID_RECT(source); + CHECK_VALID_RECT(crop); sp surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); - transaction->setCrop(surfaceControl, static_cast(source)); + transaction->setCrop(surfaceControl, static_cast(crop)); } -void ASurfaceTransaction_setPosition(ASurfaceTransaction* /* aSurfaceTransaction */, - ASurfaceControl* /* aSurfaceControl */, - const ARect& /* destination */) { - // TODO: Fix this function - /* CHECK_NOT_NULL(aSurfaceTransaction); +void ASurfaceTransaction_setPosition(ASurfaceTransaction* aSurfaceTransaction, + ASurfaceControl* aSurfaceControl, int32_t x, int32_t y) { + CHECK_NOT_NULL(aSurfaceTransaction); CHECK_NOT_NULL(aSurfaceControl); - CHECK_VALID_RECT(destination); sp surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); - transaction->setFrame(surfaceControl, static_cast(destination));*/ + transaction->setPosition(surfaceControl, x, y); } -void ASurfaceTransaction_setTransform(ASurfaceTransaction* aSurfaceTransaction, - ASurfaceControl* aSurfaceControl, int32_t transform) { +void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* aSurfaceTransaction, + ASurfaceControl* aSurfaceControl, int32_t transform) { CHECK_NOT_NULL(aSurfaceTransaction); CHECK_NOT_NULL(aSurfaceControl); @@ -499,6 +496,19 @@ void ASurfaceTransaction_setTransform(ASurfaceTransaction* aSurfaceTransaction, transaction->setTransformToDisplayInverse(surfaceControl, transformToInverseDisplay); } +void ASurfaceTransaction_setScale(ASurfaceTransaction* aSurfaceTransaction, + ASurfaceControl* aSurfaceControl, float xScale, float yScale) { + CHECK_NOT_NULL(aSurfaceTransaction); + CHECK_NOT_NULL(aSurfaceControl); + LOG_ALWAYS_FATAL_IF(xScale < 0, "negative value passed in for xScale"); + LOG_ALWAYS_FATAL_IF(yScale < 0, "negative value passed in for yScale"); + + sp surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl); + Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction); + + transaction->setMatrix(surfaceControl, xScale, 0, 0, yScale); +} + void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* aSurfaceTransaction, ASurfaceControl* aSurfaceControl, int8_t transparency) {