blob: 51fd90848644910d902ca15492e201dff0763f5a [file]
/*
* Copyright (C) 2026 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.
*/
#define LOG_TAG "OoprTransaction"
#include <binder/Parcel.h>
#include <com_android_graphics_libgui_flags.h>
#include <gui/LayerState.h>
#include <gui/OoprTransaction.h>
#include <log/log.h>
#include <private/gui/ParcelUtils.h>
namespace android::gui {
status_t OoprTransaction::HardwareBitmapBinding::writeToParcel(Parcel* output) const {
SAFE_PARCEL(output->writeUint64, id);
if (buffer != nullptr) {
SAFE_PARCEL(output->writeInt32, 1);
SAFE_PARCEL(output->write, *buffer);
} else {
SAFE_PARCEL(output->writeInt32, 0);
}
return NO_ERROR;
}
status_t OoprTransaction::HardwareBitmapBinding::readFromParcel(const Parcel* parcel) {
SAFE_PARCEL(parcel->readUint64, &id);
int32_t hasBuffer = 0;
SAFE_PARCEL(parcel->readInt32, &hasBuffer);
if (hasBuffer != 0) {
buffer = sp<GraphicBuffer>::make();
SAFE_PARCEL(parcel->read, *buffer);
} else {
buffer = nullptr;
}
return NO_ERROR;
}
status_t OoprTransaction::writeToParcel(Parcel* output) const {
if (!com_android_graphics_libgui_flags_out_of_process_rendering()) {
return NO_ERROR;
}
SAFE_PARCEL(output->writeStrongBinder, renderResourceToken);
SAFE_PARCEL(output->writeVectorSize, bitmapBindings);
for (const auto& binding : bitmapBindings) {
SAFE_PARCEL(binding.writeToParcel, output);
}
return NO_ERROR;
}
status_t OoprTransaction::readFromParcel(const Parcel* parcel) {
if (!com_android_graphics_libgui_flags_out_of_process_rendering()) {
return NO_ERROR;
}
SAFE_PARCEL(parcel->readNullableStrongBinder, &renderResourceToken);
int32_t count = 0;
SAFE_PARCEL_READ_SIZE(parcel->readInt32, &count, parcel->dataSize());
bitmapBindings.resize(static_cast<size_t>(count));
for (int32_t i = 0; i < count; i++) {
SAFE_PARCEL(bitmapBindings[static_cast<size_t>(i)].readFromParcel, parcel);
}
return NO_ERROR;
}
void OoprTransaction::sanitize(uint32_t permissions) {
if (empty()) {
return;
}
if (!(permissions & layer_state_t::Permission::ACCESS_OUT_OF_PROCESS_RENDERING)) {
ALOGW("Stripping out-of-process rendering (OOPR) transaction from a caller without the "
"ACCESS_OUT_OF_PROCESS_RENDERING permission");
renderResourceToken = nullptr;
bitmapBindings.clear();
}
}
} // namespace android::gui