summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2021-11-11 18:11:32 -0800
committerGravatar bunnei2022-03-24 18:13:32 -0700
commit5a8b9a97062d6dbd64f4401036a3a4445ed4fe1b (patch)
treee604b8caa28839f4f14c785e780c799d90a69f5f
parenthle: nvflinger: Add implementation for Fence class. (diff)
downloadyuzu-5a8b9a97062d6dbd64f4401036a3a4445ed4fe1b.tar.gz
yuzu-5a8b9a97062d6dbd64f4401036a3a4445ed4fe1b.tar.xz
yuzu-5a8b9a97062d6dbd64f4401036a3a4445ed4fe1b.zip
hle: nvflinger: Add implementation for GraphicBuffer class.
-rw-r--r--src/core/CMakeLists.txt1
-rw-r--r--src/core/hle/service/nvflinger/ui/graphic_buffer.h100
2 files changed, 101 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 6cca114db..5e9b959a5 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -541,6 +541,7 @@ add_library(core STATIC
541 hle/service/nvflinger/nvflinger.h 541 hle/service/nvflinger/nvflinger.h
542 hle/service/nvflinger/status.h 542 hle/service/nvflinger/status.h
543 hle/service/nvflinger/ui/fence.h 543 hle/service/nvflinger/ui/fence.h
544 hle/service/nvflinger/ui/graphic_buffer.h
544 hle/service/nvflinger/ui/rect.h 545 hle/service/nvflinger/ui/rect.h
545 hle/service/olsc/olsc.cpp 546 hle/service/olsc/olsc.cpp
546 hle/service/olsc/olsc.h 547 hle/service/olsc/olsc.h
diff --git a/src/core/hle/service/nvflinger/ui/graphic_buffer.h b/src/core/hle/service/nvflinger/ui/graphic_buffer.h
new file mode 100644
index 000000000..c1e54d9ed
--- /dev/null
+++ b/src/core/hle/service/nvflinger/ui/graphic_buffer.h
@@ -0,0 +1,100 @@
1// SPDX-License-Identifier: GPL-3.0-or-later
2// Copyright 2021 yuzu Emulator Project
3// Copyright 2007 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/ui/GraphicBuffer.h
6
7#pragma once
8
9#include "common/common_funcs.h"
10#include "common/common_types.h"
11#include "core/hle/service/nvflinger/pixel_format.h"
12
13namespace android {
14
15class GraphicBuffer final {
16public:
17 constexpr GraphicBuffer() = default;
18
19 constexpr GraphicBuffer(u32 width_, u32 height_, PixelFormat format_, u32 usage_)
20 : width{static_cast<s32>(width_)}, height{static_cast<s32>(height_)}, format{format_},
21 usage{static_cast<s32>(usage_)} {}
22
23 constexpr u32 Width() const {
24 return static_cast<u32>(width);
25 }
26
27 constexpr u32 Height() const {
28 return static_cast<u32>(height);
29 }
30
31 constexpr u32 Stride() const {
32 return static_cast<u32>(stride);
33 }
34
35 constexpr u32 Usage() const {
36 return static_cast<u32>(usage);
37 }
38
39 constexpr PixelFormat Format() const {
40 return format;
41 }
42
43 constexpr u32 BufferId() const {
44 return buffer_id;
45 }
46
47 constexpr u32 ExternalFormat() const {
48 return external_format;
49 }
50
51 constexpr u32 Handle() const {
52 return handle;
53 }
54
55 constexpr u32 Offset() const {
56 return offset;
57 }
58
59 constexpr bool NeedsReallocation(u32 width_, u32 height_, PixelFormat format_,
60 u32 usage_) const {
61 if (static_cast<s32>(width_) != width) {
62 return true;
63 }
64
65 if (static_cast<s32>(height_) != height) {
66 return true;
67 }
68
69 if (format_ != format) {
70 return true;
71 }
72
73 if ((static_cast<u32>(usage) & usage_) != usage_) {
74 return true;
75 }
76
77 return false;
78 }
79
80private:
81 u32 magic{};
82 s32 width{};
83 s32 height{};
84 s32 stride{};
85 PixelFormat format{};
86 s32 usage{};
87 INSERT_PADDING_WORDS(1);
88 u32 index{};
89 INSERT_PADDING_WORDS(3);
90 u32 buffer_id{};
91 INSERT_PADDING_WORDS(6);
92 u32 external_format{};
93 INSERT_PADDING_WORDS(10);
94 u32 handle{};
95 u32 offset{};
96 INSERT_PADDING_WORDS(60);
97};
98static_assert(sizeof(GraphicBuffer) == 0x16C, "GraphicBuffer has wrong size");
99
100} // namespace android