display_service.h revision a3613612a1142c3134045f08c30a861ea43288ed
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 int 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 SetActive(bool activated) { 64 if (activated) { 65 hardware_composer_.Resume(); 66 } else { 67 hardware_composer_.Suspend(); 68 } 69 } 70 71 void OnHardwareComposerRefresh(); 72 73 private: 74 friend BASE; 75 friend DisplaySurface; 76 77 friend class VrDisplayStateService; 78 79 DisplayService(); 80 DisplayService(android::Hwc2::Composer* hidl); 81 82 SystemDisplayMetrics OnGetMetrics(pdx::Message& message); 83 int OnCreateSurface(pdx::Message& message, int width, int height, 84 int format, int usage, DisplaySurfaceFlags flags); 85 86 DisplayRPC::ByteBuffer OnGetEdsCapture(pdx::Message& message); 87 88 int OnEnterVrMode(pdx::Message& message); 89 int OnExitVrMode(pdx::Message& message); 90 void OnSetViewerParams(pdx::Message& message, const ViewerParams& view_params); 91 92 // Called by DisplaySurface to signal that a surface property has changed and 93 // the display manager should be notified. 94 void NotifyDisplayConfigurationUpdate(); 95 96 int HandleSurfaceMessage(pdx::Message& message); 97 98 DisplayService(const DisplayService&) = delete; 99 void operator=(const DisplayService&) = delete; 100 101 HardwareComposer hardware_composer_; 102 DisplayConfigurationUpdateNotifier update_notifier_; 103}; 104 105} // namespace dvr 106} // namespace android 107 108#endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_ 109