Zero-initialize HIDL structs before passing
Test: atest CtsMediaTestCases -- --module-arg CtsMediaTestCases:size:small
(only existing failures/flakes)
Bug: 131267328
Bug: 131356202
Change-Id: I91e6e0c692d470f4d3a713068545cedf5ae925a7
diff --git a/libs/gui/bufferqueue/2.0/B2HGraphicBufferProducer.cpp b/libs/gui/bufferqueue/2.0/B2HGraphicBufferProducer.cpp
index e039593..e891ec5 100644
--- a/libs/gui/bufferqueue/2.0/B2HGraphicBufferProducer.cpp
+++ b/libs/gui/bufferqueue/2.0/B2HGraphicBufferProducer.cpp
@@ -15,7 +15,7 @@
*/
//#define LOG_NDEBUG 0
-#define LOG_TAG "H2BGraphicBufferProducer@2.0"
+#define LOG_TAG "B2HGraphicBufferProducer@2.0"
#include <android-base/logging.h>
@@ -30,13 +30,38 @@
#include <vndk/hardware_buffer.h>
namespace android {
-
namespace hardware {
namespace graphics {
namespace bufferqueue {
namespace V2_0 {
namespace utils {
+namespace /* unnamed */ {
+
+using BQueueBufferInput = ::android::
+ IGraphicBufferProducer::QueueBufferInput;
+using HQueueBufferInput = ::android::hardware::graphics::bufferqueue::V2_0::
+ IGraphicBufferProducer::QueueBufferInput;
+using BQueueBufferOutput = ::android::
+ IGraphicBufferProducer::QueueBufferOutput;
+using HQueueBufferOutput = ::android::hardware::graphics::bufferqueue::V2_0::
+ IGraphicBufferProducer::QueueBufferOutput;
+
+using ::android::hardware::graphics::bufferqueue::V2_0::utils::b2h;
+using ::android::hardware::graphics::bufferqueue::V2_0::utils::h2b;
+
+bool b2h(BQueueBufferOutput const& from, HQueueBufferOutput* to) {
+ to->width = from.width;
+ to->height = from.height;
+ to->transformHint = static_cast<int32_t>(from.transformHint);
+ to->numPendingBuffers = from.numPendingBuffers;
+ to->nextFrameNumber = from.nextFrameNumber;
+ to->bufferReplaced = from.bufferReplaced;
+ return true;
+}
+
+} // unnamed namespace
+
// B2HGraphicBufferProducer
// ========================
@@ -161,11 +186,7 @@
int32_t slot,
QueueBufferInput const& hInput,
queueBuffer_cb _hidl_cb) {
- using HOutput = QueueBufferOutput;
- using BInput = BGraphicBufferProducer::QueueBufferInput;
- using BOutput = BGraphicBufferProducer::QueueBufferOutput;
-
- BInput bInput{
+ BQueueBufferInput bInput{
hInput.timestamp,
hInput.isAutoTimestamp,
static_cast<android_dataspace>(hInput.dataSpace),
@@ -178,35 +199,32 @@
// Convert crop.
if (!h2b(hInput.crop, &bInput.crop)) {
- _hidl_cb(HStatus::UNKNOWN_ERROR, HOutput{});
+ _hidl_cb(HStatus::UNKNOWN_ERROR, QueueBufferOutput{});
return {};
}
// Convert surfaceDamage.
if (!h2b(hInput.surfaceDamage, &bInput.surfaceDamage)) {
- _hidl_cb(HStatus::UNKNOWN_ERROR, HOutput{});
+ _hidl_cb(HStatus::UNKNOWN_ERROR, QueueBufferOutput{});
return {};
}
// Convert fence.
if (!h2b(hInput.fence, &bInput.fence)) {
- _hidl_cb(HStatus::UNKNOWN_ERROR, HOutput{});
+ _hidl_cb(HStatus::UNKNOWN_ERROR, QueueBufferOutput{});
return {};
}
- BOutput bOutput{};
+ BQueueBufferOutput bOutput{};
HStatus hStatus{};
- bool converted = b2h(
- mBase->queueBuffer(static_cast<int>(slot), bInput, &bOutput),
- &hStatus);
+ QueueBufferOutput hOutput{};
+ bool converted =
+ b2h(
+ mBase->queueBuffer(static_cast<int>(slot), bInput, &bOutput),
+ &hStatus) &&
+ b2h(bOutput, &hOutput);
- _hidl_cb(converted ? hStatus : HStatus::UNKNOWN_ERROR,
- HOutput{bOutput.width,
- bOutput.height,
- static_cast<int32_t>(bOutput.transformHint),
- bOutput.numPendingBuffers,
- bOutput.nextFrameNumber,
- bOutput.bufferReplaced});
+ _hidl_cb(converted ? hStatus : HStatus::UNKNOWN_ERROR, hOutput);
return {};
}
@@ -236,33 +254,23 @@
HConnectionType hConnectionType,
bool producerControlledByApp,
connect_cb _hidl_cb) {
- using BOutput = BGraphicBufferProducer::QueueBufferOutput;
- using HOutput = HGraphicBufferProducer::QueueBufferOutput;
sp<BProducerListener> bListener = new H2BProducerListener(hListener);
- if (!bListener) {
- _hidl_cb(HStatus::UNKNOWN_ERROR, HOutput{});
+ int bConnectionType{};
+ if (!bListener || !h2b(hConnectionType, &bConnectionType)) {
+ _hidl_cb(HStatus::UNKNOWN_ERROR, QueueBufferOutput{});
return {};
}
- int bConnectionType;
- if (!h2b(hConnectionType, &bConnectionType)) {
- _hidl_cb(HStatus::UNKNOWN_ERROR, HOutput{});
- return {};
- }
- BOutput bOutput{};
+ BQueueBufferOutput bOutput{};
HStatus hStatus{};
- bool converted = b2h(
- mBase->connect(bListener,
- bConnectionType,
- producerControlledByApp,
- &bOutput),
- &hStatus);
- _hidl_cb(converted ? hStatus : HStatus::UNKNOWN_ERROR,
- HOutput{bOutput.width,
- bOutput.height,
- static_cast<int32_t>(bOutput.transformHint),
- bOutput.numPendingBuffers,
- bOutput.nextFrameNumber,
- bOutput.bufferReplaced});
+ QueueBufferOutput hOutput{};
+ bool converted =
+ b2h(mBase->connect(bListener,
+ bConnectionType,
+ producerControlledByApp,
+ &bOutput),
+ &hStatus) &&
+ b2h(bOutput, &hOutput);
+ _hidl_cb(converted ? hStatus : HStatus::UNKNOWN_ERROR, hOutput);
return {};
}