vr_flinger.h 1.9 KB

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