From aeebeb4eca5967d2a893ac09464499301936a134 Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Tue, 13 Jun 2023 19:53:03 +0000 Subject: Use a strongly typed Pid in WindowInfo Bug: 286428012 Test: presubmit Change-Id: I6a3572ff10b259feae74863c0203bb5f085f233f --- libs/gui/WindowInfo.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libs/gui/WindowInfo.cpp') diff --git a/libs/gui/WindowInfo.cpp b/libs/gui/WindowInfo.cpp index cd9b424e13..52af9d5114 100644 --- a/libs/gui/WindowInfo.cpp +++ b/libs/gui/WindowInfo.cpp @@ -92,6 +92,7 @@ status_t WindowInfo::writeToParcel(android::Parcel* parcel) const { // Ensure that the size of custom types are what we expect for writing into the parcel. static_assert(sizeof(inputConfig) == 4u); + static_assert(sizeof(ownerPid.val()) == 4u); static_assert(sizeof(ownerUid.val()) == 4u); // clang-format off @@ -116,7 +117,7 @@ status_t WindowInfo::writeToParcel(android::Parcel* parcel) const { parcel->writeFloat(transform.dsdy()) ?: parcel->writeFloat(transform.ty()) ?: parcel->writeInt32(static_cast(touchOcclusionMode)) ?: - parcel->writeInt32(ownerPid) ?: + parcel->writeInt32(ownerPid.val()) ?: parcel->writeInt32(ownerUid.val()) ?: parcel->writeUtf8AsUtf16(packageName) ?: parcel->writeInt32(inputConfig.get()) ?: @@ -148,7 +149,7 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { } float dsdx, dtdx, tx, dtdy, dsdy, ty; - int32_t lpFlags, lpType, touchOcclusionModeInt, inputConfigInt, ownerUidInt; + int32_t lpFlags, lpType, touchOcclusionModeInt, inputConfigInt, ownerPidInt, ownerUidInt; sp touchableRegionCropHandleSp; // clang-format off @@ -168,7 +169,7 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { parcel->readFloat(&dsdy) ?: parcel->readFloat(&ty) ?: parcel->readInt32(&touchOcclusionModeInt) ?: - parcel->readInt32(&ownerPid) ?: + parcel->readInt32(&ownerPidInt) ?: parcel->readInt32(&ownerUidInt) ?: parcel->readUtf8FromUtf16(&packageName) ?: parcel->readInt32(&inputConfigInt) ?: @@ -191,6 +192,7 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1}); touchOcclusionMode = static_cast(touchOcclusionModeInt); inputConfig = ftl::Flags(inputConfigInt); + ownerPid = Pid{ownerPidInt}; ownerUid = Uid{static_cast(ownerUidInt)}; touchableRegionCropHandle = touchableRegionCropHandleSp; -- cgit v1.2.3-59-g8ed1b From 7f019199c94d15923704bb0e2896c6147dc38998 Mon Sep 17 00:00:00 2001 From: Chavi Weingarten Date: Tue, 8 Aug 2023 20:39:01 +0000 Subject: Use rect instead of four int frame values for WindowInfo Test: Builds Bug: 290795410 Change-Id: Iff104ad14c5da792f32a68d25145b936f6ea71f6 --- libs/gui/WindowInfo.cpp | 25 +++++++--------------- .../fuzzer/libgui_surfaceComposerClient_fuzzer.cpp | 6 ++---- libs/gui/include/gui/WindowInfo.h | 5 +---- libs/gui/tests/WindowInfo_test.cpp | 10 ++------- .../benchmarks/InputDispatcher_benchmarks.cpp | 5 +---- .../inputflinger/dispatcher/InputDispatcher.cpp | 10 ++++----- .../inputflinger/tests/InputDispatcher_test.cpp | 10 ++------- .../FrontEnd/LayerSnapshotBuilder.cpp | 7 +----- services/surfaceflinger/Layer.cpp | 6 +----- services/surfaceflinger/LayerProtoHelper.cpp | 4 ++-- 10 files changed, 25 insertions(+), 63 deletions(-) (limited to 'libs/gui/WindowInfo.cpp') diff --git a/libs/gui/WindowInfo.cpp b/libs/gui/WindowInfo.cpp index 52af9d5114..2eb6bd670d 100644 --- a/libs/gui/WindowInfo.cpp +++ b/libs/gui/WindowInfo.cpp @@ -43,7 +43,7 @@ bool WindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const { } bool WindowInfo::frameContainsPoint(int32_t x, int32_t y) const { - return x >= frameLeft && x < frameRight && y >= frameTop && y < frameBottom; + return x >= frame.left && x < frame.right && y >= frame.top && y < frame.bottom; } bool WindowInfo::supportsSplitTouch() const { @@ -59,18 +59,15 @@ bool WindowInfo::interceptsStylus() const { } bool WindowInfo::overlaps(const WindowInfo* other) const { - const bool nonEmpty = (frameRight - frameLeft > 0) || (frameBottom - frameTop > 0); - return nonEmpty && frameLeft < other->frameRight && frameRight > other->frameLeft && - frameTop < other->frameBottom && frameBottom > other->frameTop; + return !frame.isEmpty() && frame.left < other->frame.right && frame.right > other->frame.left && + frame.top < other->frame.bottom && frame.bottom > other->frame.top; } bool WindowInfo::operator==(const WindowInfo& info) const { return info.token == token && info.id == id && info.name == name && - info.dispatchingTimeout == dispatchingTimeout && info.frameLeft == frameLeft && - info.frameTop == frameTop && info.frameRight == frameRight && - info.frameBottom == frameBottom && info.surfaceInset == surfaceInset && - info.globalScaleFactor == globalScaleFactor && info.transform == transform && - info.touchableRegion.hasSameRects(touchableRegion) && + info.dispatchingTimeout == dispatchingTimeout && info.frame == frame && + info.surfaceInset == surfaceInset && info.globalScaleFactor == globalScaleFactor && + info.transform == transform && info.touchableRegion.hasSameRects(touchableRegion) && info.touchOcclusionMode == touchOcclusionMode && info.ownerPid == ownerPid && info.ownerUid == ownerUid && info.packageName == packageName && info.inputConfig == inputConfig && info.displayId == displayId && @@ -103,10 +100,7 @@ status_t WindowInfo::writeToParcel(android::Parcel* parcel) const { parcel->writeInt32(layoutParamsFlags.get()) ?: parcel->writeInt32( static_cast>(layoutParamsType)) ?: - parcel->writeInt32(frameLeft) ?: - parcel->writeInt32(frameTop) ?: - parcel->writeInt32(frameRight) ?: - parcel->writeInt32(frameBottom) ?: + parcel->write(frame) ?: parcel->writeInt32(surfaceInset) ?: parcel->writeFloat(globalScaleFactor) ?: parcel->writeFloat(alpha) ?: @@ -155,10 +149,7 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { // clang-format off status = parcel->readInt32(&lpFlags) ?: parcel->readInt32(&lpType) ?: - parcel->readInt32(&frameLeft) ?: - parcel->readInt32(&frameTop) ?: - parcel->readInt32(&frameRight) ?: - parcel->readInt32(&frameBottom) ?: + parcel->read(frame) ?: parcel->readInt32(&surfaceInset) ?: parcel->readFloat(&globalScaleFactor) ?: parcel->readFloat(&alpha) ?: diff --git a/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp b/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp index 3e37e4850e..4daa3be36f 100644 --- a/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp +++ b/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp @@ -178,10 +178,8 @@ void SurfaceComposerClientFuzzer::getWindowInfo(gui::WindowInfo* windowInfo) { windowInfo->name = mFdp.ConsumeRandomLengthString(kRandomStringMaxBytes); windowInfo->layoutParamsFlags = mFdp.PickValueInArray(kFlags); windowInfo->layoutParamsType = mFdp.PickValueInArray(kType); - windowInfo->frameLeft = mFdp.ConsumeIntegral(); - windowInfo->frameTop = mFdp.ConsumeIntegral(); - windowInfo->frameRight = mFdp.ConsumeIntegral(); - windowInfo->frameBottom = mFdp.ConsumeIntegral(); + windowInfo->frame = Rect(mFdp.ConsumeIntegral(), mFdp.ConsumeIntegral(), + mFdp.ConsumeIntegral(), mFdp.ConsumeIntegral()); windowInfo->surfaceInset = mFdp.ConsumeIntegral(); windowInfo->alpha = mFdp.ConsumeFloatingPointInRange(0, 1); ui::Transform transform(mFdp.PickValueInArray(kOrientation)); diff --git a/libs/gui/include/gui/WindowInfo.h b/libs/gui/include/gui/WindowInfo.h index 7ff73874ae..bd2eb7413b 100644 --- a/libs/gui/include/gui/WindowInfo.h +++ b/libs/gui/include/gui/WindowInfo.h @@ -194,10 +194,7 @@ struct WindowInfo : public Parcelable { std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5); /* These values are filled in by SurfaceFlinger. */ - int32_t frameLeft = -1; - int32_t frameTop = -1; - int32_t frameRight = -1; - int32_t frameBottom = -1; + Rect frame = Rect::INVALID_RECT; /* * SurfaceFlinger consumes this value to shrink the computed frame. This is diff --git a/libs/gui/tests/WindowInfo_test.cpp b/libs/gui/tests/WindowInfo_test.cpp index 461fe4a4ce..f2feaefa13 100644 --- a/libs/gui/tests/WindowInfo_test.cpp +++ b/libs/gui/tests/WindowInfo_test.cpp @@ -52,10 +52,7 @@ TEST(WindowInfo, Parcelling) { i.layoutParamsFlags = WindowInfo::Flag::SLIPPERY; i.layoutParamsType = WindowInfo::Type::INPUT_METHOD; i.dispatchingTimeout = 12s; - i.frameLeft = 93; - i.frameTop = 34; - i.frameRight = 16; - i.frameBottom = 19; + i.frame = Rect(93, 34, 16, 19); i.surfaceInset = 17; i.globalScaleFactor = 0.3; i.alpha = 0.7; @@ -85,10 +82,7 @@ TEST(WindowInfo, Parcelling) { ASSERT_EQ(i.layoutParamsFlags, i2.layoutParamsFlags); ASSERT_EQ(i.layoutParamsType, i2.layoutParamsType); ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout); - ASSERT_EQ(i.frameLeft, i2.frameLeft); - ASSERT_EQ(i.frameTop, i2.frameTop); - ASSERT_EQ(i.frameRight, i2.frameRight); - ASSERT_EQ(i.frameBottom, i2.frameBottom); + ASSERT_EQ(i.frame, i2.frame); ASSERT_EQ(i.surfaceInset, i2.surfaceInset); ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor); ASSERT_EQ(i.alpha, i2.alpha); diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index 6dd785ae56..188d5f048d 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -185,10 +185,7 @@ public: mInfo.token = mClientChannel->getConnectionToken(); mInfo.name = "FakeWindowHandle"; mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT; - mInfo.frameLeft = mFrame.left; - mInfo.frameTop = mFrame.top; - mInfo.frameRight = mFrame.right; - mInfo.frameBottom = mFrame.bottom; + mInfo.frame = mFrame; mInfo.globalScaleFactor = 1.0; mInfo.touchableRegion.clear(); mInfo.addTouchableRegion(mFrame); diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 2923a3cfa7..630542fe47 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -3011,8 +3011,8 @@ std::string InputDispatcher::dumpWindowForTouchOcclusion(const WindowInfo* info, "hasToken=%s, applicationInfo.name=%s, applicationInfo.token=%s\n", isTouchedWindow ? "[TOUCHED] " : "", info->packageName.c_str(), info->ownerUid.toString().c_str(), info->id, - toString(info->touchOcclusionMode).c_str(), info->alpha, info->frameLeft, - info->frameTop, info->frameRight, info->frameBottom, + toString(info->touchOcclusionMode).c_str(), info->alpha, info->frame.left, + info->frame.top, info->frame.right, info->frame.bottom, dumpRegion(info->touchableRegion).c_str(), info->name.c_str(), info->inputConfig.string().c_str(), toString(info->token != nullptr), info->applicationInfo.name.c_str(), @@ -5644,9 +5644,9 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const { i, windowInfo->name.c_str(), windowInfo->id, windowInfo->displayId, windowInfo->inputConfig.string().c_str(), - windowInfo->alpha, windowInfo->frameLeft, - windowInfo->frameTop, windowInfo->frameRight, - windowInfo->frameBottom, windowInfo->globalScaleFactor, + windowInfo->alpha, windowInfo->frame.left, + windowInfo->frame.top, windowInfo->frame.right, + windowInfo->frame.bottom, windowInfo->globalScaleFactor, windowInfo->applicationInfo.name.c_str(), binderToString(windowInfo->applicationInfo.token).c_str()); dump += dumpRegion(windowInfo->touchableRegion); diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 6d9cd87c4f..4dd40cda80 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -1131,10 +1131,7 @@ public: mInfo.name = name; mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT; mInfo.alpha = 1.0; - mInfo.frameLeft = 0; - mInfo.frameTop = 0; - mInfo.frameRight = WIDTH; - mInfo.frameBottom = HEIGHT; + mInfo.frame = Rect(0, 0, WIDTH, HEIGHT); mInfo.transform.set(0, 0); mInfo.globalScaleFactor = 1.0; mInfo.touchableRegion.clear(); @@ -1215,10 +1212,7 @@ public: void setApplicationToken(sp token) { mInfo.applicationInfo.token = token; } void setFrame(const Rect& frame, const ui::Transform& displayTransform = ui::Transform()) { - mInfo.frameLeft = frame.left; - mInfo.frameTop = frame.top; - mInfo.frameRight = frame.right; - mInfo.frameBottom = frame.bottom; + mInfo.frame = frame; mInfo.touchableRegion.clear(); mInfo.addTouchableRegion(frame); diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp index 159d0f028d..30a795f166 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp +++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp @@ -178,12 +178,7 @@ void fillInputFrameInfo(gui::WindowInfo& info, const ui::Transform& screenToDisp info.touchableRegion.clear(); } - const Rect roundedFrameInDisplay = - getInputBoundsInDisplaySpace(snapshot, inputBounds, screenToDisplay); - info.frameLeft = roundedFrameInDisplay.left; - info.frameTop = roundedFrameInDisplay.top; - info.frameRight = roundedFrameInDisplay.right; - info.frameBottom = roundedFrameInDisplay.bottom; + info.frame = getInputBoundsInDisplaySpace(snapshot, inputBounds, screenToDisplay); ui::Transform inputToLayer; inputToLayer.set(inputBounds.left, inputBounds.top); diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 59a8825de5..377ebd4cd1 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -2398,11 +2398,7 @@ void Layer::fillInputFrameInfo(WindowInfo& info, const ui::Transform& screenToDi info.touchableRegion.clear(); } - const Rect roundedFrameInDisplay = getInputBoundsInDisplaySpace(inputBounds, screenToDisplay); - info.frameLeft = roundedFrameInDisplay.left; - info.frameTop = roundedFrameInDisplay.top; - info.frameRight = roundedFrameInDisplay.right; - info.frameBottom = roundedFrameInDisplay.bottom; + info.frame = getInputBoundsInDisplaySpace(inputBounds, screenToDisplay); ui::Transform inputToLayer; inputToLayer.set(inputBounds.left, inputBounds.top); diff --git a/services/surfaceflinger/LayerProtoHelper.cpp b/services/surfaceflinger/LayerProtoHelper.cpp index 1c7581b093..341f041086 100644 --- a/services/surfaceflinger/LayerProtoHelper.cpp +++ b/services/surfaceflinger/LayerProtoHelper.cpp @@ -185,8 +185,8 @@ void LayerProtoHelper::writeToProto( static_assert(std::is_same_v); proto->set_layout_params_type(static_cast(inputInfo.layoutParamsType)); - LayerProtoHelper::writeToProto({inputInfo.frameLeft, inputInfo.frameTop, inputInfo.frameRight, - inputInfo.frameBottom}, + LayerProtoHelper::writeToProto({inputInfo.frame.left, inputInfo.frame.top, + inputInfo.frame.right, inputInfo.frame.bottom}, [&]() { return proto->mutable_frame(); }); LayerProtoHelper::writeToProto(inputInfo.touchableRegion, [&]() { return proto->mutable_touchable_region(); }); -- cgit v1.2.3-59-g8ed1b From 494a2e40b6fb1d9703735aa518ed6283e6d026ca Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Fri, 10 Nov 2023 17:21:19 -0800 Subject: Added contentSize to WindowInfo In order to compute TPL using WindowInfoListener, it needs contentSize to know the original bounds vs the displayed bounds. This is to ensure the crop is factored in when computing percentage visible. Test: WindowInfo Bug: 290795410 Change-Id: Ic5a69d6ce9c4c436a63e51d7ce086960426d688b --- libs/gui/WindowInfo.cpp | 9 +++++++-- libs/gui/include/gui/WindowInfo.h | 4 ++++ libs/gui/tests/WindowInfo_test.cpp | 3 +++ services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp | 3 +++ services/surfaceflinger/Layer.cpp | 4 ++++ 5 files changed, 21 insertions(+), 2 deletions(-) (limited to 'libs/gui/WindowInfo.cpp') diff --git a/libs/gui/WindowInfo.cpp b/libs/gui/WindowInfo.cpp index 2eb6bd670d..6a4460b650 100644 --- a/libs/gui/WindowInfo.cpp +++ b/libs/gui/WindowInfo.cpp @@ -66,8 +66,9 @@ bool WindowInfo::overlaps(const WindowInfo* other) const { bool WindowInfo::operator==(const WindowInfo& info) const { return info.token == token && info.id == id && info.name == name && info.dispatchingTimeout == dispatchingTimeout && info.frame == frame && - info.surfaceInset == surfaceInset && info.globalScaleFactor == globalScaleFactor && - info.transform == transform && info.touchableRegion.hasSameRects(touchableRegion) && + info.contentSize == contentSize && info.surfaceInset == surfaceInset && + info.globalScaleFactor == globalScaleFactor && info.transform == transform && + info.touchableRegion.hasSameRects(touchableRegion) && info.touchOcclusionMode == touchOcclusionMode && info.ownerPid == ownerPid && info.ownerUid == ownerUid && info.packageName == packageName && info.inputConfig == inputConfig && info.displayId == displayId && @@ -101,6 +102,8 @@ status_t WindowInfo::writeToParcel(android::Parcel* parcel) const { parcel->writeInt32( static_cast>(layoutParamsType)) ?: parcel->write(frame) ?: + parcel->writeInt32(contentSize.width) ?: + parcel->writeInt32(contentSize.height) ?: parcel->writeInt32(surfaceInset) ?: parcel->writeFloat(globalScaleFactor) ?: parcel->writeFloat(alpha) ?: @@ -150,6 +153,8 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { status = parcel->readInt32(&lpFlags) ?: parcel->readInt32(&lpType) ?: parcel->read(frame) ?: + parcel->readInt32(&contentSize.width) ?: + parcel->readInt32(&contentSize.height) ?: parcel->readInt32(&surfaceInset) ?: parcel->readFloat(&globalScaleFactor) ?: parcel->readFloat(&alpha) ?: diff --git a/libs/gui/include/gui/WindowInfo.h b/libs/gui/include/gui/WindowInfo.h index bd2eb7413b..dcc38d7564 100644 --- a/libs/gui/include/gui/WindowInfo.h +++ b/libs/gui/include/gui/WindowInfo.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -196,6 +197,9 @@ struct WindowInfo : public Parcelable { /* These values are filled in by SurfaceFlinger. */ Rect frame = Rect::INVALID_RECT; + // The real size of the content, excluding any crop. If no buffer is rendered, this is 0,0 + ui::Size contentSize = ui::Size(0, 0); + /* * SurfaceFlinger consumes this value to shrink the computed frame. This is * different from shrinking the touchable region in that it DOES shift the coordinate diff --git a/libs/gui/tests/WindowInfo_test.cpp b/libs/gui/tests/WindowInfo_test.cpp index f2feaefa13..5eb5d3bff0 100644 --- a/libs/gui/tests/WindowInfo_test.cpp +++ b/libs/gui/tests/WindowInfo_test.cpp @@ -28,6 +28,7 @@ namespace android { using gui::InputApplicationInfo; using gui::TouchOcclusionMode; using gui::WindowInfo; +using ui::Size; namespace test { @@ -53,6 +54,7 @@ TEST(WindowInfo, Parcelling) { i.layoutParamsType = WindowInfo::Type::INPUT_METHOD; i.dispatchingTimeout = 12s; i.frame = Rect(93, 34, 16, 19); + i.contentSize = Size(10, 40); i.surfaceInset = 17; i.globalScaleFactor = 0.3; i.alpha = 0.7; @@ -83,6 +85,7 @@ TEST(WindowInfo, Parcelling) { ASSERT_EQ(i.layoutParamsType, i2.layoutParamsType); ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout); ASSERT_EQ(i.frame, i2.frame); + ASSERT_EQ(i.contentSize, i2.contentSize); ASSERT_EQ(i.surfaceInset, i2.surfaceInset); ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor); ASSERT_EQ(i.alpha, i2.alpha); diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp index 2a0857d4dd..9476ff4932 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp +++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp @@ -739,6 +739,7 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a !snapshot.changes.test(RequestedLayerState::Changes::Created)) { if (forceUpdate || snapshot.changes.any(RequestedLayerState::Changes::Geometry | + RequestedLayerState::Changes::BufferSize | RequestedLayerState::Changes::Input)) { updateInput(snapshot, requested, parentSnapshot, path, args); } @@ -1095,6 +1096,8 @@ void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot, snapshot.inputInfo.inputConfig |= gui::WindowInfo::InputConfig::TRUSTED_OVERLAY; } + snapshot.inputInfo.contentSize = snapshot.croppedBufferSize.getSize(); + // If the layer is a clone, we need to crop the input region to cloned root to prevent // touches from going outside the cloned area. if (path.isClone()) { diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 66ea15ca2d..3ca83e0c47 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -136,6 +136,7 @@ using frontend::RoundedCornerState; using gui::GameMode; using gui::LayerMetadata; using gui::WindowInfo; +using ui::Size; using PresentState = frametimeline::SurfaceFrame::PresentState; @@ -2591,6 +2592,9 @@ WindowInfo Layer::fillInputInfo(const InputDisplayArgs& displayArgs) { } } + Rect bufferSize = getBufferSize(getDrawingState()); + info.contentSize = Size(bufferSize.width(), bufferSize.height()); + return info; } -- cgit v1.2.3-59-g8ed1b From 366fb5bfcb2fd14504da9702759b431840bd0caf Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 6 Dec 2023 11:23:41 -0800 Subject: InputDispatcher: dump window in a separate function This makes it more convenient to dump windows from other places during debugging. For example, this could also be called from setInputWindows to inspect all of the window flags that might be changing. Bug: 312714754 Test: adb shell dumpsys input Change-Id: I2ace23bec1231f3a318e1b6a19f146b588e077b6 --- include/input/PrintTools.h | 8 ++++ libs/gui/WindowInfo.cpp | 55 ++++++++++++++++++++++ libs/gui/android/gui/TouchOcclusionMode.aidl | 3 +- libs/gui/include/gui/WindowInfo.h | 3 ++ .../inputflinger/dispatcher/InputDispatcher.cpp | 42 +++-------------- 5 files changed, 74 insertions(+), 37 deletions(-) (limited to 'libs/gui/WindowInfo.cpp') diff --git a/include/input/PrintTools.h b/include/input/PrintTools.h index 63c0e40e4e..83fffa37c6 100644 --- a/include/input/PrintTools.h +++ b/include/input/PrintTools.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -33,6 +34,13 @@ std::string bitsetToString(const std::bitset& bitset) { return bitset.to_string(); } +template +std::string streamableToString(const T& streamable) { + std::stringstream out; + out << streamable; + return out.str(); +} + template inline std::string constToString(const T& v) { return std::to_string(v); diff --git a/libs/gui/WindowInfo.cpp b/libs/gui/WindowInfo.cpp index 6a4460b650..ba1d196e9c 100644 --- a/libs/gui/WindowInfo.cpp +++ b/libs/gui/WindowInfo.cpp @@ -26,6 +26,41 @@ namespace android::gui { +namespace { + +std::ostream& operator<<(std::ostream& out, const sp& binder) { + if (binder == nullptr) { + out << ""; + } else { + out << binder.get(); + } + return out; +} + +std::ostream& operator<<(std::ostream& out, const Region& region) { + if (region.isEmpty()) { + out << ""; + return out; + } + + bool first = true; + Region::const_iterator cur = region.begin(); + Region::const_iterator const tail = region.end(); + while (cur != tail) { + if (first) { + first = false; + } else { + out << "|"; + } + out << "[" << cur->left << "," << cur->top << "][" << cur->right << "," << cur->bottom + << "]"; + cur++; + } + return out; +} + +} // namespace + void WindowInfo::setInputConfig(ftl::Flags config, bool value) { if (value) { inputConfig |= config; @@ -222,4 +257,24 @@ sp WindowInfoHandle::getToken() const { void WindowInfoHandle::updateFrom(sp handle) { mInfo = handle->mInfo; } + +std::ostream& operator<<(std::ostream& out, const WindowInfoHandle& window) { + const WindowInfo& info = *window.getInfo(); + std::string transform; + info.transform.dump(transform, "transform", " "); + out << "name=" << info.name << ", id=" << info.id << ", displayId=" << info.displayId + << ", inputConfig=" << info.inputConfig.string() << ", alpha=" << info.alpha << ", frame=[" + << info.frame.left << "," << info.frame.top << "][" << info.frame.right << "," + << info.frame.bottom << "], globalScale=" << info.globalScaleFactor + << ", applicationInfo.name=" << info.applicationInfo.name + << ", applicationInfo.token=" << info.applicationInfo.token + << ", touchableRegion=" << info.touchableRegion << ", ownerPid=" << info.ownerPid.toString() + << ", ownerUid=" << info.ownerUid.toString() << ", dispatchingTimeout=" + << std::chrono::duration_cast(info.dispatchingTimeout).count() + << "ms, token=" << info.token.get() + << ", touchOcclusionMode=" << ftl::enum_string(info.touchOcclusionMode) << "\n" + << transform; + return out; +} + } // namespace android::gui diff --git a/libs/gui/android/gui/TouchOcclusionMode.aidl b/libs/gui/android/gui/TouchOcclusionMode.aidl index d91d052135..ed721054df 100644 --- a/libs/gui/android/gui/TouchOcclusionMode.aidl +++ b/libs/gui/android/gui/TouchOcclusionMode.aidl @@ -43,5 +43,6 @@ enum TouchOcclusionMode { * The window won't count for touch occlusion rules if the touch passes * through it. */ - ALLOW + ALLOW, + ftl_last=ALLOW, } diff --git a/libs/gui/include/gui/WindowInfo.h b/libs/gui/include/gui/WindowInfo.h index dcc38d7564..4d4c5e4394 100644 --- a/libs/gui/include/gui/WindowInfo.h +++ b/libs/gui/include/gui/WindowInfo.h @@ -315,4 +315,7 @@ protected: WindowInfo mInfo; }; + +std::ostream& operator<<(std::ostream& out, const WindowInfoHandle& window); + } // namespace android::gui diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 1a94f41169..6033398b25 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -126,10 +126,6 @@ inline nsecs_t now() { return systemTime(SYSTEM_TIME_MONOTONIC); } -bool isEmpty(const std::stringstream& ss) { - return ss.rdbuf()->in_avail() == 0; -} - inline const std::string binderToString(const sp& binder) { if (binder == nullptr) { return ""; @@ -5129,7 +5125,7 @@ void InputDispatcher::setInputWindowsLocked( for (const sp& iwh : windowInfoHandles) { windowList += iwh->getName() + " "; } - ALOGD("setInputWindows displayId=%" PRId32 " %s", displayId, windowList.c_str()); + LOG(INFO) << "setInputWindows displayId=" << displayId << " " << windowList; } // Check preconditions for new input windows @@ -5687,33 +5683,8 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const { if (!windowHandles.empty()) { dump += INDENT2 "Windows:\n"; for (size_t i = 0; i < windowHandles.size(); i++) { - const sp& windowHandle = windowHandles[i]; - const WindowInfo* windowInfo = windowHandle->getInfo(); - - dump += StringPrintf(INDENT3 "%zu: name='%s', id=%" PRId32 ", displayId=%d, " - "inputConfig=%s, alpha=%.2f, " - "frame=[%d,%d][%d,%d], globalScale=%f, " - "applicationInfo.name=%s, " - "applicationInfo.token=%s, " - "touchableRegion=", - i, windowInfo->name.c_str(), windowInfo->id, - windowInfo->displayId, - windowInfo->inputConfig.string().c_str(), - windowInfo->alpha, windowInfo->frame.left, - windowInfo->frame.top, windowInfo->frame.right, - windowInfo->frame.bottom, windowInfo->globalScaleFactor, - windowInfo->applicationInfo.name.c_str(), - binderToString(windowInfo->applicationInfo.token).c_str()); - dump += dumpRegion(windowInfo->touchableRegion); - dump += StringPrintf(", ownerPid=%s, ownerUid=%s, dispatchingTimeout=%" PRId64 - "ms, hasToken=%s, " - "touchOcclusionMode=%s\n", - windowInfo->ownerPid.toString().c_str(), - windowInfo->ownerUid.toString().c_str(), - millis(windowInfo->dispatchingTimeout), - binderToString(windowInfo->token).c_str(), - toString(windowInfo->touchOcclusionMode).c_str()); - windowInfo->transform.dump(dump, "transform", INDENT4); + dump += StringPrintf(INDENT3 "%zu: %s", i, + streamableToString(*windowHandles[i]).c_str()); } } else { dump += INDENT2 "Windows: \n"; @@ -5802,11 +5773,10 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const { } else { dump += INDENT3 "WaitQueue: \n"; } - std::stringstream inputStateDump; - inputStateDump << connection->inputState; - if (!isEmpty(inputStateDump)) { + std::string inputStateDump = streamableToString(connection->inputState); + if (!inputStateDump.empty()) { dump += INDENT3 "InputState: "; - dump += inputStateDump.str() + "\n"; + dump += inputStateDump + "\n"; } } } else { -- cgit v1.2.3-59-g8ed1b