nvflinger.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <optional>
  7. #include <string>
  8. #include <string_view>
  9. #include <vector>
  10. #include "common/common_types.h"
  11. #include "core/hle/kernel/object.h"
  12. namespace Core::Timing {
  13. class CoreTiming;
  14. struct EventType;
  15. } // namespace Core::Timing
  16. namespace Kernel {
  17. class ReadableEvent;
  18. class WritableEvent;
  19. } // namespace Kernel
  20. namespace Service::Nvidia {
  21. class Module;
  22. } // namespace Service::Nvidia
  23. namespace Service::VI {
  24. class Display;
  25. class Layer;
  26. } // namespace Service::VI
  27. namespace Service::NVFlinger {
  28. class BufferQueue;
  29. class NVFlinger final {
  30. public:
  31. explicit NVFlinger(Core::System& system);
  32. ~NVFlinger();
  33. /// Sets the NVDrv module instance to use to send buffers to the GPU.
  34. void SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance);
  35. /// Opens the specified display and returns the ID.
  36. ///
  37. /// If an invalid display name is provided, then an empty optional is returned.
  38. std::optional<u64> OpenDisplay(std::string_view name);
  39. /// Creates a layer on the specified display and returns the layer ID.
  40. ///
  41. /// If an invalid display ID is specified, then an empty optional is returned.
  42. std::optional<u64> CreateLayer(u64 display_id);
  43. /// Finds the buffer queue ID of the specified layer in the specified display.
  44. ///
  45. /// If an invalid display ID or layer ID is provided, then an empty optional is returned.
  46. std::optional<u32> FindBufferQueueId(u64 display_id, u64 layer_id) const;
  47. /// Gets the vsync event for the specified display.
  48. ///
  49. /// If an invalid display ID is provided, then nullptr is returned.
  50. std::shared_ptr<Kernel::ReadableEvent> FindVsyncEvent(u64 display_id) const;
  51. /// Obtains a buffer queue identified by the ID.
  52. BufferQueue& FindBufferQueue(u32 id);
  53. /// Obtains a buffer queue identified by the ID.
  54. const BufferQueue& FindBufferQueue(u32 id) const;
  55. /// Performs a composition request to the emulated nvidia GPU and triggers the vsync events when
  56. /// finished.
  57. void Compose();
  58. s64 GetNextTicks() const;
  59. private:
  60. /// Finds the display identified by the specified ID.
  61. VI::Display* FindDisplay(u64 display_id);
  62. /// Finds the display identified by the specified ID.
  63. const VI::Display* FindDisplay(u64 display_id) const;
  64. /// Finds the layer identified by the specified ID in the desired display.
  65. VI::Layer* FindLayer(u64 display_id, u64 layer_id);
  66. /// Finds the layer identified by the specified ID in the desired display.
  67. const VI::Layer* FindLayer(u64 display_id, u64 layer_id) const;
  68. std::shared_ptr<Nvidia::Module> nvdrv;
  69. std::vector<VI::Display> displays;
  70. std::vector<BufferQueue> buffer_queues;
  71. /// Id to use for the next layer that is created, this counter is shared among all displays.
  72. u64 next_layer_id = 1;
  73. /// Id to use for the next buffer queue that is created, this counter is shared among all
  74. /// layers.
  75. u32 next_buffer_queue_id = 1;
  76. u32 swap_interval = 1;
  77. /// Event that handles screen composition.
  78. std::shared_ptr<Core::Timing::EventType> composition_event;
  79. Core::System& system;
  80. };
  81. } // namespace Service::NVFlinger