[Qt] r122720 causes performance regression with DirectFB on ARMv7
https://bugs.webkit.org/show_bug.cgi?id=97548

Reviewed by Jocelyn Turcotte.

Revert the rest of r122720. This change modifies the NativeImagePtr from QImage* to QPixmap*.

Covered by existing tests.

Source/WebCore:

* bridge/qt/qt_pixmapruntime.cpp:
(JSC::Bindings::assignToHTMLImageElement):
(JSC::Bindings::QtPixmapRuntime::toQt):
* platform/DragImage.h:
(WebCore):
* platform/graphics/GraphicsContext.h:
(GraphicsContext):
* platform/graphics/Image.h:
(Image):
* platform/graphics/NativeImagePtr.h:
(WebCore):
* platform/graphics/gstreamer/ImageGStreamer.h:
* platform/graphics/gstreamer/ImageGStreamerQt.cpp:
(ImageGStreamer::ImageGStreamer):
* platform/graphics/qt/GraphicsContext3DQt.cpp:
(WebCore::GraphicsContext3D::getImageData):
* platform/graphics/qt/GraphicsContextQt.cpp:
(WebCore::GraphicsContext::pushTransparencyLayerInternal):
(WebCore::GraphicsContext::beginPlatformTransparencyLayer):
(WebCore::GraphicsContext::endPlatformTransparencyLayer):
* platform/graphics/qt/ImageBufferDataQt.h:
(ImageBufferData):
* platform/graphics/qt/ImageBufferQt.cpp:
(WebCore::ImageBufferData::ImageBufferData):
(WebCore):
(WebCore::ImageBufferData::toQImage):
(WebCore::ImageBuffer::copyImage):
(WebCore::ImageBuffer::clip):
(WebCore::ImageBuffer::platformTransformColorSpace):
(WebCore::getImageData):
(WebCore::ImageBuffer::putByteArray):
(WebCore::encodeImage):
(WebCore::ImageBuffer::toDataURL):
* platform/graphics/qt/ImageDecoderQt.cpp:
(WebCore::ImageFrame::asNewNativeImage):
* platform/graphics/qt/ImageQt.cpp:
(graphics):
(loadResourcePixmap):
(WebCore::Image::loadPlatformResource):
(WebCore::Image::setPlatformResource):
(WebCore::Image::drawPattern):
(WebCore::BitmapImage::BitmapImage):
(WebCore::BitmapImage::draw):
(WebCore::BitmapImage::checkForSolidColor):
(WebCore::BitmapImage::create):
* platform/graphics/qt/PatternQt.cpp:
(WebCore::Pattern::createPlatformPattern):
* platform/graphics/qt/StillImageQt.cpp:
(WebCore::StillImage::StillImage):
(WebCore::StillImage::~StillImage):
(WebCore::StillImage::currentFrameHasAlpha):
(WebCore::StillImage::size):
(WebCore::StillImage::nativeImageForCurrentFrame):
(WebCore::StillImage::draw):
* platform/graphics/qt/StillImageQt.h:
(WebCore::StillImage::create):
(WebCore::StillImage::createForRendering):
(StillImage):
* platform/graphics/qt/TransparencyLayer.h:
(WebCore::TransparencyLayer::TransparencyLayer):
(TransparencyLayer):
* platform/graphics/surfaces/qt/GraphicsSurfaceQt.cpp:
(WebCore::GraphicsSurface::createReadOnlyImage):
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::BitmapTextureGL::updateContents):
* platform/qt/ClipboardQt.cpp:
(WebCore::ClipboardQt::createDragImage):
(WebCore::ClipboardQt::declareAndWriteDragImage):
* platform/qt/CursorQt.cpp:
(WebCore::createCustomCursor):
* platform/qt/DragImageQt.cpp:
(WebCore::createDragImageFromImage):
* platform/qt/PasteboardQt.cpp:
(WebCore::Pasteboard::writeImage):

Source/WebKit/qt:

