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 | |
| 4 | #include <pdx/service.h> |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 5 | #include <pdx/status.h> |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 6 | #include <private/dvr/buffer_hub_client.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 | |
Hendrik Wagenaar | eaa5522 | 2017-04-06 10:56:23 -0700 | [diff] [blame] | 43 | pdx::Status<BorrowedNativeBufferHandle> SetupNamedBuffer( |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 44 | const std::string& name, size_t size, uint64_t usage); |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 45 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 46 | template <class A> |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 47 | void ForEachDisplaySurface(SurfaceType surface_type, A action) const { |
| 48 | ForEachChannel([surface_type, |
| 49 | action](const ChannelIterator::value_type& pair) mutable { |
| 50 | auto surface = std::static_pointer_cast<DisplaySurface>(pair.second); |
| 51 | if (surface->surface_type() == surface_type) |
| 52 | action(surface); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 53 | }); |
| 54 | } |
| 55 | |
| 56 | using DisplayConfigurationUpdateNotifier = std::function<void(void)>; |
| 57 | void SetDisplayConfigurationUpdateNotifier( |
| 58 | DisplayConfigurationUpdateNotifier notifier); |
| 59 | |
| 60 | using VSyncCallback = HardwareComposer::VSyncCallback; |
| 61 | void SetVSyncCallback(VSyncCallback callback) { |
| 62 | hardware_composer_.SetVSyncCallback(callback); |
| 63 | } |
| 64 | |
| 65 | HWCDisplayMetrics GetDisplayMetrics() { |
| 66 | return hardware_composer_.display_metrics(); |
| 67 | } |
| 68 | |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 69 | void GrantDisplayOwnership() { hardware_composer_.Enable(); } |
| 70 | void SeizeDisplayOwnership() { hardware_composer_.Disable(); } |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 71 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 72 | void OnHardwareComposerRefresh(); |
| 73 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 74 | private: |
| 75 | friend BASE; |
| 76 | friend DisplaySurface; |
| 77 | |
| 78 | friend class VrDisplayStateService; |
| 79 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 80 | using RequestDisplayCallback = std::function<void(bool)>; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 81 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 82 | DisplayService(android::Hwc2::Composer* hidl, |
| 83 | RequestDisplayCallback request_display_callback); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 84 | |
Hendrik Wagenaar | eaa5522 | 2017-04-06 10:56:23 -0700 | [diff] [blame] | 85 | pdx::Status<BorrowedNativeBufferHandle> OnGetNamedBuffer( |
| 86 | pdx::Message& message, const std::string& name); |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 87 | pdx::Status<display::Metrics> OnGetMetrics(pdx::Message& message); |
| 88 | pdx::Status<display::SurfaceInfo> OnCreateSurface( |
| 89 | pdx::Message& message, const display::SurfaceAttributes& attributes); |
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 | RequestDisplayCallback request_display_callback_; |
| 113 | EpollEventDispatcher dispatcher_; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 114 | DisplayConfigurationUpdateNotifier update_notifier_; |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 115 | |
Hendrik Wagenaar | eaa5522 | 2017-04-06 10:56:23 -0700 | [diff] [blame] | 116 | std::unordered_map<std::string, std::unique_ptr<IonBuffer>> named_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_ |