Changeset 249414 in webkit


Ignore:
Timestamp:
Sep 2, 2019 2:37:06 PM (5 years ago)
Author:
Brent Fulgham
Message:

[FTW] NativeImagePtr is drawn with invalid scaling
https://bugs.webkit.org/show_bug.cgi?id=201391

Reviewed by Don Olmstead.

The current implementation of FTW improperly applies scaling factors to native images,
resulting in blocky images (in some cases).

This patch corrects the handling of native images, corrects a bug in bitmap render
context scaling, and retrieves more data from the ImageDecoder's metadata system.

  • platform/graphics/win/Direct2DUtilities.cpp:

(WebCore::Direct2D::createBitmapRenderTargetOfSize): Supply an appropriately sized
pixel dimension for non-unity scale factors.

  • platform/graphics/win/ImageBufferDirect2D.cpp:

(WebCore::ImageBuffer::ImageBuffer): Include the scale factor when creating a
bitmap render target.

  • platform/graphics/win/ImageDecoderDirect2D.cpp:

(WebCore::ImageDecoderDirect2D::frameOrientationAtIndex const): Read the orientation
data form the image metadata.
(WebCore::ImageDecoderDirect2D::frameAllowSubsamplingAtIndex const): Always return
true, to match the CG implementation.
(WebCore::ImageDecoderDirect2D::frameHasAlphaAtIndex const): Correct to match the
behavior of CG.

  • platform/graphics/win/NativeImageDirect2D.cpp:

