Changeset 254202 in webkit


Ignore:
Timestamp:
Jan 8, 2020 8:33:18 AM (4 years ago)
Author:
Wenson Hsieh
Message:

Add support for encoding WebCore::Font over IPC for DisplayList::DrawGlyphs
https://bugs.webkit.org/show_bug.cgi?id=205830
<rdar://problem/57347719>

Reviewed by Dean Jackson.

Source/WebCore:

Add support for encoding Fonts. In the case where the Font is installed, we use platform encoders to send across
the font descriptor, and reconstruct the font using this descriptor on the receiving end (see the existing
implementations of encodeFontInternal and decodeFontInternal). In the case where the Font is not installed, we
instead send the font face data over (plumbed across from the CachedFont), and reconstruct the platform font
data from the raw font data on the receiving end.

This allows us to render web fonts in the GPU process through the DrawGlyphs display list item.

  • css/CSSFontFace.cpp:

(WebCore::CSSFontFace::font):

  • css/CSSFontFaceSource.h:
  • platform/graphics/Font.cpp:

(WebCore::Font::setFontFaceData):

Add a way to set font face data used to create the Font. This data comes from a CachedFont's data buffer, and is
used to serialize FontHandles when building display list items.

(WebCore::FontHandle::FontHandle):

Add a serializable wrapper class that contains a nullable Font. The encoder/decoders for FontHandle are
implemented in WebKit2.

  • platform/graphics/Font.h:

(WebCore::Font::fontFaceData const):

  • platform/graphics/displaylists/DisplayListItems.cpp:

(WebCore::DisplayList::DrawGlyphs::DrawGlyphs):

Finish implementing the encode/decode methods for DrawGlyphs, by sending the Font data over via FontHandle.

  • platform/graphics/displaylists/DisplayListItems.h:

(WebCore::DisplayList::DrawGlyphs::create):
(WebCore::DisplayList::DrawGlyphs::encode const):
(WebCore::DisplayList::DrawGlyphs::decode):

When decoding DrawGlyphs, avoid having to rebuild the glyph Vector by adding (and using) new DrawGlyphs
constructors that take Vector&&s.

Source/WebKit:

Add basic support for encoding and decoding a FontHandle.

  • Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:

(IPC::ArgumentCoder<FontHandle>::encodePlatformData):
(IPC::ArgumentCoder<FontHandle>::decodePlatformData):

  • Shared/WebCoreArgumentCoders.cpp:

(IPC::ArgumentCoder<FontHandle>::encode):
(IPC::ArgumentCoder<FontHandle>::decode):

When encoding a Font on Cocoa platforms, send across the font face data (if present); otherwise, fall back to
sending the font descriptor for the UIFont or NSFont (as is the case for installed fonts).

  • Shared/WebCoreArgumentCoders.h:
  • Shared/curl/WebCoreArgumentCodersCurl.cpp:

(IPC::ArgumentCoder<FontHandle>::encodePlatformData):
(IPC::ArgumentCoder<FontHandle>::decodePlatformData):

  • Shared/soup/WebCoreArgumentCodersSoup.cpp:

(IPC::ArgumentCoder<FontHandle>::encodePlatformData):
(IPC::ArgumentCoder<FontHandle>::decodePlatformData):

