Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 1 | #ifndef ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_ |
| 2 | #define ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_ |
| 3 | |
Okan Arikan | 36d2380 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 4 | #include <dvr/dvr_api.h> |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 5 | #include <pdx/service.h> |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 6 | #include <pdx/status.h> |
Hendrik Wagenaar | eaa5522 | 2017-04-06 10:56:23 -0700 | [diff] [blame] | 7 | #include <private/dvr/bufferhub_rpc.h> |
Corey Tabaka | 3f82d31 | 2017-04-20 14:42:08 -0700 | [diff] [blame] | 8 | #include <private/dvr/display_protocol.h> |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 9 | |
| 10 | #include <functional> |
| 11 | #include <iterator> |
| 12 | #include <memory> |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
| 16 | #include "acquired_buffer.h" |
| 17 | #include "display_surface.h" |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 18 | #include "epoll_event_dispatcher.h" |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 19 | #include "hardware_composer.h" |
| 20 | |
| 21 | namespace android { |
| 22 | namespace dvr { |
| 23 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 24 | // DisplayService implements the display service component of VrFlinger. |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 25 | class DisplayService : public pdx::ServiceBase<DisplayService> { |
| 26 | public: |
Stephen Kiazyk | 016e5e3 | 2017-02-21 17:09:22 -0800 | [diff] [blame] | 27 | bool IsInitialized() const override; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 28 | std::string DumpState(size_t max_length) override; |
| 29 | |
| 30 | void OnChannelClose(pdx::Message& message, |
| 31 | const std::shared_ptr<pdx::Channel>& channel) override; |
Alex Vakulenko | f0a7bd0 | 2017-03-31 18:06:19 -0700 | [diff] [blame] | 32 | pdx::Status<void> HandleMessage(pdx::Message& message) override; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 33 | |
| 34 | std::shared_ptr<DisplaySurface> GetDisplaySurface(int surface_id) const; |
| 35 | std::vector<std::shared_ptr<DisplaySurface>> GetDisplaySurfaces() const; |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 36 | std::vector<std::shared_ptr<DirectDisplaySurface>> GetVisibleDisplaySurfaces() |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 37 | const; |
| 38 | |
| 39 | // Updates the list of actively displayed surfaces. This must be called after |
| 40 | // any change to client/manager attributes that affect visibility or z order. |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 41 | void UpdateActiveDisplaySurfaces(); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 42 | |
Okan Arikan | 36d2380 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 43 | pdx::Status<BorrowedNativeBufferHandle> SetupGlobalBuffer( |
| 44 | DvrGlobalBufferKey key, size_t size, uint64_t usage); |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 45 | |
John Bates | 954796e | 2017-05-11 11:00:31 -0700 | [diff] [blame] | 46 | pdx::Status<void> DeleteGlobalBuffer(DvrGlobalBufferKey key); |
| 47 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 48 | template <class A> |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 49 | void ForEachDisplaySurface(SurfaceType surface_type, A action) const { |
| 50 | ForEachChannel([surface_type, |
| 51 | action](const ChannelIterator::value_type& pair) mutable { |
| 52 | auto surface = std::static_pointer_cast<DisplaySurface>(pair.second); |
| 53 | if (surface->surface_type() == surface_type) |
| 54 | action(surface); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 55 | }); |
| 56 | } |
| 57 | |
| 58 | using DisplayConfigurationUpdateNotifier = std::function<void(void)>; |
| 59 | void SetDisplayConfigurationUpdateNotifier( |
| 60 | DisplayConfigurationUpdateNotifier notifier); |
| 61 | |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 62 | void GrantDisplayOwnership() { hardware_composer_.Enable(); } |
| 63 | void SeizeDisplayOwnership() { hardware_composer_.Disable(); } |
Steven Thomas | af33627 | 2018-01-04 17:36:47 -0800 | [diff] [blame] | 64 | void OnBootFinished() { hardware_composer_.OnBootFinished(); } |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 65 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 66 | private: |
| 67 | friend BASE; |
| 68 | friend DisplaySurface; |
| 69 | |
| 70 | friend class VrDisplayStateService; |
| 71 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 72 | using RequestDisplayCallback = std::function<void(bool)>; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 73 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 74 | DisplayService(android::Hwc2::Composer* hidl, |
Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 75 | hwc2_display_t primary_display_id, |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 76 | RequestDisplayCallback request_display_callback); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 77 | |
Okan Arikan | 36d2380 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 78 | pdx::Status<BorrowedNativeBufferHandle> OnGetGlobalBuffer( |
| 79 | pdx::Message& message, DvrGlobalBufferKey key); |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 80 | pdx::Status<display::Metrics> OnGetMetrics(pdx::Message& message); |
Hendrik Wagenaar | bcb03d0 | 2017-05-23 14:59:08 -0700 | [diff] [blame] | 81 | pdx::Status<std::string> OnGetConfigurationData( |
| 82 | pdx::Message& message, display::ConfigFileType config_type); |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 83 | pdx::Status<display::SurfaceInfo> OnCreateSurface( |
| 84 | pdx::Message& message, const display::SurfaceAttributes& attributes); |
Corey Tabaka | 99c2d73 | 2017-06-07 17:54:33 -0700 | [diff] [blame] | 85 | pdx::Status<BorrowedNativeBufferHandle> OnSetupGlobalBuffer( |
| 86 | pdx::Message& message, DvrGlobalBufferKey key, size_t size, |
| 87 | uint64_t usage); |
| 88 | pdx::Status<void> OnDeleteGlobalBuffer(pdx::Message& message, |
| 89 | DvrGlobalBufferKey key); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 90 | |
Albert Chaulk | b7c8a4b | 2017-03-20 13:03:39 -0400 | [diff] [blame] | 91 | // Temporary query for current VR status. Will be removed later. |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 92 | pdx::Status<bool> IsVrAppRunning(pdx::Message& message); |
| 93 | |
| 94 | pdx::Status<void> AddEventHandler(int fd, int events, |
| 95 | EpollEventDispatcher::Handler handler) { |
| 96 | return dispatcher_.AddEventHandler(fd, events, handler); |
| 97 | } |
| 98 | pdx::Status<void> RemoveEventHandler(int fd) { |
| 99 | return dispatcher_.RemoveEventHandler(fd); |
| 100 | } |
| 101 | |
| 102 | void SurfaceUpdated(SurfaceType surface_type, |
| 103 | display::SurfaceUpdateFlags update_flags); |
Albert Chaulk | b7c8a4b | 2017-03-20 13:03:39 -0400 | [diff] [blame] | 104 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 105 | // Called by DisplaySurface to signal that a surface property has changed and |
| 106 | // the display manager should be notified. |
| 107 | void NotifyDisplayConfigurationUpdate(); |
| 108 | |
Alex Vakulenko | f0a7bd0 | 2017-03-31 18:06:19 -0700 | [diff] [blame] | 109 | pdx::Status<void> HandleSurfaceMessage(pdx::Message& message); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 110 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 111 | HardwareComposer hardware_composer_; |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 112 | EpollEventDispatcher dispatcher_; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 113 | DisplayConfigurationUpdateNotifier update_notifier_; |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 114 | |
Okan Arikan | 36d2380 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 115 | std::unordered_map<DvrGlobalBufferKey, std::unique_ptr<IonBuffer>> |
| 116 | global_buffers_; |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 117 | |
| 118 | DisplayService(const DisplayService&) = delete; |
| 119 | void operator=(const DisplayService&) = delete; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | } // namespace dvr |
| 123 | } // namespace android |
| 124 | |
| 125 | #endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_ |