Title: [160080] releases/WebKitGTK/webkit-2.2/Source
Revision
160080
Author
[email protected]
Date
2013-12-04 01:47:51 -0800 (Wed, 04 Dec 2013)

Log Message

Merge r154819 - [cairo] canvas drawing on itself doesn't work with accelerated canvas
https://bugs.webkit.org/show_bug.cgi?id=118808

Reviewed by Martin Robinson.

Source/WebCore:

When copying an accelerated image, we try to get its dimensions with
cairo_image_surface_get_width/cairo_image_surface_get_height. As
surface is not an image, this returns width and height of 0.

Many other places use cairo_image_surface_get although the surface may
be a gl surface.

This patch fixes those issues by implementing a cairoSurfaceSize
helper that returns the surface size whatever type it is.

It use cairo_surface_create_similar instead of
cairo_image_surface_create in copyCairoImageSurface. It also calls
cairo_paint in encodeImage when a drawing over a black background is
needed.

It copies the surface to an image surface if needed in extractImage.

No new tests. Covered by existing tests.

* platform/graphics/cairo/BitmapImageCairo.cpp:
(WebCore::BitmapImage::BitmapImage):
(WebCore::BitmapImage::draw):
(WebCore::BitmapImage::checkForSolidColor):
* platform/graphics/cairo/CairoUtilities.cpp:
(WebCore::copyCairoImageSurface):
(WebCore::cairoSurfaceSize):
* platform/graphics/cairo/CairoUtilities.h:
* platform/graphics/cairo/GraphicsContext3DCairo.cpp:
(WebCore::GraphicsContext3D::ImageExtractor::extractImage):
* platform/graphics/gtk/GdkCairoUtilities.cpp:
(cairoSurfaceToGdkPixbuf):
* platform/graphics/gtk/GdkCairoUtilities.h:
* platform/graphics/gtk/ImageBufferGtk.cpp:
(WebCore::encodeImage):
* platform/graphics/gtk/ImageGtk.cpp:
(WebCore::BitmapImage::getGdkPixbuf):
* platform/gtk/DragIcon.cpp:
(WebCore::DragIcon::setImage):

Source/WebKit/gtk:

Change cairoImageSurfaceToGdkPixbuf to cairoSurfaceToGdkPixbuf.

