#ifndef ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_ #define ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_ #include #include #include #include #include #include #include #include #include #include #include #include "acquired_buffer.h" #include "display_surface.h" #include "epoll_event_dispatcher.h" #include "hardware_composer.h" namespace android { namespace dvr { // DisplayService implements the display service component of VrFlinger. class DisplayService : public pdx::ServiceBase { public: bool IsInitialized() const override; std::string DumpState(size_t max_length) override; void OnChannelClose(pdx::Message& message, const std::shared_ptr& channel) override; pdx::Status HandleMessage(pdx::Message& message) override; std::shared_ptr GetDisplaySurface(int surface_id) const; std::vector> GetDisplaySurfaces() const; std::vector> GetVisibleDisplaySurfaces() const; // Updates the list of actively displayed surfaces. This must be called after // any change to client/manager attributes that affect visibility or z order. void UpdateActiveDisplaySurfaces(); pdx::Status SetupGlobalBuffer( DvrGlobalBufferKey key, size_t size, uint64_t usage); pdx::Status DeleteGlobalBuffer(DvrGlobalBufferKey key); template void ForEachDisplaySurface(SurfaceType surface_type, A action) const { ForEachChannel([surface_type, action](const ChannelIterator::value_type& pair) mutable { auto surface = std::static_pointer_cast(pair.second); if (surface->surface_type() == surface_type) action(surface); }); } using DisplayConfigurationUpdateNotifier = std::function; void SetDisplayConfigurationUpdateNotifier( DisplayConfigurationUpdateNotifier notifier); using VSyncCallback = HardwareComposer::VSyncCallback; void SetVSyncCallback(VSyncCallback callback) { hardware_composer_.SetVSyncCallback(callback); } HWCDisplayMetrics GetDisplayMetrics() { return hardware_composer_.display_metrics(); } void GrantDisplayOwnership() { hardware_composer_.Enable(); } void SeizeDisplayOwnership() { hardware_composer_.Disable(); } private: friend BASE; friend DisplaySurface; friend class VrDisplayStateService; using RequestDisplayCallback = std::function; DisplayService(android::Hwc2::Composer* hidl, RequestDisplayCallback request_display_callback); pdx::Status OnGetGlobalBuffer( pdx::Message& message, DvrGlobalBufferKey key); pdx::Status OnGetMetrics(pdx::Message& message); pdx::Status OnGetConfigurationData( pdx::Message& message, display::ConfigFileType config_type); pdx::Status OnCreateSurface( pdx::Message& message, const display::SurfaceAttributes& attributes); pdx::Status OnSetupGlobalBuffer( pdx::Message& message, DvrGlobalBufferKey key, size_t size, uint64_t usage); pdx::Status OnDeleteGlobalBuffer(pdx::Message& message, DvrGlobalBufferKey key); // Temporary query for current VR status. Will be removed later. pdx::Status IsVrAppRunning(pdx::Message& message); pdx::Status AddEventHandler(int fd, int events, EpollEventDispatcher::Handler handler) { return dispatcher_.AddEventHandler(fd, events, handler); } pdx::Status RemoveEventHandler(int fd) { return dispatcher_.RemoveEventHandler(fd); } void SurfaceUpdated(SurfaceType surface_type, display::SurfaceUpdateFlags update_flags); // Called by DisplaySurface to signal that a surface property has changed and // the display manager should be notified. void NotifyDisplayConfigurationUpdate(); pdx::Status HandleSurfaceMessage(pdx::Message& message); HardwareComposer hardware_composer_; EpollEventDispatcher dispatcher_; DisplayConfigurationUpdateNotifier update_notifier_; std::unordered_map> global_buffers_; DisplayService(const DisplayService&) = delete; void operator=(const DisplayService&) = delete; }; } // namespace dvr } // namespace android #endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_