Location:
trunk/Source
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r254201 r254202  
     12020-01-08  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for encoding WebCore::Font over IPC for DisplayList::DrawGlyphs
     4        https://bugs.webkit.org/show_bug.cgi?id=205830
     5        <rdar://problem/57347719>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Add support for encoding Fonts. In the case where the Font is installed, we use platform encoders to send across
     10        the font descriptor, and reconstruct the font using this descriptor on the receiving end (see the existing
     11        implementations of encodeFontInternal and decodeFontInternal). In the case where the Font is not installed, we
     12        instead send the font face data over (plumbed across from the CachedFont), and reconstruct the platform font
     13        data from the raw font data on the receiving end.
     14
     15        This allows us to render web fonts in the GPU process through the `DrawGlyphs` display list item.
     16
     17        * css/CSSFontFace.cpp:
     18        (WebCore::CSSFontFace::font):
     19        * css/CSSFontFaceSource.h:
     20        * platform/graphics/Font.cpp:
     21        (WebCore::Font::setFontFaceData):
     22
     23        Add a way to set font face data used to create the Font. This data comes from a CachedFont's data buffer, and is
     24        used to serialize FontHandles when building display list items.
     25
     26        (WebCore::FontHandle::FontHandle):
     27
     28        Add a serializable wrapper class that contains a nullable Font. The encoder/decoders for FontHandle are
     29        implemented in WebKit2.
     30
     31        * platform/graphics/Font.h:
     32        (WebCore::Font::fontFaceData const):
     33        * platform/graphics/displaylists/DisplayListItems.cpp:
     34        (WebCore::DisplayList::DrawGlyphs::DrawGlyphs):
     35
     36        Finish implementing the encode/decode methods for DrawGlyphs, by sending the Font data over via FontHandle.
     37
     38        * platform/graphics/displaylists/DisplayListItems.h:
     39        (WebCore::DisplayList::DrawGlyphs::create):
     40        (WebCore::DisplayList::DrawGlyphs::encode const):
     41        (WebCore::DisplayList::DrawGlyphs::decode):
     42
     43        When decoding `DrawGlyphs`, avoid having to rebuild the glyph Vector by adding (and using) new DrawGlyphs
     44        constructors that take `Vector&&`s.
     45
    1462020-01-08  Antoine Quint  <graouts@apple.com>
    247
  • trunk/Source/WebCore/css/CSSFontFace.cpp

    r253987 r254202  
    3636#include "CSSValue.h"
    3737#include "CSSValueList.h"
     38#include "CachedFont.h"
    3839#include "Document.h"
    3940#include "Font.h"
     
    4243#include "FontFace.h"
    4344#include "Settings.h"
     45#include "SharedBuffer.h"
    4446#include "StyleBuilderConverter.h"
    4547#include "StyleProperties.h"
     
    674676        }
    675677        case CSSFontFaceSource::Status::Success:
    676             if (RefPtr<Font> result = source->font(fontDescription, syntheticBold, syntheticItalic, m_featureSettings, m_fontSelectionCapabilities))
     678            if (auto result = source->font(fontDescription, syntheticBold, syntheticItalic, m_featureSettings, m_fontSelectionCapabilities)) {
     679                auto* cachedFont = source->cachedFont();
     680                result->setFontFaceData(cachedFont ? cachedFont->resourceBuffer() : nullptr);
    677681                return result;
     682            }
    678683            break;
    679684        case CSSFontFaceSource::Status::Failure:
  • trunk/Source/WebCore/css/CSSFontFaceSource.h

    r252760 r254202  
    7373    RefPtr<Font> font(const FontDescription&, bool syntheticBold, bool syntheticItalic, const FontFeatureSettings&, FontSelectionSpecifiedCapabilities);
    7474
     75    CachedFont* cachedFont() const { return m_font.get(); }
    7576    bool requiresExternalResource() const { return m_font; }
    7677
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r253987 r254202  
    3434#include <pal/spi/cocoa/CoreTextSPI.h>
    3535#endif
     36#include "CachedFont.h"
    3637#include "CharacterProperties.h"
    3738#include "FontCache.h"
    3839#include "FontCascade.h"
     40#include "FontCustomPlatformData.h"
    3941#include "OpenTypeMathData.h"
     42#include "SharedBuffer.h"
    4043#include <wtf/MathExtras.h>
    4144#include <wtf/NeverDestroyed.h>
     
    706709}
    707710
     711void Font::setFontFaceData(RefPtr<SharedBuffer>&& fontFaceData)
     712{
     713    m_fontFaceData = WTFMove(fontFaceData);
     714}
     715
     716FontHandle::FontHandle(Ref<SharedBuffer>&& fontFaceData, Font::Origin origin, float fontSize, bool syntheticBold, bool syntheticItalic)
     717{
     718    bool wrapping;
     719    auto customFontData = CachedFont::createCustomFontData(fontFaceData.get(), { }, wrapping);
     720    FontDescription description;
     721    description.setComputedSize(fontSize);
     722    font = Font::create(CachedFont::platformDataFromCustomData(*customFontData, description, syntheticBold, syntheticItalic, { }, { }), origin);
     723}
     724
    708725} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/Font.h

    r253987 r254202  
    219219#endif
    220220
     221    SharedBuffer* fontFaceData() const { return m_fontFaceData.get(); }
     222    void setFontFaceData(RefPtr<SharedBuffer>&&);
     223
    221224private:
    222     Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback);
     225    WEBCORE_EXPORT Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback);
    223226
    224227    void platformInit();
     
    292295#endif
    293296
     297    RefPtr<SharedBuffer> m_fontFaceData;
     298
    294299    Glyph m_spaceGlyph { 0 };
    295300    Glyph m_zeroGlyph { 0 };
     
    320325    unsigned m_shouldNotBeUsedForArabic : 1;
    321326#endif
     327};
     328
     329class FontHandle {
     330public:
     331    FontHandle() = default;
     332    WEBCORE_EXPORT FontHandle(Ref<SharedBuffer>&& fontFaceData, Font::Origin, float fontSize, bool syntheticBold, bool syntheticItalic);
     333
     334    RefPtr<Font> font;
    322335};
    323336
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp

    r254047 r254202  
    513513}
    514514
     515DrawGlyphs::DrawGlyphs(const Font& font, Vector<GlyphBufferGlyph, 128>&& glyphs, Vector<GlyphBufferAdvance, 128>&& advances, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode smoothingMode)
     516    : DrawingItem(ItemType::DrawGlyphs)
     517    , m_font(const_cast<Font&>(font))
     518    , m_glyphs(WTFMove(glyphs))
     519    , m_advances(WTFMove(advances))
     520    , m_blockLocation(blockLocation)
     521    , m_localAnchor(localAnchor)
     522    , m_smoothingMode(smoothingMode)
     523{
     524    computeBounds();
     525}
     526
    515527DrawGlyphs::DrawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned count, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode smoothingMode)
    516528    : DrawingItem(ItemType::DrawGlyphs)
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h

    r254047 r254202  
    10581058    }
    10591059
     1060    static Ref<DrawGlyphs> create(const Font& font, Vector<GlyphBufferGlyph, 128>&& glyphs, Vector<GlyphBufferAdvance, 128>&& advances, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode smoothingMode)
     1061    {
     1062        return adoptRef(*new DrawGlyphs(font, WTFMove(glyphs), WTFMove(advances), blockLocation, localAnchor, smoothingMode));
     1063    }
     1064
    10601065    WEBCORE_EXPORT virtual ~DrawGlyphs();
    10611066
     
    10731078
    10741079private:
    1075     WEBCORE_EXPORT DrawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode);
     1080    DrawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode);
     1081    WEBCORE_EXPORT DrawGlyphs(const Font&, Vector<GlyphBufferGlyph, 128>&&, Vector<GlyphBufferAdvance, 128>&&, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode);
    10761082
    10771083    void computeBounds();
     
    10951101void DrawGlyphs::encode(Encoder& encoder) const
    10961102{
    1097     // FIXME: Add font data to the encoder.
     1103    FontHandle handle;
     1104    handle.font = m_font.ptr();
     1105    encoder << handle;
    10981106    encoder << m_glyphs;
    10991107    encoder << m_advances;
     
    11061114Optional<Ref<DrawGlyphs>> DrawGlyphs::decode(Decoder& decoder)
    11071115{
     1116    Optional<FontHandle> handle;
     1117    decoder >> handle;
     1118    if (!handle || !handle->font)
     1119        return WTF::nullopt;
     1120
    11081121    Optional<Vector<GlyphBufferGlyph, 128>> glyphs;
    11091122    decoder >> glyphs;
     
    11341147        return WTF::nullopt;
    11351148
    1136     // FIXME: Create and return a DrawGlyphs once we're able to decode font data.
    1137     return WTF::nullopt;
     1149    return DrawGlyphs::create(handle->font.releaseNonNull(), WTFMove(*glyphs), WTFMove(*advances), *blockLocation, *localAnchor, *smoothingMode);
    11381150}
    11391151
  • trunk/Source/WebKit/ChangeLog

    r254199 r254202  
     12020-01-08  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for encoding WebCore::Font over IPC for DisplayList::DrawGlyphs
     4        https://bugs.webkit.org/show_bug.cgi?id=205830
     5        <rdar://problem/57347719>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Add basic support for encoding and decoding a FontHandle.
     10
     11        * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
     12        (IPC::ArgumentCoder<FontHandle>::encodePlatformData):
     13        (IPC::ArgumentCoder<FontHandle>::decodePlatformData):
     14        * Shared/WebCoreArgumentCoders.cpp:
     15        (IPC::ArgumentCoder<FontHandle>::encode):
     16        (IPC::ArgumentCoder<FontHandle>::decode):
     17
     18        When encoding a Font on Cocoa platforms, send across the font face data (if present); otherwise, fall back to
     19        sending the font descriptor for the UIFont or NSFont (as is the case for installed fonts).
     20
     21        * Shared/WebCoreArgumentCoders.h:
     22        * Shared/curl/WebCoreArgumentCodersCurl.cpp:
     23        (IPC::ArgumentCoder<FontHandle>::encodePlatformData):
     24        (IPC::ArgumentCoder<FontHandle>::decodePlatformData):
     25        * Shared/soup/WebCoreArgumentCodersSoup.cpp:
     26        (IPC::ArgumentCoder<FontHandle>::encodePlatformData):
     27        (IPC::ArgumentCoder<FontHandle>::decodePlatformData):
     28
    1292020-01-08  Milan Crha  <mcrha@redhat.com>
    230
  • trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm

    r250179 r254202  
    2929#import "ArgumentCodersCocoa.h"
    3030#import <WebCore/DictionaryPopupInfo.h>
     31#import <WebCore/Font.h>
    3132#import <WebCore/FontAttributes.h>
    3233
     
    473474}
    474475
     476#if PLATFORM(IOS_FAMILY)
     477#define CocoaFont UIFont
     478#else
     479#define CocoaFont NSFont
     480#endif
     481
     482void ArgumentCoder<FontHandle>::encodePlatformData(Encoder& encoder, const FontHandle& handle)
     483{
     484    auto ctFont = handle.font && !handle.font->fontFaceData() ? handle.font->getCTFont() : nil;
     485    encoder << !!ctFont;
     486    if (ctFont)
     487        encoder << (__bridge CocoaFont *)ctFont;
     488}
     489
     490bool ArgumentCoder<FontHandle>::decodePlatformData(Decoder& decoder, FontHandle& handle)
     491{
     492    bool hasPlatformFont;
     493    if (!decoder.decode(hasPlatformFont))
     494        return false;
     495
     496    if (!hasPlatformFont)
     497        return true;
     498
     499    RetainPtr<CocoaFont> font;
     500    if (!IPC::decode(decoder, font))
     501        return false;
     502
     503    auto previousValue = handle.font;
     504    handle.font = Font::create({ (__bridge CTFontRef)font.get(), static_cast<float>([font pointSize]) });
     505    return true;
     506}
     507
    475508} // namespace IPC
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp

    r253636 r254202  
    4949#include <WebCore/FilterOperation.h>
    5050#include <WebCore/FilterOperations.h>
     51#include <WebCore/Font.h>
    5152#include <WebCore/FontAttributes.h>
    5253#include <WebCore/GraphicsContext.h>
     
    11261127}
    11271128
     1129void ArgumentCoder<FontHandle>::encode(Encoder& encoder, const FontHandle& handle)
     1130{
     1131    encoder << !!handle.font;
     1132    if (!handle.font)
     1133        return;
     1134
     1135    auto* fontFaceData = handle.font->fontFaceData();
     1136    encoder << !!fontFaceData;
     1137    if (fontFaceData) {
     1138        encodeSharedBuffer(encoder, fontFaceData);
     1139        auto& data = handle.font->platformData();
     1140        encoder << data.size();
     1141        encoder << data.syntheticBold();
     1142        encoder << data.syntheticOblique();
     1143    }
     1144
     1145    encodePlatformData(encoder, handle);
     1146}
     1147
     1148bool ArgumentCoder<FontHandle>::decode(Decoder& decoder, FontHandle& handle)
     1149{
     1150    Optional<bool> hasFont;
     1151    decoder >> hasFont;
     1152    if (!hasFont.hasValue())
     1153        return false;
     1154
     1155    if (!hasFont.value())
     1156        return true;
     1157
     1158    Optional<bool> hasFontFaceData;
     1159    decoder >> hasFontFaceData;
     1160    if (!hasFontFaceData.hasValue())
     1161        return false;
     1162
     1163    if (hasFontFaceData.value()) {
     1164        RefPtr<SharedBuffer> fontFaceData;
     1165        if (!decodeSharedBuffer(decoder, fontFaceData))
     1166            return false;
     1167
     1168        if (!fontFaceData)
     1169            return false;
     1170
     1171        Optional<float> fontSize;
     1172        decoder >> fontSize;
     1173        if (!fontSize)
     1174            return false;
     1175
     1176        Optional<bool> syntheticBold;
     1177        decoder >> syntheticBold;
     1178        if (!syntheticBold)
     1179            return false;
     1180
     1181        Optional<bool> syntheticItalic;
     1182        decoder >> syntheticItalic;
     1183        if (!syntheticItalic)
     1184            return false;
     1185
     1186        FontDescription description;
     1187        description.setComputedSize(*fontSize);
     1188        handle = { fontFaceData.releaseNonNull(), Font::Origin::Remote, *fontSize, *syntheticBold, *syntheticItalic };
     1189    }
     1190
     1191    return decodePlatformData(decoder, handle);
     1192}
     1193
    11281194void ArgumentCoder<Cursor>::encode(Encoder& encoder, const Cursor& cursor)
    11291195{
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h

    r253495 r254202  
    8181class FloatSize;
    8282class FixedPositionViewportConstraints;
     83class FontHandle;
    8384class HTTPHeaderMap;
    8485class ImageHandle;
     
    380381};
    381382
     383template<> struct ArgumentCoder<WebCore::FontHandle> {
     384    static void encode(Encoder&, const WebCore::FontHandle&);
     385    static bool decode(Decoder&, WebCore::FontHandle&);
     386    static void encodePlatformData(Encoder&, const WebCore::FontHandle&);
     387    static bool decodePlatformData(Decoder&, WebCore::FontHandle&);
     388};
     389
    382390template<> struct ArgumentCoder<WebCore::ImageHandle> {
    383391    static void encode(Encoder&, const WebCore::ImageHandle&);
  • trunk/Source/WebKit/Shared/curl/WebCoreArgumentCodersCurl.cpp

    r242908 r254202  
    3131#include <WebCore/CurlProxySettings.h>
    3232#include <WebCore/DictionaryPopupInfo.h>
     33#include <WebCore/Font.h>
    3334#include <WebCore/FontAttributes.h>
    3435#include <WebCore/ProtectionSpace.h>
     
    235236}
    236237
    237 }
     238void ArgumentCoder<FontHandle>::encodePlatformData(Encoder&, const FontHandle&)
     239{
     240    ASSERT_NOT_REACHED();
     241}
     242
     243bool ArgumentCoder<FontHandle>::decodePlatformData(Decoder&, FontHandle&)
     244{
     245    ASSERT_NOT_REACHED();
     246    return false;
     247}
     248
     249}
  • trunk/Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp

    r242908 r254202  
    3232#include <WebCore/CertificateInfo.h>
    3333#include <WebCore/DictionaryPopupInfo.h>
     34#include <WebCore/Font.h>
    3435#include <WebCore/FontAttributes.h>
    3536#include <WebCore/ResourceError.h>
     
    252253}
    253254
    254 }
    255 
     255void ArgumentCoder<FontHandle>::encodePlatformData(Encoder&, const FontHandle&)
     256{
     257    ASSERT_NOT_REACHED();
     258}
     259
     260bool ArgumentCoder<FontHandle>::decodePlatformData(Decoder&, FontHandle&)
     261{
     262    ASSERT_NOT_REACHED();
     263    return false;
     264}
     265
     266}
     267
Note: See TracChangeset for help on using the changeset viewer.