Changeset 161577 in webkit


Ignore:
Timestamp:
Jan 9, 2014 1:21:53 PM (10 years ago)
Author:
BJ Burg
Message:

REGRESSION (r160152): Selection drag snapshot doesn't appear or has the wrong content on Retina
https://bugs.webkit.org/show_bug.cgi?id=125375

Reviewed by Darin Adler.

Source/WebCore:

Move scaling of drag images by the device scale factor out of DragClient
and into WebCore. This removes several redundant copies and scaling operations.

Fix scaling bugs that were cancelled out by over-allocating the backing store.

  • page/DragController.cpp:

(WebCore::DragController::startDrag): Scale the drag image for a link
according to the device scale factor before giving it to the OS.

(WebCore::DragController::doImageDrag): Scale the drag image for an image
according to the device scale factor before giving it to the OS.

  • page/FrameSnapshotting.cpp:

(WebCore::snapshotFrameRect): Don't pre-scale or clip the snapshot. The
ImageBuffer does this already.

  • platform/DragImage.cpp:

(WebCore::createDragImageFromSnapshot): Don't scale the backing store
when copying an ImageBuffer into an Image.

  • platform/graphics/cg/ImageBufferCG.cpp:

(WebCore::ImageBuffer::copyImage): Draw the image in user-space coordinates,
not in backing-store coordinates. Remove unnecessary assertions. Crop the
buffer before drawing the image into it.

Source/WebKit2:

Remove scaling from WebDragClient because it is now selectively
performed by WebCore according to the drag image source.

  • WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:

