1 #ifndef ANDROID_DVR_VR_FLINGER_H_ 2 #define ANDROID_DVR_VR_FLINGER_H_ 3 4 #include <thread> 5 #include <memory> 6 7 #include <pdx/service_dispatcher.h> 8 #include <vr/vr_manager/vr_manager.h> 9 10 namespace android { 11 12 namespace Hwc2 { 13 class Composer; 14 } // namespace Hwc2 15 16 namespace dvr { 17 18 class DisplayService; 19 20 class VrFlinger { 21 public: 22 using RequestDisplayCallback = std::function<void(bool)>; 23 static std::unique_ptr<VrFlinger> Create( 24 Hwc2::Composer* hidl, RequestDisplayCallback request_display_callback); 25 ~VrFlinger(); 26 27 // These functions are all called on surface flinger's main thread. 28 void OnBootFinished(); 29 void GrantDisplayOwnership(); 30 void SeizeDisplayOwnership(); 31 32 // dump all vr flinger state. 33 std::string Dump(); 34 35 private: 36 VrFlinger(); 37 bool Init(Hwc2::Composer* hidl, 38 RequestDisplayCallback request_display_callback); 39 40 // Needs to be a separate class for binder's ref counting 41 class PersistentVrStateCallback : public BnPersistentVrStateCallbacks { 42 public: PersistentVrStateCallback(RequestDisplayCallback request_display_callback)43 PersistentVrStateCallback(RequestDisplayCallback request_display_callback) 44 : request_display_callback_(request_display_callback) {} 45 void onPersistentVrStateChanged(bool enabled) override; 46 private: 47 RequestDisplayCallback request_display_callback_; 48 }; 49 50 std::thread dispatcher_thread_; 51 std::unique_ptr<android::pdx::ServiceDispatcher> dispatcher_; 52 std::shared_ptr<android::dvr::DisplayService> display_service_; 53 sp<PersistentVrStateCallback> persistent_vr_state_callback_; 54 RequestDisplayCallback request_display_callback_; 55 }; 56 57 } // namespace dvr 58 } // namespace android 59 60 #endif // ANDROID_DVR_VR_FLINGER_H_ 61