diff options
| author | 2021-11-11 18:46:56 -0800 | |
|---|---|---|
| committer | 2022-03-24 18:13:32 -0700 | |
| commit | 00571590663f73b7bfb659f78d6cc59473113a5a (patch) | |
| tree | 9377eef35b2a49fc47cb6bf6becb3f4c1fba933f /src | |
| parent | hle: nvflinger: Add implementation for ConsumerBase class. (diff) | |
| download | yuzu-00571590663f73b7bfb659f78d6cc59473113a5a.tar.gz yuzu-00571590663f73b7bfb659f78d6cc59473113a5a.tar.xz yuzu-00571590663f73b7bfb659f78d6cc59473113a5a.zip | |
hle: nvflinger: Add implementation for BufferItemConsumer class.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/hle/service/nvflinger/buffer_item_consumer.cpp | 59 | ||||
| -rw-r--r-- | src/core/hle/service/nvflinger/buffer_item_consumer.h | 26 |
3 files changed, 87 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 44d6b3cf7..78b1e68ea 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -539,6 +539,8 @@ add_library(core STATIC | |||
| 539 | hle/service/nvflinger/buffer_queue.h | 539 | hle/service/nvflinger/buffer_queue.h |
| 540 | hle/service/nvflinger/binder.h | 540 | hle/service/nvflinger/binder.h |
| 541 | hle/service/nvflinger/buffer_item.h | 541 | hle/service/nvflinger/buffer_item.h |
| 542 | hle/service/nvflinger/buffer_item_consumer.cpp | ||
| 543 | hle/service/nvflinger/buffer_item_consumer.h | ||
| 542 | hle/service/nvflinger/buffer_queue_defs.h | 544 | hle/service/nvflinger/buffer_queue_defs.h |
| 543 | hle/service/nvflinger/buffer_slot.h | 545 | hle/service/nvflinger/buffer_slot.h |
| 544 | hle/service/nvflinger/buffer_transform_flags.h | 546 | hle/service/nvflinger/buffer_transform_flags.h |
diff --git a/src/core/hle/service/nvflinger/buffer_item_consumer.cpp b/src/core/hle/service/nvflinger/buffer_item_consumer.cpp new file mode 100644 index 000000000..424b19d32 --- /dev/null +++ b/src/core/hle/service/nvflinger/buffer_item_consumer.cpp | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 2 | // Copyright 2021 yuzu Emulator Project | ||
| 3 | // Copyright 2012 The Android Open Source Project | ||
| 4 | // Parts of this implementation were base on: | ||
| 5 | // https://cs.android.com/android/platform/superproject/+/android-5.1.1_r38:frameworks/native/libs/gui/BufferItemConsumer.cpp | ||
| 6 | |||
| 7 | #include "common/assert.h" | ||
| 8 | #include "common/logging/log.h" | ||
| 9 | #include "core/hle/service/nvflinger/buffer_item.h" | ||
| 10 | #include "core/hle/service/nvflinger/buffer_item_consumer.h" | ||
| 11 | #include "core/hle/service/nvflinger/buffer_queue_consumer.h" | ||
| 12 | |||
| 13 | namespace android { | ||
| 14 | |||
| 15 | BufferItemConsumer::BufferItemConsumer(std::unique_ptr<BufferQueueConsumer> consumer_) | ||
| 16 | : ConsumerBase{std::move(consumer_)} {} | ||
| 17 | |||
| 18 | Status BufferItemConsumer::AcquireBuffer(BufferItem* item, u64 present_when_ns, | ||
| 19 | bool wait_for_fence) { | ||
| 20 | if (!item) { | ||
| 21 | return Status::BadValue; | ||
| 22 | } | ||
| 23 | |||
| 24 | std::unique_lock lock(mutex); | ||
| 25 | |||
| 26 | if (const auto status = AcquireBufferLocked(item, present_when_ns); status != Status::NoError) { | ||
| 27 | if (status != Status::NoBufferAvailable) { | ||
| 28 | LOG_ERROR(Service_NVFlinger, "Failed to acquire buffer: {}", status); | ||
| 29 | } | ||
| 30 | return status; | ||
| 31 | } | ||
| 32 | |||
| 33 | if (wait_for_fence) { | ||
| 34 | UNIMPLEMENTED(); | ||
| 35 | } | ||
| 36 | |||
| 37 | item->graphic_buffer = slots[item->slot].graphic_buffer; | ||
| 38 | |||
| 39 | return Status::NoError; | ||
| 40 | } | ||
| 41 | |||
| 42 | Status BufferItemConsumer::ReleaseBuffer(const BufferItem& item, Fence& release_fence) { | ||
| 43 | std::unique_lock lock(mutex); | ||
| 44 | |||
| 45 | if (const auto status = AddReleaseFenceLocked(item.buf, item.graphic_buffer, release_fence); | ||
| 46 | status != Status::NoError) { | ||
| 47 | LOG_ERROR(Service_NVFlinger, "Failed to add fence: {}", status); | ||
| 48 | } | ||
| 49 | |||
| 50 | if (const auto status = ReleaseBufferLocked(item.buf, item.graphic_buffer); | ||
| 51 | status != Status::NoError) { | ||
| 52 | LOG_WARNING(Service_NVFlinger, "Failed to release buffer: {}", status); | ||
| 53 | return status; | ||
| 54 | } | ||
| 55 | |||
| 56 | return Status::NoError; | ||
| 57 | } | ||
| 58 | |||
| 59 | } // namespace android | ||
diff --git a/src/core/hle/service/nvflinger/buffer_item_consumer.h b/src/core/hle/service/nvflinger/buffer_item_consumer.h new file mode 100644 index 000000000..f61c180b3 --- /dev/null +++ b/src/core/hle/service/nvflinger/buffer_item_consumer.h | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 2 | // Copyright 2021 yuzu Emulator Project | ||
| 3 | // Copyright 2012 The Android Open Source Project | ||
| 4 | // Parts of this implementation were base on: | ||
| 5 | // https://cs.android.com/android/platform/superproject/+/android-5.1.1_r38:frameworks/native/include/gui/BufferItemConsumer.h | ||
| 6 | |||
| 7 | #pragma once | ||
| 8 | |||
| 9 | #include <memory> | ||
| 10 | |||
| 11 | #include "common/common_types.h" | ||
| 12 | #include "core/hle/service/nvflinger/consumer_base.h" | ||
| 13 | #include "core/hle/service/nvflinger/status.h" | ||
| 14 | |||
| 15 | namespace android { | ||
| 16 | |||
| 17 | class BufferItem; | ||
| 18 | |||
| 19 | class BufferItemConsumer final : public ConsumerBase { | ||
| 20 | public: | ||
| 21 | explicit BufferItemConsumer(std::unique_ptr<BufferQueueConsumer> consumer); | ||
| 22 | Status AcquireBuffer(BufferItem* item, u64 present_when_ns, bool wait_for_fence = true); | ||
| 23 | Status ReleaseBuffer(const BufferItem& item, Fence& release_fence); | ||
| 24 | }; | ||
| 25 | |||
| 26 | } // namespace android | ||