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

Commit

Permalink
Implement larger window on fullscreen. Handle video quality changes d…
Browse files Browse the repository at this point in the history
…uring VR playback. (#823)
  • Loading branch information
MortimerGoro authored and keianhzo committed Nov 23, 2018
1 parent 7af80bd commit 3b9d783
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ public void setControllersVisible(final boolean aVisible) {

@Override
public void setBrowserSize(float targetWidth, float targetHeight) {
mBrowserWidget.setSize(targetWidth, targetHeight, 1.0f);
mBrowserWidget.resizeByMultiplier(targetWidth / targetHeight, 1.0f);
}

@Override
Expand Down
19 changes: 19 additions & 0 deletions app/src/common/shared/org/mozilla/vrbrowser/browser/Media.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Media implements MediaElement.Delegate {
private boolean mIsUnloaded = false;
private org.mozilla.geckoview.MediaElement mMedia;
private MediaElement.Delegate mDelegate;
private ResizeDelegate mResizeDelegate;

public Media(@NonNull MediaElement aMediaElement) {
mMedia = aMediaElement;
Expand Down Expand Up @@ -113,6 +114,14 @@ public int getHeight() {
return mMetaData != null ? (int)mMetaData.height : 0;
}

public interface ResizeDelegate {
void onResize(int width, int height);
}

public void setResizeDelegate(ResizeDelegate aResizeDelegate) {
mResizeDelegate = aResizeDelegate;
}

// Media Element delegate
@Override
public void onPlaybackStateChange(MediaElement mediaElement, int playbackState) {
Expand All @@ -138,10 +147,20 @@ public void onReadyStateChange(MediaElement mediaElement, int readyState) {

@Override
public void onMetadataChange(MediaElement mediaElement, MediaElement.Metadata metaData) {
final int oldWidth = getWidth();
final int oldHeight = getHeight();
mMetaData = metaData;
if (mDelegate != null) {
mDelegate.onMetadataChange(mediaElement, metaData);
}

if (mResizeDelegate!= null && metaData != null) {
final int w = getWidth();
final int h = getHeight();
if (w > 0 && h > 0 && w != oldWidth || h != oldHeight) {
mResizeDelegate.onResize(w, h);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static int WINDOW_WIDTH_DEFAULT = 800;
public final static int WINDOW_HEIGHT_DEFAULT = 450;
public final static int DISPLAY_DPI_DEFAULT = 96;
public final static int MAX_WINDOW_WIDTH_DEFAULT = 800;
public final static int MAX_WINDOW_HEIGHT_DEFAULT = 450;
public final static int MAX_WINDOW_WIDTH_DEFAULT = 1200;
public final static int MAX_WINDOW_HEIGHT_DEFAULT = 1200;
public final static int POINTER_COLOR_DEFAULT_DEFAULT = Color.parseColor("#FFFFFF");
public final static String ENV_DEFAULT = "cave";
public final static float BROWSER_WORLD_WIDTH_DEFAULT = 4.0f;
Expand Down Expand Up @@ -220,6 +220,10 @@ public void setWindowHeight(int aWindowHeight) {
editor.commit();
}

public float getWindowAspect() {
return (float)getWindowWidth() / (float)getWindowHeight();
}

public int getDisplayDpi() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_display_dpi), DISPLAY_DPI_DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ private void initialize(Context aContext) {
}

@Override
public void setSize(float windowWidth, float windowHeight, float multiplier) {
public void resizeByMultiplier(float aspect, float multiplier) {
float worldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
float aspect = windowWidth / windowHeight;
float worldHeight = worldWidth / aspect;
float area = worldWidth * worldHeight * multiplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ public void disableVRVideoMode() {
}

@Override
public void setSize(float windowWidth, float windowHeight, float multiplier) {
public void resizeByMultiplier(float aspect, float multiplier) {
mMultiplier = multiplier;

float worldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
float aspect = windowWidth / windowHeight;
float worldHeight = worldWidth / aspect;
float area = worldWidth * worldHeight * multiplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private boolean mIsInFullScreenMode;
private boolean mIsResizing;
private boolean mIsInVRVideo;
private WidgetPlacement mSizeBeforeFullScreen;
private Runnable mResizeBackHandler;
private Runnable mFullScreenBackHandler;
private Runnable mVRVideoBackHandler;
Expand All @@ -88,6 +89,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private BrightnessMenuWidget mBrightnessWidget;
private MediaControlsWidget mMediaControlsWidget;
private BookmarksWidget mBookmarksWidget;
private Media mFullScreenMedia;

public NavigationBarWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -122,6 +124,7 @@ private void initialize(Context aContext) {
mBrightnessButton = findViewById(R.id.brightnessButton);
mFullScreenResizeButton = findViewById(R.id.fullScreenResizeEnterButton);
mProjectionButton = findViewById(R.id.projectionButton);
mSizeBeforeFullScreen = new WidgetPlacement(aContext);


mResizeBackHandler = () -> exitResizeMode(true);
Expand Down Expand Up @@ -344,10 +347,29 @@ public void setBookmarksWidget(BookmarksWidget aWidget) {
mBookmarksWidget = aWidget;
}

private void setFullScreenSize() {
SettingsStore settings = SettingsStore.getInstance(getContext());
mSizeBeforeFullScreen.copyFrom(mBrowserWidget.getPlacement());
final float oldWidth = settings.getBrowserWorldWidth();
final float oldHeight = settings.getBrowserWorldHeight();
// Set browser fullscreen size
float aspect = SettingsStore.getInstance(getContext()).getWindowAspect();
Media media = SessionStore.get().getFullScreenVideo();
if (media != null && media.getWidth() > 0 && media.getHeight() > 0) {
aspect = (float)media.getWidth() / (float)media.getHeight();
}
mBrowserWidget.resizeByMultiplier(aspect,1.75f);
// Save the old values on settings to prevent the fullscreen size being used on a app restart
SettingsStore.getInstance(getContext()).setBrowserWorldWidth(oldWidth);
SettingsStore.getInstance(getContext()).setBrowserWorldHeight(oldHeight);
}

private void enterFullScreenMode() {
if (mIsInFullScreenMode) {
return;
}

setFullScreenSize();
mWidgetManager.pushBackHandler(mFullScreenBackHandler);
mIsInFullScreenMode = true;
AnimationHelper.fadeIn(mFullScreenModeContainer, AnimationHelper.FADE_ANIMATION_DURATION, null);
Expand Down Expand Up @@ -386,6 +408,10 @@ private void exitFullScreenMode() {
if (!mIsInFullScreenMode) {
return;
}

mBrowserWidget.getPlacement().copyFrom(mSizeBeforeFullScreen);
mWidgetManager.updateWidget(mBrowserWidget);

mIsInFullScreenMode = false;
mWidgetManager.popBackHandler(mFullScreenBackHandler);

Expand Down Expand Up @@ -444,13 +470,17 @@ private void enterVRVideo(@VideoProjectionMenuWidget.VideoProjectionFlags int aP
// Backup the placement because the same widget is reused in FullScreen & MediaControl menus
mProjectionMenuPlacement.copyFrom(mProjectionMenu.getPlacement());

Media fullscreenMedia = SessionStore.get().getFullScreenVideo();
mFullScreenMedia = SessionStore.get().getFullScreenVideo();

this.setVisible(false);
if (fullscreenMedia != null && fullscreenMedia.getWidth() > 0 && fullscreenMedia.getHeight() > 0) {
if (mFullScreenMedia != null && mFullScreenMedia.getWidth() > 0 && mFullScreenMedia.getHeight() > 0) {
boolean resetBorder = aProjection == VideoProjectionMenuWidget.VIDEO_PROJECTION_360 ||
aProjection == VideoProjectionMenuWidget.VIDEO_PROJECTION_360_STEREO;
mBrowserWidget.enableVRVideoMode(fullscreenMedia.getWidth(), fullscreenMedia.getHeight(), resetBorder);
mBrowserWidget.enableVRVideoMode(mFullScreenMedia.getWidth(), mFullScreenMedia.getHeight(), resetBorder);
// Handle video resize while in VR video playback
mFullScreenMedia.setResizeDelegate((width, height) -> {
mBrowserWidget.resizeSurface(width, height);
});
}
mBrowserWidget.setVisible(false);

Expand All @@ -467,7 +497,7 @@ private void enterVRVideo(@VideoProjectionMenuWidget.VideoProjectionFlags int aP
mMediaControlsWidget.setBackHandler(this::exitVRVideo);
}
mMediaControlsWidget.setProjectionMenuWidget(mProjectionMenu);
mMediaControlsWidget.setMedia(fullscreenMedia);
mMediaControlsWidget.setMedia(mFullScreenMedia);
mWidgetManager.updateWidget(mMediaControlsWidget);
mWidgetManager.showVRVideo(mBrowserWidget.getHandle(), aProjection);
}
Expand All @@ -476,6 +506,9 @@ private void exitVRVideo() {
if (!mIsInVRVideo) {
return;
}
if (mFullScreenMedia != null) {
mFullScreenMedia.setResizeDelegate(null);
}
mIsInVRVideo = false;
mWidgetManager.popBackHandler(mVRVideoBackHandler);
mWidgetManager.hideVRVideo();
Expand All @@ -489,18 +522,13 @@ private void exitVRVideo() {
mMediaControlsWidget.setVisible(false);
}

private void setResizePreset(float aResizeMode) {
private void setResizePreset(float aMultiplier) {
final float aspect = SettingsStore.getInstance(getContext()).getWindowAspect();
if (mBrowserWidget.isVisible()) {
mBrowserWidget.setSize(
SettingsStore.getInstance(getContext()).getWindowWidth(),
SettingsStore.getInstance(getContext()).getWindowHeight(),
aResizeMode);
mBrowserWidget.resizeByMultiplier(aspect, aMultiplier);

} else if (mBookmarksWidget.isVisible()) {
mBookmarksWidget.setSize(
SettingsStore.getInstance(getContext()).getWindowWidth(),
SettingsStore.getInstance(getContext()).getWindowHeight(),
aResizeMode);
mBookmarksWidget.resizeByMultiplier(aspect, aMultiplier);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void initialize() {
}

@Override
public void setSize(float windowWidth, float windowHeight, float multiplier) {
public void resizeByMultiplier(float aspect, float multiplier) {
// To be implemented by inheriting widgets
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public interface Widget {
boolean getFirstDraw();
boolean isVisible();
void setVisible(boolean aVisible);
void setSize(float windowWidth, float windowHeight, float multiplier);
void resizeByMultiplier(float aspect, float multiplier);
}

0 comments on commit 3b9d783

Please sign in to comment.