diff options
Diffstat (limited to '')
| -rw-r--r-- | src/common/math_util.h | 50 | ||||
| -rw-r--r-- | src/core/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/core/hle/service/nvflinger/buffer_item.h | 4 | ||||
| -rw-r--r-- | src/core/hle/service/nvflinger/buffer_queue_producer.cpp | 8 | ||||
| -rw-r--r-- | src/core/hle/service/nvflinger/graphic_buffer_producer.h | 6 | ||||
| -rw-r--r-- | src/core/hle/service/nvflinger/ui/rect.h | 75 |
6 files changed, 54 insertions, 90 deletions
diff --git a/src/common/math_util.h b/src/common/math_util.h index 510c4e56d..54485bf53 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <algorithm> | ||
| 7 | #include <cstdlib> | 8 | #include <cstdlib> |
| 8 | #include <type_traits> | 9 | #include <type_traits> |
| 9 | 10 | ||
| @@ -20,10 +21,32 @@ struct Rectangle { | |||
| 20 | 21 | ||
| 21 | constexpr Rectangle() = default; | 22 | constexpr Rectangle() = default; |
| 22 | 23 | ||
| 24 | constexpr Rectangle(T width, T height) : right(width), bottom(height) {} | ||
| 25 | |||
| 23 | constexpr Rectangle(T left_, T top_, T right_, T bottom_) | 26 | constexpr Rectangle(T left_, T top_, T right_, T bottom_) |
| 24 | : left(left_), top(top_), right(right_), bottom(bottom_) {} | 27 | : left(left_), top(top_), right(right_), bottom(bottom_) {} |
| 25 | 28 | ||
| 26 | [[nodiscard]] T GetWidth() const { | 29 | [[nodiscard]] constexpr T Left() const { |
| 30 | return left; | ||
| 31 | } | ||
| 32 | |||
| 33 | [[nodiscard]] constexpr T Top() const { | ||
| 34 | return top; | ||
| 35 | } | ||
| 36 | |||
| 37 | [[nodiscard]] constexpr T Right() const { | ||
| 38 | return right; | ||
| 39 | } | ||
| 40 | |||
| 41 | [[nodiscard]] constexpr T Bottom() const { | ||
| 42 | return bottom; | ||
| 43 | } | ||
| 44 | |||
| 45 | [[nodiscard]] constexpr bool IsEmpty() const { | ||
| 46 | return (GetWidth() <= 0) || (GetHeight() <= 0); | ||
| 47 | } | ||
| 48 | |||
| 49 | [[nodiscard]] constexpr T GetWidth() const { | ||
| 27 | if constexpr (std::is_floating_point_v<T>) { | 50 | if constexpr (std::is_floating_point_v<T>) { |
| 28 | return std::abs(right - left); | 51 | return std::abs(right - left); |
| 29 | } else { | 52 | } else { |
| @@ -31,7 +54,7 @@ struct Rectangle { | |||
| 31 | } | 54 | } |
| 32 | } | 55 | } |
| 33 | 56 | ||
| 34 | [[nodiscard]] T GetHeight() const { | 57 | [[nodiscard]] constexpr T GetHeight() const { |
| 35 | if constexpr (std::is_floating_point_v<T>) { | 58 | if constexpr (std::is_floating_point_v<T>) { |
| 36 | return std::abs(bottom - top); | 59 | return std::abs(bottom - top); |
| 37 | } else { | 60 | } else { |
| @@ -39,18 +62,35 @@ struct Rectangle { | |||
| 39 | } | 62 | } |
| 40 | } | 63 | } |
| 41 | 64 | ||
| 42 | [[nodiscard]] Rectangle<T> TranslateX(const T x) const { | 65 | [[nodiscard]] constexpr Rectangle<T> TranslateX(const T x) const { |
| 43 | return Rectangle{left + x, top, right + x, bottom}; | 66 | return Rectangle{left + x, top, right + x, bottom}; |
| 44 | } | 67 | } |
| 45 | 68 | ||
| 46 | [[nodiscard]] Rectangle<T> TranslateY(const T y) const { | 69 | [[nodiscard]] constexpr Rectangle<T> TranslateY(const T y) const { |
| 47 | return Rectangle{left, top + y, right, bottom + y}; | 70 | return Rectangle{left, top + y, right, bottom + y}; |
| 48 | } | 71 | } |
| 49 | 72 | ||
| 50 | [[nodiscard]] Rectangle<T> Scale(const float s) const { | 73 | [[nodiscard]] constexpr Rectangle<T> Scale(const float s) const { |
| 51 | return Rectangle{left, top, static_cast<T>(static_cast<float>(left + GetWidth()) * s), | 74 | return Rectangle{left, top, static_cast<T>(static_cast<float>(left + GetWidth()) * s), |
| 52 | static_cast<T>(static_cast<float>(top + GetHeight()) * s)}; | 75 | static_cast<T>(static_cast<float>(top + GetHeight()) * s)}; |
| 53 | } | 76 | } |
| 77 | |||
| 78 | [[nodiscard]] constexpr bool operator==(const Rectangle<T>& rhs) const { | ||
| 79 | return (left == rhs.left) && (top == rhs.top) && (right == rhs.right) && | ||
| 80 | (bottom == rhs.bottom); | ||
| 81 | } | ||
| 82 | |||
| 83 | [[nodiscard]] constexpr bool operator!=(const Rectangle<T>& rhs) const { | ||
| 84 | return !operator==(rhs); | ||
| 85 | } | ||
| 86 | |||
| 87 | [[nodiscard]] constexpr bool Intersect(const Rectangle<T>& with, Rectangle<T>* result) const { | ||
| 88 | result->left = std::max(left, with.left); | ||
| 89 | result->top = std::max(top, with.top); | ||
| 90 | result->right = std::min(right, with.right); | ||
| 91 | result->bottom = std::min(bottom, with.bottom); | ||
| 92 | return !result->IsEmpty(); | ||
| 93 | } | ||
| 54 | }; | 94 | }; |
| 55 | 95 | ||
| 56 | template <typename T> | 96 | template <typename T> |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ff8adfc55..6536d0544 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -563,7 +563,6 @@ add_library(core STATIC | |||
| 563 | hle/service/nvflinger/status.h | 563 | hle/service/nvflinger/status.h |
| 564 | hle/service/nvflinger/ui/fence.h | 564 | hle/service/nvflinger/ui/fence.h |
| 565 | hle/service/nvflinger/ui/graphic_buffer.h | 565 | hle/service/nvflinger/ui/graphic_buffer.h |
| 566 | hle/service/nvflinger/ui/rect.h | ||
| 567 | hle/service/nvflinger/window.h | 566 | hle/service/nvflinger/window.h |
| 568 | hle/service/olsc/olsc.cpp | 567 | hle/service/olsc/olsc.cpp |
| 569 | hle/service/olsc/olsc.h | 568 | hle/service/olsc/olsc.h |
diff --git a/src/core/hle/service/nvflinger/buffer_item.h b/src/core/hle/service/nvflinger/buffer_item.h index d60719065..64b82b851 100644 --- a/src/core/hle/service/nvflinger/buffer_item.h +++ b/src/core/hle/service/nvflinger/buffer_item.h | |||
| @@ -9,8 +9,8 @@ | |||
| 9 | #include <memory> | 9 | #include <memory> |
| 10 | 10 | ||
| 11 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 12 | #include "common/math_util.h" | ||
| 12 | #include "core/hle/service/nvflinger/ui/fence.h" | 13 | #include "core/hle/service/nvflinger/ui/fence.h" |
| 13 | #include "core/hle/service/nvflinger/ui/rect.h" | ||
| 14 | #include "core/hle/service/nvflinger/window.h" | 14 | #include "core/hle/service/nvflinger/window.h" |
| 15 | 15 | ||
| 16 | namespace Service::android { | 16 | namespace Service::android { |
| @@ -23,7 +23,7 @@ public: | |||
| 23 | 23 | ||
| 24 | std::shared_ptr<GraphicBuffer> graphic_buffer; | 24 | std::shared_ptr<GraphicBuffer> graphic_buffer; |
| 25 | Fence fence; | 25 | Fence fence; |
| 26 | Rect crop; | 26 | Common::Rectangle<s32> crop; |
| 27 | NativeWindowTransform transform{}; | 27 | NativeWindowTransform transform{}; |
| 28 | u32 scaling_mode{}; | 28 | u32 scaling_mode{}; |
| 29 | s64 timestamp{}; | 29 | s64 timestamp{}; |
diff --git a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp b/src/core/hle/service/nvflinger/buffer_queue_producer.cpp index 99f7ec1ac..5ea48431f 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp +++ b/src/core/hle/service/nvflinger/buffer_queue_producer.cpp | |||
| @@ -441,7 +441,7 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input, | |||
| 441 | QueueBufferOutput* output) { | 441 | QueueBufferOutput* output) { |
| 442 | s64 timestamp{}; | 442 | s64 timestamp{}; |
| 443 | bool is_auto_timestamp{}; | 443 | bool is_auto_timestamp{}; |
| 444 | Rect crop; | 444 | Common::Rectangle<s32> crop; |
| 445 | NativeWindowScalingMode scaling_mode{}; | 445 | NativeWindowScalingMode scaling_mode{}; |
| 446 | NativeWindowTransform transform; | 446 | NativeWindowTransform transform; |
| 447 | u32 sticky_transform_{}; | 447 | u32 sticky_transform_{}; |
| @@ -509,9 +509,9 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input, | |||
| 509 | crop.Bottom(), transform, scaling_mode); | 509 | crop.Bottom(), transform, scaling_mode); |
| 510 | 510 | ||
| 511 | const std::shared_ptr<GraphicBuffer>& graphic_buffer(slots[slot].graphic_buffer); | 511 | const std::shared_ptr<GraphicBuffer>& graphic_buffer(slots[slot].graphic_buffer); |
| 512 | Rect buffer_rect(graphic_buffer->Width(), graphic_buffer->Height()); | 512 | Common::Rectangle<s32> buffer_rect(graphic_buffer->Width(), graphic_buffer->Height()); |
| 513 | Rect cropped_rect; | 513 | Common::Rectangle<s32> cropped_rect; |
| 514 | crop.Intersect(buffer_rect, &cropped_rect); | 514 | [[maybe_unused]] const bool unused = crop.Intersect(buffer_rect, &cropped_rect); |
| 515 | 515 | ||
| 516 | if (cropped_rect != crop) { | 516 | if (cropped_rect != crop) { |
| 517 | LOG_ERROR(Service_NVFlinger, "crop rect is not contained within the buffer in slot {}", | 517 | LOG_ERROR(Service_NVFlinger, "crop rect is not contained within the buffer in slot {}", |
diff --git a/src/core/hle/service/nvflinger/graphic_buffer_producer.h b/src/core/hle/service/nvflinger/graphic_buffer_producer.h index 58763cf08..98d27871c 100644 --- a/src/core/hle/service/nvflinger/graphic_buffer_producer.h +++ b/src/core/hle/service/nvflinger/graphic_buffer_producer.h | |||
| @@ -8,8 +8,8 @@ | |||
| 8 | 8 | ||
| 9 | #include "common/common_funcs.h" | 9 | #include "common/common_funcs.h" |
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/math_util.h" | ||
| 11 | #include "core/hle/service/nvflinger/ui/fence.h" | 12 | #include "core/hle/service/nvflinger/ui/fence.h" |
| 12 | #include "core/hle/service/nvflinger/ui/rect.h" | ||
| 13 | #include "core/hle/service/nvflinger/window.h" | 13 | #include "core/hle/service/nvflinger/window.h" |
| 14 | 14 | ||
| 15 | namespace Service::android { | 15 | namespace Service::android { |
| @@ -20,7 +20,7 @@ class Parcel; | |||
| 20 | struct QueueBufferInput final { | 20 | struct QueueBufferInput final { |
| 21 | explicit QueueBufferInput(Parcel& parcel); | 21 | explicit QueueBufferInput(Parcel& parcel); |
| 22 | 22 | ||
| 23 | void Deflate(s64* timestamp_, bool* is_auto_timestamp_, Rect* crop_, | 23 | void Deflate(s64* timestamp_, bool* is_auto_timestamp_, Common::Rectangle<s32>* crop_, |
| 24 | NativeWindowScalingMode* scaling_mode_, NativeWindowTransform* transform_, | 24 | NativeWindowScalingMode* scaling_mode_, NativeWindowTransform* transform_, |
| 25 | u32* sticky_transform_, bool* async_, s32* swap_interval_, Fence* fence_) const { | 25 | u32* sticky_transform_, bool* async_, s32* swap_interval_, Fence* fence_) const { |
| 26 | *timestamp_ = timestamp; | 26 | *timestamp_ = timestamp; |
| @@ -37,7 +37,7 @@ struct QueueBufferInput final { | |||
| 37 | private: | 37 | private: |
| 38 | s64 timestamp{}; | 38 | s64 timestamp{}; |
| 39 | s32 is_auto_timestamp{}; | 39 | s32 is_auto_timestamp{}; |
| 40 | Rect crop{}; | 40 | Common::Rectangle<s32> crop{}; |
| 41 | NativeWindowScalingMode scaling_mode{}; | 41 | NativeWindowScalingMode scaling_mode{}; |
| 42 | NativeWindowTransform transform{}; | 42 | NativeWindowTransform transform{}; |
| 43 | u32 sticky_transform{}; | 43 | u32 sticky_transform{}; |
diff --git a/src/core/hle/service/nvflinger/ui/rect.h b/src/core/hle/service/nvflinger/ui/rect.h deleted file mode 100644 index c7b5f1815..000000000 --- a/src/core/hle/service/nvflinger/ui/rect.h +++ /dev/null | |||
| @@ -1,75 +0,0 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 2 | // Copyright 2021 yuzu Emulator Project | ||
| 3 | // Copyright 2006 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/Rect.h | ||
| 6 | |||
| 7 | #pragma once | ||
| 8 | |||
| 9 | #include <cstdint> | ||
| 10 | #include <utility> | ||
| 11 | |||
| 12 | #include "common/common_types.h" | ||
| 13 | |||
| 14 | namespace Service::android { | ||
| 15 | |||
| 16 | class Rect final { | ||
| 17 | public: | ||
| 18 | constexpr Rect() = default; | ||
| 19 | |||
| 20 | constexpr Rect(s32 width_, s32 height_) : right{width_}, bottom{height_} {} | ||
| 21 | |||
| 22 | constexpr s32 Left() const { | ||
| 23 | return left; | ||
| 24 | } | ||
| 25 | |||
| 26 | constexpr s32 Top() const { | ||
| 27 | return top; | ||
| 28 | } | ||
| 29 | |||
| 30 | constexpr s32 Right() const { | ||
| 31 | return right; | ||
| 32 | } | ||
| 33 | |||
| 34 | constexpr s32 Bottom() const { | ||
| 35 | return bottom; | ||
| 36 | } | ||
| 37 | |||
| 38 | constexpr bool IsEmpty() const { | ||
| 39 | return (GetWidth() <= 0) || (GetHeight() <= 0); | ||
| 40 | } | ||
| 41 | |||
| 42 | constexpr s32 GetWidth() const { | ||
| 43 | return right - left; | ||
| 44 | } | ||
| 45 | |||
| 46 | constexpr s32 GetHeight() const { | ||
| 47 | return bottom - top; | ||
| 48 | } | ||
| 49 | |||
| 50 | constexpr bool operator==(const Rect& rhs) const { | ||
| 51 | return (left == rhs.left) && (top == rhs.top) && (right == rhs.right) && | ||
| 52 | (bottom == rhs.bottom); | ||
| 53 | } | ||
| 54 | |||
| 55 | constexpr bool operator!=(const Rect& rhs) const { | ||
| 56 | return !operator==(rhs); | ||
| 57 | } | ||
| 58 | |||
| 59 | constexpr bool Intersect(const Rect& with, Rect* result) const { | ||
| 60 | result->left = std::max(left, with.left); | ||
| 61 | result->top = std::max(top, with.top); | ||
| 62 | result->right = std::min(right, with.right); | ||
| 63 | result->bottom = std::min(bottom, with.bottom); | ||
| 64 | return !result->IsEmpty(); | ||
| 65 | } | ||
| 66 | |||
| 67 | private: | ||
| 68 | s32 left{}; | ||
| 69 | s32 top{}; | ||
| 70 | s32 right{}; | ||
| 71 | s32 bottom{}; | ||
| 72 | }; | ||
| 73 | static_assert(sizeof(Rect) == 16, "Rect has wrong size"); | ||
| 74 | |||
| 75 | } // namespace Service::android | ||