(WebKit::WebDragClient::startDrag): Don't scale the provided drag image.

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r161573 r161577  
     12014-01-09  Brian Burg  <bburg@apple.com>
     2
     3        REGRESSION (r160152): Selection drag snapshot doesn't appear or has the wrong content on Retina
     4        https://bugs.webkit.org/show_bug.cgi?id=125375
     5
     6        Reviewed by Darin Adler.
     7
     8        Move scaling of drag images by the device scale factor out of DragClient
     9        and into WebCore. This removes several redundant copies and scaling operations.
     10
     11        Fix scaling bugs that were cancelled out by over-allocating the backing store.
     12
     13        * page/DragController.cpp:
     14        (WebCore::DragController::startDrag): Scale the drag image for a link
     15        according to the device scale factor before giving it to the OS.
     16
     17        (WebCore::DragController::doImageDrag): Scale the drag image for an image
     18        according to the device scale factor before giving it to the OS.
     19
     20        * page/FrameSnapshotting.cpp:
     21        (WebCore::snapshotFrameRect): Don't pre-scale or clip the snapshot. The
     22        ImageBuffer does this already.
     23
     24        * platform/DragImage.cpp:
     25        (WebCore::createDragImageFromSnapshot): Don't scale the backing store
     26        when copying an ImageBuffer into an Image.
     27
     28        * platform/graphics/cg/ImageBufferCG.cpp:
     29        (WebCore::ImageBuffer::copyImage): Draw the image in user-space coordinates,
     30        not in backing-store coordinates. Remove unnecessary assertions. Crop the
     31        buffer before drawing the image into it.
     32
    1332014-01-09  Myles C. Maxfield  <mmaxfield@apple.com>
    234
  • trunk/Source/WebCore/page/DragController.cpp

    r161537 r161577  
    829829            m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset);
    830830            dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y());
     831            // Later code expects the drag image to be scaled by device's scale factor.
     832            dragImage = scaleDragImage(dragImage, FloatSize(m_page.deviceScaleFactor(), m_page.deviceScaleFactor()));
    831833        }
    832834        doSystemDrag(dragImage, dragLoc, mouseDraggedPoint, clipboard, src, true);
     
    870872        IntSize fittedSize = dragImageSize(dragImage);
    871873
     874        dragImage = scaleDragImage(dragImage, FloatSize(m_page.deviceScaleFactor(), m_page.deviceScaleFactor()));
    872875        dragImage = dissolveDragImageToFraction(dragImage, DragImageAlpha);
    873876
  • trunk/Source/WebCore/page/FrameSnapshotting.cpp

    r160152 r161577  
    9191    frame.view()->setPaintBehavior(paintBehavior);
    9292
    93     float deviceScaleFactor = frame.page()->deviceScaleFactor();
    94     IntRect usedRect(imageRect);
    95     usedRect.scale(deviceScaleFactor);
    96 
    97     std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(usedRect.size(), deviceScaleFactor, ColorSpaceDeviceRGB);
     93    std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(imageRect.size(), frame.page()->deviceScaleFactor(), ColorSpaceDeviceRGB);
    9894    if (!buffer)
    9995        return nullptr;
    100     buffer->context()->translate(-usedRect.x(), -usedRect.y());
    101     buffer->context()->clip(FloatRect(0, 0, usedRect.maxX(), usedRect.maxY()));
     96    buffer->context()->translate(-imageRect.x(), -imageRect.y());
    10297
    103     frame.view()->paintContentsForSnapshot(buffer->context(), usedRect, shouldIncludeSelection, coordinateSpace);
     98    frame.view()->paintContentsForSnapshot(buffer->context(), imageRect, shouldIncludeSelection, coordinateSpace);
    10499    return buffer;
    105100}
  • trunk/Source/WebCore/platform/DragImage.cpp

    r161537 r161577  
    109109    UNUSED_PARAM(node);
    110110#endif
    111     RefPtr<Image> image = snapshot->copyImage(ImageBuffer::fastCopyImageMode());
     111    RefPtr<Image> image = snapshot->copyImage(ImageBuffer::fastCopyImageMode(), Unscaled);
    112112    if (!image)
    113113        return nullptr;
  • trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp

    r161001 r161577  
    213213{
    214214    RetainPtr<CGImageRef> image;
    215     if (m_resolutionScale == 1 || scaleBehavior == Unscaled)
     215    if (m_resolutionScale == 1 || scaleBehavior == Unscaled) {
    216216        image = copyNativeImage(copyBehavior);
    217     else {
     217        image = createCroppedImageIfNecessary(image.get(), internalSize());
     218    } else {
    218219        image = copyNativeImage(DontCopyBackingStore);
    219220        RetainPtr<CGContextRef> context = adoptCF(CGBitmapContextCreate(0, logicalSize().width(), logicalSize().height(), 8, 4 * logicalSize().width(), deviceRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast));
    220221        CGContextSetBlendMode(context.get(), kCGBlendModeCopy);
    221         CGContextDrawImage(context.get(), CGRectMake(0, 0, m_data.m_backingStoreSize.width(), m_data.m_backingStoreSize.height()), image.get());
     222        CGContextClipToRect(context.get(), FloatRect(FloatPoint::zero(), logicalSize()));
     223        FloatSize imageSizeInUserSpace = scaleSizeToUserSpace(logicalSize(), m_data.m_backingStoreSize, internalSize());
     224        CGContextDrawImage(context.get(), FloatRect(FloatPoint::zero(), imageSizeInUserSpace), image.get());
    222225        image = adoptCF(CGBitmapContextCreateImage(context.get()));
    223226    }
    224    
    225     image = createCroppedImageIfNecessary(image.get(), internalSize());
    226227
    227228    if (!image)
    228         return 0;
    229 
    230     ASSERT(CGImageGetWidth(image.get()) == static_cast<size_t>(m_logicalSize.width()));
    231     ASSERT(CGImageGetHeight(image.get()) == static_cast<size_t>(m_logicalSize.height()));
     229        return nullptr;
    232230
    233231    RefPtr<BitmapImage> bitmapImage = BitmapImage::create(image.get());
     
    481479        CGContextSetBlendMode(context.get(), kCGBlendModeCopy);
    482480        CGContextClipToRect(context.get(), CGRectMake(0, 0, logicalSize().width(), logicalSize().height()));
    483         FloatSize imageRectInUserBounds = scaleSizeToUserSpace(logicalSize(), m_data.m_backingStoreSize, internalSize());
    484         CGContextDrawImage(context.get(), CGRectMake(0, 0, imageRectInUserBounds.width(), imageRectInUserBounds.height()), image.get());
     481        FloatSize imageSizeInUserSpace = scaleSizeToUserSpace(logicalSize(), m_data.m_backingStoreSize, internalSize());
     482        CGContextDrawImage(context.get(), CGRectMake(0, 0, imageSizeInUserSpace.width(), imageSizeInUserSpace.height()), image.get());
    485483        image = adoptCF(CGBitmapContextCreateImage(context.get()));
    486484    }
  • trunk/Source/WebKit2/ChangeLog

    r161571 r161577  
     12014-01-09  Brian Burg  <bburg@apple.com>
     2
     3        REGRESSION (r160152): Selection drag snapshot doesn't appear or has the wrong content on Retina
     4        https://bugs.webkit.org/show_bug.cgi?id=125375
     5
     6        Reviewed by Darin Adler.
     7
     8        Remove scaling from WebDragClient because it is now selectively
     9        performed by WebCore according to the drag image source.
     10
     11        * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
     12        (WebKit::WebDragClient::startDrag): Don't scale the provided drag image.
     13
    1142014-01-09  Tim Horton  <timothy_horton@apple.com>
    215
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm

    r157058 r161577  
    8080{
    8181    IntSize bitmapSize([image.get() size]);
    82     bitmapSize.scale(frame.page()->deviceScaleFactor());
    8382    RefPtr<ShareableBitmap> bitmap = convertImageToBitmap(image.get(), bitmapSize);
    8483    ShareableBitmap::Handle handle;
Note: See TracChangeset for help on using the changeset viewer.