Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
GeckoView update: switch between Gecko and Servo browserState/Mutex/Cond
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Feb 4, 2019
1 parent 9acfc9f commit 4a975d7
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,11 @@ public void popBackHandler(Runnable aRunnable) {
mBackHandlers.removeLastOccurrence(aRunnable);
}

@Override
public void setIsServoSession(boolean aIsServo) {
queueRunnable(() -> setIsServo(aIsServo));
}

@Override
public void pushWorldBrightness(Object aKey, float aBrightness) {
if (mCurrentBrightness.second != aBrightness) {
Expand Down Expand Up @@ -999,4 +1004,5 @@ public void resetUIYaw() {
private native void resetUIYawNative();
private native void setControllersVisibleNative(boolean aVisible);
private native void runCallbackNative(long aCallback);
private native void setIsServo(boolean aIsServo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface WorldClickListener {
void setTrayVisible(boolean visible);
void setControllersVisible(boolean visible);
void setWindowSize(float targetWidth, float targetHeight);
void setIsServoSession(boolean aIsServo);
void keyboardDismissed();
void updateEnvironment();
void updatePointerColor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.TextPromptWidget;

import static org.mozilla.vrbrowser.utils.ServoUtils.isInstanceOfServoSession;

public class WindowWidget extends UIWidget implements SessionStore.SessionChangeListener,
GeckoSession.ContentDelegate, GeckoSession.PromptDelegate, TrayListener, BookmarkListener {
Expand Down Expand Up @@ -468,6 +469,8 @@ public void onCurrentSessionChange(GeckoSession aSession, int aId) {
mDisplay = null;
}

mWidgetManager.setIsServoSession(isInstanceOfServoSession(aSession));

mSessionId = aId;
mDisplay = aSession.acquireDisplay();
Log.d(LOGTAG, "surfaceChanged: " + aId);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,11 @@ BrowserWorld::ResetUIYaw() {
m.device->SetReorientTransform(matrix);
}

void
BrowserWorld::SetIsServo(const bool aIsServo) {
m.externalVR->SetSourceBrowser(aIsServo ? ExternalVR::VRBrowserType::Servo : ExternalVR::VRBrowserType::Gecko);
}

JNIEnv*
BrowserWorld::GetJNIEnv() const {
ASSERT_ON_RENDER_THREAD(nullptr);
Expand Down Expand Up @@ -1269,5 +1274,9 @@ JNI_METHOD(void, runCallbackNative)
}
}

JNI_METHOD(void, setIsServo)
(JNIEnv* aEnv, jboolean aIsServo) {
crow::BrowserWorld::Instance().SetIsServo(aIsServo);
}

} // extern "C"
1 change: 1 addition & 0 deletions app/src/main/cpp/BrowserWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class BrowserWorld {
void HideVRVideo();
void SetControllersVisible(const bool aVisible);
void ResetUIYaw();
void SetIsServo(const bool aIsServo);
JNIEnv* GetJNIEnv() const;
protected:
struct State;
Expand Down
39 changes: 32 additions & 7 deletions app/src/main/cpp/ExternalVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ namespace crow {

struct ExternalVR::State {
static ExternalVR::State * sState;
pthread_mutex_t* browserMutex;
pthread_cond_t* browserCond;
mozilla::gfx::VRBrowserState* sourceBrowserState;
mozilla::gfx::VRExternalShmem data;
mozilla::gfx::VRSystemState system;
mozilla::gfx::VRBrowserState browser;
Expand All @@ -133,16 +136,20 @@ struct ExternalVR::State {

State() : deviceCapabilities(0) {
pthread_mutex_init(&data.systemMutex, nullptr);
pthread_mutex_init(&data.browserMutex, nullptr);
pthread_mutex_init(&data.geckoMutex, nullptr);
pthread_mutex_init(&data.servoMutex, nullptr);
pthread_cond_init(&data.systemCond, nullptr);
pthread_cond_init(&data.browserCond, nullptr);
pthread_cond_init(&data.geckoCond, nullptr);
pthread_cond_init(&data.servoCond, nullptr);
}

~State() {
pthread_mutex_destroy(&(data.systemMutex));
pthread_mutex_destroy(&(data.browserMutex));
pthread_mutex_destroy(&(data.geckoMutex));
pthread_mutex_destroy(&(data.servoMutex));
pthread_cond_destroy(&(data.systemCond));
pthread_cond_destroy(&(data.browserCond));
pthread_cond_destroy(&(data.geckoCond));
pthread_cond_destroy(&(data.servoCond));
}

void Reset() {
Expand All @@ -160,6 +167,7 @@ struct ExternalVR::State {
lastFrameId = 0;
firstPresentingFrame = false;
waitingForExit = false;
SetSourceBrowser(VRBrowserType::Gecko);
}

static ExternalVR::State& Instance() {
Expand All @@ -172,7 +180,7 @@ struct ExternalVR::State {

void PullBrowserStateWhileLocked() {
const bool wasPresenting = IsPresenting();
memcpy(&browser, &data.browserState, sizeof(mozilla::gfx::VRBrowserState));
memcpy(&browser, sourceBrowserState, sizeof(mozilla::gfx::VRBrowserState));


if ((!wasPresenting && IsPresenting()) || browser.navigationTransitionActive) {
Expand All @@ -187,6 +195,18 @@ struct ExternalVR::State {
bool IsPresenting() const {
return browser.presentationActive || browser.navigationTransitionActive || browser.layerState[0].type == mozilla::gfx::VRLayerType::LayerType_Stereo_Immersive;
}

void SetSourceBrowser(VRBrowserType aBrowser) {
if (aBrowser == VRBrowserType::Gecko) {
browserCond = &data.geckoCond;
browserMutex = &data.geckoMutex;
sourceBrowserState = &data.geckoState;
} else {
browserCond = &data.servoCond;
browserMutex = &data.servoMutex;
sourceBrowserState = &data.servoState;
}
}
};

ExternalVR::State * ExternalVR::State::sState = nullptr;
Expand Down Expand Up @@ -283,12 +303,17 @@ ExternalVR::PushSystemState() {

void
ExternalVR::PullBrowserState() {
Lock lock(m.data.browserMutex);
Lock lock(*m.browserMutex);
if (lock.IsLocked()) {
m.PullBrowserStateWhileLocked();
}
}

void
ExternalVR::SetSourceBrowser(VRBrowserType aBrowser) {
m.SetSourceBrowser(aBrowser);
}

void
ExternalVR::SetCompositorEnabled(bool aEnabled) {
if (aEnabled == m.compositorEnabled) {
Expand Down Expand Up @@ -409,7 +434,7 @@ ExternalVR::PushFramePoses(const vrb::Matrix& aHeadTransform, const std::vector<

bool
ExternalVR::WaitFrameResult() {
Wait wait(m.data.browserMutex, m.data.browserCond);
Wait wait(*m.browserMutex, *m.browserCond);
wait.Lock();
// browserMutex is locked in wait.lock().
m.PullBrowserStateWhileLocked();
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/cpp/ExternalVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class ExternalVR : public ImmersiveDisplay {
LinkTraversal,
Rendering
};
enum class VRBrowserType {
Gecko,
Servo
};
static ExternalVRPtr Create();
mozilla::gfx::VRExternalShmem* GetSharedData();
// DeviceDisplay interface
Expand All @@ -51,6 +55,7 @@ class ExternalVR : public ImmersiveDisplay {
bool WaitFrameResult();
void GetFrameResult(int32_t& aSurfaceHandle, device::EyeRect& aLeftEye, device::EyeRect& aRightEye) const;
void StopPresenting();
void SetSourceBrowser(VRBrowserType aBrowser);
~ExternalVR();
protected:
struct State;
Expand Down

0 comments on commit 4a975d7

Please sign in to comment.