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