Move CaptureArgs + friends to structured aidl
No more manual parceling!
Bug: 329465218
Flag: EXEMPT mechanical refactor
Test: builds
Test: courage
Change-Id: I9f5eba12db615d6b02de0686193381f7a63bb043
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index 0714fd9..b109969 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -892,88 +892,6 @@
// ----------------------------------------------------------------------------
-namespace gui {
-
-status_t CaptureArgs::writeToParcel(Parcel* output) const {
- SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
- SAFE_PARCEL(output->write, sourceCrop);
- SAFE_PARCEL(output->writeFloat, frameScaleX);
- SAFE_PARCEL(output->writeFloat, frameScaleY);
- SAFE_PARCEL(output->writeBool, captureSecureLayers);
- SAFE_PARCEL(output->writeInt32, uid);
- SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
- SAFE_PARCEL(output->writeBool, allowProtected);
- SAFE_PARCEL(output->writeBool, grayscale);
- SAFE_PARCEL(output->writeInt32, excludeHandles.size());
- for (auto& excludeHandle : excludeHandles) {
- SAFE_PARCEL(output->writeStrongBinder, excludeHandle);
- }
- SAFE_PARCEL(output->writeBool, hintForSeamlessTransition);
- return NO_ERROR;
-}
-
-status_t CaptureArgs::readFromParcel(const Parcel* input) {
- int32_t value = 0;
- SAFE_PARCEL(input->readInt32, &value);
- pixelFormat = static_cast<ui::PixelFormat>(value);
- SAFE_PARCEL(input->read, sourceCrop);
- SAFE_PARCEL(input->readFloat, &frameScaleX);
- SAFE_PARCEL(input->readFloat, &frameScaleY);
- SAFE_PARCEL(input->readBool, &captureSecureLayers);
- SAFE_PARCEL(input->readInt32, &uid);
- SAFE_PARCEL(input->readInt32, &value);
- dataspace = static_cast<ui::Dataspace>(value);
- SAFE_PARCEL(input->readBool, &allowProtected);
- SAFE_PARCEL(input->readBool, &grayscale);
- int32_t numExcludeHandles = 0;
- SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
- excludeHandles.reserve(numExcludeHandles);
- for (int i = 0; i < numExcludeHandles; i++) {
- sp<IBinder> binder;
- SAFE_PARCEL(input->readStrongBinder, &binder);
- excludeHandles.emplace(binder);
- }
- SAFE_PARCEL(input->readBool, &hintForSeamlessTransition);
- return NO_ERROR;
-}
-
-status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
- SAFE_PARCEL(CaptureArgs::writeToParcel, output);
-
- SAFE_PARCEL(output->writeStrongBinder, displayToken);
- SAFE_PARCEL(output->writeUint32, width);
- SAFE_PARCEL(output->writeUint32, height);
- return NO_ERROR;
-}
-
-status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
- SAFE_PARCEL(CaptureArgs::readFromParcel, input);
-
- SAFE_PARCEL(input->readStrongBinder, &displayToken);
- SAFE_PARCEL(input->readUint32, &width);
- SAFE_PARCEL(input->readUint32, &height);
- return NO_ERROR;
-}
-
-status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
- SAFE_PARCEL(CaptureArgs::writeToParcel, output);
-
- SAFE_PARCEL(output->writeStrongBinder, layerHandle);
- SAFE_PARCEL(output->writeBool, childrenOnly);
- return NO_ERROR;
-}
-
-status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
- SAFE_PARCEL(CaptureArgs::readFromParcel, input);
-
- SAFE_PARCEL(input->readStrongBinder, &layerHandle);
-
- SAFE_PARCEL(input->readBool, &childrenOnly);
- return NO_ERROR;
-}
-
-}; // namespace gui
-
ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
uint64_t bufferId;
if (buffer) {
diff --git a/libs/gui/aidl/Android.bp b/libs/gui/aidl/Android.bp
index 8ed08c2..fd035f6 100644
--- a/libs/gui/aidl/Android.bp
+++ b/libs/gui/aidl/Android.bp
@@ -28,9 +28,6 @@
":libgui_extra_unstructured_aidl_files",
"android/gui/BitTube.aidl",
- "android/gui/CaptureArgs.aidl",
- "android/gui/DisplayCaptureArgs.aidl",
- "android/gui/LayerCaptureArgs.aidl",
"android/gui/LayerMetadata.aidl",
"android/gui/ParcelableVsyncEventData.aidl",
"android/gui/ScreenCaptureResults.aidl",
diff --git a/libs/gui/aidl/android/gui/CaptureArgs.aidl b/libs/gui/aidl/android/gui/CaptureArgs.aidl
index 9f198ca..2bbed2b 100644
--- a/libs/gui/aidl/android/gui/CaptureArgs.aidl
+++ b/libs/gui/aidl/android/gui/CaptureArgs.aidl
@@ -16,4 +16,58 @@
package android.gui;
-parcelable CaptureArgs cpp_header "gui/DisplayCaptureArgs.h" rust_type "gui_aidl_types_rs::CaptureArgs";
+import android.gui.ARect;
+
+// Common arguments for capturing content on-screen
+parcelable CaptureArgs {
+ const int UNSET_UID = -1;
+
+ // Desired pixel format of the final screenshotted buffer
+ int /*ui::PixelFormat*/ pixelFormat = 1;
+
+ // Crop in layer space: all content outside of the crop will not be captured.
+ ARect sourceCrop;
+
+ // Scale in the x-direction for the screenshotted result.
+ float frameScaleX = 1.0f;
+
+ // Scale in the y-direction for the screenshotted result.
+ float frameScaleY = 1.0f;
+
+ // True if capturing secure layers is permitted
+ boolean captureSecureLayers = false;
+
+ // UID whose content we want to screenshot
+ int uid = UNSET_UID;
+
+ // Force capture to be in a color space. If the value is ui::Dataspace::UNKNOWN, the captured
+ // result will be in a colorspace appropriate for capturing the display contents
+ // The display may use non-RGB dataspace (ex. displayP3) that could cause pixel data could be
+ // different from SRGB (byte per color), and failed when checking colors in tests.
+ // NOTE: In normal cases, we want the screen to be captured in display's colorspace.
+ int /*ui::Dataspace*/ dataspace = 0;
+
+ // The receiver of the capture can handle protected buffer. A protected buffer has
+ // GRALLOC_USAGE_PROTECTED usage bit and must not be accessed unprotected behaviour.
+ // Any read/write access from unprotected context will result in undefined behaviour.
+ // Protected contents are typically DRM contents. This has no direct implication to the
+ // secure property of the surface, which is specified by the application explicitly to avoid
+ // the contents being accessed/captured by screenshot or unsecure display.
+ boolean allowProtected = false;
+
+ // True if the content should be captured in grayscale
+ boolean grayscale = false;
+
+ // List of layers to exclude capturing from
+ IBinder[] excludeHandles;
+
+ // Hint that the caller will use the screenshot animation as part of a transition animation.
+ // The canonical example would be screen rotation - in such a case any color shift in the
+ // screenshot is a detractor so composition in the display's colorspace is required.
+ // Otherwise, the system may choose a colorspace that is more appropriate for use-cases
+ // such as file encoding or for blending HDR content into an ap's UI, where the display's
+ // exact colorspace is not an appropriate intermediate result.
+ // Note that if the caller is requesting a specific dataspace, this hint does nothing.
+ boolean hintForSeamlessTransition = false;
+}
+
diff --git a/libs/gui/aidl/android/gui/DisplayCaptureArgs.aidl b/libs/gui/aidl/android/gui/DisplayCaptureArgs.aidl
index fc97dbf..e00a2df 100644
--- a/libs/gui/aidl/android/gui/DisplayCaptureArgs.aidl
+++ b/libs/gui/aidl/android/gui/DisplayCaptureArgs.aidl
@@ -16,5 +16,18 @@
package android.gui;
-parcelable DisplayCaptureArgs cpp_header "gui/DisplayCaptureArgs.h" rust_type "gui_aidl_types_rs::DisplayCaptureArgs";
+import android.gui.CaptureArgs;
+
+// Arguments for screenshotting an entire display
+parcelable DisplayCaptureArgs {
+ CaptureArgs captureArgs;
+
+ // The display that we want to screenshot
+ IBinder displayToken;
+
+ // The width of the render area when we screenshot
+ int width = 0;
+ // The length of the render area when we screenshot
+ int height = 0;
+}
diff --git a/libs/gui/aidl/android/gui/LayerCaptureArgs.aidl b/libs/gui/aidl/android/gui/LayerCaptureArgs.aidl
index 18d293f..004c35a 100644
--- a/libs/gui/aidl/android/gui/LayerCaptureArgs.aidl
+++ b/libs/gui/aidl/android/gui/LayerCaptureArgs.aidl
@@ -16,4 +16,15 @@
package android.gui;
-parcelable LayerCaptureArgs cpp_header "gui/LayerCaptureArgs.h" rust_type "gui_aidl_types_rs::LayerCaptureArgs";
+import android.gui.CaptureArgs;
+
+// Arguments for capturing a layer and/or its children
+parcelable LayerCaptureArgs {
+ CaptureArgs captureArgs;
+
+ // The Layer that we may want to capture. We would also capture its children
+ IBinder layerHandle;
+ // True if we don't actually want to capture the layer and want to capture
+ // its children instead.
+ boolean childrenOnly = false;
+}
diff --git a/libs/gui/include/gui/AidlStatusUtil.h b/libs/gui/include/gui/AidlStatusUtil.h
index 55be27b..159e032 100644
--- a/libs/gui/include/gui/AidlStatusUtil.h
+++ b/libs/gui/include/gui/AidlStatusUtil.h
@@ -16,9 +16,11 @@
#pragma once
+#include <android/gui/ARect.h>
#include <binder/Status.h>
+#include <ui/Rect.h>
-// Extracted from frameworks/av/media/libaudioclient/include/media/AidlConversionUtil.h
+// Originally extracted from frameworks/av/media/libaudioclient/include/media/AidlConversionUtil.h
namespace android::gui::aidl_utils {
/**
@@ -111,4 +113,26 @@
return Status::fromServiceSpecificError(status, emptyIfNull);
}
+static inline Rect fromARect(ARect rect) {
+ return Rect(rect.left, rect.top, rect.right, rect.bottom);
+}
+
+static inline ARect toARect(Rect rect) {
+ ARect aRect;
+
+ aRect.left = rect.left;
+ aRect.top = rect.top;
+ aRect.right = rect.right;
+ aRect.bottom = rect.bottom;
+ return aRect;
+}
+
+static inline ARect toARect(int32_t left, int32_t top, int32_t right, int32_t bottom) {
+ return toARect(Rect(left, top, right, bottom));
+}
+
+static inline ARect toARect(int32_t width, int32_t height) {
+ return toARect(Rect(width, height));
+}
+
} // namespace android::gui::aidl_utils
diff --git a/libs/gui/include/gui/DisplayCaptureArgs.h b/libs/gui/include/gui/DisplayCaptureArgs.h
deleted file mode 100644
index e29ce41..0000000
--- a/libs/gui/include/gui/DisplayCaptureArgs.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <binder/IBinder.h>
-#include <binder/Parcel.h>
-#include <binder/Parcelable.h>
-#include <gui/SpHash.h>
-#include <ui/GraphicTypes.h>
-#include <ui/PixelFormat.h>
-#include <ui/Rect.h>
-#include <unordered_set>
-
-namespace android::gui {
-
-struct CaptureArgs : public Parcelable {
- const static int32_t UNSET_UID = -1;
- virtual ~CaptureArgs() = default;
-
- ui::PixelFormat pixelFormat{ui::PixelFormat::RGBA_8888};
- Rect sourceCrop;
- float frameScaleX{1};
- float frameScaleY{1};
- bool captureSecureLayers{false};
- int32_t uid{UNSET_UID};
- // Force capture to be in a color space. If the value is ui::Dataspace::UNKNOWN, the captured
- // result will be in a colorspace appropriate for capturing the display contents
- // The display may use non-RGB dataspace (ex. displayP3) that could cause pixel data could be
- // different from SRGB (byte per color), and failed when checking colors in tests.
- // NOTE: In normal cases, we want the screen to be captured in display's colorspace.
- ui::Dataspace dataspace = ui::Dataspace::UNKNOWN;
-
- // The receiver of the capture can handle protected buffer. A protected buffer has
- // GRALLOC_USAGE_PROTECTED usage bit and must not be accessed unprotected behaviour.
- // Any read/write access from unprotected context will result in undefined behaviour.
- // Protected contents are typically DRM contents. This has no direct implication to the
- // secure property of the surface, which is specified by the application explicitly to avoid
- // the contents being accessed/captured by screenshot or unsecure display.
- bool allowProtected = false;
-
- bool grayscale = false;
-
- std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
-
- // Hint that the caller will use the screenshot animation as part of a transition animation.
- // The canonical example would be screen rotation - in such a case any color shift in the
- // screenshot is a detractor so composition in the display's colorspace is required.
- // Otherwise, the system may choose a colorspace that is more appropriate for use-cases
- // such as file encoding or for blending HDR content into an ap's UI, where the display's
- // exact colorspace is not an appropriate intermediate result.
- // Note that if the caller is requesting a specific dataspace, this hint does nothing.
- bool hintForSeamlessTransition = false;
-
- virtual status_t writeToParcel(Parcel* output) const;
- virtual status_t readFromParcel(const Parcel* input);
-};
-
-struct DisplayCaptureArgs : CaptureArgs {
- sp<IBinder> displayToken;
- uint32_t width{0};
- uint32_t height{0};
-
- status_t writeToParcel(Parcel* output) const override;
- status_t readFromParcel(const Parcel* input) override;
-};
-
-}; // namespace android::gui
diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h
index 1ecc216..9a422fd 100644
--- a/libs/gui/include/gui/ISurfaceComposer.h
+++ b/libs/gui/include/gui/ISurfaceComposer.h
@@ -18,6 +18,7 @@
#include <android/gui/CachingHint.h>
#include <android/gui/DisplayBrightness.h>
+#include <android/gui/DisplayCaptureArgs.h>
#include <android/gui/FrameTimelineInfo.h>
#include <android/gui/IDisplayEventConnection.h>
#include <android/gui/IFpsListener.h>
@@ -27,6 +28,7 @@
#include <android/gui/ITunnelModeEnabledListener.h>
#include <android/gui/IWindowInfosListener.h>
#include <android/gui/IWindowInfosPublisher.h>
+#include <android/gui/LayerCaptureArgs.h>
#include <binder/IBinder.h>
#include <binder/IInterface.h>
#include <gui/ITransactionCompletedListener.h>
@@ -70,13 +72,6 @@
using gui::IScreenCaptureListener;
using gui::SpHash;
-namespace gui {
-
-struct DisplayCaptureArgs;
-struct LayerCaptureArgs;
-
-} // namespace gui
-
namespace ui {
struct DisplayMode;
diff --git a/libs/gui/include/gui/LayerCaptureArgs.h b/libs/gui/include/gui/LayerCaptureArgs.h
deleted file mode 100644
index fae2bcc..0000000
--- a/libs/gui/include/gui/LayerCaptureArgs.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <gui/DisplayCaptureArgs.h>
-
-namespace android::gui {
-
-struct LayerCaptureArgs : CaptureArgs {
- sp<IBinder> layerHandle;
- bool childrenOnly{false};
-
- status_t writeToParcel(Parcel* output) const override;
- status_t readFromParcel(const Parcel* input) override;
-};
-
-}; // namespace android::gui
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index d419945..2cdde32 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -21,7 +21,9 @@
#include <stdint.h>
#include <sys/types.h>
+#include <android/gui/DisplayCaptureArgs.h>
#include <android/gui/IWindowInfosReportedListener.h>
+#include <android/gui/LayerCaptureArgs.h>
#include <android/gui/TrustedPresentationThresholds.h>
#include <android/native_window.h>
#include <gui/IGraphicBufferProducer.h>
@@ -35,9 +37,7 @@
#include <ftl/flags.h>
#include <gui/BufferReleaseChannel.h>
-#include <gui/DisplayCaptureArgs.h>
#include <gui/ISurfaceComposer.h>
-#include <gui/LayerCaptureArgs.h>
#include <gui/LayerMetadata.h>
#include <gui/SpHash.h>
#include <gui/SurfaceControl.h>
diff --git a/libs/gui/rust/aidl_types/src/lib.rs b/libs/gui/rust/aidl_types/src/lib.rs
index fead018..2351df0 100644
--- a/libs/gui/rust/aidl_types/src/lib.rs
+++ b/libs/gui/rust/aidl_types/src/lib.rs
@@ -42,10 +42,7 @@
}
stub_unstructured_parcelable!(BitTube);
-stub_unstructured_parcelable!(CaptureArgs);
-stub_unstructured_parcelable!(DisplayCaptureArgs);
stub_unstructured_parcelable!(DisplayInfo);
-stub_unstructured_parcelable!(LayerCaptureArgs);
stub_unstructured_parcelable!(LayerDebugInfo);
stub_unstructured_parcelable!(LayerMetadata);
stub_unstructured_parcelable!(ParcelableVsyncEventData);
diff --git a/libs/gui/tests/BLASTBufferQueue_test.cpp b/libs/gui/tests/BLASTBufferQueue_test.cpp
index 6852589..46a19c2 100644
--- a/libs/gui/tests/BLASTBufferQueue_test.cpp
+++ b/libs/gui/tests/BLASTBufferQueue_test.cpp
@@ -229,7 +229,8 @@
ISurfaceComposerClient::eFXSurfaceBufferState,
/*parent*/ mRootSurfaceControl->getHandle());
- mCaptureArgs.sourceCrop = Rect(ui::Size(mDisplayWidth, mDisplayHeight));
+ mCaptureArgs.captureArgs.sourceCrop =
+ gui::aidl_utils::toARect(mDisplayWidth, mDisplayHeight);
mCaptureArgs.layerHandle = mRootSurfaceControl->getHandle();
}