summaryrefslogtreecommitdiffstats
path: root/WebCore
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2011-01-25 18:02:00 -0500
committerDerek Sollenberger <djsollen@google.com>2011-01-26 18:27:07 -0500
commit136290ef021ff9a9bf9152124a5fa42069acfdfc (patch)
tree763219807011b9f4442e72e25f44bede0a2683fa /WebCore
parent9d071845bbad7f9b73a17de59ad8b564e6ce39e4 (diff)
downloadexternal_webkit-136290ef021ff9a9bf9152124a5fa42069acfdfc.zip
external_webkit-136290ef021ff9a9bf9152124a5fa42069acfdfc.tar.gz
external_webkit-136290ef021ff9a9bf9152124a5fa42069acfdfc.tar.bz2
Initial pass at a video API for plugins.
bug: 3072603 Change-Id: Ie22d289a93682dfd68cf81f5220d658d45a69d81
Diffstat (limited to 'WebCore')
-rw-r--r--WebCore/Android.mk1
-rw-r--r--WebCore/platform/graphics/android/MediaLayer.cpp54
-rw-r--r--WebCore/platform/graphics/android/MediaLayer.h26
-rw-r--r--WebCore/platform/graphics/android/MediaTexture.cpp137
-rw-r--r--WebCore/platform/graphics/android/MediaTexture.h72
-rw-r--r--WebCore/plugins/android/PluginViewAndroid.cpp3
6 files changed, 269 insertions, 24 deletions
diff --git a/WebCore/Android.mk b/WebCore/Android.mk
index 7861bd3..4750751 100644
--- a/WebCore/Android.mk
+++ b/WebCore/Android.mk
@@ -616,6 +616,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
platform/graphics/android/ImageSourceAndroid.cpp \
platform/graphics/android/LayerAndroid.cpp \
platform/graphics/android/MediaLayer.cpp \
+ platform/graphics/android/MediaTexture.cpp \
platform/graphics/android/PaintLayerOperation.cpp \
platform/graphics/android/PathAndroid.cpp \
platform/graphics/android/PatternAndroid.cpp \
diff --git a/WebCore/platform/graphics/android/MediaLayer.cpp b/WebCore/platform/graphics/android/MediaLayer.cpp
index e4ccbdb..3ec21a4 100644
--- a/WebCore/platform/graphics/android/MediaLayer.cpp
+++ b/WebCore/platform/graphics/android/MediaLayer.cpp
@@ -15,12 +15,11 @@
*/
#include "config.h"
#include "MediaLayer.h"
+#include "MediaTexture.h"
#include "TilesManager.h"
#if USE(ACCELERATED_COMPOSITING)
-#include <wtf/CurrentTime.h>
-
#define LAYER_DEBUG
#undef LAYER_DEBUG
@@ -45,6 +44,9 @@ MediaLayer::MediaLayer() : LayerAndroid(false)
{
m_bufferedTexture = new MediaTexture(EGL_NO_CONTEXT);
m_bufferedTexture->incStrong(this);
+ m_videoTexture = new VideoTexture();
+ m_videoTexture->incStrong(this);
+
m_currentTextureInfo = 0;
m_isContentInverted = false;
XLOG("Creating Media Layer %p", this);
@@ -54,6 +56,9 @@ MediaLayer::MediaLayer(const MediaLayer& layer) : LayerAndroid(layer)
{
m_bufferedTexture = layer.getTexture();
m_bufferedTexture->incStrong(this);
+ m_videoTexture = layer.m_videoTexture;
+ m_videoTexture->incStrong(this);
+
m_currentTextureInfo = 0;
m_isContentInverted = layer.m_isContentInverted;
XLOG("Creating Media Layer Copy %p -> %p", &layer, this);
@@ -63,24 +68,31 @@ MediaLayer::~MediaLayer()
{
XLOG("Deleting Media Layer");
m_bufferedTexture->decStrong(this);
+ m_videoTexture->decStrong(this);
}
bool MediaLayer::drawGL(SkMatrix& matrix)
{
+
+ TransformationMatrix m = drawTransform();
+ // the layer's shader draws the content inverted so we must undo
+ // that change in the transformation matrix
+ if (!m_isContentInverted) {
+ m.flipY();
+ m.translate(0, -getSize().height());
+ }
+
+ // check to see if we need to create a video texture
+ m_videoTexture->initNativeWindowIfNeeded();
+ // draw any video content if present
+ m_videoTexture->drawVideo(m);
+
+ // draw the primary content
if (m_bufferedTexture) {
TextureInfo* textureInfo = m_bufferedTexture->consumerLock();
if (textureInfo) {
SkRect rect;
rect.set(0, 0, getSize().width(), getSize().height());
- TransformationMatrix m = drawTransform();
-
- // the layer's shader draws the content inverted so we must undo
- // that change in the transformation matrix
- if (!m_isContentInverted) {
- m.flipY();
- m.translate(0, -getSize().height());
- }
-
TilesManager::instance()->shader()->drawLayerQuad(m, rect,
textureInfo->m_textureId,
1.0f); //TODO fix this m_drawOpacity
@@ -94,6 +106,26 @@ bool MediaLayer::drawGL(SkMatrix& matrix)
return true;
}
+ANativeWindow* MediaLayer::acquireNativeWindowForVideo()
+{
+ return m_videoTexture->requestNewWindow();
+}
+
+void MediaLayer::setWindowDimensionsForVideo(const ANativeWindow* window, const SkRect& dimensions)
+{
+ if (window != m_videoTexture->getNativeWindow())
+ return;
+
+ //TODO validate that the dimensions do not exceed the plugin's bounds
+ m_videoTexture->setDimensions(dimensions);
+}
+
+void MediaLayer::releaseNativeWindowForVideo(ANativeWindow* window)
+{
+ if (window == m_videoTexture->getNativeWindow())
+ m_videoTexture->releaseNativeWindow();
+}
+
} // namespace WebCore
#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebCore/platform/graphics/android/MediaLayer.h b/WebCore/platform/graphics/android/MediaLayer.h
index 1944512..dec6427 100644
--- a/WebCore/platform/graphics/android/MediaLayer.h
+++ b/WebCore/platform/graphics/android/MediaLayer.h
@@ -19,22 +19,15 @@
#if USE(ACCELERATED_COMPOSITING)
-#include "RefPtr.h"
-#include "DoubleBufferedTexture.h"
+#include "MediaTexture.h"
#include "LayerAndroid.h"
-#include <utils/RefBase.h>
+namespace android {
+ class SurfaceTexture;
+}
namespace WebCore {
-class MediaTexture : public DoubleBufferedTexture,
- public android::LightRefBase<MediaTexture> {
-
-public:
- MediaTexture(EGLContext sharedContext) : DoubleBufferedTexture(sharedContext) { };
-};
-
-
class MediaLayer : public LayerAndroid {
public:
@@ -56,14 +49,21 @@ public:
void invertContents(bool invertContent) { m_isContentInverted = invertContent; }
+ // functions to manipulate secondary layers for video playback
+ ANativeWindow* acquireNativeWindowForVideo();
+ void setWindowDimensionsForVideo(const ANativeWindow* window, const SkRect& dimensions);
+ void releaseNativeWindowForVideo(ANativeWindow* window);
+
private:
- // GL textures management
+ // Primary GL texture variables
MediaTexture* m_bufferedTexture;
-
TextureInfo* m_currentTextureInfo;
bool m_isContentInverted;
+
+ // Video texture variables
+ VideoTexture* m_videoTexture;
};
} // namespace WebCore
diff --git a/WebCore/platform/graphics/android/MediaTexture.cpp b/WebCore/platform/graphics/android/MediaTexture.cpp
new file mode 100644
index 0000000..71a4a0e
--- /dev/null
+++ b/WebCore/platform/graphics/android/MediaTexture.cpp
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "config.h"
+#include "MediaTexture.h"
+#include "TilesManager.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include <android/native_window.h>
+#include <gui/SurfaceTexture.h>
+#include <gui/SurfaceTextureClient.h>
+#include <wtf/CurrentTime.h>
+
+#define LAYER_DEBUG
+#undef LAYER_DEBUG
+
+#ifdef DEBUG
+
+#include <cutils/log.h>
+#include <wtf/text/CString.h>
+
+#undef XLOG
+#define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "MediaTexture", __VA_ARGS__)
+
+#else
+
+#undef XLOG
+#define XLOG(...)
+
+#endif // DEBUG
+
+namespace WebCore {
+
+VideoTexture::VideoTexture()
+{
+ m_textureId = 0;
+ m_dimensions.setEmpty();
+ m_newWindowRequest = false;
+ m_newWindowReady = false;
+}
+
+VideoTexture::~VideoTexture()
+{
+ releaseNativeWindow();
+ if (m_textureId)
+ glDeleteTextures(1, &m_textureId);
+}
+
+void VideoTexture::initNativeWindowIfNeeded()
+{
+ android::Mutex::Autolock lock(m_videoLock);
+
+ if(!m_newWindowRequest)
+ return;
+
+ // reuse an existing texture if possible
+ if (!m_textureId)
+ glGenTextures(1, &m_textureId);
+
+ m_surfaceTexture = new android::SurfaceTexture(m_textureId);
+ m_surfaceTextureClient = new android::SurfaceTextureClient(m_surfaceTexture);
+ m_newWindowRequest = false;
+ m_newWindowReady = true;
+ m_newVideoRequestCond.signal();
+}
+
+void VideoTexture::drawVideo(TransformationMatrix matrix)
+{
+ android::Mutex::Autolock lock(m_videoLock);
+
+ if(!m_surfaceTexture.get() || m_dimensions.isEmpty())
+ return;
+
+ m_surfaceTexture->updateTexImage();
+ TilesManager::instance()->shader()->drawLayerQuad(matrix, m_dimensions, m_textureId, 1.0f);
+}
+
+ANativeWindow* VideoTexture::requestNewWindow()
+{
+ android::Mutex::Autolock lock(m_videoLock);
+
+ // the window was not ready before the timeout so return it this time
+ if (m_newWindowReady) {
+ m_newWindowReady = false;
+ return m_surfaceTextureClient.get();
+ }
+ // we only allow for one texture, so if one already exists return null
+ else if (m_surfaceTextureClient.get()) {
+ return 0;
+ }
+
+ m_newWindowRequest = true;
+ //block until the request can be fulfilled or we time out
+ m_newVideoRequestCond.waitRelative(m_videoLock, 1000000000); // 1 sec
+
+ if (m_surfaceTextureClient.get())
+ m_newWindowReady = false;
+
+ return m_surfaceTextureClient.get();
+}
+
+ANativeWindow* VideoTexture::getNativeWindow()
+{
+ android::Mutex::Autolock lock(m_videoLock);
+ return m_surfaceTextureClient.get();
+}
+
+void VideoTexture::releaseNativeWindow()
+{
+ android::Mutex::Autolock lock(m_videoLock);
+ m_dimensions.setEmpty();
+ m_surfaceTextureClient.clear();
+ m_surfaceTexture.clear();
+}
+
+void VideoTexture::setDimensions(const SkRect& dimensions)
+{
+ android::Mutex::Autolock lock(m_videoLock);
+ m_dimensions = dimensions;
+}
+
+} // namespace WebCore
+
+#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebCore/platform/graphics/android/MediaTexture.h b/WebCore/platform/graphics/android/MediaTexture.h
new file mode 100644
index 0000000..abb8081
--- /dev/null
+++ b/WebCore/platform/graphics/android/MediaTexture.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MediaTexture_h
+#define MediaTexture_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "RefPtr.h"
+#include "DoubleBufferedTexture.h"
+#include "LayerAndroid.h"
+#include <utils/RefBase.h>
+
+namespace android {
+ class SurfaceTexture;
+}
+
+namespace WebCore {
+
+class MediaTexture : public DoubleBufferedTexture,
+ public android::LightRefBase<MediaTexture> {
+
+public:
+ MediaTexture(EGLContext sharedContext) : DoubleBufferedTexture(sharedContext) { };
+};
+
+class VideoTexture : public android::LightRefBase<VideoTexture> {
+
+public:
+ VideoTexture();
+ ~VideoTexture();
+
+ void initNativeWindowIfNeeded();
+ void drawVideo(TransformationMatrix matrix);
+
+ ANativeWindow* requestNewWindow();
+ ANativeWindow* getNativeWindow();
+ void releaseNativeWindow();
+ void setDimensions(const SkRect& dimensions);
+
+
+private:
+ GLuint m_textureId;
+ sp<android::SurfaceTexture> m_surfaceTexture;
+ sp<ANativeWindow> m_surfaceTextureClient;
+ SkRect m_dimensions;
+ bool m_newWindowRequest;
+ bool m_newWindowReady;
+
+ android::Mutex m_videoLock;
+ android::Condition m_newVideoRequestCond;
+};
+
+
+} // namespace WebCore
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif // MediaTexture_h
diff --git a/WebCore/plugins/android/PluginViewAndroid.cpp b/WebCore/plugins/android/PluginViewAndroid.cpp
index bd367c3..122404a 100644
--- a/WebCore/plugins/android/PluginViewAndroid.cpp
+++ b/WebCore/plugins/android/PluginViewAndroid.cpp
@@ -86,6 +86,7 @@
#include "ANPOpenGL_npapi.h"
#include "ANPSurface_npapi.h"
#include "ANPSystem_npapi.h"
+#include "ANPVideo_npapi.h"
#include "SkANP.h"
#include "SkFlipPixelRef.h"
@@ -107,6 +108,7 @@ extern void ANPWindowInterfaceV0_Init(ANPInterface* value);
extern void ANPWindowInterfaceV1_Init(ANPInterface* value);
extern void ANPSystemInterfaceV0_Init(ANPInterface* value);
extern void ANPOpenGLInterfaceV0_Init(ANPInterface* value);
+extern void ANPVideoInterfaceV0_Init(ANPInterface* value);
struct VarProcPair {
int enumValue;
@@ -133,6 +135,7 @@ static const VarProcPair gVarProcs[] = {
{ VARPROCLINE(WindowInterfaceV1) },
{ VARPROCLINE(SystemInterfaceV0) },
{ VARPROCLINE(OpenGLInterfaceV0) },
+ { VARPROCLINE(VideoInterfaceV0) },
};
/* return true if var was an interface request (error will be set accordingly)