summaryrefslogtreecommitdiffstats
path: root/src/video_core/framebuffer_config.cpp
diff options
context:
space:
mode:
authorFernando S <fsahmkow27@gmail.com>2024-02-02 15:08:06 +0100
committerGitHub <noreply@github.com>2024-02-02 15:08:06 +0100
commit58cf2ee1f93ebfa0e6b25b71d349ad2ad7895f53 (patch)
treea6efdfb4de7a7bac87926f6f1e93e7275634c731 /src/video_core/framebuffer_config.cpp
parentMerge pull request #12878 from zhaobot/tx-update-20240201020554 (diff)
parenthardware_composer: implement speed limit extensions (diff)
downloadyuzu-58cf2ee1f93ebfa0e6b25b71d349ad2ad7895f53.tar
yuzu-58cf2ee1f93ebfa0e6b25b71d349ad2ad7895f53.tar.gz
yuzu-58cf2ee1f93ebfa0e6b25b71d349ad2ad7895f53.tar.bz2
yuzu-58cf2ee1f93ebfa0e6b25b71d349ad2ad7895f53.tar.lz
yuzu-58cf2ee1f93ebfa0e6b25b71d349ad2ad7895f53.tar.xz
yuzu-58cf2ee1f93ebfa0e6b25b71d349ad2ad7895f53.tar.zst
yuzu-58cf2ee1f93ebfa0e6b25b71d349ad2ad7895f53.zip
Diffstat (limited to 'src/video_core/framebuffer_config.cpp')
-rw-r--r--src/video_core/framebuffer_config.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/video_core/framebuffer_config.cpp b/src/video_core/framebuffer_config.cpp
new file mode 100644
index 000000000..e28d41f84
--- /dev/null
+++ b/src/video_core/framebuffer_config.cpp
@@ -0,0 +1,55 @@
+// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "common/assert.h"
+#include "video_core/framebuffer_config.h"
+
+namespace Tegra {
+
+Common::Rectangle<f32> NormalizeCrop(const FramebufferConfig& framebuffer, u32 texture_width,
+ u32 texture_height) {
+ f32 left, top, right, bottom;
+
+ if (!framebuffer.crop_rect.IsEmpty()) {
+ // If crop rectangle is not empty, apply properties from rectangle.
+ left = static_cast<f32>(framebuffer.crop_rect.left);
+ top = static_cast<f32>(framebuffer.crop_rect.top);
+ right = static_cast<f32>(framebuffer.crop_rect.right);
+ bottom = static_cast<f32>(framebuffer.crop_rect.bottom);
+ } else {
+ // Otherwise, fall back to framebuffer dimensions.
+ left = 0;
+ top = 0;
+ right = static_cast<f32>(framebuffer.width);
+ bottom = static_cast<f32>(framebuffer.height);
+ }
+
+ // Apply transformation flags.
+ auto framebuffer_transform_flags = framebuffer.transform_flags;
+
+ if (True(framebuffer_transform_flags & Service::android::BufferTransformFlags::FlipH)) {
+ // Switch left and right.
+ std::swap(left, right);
+ }
+ if (True(framebuffer_transform_flags & Service::android::BufferTransformFlags::FlipV)) {
+ // Switch top and bottom.
+ std::swap(top, bottom);
+ }
+
+ framebuffer_transform_flags &= ~Service::android::BufferTransformFlags::FlipH;
+ framebuffer_transform_flags &= ~Service::android::BufferTransformFlags::FlipV;
+ if (True(framebuffer_transform_flags)) {
+ UNIMPLEMENTED_MSG("Unsupported framebuffer_transform_flags={}",
+ static_cast<u32>(framebuffer_transform_flags));
+ }
+
+ // Normalize coordinate space.
+ left /= static_cast<f32>(texture_width);
+ top /= static_cast<f32>(texture_height);
+ right /= static_cast<f32>(texture_width);
+ bottom /= static_cast<f32>(texture_height);
+
+ return Common::Rectangle<f32>(left, top, right, bottom);
+}
+
+} // namespace Tegra