From c359ad93e3338fee4ff3284b642ade2140567c3e Mon Sep 17 00:00:00 2001
From: Benjamin Otte <otte@gnome.org>
Date: Tue, 13 Oct 2009 22:14:39 +0200
Subject: [PATCH 04/12] [cairo] Make BitmapImage::checkForSolidColor() work for all surfaces

Remove the requirement to have an image surface by copying to an image
surface if it is not.
---
 WebCore/platform/graphics/cairo/ImageCairo.cpp |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/WebCore/platform/graphics/cairo/ImageCairo.cpp b/WebCore/platform/graphics/cairo/ImageCairo.cpp
index c8c992e..bfc75df 100644
--- a/WebCore/platform/graphics/cairo/ImageCairo.cpp
+++ b/WebCore/platform/graphics/cairo/ImageCairo.cpp
@@ -210,22 +210,31 @@ void BitmapImage::checkForSolidColor()
     if (frameCount() > 1)
         return;
 
+    if (size().width() != 1 || size().height() != 1)
+        return;
+
     cairo_surface_t* frameSurface = frameAtIndex(0);
     if (!frameSurface)
         return;
 
-    ASSERT(cairo_surface_get_type(frameSurface) == CAIRO_SURFACE_TYPE_IMAGE);
-
-    int width = cairo_image_surface_get_width(frameSurface);
-    int height = cairo_image_surface_get_height(frameSurface);
-
-    if (width != 1 || height != 1)
-        return;
+    if (cairo_surface_get_type(frameSurface) == CAIRO_SURFACE_TYPE_IMAGE &&
+        cairo_image_surface_get_format(frameSurface) == CAIRO_FORMAT_ARGB32) {
+      cairo_surface_reference (frameSurface);
+    } else {
+      cairo_surface_t *image = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
+      cairo_t *cr = cairo_create(image);
+      cairo_set_source_surface(cr, frameSurface, 0, 0);
+      cairo_paint(cr);
+      cairo_destroy(cr);
+      frameSurface = image;
+    }
 
     unsigned* pixelColor = reinterpret_cast<unsigned*>(cairo_image_surface_get_data(frameSurface));
     m_solidColor = colorFromPremultipliedARGB(*pixelColor);
 
     m_isSolidColor = true;
+
+    cairo_surface_destroy (frameSurface);
 }
 
 }
-- 
1.6.3.3

