summaryrefslogtreecommitdiffstats
path: root/WebCore/platform
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2011-01-26 15:39:46 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-01-26 15:39:46 -0800
commitaf1d8497b809bbb7ec0ccd9dec17a091f4d86617 (patch)
tree1d0504232dd507fa435cedfd07a8db6020659fdb /WebCore/platform
parent7a7307a06aa1a2f811de4355ea0e772213f2da67 (diff)
parent136290ef021ff9a9bf9152124a5fa42069acfdfc (diff)
downloadexternal_webkit-af1d8497b809bbb7ec0ccd9dec17a091f4d86617.zip
external_webkit-af1d8497b809bbb7ec0ccd9dec17a091f4d86617.tar.gz
external_webkit-af1d8497b809bbb7ec0ccd9dec17a091f4d86617.tar.bz2
Merge "Initial pass at a video API for plugins." into honeycomb
Diffstat (limited to 'WebCore/platform')
-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
4 files changed, 265 insertions, 24 deletions
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