SurfaceFlinger Transactions as distinct objects.
Essentially a process global singleton for transactions is not so useful once
we make surface control public API as process isn't something an app developer
is really thinking about. It's also nice that we get to delete two of the plumbing layers.
Test: Boots
Change-Id: I8864bd7e2f5865e3c0a425cf82f9928211911774
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 921492b..47924ae 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -33,8 +33,7 @@
#include <ui/Region.h>
#include <gui/ISurfaceComposerClient.h>
-
-#include <private/gui/LayerState.h>
+#include <gui/LayerState.h>
#include <list>
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index e87d35f..32e4067 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -43,14 +43,14 @@
#include <gui/FrameTimestamps.h>
#include <gui/ISurfaceComposer.h>
#include <gui/ISurfaceComposerClient.h>
+#include <gui/LayerState.h>
+
#include <gui/OccupancyTracker.h>
#include <hardware/hwcomposer_defs.h>
#include <system/graphics.h>
-#include <private/gui/LayerState.h>
-
#include "Barrier.h"
#include "DisplayDevice.h"
#include "DispSync.h"
diff --git a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
index 0cc763c..ed806b8 100644
--- a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
+++ b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
@@ -22,10 +22,11 @@
#include <android/native_window.h>
#include <gui/ISurfaceComposer.h>
+#include <gui/LayerState.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
+
#include <private/gui/ComposerService.h>
-#include <private/gui/LayerState.h>
#include <ui/DisplayInfo.h>
#include <fstream>
@@ -34,6 +35,8 @@
namespace android {
+using Transaction = SurfaceComposerClient::Transaction;
+
constexpr int32_t SCALING_UPDATE = 1;
constexpr uint32_t BUFFER_UPDATES = 18;
constexpr uint32_t LAYER_UPDATE = INT_MAX - 2;
@@ -149,11 +152,11 @@
ASSERT_TRUE(mBGSurfaceControl->isValid());
mBGLayerId = getSurfaceId("BG Interceptor Test Surface");
- SurfaceComposerClient::openGlobalTransaction();
- mComposerClient->setDisplayLayerStack(display, 0);
- ASSERT_EQ(NO_ERROR, mBGSurfaceControl->setLayer(INT_MAX-3));
- ASSERT_EQ(NO_ERROR, mBGSurfaceControl->show());
- SurfaceComposerClient::closeGlobalTransaction(true);
+ Transaction t;
+ t.setDisplayLayerStack(display, 0);
+ ASSERT_EQ(NO_ERROR, t.setLayer(mBGSurfaceControl, INT_MAX-3)
+ .show(mBGSurfaceControl)
+ .apply());
}
virtual void TearDown() {
@@ -169,13 +172,14 @@
int32_t mTargetId;
public:
- void captureTest(void (SurfaceInterceptorTest::* action)(void),
+ void captureTest(void (SurfaceInterceptorTest::* action)(Transaction&),
bool (SurfaceInterceptorTest::* verification)(Trace *));
- void captureTest(void (SurfaceInterceptorTest::* action)(void),
+ void captureTest(void (SurfaceInterceptorTest::* action)(Transaction&),
SurfaceChange::SurfaceChangeCase changeCase);
- void captureTest(void (SurfaceInterceptorTest::* action)(void),
+ void captureTest(void (SurfaceInterceptorTest::* action)(Transaction&),
Increment::IncrementCase incrementCase);
- void runInTransaction(void (SurfaceInterceptorTest::* action)(void), bool intercepted = false);
+ void runInTransaction(void (SurfaceInterceptorTest::* action)(Transaction&),
+ bool intercepted = false);
// Verification of changes to a surface
bool positionUpdateFound(const SurfaceChange& change, bool foundPosition);
@@ -206,28 +210,29 @@
bool bufferUpdatesFound(Trace* trace);
// Perform each of the possible changes to a surface
- void positionUpdate();
- void sizeUpdate();
- void alphaUpdate();
- void layerUpdate();
- void cropUpdate();
- void finalCropUpdate();
- void matrixUpdate();
- void overrideScalingModeUpdate();
- void transparentRegionHintUpdate();
- void layerStackUpdate();
- void hiddenFlagUpdate();
- void opaqueFlagUpdate();
- void secureFlagUpdate();
- void deferredTransactionUpdate();
- void runAllUpdates();
- void surfaceCreation();
+ void positionUpdate(Transaction&);
+ void sizeUpdate(Transaction&);
+ void alphaUpdate(Transaction&);
+ void layerUpdate(Transaction&);
+ void cropUpdate(Transaction&);
+ void finalCropUpdate(Transaction&);
+ void matrixUpdate(Transaction&);
+ void overrideScalingModeUpdate(Transaction&);
+ void transparentRegionHintUpdate(Transaction&);
+ void layerStackUpdate(Transaction&);
+ void hiddenFlagUpdate(Transaction&);
+ void opaqueFlagUpdate(Transaction&);
+ void secureFlagUpdate(Transaction&);
+ void deferredTransactionUpdate(Transaction&);
+ void surfaceCreation(Transaction&);
+ void displayCreation(Transaction&);
+ void displayDeletion(Transaction&);
+
void nBufferUpdates();
- void displayCreation();
- void displayDeletion();
+ void runAllUpdates();
};
-void SurfaceInterceptorTest::captureTest(void (SurfaceInterceptorTest::* action)(void),
+void SurfaceInterceptorTest::captureTest(void (SurfaceInterceptorTest::* action)(Transaction&),
bool (SurfaceInterceptorTest::* verification)(Trace *))
{
runInTransaction(action, true);
@@ -236,7 +241,7 @@
ASSERT_TRUE((this->*verification)(&capturedTrace));
}
-void SurfaceInterceptorTest::captureTest(void (SurfaceInterceptorTest::* action)(void),
+void SurfaceInterceptorTest::captureTest(void (SurfaceInterceptorTest::* action)(Transaction&),
Increment::IncrementCase incrementCase)
{
runInTransaction(action, true);
@@ -245,7 +250,7 @@
ASSERT_TRUE(singleIncrementFound(&capturedTrace, incrementCase));
}
-void SurfaceInterceptorTest::captureTest(void (SurfaceInterceptorTest::* action)(void),
+void SurfaceInterceptorTest::captureTest(void (SurfaceInterceptorTest::* action)(Transaction&),
SurfaceChange::SurfaceChangeCase changeCase)
{
runInTransaction(action, true);
@@ -254,83 +259,84 @@
ASSERT_TRUE(surfaceUpdateFound(&capturedTrace, changeCase));
}
-void SurfaceInterceptorTest::runInTransaction(void (SurfaceInterceptorTest::* action)(void),
+void SurfaceInterceptorTest::runInTransaction(void (SurfaceInterceptorTest::* action)(Transaction&),
bool intercepted)
{
if (intercepted) {
enableInterceptor();
}
- SurfaceComposerClient::openGlobalTransaction();
- (this->*action)();
- SurfaceComposerClient::closeGlobalTransaction(true);
+ Transaction t;
+ (this->*action)(t);
+ t.apply(true);
+
if (intercepted) {
disableInterceptor();
}
}
-void SurfaceInterceptorTest::positionUpdate() {
- mBGSurfaceControl->setPosition(POSITION_UPDATE, POSITION_UPDATE);
+void SurfaceInterceptorTest::positionUpdate(Transaction& t) {
+ t.setPosition(mBGSurfaceControl, POSITION_UPDATE, POSITION_UPDATE);
}
-void SurfaceInterceptorTest::sizeUpdate() {
- mBGSurfaceControl->setSize(SIZE_UPDATE, SIZE_UPDATE);
+void SurfaceInterceptorTest::sizeUpdate(Transaction& t) {
+ t.setSize(mBGSurfaceControl, SIZE_UPDATE, SIZE_UPDATE);
}
-void SurfaceInterceptorTest::alphaUpdate() {
- mBGSurfaceControl->setAlpha(ALPHA_UPDATE);
+void SurfaceInterceptorTest::alphaUpdate(Transaction& t) {
+ t.setAlpha(mBGSurfaceControl, ALPHA_UPDATE);
}
-void SurfaceInterceptorTest::layerUpdate() {
- mBGSurfaceControl->setLayer(LAYER_UPDATE);
+void SurfaceInterceptorTest::layerUpdate(Transaction& t) {
+ t.setLayer(mBGSurfaceControl, LAYER_UPDATE);
}
-void SurfaceInterceptorTest::cropUpdate() {
- mBGSurfaceControl->setCrop(CROP_UPDATE);
+void SurfaceInterceptorTest::cropUpdate(Transaction& t) {
+ t.setCrop(mBGSurfaceControl, CROP_UPDATE);
}
-void SurfaceInterceptorTest::finalCropUpdate() {
- mBGSurfaceControl->setFinalCrop(CROP_UPDATE);
+void SurfaceInterceptorTest::finalCropUpdate(Transaction& t) {
+ t.setFinalCrop(mBGSurfaceControl, CROP_UPDATE);
}
-void SurfaceInterceptorTest::matrixUpdate() {
- mBGSurfaceControl->setMatrix(M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2, M_SQRT1_2);
+void SurfaceInterceptorTest::matrixUpdate(Transaction& t) {
+ t.setMatrix(mBGSurfaceControl, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2, M_SQRT1_2);
}
-void SurfaceInterceptorTest::overrideScalingModeUpdate() {
- mBGSurfaceControl->setOverrideScalingMode(SCALING_UPDATE);
+void SurfaceInterceptorTest::overrideScalingModeUpdate(Transaction& t) {
+ t.setOverrideScalingMode(mBGSurfaceControl, SCALING_UPDATE);
}
-void SurfaceInterceptorTest::transparentRegionHintUpdate() {
+void SurfaceInterceptorTest::transparentRegionHintUpdate(Transaction& t) {
Region region(CROP_UPDATE);
- mBGSurfaceControl->setTransparentRegionHint(region);
+ t.setTransparentRegionHint(mBGSurfaceControl, region);
}
-void SurfaceInterceptorTest::layerStackUpdate() {
- mBGSurfaceControl->setLayerStack(STACK_UPDATE);
+void SurfaceInterceptorTest::layerStackUpdate(Transaction& t) {
+ t.setLayerStack(mBGSurfaceControl, STACK_UPDATE);
}
-void SurfaceInterceptorTest::hiddenFlagUpdate() {
- mBGSurfaceControl->setFlags(layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
+void SurfaceInterceptorTest::hiddenFlagUpdate(Transaction& t) {
+ t.setFlags(mBGSurfaceControl, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
}
-void SurfaceInterceptorTest::opaqueFlagUpdate() {
- mBGSurfaceControl->setFlags(layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque);
+void SurfaceInterceptorTest::opaqueFlagUpdate(Transaction& t) {
+ t.setFlags(mBGSurfaceControl, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque);
}
-void SurfaceInterceptorTest::secureFlagUpdate() {
- mBGSurfaceControl->setFlags(layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
+void SurfaceInterceptorTest::secureFlagUpdate(Transaction& t) {
+ t.setFlags(mBGSurfaceControl, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
}
-void SurfaceInterceptorTest::deferredTransactionUpdate() {
- mBGSurfaceControl->deferTransactionUntil(mBGSurfaceControl->getHandle(), DEFERRED_UPDATE);
+void SurfaceInterceptorTest::deferredTransactionUpdate(Transaction& t) {
+ t.deferTransactionUntil(mBGSurfaceControl, mBGSurfaceControl->getHandle(), DEFERRED_UPDATE);
}
-void SurfaceInterceptorTest::displayCreation() {
+void SurfaceInterceptorTest::displayCreation(Transaction&) {
sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, true);
SurfaceComposerClient::destroyDisplay(testDisplay);
}
-void SurfaceInterceptorTest::displayDeletion() {
+void SurfaceInterceptorTest::displayDeletion(Transaction&) {
sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, false);
mTargetId = getDisplayId(DISPLAY_NAME.string());
SurfaceComposerClient::destroyDisplay(testDisplay);
@@ -353,7 +359,7 @@
runInTransaction(&SurfaceInterceptorTest::deferredTransactionUpdate);
}
-void SurfaceInterceptorTest::surfaceCreation() {
+void SurfaceInterceptorTest::surfaceCreation(Transaction&) {
mComposerClient->createSurface(String8(LAYER_NAME), SIZE_UPDATE, SIZE_UPDATE,
PIXEL_FORMAT_RGBA_8888, 0);
}
@@ -825,8 +831,10 @@
}
TEST_F(SurfaceInterceptorTest, InterceptBufferUpdateWorks) {
- captureTest(&SurfaceInterceptorTest::nBufferUpdates,
- &SurfaceInterceptorTest::bufferUpdatesFound);
+ nBufferUpdates();
+ Trace capturedTrace;
+ ASSERT_EQ(NO_ERROR, readProtoFile(&capturedTrace));
+ ASSERT_TRUE(bufferUpdatesFound(&capturedTrace));
}
// If the interceptor is enabled while buffer updates are being pushed, the interceptor should
diff --git a/services/surfaceflinger/tests/Transaction_test.cpp b/services/surfaceflinger/tests/Transaction_test.cpp
index d285785..f61a978 100644
--- a/services/surfaceflinger/tests/Transaction_test.cpp
+++ b/services/surfaceflinger/tests/Transaction_test.cpp
@@ -19,10 +19,11 @@
#include <android/native_window.h>
#include <gui/ISurfaceComposer.h>
+#include <gui/LayerState.h>
+
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <private/gui/ComposerService.h>
-#include <private/gui/LayerState.h>
#include <utils/String8.h>
#include <ui/DisplayInfo.h>
@@ -30,8 +31,12 @@
#include <math.h>
#include <math/vec3.h>
+#include <functional>
+
namespace android {
+using Transaction = SurfaceComposerClient::Transaction;
+
// Fill an RGBA_8888 formatted surface with a single color.
static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc,
uint8_t r, uint8_t g, uint8_t b, bool unlock=true) {
@@ -66,8 +71,8 @@
sp<ISurfaceComposer> sf(ComposerService::getComposerService());
sp<IBinder> display(sf->getBuiltInDisplay(
ISurfaceComposer::eDisplayIdMain));
- SurfaceComposerClient::openGlobalTransaction();
- SurfaceComposerClient::closeGlobalTransaction(true);
+ SurfaceComposerClient::Transaction().apply(true);
+
ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(), 0, 0,
0, INT_MAX, false));
*sc = new ScreenCapture(cpuConsumer);
@@ -149,23 +154,21 @@
fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
- SurfaceComposerClient::openGlobalTransaction();
+ asTransaction([&](Transaction& t) {
+ t.setDisplayLayerStack(display, 0);
- mComposerClient->setDisplayLayerStack(display, 0);
+ t.setLayer(mBGSurfaceControl, INT32_MAX-2)
+ .show(mBGSurfaceControl);
- ASSERT_EQ(NO_ERROR, mBGSurfaceControl->setLayer(INT32_MAX-2));
- ASSERT_EQ(NO_ERROR, mBGSurfaceControl->show());
+ t.setLayer(mFGSurfaceControl, INT32_MAX-1)
+ .setPosition(mFGSurfaceControl, 64, 64)
+ .show(mFGSurfaceControl);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT32_MAX-1));
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(64, 64));
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show());
-
- ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setLayer(INT32_MAX-1));
- ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setPosition(displayWidth-2,
- displayHeight-2));
- ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->show());
-
- SurfaceComposerClient::closeGlobalTransaction(true);
+ t.setLayer(mSyncSurfaceControl, INT32_MAX-1)
+ .setPosition(mSyncSurfaceControl, displayWidth-2,
+ displayHeight-2)
+ .show(mSyncSurfaceControl);
+ });
}
virtual void TearDown() {
@@ -186,6 +189,12 @@
fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
}
+ void asTransaction(const std::function<void(Transaction&)>& exec) {
+ Transaction t;
+ exec(t);
+ t.apply(true);
+ }
+
sp<SurfaceComposerClient> mComposerClient;
sp<SurfaceControl> mBGSurfaceControl;
sp<SurfaceControl> mFGSurfaceControl;
@@ -205,9 +214,10 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128, 128));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setPosition(mFGSurfaceControl, 128, 128);
+ });
+
{
// This should reflect the new position, but not the new color.
SCOPED_TRACE("after move, before redraw");
@@ -240,9 +250,9 @@
}
ALOGD("resizing");
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setSize(128, 128));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 128, 128);
+ });
ALOGD("resized");
{
// This should not reflect the new size or color because SurfaceFlinger
@@ -278,10 +288,10 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- Rect cropRect(16, 16, 32, 32);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setCrop(cropRect));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ Rect cropRect(16, 16, 32, 32);
+ t.setCrop(mFGSurfaceControl, cropRect);
+ });
{
// This should crop the foreground surface.
SCOPED_TRACE("after crop");
@@ -303,10 +313,10 @@
sc->expectFGColor(75, 75);
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- Rect cropRect(16, 16, 32, 32);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFinalCrop(cropRect));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ Rect cropRect(16, 16, 32, 32);
+ t.setFinalCrop(mFGSurfaceControl, cropRect);
+ });
{
// This should crop the foreground surface.
SCOPED_TRACE("after crop");
@@ -329,9 +339,10 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX - 3));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setLayer(mFGSurfaceControl, INT_MAX - 3);
+ });
+
{
// This should hide the foreground surface beneath the background.
SCOPED_TRACE("after setLayer");
@@ -352,9 +363,10 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->hide());
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.hide(mFGSurfaceControl);
+ });
+
{
// This should hide the foreground surface.
SCOPED_TRACE("after hide, before show");
@@ -364,9 +376,10 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show());
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mFGSurfaceControl);
+ });
+
{
// This should show the foreground surface.
SCOPED_TRACE("after show");
@@ -387,9 +400,10 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75f));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setAlpha(mFGSurfaceControl, 0.75f);
+ });
+
{
// This should set foreground to be 75% opaque.
SCOPED_TRACE("after setAlpha");
@@ -410,9 +424,9 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayerStack(1));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setLayerStack(mFGSurfaceControl, 1);
+ });
{
// This should hide the foreground surface since it goes to a different
// layer stack.
@@ -434,10 +448,10 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFlags(
- layer_state_t::eLayerHidden, layer_state_t::eLayerHidden));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setFlags(mFGSurfaceControl,
+ layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
+ });
{
// This should hide the foreground surface
SCOPED_TRACE("after setFlags");
@@ -459,10 +473,11 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setMatrix(M_SQRT1_2, M_SQRT1_2,
- -M_SQRT1_2, M_SQRT1_2));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setMatrix(mFGSurfaceControl,
+ M_SQRT1_2, M_SQRT1_2,
+ -M_SQRT1_2, M_SQRT1_2);
+ });
{
SCOPED_TRACE("after setMatrix");
ScreenCapture::captureScreen(&sc);
@@ -498,12 +513,12 @@
waitForPostedBuffers();
}
void restoreInitialState() {
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setSize(64, 64);
- mFGSurfaceControl->setPosition(64, 64);
- mFGSurfaceControl->setCrop(Rect(0, 0, 64, 64));
- mFGSurfaceControl->setFinalCrop(Rect(0, 0, -1, -1));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 64, 64);
+ t.setPosition(mFGSurfaceControl, 64, 64);
+ t.setCrop(mFGSurfaceControl, Rect(0, 0, 64, 64));
+ t.setFinalCrop(mFGSurfaceControl, Rect(0, 0, -1, -1));
+ });
EXPECT_INITIAL_STATE("After restoring initial state");
}
@@ -515,10 +530,10 @@
// By default position can be updated even while
// a resize is pending.
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setSize(32, 32);
- mFGSurfaceControl->setPosition(100, 100);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 32, 32);
+ t.setPosition(mFGSurfaceControl, 100, 100);
+ });
{
SCOPED_TRACE("After moving surface");
@@ -532,11 +547,11 @@
// Now we repeat with setGeometryAppliesWithResize
// and verify the position DOESN'T latch.
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setGeometryAppliesWithResize();
- mFGSurfaceControl->setSize(32, 32);
- mFGSurfaceControl->setPosition(100, 100);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setGeometryAppliesWithResize(mFGSurfaceControl);
+ t.setSize(mFGSurfaceControl, 32, 32);
+ t.setPosition(mFGSurfaceControl, 100, 100);
+ });
{
SCOPED_TRACE("While resize is pending");
@@ -581,20 +596,20 @@
TEST_F(CropLatchingTest, CropLatching) {
EXPECT_INITIAL_STATE("before anything");
// Normally the crop applies immediately even while a resize is pending.
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setCrop(Rect(0, 0, 63, 63));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 128, 128);
+ t.setCrop(mFGSurfaceControl, Rect(0, 0, 63, 63));
+ });
EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)");
restoreInitialState();
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setGeometryAppliesWithResize();
- mFGSurfaceControl->setCrop(Rect(0, 0, 63, 63));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 128, 128);
+ t.setGeometryAppliesWithResize(mFGSurfaceControl);
+ t.setCrop(mFGSurfaceControl, Rect(0, 0, 63, 63));
+ });
EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)");
@@ -606,20 +621,20 @@
TEST_F(CropLatchingTest, FinalCropLatching) {
EXPECT_INITIAL_STATE("before anything");
// Normally the crop applies immediately even while a resize is pending.
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 128, 128);
+ t.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
+ });
EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)");
restoreInitialState();
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setGeometryAppliesWithResize();
- mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 128, 128);
+ t.setGeometryAppliesWithResize(mFGSurfaceControl);
+ t.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
+ });
EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)");
@@ -633,10 +648,10 @@
TEST_F(CropLatchingTest, FinalCropLatchingBufferOldSize) {
EXPECT_INITIAL_STATE("before anything");
// Normally the crop applies immediately even while a resize is pending.
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 128, 128);
+ t.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
+ });
EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)");
@@ -646,11 +661,11 @@
// initiating the resize.
lockAndFillFGBuffer();
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setGeometryAppliesWithResize();
- mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 128, 128);
+ t.setGeometryAppliesWithResize(mFGSurfaceControl);
+ t.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
+ });
EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)");
@@ -670,17 +685,17 @@
// In this scenario, we attempt to set the final crop a second time while the resize
// is still pending, and ensure we are successful. Success meaning the second crop
// is the one which eventually latches and not the first.
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setGeometryAppliesWithResize();
- mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 128, 128);
+ t.setGeometryAppliesWithResize(mFGSurfaceControl);
+ t.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
+ });
EXPECT_INITIAL_STATE("after setting crops with geometryAppliesWithResize");
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setFinalCrop(Rect(0, 0, -1, -1));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setFinalCrop(mFGSurfaceControl, Rect(0, 0, -1, -1));
+ });
EXPECT_INITIAL_STATE("after setting another crop");
@@ -700,17 +715,17 @@
}
// set up two deferred transactions on different frames
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75));
- mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(),
- mSyncSurfaceControl->getSurface()->getNextFrameNumber());
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setAlpha(mFGSurfaceControl, 0.75);
+ t.deferTransactionUntil(mFGSurfaceControl, mSyncSurfaceControl->getHandle(),
+ mSyncSurfaceControl->getSurface()->getNextFrameNumber());
+ });
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128,128));
- mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(),
- mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setPosition(mFGSurfaceControl, 128,128);
+ t.deferTransactionUntil(mFGSurfaceControl, mSyncSurfaceControl->getHandle(),
+ mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1);
+ });
{
SCOPED_TRACE("before any trigger");
@@ -731,9 +746,9 @@
}
// should show up immediately since it's not deferred
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(1.0));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setAlpha(mFGSurfaceControl, 1.0);
+ });
// trigger the second deferred transaction
fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
@@ -762,12 +777,11 @@
waitForPostedBuffers();
// Now we stack the surface above the foreground surface and make sure it is visible.
- SurfaceComposerClient::openGlobalTransaction();
- relativeSurfaceControl->setPosition(64, 64);
- relativeSurfaceControl->show();
- relativeSurfaceControl->setRelativeLayer(mFGSurfaceControl->getHandle(), 1);
- SurfaceComposerClient::closeGlobalTransaction(true);
-
+ asTransaction([&](Transaction& t) {
+ t.setPosition(relativeSurfaceControl, 64, 64);
+ t.show(relativeSurfaceControl);
+ t.setRelativeLayer(relativeSurfaceControl, mFGSurfaceControl->getHandle(), 1);
+ });
{
SCOPED_TRACE("after adding relative surface");
@@ -777,9 +791,9 @@
}
// A call to setLayer will override a call to setRelativeLayer
- SurfaceComposerClient::openGlobalTransaction();
- relativeSurfaceControl->setLayer(0);
- SurfaceComposerClient::closeGlobalTransaction();
+ asTransaction([&](Transaction& t) {
+ t.setLayer(relativeSurfaceControl, 0);
+ });
{
SCOPED_TRACE("after set layer");
@@ -801,11 +815,10 @@
PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get());
fillSurfaceRGBA8(childBuffer, 200, 200, 200);
- SurfaceComposerClient::openGlobalTransaction();
- childNoBuffer->show();
- childBuffer->show();
- SurfaceComposerClient::closeGlobalTransaction();
-
+ SurfaceComposerClient::Transaction{}
+ .show(childNoBuffer)
+ .show(childBuffer)
+ .apply(true);
{
ScreenCapture::captureScreen(&sc);
@@ -813,9 +826,9 @@
sc->expectFGColor(74, 74);
}
- SurfaceComposerClient::openGlobalTransaction();
- childNoBuffer->setSize(20, 20);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ SurfaceComposerClient::Transaction{}
+ .setSize(childNoBuffer, 20, 20)
+ .apply(true);
{
ScreenCapture::captureScreen(&sc);
@@ -850,11 +863,11 @@
};
TEST_F(ChildLayerTest, ChildLayerPositioning) {
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mChild->setPosition(10, 10);
- mFGSurfaceControl->setPosition(64, 64);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mChild, 10, 10);
+ t.setPosition(mFGSurfaceControl, 64, 64);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -866,9 +879,9 @@
mCapture->expectFGColor(84, 84);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(0, 0));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setPosition(mFGSurfaceControl, 0, 0);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -882,12 +895,12 @@
}
TEST_F(ChildLayerTest, ChildLayerCropping) {
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mChild->setPosition(0, 0);
- mFGSurfaceControl->setPosition(0, 0);
- mFGSurfaceControl->setCrop(Rect(0, 0, 5, 5));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mChild, 0, 0);
+ t.setPosition(mFGSurfaceControl, 0, 0);
+ t.setCrop(mFGSurfaceControl, Rect(0, 0, 5, 5));
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -898,12 +911,12 @@
}
TEST_F(ChildLayerTest, ChildLayerFinalCropping) {
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mChild->setPosition(0, 0);
- mFGSurfaceControl->setPosition(0, 0);
- mFGSurfaceControl->setFinalCrop(Rect(0, 0, 5, 5));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mChild, 0, 0);
+ t.setPosition(mFGSurfaceControl, 0, 0);
+ t.setFinalCrop(mFGSurfaceControl, Rect(0, 0, 5, 5));
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -914,11 +927,11 @@
}
TEST_F(ChildLayerTest, ChildLayerConstraints) {
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mFGSurfaceControl->setPosition(0, 0);
- mChild->setPosition(63, 63);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mFGSurfaceControl, 0, 0);
+ t.setPosition(mChild, 63, 63);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -932,9 +945,9 @@
}
TEST_F(ChildLayerTest, ChildLayerScaling) {
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setPosition(0, 0);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setPosition(mFGSurfaceControl, 0, 0);
+ });
// Find the boundary between the parent and child
{
@@ -943,9 +956,9 @@
mCapture->expectFGColor(10, 10);
}
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setMatrix(2.0, 0, 0, 2.0);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0);
+ });
// The boundary should be twice as far from the origin now.
// The pixels from the last test should all be child now
@@ -964,11 +977,11 @@
fillSurfaceRGBA8(mChild, 0, 254, 0);
waitForPostedBuffers();
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mChild->setPosition(0, 0);
- mFGSurfaceControl->setPosition(0, 0);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mChild, 0, 0);
+ t.setPosition(mFGSurfaceControl, 0, 0);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -976,9 +989,9 @@
mCapture->checkPixel(0, 0, 0, 254, 0);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mChild->setAlpha(0.5));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setAlpha(mChild, 0.5);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -986,9 +999,9 @@
mCapture->checkPixel(0, 0, 127, 127, 0);
}
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.5));
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setAlpha(mFGSurfaceControl, 0.5);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -998,11 +1011,11 @@
}
TEST_F(ChildLayerTest, ReparentChildren) {
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mChild->setPosition(10, 10);
- mFGSurfaceControl->setPosition(64, 64);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mChild, 10, 10);
+ t.setPosition(mFGSurfaceControl, 64, 64);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1013,7 +1026,11 @@
// And 10 more pixels we should be back to the foreground surface
mCapture->expectFGColor(84, 84);
}
- mFGSurfaceControl->reparentChildren(mBGSurfaceControl->getHandle());
+
+ asTransaction([&](Transaction& t) {
+ t.reparentChildren(mFGSurfaceControl, mBGSurfaceControl->getHandle());
+ });
+
{
ScreenCapture::captureScreen(&mCapture);
mCapture->expectFGColor(64, 64);
@@ -1027,11 +1044,11 @@
}
TEST_F(ChildLayerTest, DetachChildrenSameClient) {
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mChild->setPosition(10, 10);
- mFGSurfaceControl->setPosition(64, 64);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mChild, 10, 10);
+ t.setPosition(mFGSurfaceControl, 64, 64);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1043,13 +1060,13 @@
mCapture->expectFGColor(84, 84);
}
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->detachChildren();
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.detachChildren(mFGSurfaceControl);
+ });
- SurfaceComposerClient::openGlobalTransaction();
- mChild->hide();
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.hide(mChild);
+ });
// Since the child has the same client as the parent, it will not get
// detached and will be hidden.
@@ -1072,12 +1089,12 @@
fillSurfaceRGBA8(mChildNewClient, 200, 200, 200);
- SurfaceComposerClient::openGlobalTransaction();
- mChild->hide();
- mChildNewClient->show();
- mChildNewClient->setPosition(10, 10);
- mFGSurfaceControl->setPosition(64, 64);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.hide(mChild);
+ t.show(mChildNewClient);
+ t.setPosition(mChildNewClient, 10, 10);
+ t.setPosition(mFGSurfaceControl, 64, 64);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1089,13 +1106,13 @@
mCapture->expectFGColor(84, 84);
}
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->detachChildren();
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.detachChildren(mFGSurfaceControl);
+ });
- SurfaceComposerClient::openGlobalTransaction();
- mChildNewClient->hide();
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.hide(mChildNewClient);
+ });
// Nothing should have changed.
{
@@ -1107,11 +1124,11 @@
}
TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) {
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mChild->setPosition(0, 0);
- mFGSurfaceControl->setPosition(0, 0);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mChild, 0, 0);
+ t.setPosition(mFGSurfaceControl, 0, 0);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1121,11 +1138,11 @@
mCapture->expectFGColor(10, 10);
}
- SurfaceComposerClient::openGlobalTransaction();
- mFGSurfaceControl->setOverrideScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
- // We cause scaling by 2.
- mFGSurfaceControl->setSize(128, 128);
- SurfaceComposerClient::closeGlobalTransaction();
+ asTransaction([&](Transaction& t) {
+ t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
+ // We cause scaling by 2.
+ t.setSize(mFGSurfaceControl, 128, 128);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1140,11 +1157,11 @@
// Regression test for b/37673612
TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) {
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mChild->setPosition(0, 0);
- mFGSurfaceControl->setPosition(0, 0);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mChild, 0, 0);
+ t.setPosition(mFGSurfaceControl, 0, 0);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1153,11 +1170,11 @@
// But it's only 10x10.
mCapture->expectFGColor(10, 10);
}
-
-
// We set things up as in b/37673612 so that there is a mismatch between the buffer size and
// the WM specified state size.
- mFGSurfaceControl->setSize(128, 64);
+ asTransaction([&](Transaction& t) {
+ t.setSize(mFGSurfaceControl, 128, 64);
+ });
sp<Surface> s = mFGSurfaceControl->getSurface();
auto anw = static_cast<ANativeWindow*>(s.get());
native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90);
@@ -1184,11 +1201,11 @@
mFGSurfaceControl.get());
// Show the child layer in a deferred transaction
- SurfaceComposerClient::openGlobalTransaction();
- mChild->deferTransactionUntil(mFGSurfaceControl->getHandle(),
- mFGSurfaceControl->getSurface()->getNextFrameNumber());
- mChild->show();
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.deferTransactionUntil(mChild, mFGSurfaceControl->getHandle(),
+ mFGSurfaceControl->getSurface()->getNextFrameNumber());
+ t.show(mChild);
+ });
// Render the foreground surface a few times
//
@@ -1206,11 +1223,11 @@
}
TEST_F(ChildLayerTest, Reparent) {
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mChild->setPosition(10, 10);
- mFGSurfaceControl->setPosition(64, 64);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mChild, 10, 10);
+ t.setPosition(mFGSurfaceControl, 64, 64);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1221,7 +1238,11 @@
// And 10 more pixels we should be back to the foreground surface
mCapture->expectFGColor(84, 84);
}
- mChild->reparent(mBGSurfaceControl->getHandle());
+
+ asTransaction([&](Transaction& t) {
+ t.reparent(mChild, mBGSurfaceControl->getHandle());
+ });
+
{
ScreenCapture::captureScreen(&mCapture);
mCapture->expectFGColor(64, 64);
@@ -1235,11 +1256,11 @@
}
TEST_F(ChildLayerTest, ReparentToNoParent) {
- SurfaceComposerClient::openGlobalTransaction();
- mChild->show();
- mChild->setPosition(10, 10);
- mFGSurfaceControl->setPosition(64, 64);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mChild);
+ t.setPosition(mChild, 10, 10);
+ t.setPosition(mFGSurfaceControl, 64, 64);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1250,7 +1271,9 @@
// And 10 more pixels we should be back to the foreground surface
mCapture->expectFGColor(84, 84);
}
- mChild->reparent(nullptr);
+ asTransaction([&](Transaction& t) {
+ t.reparent(mChild, nullptr);
+ });
{
ScreenCapture::captureScreen(&mCapture);
// Nothing should have changed.
@@ -1267,13 +1290,13 @@
ASSERT_TRUE(newSurface->isValid());
fillSurfaceRGBA8(newSurface, 63, 195, 63);
- SurfaceComposerClient::openGlobalTransaction();
- mChild->hide();
- newSurface->show();
- newSurface->setPosition(10, 10);
- newSurface->setLayer(INT32_MAX-2);
- mFGSurfaceControl->setPosition(64, 64);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.hide(mChild);
+ t.show(newSurface);
+ t.setPosition(newSurface, 10, 10);
+ t.setLayer(newSurface, INT32_MAX-2);
+ t.setPosition(mFGSurfaceControl, 64, 64);
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1283,9 +1306,9 @@
mCapture->checkPixel(10, 10, 63, 195, 63);
}
- SurfaceComposerClient::openGlobalTransaction();
- newSurface->reparent(mFGSurfaceControl->getHandle());
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.reparent(newSurface, mFGSurfaceControl->getHandle());
+ });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1325,12 +1348,12 @@
ASSERT_TRUE(mLayerColorControl != NULL);
ASSERT_TRUE(mLayerColorControl->isValid());
- SurfaceComposerClient::openGlobalTransaction();
- ASSERT_EQ(NO_ERROR, mLayerColorControl->setLayer(INT32_MAX-1));
- ASSERT_EQ(NO_ERROR, mLayerColorControl->setPosition(140, 140));
- ASSERT_EQ(NO_ERROR, mLayerColorControl->hide());
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->hide());
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.setLayer(mLayerColorControl, INT32_MAX-1);
+ t.setPosition(mLayerColorControl, 140, 140);
+ t.hide(mLayerColorControl);
+ t.hide(mFGSurfaceControl);
+ });
}
void TearDown() override {
@@ -1350,15 +1373,16 @@
sc->expectBGColor(145, 145);
}
+ asTransaction([&](Transaction& t) {
+ half3 color(43.0f/255.0f, 207.0f/255.0f, 131.0f/255.0f);
+ t.setColor(mLayerColorControl, color);
+ t.show(mLayerColorControl);
+ });
- SurfaceComposerClient::openGlobalTransaction();
- half3 color(43.0f/255.0f, 207.0f/255.0f, 131.0f/255.0f);
- mLayerColorControl->setColor(color);
- mLayerColorControl->show();
- SurfaceComposerClient::closeGlobalTransaction(true);
{
// There should now be a color
SCOPED_TRACE("after setColor");
+
ScreenCapture::captureScreen(&sc);
sc->checkPixel(145, 145, 43, 207, 131);
}
@@ -1372,12 +1396,13 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- half3 color(43.0f/255.0f, 207.0f/255.0f, 131.0f/255.0f);
- mLayerColorControl->setColor(color);
- mLayerColorControl->setAlpha(.75f);
- mLayerColorControl->show();
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ half3 color(43.0f/255.0f, 207.0f/255.0f, 131.0f/255.0f);
+ t.setColor(mLayerColorControl, color);
+ t.setAlpha(mLayerColorControl, .75f);
+ t.show(mLayerColorControl);
+ });
+
{
// There should now be a color with .75 alpha
SCOPED_TRACE("after setColor");
@@ -1394,9 +1419,10 @@
sc->expectBGColor(145, 145);
}
- SurfaceComposerClient::openGlobalTransaction();
- mLayerColorControl->show();
- SurfaceComposerClient::closeGlobalTransaction(true);
+ asTransaction([&](Transaction& t) {
+ t.show(mLayerColorControl);
+ });
+
{
// There should now be set to 0,0,0 (black) as default.
SCOPED_TRACE("after setColor");
diff --git a/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.h b/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.h
index 74dc0e5..1258a97 100644
--- a/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.h
+++ b/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.h
@@ -87,7 +87,7 @@
/*
* All surface state changes are supposed to happen inside a global
- * transaction. GlobalTransactionScope object at the beginning of
+ * transaction. TransactionScope object at the beginning of
* scope automates the process. The resulting scope gives a visual cue
* on the span of the transaction as well.
*
@@ -96,23 +96,26 @@
* is built to explicitly request vsyncs one at the time. A delayed
* request must be made before closing the transaction or the test
* thread stalls until SurfaceFlinger does an emergency vsync by
- * itself. GlobalTransactionScope encapsulates this vsync magic.
+ * itself. TransactionScope encapsulates this vsync magic.
*/
-class GlobalTransactionScope {
+class TransactionScope : public android::SurfaceComposerClient::Transaction {
public:
- GlobalTransactionScope(FakeComposerClient& composer) : mComposer(composer) {
- android::SurfaceComposerClient::openGlobalTransaction();
+ TransactionScope(FakeComposerClient& composer) :
+ Transaction(),
+ mComposer(composer) {
}
- ~GlobalTransactionScope() {
+
+ ~TransactionScope() {
int frameCount = mComposer.getFrameCount();
mComposer.runVSyncAfter(1ms);
- android::SurfaceComposerClient::closeGlobalTransaction(true);
+ LOG_ALWAYS_FATAL_IF(android::NO_ERROR != apply());
// Make sure that exactly one frame has been rendered.
mComposer.waitUntilFrame(frameCount + 1);
LOG_ALWAYS_FATAL_IF(frameCount + 1 != mComposer.getFrameCount(),
"Unexpected frame advance. Delta: %d",
mComposer.getFrameCount() - frameCount);
}
+
FakeComposerClient& mComposer;
};
diff --git a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp
index 9ac3331..7f4c58a 100644
--- a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp
+++ b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp
@@ -24,11 +24,11 @@
#include <gui/ISurfaceComposer.h>
#include <gui/LayerDebugInfo.h>
+#include <gui/LayerState.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <private/gui/ComposerService.h>
-#include <private/gui/LayerState.h>
#include <ui/DisplayInfo.h>
@@ -62,6 +62,8 @@
using ::testing::SetArgPointee;
using ::testing::_;
+using Transaction = SurfaceComposerClient::Transaction;
+
///////////////////////////////////////////////
struct TestColor {
@@ -248,11 +250,11 @@
fillSurfaceRGBA8(surfaceControl, BLUE);
{
- GlobalTransactionScope gts(*mMockComposer);
- mComposerClient->setDisplayLayerStack(display, 0);
+ TransactionScope ts(*mMockComposer);
+ ts.setDisplayLayerStack(display, 0);
- ASSERT_EQ(NO_ERROR, surfaceControl->setLayer(INT32_MAX - 2));
- ASSERT_EQ(NO_ERROR, surfaceControl->show());
+ ts.setLayer(surfaceControl, INT32_MAX - 2)
+ .show(surfaceControl);
}
}
@@ -278,11 +280,11 @@
fillSurfaceRGBA8(surfaceControl, BLUE);
{
- GlobalTransactionScope gts(*mMockComposer);
- mComposerClient->setDisplayLayerStack(display, 0);
+ TransactionScope ts(*mMockComposer);
+ ts.setDisplayLayerStack(display, 0);
- ASSERT_EQ(NO_ERROR, surfaceControl->setLayer(INT32_MAX - 2));
- ASSERT_EQ(NO_ERROR, surfaceControl->show());
+ ts.setLayer(surfaceControl, INT32_MAX - 2)
+ .show(surfaceControl);
}
}
mMockComposer->hotplugDisplay(EXTERNAL_DISPLAY, IComposerCallback::Connection::DISCONNECTED);
@@ -370,25 +372,24 @@
fillSurfaceRGBA8(mFGSurfaceControl, RED);
- SurfaceComposerClient::openGlobalTransaction();
+ Transaction t;
+ t.setDisplayLayerStack(display, 0);
- mComposerClient->setDisplayLayerStack(display, 0);
+ t.setLayer(mBGSurfaceControl, INT32_MAX - 2);
+ t.show(mBGSurfaceControl);
- ASSERT_EQ(NO_ERROR, mBGSurfaceControl->setLayer(INT32_MAX - 2));
- ASSERT_EQ(NO_ERROR, mBGSurfaceControl->show());
-
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT32_MAX - 1));
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(64, 64));
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show());
+ t.setLayer(mFGSurfaceControl, INT32_MAX - 1);
+ t.setPosition(mFGSurfaceControl, 64, 64);
+ t.show(mFGSurfaceControl);
// Synchronous transaction will stop this thread, so we set up a
// delayed, off-thread vsync request before closing the
// transaction. In the test code this is usually done with
- // GlobalTransactionScope. Leaving here in the 'vanilla' form for
+ // TransactionScope. Leaving here in the 'vanilla' form for
// reference.
ASSERT_EQ(0, sFakeComposer->getFrameCount());
sFakeComposer->runVSyncAfter(1ms);
- SurfaceComposerClient::closeGlobalTransaction(true);
+ t.apply();
sFakeComposer->waitUntilFrame(1);
// Reference data. This is what the HWC should see.
@@ -445,8 +446,8 @@
// should be available in the latest frame stored by the fake
// composer.
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128, 128));
+ TransactionScope ts(*sFakeComposer);
+ ts.setPosition(mFGSurfaceControl, 128, 128);
// NOTE: No changes yet, so vsync will do nothing, HWC does not get any calls.
// (How to verify that? Throw in vsync and wait a 2x frame time? Separate test?)
//
@@ -473,8 +474,8 @@
TEST_F(TransactionTest, LayerResize) {
ALOGD("TransactionTest::LayerResize");
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setSize(128, 128));
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 128, 128);
}
fillSurfaceRGBA8(mFGSurfaceControl, GREEN);
@@ -497,9 +498,9 @@
TEST_F(TransactionTest, LayerCrop) {
// TODO: Add scaling to confirm that crop happens in buffer space?
{
- GlobalTransactionScope gts(*sFakeComposer);
+ TransactionScope ts(*sFakeComposer);
Rect cropRect(16, 16, 32, 32);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setCrop(cropRect));
+ ts.setCrop(mFGSurfaceControl, cropRect);
}
ASSERT_EQ(2, sFakeComposer->getFrameCount());
@@ -512,9 +513,9 @@
TEST_F(TransactionTest, LayerFinalCrop) {
// TODO: Add scaling to confirm that crop happens in display space?
{
- GlobalTransactionScope gts(*sFakeComposer);
+ TransactionScope ts(*sFakeComposer);
Rect cropRect(32, 32, 32 + 64, 32 + 64);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFinalCrop(cropRect));
+ ts.setFinalCrop(mFGSurfaceControl, cropRect);
}
ASSERT_EQ(2, sFakeComposer->getFrameCount());
@@ -530,9 +531,9 @@
TEST_F(TransactionTest, LayerFinalCropEmpty) {
// TODO: Add scaling to confirm that crop happens in display space?
{
- GlobalTransactionScope gts(*sFakeComposer);
+ TransactionScope ts(*sFakeComposer);
Rect cropRect(16, 16, 32, 32);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFinalCrop(cropRect));
+ ts.setFinalCrop(mFGSurfaceControl, cropRect);
}
ASSERT_EQ(2, sFakeComposer->getFrameCount());
@@ -545,8 +546,8 @@
TEST_F(TransactionTest, LayerSetLayer) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX - 3));
+ TransactionScope ts(*sFakeComposer);
+ ts.setLayer(mFGSurfaceControl, INT_MAX - 3);
}
ASSERT_EQ(2, sFakeComposer->getFrameCount());
@@ -560,11 +561,10 @@
TEST_F(TransactionTest, LayerSetLayerOpaque) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX - 3));
- ASSERT_EQ(NO_ERROR,
- mBGSurfaceControl->setFlags(layer_state_t::eLayerOpaque,
- layer_state_t::eLayerOpaque));
+ TransactionScope ts(*sFakeComposer);
+ ts.setLayer(mFGSurfaceControl, INT_MAX - 3);
+ ts.setFlags(mBGSurfaceControl, layer_state_t::eLayerOpaque,
+ layer_state_t::eLayerOpaque);
}
ASSERT_EQ(2, sFakeComposer->getFrameCount());
@@ -577,8 +577,8 @@
TEST_F(TransactionTest, SetLayerStack) {
ALOGD("TransactionTest::SetLayerStack");
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayerStack(1));
+ TransactionScope ts(*sFakeComposer);
+ ts.setLayerStack(mFGSurfaceControl, 1);
}
// Foreground layer should have disappeared.
@@ -591,8 +591,8 @@
TEST_F(TransactionTest, LayerShowHide) {
ALOGD("TransactionTest::LayerShowHide");
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->hide());
+ TransactionScope ts(*sFakeComposer);
+ ts.hide(mFGSurfaceControl);
}
// Foreground layer should have disappeared.
@@ -602,8 +602,8 @@
EXPECT_TRUE(framesAreSame(refFrame, sFakeComposer->getLatestFrame()));
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show());
+ TransactionScope ts(*sFakeComposer);
+ ts.show(mFGSurfaceControl);
}
// Foreground layer should be back
@@ -613,8 +613,8 @@
TEST_F(TransactionTest, LayerSetAlpha) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75f));
+ TransactionScope ts(*sFakeComposer);
+ ts.setAlpha(mFGSurfaceControl, 0.75f);
}
ASSERT_EQ(2, sFakeComposer->getFrameCount());
@@ -625,10 +625,9 @@
TEST_F(TransactionTest, LayerSetFlags) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR,
- mFGSurfaceControl->setFlags(layer_state_t::eLayerHidden,
- layer_state_t::eLayerHidden));
+ TransactionScope ts(*sFakeComposer);
+ ts.setFlags(mFGSurfaceControl, layer_state_t::eLayerHidden,
+ layer_state_t::eLayerHidden);
}
// Foreground layer should have disappeared.
@@ -667,10 +666,9 @@
const matrixTestData& xform = MATRIX_TESTS[i];
SCOPED_TRACE(i);
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR,
- mFGSurfaceControl->setMatrix(xform.matrix[0], xform.matrix[1],
- xform.matrix[2], xform.matrix[3]));
+ TransactionScope ts(*sFakeComposer);
+ ts.setMatrix(mFGSurfaceControl, xform.matrix[0], xform.matrix[1],
+ xform.matrix[2], xform.matrix[3]);
}
auto referenceFrame = mBaseFrame;
@@ -684,10 +682,10 @@
#if 0
TEST_F(TransactionTest, LayerSetMatrix2) {
{
- GlobalTransactionScope gts(*sFakeComposer);
+ TransactionScope ts(*sFakeComposer);
// TODO: PLEASE SPEC THE FUNCTION!
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setMatrix(0.11f, 0.123f,
- -2.33f, 0.22f));
+ ts.setMatrix(mFGSurfaceControl, 0.11f, 0.123f,
+ -2.33f, 0.22f);
}
auto referenceFrame = mBaseFrame;
// TODO: Is this correct for sure?
@@ -708,10 +706,10 @@
fillSurfaceRGBA8(syncSurfaceControl, DARK_GRAY);
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, syncSurfaceControl->setLayer(INT32_MAX - 1));
- ASSERT_EQ(NO_ERROR, syncSurfaceControl->setPosition(mDisplayWidth - 2, mDisplayHeight - 2));
- ASSERT_EQ(NO_ERROR, syncSurfaceControl->show());
+ TransactionScope ts(*sFakeComposer);
+ ts.setLayer(syncSurfaceControl, INT32_MAX - 1);
+ ts.setPosition(syncSurfaceControl, mDisplayWidth - 2, mDisplayHeight - 2);
+ ts.show(syncSurfaceControl);
}
auto referenceFrame = mBaseFrame;
referenceFrame.push_back(makeSimpleRect(mDisplayWidth - 2, mDisplayHeight - 2,
@@ -723,20 +721,20 @@
// set up two deferred transactions on different frames - these should not yield composited
// frames
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75));
- mFGSurfaceControl
- ->deferTransactionUntil(syncSurfaceControl->getHandle(),
- syncSurfaceControl->getSurface()->getNextFrameNumber());
+ TransactionScope ts(*sFakeComposer);
+ ts.setAlpha(mFGSurfaceControl, 0.75);
+ ts.deferTransactionUntil(mFGSurfaceControl,
+ syncSurfaceControl->getHandle(),
+ syncSurfaceControl->getSurface()->getNextFrameNumber());
}
EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128, 128));
- mFGSurfaceControl
- ->deferTransactionUntil(syncSurfaceControl->getHandle(),
- syncSurfaceControl->getSurface()->getNextFrameNumber() + 1);
+ TransactionScope ts(*sFakeComposer);
+ ts.setPosition(mFGSurfaceControl, 128, 128);
+ ts.deferTransactionUntil(mFGSurfaceControl,
+ syncSurfaceControl->getHandle(),
+ syncSurfaceControl->getSurface()->getNextFrameNumber() + 1);
}
EXPECT_EQ(4, sFakeComposer->getFrameCount());
EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
@@ -752,8 +750,8 @@
// should show up immediately since it's not deferred
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(1.0));
+ TransactionScope ts(*sFakeComposer);
+ ts.setAlpha(mFGSurfaceControl, 1.0);
}
referenceFrame[FG_LAYER].mPlaneAlpha = 1.f;
EXPECT_EQ(6, sFakeComposer->getFrameCount());
@@ -777,10 +775,10 @@
// Now we stack the surface above the foreground surface and make sure it is visible.
{
- GlobalTransactionScope gts(*sFakeComposer);
- relativeSurfaceControl->setPosition(64, 64);
- relativeSurfaceControl->show();
- relativeSurfaceControl->setRelativeLayer(mFGSurfaceControl->getHandle(), 1);
+ TransactionScope ts(*sFakeComposer);
+ ts.setPosition(relativeSurfaceControl, 64, 64);
+ ts.show(relativeSurfaceControl);
+ ts.setRelativeLayer(relativeSurfaceControl, mFGSurfaceControl->getHandle(), 1);
}
auto referenceFrame = mBaseFrame;
// NOTE: All three layers will be visible as the surfaces are
@@ -791,8 +789,8 @@
// A call to setLayer will override a call to setRelativeLayer
{
- GlobalTransactionScope gts(*sFakeComposer);
- relativeSurfaceControl->setLayer(0);
+ TransactionScope ts(*sFakeComposer);
+ ts.setLayer(relativeSurfaceControl, 0);
}
// Previous top layer will now appear at the bottom.
@@ -828,11 +826,11 @@
TEST_F(ChildLayerTest, Positioning) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->show();
- mChild->setPosition(10, 10);
+ TransactionScope ts(*sFakeComposer);
+ ts.show(mChild);
+ ts.setPosition(mChild, 10, 10);
// Move to the same position as in the original setup.
- mFGSurfaceControl->setPosition(64, 64);
+ ts.setPosition(mFGSurfaceControl, 64, 64);
}
auto referenceFrame = mBaseFrame;
@@ -842,8 +840,8 @@
EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(0, 0));
+ TransactionScope ts(*sFakeComposer);
+ ts.setPosition(mFGSurfaceControl, 0, 0);
}
auto referenceFrame2 = mBaseFrame;
@@ -855,11 +853,11 @@
TEST_F(ChildLayerTest, Cropping) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->show();
- mChild->setPosition(0, 0);
- mFGSurfaceControl->setPosition(0, 0);
- mFGSurfaceControl->setCrop(Rect(0, 0, 5, 5));
+ TransactionScope ts(*sFakeComposer);
+ ts.show(mChild);
+ ts.setPosition(mChild, 0, 0);
+ ts.setPosition(mFGSurfaceControl, 0, 0);
+ ts.setCrop(mFGSurfaceControl, Rect(0, 0, 5, 5));
}
// NOTE: The foreground surface would be occluded by the child
// now, but is included in the stack because the child is
@@ -874,11 +872,11 @@
TEST_F(ChildLayerTest, FinalCropping) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->show();
- mChild->setPosition(0, 0);
- mFGSurfaceControl->setPosition(0, 0);
- mFGSurfaceControl->setFinalCrop(Rect(0, 0, 5, 5));
+ TransactionScope ts(*sFakeComposer);
+ ts.show(mChild);
+ ts.setPosition(mChild, 0, 0);
+ ts.setPosition(mFGSurfaceControl, 0, 0);
+ ts.setFinalCrop(mFGSurfaceControl, Rect(0, 0, 5, 5));
}
auto referenceFrame = mBaseFrame;
referenceFrame[FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 0 + 5, 0 + 5};
@@ -890,10 +888,10 @@
TEST_F(ChildLayerTest, Constraints) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->show();
- mFGSurfaceControl->setPosition(0, 0);
- mChild->setPosition(63, 63);
+ TransactionScope ts(*sFakeComposer);
+ ts.show(mChild);
+ ts.setPosition(mFGSurfaceControl, 0, 0);
+ ts.setPosition(mChild, 63, 63);
}
auto referenceFrame = mBaseFrame;
referenceFrame[FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 64, 64};
@@ -904,8 +902,8 @@
TEST_F(ChildLayerTest, Scaling) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setPosition(0, 0);
+ TransactionScope ts(*sFakeComposer);
+ ts.setPosition(mFGSurfaceControl, 0, 0);
}
auto referenceFrame = mBaseFrame;
referenceFrame[FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 64, 64};
@@ -913,8 +911,8 @@
EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setMatrix(2.0, 0, 0, 2.0);
+ TransactionScope ts(*sFakeComposer);
+ ts.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0);
}
auto referenceFrame2 = mBaseFrame;
@@ -925,11 +923,11 @@
TEST_F(ChildLayerTest, LayerAlpha) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->show();
- mChild->setPosition(0, 0);
- mFGSurfaceControl->setPosition(0, 0);
- ASSERT_EQ(NO_ERROR, mChild->setAlpha(0.5));
+ TransactionScope ts(*sFakeComposer);
+ ts.show(mChild);
+ ts.setPosition(mChild, 0, 0);
+ ts.setPosition(mFGSurfaceControl, 0, 0);
+ ts.setAlpha(mChild, 0.5);
}
auto referenceFrame = mBaseFrame;
@@ -939,8 +937,8 @@
EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
{
- GlobalTransactionScope gts(*sFakeComposer);
- ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.5));
+ TransactionScope ts(*sFakeComposer);
+ ts.setAlpha(mFGSurfaceControl, 0.5);
}
auto referenceFrame2 = referenceFrame;
@@ -951,10 +949,10 @@
TEST_F(ChildLayerTest, ReparentChildren) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->show();
- mChild->setPosition(10, 10);
- mFGSurfaceControl->setPosition(64, 64);
+ TransactionScope ts(*sFakeComposer);
+ ts.show(mChild);
+ ts.setPosition(mChild, 10, 10);
+ ts.setPosition(mFGSurfaceControl, 64, 64);
}
auto referenceFrame = mBaseFrame;
referenceFrame[FG_LAYER].mDisplayFrame = hwc_rect_t{64, 64, 64 + 64, 64 + 64};
@@ -963,8 +961,8 @@
EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->reparentChildren(mBGSurfaceControl->getHandle());
+ TransactionScope ts(*sFakeComposer);
+ ts.reparentChildren(mFGSurfaceControl, mBGSurfaceControl->getHandle());
}
auto referenceFrame2 = referenceFrame;
@@ -975,10 +973,10 @@
TEST_F(ChildLayerTest, DetachChildren) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->show();
- mChild->setPosition(10, 10);
- mFGSurfaceControl->setPosition(64, 64);
+ TransactionScope ts(*sFakeComposer);
+ ts.show(mChild);
+ ts.setPosition(mChild, 10, 10);
+ ts.setPosition(mFGSurfaceControl, 64, 64);
}
auto referenceFrame = mBaseFrame;
@@ -988,13 +986,13 @@
EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->detachChildren();
+ TransactionScope ts(*sFakeComposer);
+ ts.detachChildren(mFGSurfaceControl);
}
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->hide();
+ TransactionScope ts(*sFakeComposer);
+ ts.hide(mChild);
}
// Nothing should have changed. The child control becomes a no-op
@@ -1005,17 +1003,17 @@
TEST_F(ChildLayerTest, InheritNonTransformScalingFromParent) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->show();
- mChild->setPosition(0, 0);
- mFGSurfaceControl->setPosition(0, 0);
+ TransactionScope ts(*sFakeComposer);
+ ts.show(mChild);
+ ts.setPosition(mChild, 0, 0);
+ ts.setPosition(mFGSurfaceControl, 0, 0);
}
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setOverrideScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
+ TransactionScope ts(*sFakeComposer);
+ ts.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
// We cause scaling by 2.
- mFGSurfaceControl->setSize(128, 128);
+ ts.setSize(mFGSurfaceControl, 128, 128);
}
auto referenceFrame = mBaseFrame;
@@ -1029,17 +1027,17 @@
// Regression test for b/37673612
TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) {
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->show();
- mChild->setPosition(0, 0);
- mFGSurfaceControl->setPosition(0, 0);
+ TransactionScope ts(*sFakeComposer);
+ ts.show(mChild);
+ ts.setPosition(mChild, 0, 0);
+ ts.setPosition(mFGSurfaceControl, 0, 0);
}
// We set things up as in b/37673612 so that there is a mismatch between the buffer size and
// the WM specified state size.
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setSize(128, 64);
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 128, 64);
}
sp<Surface> s = mFGSurfaceControl->getSurface();
@@ -1070,10 +1068,10 @@
// Show the child layer in a deferred transaction
{
- GlobalTransactionScope gts(*sFakeComposer);
- mChild->deferTransactionUntil(mFGSurfaceControl->getHandle(),
+ TransactionScope ts(*sFakeComposer);
+ ts.deferTransactionUntil(mChild, mFGSurfaceControl->getHandle(),
mFGSurfaceControl->getSurface()->getNextFrameNumber());
- mChild->show();
+ ts.show(mChild);
}
// Render the foreground surface a few times
@@ -1110,11 +1108,11 @@
sFakeComposer->runVSyncAndWait();
}
void restoreInitialState() {
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setSize(64, 64);
- mFGSurfaceControl->setPosition(64, 64);
- mFGSurfaceControl->setCrop(Rect(0, 0, 64, 64));
- mFGSurfaceControl->setFinalCrop(Rect(0, 0, -1, -1));
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 64, 64);
+ ts.setPosition(mFGSurfaceControl, 64, 64);
+ ts.setCrop(mFGSurfaceControl, Rect(0, 0, 64, 64));
+ ts.setFinalCrop(mFGSurfaceControl, Rect(0, 0, -1, -1));
}
};
@@ -1122,9 +1120,9 @@
// By default position can be updated even while
// a resize is pending.
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setSize(32, 32);
- mFGSurfaceControl->setPosition(100, 100);
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 32, 32);
+ ts.setPosition(mFGSurfaceControl, 100, 100);
}
// The size should not have updated as we have not provided a new buffer.
@@ -1137,10 +1135,10 @@
// Now we repeat with setGeometryAppliesWithResize
// and verify the position DOESN'T latch.
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setGeometryAppliesWithResize();
- mFGSurfaceControl->setSize(32, 32);
- mFGSurfaceControl->setPosition(100, 100);
+ TransactionScope ts(*sFakeComposer);
+ ts.setGeometryAppliesWithResize(mFGSurfaceControl);
+ ts.setSize(mFGSurfaceControl, 32, 32);
+ ts.setPosition(mFGSurfaceControl, 100, 100);
}
EXPECT_TRUE(framesAreSame(mBaseFrame, sFakeComposer->getLatestFrame()));
@@ -1156,9 +1154,9 @@
TEST_F(LatchingTest, CropLatching) {
// Normally the crop applies immediately even while a resize is pending.
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setCrop(Rect(0, 0, 63, 63));
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 128, 128);
+ ts.setCrop(mFGSurfaceControl, Rect(0, 0, 63, 63));
}
auto referenceFrame1 = mBaseFrame;
@@ -1169,10 +1167,10 @@
restoreInitialState();
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setGeometryAppliesWithResize();
- mFGSurfaceControl->setCrop(Rect(0, 0, 63, 63));
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 128, 128);
+ ts.setGeometryAppliesWithResize(mFGSurfaceControl);
+ ts.setCrop(mFGSurfaceControl, Rect(0, 0, 63, 63));
}
EXPECT_TRUE(framesAreSame(mBaseFrame, sFakeComposer->getLatestFrame()));
@@ -1188,9 +1186,9 @@
TEST_F(LatchingTest, FinalCropLatching) {
// Normally the crop applies immediately even while a resize is pending.
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 128, 128);
+ ts.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
}
auto referenceFrame1 = mBaseFrame;
@@ -1202,10 +1200,10 @@
restoreInitialState();
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setGeometryAppliesWithResize();
- mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 128, 128);
+ ts.setGeometryAppliesWithResize(mFGSurfaceControl);
+ ts.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
}
EXPECT_TRUE(framesAreSame(mBaseFrame, sFakeComposer->getLatestFrame()));
@@ -1224,9 +1222,9 @@
TEST_F(LatchingTest, FinalCropLatchingBufferOldSize) {
// Normally the crop applies immediately even while a resize is pending.
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 128, 128);
+ ts.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
}
auto referenceFrame1 = mBaseFrame;
@@ -1242,10 +1240,10 @@
lockAndFillFGBuffer();
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setGeometryAppliesWithResize();
- mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 128, 128);
+ ts.setGeometryAppliesWithResize(mFGSurfaceControl);
+ ts.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
}
EXPECT_TRUE(framesAreSame(mBaseFrame, sFakeComposer->getLatestFrame()));
@@ -1271,15 +1269,15 @@
// is still pending, and ensure we are successful. Success meaning the second crop
// is the one which eventually latches and not the first.
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setSize(128, 128);
- mFGSurfaceControl->setGeometryAppliesWithResize();
- mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
+ TransactionScope ts(*sFakeComposer);
+ ts.setSize(mFGSurfaceControl, 128, 128);
+ ts.setGeometryAppliesWithResize(mFGSurfaceControl);
+ ts.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
}
{
- GlobalTransactionScope gts(*sFakeComposer);
- mFGSurfaceControl->setFinalCrop(Rect(0, 0, -1, -1));
+ TransactionScope ts(*sFakeComposer);
+ ts.setFinalCrop(mFGSurfaceControl, Rect(0, 0, -1, -1));
}
EXPECT_TRUE(framesAreSame(mBaseFrame, sFakeComposer->getLatestFrame()));