* webkit/webkitfavicondatabase.cpp:
(getIconPixbufSynchronously):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/ChangeLog (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/ChangeLog	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/ChangeLog	2013-12-04 09:47:51 UTC (rev 160080)
@@ -1,3 +1,49 @@
+2013-08-29  Arnaud Renevier  <[email protected]>
+
+        [cairo] canvas drawing on itself doesn't work with accelerated canvas
+        https://bugs.webkit.org/show_bug.cgi?id=118808
+
+        Reviewed by Martin Robinson.
+
+        When copying an accelerated image, we try to get its dimensions with
+        cairo_image_surface_get_width/cairo_image_surface_get_height. As
+        surface is not an image, this returns width and height of 0.
+
+        Many other places use cairo_image_surface_get although the surface may
+        be a gl surface. 
+        
+        This patch fixes those issues by implementing a cairoSurfaceSize
+        helper that returns the surface size whatever type it is.
+
+        It use cairo_surface_create_similar instead of
+        cairo_image_surface_create in copyCairoImageSurface. It also calls
+        cairo_paint in encodeImage when a drawing over a black background is
+        needed.
+
+        It copies the surface to an image surface if needed in extractImage.
+
+        No new tests. Covered by existing tests.
+
+        * platform/graphics/cairo/BitmapImageCairo.cpp:
+        (WebCore::BitmapImage::BitmapImage):
+        (WebCore::BitmapImage::draw):
+        (WebCore::BitmapImage::checkForSolidColor):
+        * platform/graphics/cairo/CairoUtilities.cpp:
+        (WebCore::copyCairoImageSurface):
+        (WebCore::cairoSurfaceSize):
+        * platform/graphics/cairo/CairoUtilities.h:
+        * platform/graphics/cairo/GraphicsContext3DCairo.cpp:
+        (WebCore::GraphicsContext3D::ImageExtractor::extractImage):
+        * platform/graphics/gtk/GdkCairoUtilities.cpp:
+        (cairoSurfaceToGdkPixbuf):
+        * platform/graphics/gtk/GdkCairoUtilities.h:
+        * platform/graphics/gtk/ImageBufferGtk.cpp:
+        (WebCore::encodeImage):
+        * platform/graphics/gtk/ImageGtk.cpp:
+        (WebCore::BitmapImage::getGdkPixbuf):
+        * platform/gtk/DragIcon.cpp:
+        (WebCore::DragIcon::setImage):
+
 2013-12-02  Andres Gomez  <[email protected]>
 
         [GTK] Fails to build with freetype 2.5.1

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp	2013-12-04 09:47:51 UTC (rev 160080)
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "BitmapImage.h"
 
+#include "CairoUtilities.h"
 #include "ImageObserver.h"
 #include "PlatformContextCairo.h"
 #include <cairo.h>
@@ -36,6 +37,7 @@
 
 BitmapImage::BitmapImage(PassRefPtr<cairo_surface_t> nativeImage, ImageObserver* observer)
     : Image(observer)
+    , m_size(cairoSurfaceSize(nativeImage.get()))
     , m_currentFrame(0)
     , m_frames(0)
     , m_frameTimer(0)
@@ -52,10 +54,7 @@
     , m_sizeAvailable(true)
     , m_haveFrameCount(true)
 {
-    int width = cairo_image_surface_get_width(nativeImage.get());
-    int height = cairo_image_surface_get_height(nativeImage.get());
-    m_decodedSize = width * height * 4;
-    m_size = IntSize(width, height);
+    m_decodedSize = m_size.width() * m_size.height() * 4;
 
     m_frames.grow(1);
     m_frames[0].m_hasAlpha = cairo_surface_get_content(nativeImage.get()) != CAIRO_CONTENT_COLOR;
@@ -95,7 +94,7 @@
         context->setCompositeOperation(op, blendMode);
 
 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
-    IntSize scaledSize(cairo_image_surface_get_width(surface.get()), cairo_image_surface_get_height(surface.get()));
+    IntSize scaledSize = cairoSurfaceSize(surface.get());
     FloatRect adjustedSrcRect = adjustSourceRectForDownSampling(src, scaledSize);
 #else
     FloatRect adjustedSrcRect(src);
@@ -139,12 +138,12 @@
     if (!surface) // If it's too early we won't have an image yet.
         return;
 
-    ASSERT(cairo_surface_get_type(surface.get()) == CAIRO_SURFACE_TYPE_IMAGE);
+    if (cairo_surface_get_type(surface.get()) != CAIRO_SURFACE_TYPE_IMAGE)
+        return;
 
-    int width = cairo_image_surface_get_width(surface.get());
-    int height = cairo_image_surface_get_height(surface.get());
+    IntSize size = cairoSurfaceSize(surface.get());
 
-    if (width != 1 || height != 1)
+    if (size.width() != 1 || size.height() != 1)
         return;
 
     unsigned* pixelColor = reinterpret_cast_ptr<unsigned*>(cairo_image_surface_get_data(surface.get()));

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp	2013-12-04 09:47:51 UTC (rev 160080)
@@ -38,6 +38,10 @@
 #include "RefPtrCairo.h"
 #include <wtf/Vector.h>
 
+#if ENABLE(ACCELERATED_2D_CANVAS)
+#include <cairo-gl.h>
+#endif
+
 namespace WebCore {
 
 void copyContextProperties(cairo_t* srcCr, cairo_t* dstCr)
@@ -214,9 +218,9 @@
     // Cairo doesn't provide a way to copy a cairo_surface_t.
     // See http://lists.cairographics.org/archives/cairo/2007-June/010877.html
     // Once cairo provides the way, use the function instead of this.
-    RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_image_surface_create(cairo_image_surface_get_format(originalSurface), 
-                                                                             cairo_image_surface_get_width(originalSurface),
-                                                                             cairo_image_surface_get_height(originalSurface)));
+    IntSize size = cairoSurfaceSize(originalSurface);
+    RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_surface_create_similar(originalSurface,
+        cairo_surface_get_content(originalSurface), size.width(), size.height()));
 
     RefPtr<cairo_t> cr = adoptRef(cairo_create(newSurface.get()));
     cairo_set_source_surface(cr.get(), originalSurface, 0, 0);
@@ -240,4 +244,19 @@
     copyRectFromCairoSurfaceToContext(from, context.get(), sourceOffset, rect);
 }
 
