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