Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(🐛): fix concurrency issue with surface events #2505

Merged
merged 1 commit into from
Jun 28, 2024
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 @@ -13,6 +13,8 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView

private String tag = "SkiaView";

private boolean isDropped = false;

public SkiaBaseView(Context context) {
super(context);
mTexture = new TextureView(context);
Expand All @@ -21,11 +23,6 @@ public SkiaBaseView(Context context) {
addView(mTexture);
}

public void destroySurface() {
Log.i(tag, "destroySurface");
surfaceDestroyed();
}

private void createSurfaceTexture() {
// This API Level is >= 26, we created our own SurfaceTexture to have a faster time to first frame
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
Expand All @@ -36,6 +33,11 @@ private void createSurfaceTexture() {
}
}

void dropInstance() {
isDropped = true;
unregisterView();
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
Expand Down Expand Up @@ -129,6 +131,9 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei

@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
if (isDropped) {
return;
}
Log.i(tag, "onSurfaceTextureSizeChanged " + width + "/" + height);
surfaceSizeChanged(width, height);
}
Expand All @@ -137,12 +142,14 @@ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int h
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.i(tag, "onSurfaceTextureDestroyed");
// https://developer.android.com/reference/android/view/TextureView.SurfaceTextureListener#onSurfaceTextureDestroyed(android.graphics.SurfaceTexture)
destroySurface();
surfaceDestroyed();
// Because of React Native Screens (which dettach the view), we always keep the surface alive.
// If not, Texture view will recreate the texture surface by itself and
// we will lose the fast first time to frame.
// We only delete the surface when the view is dropped (destroySurface invoked by SkiaBaseViewManager);
createSurfaceTexture();
if (!isDropped) {
createSurfaceTexture();
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public void setDebug(T view, boolean show) {
@Override
public void onDropViewInstance(@NonNull ReactViewGroup view) {
super.onDropViewInstance(view);
((SkiaBaseView)view).destroySurface();
((SkiaBaseView)view).unregisterView();
((SkiaBaseView)view).dropInstance();
}
}
Loading