display_service.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_
  2. #define ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_
  3. #include <dvr/dvr_api.h>
  4. #include <pdx/service.h>
  5. #include <pdx/status.h>
  6. #include <private/dvr/bufferhub_rpc.h>
  7. #include <private/dvr/display_protocol.h>
  8. #include <functional>
  9. #include <iterator>
  10. #include <memory>
  11. #include <string>
  12. #include <vector>
  13. #include "acquired_buffer.h"
  14. #include "display_surface.h"
  15. #include "epoll_event_dispatcher.h"
  16. #include "hardware_composer.h"
  17. namespace android {
  18. namespace dvr {
  19. // DisplayService implements the display service component of VrFlinger.
  20. class DisplayService : public pdx::ServiceBase<DisplayService> {
  21. public:
  22. bool IsInitialized() const override;
  23. std::string DumpState(size_t max_length) override;
  24. void OnChannelClose(pdx::Message& message,
  25. const std::shared_ptr<pdx::Channel>& channel) override;
  26. pdx::Status<void> HandleMessage(pdx::Message& message) override;
  27. std::shared_ptr<DisplaySurface> GetDisplaySurface(int surface_id) const;
  28. std::vector<std::shared_ptr<DisplaySurface>> GetDisplaySurfaces() const;
  29. std::vector<std::shared_ptr<DirectDisplaySurface>> GetVisibleDisplaySurfaces()
  30. const;
  31. // Updates the list of actively displayed surfaces. This must be called after
  32. // any change to client/manager attributes that affect visibility or z order.
  33. void UpdateActiveDisplaySurfaces();
  34. pdx::Status<BorrowedNativeBufferHandle> SetupGlobalBuffer(
  35. DvrGlobalBufferKey key, size_t size, uint64_t usage);
  36. pdx::Status<void> DeleteGlobalBuffer(DvrGlobalBufferKey key);
  37. template <class A>
  38. void ForEachDisplaySurface(SurfaceType surface_type, A action) const {
  39. ForEachChannel([surface_type,
  40. action](const ChannelIterator::value_type& pair) mutable {
  41. auto surface = std::static_pointer_cast<DisplaySurface>(pair.second);
  42. if (surface->surface_type() == surface_type)
  43. action(surface);
  44. });
  45. }
  46. using DisplayConfigurationUpdateNotifier = std::function<void(void)>;
  47. void SetDisplayConfigurationUpdateNotifier(
  48. DisplayConfigurationUpdateNotifier notifier);
  49. void GrantDisplayOwnership() { hardware_composer_.Enable(); }
  50. void SeizeDisplayOwnership() { hardware_composer_.Disable(); }
  51. void OnBootFinished() { hardware_composer_.OnBootFinished(); }
  52. private:
  53. friend BASE;
  54. friend DisplaySurface;
  55. friend class VrDisplayStateService;
  56. using RequestDisplayCallback = std::function<void(bool)>;
  57. DisplayService(android::Hwc2::Composer* hidl,
  58. hwc2_display_t primary_display_id,
  59. RequestDisplayCallback request_display_callback);
  60. pdx::Status<BorrowedNativeBufferHandle> OnGetGlobalBuffer(
  61. pdx::Message& message, DvrGlobalBufferKey key);
  62. pdx::Status<display::Metrics> OnGetMetrics(pdx::Message& message);
  63. pdx::Status<std::string> OnGetConfigurationData(
  64. pdx::Message& message, display::ConfigFileType config_type);
  65. pdx::Status<display::SurfaceInfo> OnCreateSurface(
  66. pdx::Message& message, const display::SurfaceAttributes& attributes);
  67. pdx::Status<BorrowedNativeBufferHandle> OnSetupGlobalBuffer(
  68. pdx::Message& message, DvrGlobalBufferKey key, size_t size,
  69. uint64_t usage);
  70. pdx::Status<void> OnDeleteGlobalBuffer(pdx::Message& message,
  71. DvrGlobalBufferKey key);
  72. // Temporary query for current VR status. Will be removed later.
  73. pdx::Status<bool> IsVrAppRunning(pdx::Message& message);
  74. pdx::Status<void> AddEventHandler(int fd, int events,
  75. EpollEventDispatcher::Handler handler) {
  76. return dispatcher_.AddEventHandler(fd, events, handler);
  77. }
  78. pdx::Status<void> RemoveEventHandler(int fd) {
  79. return dispatcher_.RemoveEventHandler(fd);
  80. }
  81. void SurfaceUpdated(SurfaceType surface_type,
  82. display::SurfaceUpdateFlags update_flags);
  83. // Called by DisplaySurface to signal that a surface property has changed and
  84. // the display manager should be notified.
  85. void NotifyDisplayConfigurationUpdate();
  86. pdx::Status<void> HandleSurfaceMessage(pdx::Message& message);
  87. HardwareComposer hardware_composer_;
  88. EpollEventDispatcher dispatcher_;
  89. DisplayConfigurationUpdateNotifier update_notifier_;
  90. std::unordered_map<DvrGlobalBufferKey, std::unique_ptr<IonBuffer>>
  91. global_buffers_;
  92. DisplayService(const DisplayService&) = delete;
  93. void operator=(const DisplayService&) = delete;
  94. };
  95. } // namespace dvr
  96. } // namespace android
  97. #endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_