diff options
| author | Teng-Hui Zhu <ztenghui@google.com> | 2011-05-31 15:15:31 -0700 |
|---|---|---|
| committer | Teng-Hui Zhu <ztenghui@google.com> | 2011-06-01 13:42:46 -0700 |
| commit | 3fafd39d0776a15c3613795183043a2c28277691 (patch) | |
| tree | 2362b19c6829a0ccff61f49e7a0ebe658fe4243f /core/java/android/webkit/HTML5VideoInline.java | |
| parent | 2978cef0a77550ea3a364ffbf42fc43f2029070e (diff) | |
The screen shot support for inline video on Java side
Basically, the GL texture bound with Surface Texture is not a singleton any
more. And the Surface Texture will be recreated every time a new video starts.
This can help to recycle the decoder's memory while using the GL texture to
show the screen shot.
The corresponding webkit change is: 112500
Change-Id: I3c35f6a0abc70b9039c316ca82b236c797d81c7e
Diffstat (limited to 'core/java/android/webkit/HTML5VideoInline.java')
| -rw-r--r-- | core/java/android/webkit/HTML5VideoInline.java | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/core/java/android/webkit/HTML5VideoInline.java b/core/java/android/webkit/HTML5VideoInline.java index 25921bc86a52..ef1906c1ea2c 100644 --- a/core/java/android/webkit/HTML5VideoInline.java +++ b/core/java/android/webkit/HTML5VideoInline.java @@ -12,10 +12,15 @@ import android.opengl.GLES20; */ public class HTML5VideoInline extends HTML5VideoView{ - // Due to the fact that SurfaceTexture consume a lot of memory, we make it - // as static. m_textureNames is the texture bound with this SurfaceTexture. + // Due to the fact that the decoder consume a lot of memory, we make the + // surface texture as singleton. But the GL texture (m_textureNames) + // associated with the surface texture can be used for showing the screen + // shot when paused, so they are not singleton. private static SurfaceTexture mSurfaceTexture = null; - private static int[] mTextureNames; + private int[] mTextureNames; + // Every time when the VideoLayer Id change, we need to recreate the + // SurfaceTexture in order to delete the old video's decoder memory. + private static int mVideoLayerUsingSurfaceTexture = -1; // Video control FUNCTIONS: @Override @@ -28,11 +33,12 @@ public class HTML5VideoInline extends HTML5VideoView{ HTML5VideoInline(int videoLayerId, int position, boolean autoStart) { init(videoLayerId, position, autoStart); + mTextureNames = null; } @Override public void decideDisplayMode() { - mPlayer.setTexture(getSurfaceTextureInstance()); + mPlayer.setTexture(getSurfaceTexture(getVideoLayerId())); } // Normally called immediately after setVideoURI. But for full screen, @@ -52,31 +58,38 @@ public class HTML5VideoInline extends HTML5VideoView{ // Inline Video specific FUNCTIONS: @Override - public SurfaceTexture getSurfaceTexture() { + public SurfaceTexture getSurfaceTexture(int videoLayerId) { + // Create the surface texture. + if (videoLayerId != mVideoLayerUsingSurfaceTexture + || mSurfaceTexture == null) { + if (mTextureNames == null) { + mTextureNames = new int[1]; + GLES20.glGenTextures(1, mTextureNames, 0); + } + mSurfaceTexture = new SurfaceTexture(mTextureNames[0]); + } + mVideoLayerUsingSurfaceTexture = videoLayerId; return mSurfaceTexture; } + public boolean surfaceTextureDeleted() { + return (mSurfaceTexture == null); + } + @Override public void deleteSurfaceTexture() { mSurfaceTexture = null; + mVideoLayerUsingSurfaceTexture = -1; return; } - // SurfaceTexture is a singleton here , too - private SurfaceTexture getSurfaceTextureInstance() { - // Create the surface texture. - if (mSurfaceTexture == null) - { - mTextureNames = new int[1]; - GLES20.glGenTextures(1, mTextureNames, 0); - mSurfaceTexture = new SurfaceTexture(mTextureNames[0]); - } - return mSurfaceTexture; - } - @Override public int getTextureName() { - return mTextureNames[0]; + if (mTextureNames != null) { + return mTextureNames[0]; + } else { + return 0; + } } private void setFrameAvailableListener(SurfaceTexture.OnFrameAvailableListener l) { |
