summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2011-02-04 11:57:40 -0500
committerDerek Sollenberger <djsollen@google.com>2011-02-04 14:11:29 -0500
commit2bac1e45807d68b80f4a5cc7a62d0e3c24a4b6f6 (patch)
tree4fc5ebfe391f35bcc51881f75a47017ab0abe64b
parentafd330e2308bd382fb7d31431cb47e2d7a99f26a (diff)
downloadexternal_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
-rw-r--r--WebCore/platform/graphics/android/MediaLayer.cpp13
-rw-r--r--WebCore/platform/graphics/android/MediaLayer.h3
-rw-r--r--WebCore/platform/graphics/android/MediaTexture.cpp56
-rw-r--r--WebCore/platform/graphics/android/MediaTexture.h5
-rw-r--r--WebKit/android/plugins/ANPOpenGLInterface.cpp3
-rw-r--r--WebKit/android/plugins/PluginWidgetAndroid.cpp16
-rw-r--r--WebKit/android/plugins/PluginWidgetAndroid.h2
7 files changed, 87 insertions, 11 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;
};
diff --git a/WebKit/android/plugins/ANPOpenGLInterface.cpp b/WebKit/android/plugins/ANPOpenGLInterface.cpp
index 8f5f9b4..015a04c 100644
--- a/WebKit/android/plugins/ANPOpenGLInterface.cpp
+++ b/WebKit/android/plugins/ANPOpenGLInterface.cpp
@@ -87,6 +87,9 @@ static void anp_releaseTexture(NPP instance, const ANPTextureInfo* textureInfo)
info->m_internalFormat = textureInfo->internalFormat;
texture->producerReleaseAndSwap();
+
+ // invalidate the java view so that this content is drawn
+ pluginWidget->viewInvalidate();
}
static void anp_invertPluginContent(NPP instance, bool isContentInverted) {
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp
index 90dceba..a02047b 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.cpp
+++ b/WebKit/android/plugins/PluginWidgetAndroid.cpp
@@ -156,8 +156,14 @@ void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) {
bool PluginWidgetAndroid::setDrawingModel(ANPDrawingModel model) {
- if (model == kOpenGL_ANPDrawingModel && m_layer == 0)
- m_layer = new WebCore::MediaLayer();
+ if (model == kOpenGL_ANPDrawingModel && m_layer == 0) {
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ jobject webview = m_core->getWebViewJavaObject();
+ jobject weakWebViewRef = 0;
+ if (webview)
+ weakWebViewRef = env->NewWeakGlobalRef(webview);
+ m_layer = new WebCore::MediaLayer(weakWebViewRef);
+ }
else if (model != kOpenGL_ANPDrawingModel && m_layer != 0)
m_layer->unref();
@@ -204,6 +210,12 @@ void PluginWidgetAndroid::inval(const WebCore::IntRect& rect,
}
}
+void PluginWidgetAndroid::viewInvalidate() {
+ WebCore::IntRect rect(m_pluginBounds.fLeft, m_pluginBounds.fTop,
+ m_pluginBounds.width(), m_pluginBounds.height());
+ m_core->viewInvalidate(rect);
+}
+
void PluginWidgetAndroid::draw(SkCanvas* canvas) {
if (NULL == m_flipPixelRef || !m_flipPixelRef->isDirty()) {
return;
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.h b/WebKit/android/plugins/PluginWidgetAndroid.h
index 9726a22..5d586b1 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.h
+++ b/WebKit/android/plugins/PluginWidgetAndroid.h
@@ -177,6 +177,8 @@ struct PluginWidgetAndroid {
void setPowerState(ANPPowerState powerState);
+ void viewInvalidate();
+
private:
void computeVisiblePluginRect();
void scrollToVisiblePluginRect();