diff --git a/gfx/layers/wr/WebRenderBridgeChild.h b/gfx/layers/wr/WebRenderBridgeChild.h --- a/gfx/layers/wr/WebRenderBridgeChild.h +++ b/gfx/layers/wr/WebRenderBridgeChild.h @@ -128,11 +128,11 @@ wr::WrImageKey GetNextImageKey() { 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, bool aBackfaceVisible, const wr::GlyphOptions* aGlyphOptions = nullptr); diff --git a/gfx/layers/wr/WebRenderBridgeChild.cpp b/gfx/layers/wr/WebRenderBridgeChild.cpp --- a/gfx/layers/wr/WebRenderBridgeChild.cpp +++ b/gfx/layers/wr/WebRenderBridgeChild.cpp @@ -286,27 +286,26 @@ sink->mResources->AddFontDescriptor(*sink->mFontKey, Range(const_cast(aData), aLength), 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) { MOZ_ASSERT(aFont); - MOZ_ASSERT(!aGlyphs.IsEmpty()); wr::WrFontInstanceKey key = GetFontKeyForScaledFont(aFont); MOZ_ASSERT(key.mNamespace.mHandle && key.mHandle); aBuilder.PushText(aBounds, aClip, aBackfaceVisible, aColor, key, - Range(aGlyphs.Elements(), aGlyphs.Length()), + aGlyphs, aGlyphOptions); } wr::FontInstanceKey WebRenderBridgeChild::GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont) diff --git a/layout/generic/TextDrawTarget.h b/layout/generic/TextDrawTarget.h --- a/layout/generic/TextDrawTarget.h +++ b/layout/generic/TextDrawTarget.h @@ -103,31 +103,39 @@ { // Make sure we're only given boring color patterns 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); if (!aFont->CanSerialize()) { FoundUnsupportedFeature(); return; } - // 170 is the maximum size gfxFont is expected to hand us - AutoTArray 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(&aPattern); + auto color = wr::ToColorF(colorPat->mColor); + MOZ_ASSERT(aBuffer.mNumGlyphs); + auto glyphs = Range(reinterpret_cast(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::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() + && std::is_same() + && std::is_same() + && 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>::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()); mManager->WrBridge()->PushGlyphs(mBuilder, glyphs, aFont,