Skip to content
Permalink
Browse files
[FTW] Refactor Direct2D code to follow Cairo's model to support moder…
…n WebKit

https://bugs.webkit.org/show_bug.cgi?id=200270

Reviewed by Dean Jackson.

Refactor the Direct2D code in WebCore so that the core routines can be shared
between GraphicsContext and GraphicsContextImpl. Implement PlatformContext,
BackingStoreBackend, and GraphicsContextImpl for the Direct2D engine.

This patch effectively just moves code around.

* PlatformFTW.cmake:
* platform/graphics/GraphicsContext.h:
* platform/graphics/GraphicsContextImpl.h:
* platform/graphics/ImageSource.cpp:
* platform/graphics/Pattern.h:
* platform/graphics/displaylists/DisplayListRecorder.cpp:
* platform/graphics/displaylists/DisplayListRecorder.h:
* platform/graphics/win/BackingStoreBackendDirect2D.h: Added.
* platform/graphics/win/BackingStoreBackendDirect2DImpl.cpp: Added.
* platform/graphics/win/BackingStoreBackendDirect2DImpl.h: Added.
* platform/graphics/win/Direct2DOperations.cpp: Added.
* platform/graphics/win/Direct2DOperations.h: Added.
* platform/graphics/win/Direct2DUtilities.cpp: Added.
* platform/graphics/win/Direct2DUtilities.h: Added.
* platform/graphics/win/FontCascadeDirect2D.cpp:
* platform/graphics/win/GradientDirect2D.cpp:
* platform/graphics/win/GraphicsContextDirect2D.cpp:
* platform/graphics/win/GraphicsContextImplDirect2D.cpp: Added.
* platform/graphics/win/GraphicsContextImplDirect2D.h: Added.
* platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h:
* platform/graphics/win/ImageBufferDataDirect2D.h:
* platform/graphics/win/ImageBufferDirect2D.cpp:
* platform/graphics/win/NativeImageDirect2D.cpp:
* platform/graphics/win/PathDirect2D.cpp:
* platform/graphics/win/PatternDirect2D.cpp:
* platform/graphics/win/PlatformContextDirect2D.cpp: Added.
* platform/graphics/win/PlatformContextDirect2D.h: Added.
* platform/win/DragImageWin.cpp:
* svg/graphics/SVGImage.cpp:


Canonical link: https://commits.webkit.org/214068@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
brentfulgham committed Jul 30, 2019
1 parent cd8089a commit d702912f9b9951fb32b7d19bbcf67d3fdc54be7d
Showing 33 changed files with 3,046 additions and 1,139 deletions.
@@ -1,3 +1,46 @@
2019-07-30 Brent Fulgham <bfulgham@apple.com>

[FTW] Refactor Direct2D code to follow Cairo's model to support modern WebKit
https://bugs.webkit.org/show_bug.cgi?id=200270

Reviewed by Dean Jackson.

Refactor the Direct2D code in WebCore so that the core routines can be shared
between GraphicsContext and GraphicsContextImpl. Implement PlatformContext,
BackingStoreBackend, and GraphicsContextImpl for the Direct2D engine.

This patch effectively just moves code around.

