From a49417c5ed8357eaf7c1e2084dd46366c3e1213b Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Sat, 2 Dec 2017 13:45:57 -0500 Subject: [PATCH] Bug 1422466. Drop a copy from TextDrawTarget::FillGlyphs. r=Gankro We try hard to ensure that the glyph buffers are of the same type. --HG-- extra : rebase_source : b785541c15ee2d715b549e0c306e5e0669d4ad71 --- gfx/layers/wr/WebRenderBridgeChild.cpp | 4 ++-- gfx/layers/wr/WebRenderBridgeChild.h | 2 +- layout/generic/TextDrawTarget.h | 28 +++++++++++++++----------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/gfx/layers/wr/WebRenderBridgeChild.cpp b/gfx/layers/wr/WebRenderBridgeChild.cpp index 06fb195b7520..de9664fd1ac3 100644 --- a/gfx/layers/wr/WebRenderBridgeChild.cpp +++ b/gfx/layers/wr/WebRenderBridgeChild.cpp @@ -288,7 +288,7 @@ WriteFontDescriptor(const uint8_t* aData, uint32_t aLength, uint32_t aIndex, } void -WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray& aGlyphs, +WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, Range 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) @@ -304,7 +304,7 @@ WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArra aBackfaceVisible, aColor, key, - Range(aGlyphs.Elements(), aGlyphs.Length()), + aGlyphs, aGlyphOptions); } diff --git a/gfx/layers/wr/WebRenderBridgeChild.h b/gfx/layers/wr/WebRenderBridgeChild.h index 25e5f920f25e..929fd03bb275 100644 --- a/gfx/layers/wr/WebRenderBridgeChild.h +++ b/gfx/layers/wr/WebRenderBridgeChild.h @@ -130,7 +130,7 @@ public: return wr::WrImageKey{ GetNamespace(), GetNextResourceId() }; } - void PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray& aGlyphs, + void PushGlyphs(wr::DisplayListBuilder& aBuilder, Range aGlyphs, gfx::ScaledFont* aFont, const wr::ColorF& aColor, const StackingContextHelper& aSc, const wr::LayerRect& aBounds, const wr::LayerRect& aClip, diff --git a/layout/generic/TextDrawTarget.h b/layout/generic/TextDrawTarget.h index 5d0712d57b17..6bb0eeb0b4c4 100644 --- a/layout/generic/TextDrawTarget.h +++ b/layout/generic/TextDrawTarget.h @@ -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(&aPattern); - auto color = wr::ToColorF(colorPat->mColor); // Make sure the font exists, and can be serialized MOZ_RELEASE_ASSERT(aFont); @@ -115,17 +113,23 @@ public: return; } - // 170 is the maximum size gfxFont is expected to hand us - AutoTArray glyphs; - glyphs.SetLength(aBuffer.mNumGlyphs); + auto* colorPat = static_cast(&aPattern); + auto color = wr::ToColorF(colorPat->mColor); + auto glyphs = Range(reinterpret_cast(aBuffer.mGlyphs), 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)); - } + // 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() + && std::is_same() + && std::is_same() + && offsetof(std::remove_reference::type, mIndex) == offsetof(wr::GlyphInstance, index) + && offsetof(std::remove_reference::type, 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::value == std::is_standard_layout::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());