+IntSize cairoSurfaceSize(cairo_surface_t* surface)
+{
+    switch (cairo_surface_get_type(surface)) {
+    case CAIRO_SURFACE_TYPE_IMAGE:
+        return IntSize(cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface));
+#if ENABLE(ACCELERATED_2D_CANVAS)
+    case CAIRO_SURFACE_TYPE_GL:
+        return IntSize(cairo_gl_surface_get_width(surface), cairo_gl_surface_get_height(surface));
+#endif
+    default:
+        ASSERT_NOT_REACHED();
+        return IntSize();
+    }
+}
+
 } // namespace WebCore

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/CairoUtilities.h (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/CairoUtilities.h	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/CairoUtilities.h	2013-12-04 09:47:51 UTC (rev 160080)
@@ -55,6 +55,8 @@
 void copyRectFromCairoSurfaceToContext(cairo_surface_t* from, cairo_t* to, const IntSize& offset, const IntRect&);
 void copyRectFromOneSurfaceToAnother(cairo_surface_t* from, cairo_surface_t* to, const IntSize& offset, const IntRect&, const IntSize& = IntSize(), cairo_operator_t = CAIRO_OPERATOR_OVER);
 
+IntSize cairoSurfaceSize(cairo_surface_t*);
+
 } // namespace WebCore
 
 #endif // CairoUtilities_h

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp	2013-12-04 09:47:51 UTC (rev 160080)
@@ -30,6 +30,7 @@
 
 #if USE(3D_GRAPHICS)
 
+#include "CairoUtilities.h"
 #include "GraphicsContext3DPrivate.h"
 #include "Image.h"
 #include "ImageSource.h"
@@ -201,13 +202,23 @@
         // do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to false.
         if (!premultiplyAlpha && m_imageHtmlDomSource != HtmlDomVideo)
             m_alphaOp = AlphaDoUnmultiply;
+
+        // if m_imageSurface is not an image, extract a copy of the surface
+        if (m_imageSurface && cairo_surface_get_type(m_imageSurface.get()) != CAIRO_SURFACE_TYPE_IMAGE) {
+            RefPtr<cairo_surface_t> tmpSurface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m_imageWidth, m_imageHeight));
+            copyRectFromOneSurfaceToAnother(m_imageSurface.get(), tmpSurface.get(), IntSize(), IntRect(0, 0, m_imageWidth, m_imageHeight), IntSize(), CAIRO_OPERATOR_SOURCE);
+            m_imageSurface = tmpSurface.release();
+        }
     }
 
     if (!m_imageSurface)
         return false;
 
-    m_imageWidth = cairo_image_surface_get_width(m_imageSurface.get());
-    m_imageHeight = cairo_image_surface_get_height(m_imageSurface.get());
+    ASSERT(cairo_surface_get_type(m_imageSurface.get()) == CAIRO_SURFACE_TYPE_IMAGE);
+
+    IntSize imageSize = cairoSurfaceSize(m_imageSurface.get());
+    m_imageWidth = imageSize.width();
+    m_imageHeight = imageSize.height();
     if (!m_imageWidth || !m_imageHeight)
         return false;
 

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp	2013-12-04 09:47:51 UTC (rev 160080)
@@ -24,16 +24,19 @@
  */
 
 #include "config.h"
+#include "CairoUtilities.h"
+
 #include "GdkCairoUtilities.h"
 #include "GtkVersioning.h"
-
+#include "IntSize.h"
 #include <cairo.h>
 #include <gtk/gtk.h>
 
-GdkPixbuf* cairoImageSurfaceToGdkPixbuf(cairo_surface_t* surface)
+using namespace WebCore;
+
+GdkPixbuf* cairoSurfaceToGdkPixbuf(cairo_surface_t* surface)
 {
-    return gdk_pixbuf_get_from_surface(surface, 0, 0,
-                                       cairo_image_surface_get_width(surface),
-                                       cairo_image_surface_get_height(surface));
+    IntSize size = cairoSurfaceSize(surface);
+    return gdk_pixbuf_get_from_surface(surface, 0, 0, size.width(), size.height());
 }
 

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.h (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.h	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.h	2013-12-04 09:47:51 UTC (rev 160080)
@@ -26,6 +26,6 @@
 #ifndef GdkCairoUtilities_h
 #define GdkCairoUtilities_h
 
-GdkPixbuf* cairoImageSurfaceToGdkPixbuf(cairo_surface_t* surface);
+GdkPixbuf* cairoSurfaceToGdkPixbuf(cairo_surface_t*);
 
 #endif // GdkCairoUtilities_h

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/ImageBufferGtk.cpp	2013-12-04 09:47:51 UTC (rev 160080)
@@ -19,6 +19,7 @@
 #include "config.h"
 #include "ImageBuffer.h"
 
+#include "CairoUtilities.h"
 #include "GdkCairoUtilities.h"
 #include <wtf/gobject/GOwnPtr.h>
 #include "GRefPtrGtk.h"
@@ -44,14 +45,23 @@
     if (type == "jpeg") {
         // JPEG doesn't support alpha channel. The <canvas> spec states that toDataURL() must encode a Porter-Duff
         // composite source-over black for image types that do not support alpha.
-        RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_image_surface_create_for_data(cairo_image_surface_get_data(surface),
-                                                                                          CAIRO_FORMAT_RGB24,
-                                                                                          cairo_image_surface_get_width(surface),
-                                                                                          cairo_image_surface_get_height(surface),
-                                                                                          cairo_image_surface_get_stride(surface)));
-        pixbuf = adoptGRef(cairoImageSurfaceToGdkPixbuf(newSurface.get()));
+        RefPtr<cairo_surface_t> newSurface;
+        if (cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_IMAGE) {
+            newSurface = adoptRef(cairo_image_surface_create_for_data(cairo_image_surface_get_data(surface),
+                CAIRO_FORMAT_RGB24,
+                cairo_image_surface_get_width(surface),
+                cairo_image_surface_get_height(surface),
+                cairo_image_surface_get_stride(surface)));
+        } else {
+            IntSize size = cairoSurfaceSize(surface);
+            newSurface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_RGB24, size.width(), size.height()));
+            RefPtr<cairo_t> cr = adoptRef(cairo_create(newSurface.get()));
+            cairo_set_source_surface(cr.get(), surface, 0, 0);
+            cairo_paint(cr.get());
+        }
+        pixbuf = adoptGRef(cairoSurfaceToGdkPixbuf(newSurface.get()));
     } else
