diff options
author | Derek Sollenberger <djsollen@google.com> | 2011-02-07 13:44:49 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-02-07 13:44:49 -0800 |
commit | 2e7db7594335b3202dd085c9f70ea727b4ffb1e9 (patch) | |
tree | cd3467532a35708fb0a0da593a6f95d59c04dbb3 /WebCore/platform | |
parent | 8b7cce7f189cb149ee3f31faac189d3a6451a2ac (diff) | |
parent | 4fff0b9fdd23cd60b036e2ea48190e7a7d8dbf13 (diff) | |
download | external_webkit-2e7db7594335b3202dd085c9f70ea727b4ffb1e9.zip external_webkit-2e7db7594335b3202dd085c9f70ea727b4ffb1e9.tar.gz external_webkit-2e7db7594335b3202dd085c9f70ea727b4ffb1e9.tar.bz2 |
am 4fff0b9f: am 2bac1e45: Only invalidate the webview when the plugin has new content.
* commit '4fff0b9fdd23cd60b036e2ea48190e7a7d8dbf13':
Only invalidate the webview when the plugin has new content.
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; }; |