* PlatformFTW.cmake:
* platform/graphics/GraphicsContext.h:
* platform/graphics/GraphicsContextImpl.h:
* platform/graphics/ImageSource.cpp:
* platform/graphics/Pattern.h:
* platform/graphics/displaylists/DisplayListRecorder.cpp:
* platform/graphics/displaylists/DisplayListRecorder.h:
* platform/graphics/win/BackingStoreBackendDirect2D.h: Added.
* platform/graphics/win/BackingStoreBackendDirect2DImpl.cpp: Added.
* platform/graphics/win/BackingStoreBackendDirect2DImpl.h: Added.
* platform/graphics/win/Direct2DOperations.cpp: Added.
* platform/graphics/win/Direct2DOperations.h: Added.
* platform/graphics/win/Direct2DUtilities.cpp: Added.
* platform/graphics/win/Direct2DUtilities.h: Added.
* platform/graphics/win/FontCascadeDirect2D.cpp:
* platform/graphics/win/GradientDirect2D.cpp:
* platform/graphics/win/GraphicsContextDirect2D.cpp:
* platform/graphics/win/GraphicsContextImplDirect2D.cpp: Added.
* platform/graphics/win/GraphicsContextImplDirect2D.h: Added.
* platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h:
* platform/graphics/win/ImageBufferDataDirect2D.h:
* platform/graphics/win/ImageBufferDirect2D.cpp:
* platform/graphics/win/NativeImageDirect2D.cpp:
* platform/graphics/win/PathDirect2D.cpp:
* platform/graphics/win/PatternDirect2D.cpp:
* platform/graphics/win/PlatformContextDirect2D.cpp: Added.
* platform/graphics/win/PlatformContextDirect2D.h: Added.
* platform/win/DragImageWin.cpp:
* svg/graphics/SVGImage.cpp:

2019-07-30 Myles C. Maxfield <mmaxfield@apple.com>

