framebuffer_config.cpp 2.0 KB

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