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

Commit 1ca75cd

Browse files
MortimerGorobluemarvin
authored andcommitted
Add support for clearing window color before GV does the first composition (#1697)
* Add support for clearing window color before GV does the first composition * Update to use new GeckoView onFirstContentfulPaint() callback * Fix HTC * Bump GV version to 71.0.20190919094654
1 parent 0f16dc0 commit 1ca75cd

22 files changed

Lines changed: 219 additions & 98 deletions

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -675,19 +675,14 @@ void dispatchCreateWidget(final int aHandle, final SurfaceTexture aTexture, fina
675675
if (aTexture == null) {
676676
Log.d(LOGTAG, "Widget: " + aHandle + " (" + aWidth + "x" + aHeight + ") received a null surface texture.");
677677
} else {
678-
aTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
679-
@Override
680-
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
681-
surfaceTexture.setOnFrameAvailableListener(null);
682-
if (!widget.getFirstDraw()) {
683-
widget.setFirstDraw(true);
684-
updateWidget(widget);
685-
}
678+
Runnable aFirstDrawCallback = () -> {
679+
if (!widget.getFirstDraw()) {
680+
widget.setFirstDraw(true);
681+
updateWidget(widget);
686682
}
687-
688-
}, mHandler);
683+
};
684+
widget.setSurfaceTexture(aTexture, aWidth, aHeight, aFirstDrawCallback);
689685
}
690-
widget.setSurfaceTexture(aTexture, aWidth, aHeight);
691686
// Add widget to a virtual display for invalidation
692687
View view = (View) widget;
693688
if (view.getParent() == null) {

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStack.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,15 @@ public void onFirstComposite(@NonNull GeckoSession aSession) {
11591159
}
11601160
}
11611161

1162+
@Override
1163+
public void onFirstContentfulPaint(@NonNull GeckoSession aSession) {
1164+
if (mCurrentSession == aSession) {
1165+
for (GeckoSession.ContentDelegate listener : mContentListeners) {
1166+
listener.onFirstContentfulPaint(aSession);
1167+
}
1168+
}
1169+
}
1170+
11621171
// TextInput Delegate
11631172

