diff options
author | Derek Sollenberger <djsollen@google.com> | 2011-08-03 11:06:56 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2011-08-03 14:00:17 -0400 |
commit | 2c05b037dcbc9de2f41781747422c2098c42c16e (patch) | |
tree | c7dc65608bd8e57fa550413cc04211c670dbbfa8 /Source/WebCore/platform | |
parent | 03137dd16df459ef3bee925373347982cb98124d (diff) | |
download | external_webkit-2c05b037dcbc9de2f41781747422c2098c42c16e.zip external_webkit-2c05b037dcbc9de2f41781747422c2098c42c16e.tar.gz external_webkit-2c05b037dcbc9de2f41781747422c2098c42c16e.tar.bz2 |
Replace plugin's OpenGL API with a NativeWindow API.
bug: 5114637
Change-Id: Idfadf95b9b65bf87ad2edf76fd2c5fc0513a75c3
Diffstat (limited to 'Source/WebCore/platform')
-rw-r--r-- | Source/WebCore/platform/graphics/android/GLUtils.cpp | 15 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/GLUtils.h | 8 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/MediaLayer.cpp | 63 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/MediaLayer.h | 18 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/MediaListener.h (renamed from Source/WebCore/platform/graphics/android/VideoListener.h) | 12 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/MediaTexture.cpp | 140 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/MediaTexture.h | 34 | ||||
-rw-r--r-- | Source/WebCore/platform/graphics/android/TextureInfo.cpp | 15 |
8 files changed, 105 insertions, 200 deletions
diff --git a/Source/WebCore/platform/graphics/android/GLUtils.cpp b/Source/WebCore/platform/graphics/android/GLUtils.cpp index 5a6a158..d39b05b 100644 --- a/Source/WebCore/platform/graphics/android/GLUtils.cpp +++ b/Source/WebCore/platform/graphics/android/GLUtils.cpp @@ -623,6 +623,21 @@ void GLUtils::createTextureFromEGLImage(GLuint texture, EGLImageKHR image, GLint glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); } +GLenum GLUtils::getTextureTarget(android::SurfaceTexture* surfaceTexture) +{ +#if DEPRECATED_SURFACE_TEXTURE_MODE + if (surfaceTexture) { + GLenum target = surfaceTexture->getCurrentTextureTarget(); + // TODO: remove this translation when TEXTURE_2D+RGBA surface texture + // support is deprecated. + if (target == GL_TEXTURE_2D) + return 0; + return target; + } +#endif + return GL_TEXTURE_2D; +} + } // namespace WebCore #endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/GLUtils.h b/Source/WebCore/platform/graphics/android/GLUtils.h index 57557b2..67ff77a 100644 --- a/Source/WebCore/platform/graphics/android/GLUtils.h +++ b/Source/WebCore/platform/graphics/android/GLUtils.h @@ -38,6 +38,12 @@ #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> +namespace android { + +class SurfaceTexture; + +} // namespace android + namespace WebCore { class GLUtils { @@ -77,6 +83,8 @@ public: static void updateSurfaceTextureWithBitmap(const TileRenderInfo* , int x, int y, const SkBitmap& bitmap, GLint filter = GL_LINEAR); #endif static void updateSharedSurfaceTextureWithBitmap(const TileRenderInfo* , int x, int y, const SkBitmap& bitmap); + + static GLenum getTextureTarget(android::SurfaceTexture*); }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/MediaLayer.cpp b/Source/WebCore/platform/graphics/android/MediaLayer.cpp index 42bb7d4..1d5ce3f 100644 --- a/Source/WebCore/platform/graphics/android/MediaLayer.cpp +++ b/Source/WebCore/platform/graphics/android/MediaLayer.cpp @@ -42,46 +42,34 @@ namespace WebCore { MediaLayer::MediaLayer(jobject weakWebViewRef) : LayerAndroid((RenderLayer*) NULL) { - m_bufferedTexture = new MediaTexture(EGL_NO_CONTEXT); - m_bufferedTexture->producerInc(); - m_videoTexture = new VideoTexture(weakWebViewRef); + m_contentTexture = new MediaTexture(weakWebViewRef); + m_contentTexture->incStrong(this); + m_videoTexture = new MediaTexture(weakWebViewRef); m_videoTexture->incStrong(this); m_isCopy = false; - m_currentTextureInfo = 0; m_isContentInverted = false; m_outlineSize = 0; XLOG("Creating Media Layer %p", this); - XLOG("producer: %d consumer: %d", m_bufferedTexture->getProducerCount(), - m_bufferedTexture->getConsumerCount()); } MediaLayer::MediaLayer(const MediaLayer& layer) : LayerAndroid(layer) { - m_bufferedTexture = layer.getTexture(); - m_bufferedTexture->consumerInc(); + m_contentTexture = layer.m_contentTexture; + m_contentTexture->incStrong(this); m_videoTexture = layer.m_videoTexture; m_videoTexture->incStrong(this); m_isCopy = true; - m_currentTextureInfo = 0; m_isContentInverted = layer.m_isContentInverted; m_outlineSize = layer.m_outlineSize; XLOG("Creating Media Layer Copy %p -> %p", &layer, this); - XLOG("producer: %d consumer: %d COPY", m_bufferedTexture->getProducerCount(), - m_bufferedTexture->getConsumerCount()); } MediaLayer::~MediaLayer() { XLOG("Deleting Media Layer"); - XLOG("producer: %d consumer: %d %s", m_bufferedTexture->getProducerCount(), - m_bufferedTexture->getConsumerCount(), (m_isCopy) ? "COPY" : ""); - - if (m_isCopy) - m_bufferedTexture->consumerDec(); - else - m_bufferedTexture->producerDec(); + m_contentTexture->decStrong(this); m_videoTexture->decStrong(this); } @@ -102,32 +90,29 @@ bool MediaLayer::drawGL(GLWebViewState* glWebViewState, SkMatrix& matrix) // draw any video content if present m_videoTexture->drawVideo(m_drawTransform, mediaBounds); - // draw the primary content - if (m_bufferedTexture) { - TextureInfo* textureInfo = m_bufferedTexture->consumerLock(); - if (textureInfo && textureInfo->m_width != 0 && textureInfo->m_height != 0) { - // the layer's shader draws the content inverted so we must undo - // that change in the transformation matrix - TransformationMatrix m = m_drawTransform; - if (!m_isContentInverted) { - m.flipY(); - m.translate(0, -getSize().height()); - } - - bool forceBlending = textureInfo->m_internalFormat == GL_RGBA || - textureInfo->m_internalFormat == GL_BGRA_EXT || - textureInfo->m_internalFormat == GL_ALPHA; - TilesManager::instance()->shader()->drawLayerQuad(m, mediaBounds, - textureInfo->m_textureId, - 1.0f, forceBlending, - textureInfo->getTextureTarget()); - } - m_bufferedTexture->consumerRelease(); + // the layer's shader draws the content inverted so we must undo + // that change in the transformation matrix + TransformationMatrix m = m_drawTransform; + if (!m_isContentInverted) { + m.flipY(); + m.translate(0, -getSize().height()); } + // check to see if we need to create a content texture + m_contentTexture->initNativeWindowIfNeeded(); + // draw any content if present + m_contentTexture->setDimensions(mediaBounds); + m_contentTexture->drawContent(m); + return drawChildrenGL(glWebViewState, matrix); } +ANativeWindow* MediaLayer::acquireNativeWindowForContent() +{ + return m_contentTexture->requestNewWindow(); +} + + ANativeWindow* MediaLayer::acquireNativeWindowForVideo() { return m_videoTexture->requestNewWindow(); diff --git a/Source/WebCore/platform/graphics/android/MediaLayer.h b/Source/WebCore/platform/graphics/android/MediaLayer.h index 8a07134..dd58674 100644 --- a/Source/WebCore/platform/graphics/android/MediaLayer.h +++ b/Source/WebCore/platform/graphics/android/MediaLayer.h @@ -43,14 +43,12 @@ public: virtual bool isMedia() const { return true; } virtual LayerAndroid* copy() const { return new MediaLayer(*this); } - MediaTexture* getTexture() const { return m_bufferedTexture; } - - void setCurrentTextureInfo(TextureInfo* info) { m_currentTextureInfo = info; } - TextureInfo* getCurrentTextureInfo() const { return m_currentTextureInfo; } - void invertContents(bool invertContent) { m_isContentInverted = invertContent; } void setOutlineSize(int size) { m_outlineSize = size; } + // function to setup the primary SurfaceTexture in the renderer's context + ANativeWindow* acquireNativeWindowForContent(); + // functions to manipulate secondary layers for video playback ANativeWindow* acquireNativeWindowForVideo(); void setWindowDimensionsForVideo(const ANativeWindow* window, const SkRect& dimensions); @@ -58,16 +56,12 @@ public: private: bool m_isCopy; - - // Primary GL texture variables - MediaTexture* m_bufferedTexture; - TextureInfo* m_currentTextureInfo; - bool m_isContentInverted; int m_outlineSize; - // Video texture variables - VideoTexture* m_videoTexture; + // SurfaceTexture member variables + MediaTexture* m_contentTexture; + MediaTexture* m_videoTexture; }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/VideoListener.h b/Source/WebCore/platform/graphics/android/MediaListener.h index 7cac6d6..0a85574 100644 --- a/Source/WebCore/platform/graphics/android/VideoListener.h +++ b/Source/WebCore/platform/graphics/android/MediaListener.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef VideoListener_h -#define VideoListener_h +#ifndef MediaListener_h +#define MediaListener_h #if USE(ACCELERATED_COMPOSITING) @@ -30,7 +30,7 @@ #include <wtf/text/CString.h> #undef XLOG -#define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "VideoListener", __VA_ARGS__) +#define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "MediaListener", __VA_ARGS__) #else @@ -41,10 +41,10 @@ namespace WebCore { -class VideoListener : public android::SurfaceTexture::FrameAvailableListener { +class MediaListener : public android::SurfaceTexture::FrameAvailableListener { public: - VideoListener(jobject weakWebViewRef) + MediaListener(jobject weakWebViewRef) : m_weakWebViewRef(weakWebViewRef) , m_postInvalMethod(0) , m_frameAvailable(false) @@ -89,4 +89,4 @@ private: } // namespace WebCore #endif // USE(ACCELERATED_COMPOSITING) -#endif // VideoListener_h +#endif // MediaListener_h diff --git a/Source/WebCore/platform/graphics/android/MediaTexture.cpp b/Source/WebCore/platform/graphics/android/MediaTexture.cpp index d8dc960..a653d6e 100644 --- a/Source/WebCore/platform/graphics/android/MediaTexture.cpp +++ b/Source/WebCore/platform/graphics/android/MediaTexture.cpp @@ -17,7 +17,7 @@ #include "MediaTexture.h" #include "TilesManager.h" #include "GLUtils.h" -#include "VideoListener.h" +#include "MediaListener.h" #if USE(ACCELERATED_COMPOSITING) @@ -48,98 +48,17 @@ namespace WebCore { -MediaTexture::MediaTexture(EGLContext sharedContext) : DoubleBufferedTexture(sharedContext, EglImageMode) -{ - m_producerRefCount = 0; - m_consumerRefCount = 0; -} - -/* Increment the number of objects in the producer's thread that hold a reference - * to this object. In practice, there is often only one producer reference for - * the lifetime of the object. - */ -void MediaTexture::producerInc() -{ - android::Mutex::Autolock lock(m_mediaLock); - m_producerRefCount++; -} - -/* Decrement the number of objects in the producer's thread that are holding a - * reference to this object. When removing the last reference we must cleanup - * all GL objects that are associated with the producer's thread. There may not - * be a consumer reference as the object may not have synced to the UI thread, - * in which case the producer needs to handle the deletion of the object. - */ -void MediaTexture::producerDec() -{ - bool needsDeleted = false; - - m_mediaLock.lock(); - m_producerRefCount--; - if (m_producerRefCount == 0) { - producerDeleteTextures(); - if (m_consumerRefCount < 1) { - XLOG("INFO: This texture has not been synced to the UI thread"); - needsDeleted = true; - } - } - m_mediaLock.unlock(); - - if (needsDeleted) { - XLOG("Deleting MediaTexture Object"); - delete this; - } -} - -/* Increment the number of objects in the consumer's thread that hold a reference - * to this object. In practice, there can be multiple producer references as the - * consumer (i.e. UI) thread may have multiple copies of the layer tree. - */ -void MediaTexture::consumerInc() -{ - android::Mutex::Autolock lock(m_mediaLock); - m_consumerRefCount++; -} - -/* Decrement the number of objects in the consumer's thread that are holding a - * reference to this object. When removing the last reference we must delete - * this object and by extension cleanup all GL objects that are associated with - * the consumer's thread. At the time of deletion if there is a remaining - * producer reference we must cleanup the consumer GL objects in the event that - * this texture will not be re-synced with the UI thread. - */ -void MediaTexture::consumerDec() -{ - bool needsDeleted = false; - - m_mediaLock.lock(); - m_consumerRefCount--; - if (m_consumerRefCount == 0) { - consumerDeleteTextures(); - if (m_producerRefCount < 1) { - XLOG("WARNING: This texture still exists within webkit."); - needsDeleted = true; - } - } - m_mediaLock.unlock(); - - if (needsDeleted) { - XLOG("Deleting MediaTexture Object"); - delete this; - } -} - -VideoTexture::VideoTexture(jobject weakWebViewRef) : android::LightRefBase<VideoTexture>() +MediaTexture::MediaTexture(jobject weakWebViewRef) : android::LightRefBase<MediaTexture>() { m_weakWebViewRef = weakWebViewRef; m_textureId = 0; m_dimensions.setEmpty(); m_newWindowRequest = false; m_newWindowReady = false; - m_videoListener = new VideoListener(m_weakWebViewRef); + m_mediaListener = new MediaListener(m_weakWebViewRef); } -VideoTexture::~VideoTexture() +MediaTexture::~MediaTexture() { releaseNativeWindow(); if (m_textureId) @@ -150,10 +69,10 @@ VideoTexture::~VideoTexture() } } -void VideoTexture::initNativeWindowIfNeeded() +void MediaTexture::initNativeWindowIfNeeded() { { - android::Mutex::Autolock lock(m_videoLock); + android::Mutex::Autolock lock(m_mediaLock); if(!m_newWindowRequest) return; @@ -166,21 +85,38 @@ void VideoTexture::initNativeWindowIfNeeded() m_surfaceTextureClient = new android::SurfaceTextureClient(m_surfaceTexture); //setup callback - m_videoListener->resetFrameAvailable(); - m_surfaceTexture->setFrameAvailableListener(m_videoListener); + m_mediaListener->resetFrameAvailable(); + m_surfaceTexture->setFrameAvailableListener(m_mediaListener); m_newWindowRequest = false; m_newWindowReady = true; } - m_newVideoRequestCond.signal(); + m_newMediaRequestCond.signal(); +} + +void MediaTexture::drawContent(const TransformationMatrix& matrix) +{ + android::Mutex::Autolock lock(m_mediaLock); + + if(!m_surfaceTexture.get() || m_dimensions.isEmpty() + || !m_mediaListener->isFrameAvailable()) + return; + + m_surfaceTexture->updateTexImage(); + + bool forceBlending = ANativeWindow_getFormat(m_surfaceTextureClient.get()) == WINDOW_FORMAT_RGB_565; + GLenum target = GLUtils::getTextureTarget(m_surfaceTexture.get()); + TilesManager::instance()->shader()->drawLayerQuad(matrix, m_dimensions, + m_textureId, 1.0f, + forceBlending, target); } -void VideoTexture::drawVideo(const TransformationMatrix& matrix, const SkRect& parentBounds) +void MediaTexture::drawVideo(const TransformationMatrix& matrix, const SkRect& parentBounds) { - android::Mutex::Autolock lock(m_videoLock); + android::Mutex::Autolock lock(m_mediaLock); if(!m_surfaceTexture.get() || m_dimensions.isEmpty() - || !m_videoListener->isFrameAvailable()) + || !m_mediaListener->isFrameAvailable()) return; m_surfaceTexture->updateTexImage(); @@ -201,9 +137,9 @@ void VideoTexture::drawVideo(const TransformationMatrix& matrix, const SkRect& p dimensions, m_textureId); } -ANativeWindow* VideoTexture::requestNewWindow() +ANativeWindow* MediaTexture::requestNewWindow() { - android::Mutex::Autolock lock(m_videoLock); + android::Mutex::Autolock lock(m_mediaLock); // the window was not ready before the timeout so return it this time if (m_newWindowReady) { @@ -234,7 +170,7 @@ ANativeWindow* VideoTexture::requestNewWindow() //block until the request can be fulfilled or we time out bool timedOut = false; while (m_newWindowRequest && !timedOut) { - int ret = m_newVideoRequestCond.waitRelative(m_videoLock, 500000000); // .5 sec + int ret = m_newMediaRequestCond.waitRelative(m_mediaLock, 500000000); // .5 sec timedOut = ret == TIMED_OUT; } @@ -244,15 +180,15 @@ ANativeWindow* VideoTexture::requestNewWindow() return m_surfaceTextureClient.get(); } -ANativeWindow* VideoTexture::getNativeWindow() +ANativeWindow* MediaTexture::getNativeWindow() { - android::Mutex::Autolock lock(m_videoLock); + android::Mutex::Autolock lock(m_mediaLock); return m_surfaceTextureClient.get(); } -void VideoTexture::releaseNativeWindow() +void MediaTexture::releaseNativeWindow() { - android::Mutex::Autolock lock(m_videoLock); + android::Mutex::Autolock lock(m_mediaLock); m_dimensions.setEmpty(); if (m_surfaceTexture.get()) @@ -263,9 +199,9 @@ void VideoTexture::releaseNativeWindow() m_surfaceTexture.clear(); } -void VideoTexture::setDimensions(const SkRect& dimensions) +void MediaTexture::setDimensions(const SkRect& dimensions) { - android::Mutex::Autolock lock(m_videoLock); + android::Mutex::Autolock lock(m_mediaLock); m_dimensions = dimensions; } diff --git a/Source/WebCore/platform/graphics/android/MediaTexture.h b/Source/WebCore/platform/graphics/android/MediaTexture.h index 722afd8..d7ae9cb 100644 --- a/Source/WebCore/platform/graphics/android/MediaTexture.h +++ b/Source/WebCore/platform/graphics/android/MediaTexture.h @@ -31,34 +31,16 @@ namespace android { namespace WebCore { -class VideoListener; +class MediaListener; -class MediaTexture : public DoubleBufferedTexture { +class MediaTexture : public android::LightRefBase<MediaTexture> { public: - MediaTexture(EGLContext sharedContext); - - void producerInc(); - void producerDec(); - void consumerInc(); - void consumerDec(); - - int getProducerCount() { android::Mutex::Autolock lock(m_mediaLock); return m_producerRefCount; } - int getConsumerCount() { android::Mutex::Autolock lock(m_mediaLock); return m_consumerRefCount; } - -private: - android::Mutex m_mediaLock; - int m_producerRefCount; - int m_consumerRefCount; -}; - -class VideoTexture : public android::LightRefBase<VideoTexture> { - -public: - VideoTexture(jobject weakWebViewRef); - ~VideoTexture(); + MediaTexture(jobject weakWebViewRef); + ~MediaTexture(); void initNativeWindowIfNeeded(); + void drawContent(const TransformationMatrix& matrix); void drawVideo(const TransformationMatrix& matrix, const SkRect& parentBounds); ANativeWindow* requestNewWindow(); @@ -71,15 +53,15 @@ private: GLuint m_textureId; sp<android::SurfaceTexture> m_surfaceTexture; sp<ANativeWindow> m_surfaceTextureClient; - sp<VideoListener> m_videoListener; + sp<MediaListener> m_mediaListener; SkRect m_dimensions; bool m_newWindowRequest; bool m_newWindowReady; jobject m_weakWebViewRef; - android::Mutex m_videoLock; - android::Condition m_newVideoRequestCond; + android::Mutex m_mediaLock; + android::Condition m_newMediaRequestCond; }; diff --git a/Source/WebCore/platform/graphics/android/TextureInfo.cpp b/Source/WebCore/platform/graphics/android/TextureInfo.cpp index 8b3da8e..5356dcb 100644 --- a/Source/WebCore/platform/graphics/android/TextureInfo.cpp +++ b/Source/WebCore/platform/graphics/android/TextureInfo.cpp @@ -65,19 +65,4 @@ bool TextureInfo::operator==(const TextureInfo& otherTexture) return otherTexture.m_textureId == m_textureId && equalsAttributes(&otherTexture); } -GLenum TextureInfo::getTextureTarget() -{ -#if DEPRECATED_SURFACE_TEXTURE_MODE - if (m_surfaceTexture.get()) { - GLenum target = m_surfaceTexture->getCurrentTextureTarget(); - // TODO: remove this translation when TEXTURE_2D+RGBA surface texture - // support is deprecated. - if (target == GL_TEXTURE_2D) - return 0; - return target; - } -#endif - return GL_TEXTURE_2D; -} - } // namespace WebCore |