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> |
| 5 | #include <private/dvr/buffer_hub_client.h> |
| 6 | #include <private/dvr/display_rpc.h> |
| 7 | #include <private/dvr/late_latch.h> |
| 8 | |
| 9 | #include <functional> |
| 10 | #include <iterator> |
| 11 | #include <memory> |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
| 15 | #include "acquired_buffer.h" |
| 16 | #include "display_surface.h" |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 17 | #include "hardware_composer.h" |
| 18 | |
| 19 | namespace android { |
| 20 | namespace dvr { |
| 21 | |
| 22 | // DisplayService implements the displayd display service over ServiceFS. |
| 23 | class DisplayService : public pdx::ServiceBase<DisplayService> { |
| 24 | public: |
Stephen Kiazyk | 016e5e3 | 2017-02-21 17:09:22 -0800 | [diff] [blame] | 25 | bool IsInitialized() const override; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 26 | std::string DumpState(size_t max_length) override; |
| 27 | |
| 28 | void OnChannelClose(pdx::Message& message, |
| 29 | const std::shared_ptr<pdx::Channel>& channel) override; |
| 30 | int HandleMessage(pdx::Message& message) override; |
| 31 | |
| 32 | std::shared_ptr<DisplaySurface> GetDisplaySurface(int surface_id) const; |
| 33 | std::vector<std::shared_ptr<DisplaySurface>> GetDisplaySurfaces() const; |
| 34 | std::vector<std::shared_ptr<DisplaySurface>> GetVisibleDisplaySurfaces() |
| 35 | const; |
| 36 | |
| 37 | // Updates the list of actively displayed surfaces. This must be called after |
| 38 | // any change to client/manager attributes that affect visibility or z order. |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 39 | void UpdateActiveDisplaySurfaces(); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 40 | |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 41 | pdx::BorrowedChannelHandle SetupPoseBuffer(size_t extended_region_size, |
| 42 | int usage); |
| 43 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 44 | template <class A> |
| 45 | void ForEachDisplaySurface(A action) const { |
| 46 | ForEachChannel([action](const ChannelIterator::value_type& pair) mutable { |
| 47 | auto surface = std::static_pointer_cast<SurfaceChannel>(pair.second); |
| 48 | if (surface->type() == SurfaceTypeEnum::Normal) |
| 49 | action(std::static_pointer_cast<DisplaySurface>(surface)); |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | using DisplayConfigurationUpdateNotifier = std::function<void(void)>; |
| 54 | void SetDisplayConfigurationUpdateNotifier( |
| 55 | DisplayConfigurationUpdateNotifier notifier); |
| 56 | |
| 57 | using VSyncCallback = HardwareComposer::VSyncCallback; |
| 58 | void SetVSyncCallback(VSyncCallback callback) { |
| 59 | hardware_composer_.SetVSyncCallback(callback); |
| 60 | } |
| 61 | |
| 62 | HWCDisplayMetrics GetDisplayMetrics() { |
| 63 | return hardware_composer_.display_metrics(); |
| 64 | } |
| 65 | |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 66 | void GrantDisplayOwnership() { hardware_composer_.Enable(); } |
| 67 | void SeizeDisplayOwnership() { hardware_composer_.Disable(); } |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 68 | |
Steven Thomas | 3cfac28 | 2017-02-06 12:29:30 -0800 | [diff] [blame] | 69 | void OnHardwareComposerRefresh(); |
| 70 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 71 | private: |
| 72 | friend BASE; |
| 73 | friend DisplaySurface; |
| 74 | |
| 75 | friend class VrDisplayStateService; |
| 76 | |
| 77 | DisplayService(); |
| 78 | DisplayService(android::Hwc2::Composer* hidl); |
| 79 | |
| 80 | SystemDisplayMetrics OnGetMetrics(pdx::Message& message); |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 81 | int OnCreateSurface(pdx::Message& message, int width, int height, int format, |
| 82 | int usage, DisplaySurfaceFlags flags); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 83 | |
| 84 | DisplayRPC::ByteBuffer OnGetEdsCapture(pdx::Message& message); |
| 85 | |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 86 | void OnSetViewerParams(pdx::Message& message, |
| 87 | const ViewerParams& view_params); |
| 88 | pdx::LocalChannelHandle OnGetPoseBuffer(pdx::Message& message); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 89 | |
Albert Chaulk | b7c8a4b | 2017-03-20 13:03:39 -0400 | [diff] [blame^] | 90 | // Temporary query for current VR status. Will be removed later. |
| 91 | int IsVrAppRunning(pdx::Message& message); |
| 92 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 93 | // Called by DisplaySurface to signal that a surface property has changed and |
| 94 | // the display manager should be notified. |
| 95 | void NotifyDisplayConfigurationUpdate(); |
| 96 | |
| 97 | int HandleSurfaceMessage(pdx::Message& message); |
| 98 | |
| 99 | DisplayService(const DisplayService&) = delete; |
| 100 | void operator=(const DisplayService&) = delete; |
| 101 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 102 | HardwareComposer hardware_composer_; |
| 103 | DisplayConfigurationUpdateNotifier update_notifier_; |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 104 | |
| 105 | std::unique_ptr<BufferProducer> pose_buffer_; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | } // namespace dvr |
| 109 | } // namespace android |
| 110 | |
| 111 | #endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_ |