REGRESSION(r241288): Text on Yahoo Japan mobile looks too bold
@@ -45,6 +45,7 @@ list(APPEND WebCore_SOURCES

platform/graphics/GLContext.cpp
platform/graphics/GraphicsContext3DPrivate.cpp
platform/graphics/GraphicsContextImpl.cpp
platform/graphics/PlatformDisplay.cpp

platform/graphics/egl/GLContextEGL.cpp
@@ -57,9 +58,12 @@ list(APPEND WebCore_SOURCES

platform/graphics/opentype/OpenTypeUtilities.cpp

platform/graphics/win/BackingStoreBackendDirect2DImpl.cpp
platform/graphics/win/ColorDirect2D.cpp
platform/graphics/win/ComplexTextControllerDirectWrite.cpp
platform/graphics/win/DIBPixelData.cpp
platform/graphics/win/Direct2DOperations.cpp
platform/graphics/win/Direct2DUtilities.cpp
platform/graphics/win/FloatPointDirect2D.cpp
platform/graphics/win/FloatRectDirect2D.cpp
platform/graphics/win/FloatSizeDirect2D.cpp
@@ -73,6 +77,7 @@ list(APPEND WebCore_SOURCES
platform/graphics/win/GradientDirect2D.cpp
platform/graphics/win/GraphicsContext3DDirect2D.cpp
platform/graphics/win/GraphicsContextDirect2D.cpp
platform/graphics/win/GraphicsContextImplDirect2D.cpp
platform/graphics/win/GraphicsContextWin.cpp
platform/graphics/win/IconWin.cpp
platform/graphics/win/ImageBufferDataDirect2D.cpp
@@ -87,6 +92,7 @@ list(APPEND WebCore_SOURCES
platform/graphics/win/NativeImageDirect2D.cpp
platform/graphics/win/PathDirect2D.cpp
platform/graphics/win/PatternDirect2D.cpp
platform/graphics/win/PlatformContextDirect2D.cpp
platform/graphics/win/SimpleFontDataWin.cpp
platform/graphics/win/SimpleFontDataDirect2D.cpp
platform/graphics/win/TextAnalyzerHelper.cpp
@@ -149,12 +155,19 @@ list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS

page/win/FrameWin.h

platform/graphics/win/BackingStoreBackendDirect2D.h
platform/graphics/win/BackingStoreBackendDirect2DImpl.h
platform/graphics/win/DIBPixelData.h
platform/graphics/win/Direct2DOperations.h
platform/graphics/win/Direct2DUtilities.h
platform/graphics/win/FullScreenController.h
platform/graphics/win/FullScreenControllerClient.h
platform/graphics/win/GraphicsContextImplDirect2D.h
platform/graphics/win/ImageBufferDataDirect2D.h
platform/graphics/win/ImageDecoderDirect2D.h
platform/graphics/win/LocalWindowsContext.h
platform/graphics/win/MediaPlayerPrivateFullscreenWindow.h
platform/graphics/win/PlatformContextDirect2D.h
platform/graphics/win/SharedGDIObject.h

platform/win/BString.h
@@ -43,6 +43,8 @@ typedef struct _cairo_device cairo_device_t;

namespace WebCore {

class IntSize;

class GLContext {
WTF_MAKE_NONCOPYABLE(GLContext); WTF_MAKE_FAST_ALLOCATED;
public:
@@ -44,7 +44,10 @@ interface ID2D1DCRenderTarget;
interface ID2D1RenderTarget;
interface ID2D1Factory;
interface ID2D1SolidColorBrush;
typedef ID2D1RenderTarget PlatformGraphicsContext;
namespace WebCore {
class PlatformContextDirect2D;
}
typedef WebCore::PlatformContextDirect2D PlatformGraphicsContext;
#elif USE(CAIRO)
namespace WebCore {
class PlatformContextCairo;
@@ -347,10 +350,6 @@ class GraphicsContext {
WEBCORE_EXPORT void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver, BlendMode = BlendMode::Normal, ImageOrientation = ImageOrientation());
#endif

#if USE(DIRECT2D)
void drawDeviceBitmap(const COMPtr<ID2D1Bitmap>&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver, BlendMode = BlendMode::Normal, ImageOrientation = ImageOrientation());
#endif

#if USE(CG) || USE(DIRECT2D)
void applyStrokePattern();
void applyFillPattern();
@@ -619,9 +618,7 @@ class GraphicsContext {

#if USE(DIRECT2D)
void platformInit(HDC, ID2D1RenderTarget**, RECT, bool hasAlpha = false);
void platformInit(PlatformGraphicsContext*, BitmapRenderingContextType);
void drawWithoutShadow(const FloatRect& boundingRect, const WTF::Function<void(ID2D1RenderTarget*)>&);
void drawWithShadow(const FloatRect& boundingRect, const WTF::Function<void(ID2D1RenderTarget*)>&);
void platformInit(PlatformContextDirect2D*, BitmapRenderingContextType);
#endif

void savePlatformState();
@@ -71,7 +71,7 @@ class GraphicsContextImpl {
virtual ImageDrawResult drawImage(Image&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&) = 0;
virtual ImageDrawResult drawTiledImage(Image&, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions&) = 0;
virtual ImageDrawResult drawTiledImage(Image&, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions&) = 0;
#if USE(CG) || USE(CAIRO)
#if USE(CG) || USE(CAIRO) || USE(DIRECT2D)
virtual void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator, BlendMode, ImageOrientation) = 0;
#endif
virtual void drawPattern(Image&, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator, BlendMode = BlendMode::Normal) = 0;
@@ -38,6 +38,7 @@

#if USE(DIRECT2D)
#include "GraphicsContext.h"
#include "PlatformContextDirect2D.h"
#endif

namespace WebCore {
@@ -661,7 +662,7 @@ ImageOrientation ImageSource::frameOrientationAtIndex(size_t index)
void ImageSource::setTargetContext(const GraphicsContext* targetContext)
{
if (isDecoderAvailable() && targetContext)
m_decoder->setTargetContext(targetContext->platformContext());
m_decoder->setTargetContext(targetContext->platformContext()->renderTarget());
}
#endif

@@ -38,6 +38,10 @@ typedef CGPatternRef PlatformPatternPtr;
#elif USE(DIRECT2D)
interface ID2D1BitmapBrush;
typedef ID2D1BitmapBrush* PlatformPatternPtr;
namespace WebCore {
class PlatformContextDirect2D;
}
typedef WebCore::PlatformContextDirect2D PlatformGraphicsContext;
#elif USE(CAIRO)
typedef struct _cairo_pattern cairo_pattern_t;
typedef cairo_pattern_t* PlatformPatternPtr;
@@ -62,6 +66,7 @@ class Pattern final : public RefCounted<Pattern> {
#if !USE(DIRECT2D)
PlatformPatternPtr createPlatformPattern(const AffineTransform& userSpaceTransformation) const;
#else
PlatformPatternPtr createPlatformPattern(PlatformGraphicsContext&, float alpha, const AffineTransform& userSpaceTransformation) const;
PlatformPatternPtr createPlatformPattern(const GraphicsContext&, float alpha, const AffineTransform& userSpaceTransformation) const;
#endif
void setPatternSpaceTransform(const AffineTransform& patternSpaceTransformation);
@@ -486,7 +486,7 @@ static TextStream& operator<<(TextStream& ts, const DrawTiledScaledImage& item)
return ts;
}

#if USE(CG) || USE(CAIRO)
#if USE(CG) || USE(CAIRO) || USE(DIRECT2D)
DrawNativeImage::DrawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, ImageOrientation orientation)
: DrawingItem(ItemType::DrawNativeImage)
#if USE(CG)
@@ -70,7 +70,7 @@ enum class ItemType {
DrawImage,
DrawTiledImage,
DrawTiledScaledImage,
#if USE(CG) || USE(CAIRO)
#if USE(CG) || USE(CAIRO) || USE(DIRECT2D)
DrawNativeImage,
#endif
DrawPattern,
@@ -638,7 +638,7 @@ class DrawTiledScaledImage : public DrawingItem {
ImagePaintingOptions m_imagePaintingOptions;
};

#if USE(CG) || USE(CAIRO)
#if USE(CG) || USE(CAIRO) || USE(DIRECT2D)
class DrawNativeImage : public DrawingItem {
public:
static Ref<DrawNativeImage> create(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, ImageOrientation orientation)
@@ -126,7 +126,7 @@ ImageDrawResult Recorder::drawTiledImage(Image& image, const FloatRect& destinat
return ImageDrawResult::DidRecord;
}

#if USE(CG) || USE(CAIRO)
#if USE(CG) || USE(CAIRO) || USE(DIRECT2D)
void Recorder::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, ImageOrientation orientation)
{
DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawNativeImage::create(image, imageSize, destRect, srcRect, op, blendMode, orientation)));
@@ -91,7 +91,7 @@ class Recorder : public GraphicsContextImpl {
ImageDrawResult drawImage(Image&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&) override;
ImageDrawResult drawTiledImage(Image&, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions&) override;
ImageDrawResult drawTiledImage(Image&, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions&) override;
#if USE(CG) || USE(CAIRO)
#if USE(CG) || USE(CAIRO) || USE(DIRECT2D)
void drawNativeImage(const NativeImagePtr&, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator, BlendMode, ImageOrientation) override;
#endif
void drawPattern(Image&, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator, BlendMode = BlendMode::Normal) override;
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if USE(DIRECT2D)

#include "COMPtr.h"
#include "IntRect.h"
#include <wincodec.h>
#include <wtf/FastMalloc.h>
#include <wtf/Noncopyable.h>


namespace WebCore {

class BackingStoreBackendDirect2D {
WTF_MAKE_NONCOPYABLE(BackingStoreBackendDirect2D);
WTF_MAKE_FAST_ALLOCATED;
public:
virtual ~BackingStoreBackendDirect2D() = default;

IWICBitmap* surface() const { return m_surface.get(); }
const IntSize& size() const { return m_size; }

virtual void scroll(const IntRect& scrollRect, const IntSize& scrollOffset) = 0;

protected:
BackingStoreBackendDirect2D(const IntSize& size)
: m_size(size)
{
}

COMPtr<IWICBitmap> m_surface;
void* m_surfaceBackingData { nullptr };
IntSize m_size;
};


} // namespace WebCore

#endif // USE(DIRECT2D)

0 comments on commit d702912

Please sign in to comment.