summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2022-03-20 06:47:46 +0100
committerbunnei <bunneidev@gmail.com>2022-03-25 02:13:33 +0100
commit4d9488033f849132446ffb7840f1309fa38be8fd (patch)
treea8737261a62a54962acb4957b1a72c2a9e0c3eea
parenthle: nvflinger: buffer_queue_core: Declare default dtor. (diff)
downloadyuzu-4d9488033f849132446ffb7840f1309fa38be8fd.tar
yuzu-4d9488033f849132446ffb7840f1309fa38be8fd.tar.gz
yuzu-4d9488033f849132446ffb7840f1309fa38be8fd.tar.bz2
yuzu-4d9488033f849132446ffb7840f1309fa38be8fd.tar.lz
yuzu-4d9488033f849132446ffb7840f1309fa38be8fd.tar.xz
yuzu-4d9488033f849132446ffb7840f1309fa38be8fd.tar.zst
yuzu-4d9488033f849132446ffb7840f1309fa38be8fd.zip
-rw-r--r--src/common/math_util.h50
-rw-r--r--src/core/CMakeLists.txt1
-rw-r--r--src/core/hle/service/nvflinger/buffer_item.h4
-rw-r--r--src/core/hle/service/nvflinger/buffer_queue_producer.cpp8
-rw-r--r--src/core/hle/service/nvflinger/graphic_buffer_producer.h6
-rw-r--r--src/core/hle/service/nvflinger/ui/rect.h75
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 @@
#pragma once
+#include <algorithm>
#include <cstdlib>
#include <type_traits>
@@ -20,10 +21,32 @@ struct Rectangle {
constexpr Rectangle() = default;
+ constexpr Rectangle(T width, T height) : right(width), bottom(height) {}
+
constexpr Rectangle(T left_, T top_, T right_, T bottom_)
: left(left_), top(top_), right(right_), bottom(bottom_) {}
- [[nodiscard]] T GetWidth() const {
+ [[nodiscard]] constexpr T Left() const {
+ return left;
+ }
+
+ [[nodiscard]] constexpr T Top() const {
+ return top;
+ }
+
+ [[nodiscard]] constexpr T Right() const {
+ return right;
+ }
+
+ [[nodiscard]] constexpr T Bottom() const {
+ return bottom;
+ }
+
+ [[nodiscard]] constexpr bool IsEmpty() const {
+ return (GetWidth() <= 0) || (GetHeight() <= 0);
+ }
+
+ [[nodiscard]] constexpr T GetWidth() const {
if constexpr (std::is_floating_point_v<T>) {
return std::abs(right - left);
} else {
@@ -31,7 +54,7 @@ struct Rectangle {
}
}
- [[nodiscard]] T GetHeight() const {
+ [[nodiscard]] constexpr T GetHeight() const {
if constexpr (std::is_floating_point_v<T>) {
return std::abs(bottom - top);
} else {
@@ -39,18 +62,35 @@ struct Rectangle {
}
}
- [[nodiscard]] Rectangle<T> TranslateX(const T x) const {
+ [[nodiscard]] constexpr Rectangle<T> TranslateX(const T x) const {
return Rectangle{left + x, top, right + x, bottom};
}
- [[nodiscard]] Rectangle<T> TranslateY(const T y) const {
+ [[nodiscard]] constexpr Rectangle<T> TranslateY(const T y) const {
return Rectangle{left, top + y, right, bottom + y};
}
- [[nodiscard]] Rectangle<T> Scale(const float s) const {
+ [[nodiscard]] constexpr Rectangle<T> Scale(const float s) const {
return Rectangle{left, top, static_cast<T>(static_cast<float>(left + GetWidth()) * s),
static_cast<T>(static_cast<float>(top + GetHeight()) * s)};
}
+
+ [[nodiscard]] constexpr bool operator==(const Rectangle<T>& rhs) const {
+ return (left == rhs.left) && (top == rhs.top) && (right == rhs.right) &&
+ (bottom == rhs.bottom);
+ }
+
+ [[nodiscard]] constexpr bool operator!=(const Rectangle<T>& rhs) const {
+ return !operator==(rhs);
+ }
+
+ [[nodiscard]] constexpr bool Intersect(const Rectangle<T>& with, Rectangle<T>* result) const {
+ result->left = std::max(left, with.left);
+ result->top = std::max(top, with.top);
+ result->right = std::min(right, with.right);
+ result->bottom = std::min(bottom, with.bottom);
+ return !result->IsEmpty();
+ }
};
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
hle/service/nvflinger/status.h
hle/service/nvflinger/ui/fence.h
hle/service/nvflinger/ui/graphic_buffer.h
- hle/service/nvflinger/ui/rect.h
hle/service/nvflinger/window.h
hle/service/olsc/olsc.cpp
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 @@
#include <memory>
#include "common/common_types.h"
+#include "common/math_util.h"
#include "core/hle/service/nvflinger/ui/fence.h"
-#include "core/hle/service/nvflinger/ui/rect.h"
#include "core/hle/service/nvflinger/window.h"
namespace Service::android {
@@ -23,7 +23,7 @@ public:
std::shared_ptr<GraphicBuffer> graphic_buffer;
Fence fence;
- Rect crop;
+ Common::Rectangle<s32> crop;
NativeWindowTransform transform{};
u32 scaling_mode{};
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,
QueueBufferOutput* output) {
s64 timestamp{};
bool is_auto_timestamp{};
- Rect crop;
+ Common::Rectangle<s32> crop;
NativeWindowScalingMode scaling_mode{};
NativeWindowTransform transform;
u32 sticky_transform_{};
@@ -509,9 +509,9 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input,
crop.Bottom(), transform, scaling_mode);
const std::shared_ptr<GraphicBuffer>& graphic_buffer(slots[slot].graphic_buffer);
- Rect buffer_rect(graphic_buffer->Width(), graphic_buffer->Height());
- Rect cropped_rect;
- crop.Intersect(buffer_rect, &cropped_rect);
+ Common::Rectangle<s32> buffer_rect(graphic_buffer->Width(), graphic_buffer->Height());
+ Common::Rectangle<s32> cropped_rect;
+ [[maybe_unused]] const bool unused = crop.Intersect(buffer_rect, &cropped_rect);
if (cropped_rect != crop) {
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 @@
#include "common/common_funcs.h"
#include "common/common_types.h"
+#include "common/math_util.h"
#include "core/hle/service/nvflinger/ui/fence.h"
-#include "core/hle/service/nvflinger/ui/rect.h"
#include "core/hle/service/nvflinger/window.h"
namespace Service::android {
@@ -20,7 +20,7 @@ class Parcel;
struct QueueBufferInput final {
explicit QueueBufferInput(Parcel& parcel);
- void Deflate(s64* timestamp_, bool* is_auto_timestamp_, Rect* crop_,
+ void Deflate(s64* timestamp_, bool* is_auto_timestamp_, Common::Rectangle<s32>* crop_,
NativeWindowScalingMode* scaling_mode_, NativeWindowTransform* transform_,
u32* sticky_transform_, bool* async_, s32* swap_interval_, Fence* fence_) const {
*timestamp_ = timestamp;
@@ -37,7 +37,7 @@ struct QueueBufferInput final {
private:
s64 timestamp{};
s32 is_auto_timestamp{};
- Rect crop{};
+ Common::Rectangle<s32> crop{};
NativeWindowScalingMode scaling_mode{};
NativeWindowTransform transform{};
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 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-// Copyright 2021 yuzu Emulator Project
-// Copyright 2006 The Android Open Source Project
-// Parts of this implementation were base on:
-// https://cs.android.com/android/platform/superproject/+/android-5.1.1_r38:frameworks/native/include/ui/Rect.h
-
-#pragma once
-
-#include <cstdint>
-#include <utility>
-
-#include "common/common_types.h"
-
-namespace Service::android {
-
-class Rect final {
-public:
- constexpr Rect() = default;
-
- constexpr Rect(s32 width_, s32 height_) : right{width_}, bottom{height_} {}
-
- constexpr s32 Left() const {
- return left;
- }
-
- constexpr s32 Top() const {
- return top;
- }
-
- constexpr s32 Right() const {
- return right;
- }
-
- constexpr s32 Bottom() const {
- return bottom;
- }
-
- constexpr bool IsEmpty() const {
- return (GetWidth() <= 0) || (GetHeight() <= 0);
- }
-
- constexpr s32 GetWidth() const {
- return right - left;
- }
-
- constexpr s32 GetHeight() const {
- return bottom - top;
- }
-
- constexpr bool operator==(const Rect& rhs) const {
- return (left == rhs.left) && (top == rhs.top) && (right == rhs.right) &&
- (bottom == rhs.bottom);
- }
-
- constexpr bool operator!=(const Rect& rhs) const {
- return !operator==(rhs);
- }
-
- constexpr bool Intersect(const Rect& with, Rect* result) const {
- result->left = std::max(left, with.left);
- result->top = std::max(top, with.top);
- result->right = std::min(right, with.right);
- result->bottom = std::min(bottom, with.bottom);
- return !result->IsEmpty();
- }
-
-private:
- s32 left{};
- s32 top{};
- s32 right{};
- s32 bottom{};
-};
-static_assert(sizeof(Rect) == 16, "Rect has wrong size");
-
-} // namespace Service::android