@@ -212,17 +212,20 @@ namespace gamescope
212212 float flAlpha = 1 .0f ;
213213 };
214214
215- class COpenVRPlane
215+ class COpenVRPlane final : public IBackendPlane
216216 {
217217 public:
218218 COpenVRPlane ( COpenVRConnector *pConnector );
219219 ~COpenVRPlane ();
220220
221221 bool Init ( COpenVRPlane *pParent, COpenVRPlane *pSiblingBelow );
222+ void InitAsForwarder ( vr::VROverlayHandle_t hOverlay ) { m_hOverlay = hOverlay; }
222223
223224 void Present ( std::optional<OpenVRPlaneState> oState );
224225 void Present ( const FrameInfo_t::Layer_t *pLayer );
225226
227+ void ForwardFramebuffer ( COpenVRFb *pFb );
228+
226229 vr::VROverlayHandle_t GetOverlay () const { return m_hOverlay; }
227230 vr::VROverlayHandle_t GetOverlayThumbnail () const { return m_hOverlayThumbnail; }
228231
@@ -424,6 +427,17 @@ namespace gamescope
424427 }
425428 }
426429
430+ {
431+ std::scoped_lock lock{ m_mutForwarderPlanes };
432+
433+ for ( std::shared_ptr<COpenVRPlane> &pPlane : m_pForwarderPlanesInFlight )
434+ {
435+ pPlane->OnPageFlip ();
436+ }
437+
438+ m_pForwarderPlanesInFlight.clear ();
439+ }
440+
427441 ProcessVRInput ();
428442 }
429443 }
@@ -898,16 +912,31 @@ namespace gamescope
898912 return true ;
899913 }
900914
901- void ForwardFramebuffer ( IBackendFb *pFramebuffer, const void *pData ) override
915+ void ForwardFramebuffer ( std::shared_ptr<IBackendPlane> &pPlane, IBackendFb *pFramebuffer, const void *pData ) override
902916 {
903917 COpenVRFb *pVRFB = static_cast <COpenVRFb *>( pFramebuffer );
904918
905919 vr::VROverlayHandle_t hOverlay = static_cast <vr::VROverlayHandle_t>( *reinterpret_cast <const uint64_t *>( pData ) );
906- vr::SharedTextureHandle_t ulHandle = pVRFB->GetSharedTextureHandle ();
907-
908920 openvr_log.debugf ( " Forwarding for overlay: %lx" , (unsigned long )hOverlay );
909- vr::Texture_t texture = { (void *)&ulHandle, vr::TextureType_SharedTextureHandle, vr::ColorSpace_Gamma };
910- vr::VROverlay ()->SetOverlayTexture ( hOverlay, &texture );
921+
922+ if ( !pPlane )
923+ {
924+ std::shared_ptr<COpenVRPlane> pOpenVRPlane = std::make_shared<COpenVRPlane>( nullptr );
925+ pOpenVRPlane->InitAsForwarder ( hOverlay );
926+ pPlane = pOpenVRPlane;
927+ }
928+
929+ std::shared_ptr<COpenVRPlane> pOpenVRPlane = std::static_pointer_cast<COpenVRPlane>( pPlane );
930+ assert ( pOpenVRPlane->GetOverlay () == hOverlay );
931+
932+ pOpenVRPlane->ForwardFramebuffer ( pVRFB );
933+ {
934+ std::scoped_lock lock{ m_mutForwarderPlanes };
935+ if ( !Algorithm::Contains ( m_pForwarderPlanesInFlight, pOpenVRPlane ) )
936+ {
937+ m_pForwarderPlanesInFlight.emplace_back ( std::move ( pOpenVRPlane ) );
938+ }
939+ }
911940 }
912941
913942 vr::IVRIPCResourceManagerClient *GetIPCResourceManager ()
@@ -1334,6 +1363,9 @@ namespace gamescope
13341363 std::shared_ptr<CLibInputHandler> m_pLibInput;
13351364 CAsyncWaiter<CRawPointer<IWaitable>, 16 > m_LibInputWaiter;
13361365
1366+ std::mutex m_mutForwarderPlanes;
1367+ std::vector<std::shared_ptr<COpenVRPlane>> m_pForwarderPlanesInFlight;
1368+
13371369 // Threads need to go last, as they rely on the other things in the class being constructed before their code is run.
13381370 std::thread m_FlipHandlerThread;
13391371 };
@@ -1681,7 +1713,7 @@ namespace gamescope
16811713
16821714 COpenVRPlane::COpenVRPlane ( COpenVRConnector *pConnector )
16831715 : m_pConnector{ pConnector }
1684- , m_pBackend{ pConnector->GetBackend () }
1716+ , m_pBackend{ pConnector ? pConnector ->GetBackend () : nullptr }
16851717 {
16861718 }
16871719 COpenVRPlane::~COpenVRPlane ()
@@ -1888,6 +1920,19 @@ namespace gamescope
18881920 }
18891921 }
18901922
1923+ void COpenVRPlane::ForwardFramebuffer ( COpenVRFb *pFb )
1924+ {
1925+ vr::SharedTextureHandle_t ulHandle = pFb->GetSharedTextureHandle ();
1926+
1927+ vr::Texture_t texture = { (void *)&ulHandle, vr::TextureType_SharedTextureHandle, vr::ColorSpace_Gamma };
1928+ vr::VROverlay ()->SetOverlayTexture ( m_hOverlay, &texture );
1929+
1930+ {
1931+ std::scoped_lock lock{ m_mutFbIds };
1932+ m_pQueuedFbId = pFb;
1933+ }
1934+ }
1935+
18911936 void COpenVRPlane::OnPageFlip ()
18921937 {
18931938 {
0 commit comments