From 9f0835e72949f7ed0d7df35960047931a2051a2c Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Fri, 7 Jan 2022 09:33:19 -0800 Subject: SF: Make BufferData mockable Expose GraphicBuffer properties through the BufferData class so we can inject fake GraphicBuffers in transactions. This is required to recreate layer state from transaction traces without actually allocating buffers. Test: compiles Bug: 200284593 Change-Id: I74036cba1f544cbd045489fa5337d59ae4bdebcb --- libs/gui/LayerState.cpp | 57 ++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'libs/gui/LayerState.cpp') diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp index acd9ac5a93..27d86bb4e2 100644 --- a/libs/gui/LayerState.cpp +++ b/libs/gui/LayerState.cpp @@ -153,7 +153,8 @@ status_t layer_state_t::write(Parcel& output) const SAFE_PARCEL(output.writeBool, isTrustedOverlay); SAFE_PARCEL(output.writeUint32, static_cast(dropInputMode)); - SAFE_PARCEL(bufferData.write, output); + SAFE_PARCEL(output.writeNullableParcelable, + bufferData ? std::make_optional(*bufferData) : std::nullopt); return NO_ERROR; } @@ -263,7 +264,9 @@ status_t layer_state_t::read(const Parcel& input) uint32_t mode; SAFE_PARCEL(input.readUint32, &mode); dropInputMode = static_cast(mode); - SAFE_PARCEL(bufferData.read, input); + std::optional tmpBufferData; + SAFE_PARCEL(input.readParcelable, &tmpBufferData); + bufferData = tmpBufferData ? std::make_shared(*tmpBufferData) : nullptr; return NO_ERROR; } @@ -518,7 +521,7 @@ bool layer_state_t::hasBufferChanges() const { } bool layer_state_t::hasValidBuffer() const { - return bufferData.buffer || bufferData.cachedBuffer.isValid(); + return bufferData && (bufferData->buffer || bufferData->cachedBuffer.isValid()); } status_t layer_state_t::matrix22_t::write(Parcel& output) const { @@ -681,64 +684,64 @@ ReleaseCallbackId BufferData::generateReleaseCallbackId() const { return {buffer->getId(), frameNumber}; } -status_t BufferData::write(Parcel& output) const { - SAFE_PARCEL(output.writeInt32, flags.get()); +status_t BufferData::writeToParcel(Parcel* output) const { + SAFE_PARCEL(output->writeInt32, flags.get()); if (buffer) { - SAFE_PARCEL(output.writeBool, true); - SAFE_PARCEL(output.write, *buffer); + SAFE_PARCEL(output->writeBool, true); + SAFE_PARCEL(output->write, *buffer); } else { - SAFE_PARCEL(output.writeBool, false); + SAFE_PARCEL(output->writeBool, false); } if (acquireFence) { - SAFE_PARCEL(output.writeBool, true); - SAFE_PARCEL(output.write, *acquireFence); + SAFE_PARCEL(output->writeBool, true); + SAFE_PARCEL(output->write, *acquireFence); } else { - SAFE_PARCEL(output.writeBool, false); + SAFE_PARCEL(output->writeBool, false); } - SAFE_PARCEL(output.writeUint64, frameNumber); - SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(releaseBufferListener)); - SAFE_PARCEL(output.writeStrongBinder, releaseBufferEndpoint); + SAFE_PARCEL(output->writeUint64, frameNumber); + SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener)); + SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint); - SAFE_PARCEL(output.writeStrongBinder, cachedBuffer.token.promote()); - SAFE_PARCEL(output.writeUint64, cachedBuffer.id); + SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote()); + SAFE_PARCEL(output->writeUint64, cachedBuffer.id); return NO_ERROR; } -status_t BufferData::read(const Parcel& input) { +status_t BufferData::readFromParcel(const Parcel* input) { int32_t tmpInt32; - SAFE_PARCEL(input.readInt32, &tmpInt32); + SAFE_PARCEL(input->readInt32, &tmpInt32); flags = Flags(tmpInt32); bool tmpBool = false; - SAFE_PARCEL(input.readBool, &tmpBool); + SAFE_PARCEL(input->readBool, &tmpBool); if (tmpBool) { buffer = new GraphicBuffer(); - SAFE_PARCEL(input.read, *buffer); + SAFE_PARCEL(input->read, *buffer); } - SAFE_PARCEL(input.readBool, &tmpBool); + SAFE_PARCEL(input->readBool, &tmpBool); if (tmpBool) { acquireFence = new Fence(); - SAFE_PARCEL(input.read, *acquireFence); + SAFE_PARCEL(input->read, *acquireFence); } - SAFE_PARCEL(input.readUint64, &frameNumber); + SAFE_PARCEL(input->readUint64, &frameNumber); sp tmpBinder = nullptr; - SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder); + SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder); if (tmpBinder) { releaseBufferListener = checked_interface_cast(tmpBinder); } - SAFE_PARCEL(input.readNullableStrongBinder, &releaseBufferEndpoint); + SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint); tmpBinder = nullptr; - SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder); + SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder); cachedBuffer.token = tmpBinder; - SAFE_PARCEL(input.readUint64, &cachedBuffer.id); + SAFE_PARCEL(input->readUint64, &cachedBuffer.id); return NO_ERROR; } -- cgit v1.2.3-59-g8ed1b