blob: 2e6a93627f07fa85f37561e3cae8943e41473dc4 [file]
/*
* Copyright (C) 2025 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 "OoprServer OOPR"
#include <android/ipcrenderbuffer/OoprServer.h>
#include <log/log.h>
#include <cinttypes>
#include <android/ipcrenderbuffer/RenderBufferOps.h>
#include <gui/OoprTransaction.h>
#include <gui/TraceUtils.h>
namespace android {
OoprServer::OoprServer() = default;
OoprServer::~OoprServer() = default;
void OoprServer::handleOoprTransaction(const gui::OoprTransaction& transaction) {
ATRACE_CALL();
if (!transaction.renderResourceToken) {
ALOGE("handleOoprTransaction: transaction has no renderResourceToken!");
return;
}
std::shared_ptr<OoprServerCache> cache = getCache(transaction.renderResourceToken);
if (!cache) return;
std::lock_guard<std::mutex> lock(cache->mLock);
for (const auto& binding : transaction.bitmapBindings) {
if (!binding.buffer) {
ALOGE("handleOoprTransaction: binding id=%" PRIu64 " has null buffer!", binding.id);
continue;
}
ATRACE_FORMAT("OOPR_register_bitmap_binding %" PRIu64, binding.id);
cache->mPendingBitmapBindings[OoprBitmapHandle{binding.id}] = binding.buffer;
}
}
std::shared_ptr<OoprServerCache> OoprServer::getCache(const sp<IBinder>& token) {
ATRACE_CALL();
if (!token) return nullptr;
std::lock_guard<std::mutex> lock(mLock);
auto it = mCaches.find(token);
if (it != mCaches.end()) {
return it->second;
}
sp<DeathRecipient> recipient = sp<DeathRecipient>::fromExisting(this);
status_t status = token->linkToDeath(recipient);
if (status != OK) {
ALOGE("Failed to linkToDeath on cache token: %d. Refusing to create OoprServerCache.",
status);
return nullptr;
}
auto cache = std::make_shared<OoprServerCache>();
mCaches[token] = cache;
return cache;
}
void OoprServer::binderDied(const wp<IBinder>& binder) {
std::lock_guard<std::mutex> lock(mLock);
mCaches.erase(binder);
}
void drainOoprLayers(const std::vector<OoprLayer>& layers, OoprRenderFuncs funcs) {
for (const auto& layer : layers) {
if (!layer.cache) {
ALOGE("Layer is missing OOPR cache!");
continue;
}
drainRenderCommandBuffer(layer.cache.get(), layer.consumer.get(), layer.targetFrameId,
funcs);
}
}
} // namespace android