2 Copyright (C) 2012 Samsung Electronics.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "VideoLayerTizen.h"
23 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER)
25 #include "GraphicsContext.h"
27 #include "RenderLayerBacking.h"
29 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
30 #include <gst/interfaces/xoverlay.h>
31 #include <gst/video/gstvideosink.h>
32 #include <gst/video/video.h>
34 #include <cairo-xlib.h>
36 #include <X11/Xutil.h>
37 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
39 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) || CPU(X86) || CPU(X86_64)
40 static Display* g_nativeDisplay = 0;
41 static int g_nativeWindow = 0;
46 VideoLayerTizen::VideoLayerTizen(HTMLMediaElement* media)
48 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
51 , m_platformSurfaceID(0)
52 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
54 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) || CPU(X86) || CPU(X86_64)
56 g_nativeDisplay = XOpenDisplay(0);
61 g_nativeWindow = XCreateSimpleWindow(g_nativeDisplay, XDefaultRootWindow(g_nativeDisplay),
63 BlackPixel(g_nativeDisplay, 0), WhitePixel(g_nativeDisplay, 0));
64 XFlush(g_nativeDisplay);
68 VideoLayerTizen::~VideoLayerTizen()
72 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
73 if (m_platformSurface)
74 m_platformSurface.clear();
76 if (m_platformSurfaceToBeRemoved)
77 m_platformSurfaceToBeRemoved.clear();
81 if (m_platformSurfaceID) {
82 XFreePixmap(g_nativeDisplay, m_platformSurfaceID);
83 m_platformSurfaceID = 0;
86 XDestroyWindow(g_nativeDisplay, g_nativeWindow);
89 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
92 PlatformLayer* VideoLayerTizen::platformLayer() const
94 return const_cast<TextureMapperPlatformLayer*>(static_cast<const TextureMapperPlatformLayer*>(this));
97 void VideoLayerTizen::syncLayer(VideoLayerTizen* layer)
99 RenderBox* renderBox = m_media->renderBox();
100 if (renderBox && renderBox->hasAcceleratedCompositing()) {
101 RenderLayer* renderLayer = renderBox->layer();
102 if (renderLayer && renderLayer->isComposited()) {
103 GraphicsLayer* graphicsLayer = renderLayer->backing()->graphicsLayer();
105 graphicsLayer->setContentsToMedia(layer);
110 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
111 static gboolean platformSurfaceUpdateTimeoutCallback(VideoLayerTizen* layer)
113 layer->notifySyncRequired();
117 bool VideoLayerTizen::swapPlatformSurfaces()
122 void VideoLayerTizen::freePlatformSurface(int id)
124 if (m_platformSurfaceToBeRemoved)
125 m_platformSurfaceToBeRemoved.clear();
128 void VideoLayerTizen::platformSurfaceUpdated()
130 notifySyncRequired();
133 GstElement* VideoLayerTizen::createVideoSink()
135 GstElement* videoSink = gst_element_factory_make("xvimagesink", "xvimagesink");
136 g_object_set(videoSink, "rotate", 0, NULL);
138 m_videoSink = videoSink;
143 void VideoLayerTizen::notifySyncRequired()
145 if (!m_platformSurface)
151 void VideoLayerTizen::setOverlay(IntSize size)
159 if (m_platformSurface)
160 m_platformSurfaceToBeRemoved = m_platformSurface.release();
162 m_platformSurface = SharedVideoPlatformSurfaceTizen::create(size);
163 m_platformSurface->setVideoPlatformSurfaceUpdateListener(this);
165 gst_x_overlay_set_window_handle(GST_X_OVERLAY(m_videoSink), m_platformSurface->id());
166 g_object_set(m_videoSink, "rotate", 0, NULL);
169 void VideoLayerTizen::paintCurrentFrameInContext(GraphicsContext* context, const IntRect& rect)
171 if (m_platformSurface)
172 m_platformSurface->paintCurrentFrameInContext(context, rect);
175 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && (CPU(X86) || CPU(X86_64))
176 bool VideoLayerTizen::swapPlatformSurfaces()
181 void VideoLayerTizen::paintVideoLayer(IntSize videoSize)
183 if (videoSize.isEmpty())
186 if (m_videoSize != videoSize) {
187 m_videoSize = videoSize;
189 if (m_platformSurfaceID) {
190 XFreePixmap(g_nativeDisplay, m_platformSurfaceID);
191 m_platformSurfaceID = 0;
193 m_platformSurfaceID = XCreatePixmap(g_nativeDisplay, g_nativeWindow, m_videoSize.width(), m_videoSize.height(), DefaultDepth(g_nativeDisplay, DefaultScreen(g_nativeDisplay)));
194 XFlush(g_nativeDisplay);
197 RefPtr<cairo_surface_t> surface = adoptRef(cairo_xlib_surface_create(g_nativeDisplay, m_platformSurfaceID, DefaultVisual(g_nativeDisplay, DefaultScreen(g_nativeDisplay)), m_videoSize.width(), m_videoSize.height()));
198 if (cairo_surface_status(surface.get()) != CAIRO_STATUS_SUCCESS)
201 RefPtr<cairo_t> cr = adoptRef(cairo_create(surface.get()));
202 OwnPtr<WebCore::GraphicsContext> context = adoptPtr(new GraphicsContext(cr.get()));
203 m_media->player()->paint(context.get(), IntRect(0, 0, m_videoSize.width(), m_videoSize.height()));
204 XFlush(g_nativeDisplay);
208 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
210 #if USE(GRAPHICS_SURFACE) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
211 uint64_t VideoLayerTizen::graphicsSurfaceToken() const
213 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
214 return (m_platformSurface ? m_platformSurface->id() : 0);
216 return m_platformSurfaceID;
220 uint32_t VideoLayerTizen::copyToGraphicsSurface()
222 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
223 return (m_platformSurface ? m_platformSurface->id() : 0);
225 return m_platformSurfaceID;
229 int VideoLayerTizen::graphicsSurfaceFlags() const
231 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !(CPU(X86) || CPU(X86_64))
232 return GraphicsSurface::Is2D | GraphicsSurface::UseLinearFilter | GraphicsSurface::Alpha;
234 return GraphicsSurface::Is2D;
237 #endif // USE(GRAPHICS_SURFACE) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
241 #endif // ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER)