diff options
author | Derek Sollenberger <djsollen@google.com> | 2011-02-04 11:57:40 -0500 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2011-02-04 14:11:29 -0500 |
commit | 2bac1e45807d68b80f4a5cc7a62d0e3c24a4b6f6 (patch) | |
tree | 4fc5ebfe391f35bcc51881f75a47017ab0abe64b /WebCore/platform | |
parent | afd330e2308bd382fb7d31431cb47e2d7a99f26a (diff) | |
download | external_webkit-2bac1e45807d68b80f4a5cc7a62d0e3c24a4b6f6.zip external_webkit-2bac1e45807d68b80f4a5cc7a62d0e3c24a4b6f6.tar.gz external_webkit-2bac1e45807d68b80f4a5cc7a62d0e3c24a4b6f6.tar.bz2 |
Only invalidate the webview when the plugin has new content.
bug: 3424551
Change-Id: I07beef845bb41980144222c3c5d076db8120037c
Diffstat (limited to 'WebCore/platform')
-rw-r--r-- | WebCore/platform/graphics/android/MediaLayer.cpp | 13 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/MediaLayer.h | 3 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/MediaTexture.cpp | 56 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/MediaTexture.h | 5 |
4 files changed, 68 insertions, 9 deletions
diff --git a/WebCore/platform/graphics/android/MediaLayer.cpp b/WebCore/platform/graphics/android/MediaLayer.cpp index fac94f5..7a4c02d 100644 --- a/WebCore/platform/graphics/android/MediaLayer.cpp +++ b/WebCore/platform/graphics/android/MediaLayer.cpp @@ -40,11 +40,11 @@ namespace WebCore { -MediaLayer::MediaLayer() : LayerAndroid(false) +MediaLayer::MediaLayer(jobject weakWebViewRef) : LayerAndroid(false) { m_bufferedTexture = new MediaTexture(EGL_NO_CONTEXT); m_bufferedTexture->incStrong(this); - m_videoTexture = new VideoTexture(); + m_videoTexture = new VideoTexture(weakWebViewRef); m_videoTexture->incStrong(this); m_currentTextureInfo = 0; @@ -78,6 +78,8 @@ bool MediaLayer::drawGL(SkMatrix& matrix) // draw any video content if present m_videoTexture->drawVideo(drawTransform()); + bool needsInval = true; + // draw the primary content if (m_bufferedTexture) { TextureInfo* textureInfo = m_bufferedTexture->consumerLock(); @@ -95,14 +97,13 @@ bool MediaLayer::drawGL(SkMatrix& matrix) TilesManager::instance()->shader()->drawLayerQuad(m, rect, textureInfo->m_textureId, 1.0f); //TODO fix this m_drawOpacity + if (!rect.isEmpty()) + needsInval = false; } m_bufferedTexture->consumerRelease(); } - drawChildrenGL(matrix); - - //TODO allow plugins to specify when they should be drawn - return true; + return drawChildrenGL(matrix) || needsInval; } ANativeWindow* MediaLayer::acquireNativeWindowForVideo() diff --git a/WebCore/platform/graphics/android/MediaLayer.h b/WebCore/platform/graphics/android/MediaLayer.h index dec6427..15bd6d8 100644 --- a/WebCore/platform/graphics/android/MediaLayer.h +++ b/WebCore/platform/graphics/android/MediaLayer.h @@ -21,6 +21,7 @@ #include "MediaTexture.h" #include "LayerAndroid.h" +#include <jni.h> namespace android { class SurfaceTexture; @@ -31,7 +32,7 @@ namespace WebCore { class MediaLayer : public LayerAndroid { public: - MediaLayer(); + MediaLayer(jobject weakWebViewRef); MediaLayer(const MediaLayer& layer); virtual ~MediaLayer(); diff --git a/WebCore/platform/graphics/android/MediaTexture.cpp b/WebCore/platform/graphics/android/MediaTexture.cpp index 8481a20..c994e78 100644 --- a/WebCore/platform/graphics/android/MediaTexture.cpp +++ b/WebCore/platform/graphics/android/MediaTexture.cpp @@ -24,6 +24,8 @@ #include <gui/SurfaceTexture.h> #include <gui/SurfaceTextureClient.h> #include <wtf/CurrentTime.h> +#include <JNIUtility.h> +#include "WebCoreJni.h" #define LAYER_DEBUG #undef LAYER_DEBUG @@ -45,8 +47,46 @@ namespace WebCore { -VideoTexture::VideoTexture() +class VideoListener : public android::SurfaceTexture::FrameAvailableListener { + +public: + VideoListener(jobject weakWebViewRef) + : m_weakWebViewRef(weakWebViewRef) + , m_postInvalMethod(0) + { + if (!m_weakWebViewRef) + return; + + JNIEnv* env = JSC::Bindings::getJNIEnv(); + jobject localWebViewRef = env->NewLocalRef(m_weakWebViewRef); + if (localWebViewRef) { + jclass wvClass = env->GetObjectClass(localWebViewRef); + m_postInvalMethod = env->GetMethodID(wvClass, "postInvalidate", "()V"); + env->DeleteLocalRef(wvClass); + env->DeleteLocalRef(localWebViewRef); + } + checkException(env); + } + + virtual void onFrameAvailable() + { + JNIEnv* env = JSC::Bindings::getJNIEnv(); + jobject localWebViewRef = env->NewLocalRef(m_weakWebViewRef); + if (localWebViewRef) { + env->CallVoidMethod(localWebViewRef, m_postInvalMethod); + env->DeleteLocalRef(localWebViewRef); + } + checkException(env); + } + +private: + jobject m_weakWebViewRef; + jmethodID m_postInvalMethod; +}; + +VideoTexture::VideoTexture(jobject weakWebViewRef) : android::LightRefBase<VideoTexture>() { + m_weakWebViewRef = weakWebViewRef; m_textureId = 0; m_dimensions.setEmpty(); m_newWindowRequest = false; @@ -58,6 +98,10 @@ VideoTexture::~VideoTexture() releaseNativeWindow(); if (m_textureId) glDeleteTextures(1, &m_textureId); + if (m_weakWebViewRef) { + JNIEnv* env = JSC::Bindings::getJNIEnv(); + env->DeleteWeakGlobalRef(m_weakWebViewRef); + } } void VideoTexture::initNativeWindowIfNeeded() @@ -73,6 +117,11 @@ void VideoTexture::initNativeWindowIfNeeded() m_surfaceTexture = new android::SurfaceTexture(m_textureId); m_surfaceTextureClient = new android::SurfaceTextureClient(m_surfaceTexture); + + //setup callback + sp<VideoListener> listener = new VideoListener(m_weakWebViewRef); + m_surfaceTexture->setFrameAvailableListener(listener); + m_newWindowRequest = false; m_newWindowReady = true; m_newVideoRequestCond.signal(); @@ -128,6 +177,11 @@ void VideoTexture::releaseNativeWindow() { android::Mutex::Autolock lock(m_videoLock); m_dimensions.setEmpty(); + + if (m_surfaceTexture.get()) + m_surfaceTexture->setFrameAvailableListener(0); + + // clear the strong pointer references m_surfaceTextureClient.clear(); m_surfaceTexture.clear(); } diff --git a/WebCore/platform/graphics/android/MediaTexture.h b/WebCore/platform/graphics/android/MediaTexture.h index 156a67f..189905c 100644 --- a/WebCore/platform/graphics/android/MediaTexture.h +++ b/WebCore/platform/graphics/android/MediaTexture.h @@ -23,6 +23,7 @@ #include "DoubleBufferedTexture.h" #include "LayerAndroid.h" #include <utils/RefBase.h> +#include <jni.h> namespace android { class SurfaceTexture; @@ -40,7 +41,7 @@ public: class VideoTexture : public android::LightRefBase<VideoTexture> { public: - VideoTexture(); + VideoTexture(jobject weakWebViewRef); ~VideoTexture(); void initNativeWindowIfNeeded(); @@ -60,6 +61,8 @@ private: bool m_newWindowRequest; bool m_newWindowReady; + jobject m_weakWebViewRef; + android::Mutex m_videoLock; android::Condition m_newVideoRequestCond; }; |