diff options
Diffstat (limited to 'src/video_core/framebuffer_config.cpp')
| -rw-r--r-- | src/video_core/framebuffer_config.cpp | 55 |
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 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "common/assert.h" | ||
| 5 | #include "video_core/framebuffer_config.h" | ||
| 6 | |||
| 7 | namespace Tegra { | ||
| 8 | |||
| 9 | Common::Rectangle<f32> NormalizeCrop(const FramebufferConfig& framebuffer, u32 texture_width, | ||
| 10 | u32 texture_height) { | ||
| 11 | f32 left, top, right, bottom; | ||
| 12 | |||
| 13 | if (!framebuffer.crop_rect.IsEmpty()) { | ||
| 14 | // If crop rectangle is not empty, apply properties from rectangle. | ||
| 15 | left = static_cast<f32>(framebuffer.crop_rect.left); | ||
| 16 | top = static_cast<f32>(framebuffer.crop_rect.top); | ||
| 17 | right = static_cast<f32>(framebuffer.crop_rect.right); | ||
| 18 | bottom = static_cast<f32>(framebuffer.crop_rect.bottom); | ||
| 19 | } else { | ||
| 20 | // Otherwise, fall back to framebuffer dimensions. | ||
| 21 | left = 0; | ||
| 22 | top = 0; | ||
| 23 | right = static_cast<f32>(framebuffer.width); | ||
| 24 | bottom = static_cast<f32>(framebuffer.height); | ||
| 25 | } | ||
| 26 | |||
| 27 | // Apply transformation flags. | ||
| 28 | auto framebuffer_transform_flags = framebuffer.transform_flags; | ||
| 29 | |||
| 30 | if (True(framebuffer_transform_flags & Service::android::BufferTransformFlags::FlipH)) { | ||
| 31 | // Switch left and right. | ||
| 32 | std::swap(left, right); | ||
| 33 | } | ||
| 34 | if (True(framebuffer_transform_flags & Service::android::BufferTransformFlags::FlipV)) { | ||
| 35 | // Switch top and bottom. | ||
| 36 | std::swap(top, bottom); | ||
| 37 | } | ||
| 38 | |||
| 39 | framebuffer_transform_flags &= ~Service::android::BufferTransformFlags::FlipH; | ||
| 40 | framebuffer_transform_flags &= ~Service::android::BufferTransformFlags::FlipV; | ||
| 41 | if (True(framebuffer_transform_flags)) { | ||
| 42 | UNIMPLEMENTED_MSG("Unsupported framebuffer_transform_flags={}", | ||
| 43 | static_cast<u32>(framebuffer_transform_flags)); | ||
| 44 | } | ||
| 45 | |||
| 46 | // Normalize coordinate space. | ||
| 47 | left /= static_cast<f32>(texture_width); | ||
| 48 | top /= static_cast<f32>(texture_height); | ||
| 49 | right /= static_cast<f32>(texture_width); | ||
| 50 | bottom /= static_cast<f32>(texture_height); | ||
| 51 | |||
| 52 | return Common::Rectangle<f32>(left, top, right, bottom); | ||
| 53 | } | ||
| 54 | |||
| 55 | } // namespace Tegra | ||