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

Fix Surface leaks when closing windows or removing widgets #1716

Merged
merged 5 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ public void run() {
return;
}

mTooltipView = new TooltipWidget(getContext());
if (mTooltipView == null) {
mTooltipView = new TooltipWidget(getContext());
}
mTooltipView.setCurvedMode(mCurvedTooltip);
mTooltipView.setText(getTooltip());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public interface Delegate {

private TitleBarBinding mBinding;
private WindowWidget mAttachedWindow;
private boolean mVisible;
private boolean mVisible = false;
private Media mMedia;
private boolean mWidgetAdded = false;

public TitleBarWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -123,11 +124,11 @@ public void setVisible(boolean aIsVisible) {
}
mVisible = aIsVisible;
getPlacement().visible = aIsVisible;

if (aIsVisible) {
if (!mWidgetAdded) {
mWidgetManager.addWidget(this);
mWidgetAdded = true;
} else {
mWidgetManager.removeWidget(this);
mWidgetManager.updateWidget(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class TopBarWidget extends UIWidget implements SessionChangeListener, Wid
private WindowWidget mAttachedWindow;
private TopBarWidget.Delegate mDelegate;
private LinearLayout mMultiWindowControlsContainer;
private boolean mVisible;
private boolean mVisible = false;
private boolean mWidgetAdded = false;

public TopBarWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -171,11 +172,11 @@ public void setVisible(boolean aIsVisible) {
}
mVisible = aIsVisible;
getPlacement().visible = aIsVisible;

if (aIsVisible) {
if (!mWidgetAdded) {
mWidgetManager.addWidget(this);
mWidgetAdded = true;
} else {
mWidgetManager.removeWidget(this);
mWidgetManager.updateWidget(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,17 @@ public void handleMoveEvent(float aDeltaX, float aDeltaY, float aDeltaZ, float a
mWidgetPlacement.rotation = aRotation;
}

@Override
public void releaseWidget() {
private void releaseRenderer() {
if (mRenderer != null) {
mRenderer.release();
mRenderer = null;
}
mTexture = null;
}

@Override
public void releaseWidget() {
releaseRenderer();
mWidgetManager = null;
}

Expand Down Expand Up @@ -327,7 +331,7 @@ public void hide(@HideFlags int aHideFlags) {
mWidgetPlacement.visible = false;
if (aHideFlags == REMOVE_WIDGET) {
mWidgetManager.removeWidget(this);

releaseRenderer();
} else {
mWidgetManager.updateWidget(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ public void close() {
mBookmarksView.onDestroy();
mHistoryView.onDestroy();
SessionStore.get().destroySessionStack(mWindowId);
if (mTopBar != null) {
mWidgetManager.removeWidget(mTopBar);
}
if (mTitleBar != null) {
mWidgetManager.removeWidget(mTitleBar);
}
}

public void loadHomeIfNotRestored() {
Expand Down Expand Up @@ -783,15 +789,26 @@ public void releaseWidget() {
mSessionStack.removeProgressListener(this);
mSessionStack.setHistoryDelegate(null);
GeckoSession session = mSessionStack.getSession(mSessionId);
if (session == null) {
return;
}
if (mDisplay != null) {
mDisplay.surfaceDestroyed();
session.releaseDisplay(mDisplay);
if (session != null) {
session.releaseDisplay(mDisplay);
}
mDisplay = null;
}
session.getTextInput().setView(null);
if (session != null) {
session.getTextInput().setView(null);
}
if (mSurface != null) {
mSurface.release();
mSurface = null;
}
if (mTexture != null && mRenderer == null) {
// Custom SurfaceTexture used for GeckoView
mTexture.release();
mTexture = null;
}
super.releaseWidget();
}


Expand Down