11641173
@Override

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,9 @@ private void exitVRVideo() {
641641
mIsInVRVideo = false;
642642
mWidgetManager.popBackHandler(mVRVideoBackHandler);
643643
mWidgetManager.hideVRVideo();
644-
boolean firstDraw = mProjectionMenu.getPlacement().firstDraw;
644+
boolean composited = mProjectionMenu.getPlacement().composited;
645645
mProjectionMenu.getPlacement().copyFrom(mProjectionMenuPlacement);
646-
mProjectionMenu.getPlacement().firstDraw = firstDraw;
646+
mProjectionMenu.getPlacement().composited = composited;
647647
mWidgetManager.updateWidget(mProjectionMenu);
648648
closeFloatingMenus();
649649
mWidgetManager.setControllersVisible(true);

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ public void resizeByMultiplier(float aspect, float multiplier) {
102102
protected abstract void initializeWidgetPlacement(WidgetPlacement aPlacement);
103103

104104
@Override
105-
public void setSurfaceTexture(SurfaceTexture aTexture, final int aWidth, final int aHeight) {
105+
public void setSurfaceTexture(SurfaceTexture aTexture, final int aWidth, final int aHeight, Runnable aFirstDrawCallback) {
106106
if (mTexture!= null && (mTexture.equals(aTexture))) {
107107
Log.d(LOGTAG, "Texture already set");
108108
return;
109109
}
110+
mFirstDrawCallback = aFirstDrawCallback;
110111
if (mRenderer != null && mRenderer.isLayer()) {
111112
// Widget is using a layer write-only surface but we also want a proxy.
112113
if (mProxyRenderer != null) {
@@ -220,12 +221,12 @@ public boolean isDialog() {
220221

221222
@Override
222223
public void setFirstDraw(final boolean aIsFirstDraw) {
223-
mWidgetPlacement.firstDraw = aIsFirstDraw;
224+
mWidgetPlacement.composited = aIsFirstDraw;
224225
}
225226

226227
@Override
227228
public boolean getFirstDraw() {
228-
return mWidgetPlacement.firstDraw;
229+
return mWidgetPlacement.composited;
229230
}
230231

231232
@Override

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Widget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface Widget {
1717

1818
void onPause();
1919
void onResume();
20-
void setSurfaceTexture(SurfaceTexture aTexture, final int aWidth, final int aHeight);
20+
void setSurfaceTexture(SurfaceTexture aTexture, final int aWidth, final int aHeight, Runnable aFirstDrawCallback);
2121
void setSurface(Surface aSurface, final int aWidth, final int aHeight, Runnable aFirstDrawCallback);
2222
void resizeSurface(final int aWidth, final int aHeight);
2323
int getHandle();

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetPlacement.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ public WidgetPlacement(Context aContext) {
4444
public boolean visible = true;
4545
public boolean opaque = false;
4646
public boolean showPointer = true;
47-
public boolean firstDraw = false;
47+
public boolean composited = false;
4848
public boolean layer = true;
4949
public boolean proxifyLayer = false;
5050
public float textureScale = 0.7f;
5151
// Widget will be curved if enabled.
5252
public boolean cylinder = true;
5353
public int borderColor = 0;
5454
public String name;
55+
// Color used to render the widget before the it's composited
56+
public int clearColor = 0;
5557
/*
5658
* Flat surface placements are automatically mapped to curved coordinates.
5759
* If a radius is set it's used for the automatic mapping of the yaw & angle when the
@@ -86,7 +88,7 @@ public void copyFrom(WidgetPlacement w) {
8688
this.visible = w.visible;
8789
this.opaque = w.opaque;
8890
this.showPointer = w.showPointer;
89-
this.firstDraw = w.firstDraw;
91+
this.composited = w.composited;
9092
this.layer = w.layer;
9193
this.proxifyLayer = w.proxifyLayer;
9294
this.textureScale = w.textureScale;

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ default void onBookmarksHidden(WindowWidget aWindow) {}
134134
private WidgetPlacement mPlacementBeforeResize;
135135
private boolean mIsResizing;
136136
private boolean mIsFullScreen;
137+
private boolean mAfterFirstlPaint;
137138

138139
public interface WindowDelegate {
139140
void onFocusRequest(@NonNull WindowWidget aWindow);
@@ -171,6 +172,11 @@ public WindowWidget(Context aContext, int windowId, boolean privateMode) {
171172
mIsResizing = false;
172173
mIsFullScreen = false;
173174
initializeWidgetPlacement(mWidgetPlacement);
175+
if (mSessionStack.isPrivateMode()) {
176+
mWidgetPlacement.clearColor = ViewUtils.ARGBtoRGBA(getContext().getColor(R.color.window_private_clear_color));
177+
} else {
178+
mWidgetPlacement.clearColor = ViewUtils.ARGBtoRGBA(getContext().getColor(R.color.window_blank_clear_color));
179+
}
174180

175181
mTopBar = new TopBarWidget(aContext);
176182
mTopBar.attachToWindow(this);
@@ -622,9 +628,10 @@ public TitleBarWidget getTitleBar() {
622628
}
623629

624630
@Override
625-
public void setSurfaceTexture(SurfaceTexture aTexture, final int aWidth, final int aHeight) {
631+
public void setSurfaceTexture(SurfaceTexture aTexture, final int aWidth, final int aHeight, Runnable aFirstDrawCallback) {
632+
mFirstDrawCallback = aFirstDrawCallback;
626633
if (mView != null) {
627-
super.setSurfaceTexture(aTexture, aWidth, aHeight);
634+
super.setSurfaceTexture(aTexture, aWidth, aHeight, aFirstDrawCallback);
628635

629636
} else {
630637
GeckoSession session = mSessionStack.getSession(mSessionId);
@@ -886,12 +893,12 @@ public void releaseWidget() {
886893

887894
@Override
888895
public void setFirstDraw(final boolean aIsFirstDraw) {
889-
mWidgetPlacement.firstDraw = aIsFirstDraw;
896+
mWidgetPlacement.composited = aIsFirstDraw;
890897
}
891898

892899
@Override
893900
public boolean getFirstDraw() {
894-
return mWidgetPlacement.firstDraw;
901+
return mWidgetPlacement.composited;
895902
}
896903

897904
@Override
@@ -1427,12 +1434,25 @@ public void onContextMenu(GeckoSession session, int screenX, int screenY, Contex
14271434
}
14281435

14291436
@Override
1430-
public void onFirstComposite(GeckoSession session) {
1437+
public void onFirstComposite(@NonNull GeckoSession session) {
1438+
if (!mAfterFirstlPaint) {
1439+
return;
1440+
}
1441+
if (mFirstDrawCallback != null) {
1442+
ThreadUtils.postToUiThread(mFirstDrawCallback);
1443+
mFirstDrawCallback = null;
1444+
}
1445+
}
1446+
1447+
@Override
1448+
public void onFirstContentfulPaint(@NonNull GeckoSession session) {
1449+
if (mAfterFirstlPaint) {
1450+
return;
1451+
}
14311452
if (mFirstDrawCallback != null) {
1432-
// Post this call because running it synchronously can cause a deadlock if the runnable
1433-
// resizes the widget and calls surfaceChanged. See https://github.com/MozillaReality/FirefoxReality/issues/1459.
14341453
ThreadUtils.postToUiThread(mFirstDrawCallback);
14351454
mFirstDrawCallback = null;
1455+
mAfterFirstlPaint = true;
14361456
}
14371457
}
14381458

app/src/main/cpp/BrowserWorld.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ BrowserWorld::AddWidget(int32_t aHandle, const WidgetPlacementPtr& aPlacement) {
858858
if (aPlacement->cylinder && m.cylinderDensity > 0) {
859859
VRLayerCylinderPtr layer = m.device->CreateLayerCylinder(textureWidth, textureHeight, VRLayerQuad::SurfaceType::AndroidSurface);
860860
CylinderPtr cylinder = Cylinder::Create(m.create, layer);
861-
widget = Widget::Create(m.context, aHandle, textureWidth, textureHeight, (int32_t)worldWidth, (int32_t)worldHeight, cylinder);
861+
widget = Widget::Create(m.context, aHandle, aPlacement, textureWidth, textureHeight, (int32_t)worldWidth, (int32_t)worldHeight, cylinder);
862862
}
863863

864864
if (!widget) {
@@ -868,7 +868,7 @@ BrowserWorld::AddWidget(int32_t aHandle, const WidgetPlacementPtr& aPlacement) {
868868
}
869869

870870
QuadPtr quad = Quad::Create(m.create, worldWidth, worldHeight, layer);
871-
widget = Widget::Create(m.context, aHandle, textureWidth, textureHeight, quad);
871+
widget = Widget::Create(m.context, aHandle, aPlacement, textureWidth, textureHeight, quad);
872872
}
873873

874874
if (aPlacement->opaque) {

app/src/main/cpp/Quad.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ Quad::GetWorldHeight() const {
335335
return m.GetWorldHeight();
336336
}
337337

338+
vrb::RenderStatePtr
339+
Quad::GetRenderState() const {
340+
if (m.geometry) {
341+
return m.geometry->GetRenderState();
342+
}
343+
return nullptr;
344+
}
345+
338346
void
339347
Quad::GetWorldSize(float& aWidth, float& aHeight) const {
340348
aWidth = m.worldMax.x() - m.worldMin.x();

app/src/main/cpp/Quad.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Quad {
4848
const vrb::Vector& GetWorldMax() const;
4949
float GetWorldWidth() const;
5050
float GetWorldHeight() const;
51+
vrb::RenderStatePtr GetRenderState() const;
5152
void GetWorldSize(float& aWidth, float& aHeight) const;
5253
void SetWorldSize(const float aWidth, const float aHeight) const;
5354
void SetWorldSize(const vrb::Vector& aMin, const vrb::Vector& aMax) const;

0 commit comments

Comments
 (0)