mirror of
https://github.com/zhigang1992/libpag.git
synced 2026-04-30 05:55:44 +08:00
Release the PAGSurface before the GLSurfaceView destroys context.
This commit is contained in:
@@ -3,10 +3,17 @@ package io.pag.demo;
|
||||
import android.app.Activity;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
import javax.microedition.khronos.egl.EGLSurface;
|
||||
|
||||
import io.pag.demo.openGL.GLRender;
|
||||
|
||||
public class TextureDemoActivity extends Activity {
|
||||
private final static String TAG = TextureDemoActivity.class.getSimpleName();
|
||||
|
||||
private GLSurfaceView glSurfaceView;
|
||||
|
||||
@@ -14,12 +21,34 @@ public class TextureDemoActivity extends Activity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_texture_demo);
|
||||
glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
|
||||
GLRender glRender = new GLRender(this.getBaseContext());
|
||||
glSurfaceView = findViewById(R.id.surfaceView);
|
||||
final GLRender glRender = new GLRender(this.getBaseContext());
|
||||
glSurfaceView.setEGLContextClientVersion(2);
|
||||
glSurfaceView.setEGLWindowSurfaceFactory(new GLSurfaceView.EGLWindowSurfaceFactory() {
|
||||
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
|
||||
EGLConfig config, Object nativeWindow) {
|
||||
EGLSurface result = null;
|
||||
try {
|
||||
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// This exception indicates that the surface flinger surface
|
||||
// is not valid. This can happen if the surface flinger surface has
|
||||
// been torn down, but the application has not yet been
|
||||
// notified via SurfaceHolder.Callback.surfaceDestroyed.
|
||||
// In theory the application should be notified first,
|
||||
// but in practice sometimes it is not. See b/4588890
|
||||
Log.e(TAG, "eglCreateWindowSurface", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void destroySurface(EGL10 egl, EGLDisplay display, EGLSurface surface) {
|
||||
glRender.onDestroy();
|
||||
egl.eglDestroySurface(display, surface);
|
||||
}
|
||||
});
|
||||
glSurfaceView.setRenderer(glRender);
|
||||
glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,7 @@ public class GLRender implements GLSurfaceView.Renderer {
|
||||
|
||||
private static final String TAG = "GLRender";
|
||||
private int textureId;
|
||||
private PAGSurface pagSurface;
|
||||
private PAGPlayer pagPlayer;
|
||||
private Context context;
|
||||
private long duration;
|
||||
@@ -87,6 +88,15 @@ public class GLRender implements GLSurfaceView.Renderer {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
if (pagPlayer != null) {
|
||||
pagPlayer.release();
|
||||
}
|
||||
if (pagSurface != null) {
|
||||
pagSurface.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
@@ -97,7 +107,7 @@ public class GLRender implements GLSurfaceView.Renderer {
|
||||
|
||||
textureId = initRenderTarget();
|
||||
|
||||
PAGSurface pagSurface = PAGSurface.FromTexture(textureId, mWidth, mHeight);
|
||||
pagSurface = PAGSurface.FromTexture(textureId, mWidth, mHeight);
|
||||
pagPlayer = new PAGPlayer();
|
||||
pagPlayer.setComposition(pagFile);
|
||||
pagPlayer.setSurface(pagSurface);
|
||||
@@ -135,7 +145,7 @@ public class GLRender implements GLSurfaceView.Renderer {
|
||||
}
|
||||
|
||||
private int initRenderTarget() {
|
||||
int id[] = {0};
|
||||
int[] id = {0};
|
||||
GLES20.glGenTextures(1, id, 0);
|
||||
if (id[0] == 0) {
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user