nvflinger.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <memory>
  6. #include <boost/optional.hpp>
  7. #include "core/hle/kernel/event.h"
  8. namespace CoreTiming {
  9. struct EventType;
  10. }
  11. namespace Service::NVFlinger {
  12. class BufferQueue;
  13. struct Layer {
  14. Layer(u64 id, std::shared_ptr<BufferQueue> queue);
  15. ~Layer() = default;
  16. u64 id;
  17. std::shared_ptr<BufferQueue> buffer_queue;
  18. };
  19. struct Display {
  20. Display(u64 id, std::string name);
  21. ~Display() = default;
  22. u64 id;
  23. std::string name;
  24. std::vector<Layer> layers;
  25. Kernel::SharedPtr<Kernel::Event> vsync_event;
  26. };
  27. class NVFlinger final {
  28. public:
  29. NVFlinger();
  30. ~NVFlinger();
  31. /// Opens the specified display and returns the id.
  32. u64 OpenDisplay(const std::string& name);
  33. /// Creates a layer on the specified display and returns the layer id.
  34. u64 CreateLayer(u64 display_id);
  35. /// Gets the buffer queue id of the specified layer in the specified display.
  36. u32 GetBufferQueueId(u64 display_id, u64 layer_id);
  37. /// Gets the vsync event for the specified display.
  38. Kernel::SharedPtr<Kernel::Event> GetVsyncEvent(u64 display_id);
  39. /// Obtains a buffer queue identified by the id.
  40. std::shared_ptr<BufferQueue> GetBufferQueue(u32 id) const;
  41. /// Performs a composition request to the emulated nvidia GPU and triggers the vsync events when
  42. /// finished.
  43. void Compose();
  44. private:
  45. /// Returns the display identified by the specified id.
  46. Display& GetDisplay(u64 display_id);
  47. /// Returns the layer identified by the specified id in the desired display.
  48. Layer& GetLayer(u64 display_id, u64 layer_id);
  49. std::vector<Display> displays;
  50. std::vector<std::shared_ptr<BufferQueue>> buffer_queues;
  51. /// Id to use for the next layer that is created, this counter is shared among all displays.
  52. u64 next_layer_id = 1;
  53. /// Id to use for the next buffer queue that is created, this counter is shared among all
  54. /// layers.
  55. u32 next_buffer_queue_id = 1;
  56. /// CoreTiming event that handles screen composition.
  57. CoreTiming::EventType* composition_event;
  58. };
  59. } // namespace Service::NVFlinger