summaryrefslogtreecommitdiffstats
path: root/WebKit/android/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/android/plugins')
-rw-r--r--WebKit/android/plugins/ANPOpenGLInterface.cpp97
-rw-r--r--WebKit/android/plugins/ANPOpenGL_npapi.h57
-rw-r--r--WebKit/android/plugins/PluginWidgetAndroid.cpp26
-rw-r--r--WebKit/android/plugins/PluginWidgetAndroid.h7
-rw-r--r--WebKit/android/plugins/android_npapi.h6
5 files changed, 193 insertions, 0 deletions
diff --git a/WebKit/android/plugins/ANPOpenGLInterface.cpp b/WebKit/android/plugins/ANPOpenGLInterface.cpp
new file mode 100644
index 0000000..55eb3e0
--- /dev/null
+++ b/WebKit/android/plugins/ANPOpenGLInterface.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// must include config.h first for webkit to fiddle with new/delete
+#include "config.h"
+
+#include "ANPOpenGL_npapi.h"
+#include "PluginView.h"
+#include "PluginWidgetAndroid.h"
+#include "MediaLayer.h"
+
+using namespace android;
+
+static WebCore::PluginView* pluginViewForInstance(NPP instance) {
+ if (instance && instance->ndata)
+ return static_cast<WebCore::PluginView*>(instance->ndata);
+ return WebCore::PluginView::currentPluginView();
+}
+
+static EGLContext anp_acquireContext(NPP instance) {
+ WebCore::PluginView* pluginView = pluginViewForInstance(instance);
+ PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
+ WebCore::MediaLayer* mediaLayer = pluginWidget->getLayer();
+
+ if (!mediaLayer)
+ return EGL_NO_CONTEXT;
+
+ return mediaLayer->getTexture()->producerAcquireContext();
+}
+
+static ANPTextureInfo anp_lockTexture(NPP instance) {
+ WebCore::PluginView* pluginView = pluginViewForInstance(instance);
+ PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
+ WebCore::MediaLayer* mediaLayer = pluginWidget->getLayer();
+ WebCore::DoubleBufferedTexture* texture = mediaLayer->getTexture();
+
+ // lock the texture and cache the internal info
+ WebCore::TextureInfo* info = texture->producerLock();
+ mediaLayer->setCurrentTextureInfo(info);
+
+ ANPTextureInfo anpInfo;
+ anpInfo.textureId = info->m_textureId;
+ anpInfo.width = info->m_width;
+ anpInfo.height = info->m_height;
+ anpInfo.internalFormat = info->m_internalFormat;
+ return anpInfo;
+}
+
+static void anp_releaseTexture(NPP instance, const ANPTextureInfo* textureInfo) {
+ WebCore::PluginView* pluginView = pluginViewForInstance(instance);
+ PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
+ WebCore::MediaLayer* mediaLayer = pluginWidget->getLayer();
+ WebCore::DoubleBufferedTexture* texture = mediaLayer->getTexture();
+
+ //copy the info into our internal structure
+ WebCore::TextureInfo* info = mediaLayer->getCurrentTextureInfo();
+ info->m_textureId = textureInfo->textureId;
+ info->m_width = textureInfo->width;
+ info->m_height = textureInfo->height;
+ info->m_internalFormat = textureInfo->internalFormat;
+
+ texture->producerReleaseAndSwap();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+#define ASSIGN(obj, name) (obj)->name = anp_##name
+
+void ANPOpenGLInterfaceV0_Init(ANPInterface* v) {
+ ANPOpenGLInterfaceV0* i = reinterpret_cast<ANPOpenGLInterfaceV0*>(v);
+
+ ASSIGN(i, acquireContext);
+ ASSIGN(i, lockTexture);
+ ASSIGN(i, releaseTexture);
+}
diff --git a/WebKit/android/plugins/ANPOpenGL_npapi.h b/WebKit/android/plugins/ANPOpenGL_npapi.h
new file mode 100644
index 0000000..bfca0dd
--- /dev/null
+++ b/WebKit/android/plugins/ANPOpenGL_npapi.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ANPOpenGL_npapi_H
+#define ANPOpenGL_npapi_H
+
+#include "android_npapi.h"
+#include <EGL/egl.h>
+#include <GLES2/gl2.h>
+
+/**
+ * TODO should we not use EGL and GL data types for ABI safety?
+ */
+struct ANPTextureInfo {
+ GLuint textureId;
+ uint32_t width;
+ uint32_t height;
+ GLenum internalFormat;
+};
+
+struct ANPOpenGLInterfaceV0 : ANPInterface {
+ /**
+ */
+ EGLContext (*acquireContext)(NPP instance);
+
+ /**
+ */
+ ANPTextureInfo (*lockTexture)(NPP instance);
+
+ /**
+ */
+ void (*releaseTexture)(NPP instance, const ANPTextureInfo*);
+};
+
+#endif //ANPOpenGL_npapi_H
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp
index b90b53b..83bc8cb 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.cpp
+++ b/WebKit/android/plugins/PluginWidgetAndroid.cpp
@@ -71,6 +71,7 @@ PluginWidgetAndroid::PluginWidgetAndroid(WebCore::PluginView* view)
m_embeddedViewAttached = false;
m_acceptEvents = false;
m_isSurfaceClippedOut = false;
+ m_layer = 0;
}
PluginWidgetAndroid::~PluginWidgetAndroid() {
@@ -93,6 +94,9 @@ PluginWidgetAndroid::~PluginWidgetAndroid() {
}
m_flipPixelRef->safeUnref();
+
+ if (m_layer)
+ m_layer->unref();
}
void PluginWidgetAndroid::init(android::WebViewCore* core) {
@@ -135,6 +139,17 @@ void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) {
}
bool PluginWidgetAndroid::setDrawingModel(ANPDrawingModel model) {
+
+ if (model == kOpenGL_ANPDrawingModel && m_layer == 0)
+ m_layer = new WebCore::MediaLayer();
+ else if (model != kOpenGL_ANPDrawingModel && m_layer != 0)
+ m_layer->unref();
+
+ if (m_drawingModel != model) {
+ // Trigger layer computation in RenderLayerCompositor
+ m_pluginView->getElement()->setNeedsStyleRecalc(SyntheticStyleChange);
+ }
+
m_drawingModel = model;
return true;
}
@@ -347,6 +362,17 @@ void PluginWidgetAndroid::setVisibleScreen(const ANPRectI& visibleDocRect, float
#endif
// TODO update the bitmap size based on the zoom? (for kBitmap_ANPDrawingModel)
+ // notify the plugin of the new size
+ // TODO what if the plugin changes sizes?
+ if (m_drawingModel == kOpenGL_ANPDrawingModel && m_zoomLevel != zoom) {
+ ANPEvent event;
+ SkANP::InitEvent(&event, kDraw_ANPEventType);
+ event.data.draw.model = kOpenGL_ANPDrawingModel;
+ event.data.draw.data.surface.width = m_pluginWindow->width * zoom;
+ event.data.draw.data.surface.height = m_pluginWindow->height * zoom;
+ sendEvent(event);
+ }
+
int oldScreenW = m_visibleDocRect.width();
int oldScreenH = m_visibleDocRect.height();
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.h b/WebKit/android/plugins/PluginWidgetAndroid.h
index 162fb1d..974fbf0 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.h
+++ b/WebKit/android/plugins/PluginWidgetAndroid.h
@@ -29,6 +29,7 @@
#include "android_npapi.h"
#include "IntPoint.h"
#include "IntRect.h"
+#include "MediaLayer.h"
#include "SkRect.h"
#include <jni.h>
@@ -79,6 +80,8 @@ struct PluginWidgetAndroid {
*/
bool isSurfaceDrawingModel() const { return kSurface_ANPDrawingModel == m_drawingModel; }
+ bool isOpenGLDrawingModel() const { return kOpenGL_ANPDrawingModel == m_drawingModel; }
+
/* Returns true (and optionally updates rect with the dirty bounds in the
page coordinate) if the plugin has invalidate us.
*/
@@ -163,10 +166,14 @@ struct PluginWidgetAndroid {
*/
void requestCenterFitZoom();
+ WebCore::MediaLayer* getLayer() const { return m_layer; }
+
private:
void computeVisiblePluginRect();
void scrollToVisiblePluginRect();
+ WebCore::MediaLayer* m_layer;
+
WebCore::PluginView* m_pluginView;
android::WebViewCore* m_core;
SkFlipPixelRef* m_flipPixelRef;
diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h
index 87ca8cc..a99666e 100644
--- a/WebKit/android/plugins/android_npapi.h
+++ b/WebKit/android/plugins/android_npapi.h
@@ -121,6 +121,7 @@ typedef uint32_t ANPMatrixFlag;
#define kEventInterfaceV0_ANPGetValue ((NPNVariable)1011)
#define kAudioTrackInterfaceV1_ANPGetValue ((NPNVariable)1012)
+#define kOpenGLInterfaceV0_ANPGetValue ((NPNVariable)1013)
/** queries for the drawing models supported on this device.
@@ -182,6 +183,7 @@ enum ANPDrawingModels {
surface object.
*/
kSurface_ANPDrawingModel = 1 << 1,
+ kOpenGL_ANPDrawingModel = 1 << 2,
};
typedef int32_t ANPDrawingModel;
@@ -929,6 +931,10 @@ struct ANPEvent {
// use based on the value in model
union {
ANPBitmap bitmap;
+ struct {
+ int32_t width;
+ int32_t height;
+ } surface;
} data;
} draw;
int32_t other[8];