Bug 1422466. Drop a copy from TextDrawTarget::FillGlyphs. r=Gankro

We try hard to ensure that the glyph buffers are of the same type.
This commit is contained in:
Jeff Muizelaar 2017-12-04 13:01:55 -05:00
Родитель 2b2c246e13
Коммит 644c528356
3 изменённых файлов: 24 добавлений и 17 удалений

Просмотреть файл

@ -288,13 +288,12 @@ WriteFontDescriptor(const uint8_t* aData, uint32_t aLength, uint32_t aIndex,
}
void
WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray<wr::GlyphInstance>& aGlyphs,
WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, Range<const wr::GlyphInstance> aGlyphs,
gfx::ScaledFont* aFont, const wr::ColorF& aColor, const StackingContextHelper& aSc,
const wr::LayerRect& aBounds, const wr::LayerRect& aClip, bool aBackfaceVisible,
const wr::GlyphOptions* aGlyphOptions)
{
MOZ_ASSERT(aFont);
MOZ_ASSERT(!aGlyphs.IsEmpty());
wr::WrFontInstanceKey key = GetFontKeyForScaledFont(aFont);
MOZ_ASSERT(key.mNamespace.mHandle && key.mHandle);
@ -304,7 +303,7 @@ WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArra
aBackfaceVisible,
aColor,
key,
Range<const wr::GlyphInstance>(aGlyphs.Elements(), aGlyphs.Length()),
aGlyphs,
aGlyphOptions);
}

Просмотреть файл

@ -130,7 +130,7 @@ public:
return wr::WrImageKey{ GetNamespace(), GetNextResourceId() };
}
void PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray<wr::GlyphInstance>& aGlyphs,
void PushGlyphs(wr::DisplayListBuilder& aBuilder, Range<const wr::GlyphInstance> aGlyphs,
gfx::ScaledFont* aFont, const wr::ColorF& aColor,
const StackingContextHelper& aSc,
const wr::LayerRect& aBounds, const wr::LayerRect& aClip,

Просмотреть файл

@ -105,8 +105,6 @@ public:
MOZ_RELEASE_ASSERT(aOptions.mCompositionOp == CompositionOp::OP_OVER);
MOZ_RELEASE_ASSERT(aOptions.mAlpha == 1.0f);
MOZ_RELEASE_ASSERT(aPattern.GetType() == PatternType::COLOR);
auto* colorPat = static_cast<const ColorPattern*>(&aPattern);
auto color = wr::ToColorF(colorPat->mColor);
// Make sure the font exists, and can be serialized
MOZ_RELEASE_ASSERT(aFont);
@ -115,17 +113,27 @@ public:
return;
}
// 170 is the maximum size gfxFont is expected to hand us
AutoTArray<wr::GlyphInstance, 170> glyphs;
glyphs.SetLength(aBuffer.mNumGlyphs);
for (size_t i = 0; i < aBuffer.mNumGlyphs; i++) {
wr::GlyphInstance& targetGlyph = glyphs[i];
const gfx::Glyph& sourceGlyph = aBuffer.mGlyphs[i];
targetGlyph.index = sourceGlyph.mIndex;
targetGlyph.point = mSc.ToRelativeLayoutPoint(
LayoutDevicePoint::FromUnknownPoint(sourceGlyph.mPosition));
}
auto* colorPat = static_cast<const ColorPattern*>(&aPattern);
auto color = wr::ToColorF(colorPat->mColor);
MOZ_ASSERT(aBuffer.mNumGlyphs);
auto glyphs = Range<const wr::GlyphInstance>(reinterpret_cast<const wr::GlyphInstance*>(aBuffer.mGlyphs), aBuffer.mNumGlyphs);
// MSVC won't let us use offsetof on the following directly so we give it a
// name with typedef
typedef std::remove_reference<decltype(aBuffer.mGlyphs[0])>::type GlyphType;
// Compare gfx::Glyph and wr::GlyphInstance to make sure that they are
// structurally equivalent to ensure that our cast above was ok
static_assert(std::is_same<decltype(aBuffer.mGlyphs[0].mIndex), decltype(glyphs[0].index)>()
&& std::is_same<decltype(aBuffer.mGlyphs[0].mPosition.x), decltype(glyphs[0].point.x)>()
&& std::is_same<decltype(aBuffer.mGlyphs[0].mPosition.y), decltype(glyphs[0].point.y)>()
&& offsetof(GlyphType, mIndex) == offsetof(wr::GlyphInstance, index)
&& offsetof(GlyphType, mPosition) == offsetof(wr::GlyphInstance, point)
&& offsetof(decltype(aBuffer.mGlyphs[0].mPosition), x) == offsetof(decltype(glyphs[0].point), x)
&& offsetof(decltype(aBuffer.mGlyphs[0].mPosition), y) == offsetof(decltype(glyphs[0].point), y)
&& std::is_standard_layout<std::remove_reference<decltype(aBuffer.mGlyphs[0])>>::value
&& std::is_standard_layout<std::remove_reference<decltype(glyphs[0])>>::value
&& sizeof(aBuffer.mGlyphs[0]) == sizeof(glyphs[0])
&& sizeof(aBuffer.mGlyphs[0].mPosition) == sizeof(glyphs[0].point)
, "glyph buf types don't match");
wr::GlyphOptions glyphOptions;
glyphOptions.render_mode = wr::ToFontRenderMode(aOptions.mAntialiasMode, GetPermitSubpixelAA());