Fixed optimized cairo_surface_fill for image surface
authorOleg Romashin <romaxa@gmail.com>
Thu, 01 May 2008 14:50:24 +0300
changeset 16937 64770ba3ec7f7eaf9f826f115df85692f5e30105
parent 16936 f271a29fcba1a932c07ece789da17740d855e0d5
child 16939 3c75a8221f6f4d480de0ea4fc0d9a601e0a0ad5a
push id1298
push userpavlov@mozilla.com
push dateSun, 17 Aug 2008 05:03:09 +0000
treeherderautoland@4a506fa751d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone2.0a1pre
Fixed optimized cairo_surface_fill for image surface Enable OptimizeImage for X11 QSurface
gfx/cairo/cairo/src/cairo-qpainter-surface.cpp
gfx/thebes/public/gfxQtPlatform.h
gfx/thebes/src/gfxQtPlatform.cpp
--- a/gfx/cairo/cairo/src/cairo-qpainter-surface.cpp
+++ b/gfx/cairo/cairo/src/cairo-qpainter-surface.cpp
@@ -1157,19 +1157,41 @@ static cairo_int_status_t
     if (qs->supports_porter_duff)
         qs->p->setCompositionMode (_qpainter_compositionmode_from_cairo_op (op));
 
     // XXX Qt4.3, 4.4 misrenders some complex paths if antialiasing is
     // enabled
     //qs->p->setRenderHint (QPainter::Antialiasing, antialias == CAIRO_ANTIALIAS_NONE ? false : true);
     qs->p->setRenderHint (QPainter::SmoothPixmapTransform, source->filter != CAIRO_FILTER_FAST);
 
+    if (source->type == CAIRO_PATTERN_TYPE_SURFACE &&
+            source->extend == CAIRO_EXTEND_NONE &&
+            ((cairo_surface_pattern_t*)source)->surface->type == CAIRO_SURFACE_TYPE_QPAINTER)
+    {
+        cairo_qpainter_surface_t *qsSrc = (cairo_qpainter_surface_t*) ((cairo_surface_pattern_t*)source)->surface;
+
+        QMatrix savedMatrix = qs->p->worldMatrix();
+        cairo_matrix_t m = source->matrix;
+        cairo_matrix_invert (&m);
+        qs->p->setWorldMatrix (_qmatrix_from_cairo_matrix (m), true);
+
+        if (qsSrc->image) {
+            qs->p->drawImage (0, 0, *qsSrc->image);
+        } else if (qsSrc->pixmap) {
+            qs->p->drawPixmap (0, 0, *qsSrc->pixmap);
+        }
+
+        qs->p->setWorldMatrix (savedMatrix, false);
+    } else {
+
     PatternToBrushConverter brush(source);
 
     qs->p->fillPath (qpath, brush);
+    
+    }
 
     if (qs->supports_porter_duff)
         qs->p->setCompositionMode (QPainter::CompositionMode_SourceOver);
 
     tend("fill");
 
     return CAIRO_INT_STATUS_SUCCESS;
 }
--- a/gfx/thebes/public/gfxQtPlatform.h
+++ b/gfx/thebes/public/gfxQtPlatform.h
@@ -55,19 +55,16 @@ public:
 
     static gfxQtPlatform *GetPlatform() {
         return (gfxQtPlatform*) gfxPlatform::GetPlatform();
     }
 
     already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
                                                          gfxASurface::gfxImageFormat imageFormat);
 
-    already_AddRefed<gfxASurface> OptimizeImage(gfxImageSurface *aSurface,
-                                                gfxASurface::gfxImageFormat format);
-
     nsresult GetFontList(const nsACString& aLangGroup,
                          const nsACString& aGenericFamily,
                          nsStringArray& aListOfFonts);
 
     nsresult UpdateFontList();
 
     nsresult ResolveFontName(const nsAString& aFontName,
                              FontResolverCallback aCallback,
--- a/gfx/thebes/src/gfxQtPlatform.cpp
+++ b/gfx/thebes/src/gfxQtPlatform.cpp
@@ -58,20 +58,16 @@
 
 #include "nsMathUtils.h"
 
 #include "lcms.h"
 
 #include <ft2build.h>
 #include FT_FREETYPE_H
 
-#ifndef Q_WS_X11
-#define OPTIMIZE_TO_QPIXMAP
-#endif
-
 PRInt32 gfxQtPlatform::sDPI = -1;
 gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nsnull;
 static cairo_user_data_key_t cairo_qt_pixmap_key;
 static void do_qt_pixmap_unref (void *data)
 {
     QPixmap *pmap = (QPixmap*)data;
     delete pmap;
 }
@@ -129,38 +125,16 @@ gfxQtPlatform::CreateOffscreenSurface(co
                                       gfxASurface::gfxImageFormat imageFormat)
 {
     nsRefPtr<gfxASurface> newSurface =
         new gfxQPainterSurface (size, gfxASurface::ContentFromFormat(imageFormat));
 
     return newSurface.forget();
 }
 
-already_AddRefed<gfxASurface>
-gfxQtPlatform::OptimizeImage(gfxImageSurface *aSurface,
-                             gfxASurface::gfxImageFormat format)
-{
-#ifdef OPTIMIZE_TO_QPIXMAP
-    const gfxIntSize& surfaceSize = aSurface->GetSize();
-
-    nsRefPtr<gfxASurface> optSurface = CreateOffscreenSurface(surfaceSize, format);
-    if (!optSurface || optSurface->CairoStatus() != 0)
-        return nsnull;
-
-    gfxContext tmpCtx(optSurface);
-    tmpCtx.SetOperator(gfxContext::OPERATOR_SOURCE);
-    tmpCtx.SetSource(aSurface);
-    tmpCtx.Paint();
-
-    return optSurface.forget();
-#else
-    return nsnull;
-#endif
-}
-
 nsresult
 gfxQtPlatform::GetFontList(const nsACString& aLangGroup,
                             const nsACString& aGenericFamily,
                             nsStringArray& aListOfFonts)
 {
     return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
                                          aListOfFonts);
 }