Changeset 153790 in webkit
- Timestamp:
- Aug 7, 2013 9:34:17 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r153788 r153790 1 2013-08-07 Allan Sandfeld Jensen <allan.jensen@digia.com> 2 3 [Qt] REGRESSION(r) Two pixel result fail after r153522 4 https://bugs.webkit.org/show_bug.cgi?id=119392 5 6 Reviewed by Jocelyn Turcotte. 7 8 Consider scaling transform on the painter to determine final destination size. 9 10 Covered by existing tests. 11 12 * platform/graphics/qt/ImageQt.cpp: 13 (WebCore::prescaleImageIfRequired): 14 (WebCore::BitmapImage::draw): 15 1 16 2013-08-07 Antti Koivisto <antti@apple.com> 2 17 -
trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp
r153522 r153790 43 43 44 44 #include <QCoreApplication> 45 #include <QDebug>46 45 #include <QImage> 47 46 #include <QImageReader> … … 233 232 } 234 233 234 QPixmap* prescaleImageIfRequired(QPainter* painter, QPixmap* image, QPixmap* buffer, const QRectF& destRect, QRectF* srcRect) 235 { 236 // The quality of down scaling at 0.5x and below in QPainter is not very good 237 // due to using bilinear sampling, so for high quality scaling we need to 238 // perform scaling ourselves. 239 ASSERT(image); 240 ASSERT(painter); 241 if (!(painter->renderHints() & QPainter::SmoothPixmapTransform)) 242 return image; 243 244 QTransform transform = painter->combinedTransform(); 245 246 // Prescaling transforms that does more than scale or translate is not supported. 247 if (transform.type() > QTransform::TxScale) 248 return image; 249 250 QRectF transformedDst = transform.mapRect(destRect); 251 // Only prescale if downscaling to 0.5x or less 252 if (transformedDst.width() * 2 > srcRect->width() && transformedDst.height() * 2 > srcRect->height()) 253 return image; 254 255 // This may not work right with subpixel positions, but that can not currently happen. 256 QRect pixelSrc = srcRect->toRect(); 257 QSize scaledSize = transformedDst.size().toSize(); 258 259 QString key = QStringLiteral("qtwebkit_prescaled_") 260 % HexString<qint64>(image->cacheKey()) 261 % HexString<int>(pixelSrc.x()) % HexString<int>(pixelSrc.y()) 262 % HexString<int>(pixelSrc.width()) % HexString<int>(pixelSrc.height()) 263 % HexString<int>(scaledSize.width()) % HexString<int>(scaledSize.height()); 264 265 if (!QPixmapCache::find(key, buffer)) { 266 if (pixelSrc != image->rect()) 267 *buffer = image->copy(pixelSrc).scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 268 else 269 *buffer = image->scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 270 QPixmapCache::insert(key, *buffer); 271 } 272 273 *srcRect = QRectF(QPointF(), buffer->size()); 274 return buffer; 275 } 276 235 277 // Drawing Routines 236 278 void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst, … … 248 290 if (!image) 249 291 return; 250 QPixmap prescaled;251 292 252 293 if (mayFillWithSolidColor()) { … … 259 300 #endif 260 301 261 QPainter* painter = ctxt->platformContext(); 262 // The quality of down scaling at 0.5x and below in QPainter is not very good 263 // due only using bilinear sampling, so for high quality scaling we need to 264 // perform scaling ourselves. 265 #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) 266 const float pixelRatio = painter->device()->devicePixelRatio(); 267 #else 268 const float pixelRatio = 1; 269 #endif 270 if (painter->renderHints() & QPainter::SmoothPixmapTransform 271 && (normalizedDst.width() * 2 * pixelRatio < normalizedSrc.width() 272 || normalizedDst.height() * 2 * pixelRatio < normalizedSrc.height())) { 273 // This may not work right with subpixel positions, but that can not currently happen. 274 QRect pixelSrc = normalizedSrc.toRect(); 275 QSize scaledSize(normalizedDst.width() * pixelRatio, normalizedDst.height() * pixelRatio); 276 QString key = QStringLiteral("qtwebkit_prescaled_") 277 % HexString<qint64>(image->cacheKey()) 278 % HexString<int>(pixelSrc.x()) % HexString<int>(pixelSrc.y()) 279 % HexString<int>(pixelSrc.width()) % HexString<int>(pixelSrc.height()) 280 % HexString<int>(scaledSize.width()) % HexString<int>(scaledSize.height()); 281 if (!QPixmapCache::find(key, &prescaled)) { 282 if (pixelSrc != image->rect()) 283 prescaled = image->copy(pixelSrc).scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 284 else 285 prescaled = image->scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 286 QPixmapCache::insert(key, prescaled); 287 } 288 normalizedSrc = QRectF(QPointF(), prescaled.size()); 289 image = &prescaled; 290 } 302 QPixmap prescaledBuffer; 303 image = prescaleImageIfRequired(ctxt->platformContext(), image, &prescaledBuffer, normalizedDst, &normalizedSrc); 291 304 292 305 CompositeOperator previousOperator = ctxt->compositeOperation();
Note: See TracChangeset
for help on using the changeset viewer.