Skip to content

Commit

Permalink
wolvic: Break down processing frame code in separated methods
Browse files Browse the repository at this point in the history
This breaks down the processing frame state in a new method,
DrawFrameSubmitNow.

This also makes sure (by DCHECKing) that when OnWebXrFrameAvailable
runs, the frame arriving is still in the processing state and
guaranteeing the correct order functioning as defined by
WebXrPresentationState. Besides, it removes an unused member of the main
class (last_frame_index_).
  • Loading branch information
tiagovignatti committed Aug 21, 2023
1 parent ee600a4 commit d64ce0e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
54 changes: 34 additions & 20 deletions wolvic/browser/vr/wvr_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,25 +309,16 @@ void WvrManager::OnWebXrFrameAvailable() {
if (!webxr_frame_timeout_closure_.IsCancelled())
webxr_frame_timeout_closure_.Cancel();

// The processing frame would be empty when this method is called again from
// Android system after OnWebXrTimedOut.
if (webxr_.HaveProcessingFrame()) {
// Frame should be locked. Unlock it.
DCHECK(webxr_.GetProcessingFrame()->state_locked);
webxr_.GetProcessingFrame()->state_locked = false;

if (!SubmitFrameInternal(webxr_.GetProcessingFrame()->index))
return;

if (webxr_.HaveRenderingFrame())
webxr_.EndFrameRendering();
webxr_.TransitionFrameProcessingToRendering();
}
// LIFECYCLE: we should be in processing state.
DCHECK(webxr_.HaveProcessingFrame());
device::WebXrFrame* processing_frame = webxr_.GetProcessingFrame();

// Renderer is waiting for the previous frame to render, unblock it now.
submit_client_->OnSubmitFrameRendered();
// Frame should be locked. Unlock it.
DCHECK(processing_frame->state_locked);
processing_frame->state_locked = false;

WebXrTryStartAnimatingFrame();
// Continue with submit immediately.
DrawFrameSubmitNow(processing_frame);
}

void WvrManager::OnWebXrTimedOut() {
Expand Down Expand Up @@ -499,6 +490,26 @@ WvrManager::GetInputSourceState() {
return input_sources;
}

void WvrManager::DrawFrameSubmitNow(device::WebXrFrame* processing_frame) {
if (!SubmitFrameInternal(processing_frame->index))
return;

// Report rendering completion to the Renderer so that it's permitted to
// submit a fresh frame. We could do this earlier, as soon as the frame
// got pulled off the transfer surface, but that results in overstuffed
// buffers.

// Renderer is waiting for the previous frame to render, unblock it now.
submit_client_->OnSubmitFrameRendered();

if (webxr_.HaveRenderingFrame())
webxr_.EndFrameRendering();
webxr_.TransitionFrameProcessingToRendering();

// See if we can animate a new WebXR frame.
WebXrTryStartAnimatingFrame();
}

bool WvrManager::WebVrCanAnimateFrame() {
// If we already have a JS frame that's animating, don't send another one.
// This check depends on the Renderer calling either SubmitFrame or
Expand Down Expand Up @@ -593,16 +604,19 @@ bool WvrManager::SubmitFrameInternal(int16_t frame_index) {

if (exit_vr_callback_)
std::move(exit_vr_callback_).Run();
DLOG(WARNING) << __func__
<< "Presenting generation changed. Don't submit frame";
return false;
}

last_frame_index_ = frame_index;

if (!wvr_api_->SyncState(frame_index,
graphics_->webxr_texture_handle(),
graphics_->webxr_surface_size().width(),
graphics_->webxr_surface_size().height()))
graphics_->webxr_surface_size().height())) {
DLOG(WARNING) << __func__
<< "SyncState failed. Don't submit frame";
return false;
}

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions wolvic/browser/vr/wvr_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class WvrManager : public device::mojom::XRPresentationProvider,
device::mojom::XRRuntimeSessionOptionsPtr options,
base::OnceCallback<void(device::mojom::XRSessionPtr)> callback);

void DrawFrameSubmitNow(device::WebXrFrame* processing_frame);

device::mojom::XRPresentationTransportOptionsPtr
GetWebXrFrameTransportOptions(
const device::mojom::XRRuntimeSessionOptionsPtr&);
Expand Down Expand Up @@ -122,8 +124,6 @@ class WvrManager : public device::mojom::XRPresentationProvider,
device::mojom::XRFrameDataProvider::GetFrameDataCallback
get_frame_data_callback_;

uint64_t last_frame_index_ = 0;

// Communicate with the renderer.
mojo::Receiver<device::mojom::XRPresentationProvider> presentation_receiver_{
this};
Expand Down

0 comments on commit d64ce0e

Please sign in to comment.