diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2023-03-04 04:51:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-04 04:51:17 +0100 |
commit | ce8f4da63834be0179d98a7720dee47d65f3ec06 (patch) | |
tree | a9a9303a532d374db9ae8255e5f3f2487e370f84 /src/core/hle/service/nvnflinger/buffer_item_consumer.cpp | |
parent | Merge pull request #9855 from liamwhite/kern-16-support (diff) | |
parent | nvnflinger: fix name (diff) | |
download | yuzu-ce8f4da63834be0179d98a7720dee47d65f3ec06.tar yuzu-ce8f4da63834be0179d98a7720dee47d65f3ec06.tar.gz yuzu-ce8f4da63834be0179d98a7720dee47d65f3ec06.tar.bz2 yuzu-ce8f4da63834be0179d98a7720dee47d65f3ec06.tar.lz yuzu-ce8f4da63834be0179d98a7720dee47d65f3ec06.tar.xz yuzu-ce8f4da63834be0179d98a7720dee47d65f3ec06.tar.zst yuzu-ce8f4da63834be0179d98a7720dee47d65f3ec06.zip |
Diffstat (limited to 'src/core/hle/service/nvnflinger/buffer_item_consumer.cpp')
-rw-r--r-- | src/core/hle/service/nvnflinger/buffer_item_consumer.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/core/hle/service/nvnflinger/buffer_item_consumer.cpp b/src/core/hle/service/nvnflinger/buffer_item_consumer.cpp new file mode 100644 index 000000000..cf151ea3a --- /dev/null +++ b/src/core/hle/service/nvnflinger/buffer_item_consumer.cpp @@ -0,0 +1,59 @@ +// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2012 The Android Open Source Project +// SPDX-License-Identifier: GPL-3.0-or-later +// Parts of this implementation were based on: +// https://cs.android.com/android/platform/superproject/+/android-5.1.1_r38:frameworks/native/libs/gui/BufferItemConsumer.cpp + +#include "common/assert.h" +#include "common/logging/log.h" +#include "core/hle/service/nvnflinger/buffer_item.h" +#include "core/hle/service/nvnflinger/buffer_item_consumer.h" +#include "core/hle/service/nvnflinger/buffer_queue_consumer.h" + +namespace Service::android { + +BufferItemConsumer::BufferItemConsumer(std::unique_ptr<BufferQueueConsumer> consumer_) + : ConsumerBase{std::move(consumer_)} {} + +Status BufferItemConsumer::AcquireBuffer(BufferItem* item, std::chrono::nanoseconds present_when, + bool wait_for_fence) { + if (!item) { + return Status::BadValue; + } + + std::scoped_lock lock{mutex}; + + if (const auto status = AcquireBufferLocked(item, present_when); status != Status::NoError) { + if (status != Status::NoBufferAvailable) { + LOG_ERROR(Service_Nvnflinger, "Failed to acquire buffer: {}", status); + } + return status; + } + + if (wait_for_fence) { + UNIMPLEMENTED(); + } + + item->graphic_buffer = slots[item->slot].graphic_buffer; + + return Status::NoError; +} + +Status BufferItemConsumer::ReleaseBuffer(const BufferItem& item, const Fence& release_fence) { + std::scoped_lock lock{mutex}; + + if (const auto status = AddReleaseFenceLocked(item.buf, item.graphic_buffer, release_fence); + status != Status::NoError) { + LOG_ERROR(Service_Nvnflinger, "Failed to add fence: {}", status); + } + + if (const auto status = ReleaseBufferLocked(item.buf, item.graphic_buffer); + status != Status::NoError) { + LOG_WARNING(Service_Nvnflinger, "Failed to release buffer: {}", status); + return status; + } + + return Status::NoError; +} + +} // namespace Service::android |