buffer_queue.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <list>
  6. #include <optional>
  7. #include <vector>
  8. #include "common/common_funcs.h"
  9. #include "common/math_util.h"
  10. #include "common/swap.h"
  11. #include "core/hle/kernel/object.h"
  12. #include "core/hle/kernel/writable_event.h"
  13. #include "core/hle/service/nvdrv/nvdata.h"
  14. namespace Service::NVFlinger {
  15. struct IGBPBuffer {
  16. u32_le magic;
  17. u32_le width;
  18. u32_le height;
  19. u32_le stride;
  20. u32_le format;
  21. u32_le usage;
  22. INSERT_PADDING_WORDS(1);
  23. u32_le index;
  24. INSERT_PADDING_WORDS(3);
  25. u32_le gpu_buffer_id;
  26. INSERT_PADDING_WORDS(17);
  27. u32_le nvmap_handle;
  28. u32_le offset;
  29. INSERT_PADDING_WORDS(60);
  30. };
  31. static_assert(sizeof(IGBPBuffer) == 0x16C, "IGBPBuffer has wrong size");
  32. class BufferQueue final {
  33. public:
  34. enum class QueryType {
  35. NativeWindowWidth = 0,
  36. NativeWindowHeight = 1,
  37. NativeWindowFormat = 2,
  38. };
  39. BufferQueue(u32 id, u64 layer_id);
  40. ~BufferQueue();
  41. enum class BufferTransformFlags : u32 {
  42. /// No transform flags are set
  43. Unset = 0x00,
  44. /// Flip source image horizontally (around the vertical axis)
  45. FlipH = 0x01,
  46. /// Flip source image vertically (around the horizontal axis)
  47. FlipV = 0x02,
  48. /// Rotate source image 90 degrees clockwise
  49. Rotate90 = 0x04,
  50. /// Rotate source image 180 degrees
  51. Rotate180 = 0x03,
  52. /// Rotate source image 270 degrees clockwise
  53. Rotate270 = 0x07,
  54. };
  55. struct Buffer {
  56. enum class Status { Free = 0, Queued = 1, Dequeued = 2, Acquired = 3 };
  57. u32 slot;
  58. Status status = Status::Free;
  59. IGBPBuffer igbp_buffer;
  60. BufferTransformFlags transform;
  61. Common::Rectangle<int> crop_rect;
  62. u32 swap_interval;
  63. Service::Nvidia::MultiFence multi_fence;
  64. };
  65. void SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer);
  66. std::optional<std::pair<u32, Service::Nvidia::MultiFence*>> DequeueBuffer(u32 width,
  67. u32 height);
  68. const IGBPBuffer& RequestBuffer(u32 slot) const;
  69. void QueueBuffer(u32 slot, BufferTransformFlags transform,
  70. const Common::Rectangle<int>& crop_rect, u32 swap_interval,
  71. Service::Nvidia::MultiFence& multi_fence);
  72. std::optional<std::reference_wrapper<const Buffer>> AcquireBuffer();
  73. void ReleaseBuffer(u32 slot);
  74. u32 Query(QueryType type);
  75. u32 GetId() const {
  76. return id;
  77. }
  78. Kernel::SharedPtr<Kernel::WritableEvent> GetWritableBufferWaitEvent() const;
  79. Kernel::SharedPtr<Kernel::ReadableEvent> GetBufferWaitEvent() const;
  80. private:
  81. u32 id;
  82. u64 layer_id;
  83. std::vector<Buffer> queue;
  84. std::list<u32> queue_sequence;
  85. Kernel::EventPair buffer_wait_event;
  86. };
  87. } // namespace Service::NVFlinger