* Api/qwebframe.cpp:
(QWebHitTestResultPrivate::QWebHitTestResultPrivate):
* Api/qwebhistory.cpp:
(QWebHistoryItem::icon):
* Api/qwebsettings.cpp:
(QWebSettings::iconForUrl):
(QWebSettings::setWebGraphic):
(QWebSettings::webGraphic):
* WebCoreSupport/DragClientQt.cpp:
(WebCore::DragClientQt::startDrag):
* WebCoreSupport/InitWebCoreQt.cpp:
(WebCore::initializeWebCoreQt):

Source/WebKit2:

* Shared/qt/ShareableBitmapQt.cpp:
(WebKit::ShareableBitmap::createImage):
* UIProcess/qt/QtWebIconDatabaseClient.cpp:
(WebKit::QtWebIconDatabaseClient::iconImageForPageURL):
* WebProcess/WebCoreSupport/qt/WebDragClientQt.cpp:
(WebKit::convertQPixmapToShareableBitmap):
(WebKit::WebDragClient::startDrag):
* WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp:
(WebKit::LayerTreeCoordinator::adoptImageBackingStore):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@130636 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/platform/graphics/qt/ImageQt.cpp b/Source/WebCore/platform/graphics/qt/ImageQt.cpp
index 5be31ce..fc01c40 100644
--- a/Source/WebCore/platform/graphics/qt/ImageQt.cpp
+++ b/Source/WebCore/platform/graphics/qt/ImageQt.cpp
@@ -37,7 +37,6 @@
 #include "FloatRect.h"
 #include "GraphicsContext.h"
 #include "ImageObserver.h"
-#include "NativeImageQt.h"
 #include "ShadowBlur.h"
 #include "StillImageQt.h"
 #include <wtf/text/WTFString.h>
@@ -56,7 +55,7 @@
 Q_GUI_EXPORT QPixmap qt_pixmapFromWinHBITMAP(HBITMAP, int hbitmapFormat = 0);
 #endif
 
-typedef QHash<QByteArray, QImage> WebGraphicHash;
+typedef QHash<QByteArray, QPixmap> WebGraphicHash;
 Q_GLOBAL_STATIC(WebGraphicHash, _graphics)
 
 static void earlyClearGraphics()
@@ -70,28 +69,28 @@
 
     if (hash->isEmpty()) {
 
-        // prevent ~QImage running after ~QApplication (leaks native images)
+        // prevent ~QPixmap running after ~QApplication (leaks native pixmaps)
         qAddPostRoutine(earlyClearGraphics);
 
         // QWebSettings::MissingImageGraphic
-        hash->insert("missingImage", QImage(QLatin1String(":webkit/resources/missingImage.png")));
+        hash->insert("missingImage", QPixmap(QLatin1String(":webkit/resources/missingImage.png")));
         // QWebSettings::MissingPluginGraphic
-        hash->insert("nullPlugin", QImage(QLatin1String(":webkit/resources/nullPlugin.png")));
+        hash->insert("nullPlugin", QPixmap(QLatin1String(":webkit/resources/nullPlugin.png")));
         // QWebSettings::DefaultFrameIconGraphic
-        hash->insert("urlIcon", QImage(QLatin1String(":webkit/resources/urlIcon.png")));
+        hash->insert("urlIcon", QPixmap(QLatin1String(":webkit/resources/urlIcon.png")));
         // QWebSettings::TextAreaSizeGripCornerGraphic
-        hash->insert("textAreaResizeCorner", QImage(QLatin1String(":webkit/resources/textAreaResizeCorner.png")));
+        hash->insert("textAreaResizeCorner", QPixmap(QLatin1String(":webkit/resources/textAreaResizeCorner.png")));
         // QWebSettings::DeleteButtonGraphic
-        hash->insert("deleteButton", QImage(QLatin1String(":webkit/resources/deleteButton.png")));
+        hash->insert("deleteButton", QPixmap(QLatin1String(":webkit/resources/deleteButton.png")));
         // QWebSettings::InputSpeechButtonGraphic
-        hash->insert("inputSpeech", QImage(QLatin1String(":webkit/resources/inputSpeech.png")));
+        hash->insert("inputSpeech", QPixmap(QLatin1String(":webkit/resources/inputSpeech.png")));
     }
 
     return hash;
 }
 
 // This function loads resources into WebKit
-static QImage loadResourceImage(const char *name)
+static QPixmap loadResourcePixmap(const char *name)
 {
     return graphics()->value(name);
 }
@@ -118,23 +117,23 @@
 
 PassRefPtr<Image> Image::loadPlatformResource(const char* name)
 {
-    return StillImage::create(loadResourceImage(name));
+    return StillImage::create(loadResourcePixmap(name));
 }
 
-void Image::setPlatformResource(const char* name, const QImage& image)
+void Image::setPlatformResource(const char* name, const QPixmap& pixmap)
 {
     WebGraphicHash* h = graphics();
-    if (image.isNull())
+    if (pixmap.isNull())
         h->remove(name);
     else
-        h->insert(name, image);
+        h->insert(name, pixmap);
 }
 
 void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
                         const FloatPoint& phase, ColorSpace, CompositeOperator op, const FloatRect& destRect)
 {
-    QImage* frameImage = nativeImageForCurrentFrame();
-    if (!frameImage) // If it's too early we won't have an image yet.
+    QPixmap* framePixmap = nativeImageForCurrentFrame();
+    if (!framePixmap) // If it's too early we won't have an image yet.
         return;
 
 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
@@ -149,38 +148,34 @@
     if (!dr.width() || !dr.height() || !tr.width() || !tr.height())
         return;
 
-    QImage image = *frameImage;
-    if (tr.x() || tr.y() || tr.width() != image.width() || tr.height() != image.height())
-        image = image.copy(tr);
+    QPixmap pixmap = *framePixmap;
+    if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height())
+        pixmap = pixmap.copy(tr);
 
     CompositeOperator previousOperator = ctxt->compositeOperation();
 
-    ctxt->setCompositeOperation(!image.hasAlphaChannel() && op == CompositeSourceOver ? CompositeCopy : op);
+    ctxt->setCompositeOperation(!pixmap.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
 
     QPainter* p = ctxt->platformContext();
     QTransform transform(patternTransform);
 
-    // If this would draw more than one scaled tile, we scale the image first and then use the result to draw.
+    // If this would draw more than one scaled tile, we scale the pixmap first and then use the result to draw.
     if (transform.type() == QTransform::TxScale) {
         QRectF tileRectInTargetCoords = (transform * QTransform().translate(phase.x(), phase.y())).mapRect(tr);
 
         bool tileWillBePaintedOnlyOnce = tileRectInTargetCoords.contains(dr);
         if (!tileWillBePaintedOnlyOnce) {
-            QSizeF scaledSize(float(image.width()) * transform.m11(), float(image.height()) * transform.m22());
-            QImage scaledImage;
-            if (image.hasAlphaChannel()) {
-                scaledImage = QImage(scaledSize.toSize(), NativeImageQt::defaultFormatForAlphaEnabledImages());
-                scaledImage.fill(Qt::transparent);
-            } else
-                scaledImage = QImage(scaledSize.toSize(), NativeImageQt::defaultFormatForOpaqueImages());
-
+            QSizeF scaledSize(float(pixmap.width()) * transform.m11(), float(pixmap.height()) * transform.m22());
+            QPixmap scaledPixmap(scaledSize.toSize());
+            if (pixmap.hasAlpha())
+                scaledPixmap.fill(Qt::transparent);
             {
-                QPainter painter(&scaledImage);
+                QPainter painter(&scaledPixmap);
                 painter.setCompositionMode(QPainter::CompositionMode_Source);
                 painter.setRenderHints(p->renderHints());
-                painter.drawImage(QRect(0, 0, scaledImage.width(), scaledImage.height()), image);
+                painter.drawPixmap(QRect(0, 0, scaledPixmap.width(), scaledPixmap.height()), pixmap);
             }
-            image = scaledImage;
+            pixmap = scaledPixmap;
             transform = QTransform::fromTranslate(transform.dx(), transform.dy());
         }
     }
@@ -189,7 +184,7 @@
     transform *= QTransform().translate(phase.x(), phase.y());
     transform.translate(tr.x(), tr.y());
 
-    QBrush b(image);
+    QBrush b(pixmap);
     b.setTransform(transform);
     p->fillRect(dr, b);
 
@@ -199,7 +194,7 @@
         imageObserver()->didDraw(this);
 }
 
-BitmapImage::BitmapImage(QImage* image, ImageObserver* observer)
+BitmapImage::BitmapImage(QPixmap* pixmap, ImageObserver* observer)
     : Image(observer)
     , m_currentFrame(0)
     , m_frames(0)
@@ -217,14 +212,14 @@
     , m_sizeAvailable(true)
     , m_haveFrameCount(true)
 {
-    int width = image->width();
-    int height = image->height();
+    int width = pixmap->width();
+    int height = pixmap->height();
     m_decodedSize = width * height * 4;
     m_size = IntSize(width, height);
 
     m_frames.grow(1);
-    m_frames[0].m_frame = image;
-    m_frames[0].m_hasAlpha = image->hasAlphaChannel();
+    m_frames[0].m_frame = pixmap;
+    m_frames[0].m_hasAlpha = pixmap->hasAlpha();
     m_frames[0].m_haveMetadata = true;
     checkForSolidColor();
 }
@@ -245,8 +240,7 @@
     if (normalizedSrc.isEmpty() || normalizedDst.isEmpty())
         return;
 
-    QImage* image = nativeImageForCurrentFrame();
-
+    QPixmap* image = nativeImageForCurrentFrame();
     if (!image)
         return;
 
@@ -260,19 +254,19 @@
 #endif
 
     CompositeOperator previousOperator = ctxt->compositeOperation();
-    ctxt->setCompositeOperation(!image->hasAlphaChannel() && op == CompositeSourceOver ? CompositeCopy : op);
+    ctxt->setCompositeOperation(!image->hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
 
     if (ctxt->hasShadow()) {
         ShadowBlur* shadow = ctxt->shadowBlur();
         GraphicsContext* shadowContext = shadow->beginShadowLayer(ctxt, normalizedDst);
         if (shadowContext) {
             QPainter* shadowPainter = shadowContext->platformContext();
-            shadowPainter->drawImage(normalizedDst, *image, normalizedSrc);
+            shadowPainter->drawPixmap(normalizedDst, *image, normalizedSrc);
             shadow->endShadowLayer(ctxt);
         }
     }
 
-    ctxt->platformContext()->drawImage(normalizedDst, *image, normalizedSrc);
+    ctxt->platformContext()->drawPixmap(normalizedDst, *image, normalizedSrc);
 
     ctxt->setCompositeOperation(previousOperator);
 
@@ -288,20 +282,20 @@
     if (frameCount() > 1)
         return;
 
-    QImage* frameImage = frameAtIndex(0);
-    if (!frameImage || frameImage->width() != 1 || frameImage->height() != 1)
+    QPixmap* framePixmap = frameAtIndex(0);
+    if (!framePixmap || framePixmap->width() != 1 || framePixmap->height() != 1)
         return;
 
     m_isSolidColor = true;
-    m_solidColor = QColor::fromRgba(frameImage->pixel(0, 0));
+    m_solidColor = QColor::fromRgba(framePixmap->toImage().pixel(0, 0));
 }
 
 #if OS(WINDOWS)
 PassRefPtr<BitmapImage> BitmapImage::create(HBITMAP hBitmap)
 {
-    QImage* nativeImage = new QImage(qt_pixmapFromWinHBITMAP(hBitmap).toImage());
+    QPixmap* qPixmap = new QPixmap(qt_pixmapFromWinHBITMAP(hBitmap));
 
-    return BitmapImage::create(nativeImage);
+    return BitmapImage::create(qPixmap);
 }
 #endif