Skip to content

Commit b2d8f7e

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "Expose interface for setting stop layer" into main
2 parents 7d5cf2f + e96cc90 commit b2d8f7e

File tree

9 files changed

+61
-8
lines changed

9 files changed

+61
-8
lines changed

libs/gui/SurfaceComposerClient.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,14 +2707,16 @@ status_t SurfaceComposerClient::createSurfaceChecked(const String8& name, uint32
27072707
return err;
27082708
}
27092709

2710-
sp<SurfaceControl> SurfaceComposerClient::mirrorSurface(SurfaceControl* mirrorFromSurface) {
2710+
sp<SurfaceControl> SurfaceComposerClient::mirrorSurface(SurfaceControl* mirrorFromSurface,
2711+
SurfaceControl* stopAt) {
27112712
if (mirrorFromSurface == nullptr) {
27122713
return nullptr;
27132714
}
27142715

27152716
sp<IBinder> mirrorFromHandle = mirrorFromSurface->getHandle();
2717+
sp<IBinder> stopAtHandle = stopAt ? stopAt->getHandle() : nullptr;
27162718
gui::CreateSurfaceResult result;
2717-
const binder::Status status = mClient->mirrorSurface(mirrorFromHandle, &result);
2719+
const binder::Status status = mClient->mirrorSurface(mirrorFromHandle, stopAtHandle, &result);
27182720
const status_t err = statusTFromBinderStatus(status);
27192721
if (err == NO_ERROR) {
27202722
return sp<SurfaceControl>::make(this, result.handle, result.layerId,

libs/gui/aidl/android/gui/ISurfaceComposerClient.aidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ interface ISurfaceComposerClient {
5858
*/
5959
FrameStats getLayerFrameStats(IBinder handle);
6060

61-
CreateSurfaceResult mirrorSurface(IBinder mirrorFromHandle);
61+
CreateSurfaceResult mirrorSurface(IBinder mirrorFromHandle, @nullable IBinder stopAtHandle);
6262

6363
CreateSurfaceResult mirrorDisplay(long displayId);
6464

libs/gui/include/gui/SurfaceComposerClient.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,19 @@ class SurfaceComposerClient : public RefBase
389389
// A A'
390390
// | |
391391
// B B'
392-
sp<SurfaceControl> mirrorSurface(SurfaceControl* mirrorFromSurface);
392+
//
393+
// The mirrored hierarchy will exclude all layers z-ordered above the layer specified by
394+
// stopAt. With stopAt specified as B:
395+
//
396+
// Real Hierarchy Mirror
397+
// SC (value that's returned)
398+
// |
399+
// A A'
400+
// |
401+
// B
402+
//
403+
sp<SurfaceControl> mirrorSurface(SurfaceControl* mirrorFromSurface,
404+
SurfaceControl* stopAt = nullptr);
393405

394406
sp<SurfaceControl> mirrorDisplay(DisplayId displayId);
395407

services/surfaceflinger/Client.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ binder::Status Client::getLayerFrameStats(const sp<IBinder>& handle, gui::FrameS
9999
}
100100

101101
binder::Status Client::mirrorSurface(const sp<IBinder>& mirrorFromHandle,
102+
const sp<IBinder>& stopAtHandle,
102103
gui::CreateSurfaceResult* outResult) {
103104
LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this), "MirrorRoot",
104105
0 /* flags */, gui::LayerMetadata());
105-
status_t status = mFlinger->mirrorLayer(args, mirrorFromHandle, *outResult);
106+
status_t status = mFlinger->mirrorLayer(args, mirrorFromHandle, stopAtHandle, *outResult);
106107
return binderStatusFromStatusT(status);
107108
}
108109

services/surfaceflinger/Client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Client : public gui::BnSurfaceComposerClient {
5151
gui::FrameStats* outStats) override;
5252

5353
binder::Status mirrorSurface(const sp<IBinder>& mirrorFromHandle,
54+
const sp<IBinder>& stopAtHandle,
5455
gui::CreateSurfaceResult* outResult) override;
5556

5657
binder::Status mirrorDisplay(int64_t displayId, gui::CreateSurfaceResult* outResult) override;

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5442,6 +5442,7 @@ uint32_t SurfaceFlinger::addInputWindowCommands(const InputWindowCommands& input
54425442

54435443
status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args,
54445444
const sp<IBinder>& mirrorFromHandle,
5445+
const sp<IBinder>& stopAtHandle,
54455446
gui::CreateSurfaceResult& outResult) {
54465447
if (!mirrorFromHandle) {
54475448
return NAME_NOT_FOUND;
@@ -5459,6 +5460,13 @@ status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args,
54595460
mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill;
54605461
mirrorArgs.mirrorLayerHandle = mirrorFromHandle;
54615462
mirrorArgs.addToRoot = false;
5463+
if (stopAtHandle) {
5464+
uint32_t stopLayerId = LayerHandle::getLayerId(stopAtHandle);
5465+
if (stopLayerId == UNASSIGNED_LAYER_ID) {
5466+
return NAME_NOT_FOUND;
5467+
}
5468+
mirrorArgs.stopLayerId = stopLayerId;
5469+
}
54625470
status_t result = createLayer(mirrorArgs, &outResult.handle, &mirrorLayer);
54635471
if (result != NO_ERROR) {
54645472
return result;

services/surfaceflinger/SurfaceFlinger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ class SurfaceFlinger : public BnSurfaceComposer,
860860
status_t checkLayerLeaks();
861861

862862
status_t mirrorLayer(const LayerCreationArgs& args, const sp<IBinder>& mirrorFromHandle,
863-
gui::CreateSurfaceResult& outResult);
863+
const sp<IBinder>& stopAtHandle, gui::CreateSurfaceResult& outResult);
864864

865865
status_t mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args,
866866
gui::CreateSurfaceResult& outResult);

services/surfaceflinger/tests/MirrorLayer_test.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,35 @@ TEST_F(MirrorLayerTest, OffscreenMirrorScreenshot) {
360360
}
361361
}
362362

363+
TEST_F(MirrorLayerTest, MirrorLayerWithStopLayer) {
364+
if (!FlagManager::getInstance().stop_layer()) {
365+
GTEST_SKIP() << "skipping test - stop_layer feature flag disabled";
366+
}
367+
368+
sp<SurfaceControl> grandchild =
369+
createColorLayer("Grandchild layer", Color::BLUE, mChildLayer.get());
370+
Transaction()
371+
.setFlags(grandchild, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque)
372+
.setCrop(grandchild, Rect(0, 0, 200, 200))
373+
.show(grandchild)
374+
.apply();
375+
376+
// Mirror child with stop layer set to grandchild.
377+
sp<SurfaceControl> mirrorLayer = mClient->mirrorSurface(mChildLayer.get(), grandchild.get());
378+
ASSERT_NE(mirrorLayer, nullptr);
379+
380+
// Add mirrorLayer as child of mParentLayer so it's shown on the display
381+
Transaction()
382+
.reparent(mirrorLayer, mParentLayer)
383+
.setPosition(mirrorLayer, 500, 500)
384+
.show(mirrorLayer)
385+
.apply();
386+
387+
auto shot = screenshot();
388+
// Assert that we see the child's color and not the grandchild's color
389+
shot->expectColor(Rect(550, 550, 600, 600), Color::GREEN);
390+
}
391+
363392
} // namespace android
364393

365394
// TODO(b/129481165): remove the #pragma below and fix conversion issues

services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,8 @@ class TestableSurfaceFlinger {
572572
}
573573

574574
auto mirrorLayer(const LayerCreationArgs& args, const sp<IBinder>& mirrorFromHandle,
575-
gui::CreateSurfaceResult& outResult) {
576-
return mFlinger->mirrorLayer(args, mirrorFromHandle, outResult);
575+
const sp<IBinder>& stopAtHandle, gui::CreateSurfaceResult& outResult) {
576+
return mFlinger->mirrorLayer(args, mirrorFromHandle, stopAtHandle, outResult);
577577
}
578578

579579
void getDynamicDisplayInfoFromToken(const sp<IBinder>& displayToken,

0 commit comments

Comments
 (0)