display_service.h revision 0057fddc71d1c3c3de8f9d0bd45a51bb293bfa3c
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/bufferhub_rpc.h> 7#include <private/dvr/display_rpc.h> 8#include <private/dvr/late_latch.h> 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" 18#include "hardware_composer.h" 19 20namespace android { 21namespace dvr { 22 23// DisplayService implements the displayd display service over ServiceFS. 24class DisplayService : public pdx::ServiceBase<DisplayService> { 25 public: 26 bool IsInitialized() const override; 27 std::string DumpState(size_t max_length) override; 28 29 void OnChannelClose(pdx::Message& message, 30 const std::shared_ptr<pdx::Channel>& channel) override; 31 pdx::Status<void> HandleMessage(pdx::Message& message) override; 32 33 std::shared_ptr<DisplaySurface> GetDisplaySurface(int surface_id) const; 34 std::vector<std::shared_ptr<DisplaySurface>> GetDisplaySurfaces() const; 35 std::vector<std::shared_ptr<DisplaySurface>> GetVisibleDisplaySurfaces() 36 const; 37 38 // Updates the list of actively displayed surfaces. This must be called after 39 // any change to client/manager attributes that affect visibility or z order. 40 void UpdateActiveDisplaySurfaces(); 41 42 pdx::Status<BorrowedNativeBufferHandle> SetupNamedBuffer( 43 const std::string& name, size_t size, int usage); 44 45 template <class A> 46 void ForEachDisplaySurface(A action) const { 47 ForEachChannel([action](const ChannelIterator::value_type& pair) mutable { 48 auto surface = std::static_pointer_cast<SurfaceChannel>(pair.second); 49 if (surface->type() == SurfaceTypeEnum::Normal) 50 action(std::static_pointer_cast<DisplaySurface>(surface)); 51 }); 52 } 53 54 using DisplayConfigurationUpdateNotifier = std::function<void(void)>; 55 void SetDisplayConfigurationUpdateNotifier( 56 DisplayConfigurationUpdateNotifier notifier); 57 58 using VSyncCallback = HardwareComposer::VSyncCallback; 59 void SetVSyncCallback(VSyncCallback callback) { 60 hardware_composer_.SetVSyncCallback(callback); 61 } 62 63 HWCDisplayMetrics GetDisplayMetrics() { 64 return hardware_composer_.display_metrics(); 65 } 66 67 void GrantDisplayOwnership() { hardware_composer_.Enable(); } 68 void SeizeDisplayOwnership() { hardware_composer_.Disable(); } 69 70 void OnHardwareComposerRefresh(); 71 72 private: 73 friend BASE; 74 friend DisplaySurface; 75 76 friend class VrDisplayStateService; 77 78 DisplayService(); 79 DisplayService(android::Hwc2::Composer* hidl); 80 81 SystemDisplayMetrics OnGetMetrics(pdx::Message& message); 82 int OnCreateSurface(pdx::Message& message, int width, int height, int format, 83 int usage, DisplaySurfaceFlags flags); 84 85 DisplayRPC::ByteBuffer OnGetEdsCapture(pdx::Message& message); 86 87 void OnSetViewerParams(pdx::Message& message, 88 const ViewerParams& view_params); 89 pdx::Status<BorrowedNativeBufferHandle> OnGetNamedBuffer( 90 pdx::Message& message, const std::string& name); 91 92 // Temporary query for current VR status. Will be removed later. 93 int IsVrAppRunning(pdx::Message& message); 94 95 // Called by DisplaySurface to signal that a surface property has changed and 96 // the display manager should be notified. 97 void NotifyDisplayConfigurationUpdate(); 98 99 pdx::Status<void> HandleSurfaceMessage(pdx::Message& message); 100 101 DisplayService(const DisplayService&) = delete; 102 void operator=(const DisplayService&) = delete; 103 104 HardwareComposer hardware_composer_; 105 DisplayConfigurationUpdateNotifier update_notifier_; 106 107 std::unordered_map<std::string, std::unique_ptr<IonBuffer>> named_buffers_; 108}; 109 110} // namespace dvr 111} // namespace android 112 113#endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_ 114