Commit 4e03d6fb authored by jbroman@chromium.org's avatar jbroman@chromium.org

Remove GlyphBufferAdvance abstraction.

BUG=383594

Review URL: https://codereview.chromium.org/327243005

git-svn-id: svn://svn.chromium.org/blink/trunk@176048 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 035cb47e
...@@ -34,31 +34,10 @@ ...@@ -34,31 +34,10 @@
#include "platform/geometry/FloatSize.h" #include "platform/geometry/FloatSize.h"
#include "wtf/Vector.h" #include "wtf/Vector.h"
#if OS(MACOSX)
#include <ApplicationServices/ApplicationServices.h>
#endif
namespace WebCore { namespace WebCore {
class SimpleFontData; class SimpleFontData;
// CG uses CGSize instead of FloatSize so that the result of advances()
// can be passed directly to CGContextShowGlyphsWithAdvances in FontMac.mm
#if OS(MACOSX)
struct GlyphBufferAdvance : CGSize {
public:
GlyphBufferAdvance(CGSize size) : CGSize(size)
{
}
void setWidth(CGFloat width) { this->CGSize::width = width; }
CGFloat width() const { return this->CGSize::width; }
CGFloat height() const { return this->CGSize::height; }
};
#else
typedef FloatSize GlyphBufferAdvance;
#endif
class GlyphBuffer { class GlyphBuffer {
public: public:
bool isEmpty() const { return m_fontData.isEmpty(); } bool isEmpty() const { return m_fontData.isEmpty(); }
...@@ -72,9 +51,9 @@ public: ...@@ -72,9 +51,9 @@ public:
} }
Glyph* glyphs(unsigned from) { return m_glyphs.data() + from; } Glyph* glyphs(unsigned from) { return m_glyphs.data() + from; }
GlyphBufferAdvance* advances(unsigned from) { return m_advances.data() + from; } FloatSize* advances(unsigned from) { return m_advances.data() + from; }
const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; } const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; }
const GlyphBufferAdvance* advances(unsigned from) const { return m_advances.data() + from; } const FloatSize* advances(unsigned from) const { return m_advances.data() + from; }
const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[index]; } const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[index]; }
...@@ -85,27 +64,15 @@ public: ...@@ -85,27 +64,15 @@ public:
FloatSize advanceAt(unsigned index) const FloatSize advanceAt(unsigned index) const
{ {
#if OS(MACOSX)
return FloatSize(m_advances[index]);
#else
return m_advances[index]; return m_advances[index];
#endif
} }
void add(Glyph glyph, const SimpleFontData* font, float width) void add(Glyph glyph, const SimpleFontData* font, float width)
{ {
m_fontData.append(font); add(glyph, font, FloatSize(width, 0));
m_glyphs.append(glyph);
#if OS(MACOSX)
CGSize advance = { width, 0 };
m_advances.append(advance);
#else
m_advances.append(FloatSize(width, 0));
#endif
} }
void add(Glyph glyph, const SimpleFontData* font, GlyphBufferAdvance advance) void add(Glyph glyph, const SimpleFontData* font, const FloatSize& advance)
{ {
m_fontData.append(font); m_fontData.append(font);
m_glyphs.append(glyph); m_glyphs.append(glyph);
...@@ -121,7 +88,7 @@ public: ...@@ -121,7 +88,7 @@ public:
void expandLastAdvance(float width) void expandLastAdvance(float width)
{ {
ASSERT(!isEmpty()); ASSERT(!isEmpty());
GlyphBufferAdvance& lastAdvance = m_advances.last(); FloatSize& lastAdvance = m_advances.last();
lastAdvance.setWidth(lastAdvance.width() + width); lastAdvance.setWidth(lastAdvance.width() + width);
} }
...@@ -136,14 +103,14 @@ private: ...@@ -136,14 +103,14 @@ private:
m_glyphs[index1] = m_glyphs[index2]; m_glyphs[index1] = m_glyphs[index2];
m_glyphs[index2] = g; m_glyphs[index2] = g;
GlyphBufferAdvance s = m_advances[index1]; FloatSize s = m_advances[index1];
m_advances[index1] = m_advances[index2]; m_advances[index1] = m_advances[index2];
m_advances[index2] = s; m_advances[index2] = s;
} }
Vector<const SimpleFontData*, 2048> m_fontData; Vector<const SimpleFontData*, 2048> m_fontData;
Vector<Glyph, 2048> m_glyphs; Vector<Glyph, 2048> m_glyphs;
Vector<GlyphBufferAdvance, 2048> m_advances; Vector<FloatSize, 2048> m_advances;
}; };
} }
......
...@@ -109,7 +109,7 @@ static inline float applyFontTransforms(GlyphBuffer* glyphBuffer, bool ltr, unsi ...@@ -109,7 +109,7 @@ static inline float applyFontTransforms(GlyphBuffer* glyphBuffer, bool ltr, unsi
if (glyphBuffer->size() <= lastGlyphCount + 1) if (glyphBuffer->size() <= lastGlyphCount + 1)
return 0; return 0;
GlyphBufferAdvance* advances = glyphBuffer->advances(0); FloatSize* advances = glyphBuffer->advances(0);
float widthDifference = 0; float widthDifference = 0;
for (unsigned i = lastGlyphCount; i < glyphBufferSize; ++i) for (unsigned i = lastGlyphCount; i < glyphBufferSize; ++i)
widthDifference -= advances[i].width(); widthDifference -= advances[i].width();
......
...@@ -153,7 +153,7 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, ...@@ -153,7 +153,7 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font,
// text drawing can proceed faster. However, it's unclear when those // text drawing can proceed faster. However, it's unclear when those
// patches may be upstreamed to WebKit so we always use the slower path // patches may be upstreamed to WebKit so we always use the slower path
// here. // here.
const GlyphBufferAdvance* adv = glyphBuffer.advances(from); const FloatSize* adv = glyphBuffer.advances(from);
for (unsigned i = 0; i < numGlyphs; i++) { for (unsigned i = 0; i < numGlyphs; i++) {
pos[i].set(x, y); pos[i].set(x, y);
x += SkFloatToScalar(adv[i].width()); x += SkFloatToScalar(adv[i].width());
......
...@@ -141,9 +141,4 @@ hb_font_t* HarfBuzzFace::createFont() ...@@ -141,9 +141,4 @@ hb_font_t* HarfBuzzFace::createFont()
return font; return font;
} }
GlyphBufferAdvance HarfBuzzShaper::createGlyphBufferAdvance(float width, float height)
{
return CGSizeMake(width, height);
}
} // namespace WebCore } // namespace WebCore
...@@ -235,9 +235,4 @@ hb_font_t* HarfBuzzFace::createFont() ...@@ -235,9 +235,4 @@ hb_font_t* HarfBuzzFace::createFont()
return font; return font;
} }
GlyphBufferAdvance HarfBuzzShaper::createGlyphBufferAdvance(float width, float height)
{
return GlyphBufferAdvance(width, height);
}
} // namespace WebCore } // namespace WebCore
...@@ -946,12 +946,12 @@ void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, Ha ...@@ -946,12 +946,12 @@ void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, Ha
if (currentCharacterIndex >= m_toIndex) if (currentCharacterIndex >= m_toIndex)
m_startOffset.move(glyphAdvanceX, glyphAdvanceY); m_startOffset.move(glyphAdvanceX, glyphAdvanceY);
else if (currentCharacterIndex >= m_fromIndex) else if (currentCharacterIndex >= m_fromIndex)
glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY)); glyphBuffer->add(glyphs[i], currentRun->fontData(), FloatSize(glyphAdvanceX, glyphAdvanceY));
} else { } else {
if (currentCharacterIndex < m_fromIndex) if (currentCharacterIndex < m_fromIndex)
m_startOffset.move(glyphAdvanceX, glyphAdvanceY); m_startOffset.move(glyphAdvanceX, glyphAdvanceY);
else if (currentCharacterIndex < m_toIndex) else if (currentCharacterIndex < m_toIndex)
glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY)); glyphBuffer->add(glyphs[i], currentRun->fontData(), FloatSize(glyphAdvanceX, glyphAdvanceY));
} }
} }
} }
...@@ -1002,7 +1002,7 @@ void HarfBuzzShaper::fillGlyphBufferForTextEmphasis(GlyphBuffer* glyphBuffer, Ha ...@@ -1002,7 +1002,7 @@ void HarfBuzzShaper::fillGlyphBufferForTextEmphasis(GlyphBuffer* glyphBuffer, Ha
for (unsigned j = 0; j < graphemesInCluster; ++j) { for (unsigned j = 0; j < graphemesInCluster; ++j) {
// Do not put emphasis marks on space, separator, and control characters. // Do not put emphasis marks on space, separator, and control characters.
Glyph glyphToAdd = Character::canReceiveTextEmphasis(m_run[currentCharacterIndex]) ? 1 : 0; Glyph glyphToAdd = Character::canReceiveTextEmphasis(m_run[currentCharacterIndex]) ? 1 : 0;
glyphBuffer->add(glyphToAdd, currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, 0)); glyphBuffer->add(glyphToAdd, currentRun->fontData(), glyphAdvanceX);
} }
clusterStart = clusterEnd; clusterStart = clusterEnd;
clusterAdvance = 0; clusterAdvance = 0;
......
...@@ -138,8 +138,6 @@ private: ...@@ -138,8 +138,6 @@ private:
void setGlyphPositionsForHarfBuzzRun(HarfBuzzRun*, hb_buffer_t*); void setGlyphPositionsForHarfBuzzRun(HarfBuzzRun*, hb_buffer_t*);
void addHarfBuzzRun(unsigned startCharacter, unsigned endCharacter, const SimpleFontData*, UScriptCode); void addHarfBuzzRun(unsigned startCharacter, unsigned endCharacter, const SimpleFontData*, UScriptCode);
GlyphBufferAdvance createGlyphBufferAdvance(float, float);
const Font* m_font; const Font* m_font;
OwnPtr<UChar[]> m_normalizedBuffer; OwnPtr<UChar[]> m_normalizedBuffer;
unsigned m_normalizedBufferLength; unsigned m_normalizedBufferLength;
......
...@@ -470,7 +470,7 @@ void ComplexTextController::advance(unsigned offset, GlyphBuffer* glyphBuffer, G ...@@ -470,7 +470,7 @@ void ComplexTextController::advance(unsigned offset, GlyphBuffer* glyphBuffer, G
return; return;
if (glyphBuffer && !m_characterInCurrentGlyph) if (glyphBuffer && !m_characterInCurrentGlyph)
glyphBuffer->add(m_adjustedGlyphs[k], complexTextRun.fontData(), adjustedAdvance); glyphBuffer->add(m_adjustedGlyphs[k], complexTextRun.fontData(), FloatSize(adjustedAdvance));
unsigned oldCharacterInCurrentGlyph = m_characterInCurrentGlyph; unsigned oldCharacterInCurrentGlyph = m_characterInCurrentGlyph;
m_characterInCurrentGlyph = min(m_currentCharacter - complexTextRun.stringLocation(), glyphEndOffset) - glyphStartOffset; m_characterInCurrentGlyph = min(m_currentCharacter - complexTextRun.stringLocation(), glyphEndOffset) - glyphStartOffset;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "wtf/text/WTFString.h" #include "wtf/text/WTFString.h"
#include "wtf/unicode/Unicode.h" #include "wtf/unicode/Unicode.h"
#include "wtf/Vector.h" #include "wtf/Vector.h"
#include <ApplicationServices/ApplicationServices.h>
typedef unsigned short CGGlyph; typedef unsigned short CGGlyph;
......
...@@ -118,7 +118,7 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, ...@@ -118,7 +118,7 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font,
// text drawing can proceed faster. However, it's unclear when those // text drawing can proceed faster. However, it's unclear when those
// patches may be upstreamed to WebKit so we always use the slower path // patches may be upstreamed to WebKit so we always use the slower path
// here. // here.
const GlyphBufferAdvance* adv = glyphBuffer.advances(from); const FloatSize* adv = glyphBuffer.advances(from);
SkAutoSTMalloc<32, SkPoint> storage(numGlyphs); SkAutoSTMalloc<32, SkPoint> storage(numGlyphs);
SkPoint* pos = storage.get(); SkPoint* pos = storage.get();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment