Title: [153790] trunk/Source/WebCore
Revision
153790
Author
[email protected]
Date
2013-08-07 09:34:17 -0700 (Wed, 07 Aug 2013)

Log Message

[Qt] REGRESSION(r) Two pixel result fail after r153522
https://bugs.webkit.org/show_bug.cgi?id=119392

Reviewed by Jocelyn Turcotte.

Consider scaling transform on the painter to determine final destination size.

Covered by existing tests.

* platform/graphics/qt/ImageQt.cpp:
(WebCore::prescaleImageIfRequired):
(WebCore::BitmapImage::draw):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (153789 => 153790)


--- trunk/Source/WebCore/ChangeLog	2013-08-07 16:17:33 UTC (rev 153789)
+++ trunk/Source/WebCore/ChangeLog	2013-08-07 16:34:17 UTC (rev 153790)
@@ -1,3 +1,18 @@
+2013-08-07  Allan Sandfeld Jensen  <[email protected]>
+
+        [Qt] REGRESSION(r) Two pixel result fail after r153522
+        https://bugs.webkit.org/show_bug.cgi?id=119392
+
+        Reviewed by Jocelyn Turcotte.
+
+        Consider scaling transform on the painter to determine final destination size.
+
+        Covered by existing tests.
+
+        * platform/graphics/qt/ImageQt.cpp:
+        (WebCore::prescaleImageIfRequired):
+        (WebCore::BitmapImage::draw):
+
 2013-08-07  Antti Koivisto  <[email protected]>
 
         2.5% regression on page cycler moz

Modified: trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp (153789 => 153790)


--- trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp	2013-08-07 16:17:33 UTC (rev 153789)
+++ trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp	2013-08-07 16:34:17 UTC (rev 153790)
@@ -42,7 +42,6 @@
 #include <wtf/text/WTFString.h>
 
 #include <QCoreApplication>
-#include <QDebug>
 #include <QImage>
 #include <QImageReader>
 #include <QPainter>
@@ -232,6 +231,49 @@
 {
 }
 
+QPixmap* prescaleImageIfRequired(QPainter* painter, QPixmap* image, QPixmap* buffer, const QRectF& destRect, QRectF* srcRect)
+{
+    // The quality of down scaling at 0.5x and below in QPainter is not very good
+    // due to using bilinear sampling, so for high quality scaling we need to
+    // perform scaling ourselves.
+    ASSERT(image);
+    ASSERT(painter);
+    if (!(painter->renderHints() & QPainter::SmoothPixmapTransform))
+        return image;
+
+    QTransform transform = painter->combinedTransform();
+
+    // Prescaling transforms that does more than scale or translate is not supported.
+    if (transform.type() > QTransform::TxScale)
+        return image;
+
+    QRectF transformedDst = transform.mapRect(destRect);
+    // Only prescale if downscaling to 0.5x or less
+    if (transformedDst.width() * 2 > srcRect->width() && transformedDst.height() * 2 > srcRect->height())
+        return image;
+
+    // This may not work right with subpixel positions, but that can not currently happen.
+    QRect pixelSrc = srcRect->toRect();
+    QSize scaledSize = transformedDst.size().toSize();
+
+    QString key = QStringLiteral("qtwebkit_prescaled_")
+        % HexString<qint64>(image->cacheKey())
+        % HexString<int>(pixelSrc.x()) % HexString<int>(pixelSrc.y())
+        % HexString<int>(pixelSrc.width()) % HexString<int>(pixelSrc.height())
+        % HexString<int>(scaledSize.width()) % HexString<int>(scaledSize.height());
+
+    if (!QPixmapCache::find(key, buffer)) {
+        if (pixelSrc != image->rect())
+            *buffer = image->copy(pixelSrc).scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+        else
+            *buffer = image->scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+        QPixmapCache::insert(key, *buffer);
+    }
+
+    *srcRect = QRectF(QPointF(), buffer->size());
+    return buffer;
+}
+
 // Drawing Routines
 void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
     const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op, BlendMode)
@@ -247,7 +289,6 @@
     QPixmap* image = nativeImageForCurrentFrame();
     if (!image)
         return;
-    QPixmap prescaled;
 
     if (mayFillWithSolidColor()) {
         fillWithSolidColor(ctxt, normalizedDst, solidColor(), styleColorSpace, op);
@@ -258,36 +299,8 @@
     normalizedSrc = adjustSourceRectForDownSampling(normalizedSrc, image->size());
 #endif
 
-    QPainter* painter = ctxt->platformContext();
-    // The quality of down scaling at 0.5x and below in QPainter is not very good
-    // due only using bilinear sampling, so for high quality scaling we need to
-    // perform scaling ourselves.
-#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
-    const float pixelRatio = painter->device()->devicePixelRatio();
-#else
-    const float pixelRatio = 1;
-#endif
-    if (painter->renderHints() & QPainter::SmoothPixmapTransform
-        && (normalizedDst.width() * 2 * pixelRatio < normalizedSrc.width()
-            || normalizedDst.height() * 2 * pixelRatio < normalizedSrc.height())) {
-        // This may not work right with subpixel positions, but that can not currently happen.
-        QRect pixelSrc = normalizedSrc.toRect();
-        QSize scaledSize(normalizedDst.width() * pixelRatio, normalizedDst.height() * pixelRatio);
-        QString key = QStringLiteral("qtwebkit_prescaled_")
-            % HexString<qint64>(image->cacheKey())
-            % HexString<int>(pixelSrc.x()) % HexString<int>(pixelSrc.y())
-            % HexString<int>(pixelSrc.width()) % HexString<int>(pixelSrc.height())
-            % HexString<int>(scaledSize.width()) % HexString<int>(scaledSize.height());
-        if (!QPixmapCache::find(key, &prescaled)) {
-            if (pixelSrc != image->rect())
-                prescaled = image->copy(pixelSrc).scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
-            else
-                prescaled = image->scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
-            QPixmapCache::insert(key, prescaled);
-        }
-        normalizedSrc = QRectF(QPointF(), prescaled.size());
-        image = &prescaled;
-    }
+    QPixmap prescaledBuffer;
+    image = prescaleImageIfRequired(ctxt->platformContext(), image, &prescaledBuffer, normalizedDst, &normalizedSrc);
 
     CompositeOperator previousOperator = ctxt->compositeOperation();
     ctxt->setCompositeOperation(!image->hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to