Add copySurfaceTye argument to copySurface function.
authorYongGeol Jung <yg48.jung@samsung.com>
Mon, 1 Apr 2013 11:37:43 +0000 (20:37 +0900)
committerYongGeol Jung <yg48.jung@samsung.com>
Tue, 2 Apr 2013 02:28:18 +0000 (11:28 +0900)
[Title] Add copySurfaceTye argument to copySurface function.
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] N/A

Change-Id: I1aa1f5ce548b3c331af0a30eb1d023fc514c3f17

Source/WebCore/platform/graphics/gstreamer/tizen/SharedVideoPlatformSurfaceTizen.cpp
Source/WebCore/platform/graphics/gstreamer/tizen/SharedVideoPlatformSurfaceTizen.h
Source/WebCore/platform/graphics/gstreamer/tizen/VideoLayerTizen.cpp

index d5ae97e..53e4bb1 100644 (file)
@@ -50,7 +50,7 @@ public:
 
     int id() const { return m_platformSurface; }
     void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
-    void copySurface(VideoPlatformSurface* other);
+    void copySurface(VideoPlatformSurface* other, SharedVideoPlatformSurfaceTizen::CopySurfaceType type);
     bool hasAlpha() { return m_hasAlpha; }
 
 private:
@@ -123,7 +123,7 @@ void VideoPlatformSurface::paintCurrentFrameInContext(GraphicsContext* context,
     cairo_surface_destroy(surface);
 }
 
-void VideoPlatformSurface::copySurface(VideoPlatformSurface* other)
+void VideoPlatformSurface::copySurface(VideoPlatformSurface* other, SharedVideoPlatformSurfaceTizen::CopySurfaceType type)
 {
     RefPtr<cairo_surface_t> surface = adoptRef(cairo_xlib_surface_create(m_nativeDisplay, m_platformSurface, DefaultVisual(m_nativeDisplay, DefaultScreen(m_nativeDisplay)), m_size.width(), m_size.height()));
     RefPtr<cairo_t> context = adoptRef(cairo_create(surface.get()));
@@ -131,14 +131,23 @@ void VideoPlatformSurface::copySurface(VideoPlatformSurface* other)
 
     float xScale = static_cast<float>(m_size.width()) / other->m_size.width();
     float yScale = static_cast<float>(m_size.height()) / other->m_size.height();
+    float xPosition = 0;
+    float yPosition = 0;
 
-    // Fit to width. (scale using xScale.)
-    // Copy to center of destination surface.
     if (xScale != yScale) {
-        float yPosition = (m_size.height() - other->m_size.height() * xScale) / 2;
-        graphicsContext->translate(0, yPosition);
+        switch (type) {
+        case SharedVideoPlatformSurfaceTizen::FitToWidth:
+            yPosition = (m_size.height() - other->m_size.height() * xScale) / 2;
+            yScale = xScale;
+            break;
+        case SharedVideoPlatformSurfaceTizen::FitToHeight:
+            xPosition = (m_size.width() - other->m_size.width() * yScale) / 2;
+            xScale = yScale;
+            break;
+        }
     }
-    graphicsContext->scale(FloatSize(xScale, xScale));
+    graphicsContext->translate(xPosition, yPosition);
+    graphicsContext->scale(FloatSize(xScale, yScale));
     other->paintCurrentFrameInContext(graphicsContext.get(), IntRect());
 }
 
@@ -344,10 +353,10 @@ void SharedVideoPlatformSurfaceTizen::paintCurrentFrameInContext(GraphicsContext
         m_platformSurface->paintCurrentFrameInContext(context, rect);
 }
 
-void SharedVideoPlatformSurfaceTizen::copySurface(SharedVideoPlatformSurfaceTizen* other)
+void SharedVideoPlatformSurfaceTizen::copySurface(SharedVideoPlatformSurfaceTizen* other, CopySurfaceType type)
 {
     if (m_platformSurface)
-        m_platformSurface->copySurface(other->m_platformSurface.get());
+        m_platformSurface->copySurface(other->m_platformSurface.get(), type);
 }
 
 void SharedVideoPlatformSurfaceTizen::registerDamageHandler()
index 604739c..453b8ee 100644 (file)
@@ -41,6 +41,12 @@ public:
 
 class SharedVideoPlatformSurfaceTizen {
 public:
+    enum CopySurfaceType {
+        FitToWidth,
+        FitToHeight,
+        FitToRect
+    };
+
     static PassOwnPtr<SharedVideoPlatformSurfaceTizen> create(IntSize size);
     ~SharedVideoPlatformSurfaceTizen();
 
@@ -48,7 +54,7 @@ public:
     void platformSurfaceUpdated();
     void setVideoPlatformSurfaceUpdateListener(VideoPlatformSurfaceUpdateListener* listener);
     void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
-    void copySurface(SharedVideoPlatformSurfaceTizen*);
+    void copySurface(SharedVideoPlatformSurfaceTizen*, CopySurfaceType);
     int graphicsSurfaceFlags() const;
 
 private:
index 94a719d..655a892 100644 (file)
@@ -180,7 +180,7 @@ void VideoLayerTizen::setOverlay(IntSize size)
     m_platformSurface->setVideoPlatformSurfaceUpdateListener(this);
 
     if (m_platformSurfaceToBeRemoved)
-        m_platformSurface->copySurface(m_platformSurfaceToBeRemoved.get());
+        m_platformSurface->copySurface(m_platformSurfaceToBeRemoved.get(), SharedVideoPlatformSurfaceTizen::FitToWidth);
 
     gst_x_overlay_set_window_handle(GST_X_OVERLAY(m_videoSink), m_platformSurface->id());
 #if !USE(ACCELERATED_VIDEO_VAAPI)