display_service.h revision f43d13e4e35ae7d3cdafc4b97c819669d42cef78
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" 17#include "hardware_composer.h" 18 19namespace android { 20namespace dvr { 21 22// DisplayService implements the displayd display service over ServiceFS. 23class DisplayService : public pdx::ServiceBase<DisplayService> { 24 public: 25 bool IsInitialized() const override; 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. 39 void UpdateActiveDisplaySurfaces(); 40 41 template <class A> 42 void ForEachDisplaySurface(A action) const { 43 ForEachChannel([action](const ChannelIterator::value_type& pair) mutable { 44 auto surface = std::static_pointer_cast<SurfaceChannel>(pair.second); 45 if (surface->type() == SurfaceTypeEnum::Normal) 46 action(std::static_pointer_cast<DisplaySurface>(surface)); 47 }); 48 } 49 50 using DisplayConfigurationUpdateNotifier = std::function<void(void)>; 51 void SetDisplayConfigurationUpdateNotifier( 52 DisplayConfigurationUpdateNotifier notifier); 53 54 using VSyncCallback = HardwareComposer::VSyncCallback; 55 void SetVSyncCallback(VSyncCallback callback) { 56 hardware_composer_.SetVSyncCallback(callback); 57 } 58 59 HWCDisplayMetrics GetDisplayMetrics() { 60 return hardware_composer_.display_metrics(); 61 } 62 63 void GrantDisplayOwnership() { hardware_composer_.Enable(); } 64 void SeizeDisplayOwnership() { hardware_composer_.Disable(); } 65 66 void OnHardwareComposerRefresh(); 67 68 private: 69 friend BASE; 70 friend DisplaySurface; 71 72 friend class VrDisplayStateService; 73 74 DisplayService(); 75 DisplayService(android::Hwc2::Composer* hidl); 76 77 SystemDisplayMetrics OnGetMetrics(pdx::Message& message); 78 int OnCreateSurface(pdx::Message& message, int width, int height, 79 int format, int usage, DisplaySurfaceFlags flags); 80 81 DisplayRPC::ByteBuffer OnGetEdsCapture(pdx::Message& message); 82 83 void OnSetViewerParams(pdx::Message& message, const ViewerParams& view_params); 84 85 // Called by DisplaySurface to signal that a surface property has changed and 86 // the display manager should be notified. 87 void NotifyDisplayConfigurationUpdate(); 88 89 int HandleSurfaceMessage(pdx::Message& message); 90 91 DisplayService(const DisplayService&) = delete; 92 void operator=(const DisplayService&) = delete; 93 94 HardwareComposer hardware_composer_; 95 DisplayConfigurationUpdateNotifier update_notifier_; 96}; 97 98} // namespace dvr 99} // namespace android 100 101#endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_ 102