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