mirror of
https://github.com/yuzu-emu/yuzu-android
synced 2024-12-25 19:21:20 -08:00
hle: nvflinger: Merge Rect with Common::Rectangle.
This commit is contained in:
parent
e524def8c0
commit
4d9488033f
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
@ -20,10 +21,32 @@ struct Rectangle {
|
|||||||
|
|
||||||
constexpr Rectangle() = default;
|
constexpr Rectangle() = default;
|
||||||
|
|
||||||
|
constexpr Rectangle(T width, T height) : right(width), bottom(height) {}
|
||||||
|
|
||||||
constexpr Rectangle(T left_, T top_, T right_, T bottom_)
|
constexpr Rectangle(T left_, T top_, T right_, T bottom_)
|
||||||
: left(left_), top(top_), right(right_), bottom(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>) {
|
if constexpr (std::is_floating_point_v<T>) {
|
||||||
return std::abs(right - left);
|
return std::abs(right - left);
|
||||||
} else {
|
} else {
|
||||||
@ -31,7 +54,7 @@ struct Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] T GetHeight() const {
|
[[nodiscard]] constexpr T GetHeight() const {
|
||||||
if constexpr (std::is_floating_point_v<T>) {
|
if constexpr (std::is_floating_point_v<T>) {
|
||||||
return std::abs(bottom - top);
|
return std::abs(bottom - top);
|
||||||
} else {
|
} 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};
|
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};
|
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),
|
return Rectangle{left, top, static_cast<T>(static_cast<float>(left + GetWidth()) * s),
|
||||||
static_cast<T>(static_cast<float>(top + GetHeight()) * 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>
|
template <typename T>
|
||||||
|
@ -563,7 +563,6 @@ add_library(core STATIC
|
|||||||
hle/service/nvflinger/status.h
|
hle/service/nvflinger/status.h
|
||||||
hle/service/nvflinger/ui/fence.h
|
hle/service/nvflinger/ui/fence.h
|
||||||
hle/service/nvflinger/ui/graphic_buffer.h
|
hle/service/nvflinger/ui/graphic_buffer.h
|
||||||
hle/service/nvflinger/ui/rect.h
|
|
||||||
hle/service/nvflinger/window.h
|
hle/service/nvflinger/window.h
|
||||||
hle/service/olsc/olsc.cpp
|
hle/service/olsc/olsc.cpp
|
||||||
hle/service/olsc/olsc.h
|
hle/service/olsc/olsc.h
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "common/common_types.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/fence.h"
|
||||||
#include "core/hle/service/nvflinger/ui/rect.h"
|
|
||||||
#include "core/hle/service/nvflinger/window.h"
|
#include "core/hle/service/nvflinger/window.h"
|
||||||
|
|
||||||
namespace Service::android {
|
namespace Service::android {
|
||||||
@ -23,7 +23,7 @@ public:
|
|||||||
|
|
||||||
std::shared_ptr<GraphicBuffer> graphic_buffer;
|
std::shared_ptr<GraphicBuffer> graphic_buffer;
|
||||||
Fence fence;
|
Fence fence;
|
||||||
Rect crop;
|
Common::Rectangle<s32> crop;
|
||||||
NativeWindowTransform transform{};
|
NativeWindowTransform transform{};
|
||||||
u32 scaling_mode{};
|
u32 scaling_mode{};
|
||||||
s64 timestamp{};
|
s64 timestamp{};
|
||||||
|
@ -441,7 +441,7 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input,
|
|||||||
QueueBufferOutput* output) {
|
QueueBufferOutput* output) {
|
||||||
s64 timestamp{};
|
s64 timestamp{};
|
||||||
bool is_auto_timestamp{};
|
bool is_auto_timestamp{};
|
||||||
Rect crop;
|
Common::Rectangle<s32> crop;
|
||||||
NativeWindowScalingMode scaling_mode{};
|
NativeWindowScalingMode scaling_mode{};
|
||||||
NativeWindowTransform transform;
|
NativeWindowTransform transform;
|
||||||
u32 sticky_transform_{};
|
u32 sticky_transform_{};
|
||||||
@ -509,9 +509,9 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input,
|
|||||||
crop.Bottom(), transform, scaling_mode);
|
crop.Bottom(), transform, scaling_mode);
|
||||||
|
|
||||||
const std::shared_ptr<GraphicBuffer>& graphic_buffer(slots[slot].graphic_buffer);
|
const std::shared_ptr<GraphicBuffer>& graphic_buffer(slots[slot].graphic_buffer);
|
||||||
Rect buffer_rect(graphic_buffer->Width(), graphic_buffer->Height());
|
Common::Rectangle<s32> buffer_rect(graphic_buffer->Width(), graphic_buffer->Height());
|
||||||
Rect cropped_rect;
|
Common::Rectangle<s32> cropped_rect;
|
||||||
crop.Intersect(buffer_rect, &cropped_rect);
|
[[maybe_unused]] const bool unused = crop.Intersect(buffer_rect, &cropped_rect);
|
||||||
|
|
||||||
if (cropped_rect != crop) {
|
if (cropped_rect != crop) {
|
||||||
LOG_ERROR(Service_NVFlinger, "crop rect is not contained within the buffer in slot {}",
|
LOG_ERROR(Service_NVFlinger, "crop rect is not contained within the buffer in slot {}",
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "common/common_types.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/fence.h"
|
||||||
#include "core/hle/service/nvflinger/ui/rect.h"
|
|
||||||
#include "core/hle/service/nvflinger/window.h"
|
#include "core/hle/service/nvflinger/window.h"
|
||||||
|
|
||||||
namespace Service::android {
|
namespace Service::android {
|
||||||
@ -20,7 +20,7 @@ class Parcel;
|
|||||||
struct QueueBufferInput final {
|
struct QueueBufferInput final {
|
||||||
explicit QueueBufferInput(Parcel& parcel);
|
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_,
|
NativeWindowScalingMode* scaling_mode_, NativeWindowTransform* transform_,
|
||||||
u32* sticky_transform_, bool* async_, s32* swap_interval_, Fence* fence_) const {
|
u32* sticky_transform_, bool* async_, s32* swap_interval_, Fence* fence_) const {
|
||||||
*timestamp_ = timestamp;
|
*timestamp_ = timestamp;
|
||||||
@ -37,7 +37,7 @@ struct QueueBufferInput final {
|
|||||||
private:
|
private:
|
||||||
s64 timestamp{};
|
s64 timestamp{};
|
||||||
s32 is_auto_timestamp{};
|
s32 is_auto_timestamp{};
|
||||||
Rect crop{};
|
Common::Rectangle<s32> crop{};
|
||||||
NativeWindowScalingMode scaling_mode{};
|
NativeWindowScalingMode scaling_mode{};
|
||||||
NativeWindowTransform transform{};
|
NativeWindowTransform transform{};
|
||||||
u32 sticky_transform{};
|
u32 sticky_transform{};
|
||||||
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user