-        pixbuf = adoptGRef(cairoImageSurfaceToGdkPixbuf(surface));
+        pixbuf = adoptGRef(cairoSurfaceToGdkPixbuf(surface));
     if (!pixbuf)
         return false;
 

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/ImageGtk.cpp (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/ImageGtk.cpp	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/graphics/gtk/ImageGtk.cpp	2013-12-04 09:47:51 UTC (rev 160080)
@@ -109,7 +109,7 @@
 GdkPixbuf* BitmapImage::getGdkPixbuf()
 {
     RefPtr<cairo_surface_t> surface = nativeImageForCurrentFrame();
-    return surface ? cairoImageSurfaceToGdkPixbuf(surface.get()) : 0;
+    return surface ? cairoSurfaceToGdkPixbuf(surface.get()) : 0;
 }
 
 }

Modified: releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/gtk/DragIcon.cpp (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/gtk/DragIcon.cpp	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebCore/platform/gtk/DragIcon.cpp	2013-12-04 09:47:51 UTC (rev 160080)
@@ -103,7 +103,7 @@
     }
 
 #ifdef GTK_API_VERSION_2
-    m_pixbuf = adoptGRef(cairoImageSurfaceToGdkPixbuf(image));
+    m_pixbuf = adoptGRef(cairoSurfaceToGdkPixbuf(image));
 #endif
 }
 

Modified: releases/WebKitGTK/webkit-2.2/Source/WebKit/gtk/ChangeLog (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebKit/gtk/ChangeLog	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebKit/gtk/ChangeLog	2013-12-04 09:47:51 UTC (rev 160080)
@@ -1,3 +1,15 @@
+2013-08-29  Arnaud Renevier  <[email protected]>
+
+        [cairo] canvas drawing on itself doesn't work with accelerated canvas
+        https://bugs.webkit.org/show_bug.cgi?id=118808
+
+        Reviewed by Martin Robinson.
+
+        Change cairoImageSurfaceToGdkPixbuf to cairoSurfaceToGdkPixbuf.
+
+        * webkit/webkitfavicondatabase.cpp:
+        (getIconPixbufSynchronously):
+
 2013-12-02  Gustavo Noronha Silva  <[email protected]>
 
         [GTK] GTK2 paint code path does not render AC layers

Modified: releases/WebKitGTK/webkit-2.2/Source/WebKit/gtk/webkit/webkitfavicondatabase.cpp (160079 => 160080)


--- releases/WebKitGTK/webkit-2.2/Source/WebKit/gtk/webkit/webkitfavicondatabase.cpp	2013-12-04 09:30:03 UTC (rev 160079)
+++ releases/WebKitGTK/webkit-2.2/Source/WebKit/gtk/webkit/webkitfavicondatabase.cpp	2013-12-04 09:47:51 UTC (rev 160080)
@@ -396,7 +396,7 @@
     if (!surface)
         return 0;
 
-    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(cairoImageSurfaceToGdkPixbuf(surface.get()));
+    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(cairoSurfaceToGdkPixbuf(surface.get()));
     if (!pixbuf)
         return 0;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to