(WebCore::drawNativeImage): Pass through the Direct2DOperations helper method, which
handles scaling and subsampling properly.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r249378 r249414  
     12019-09-02  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [FTW] NativeImagePtr is drawn with invalid scaling
     4        https://bugs.webkit.org/show_bug.cgi?id=201391
     5
     6        Reviewed by Don Olmstead.
     7
     8        The current implementation of FTW improperly applies scaling factors to native images,
     9        resulting in blocky images (in some cases).
     10
     11        This patch corrects the handling of native images, corrects a bug in bitmap render
     12        context scaling, and retrieves more data from the ImageDecoder's metadata system.
     13
     14        * platform/graphics/win/Direct2DUtilities.cpp:
     15        (WebCore::Direct2D::createBitmapRenderTargetOfSize): Supply an appropriately sized
     16        pixel dimension for non-unity scale factors.
     17        * platform/graphics/win/ImageBufferDirect2D.cpp:
     18        (WebCore::ImageBuffer::ImageBuffer): Include the scale factor when creating a
     19        bitmap render target.
     20        * platform/graphics/win/ImageDecoderDirect2D.cpp:
     21        (WebCore::ImageDecoderDirect2D::frameOrientationAtIndex const): Read the orientation
     22        data form the image metadata.
     23        (WebCore::ImageDecoderDirect2D::frameAllowSubsamplingAtIndex const): Always return
     24        true, to match the CG implementation.
     25        (WebCore::ImageDecoderDirect2D::frameHasAlphaAtIndex const): Correct to match the
     26        behavior of CG.
     27        * platform/graphics/win/NativeImageDirect2D.cpp:
     28        (WebCore::drawNativeImage): Pass through the Direct2DOperations helper method, which
     29        handles scaling and subsampling properly.
     30
    1312019-09-02  Youenn Fablet  <youenn@apple.com>
    232
  • trunk/Source/WebCore/platform/graphics/win/Direct2DUtilities.cpp

    r249335 r249414  
    225225    COMPtr<ID2D1BitmapRenderTarget> bitmapContext;
    226226    auto desiredSize = D2D1::SizeF(size.width(), size.height());
    227     D2D1_SIZE_U pixelSize = size;
     227    D2D1_SIZE_U pixelSize = D2D1::SizeU(clampTo<unsigned>(deviceScaleFactor * size.width()), clampTo<unsigned>(deviceScaleFactor * size.height()));
    228228    HRESULT hr = renderTarget->CreateCompatibleRenderTarget(&desiredSize, &pixelSize, nullptr, D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_GDI_COMPATIBLE, &bitmapContext);
    229229    if (!SUCCEEDED(hr))
  • trunk/Source/WebCore/platform/graphics/win/ImageBufferDirect2D.cpp

    r249371 r249414  
    108108        renderTarget = GraphicsContext::defaultRenderTarget();
    109109
    110     D2D1_SIZE_F desiredSize = FloatSize(m_logicalSize);
    111     D2D1_SIZE_U pixelSize = IntSize(m_logicalSize);
    112 
    113     auto bitmapContext = Direct2D::createBitmapRenderTargetOfSize(m_logicalSize, renderTarget);
     110    auto bitmapContext = Direct2D::createBitmapRenderTargetOfSize(m_logicalSize, renderTarget, m_resolutionScale);
    114111    if (!bitmapContext)
    115112        return;
  • trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.cpp

    r249110 r249414  
    172172        return ImageOrientation::None;
    173173
    174     // FIXME: Identify image type, and ask proper orientation.
     174    PROPVARIANT value;
     175    PropVariantInit(&value);
     176    hr = metadata->GetMetadataByName(L"System.Photo.Orientation", &value);
     177    if (SUCCEEDED(hr))
     178        return ImageOrientation(static_cast<ImageOrientation::Orientation>(value.uiVal));
     179
    175180    return ImageOrientation::None;
    176181}
     
    193198bool ImageDecoderDirect2D::frameAllowSubsamplingAtIndex(size_t index) const
    194199{
    195     if (!m_nativeDecoder)
    196         return false;
    197 
    198     COMPtr<IWICBitmapFrameDecode> frame;
    199     HRESULT hr = m_nativeDecoder->GetFrame(index, &frame);
    200     if (!SUCCEEDED(hr))
    201         return false;
    202 
    203     // FIXME: Figure out correct image format-specific query for subsampling check.
    204     notImplemented();
    205200    return true;
    206201}
     
    216211        return false;
    217212
    218     // FIXME: Figure out correct image format-specific query for alpha check.
    219     notImplemented();
     213    COMPtr<IWICMetadataQueryReader> metadata;
     214    hr = frame->GetMetadataQueryReader(&metadata);
     215    if (!SUCCEEDED(hr))
     216        return false;
     217
     218    GUID containerFormat;
     219    hr = metadata->GetContainerFormat(&containerFormat);
     220    if (!SUCCEEDED(hr))
     221        return false;
     222
     223    if (::IsEqualGUID(GUID_ContainerFormatJpeg, containerFormat))
     224        return false;
     225
    220226    return true;
    221227}
  • trunk/Source/WebCore/platform/graphics/win/NativeImageDirect2D.cpp

    r249217 r249414  
    2828
    2929#include "Color.h"
     30#include "Direct2DOperations.h"
    3031#include "FloatRect.h"
    3132#include "GeometryUtilities.h"
     
    7980}
    8081
    81 void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& srcSize, const ImagePaintingOptions&)
     82void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& srcSize, const ImagePaintingOptions& options)
    8283{
    83     auto platformContext = context.platformContext();
     84    auto* platformContext = context.platformContext();
    8485
    8586    // Subsampling may have given us an image that is smaller than size().
     
    9192        adjustedSrcRect = mapRect(srcRect, FloatRect({ }, srcSize), FloatRect({ }, subsampledImageSize));
    9293
    93     float opacity = 1.0f;
    94 
    95     platformContext->renderTarget()->DrawBitmap(image.get(), destRect, opacity, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, adjustedSrcRect);
     94    auto& state = context.state();
     95    Direct2D::drawNativeImage(*platformContext, image.get(), subsampledImageSize, destRect, adjustedSrcRect, options, state.alpha, Direct2D::ShadowState(state));
    9696}
    9797
Note: See TracChangeset for help on using the changeset viewer.