Diff
Modified: trunk/Source/WebCore/ChangeLog (265240 => 265241)
--- trunk/Source/WebCore/ChangeLog 2020-08-04 04:32:33 UTC (rev 265240)
+++ trunk/Source/WebCore/ChangeLog 2020-08-04 04:49:59 UTC (rev 265241)
@@ -1,5 +1,64 @@
2020-08-03 Myles C. Maxfield <[email protected]>
+ Unconditionally record string offsets in the fast text codepath
+ https://bugs.webkit.org/show_bug.cgi?id=215051
+
+ Reviewed by Darin Adler.
+
+ This is in preparation for https://bugs.webkit.org/show_bug.cgi?id=214769
+ and https://bugs.webkit.org/show_bug.cgi?id=206208.
+
+ The solution for https://bugs.webkit.org/show_bug.cgi?id=214769 requires applying
+ letter-spacing after text shaping. Today, we apply letter-spacing before text
+ shaping, which is wrong. However, if we want to apply letter-spacing after text
+ shaping, we will need a way of mapping back which shaped glyphs correspond to
+ which characters in the string, so we can apply letter-spacing to the correct
+ glyphs. Therefore, we need to record string offsets any time letter-spacing can
+ be applied (which is all the time - letter spacing can be applied on any element).
+
+ This also helps on the path toward https://bugs.webkit.org/show_bug.cgi?id=214769.
+ When we move off the complex text codepath, we will need these string offsets
+ to calculate things like what the text range of a selection is when the user has
+ selected some glyphs on the page.
+
+ There is no performance change because these string offsets were already being
+ calculated; the difference is just that we're storing them now. Also, we were
+ being wildly inefficient with the members of GlyphBuffer, giving them inline
+ sizes of 2048. I measured the median and mean of these strings in our Page Load
+ Test to be 6 and 7.4. So, I cut down the inline sizes down to 1024, so now we're
+ using less memory than we were before.
+
+ No new tests because there is no behavior change. The additional string offsets
+ are unused (for now). A subsequent patch will start using them.
+
+ * platform/graphics/FontCascade.cpp:
+ (WebCore::FontCascade::layoutText const):
+ (WebCore::FontCascade::drawEmphasisMarks const):
+ (WebCore::computeUnderlineType):
+ (WebCore::FontCascade::layoutSimpleText const):
+ (WebCore::FontCascade::layoutComplexText const):
+ (WebCore::FontCascade::dashesForIntersectionsWithRect const):
+ * platform/graphics/FontCascade.h:
+ * platform/graphics/GlyphBuffer.h:
+ (WebCore::GlyphBuffer::clear):
+ (WebCore::GlyphBuffer::fonts):
+ (WebCore::GlyphBuffer::offsetsInString):
+ (WebCore::GlyphBuffer::fonts const):
+ (WebCore::GlyphBuffer::offsetsInString const):
+ (WebCore::GlyphBuffer::glyphAt const):
+ (WebCore::GlyphBuffer::advanceAt const):
+ (WebCore::GlyphBuffer::stringOffsetAt const):
+ (WebCore::GlyphBuffer::add):
+ (WebCore::GlyphBuffer::remove):
+ (WebCore::GlyphBuffer::makeHole):
+ (WebCore::GlyphBuffer::expandLastAdvance):
+ (WebCore::GlyphBuffer::shrink):
+ (WebCore::GlyphBuffer::swap):
+ (WebCore::GlyphBuffer::saveOffsetsInString): Deleted.
+ (WebCore::GlyphBuffer::offsetInString const): Deleted.
+
+2020-08-03 Myles C. Maxfield <[email protected]>
+
Rename WidthIterator::m_currentCharacter to WidthIterator::m_currentCharacterIndex
https://bugs.webkit.org/show_bug.cgi?id=215056
Modified: trunk/Source/WebCore/platform/graphics/FontCascade.cpp (265240 => 265241)
--- trunk/Source/WebCore/platform/graphics/FontCascade.cpp 2020-08-04 04:32:33 UTC (rev 265240)
+++ trunk/Source/WebCore/platform/graphics/FontCascade.cpp 2020-08-04 04:49:59 UTC (rev 265241)
@@ -2,7 +2,7 @@
* Copyright (C) 1999 Lars Knoll ([email protected])
* (C) 1999 Antti Koivisto ([email protected])
* (C) 2000 Dirk Mueller ([email protected])
- * Copyright (C) 2003-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-2020 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -285,12 +285,12 @@
m_requiresShaping = computeRequiresShaping();
}
-GlyphBuffer FontCascade::layoutText(CodePath codePathToUse, const TextRun& run, unsigned from, unsigned to, ShouldSaveOffsets shouldSaveOffsets, ForTextEmphasisOrNot forTextEmphasis) const
+GlyphBuffer FontCascade::layoutText(CodePath codePathToUse, const TextRun& run, unsigned from, unsigned to, ForTextEmphasisOrNot forTextEmphasis) const
{
if (codePathToUse != Complex)
- return layoutSimpleText(run, from, to, shouldSaveOffsets, forTextEmphasis);
+ return layoutSimpleText(run, from, to, forTextEmphasis);
- return layoutComplexText(run, from, to, shouldSaveOffsets, forTextEmphasis);
+ return layoutComplexText(run, from, to, forTextEmphasis);
}
FloatSize FontCascade::drawText(GraphicsContext& context, const TextRun& run, const FloatPoint& point, unsigned from, Optional<unsigned> to, CustomFontNotReadyAction customFontNotReadyAction) const
@@ -313,7 +313,7 @@
unsigned destination = to.valueOr(run.length());
- auto glyphBuffer = layoutText(codePath(run, from, to), run, from, destination, ShouldSaveOffsets::No, ForTextEmphasisOrNot::ForTextEmphasis);
+ auto glyphBuffer = layoutText(codePath(run, from, to), run, from, destination, ForTextEmphasisOrNot::ForTextEmphasis);
if (glyphBuffer.isEmpty())
return;
@@ -1258,18 +1258,15 @@
// so we want to draw through CJK characters (on a character-by-character basis).
// FIXME: The CSS spec says this should instead be done by the user-agent stylesheet using the lang= attribute.
UChar32 baseCharacter;
- unsigned offsetInString = glyphBuffer.offsetInString(index);
+ auto offsetInString = glyphBuffer.stringOffsetAt(index);
- if (offsetInString == GlyphBuffer::noOffset || offsetInString >= textRun.length()) {
- // We have no idea which character spawned this glyph. Bail.
- ASSERT_WITH_SECURITY_IMPLICATION(offsetInString < textRun.length());
- return GlyphUnderlineType::DrawOverGlyph;
- }
+ GlyphBufferStringOffset textRunLength = textRun.length();
+ RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(offsetInString < textRunLength);
if (textRun.is8Bit())
baseCharacter = textRun.characters8()[offsetInString];
else
- U16_NEXT(textRun.characters16(), offsetInString, textRun.length(), baseCharacter);
+ U16_GET(textRun.characters16(), 0, offsetInString, textRunLength, baseCharacter);
// u_getIntPropertyValue with UCHAR_IDEOGRAPHIC doesn't return true for Japanese or Korean codepoints.
// Instead, we can use the "Unicode allocation block" for the character.
@@ -1368,11 +1365,9 @@
return markFontData->fontMetrics().height();
}
-GlyphBuffer FontCascade::layoutSimpleText(const TextRun& run, unsigned from, unsigned to, ShouldSaveOffsets shouldSaveOffsets, ForTextEmphasisOrNot forTextEmphasis) const
+GlyphBuffer FontCascade::layoutSimpleText(const TextRun& run, unsigned from, unsigned to, ForTextEmphasisOrNot forTextEmphasis) const
{
GlyphBuffer glyphBuffer;
- if (shouldSaveOffsets == ShouldSaveOffsets::Yes)
- glyphBuffer.saveOffsetsInString();
WidthIterator it(this, run, 0, false, forTextEmphasis);
// FIXME: Using separate glyph buffers for the prefix and the suffix is incorrect when kerning or
@@ -1403,11 +1398,9 @@
return glyphBuffer;
}
-GlyphBuffer FontCascade::layoutComplexText(const TextRun& run, unsigned from, unsigned to, ShouldSaveOffsets shouldSaveOffsets, ForTextEmphasisOrNot forTextEmphasis) const
+GlyphBuffer FontCascade::layoutComplexText(const TextRun& run, unsigned from, unsigned to, ForTextEmphasisOrNot forTextEmphasis) const
{
GlyphBuffer glyphBuffer;
- if (shouldSaveOffsets == ShouldSaveOffsets::Yes)
- glyphBuffer.saveOffsetsInString();
ComplexTextController controller(*this, run, false, 0, forTextEmphasis);
GlyphBuffer dummyGlyphBuffer;
@@ -1776,7 +1769,7 @@
if (isLoadingCustomFonts())
return DashArray();
- auto glyphBuffer = layoutText(codePath(run), run, 0, run.length(), ShouldSaveOffsets::Yes);
+ auto glyphBuffer = layoutText(codePath(run), run, 0, run.length());
if (!glyphBuffer.size())
return DashArray();
Modified: trunk/Source/WebCore/platform/graphics/FontCascade.h (265240 => 265241)
--- trunk/Source/WebCore/platform/graphics/FontCascade.h 2020-08-04 04:32:33 UTC (rev 265240)
+++ trunk/Source/WebCore/platform/graphics/FontCascade.h 2020-08-04 04:49:59 UTC (rev 265241)
@@ -2,7 +2,7 @@
* Copyright (C) 2000 Lars Knoll ([email protected])
* (C) 2000 Antti Koivisto ([email protected])
* (C) 2000 Dirk Mueller ([email protected])
- * Copyright (C) 2003-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-2020 Apple Inc. All rights reserved.
* Copyright (C) 2008 Holger Hans Peter Freyther
*
* This library is free software; you can redistribute it and/or
@@ -203,13 +203,9 @@
#endif
private:
enum ForTextEmphasisOrNot { NotForTextEmphasis, ForTextEmphasis };
- enum class ShouldSaveOffsets : uint8_t {
- Yes,
- No
- };
- GlyphBuffer layoutText(CodePath, const TextRun&, unsigned from, unsigned to, ShouldSaveOffsets = ShouldSaveOffsets::No, ForTextEmphasisOrNot = NotForTextEmphasis) const;
- GlyphBuffer layoutSimpleText(const TextRun&, unsigned from, unsigned to, ShouldSaveOffsets = ShouldSaveOffsets::No, ForTextEmphasisOrNot = NotForTextEmphasis) const;
+ GlyphBuffer layoutText(CodePath, const TextRun&, unsigned from, unsigned to, ForTextEmphasisOrNot = NotForTextEmphasis) const;
+ GlyphBuffer layoutSimpleText(const TextRun&, unsigned from, unsigned to, ForTextEmphasisOrNot = NotForTextEmphasis) const;
void drawGlyphBuffer(GraphicsContext&, const GlyphBuffer&, FloatPoint&, CustomFontNotReadyAction) const;
void drawEmphasisMarks(GraphicsContext&, const GlyphBuffer&, const AtomString&, const FloatPoint&) const;
float floatWidthForSimpleText(const TextRun&, HashSet<const Font*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
@@ -221,7 +217,7 @@
static bool canReturnFallbackFontsForComplexText();
static bool canExpandAroundIdeographsInComplexText();
- GlyphBuffer layoutComplexText(const TextRun&, unsigned from, unsigned to, ShouldSaveOffsets = ShouldSaveOffsets::No, ForTextEmphasisOrNot = NotForTextEmphasis) const;
+ GlyphBuffer layoutComplexText(const TextRun&, unsigned from, unsigned to, ForTextEmphasisOrNot = NotForTextEmphasis) const;
float floatWidthForComplexText(const TextRun&, HashSet<const Font*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
int offsetForPositionForComplexText(const TextRun&, float position, bool includePartialGlyphs) const;
void adjustSelectionRectForComplexText(const TextRun&, LayoutRect& selectionRect, unsigned from, unsigned to) const;
Modified: trunk/Source/WebCore/platform/graphics/GlyphBuffer.h (265240 => 265241)
--- trunk/Source/WebCore/platform/graphics/GlyphBuffer.h 2020-08-04 04:32:33 UTC (rev 265240)
+++ trunk/Source/WebCore/platform/graphics/GlyphBuffer.h 2020-08-04 04:49:59 UTC (rev 265241)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2009, 2011, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
* Copyright (C) 2007-2008 Torch Mobile Inc.
*
* Redistribution and use in source and binary forms, with or without
@@ -32,6 +32,7 @@
#include "FloatSize.h"
#include "Glyph.h"
#include <climits>
+#include <limits>
#include <wtf/Vector.h>
#if USE(CG)
@@ -51,6 +52,7 @@
// CG uses CGSize instead of FloatSize so that the result of advances()
// can be passed directly to CGContextShowGlyphsWithAdvances in FontMac.mm
#if USE(CG)
+
struct GlyphBufferAdvance : CGSize {
public:
GlyphBufferAdvance() : CGSize(CGSizeZero) { }
@@ -100,10 +102,16 @@
return GlyphBufferAdvance(CGSizeMake(*width, *height));
}
+
+using GlyphBufferStringOffset = CFIndex;
+
#else
-typedef FloatSize GlyphBufferAdvance;
-#endif
+using GlyphBufferAdvance = FloatSize;
+using GlyphBufferStringOffset = unsigned;
+
+#endif // #if USE(CG)
+
inline FloatSize toFloatSize(const GlyphBufferAdvance& a)
{
return FloatSize(a.width(), a.height());
@@ -119,49 +127,41 @@
m_fonts.clear();
m_glyphs.clear();
m_advances.clear();
- if (m_offsetsInString)
- m_offsetsInString->clear();
+ m_offsetsInString.clear();
}
+ const Font** fonts(unsigned from) { return m_fonts.data() + from; }
GlyphBufferGlyph* glyphs(unsigned from) { return m_glyphs.data() + from; }
GlyphBufferAdvance* advances(unsigned from) { return m_advances.data() + from; }
+ GlyphBufferStringOffset* offsetsInString(unsigned from) { return m_offsetsInString.data() + from; }
+ const Font* const * fonts(unsigned from) const { return m_fonts.data() + from; }
const GlyphBufferGlyph* glyphs(unsigned from) const { return m_glyphs.data() + from; }
const GlyphBufferAdvance* advances(unsigned from) const { return m_advances.data() + from; }
+ const GlyphBufferStringOffset* offsetsInString(unsigned from) const { return m_offsetsInString.data() + from; }
const Font* fontAt(unsigned index) const { return m_fonts[index]; }
+ Glyph glyphAt(unsigned index) const { return m_glyphs[index]; }
+ GlyphBufferAdvance advanceAt(unsigned index) const { return m_advances[index]; }
+ GlyphBufferStringOffset stringOffsetAt(unsigned index) const { return m_offsetsInString[index]; }
void setInitialAdvance(GlyphBufferAdvance initialAdvance) { m_initialAdvance = initialAdvance; }
const GlyphBufferAdvance& initialAdvance() const { return m_initialAdvance; }
- Glyph glyphAt(unsigned index) const
+ static constexpr GlyphBufferStringOffset noOffset = std::numeric_limits<GlyphBufferStringOffset>::max();
+ void add(Glyph glyph, const Font* font, float width, GlyphBufferStringOffset offsetInString = noOffset)
{
- return m_glyphs[index];
- }
-
- GlyphBufferAdvance advanceAt(unsigned index) const
- {
- return m_advances[index];
- }
-
- static const unsigned noOffset = UINT_MAX;
- void add(Glyph glyph, const Font* font, float width, unsigned offsetInString = noOffset)
- {
GlyphBufferAdvance advance;
advance.setWidth(width);
advance.setHeight(0);
-
add(glyph, font, advance, offsetInString);
}
- void add(Glyph glyph, const Font* font, GlyphBufferAdvance advance, unsigned offsetInString)
+ void add(Glyph glyph, const Font* font, GlyphBufferAdvance advance, GlyphBufferStringOffset offsetInString)
{
m_fonts.append(font);
m_glyphs.append(glyph);
-
m_advances.append(advance);
-
- if (offsetInString != noOffset && m_offsetsInString)
- m_offsetsInString->append(offsetInString);
+ m_offsetsInString.append(offsetInString);
}
void remove(unsigned location, unsigned length)
@@ -169,8 +169,7 @@
m_fonts.remove(location, length);
m_glyphs.remove(location, length);
m_advances.remove(location, length);
- if (m_offsetsInString)
- m_offsetsInString->remove(location, length);
+ m_offsetsInString.remove(location, length);
}
void makeHole(unsigned location, unsigned length, const Font* font)
@@ -180,8 +179,7 @@
m_fonts.insertVector(location, Vector<const Font*>(length, font));
m_glyphs.insertVector(location, Vector<GlyphBufferGlyph>(length, 0xFFFF));
m_advances.insertVector(location, Vector<GlyphBufferAdvance>(length, GlyphBufferAdvance(0, 0)));
- if (m_offsetsInString)
- m_offsetsInString->insertVector(location, Vector<unsigned>(length, 0));
+ m_offsetsInString.insertVector(location, Vector<GlyphBufferStringOffset>(length, 0));
}
void reverse(unsigned from, unsigned length)
@@ -204,48 +202,40 @@
lastAdvance.setWidth(lastAdvance.width() + expansion.width());
lastAdvance.setHeight(lastAdvance.height() + expansion.height());
}
-
- void saveOffsetsInString()
- {
- m_offsetsInString.reset(new Vector<unsigned, 2048>());
- }
- int offsetInString(unsigned index) const
- {
- ASSERT(m_offsetsInString);
- return (*m_offsetsInString)[index];
- }
-
void shrink(unsigned truncationPoint)
{
m_fonts.shrink(truncationPoint);
m_glyphs.shrink(truncationPoint);
m_advances.shrink(truncationPoint);
- if (m_offsetsInString)
- m_offsetsInString->shrink(truncationPoint);
+ m_offsetsInString.shrink(truncationPoint);
}
private:
void swap(unsigned index1, unsigned index2)
{
- const Font* f = m_fonts[index1];
+ const Font* font = m_fonts[index1];
m_fonts[index1] = m_fonts[index2];
- m_fonts[index2] = f;
+ m_fonts[index2] = font;
- GlyphBufferGlyph g = m_glyphs[index1];
+ GlyphBufferGlyph glyph = m_glyphs[index1];
m_glyphs[index1] = m_glyphs[index2];
- m_glyphs[index2] = g;
+ m_glyphs[index2] = glyph;
- GlyphBufferAdvance s = m_advances[index1];
+ GlyphBufferAdvance advance = m_advances[index1];
m_advances[index1] = m_advances[index2];
- m_advances[index2] = s;
+ m_advances[index2] = advance;
+
+ GlyphBufferStringOffset offset = m_offsetsInString[index1];
+ m_offsetsInString[index1] = m_offsetsInString[index2];
+ m_offsetsInString[index2] = offset;
}
- Vector<const Font*, 2048> m_fonts;
- Vector<GlyphBufferGlyph, 2048> m_glyphs;
- Vector<GlyphBufferAdvance, 2048> m_advances;
+ Vector<const Font*, 1024> m_fonts;
+ Vector<GlyphBufferGlyph, 1024> m_glyphs;
+ Vector<GlyphBufferAdvance, 1024> m_advances;
+ Vector<GlyphBufferStringOffset, 1024> m_offsetsInString;
GlyphBufferAdvance m_initialAdvance;
- std::unique_ptr<Vector<unsigned, 2048>> m_offsetsInString;
};
}