diff --git a/gfx/layers/wr/WebRenderBorderLayer.cpp b/gfx/layers/wr/WebRenderBorderLayer.cpp index 7950cd331435..2db99d0e6b1f 100644 --- a/gfx/layers/wr/WebRenderBorderLayer.cpp +++ b/gfx/layers/wr/WebRenderBorderLayer.cpp @@ -18,7 +18,7 @@ namespace layers { using namespace mozilla::gfx; void -WebRenderBorderLayer::RenderLayer() +WebRenderBorderLayer::RenderLayer(wr::DisplayListBuilder& aBuilder) { WrScrollFrameStackingContextGenerator scrollFrames(this); @@ -54,23 +54,20 @@ WebRenderBorderLayer::RenderLayer() Stringify(clip).c_str()); } - WrBridge()->AddWebRenderCommand( - OpDPPushStackingContext(wr::ToWrRect(relBounds), - wr::ToWrRect(overflow), - Nothing(), - 1.0f, - GetAnimations(), - transform, - WrMixBlendMode::Normal, - FrameMetrics::NULL_SCROLL_ID)); - WrBridge()->AddWebRenderCommand( - OpDPPushBorder(wr::ToWrRect(rect), wr::ToWrRect(clip), - wr::ToWrBorderSide(mWidths[0], mColors[0], mBorderStyles[0]), - wr::ToWrBorderSide(mWidths[1], mColors[1], mBorderStyles[1]), - wr::ToWrBorderSide(mWidths[2], mColors[2], mBorderStyles[2]), - wr::ToWrBorderSide(mWidths[3], mColors[3], mBorderStyles[3]), - wr::ToWrBorderRadius(mCorners[0], mCorners[1], mCorners[3], mCorners[2]))); - WrBridge()->AddWebRenderCommand(OpDPPopStackingContext()); + aBuilder.PushStackingContext(wr::ToWrRect(relBounds), + wr::ToWrRect(overflow), + nullptr, + 1.0f, + //GetAnimations(), + transform, + WrMixBlendMode::Normal); + aBuilder.PushBorder(wr::ToWrRect(rect), wr::ToWrRect(clip), + wr::ToWrBorderSide(mWidths[0], mColors[0], mBorderStyles[0]), + wr::ToWrBorderSide(mWidths[1], mColors[1], mBorderStyles[1]), + wr::ToWrBorderSide(mWidths[2], mColors[2], mBorderStyles[2]), + wr::ToWrBorderSide(mWidths[3], mColors[3], mBorderStyles[3]), + wr::ToWrBorderRadius(mCorners[0], mCorners[1], mCorners[3], mCorners[2])); + aBuilder.PopStackingContext(); } } // namespace layers diff --git a/gfx/layers/wr/WebRenderBorderLayer.h b/gfx/layers/wr/WebRenderBorderLayer.h index fc9f941b11d0..584151e84889 100644 --- a/gfx/layers/wr/WebRenderBorderLayer.h +++ b/gfx/layers/wr/WebRenderBorderLayer.h @@ -29,7 +29,7 @@ protected: public: Layer* GetLayer() override { return this; } - void RenderLayer() override; + void RenderLayer(wr::DisplayListBuilder& aBuilder) override; }; } // namespace layers diff --git a/gfx/layers/wr/WebRenderBridgeChild.cpp b/gfx/layers/wr/WebRenderBridgeChild.cpp index dd210201849b..b93d44b1b942 100644 --- a/gfx/layers/wr/WebRenderBridgeChild.cpp +++ b/gfx/layers/wr/WebRenderBridgeChild.cpp @@ -189,13 +189,11 @@ WebRenderBridgeChild::ProcessWebrenderCommands(const gfx::IntSize &aSize, } } builder.End(); - wr::BuiltDisplayList dl; - builder.Finalize(dl.dl_desc, dl.dl, dl.aux_desc, dl.aux); - return dl; + return builder.Finalize(); } void -WebRenderBridgeChild::DPEnd(const gfx::IntSize& aSize, bool aIsSync, uint64_t aTransactionId) +WebRenderBridgeChild::DPEnd(wr::DisplayListBuilder &aBuilder, const gfx::IntSize& aSize, bool aIsSync, uint64_t aTransactionId) { MOZ_ASSERT(!mDestroyed); MOZ_ASSERT(mIsInTransaction); @@ -209,7 +207,7 @@ WebRenderBridgeChild::DPEnd(const gfx::IntSize& aSize, bool aIsSync, uint64_t aT } } - wr::BuiltDisplayList dl = ProcessWebrenderCommands(aSize, mCommands); + wr::BuiltDisplayList dl = aBuilder.Finalize(); ByteBuffer dlData(Move(dl.dl)); ByteBuffer auxData(Move(dl.aux)); diff --git a/gfx/layers/wr/WebRenderBridgeChild.h b/gfx/layers/wr/WebRenderBridgeChild.h index 85de0a3b730a..0b314d10121d 100644 --- a/gfx/layers/wr/WebRenderBridgeChild.h +++ b/gfx/layers/wr/WebRenderBridgeChild.h @@ -16,6 +16,10 @@ namespace widget { class CompositorWidget; } +namespace wr { +class DisplayListBuilder; +} + namespace layers { class CompositableClient; @@ -36,10 +40,12 @@ public: void AddWebRenderParentCommands(const nsTArray& aCommands); bool DPBegin(const gfx::IntSize& aSize); - void DPEnd(const gfx::IntSize& aSize, bool aIsSync, uint64_t aTransactionId); + void DPEnd(wr::DisplayListBuilder &aBuilder, const gfx::IntSize& aSize, bool aIsSync, uint64_t aTransactionId); CompositorBridgeChild* GetCompositorBridgeChild(); + wr::PipelineId GetPipeline() { return mPipelineId; } + // KnowsCompositor TextureForwarder* GetTextureForwarder() override; LayersIPCActor* GetLayersIPCActor() override; diff --git a/gfx/layers/wr/WebRenderCanvasLayer.cpp b/gfx/layers/wr/WebRenderCanvasLayer.cpp index d584f1157f69..eee46f8f60f0 100644 --- a/gfx/layers/wr/WebRenderCanvasLayer.cpp +++ b/gfx/layers/wr/WebRenderCanvasLayer.cpp @@ -46,7 +46,7 @@ WebRenderCanvasLayer::Initialize(const Data& aData) } void -WebRenderCanvasLayer::RenderLayer() +WebRenderCanvasLayer::RenderLayer(wr::DisplayListBuilder& aBuilder) { UpdateCompositableClient(); @@ -98,21 +98,20 @@ WebRenderCanvasLayer::RenderLayer() Stringify(mixBlendMode).c_str()); } - WrBridge()->AddWebRenderCommand( - OpDPPushStackingContext(wr::ToWrRect(relBounds), - wr::ToWrRect(overflow), - mask, - 1.0f, - GetAnimations(), - transform, - mixBlendMode, - FrameMetrics::NULL_SCROLL_ID)); WrImageKey key; key.mNamespace = WrBridge()->GetNamespace(); key.mHandle = WrBridge()->GetNextResourceId(); WrBridge()->AddWebRenderParentCommand(OpAddExternalImage(mExternalImageId, key)); - WrBridge()->AddWebRenderCommand(OpDPPushImage(wr::ToWrRect(rect), wr::ToWrRect(clip), Nothing(), filter, key)); - WrBridge()->AddWebRenderCommand(OpDPPopStackingContext()); + + aBuilder.PushStackingContext(wr::ToWrRect(relBounds), + wr::ToWrRect(overflow), + mask.ptrOr(nullptr), + 1.0f, + //GetAnimations(), + transform, + mixBlendMode); + aBuilder.PushImage(wr::ToWrRect(rect), wr::ToWrRect(clip), nullptr, filter, key); + aBuilder.PopStackingContext(); } void diff --git a/gfx/layers/wr/WebRenderCanvasLayer.h b/gfx/layers/wr/WebRenderCanvasLayer.h index 64eac3a262dd..4dda861f2966 100644 --- a/gfx/layers/wr/WebRenderCanvasLayer.h +++ b/gfx/layers/wr/WebRenderCanvasLayer.h @@ -45,7 +45,7 @@ protected: public: Layer* GetLayer() override { return this; } - void RenderLayer() override; + void RenderLayer(wr::DisplayListBuilder& aBuilder) override; protected: uint64_t mExternalImageId; diff --git a/gfx/layers/wr/WebRenderColorLayer.cpp b/gfx/layers/wr/WebRenderColorLayer.cpp index df1942f83538..143ee9399e85 100644 --- a/gfx/layers/wr/WebRenderColorLayer.cpp +++ b/gfx/layers/wr/WebRenderColorLayer.cpp @@ -17,7 +17,7 @@ namespace layers { using namespace mozilla::gfx; void -WebRenderColorLayer::RenderLayer() +WebRenderColorLayer::RenderLayer(wr::DisplayListBuilder& aBuilder) { WrScrollFrameStackingContextGenerator scrollFrames(this); @@ -58,18 +58,15 @@ WebRenderColorLayer::RenderLayer() Stringify(mixBlendMode).c_str()); } - WrBridge()->AddWebRenderCommand( - OpDPPushStackingContext(wr::ToWrRect(relBounds), + aBuilder.PushStackingContext(wr::ToWrRect(relBounds), wr::ToWrRect(overflow), - mask, + mask.ptrOr(nullptr), 1.0f, - GetAnimations(), + //GetAnimations(), transform, - mixBlendMode, - FrameMetrics::NULL_SCROLL_ID)); - WrBridge()->AddWebRenderCommand( - OpDPPushRect(wr::ToWrRect(rect), wr::ToWrRect(clip), wr::ToWrColor(mColor))); - WrBridge()->AddWebRenderCommand(OpDPPopStackingContext()); + mixBlendMode); + aBuilder.PushRect(wr::ToWrRect(rect), wr::ToWrRect(clip), wr::ToWrColor(mColor)); + aBuilder.PopStackingContext(); } } // namespace layers diff --git a/gfx/layers/wr/WebRenderColorLayer.h b/gfx/layers/wr/WebRenderColorLayer.h index 31e9f76f1bfc..45fc248c8d55 100644 --- a/gfx/layers/wr/WebRenderColorLayer.h +++ b/gfx/layers/wr/WebRenderColorLayer.h @@ -29,7 +29,7 @@ protected: public: Layer* GetLayer() override { return this; } - void RenderLayer() override; + void RenderLayer(wr::DisplayListBuilder& aBuilder) override; }; } // namespace layers diff --git a/gfx/layers/wr/WebRenderContainerLayer.cpp b/gfx/layers/wr/WebRenderContainerLayer.cpp index 7ed810b9ab2f..4cb33300ce79 100644 --- a/gfx/layers/wr/WebRenderContainerLayer.cpp +++ b/gfx/layers/wr/WebRenderContainerLayer.cpp @@ -15,7 +15,7 @@ namespace mozilla { namespace layers { void -WebRenderContainerLayer::RenderLayer() +WebRenderContainerLayer::RenderLayer(wr::DisplayListBuilder& aBuilder) { WrScrollFrameStackingContextGenerator scrollFrames(this); @@ -43,28 +43,24 @@ WebRenderContainerLayer::RenderLayer() Stringify(transform).c_str(), Stringify(mixBlendMode).c_str()); } - - WrBridge()->AddWebRenderCommand( - OpDPPushStackingContext(wr::ToWrRect(relBounds), - wr::ToWrRect(overflow), - mask, - GetLocalOpacity(), - GetLayer()->GetAnimations(), - transform, - mixBlendMode, - FrameMetrics::NULL_SCROLL_ID)); + aBuilder.PushStackingContext(wr::ToWrRect(relBounds), + wr::ToWrRect(overflow), + mask.ptrOr(nullptr), + GetLocalOpacity(), + //GetLayer()->GetAnimations(), + transform, + mixBlendMode); for (LayerPolygon& child : children) { if (child.layer->IsBackfaceHidden()) { continue; } - ToWebRenderLayer(child.layer)->RenderLayer(); + ToWebRenderLayer(child.layer)->RenderLayer(aBuilder); } - WrBridge()->AddWebRenderCommand( - OpDPPopStackingContext()); + aBuilder.PopStackingContext(); } void -WebRenderRefLayer::RenderLayer() +WebRenderRefLayer::RenderLayer(wr::DisplayListBuilder& aBuilder) { WrScrollFrameStackingContextGenerator scrollFrames(this); @@ -79,7 +75,7 @@ WebRenderRefLayer::RenderLayer() Stringify(transform).c_str()); } - WrBridge()->AddWebRenderCommand(OpDPPushIframe(wr::ToWrRect(relBounds), wr::ToWrRect(relBounds), wr::AsPipelineId(mId))); + aBuilder.PushIFrame(wr::ToWrRect(relBounds), wr::ToWrRect(relBounds), wr::AsPipelineId(mId)); } } // namespace layers diff --git a/gfx/layers/wr/WebRenderContainerLayer.h b/gfx/layers/wr/WebRenderContainerLayer.h index b5bbcdca021a..5aac77868e29 100644 --- a/gfx/layers/wr/WebRenderContainerLayer.h +++ b/gfx/layers/wr/WebRenderContainerLayer.h @@ -31,7 +31,7 @@ protected: public: Layer* GetLayer() override { return this; } - void RenderLayer() override; + void RenderLayer(wr::DisplayListBuilder& aBuilder) override; virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override { @@ -56,7 +56,7 @@ protected: public: Layer* GetLayer() override { return this; } - void RenderLayer() override; + void RenderLayer(wr::DisplayListBuilder& aBuilder) override; virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override { diff --git a/gfx/layers/wr/WebRenderDisplayItemLayer.cpp b/gfx/layers/wr/WebRenderDisplayItemLayer.cpp index d3888f11ca88..180bd24fe9ee 100644 --- a/gfx/layers/wr/WebRenderDisplayItemLayer.cpp +++ b/gfx/layers/wr/WebRenderDisplayItemLayer.cpp @@ -16,18 +16,19 @@ namespace mozilla { namespace layers { void -WebRenderDisplayItemLayer::RenderLayer() +WebRenderDisplayItemLayer::RenderLayer(wr::DisplayListBuilder& aBuilder) { if (mItem) { + wr::DisplayListBuilder builder(WrBridge()->GetPipeline()); // We might have recycled this layer. Throw away the old commands. - mCommands.Clear(); mParentCommands.Clear(); - mItem->CreateWebRenderCommands(mCommands, mParentCommands, this); + mItem->CreateWebRenderCommands(builder, mParentCommands, this); + mBuiltDisplayList = builder.Finalize(); } // else we have an empty transaction and just use the // old commands. - WrBridge()->AddWebRenderCommands(mCommands); + aBuilder.PushBuiltDisplayList(Move(mBuiltDisplayList)); WrBridge()->AddWebRenderParentCommands(mParentCommands); } diff --git a/gfx/layers/wr/WebRenderDisplayItemLayer.h b/gfx/layers/wr/WebRenderDisplayItemLayer.h index de0be8b02866..cdf22e2d7286 100644 --- a/gfx/layers/wr/WebRenderDisplayItemLayer.h +++ b/gfx/layers/wr/WebRenderDisplayItemLayer.h @@ -29,16 +29,15 @@ public: protected: virtual ~WebRenderDisplayItemLayer() { - mCommands.Clear(); MOZ_COUNT_DTOR(WebRenderDisplayItemLayer); } public: Layer* GetLayer() override { return this; } - void RenderLayer() override; + void RenderLayer(wr::DisplayListBuilder& aBuilder) override; private: - nsTArray mCommands; + wr::BuiltDisplayList mBuiltDisplayList; nsTArray mParentCommands; RefPtr mImageClient; RefPtr mImageContainer; diff --git a/gfx/layers/wr/WebRenderImageLayer.cpp b/gfx/layers/wr/WebRenderImageLayer.cpp index ad44036534cd..57a502fbd69f 100644 --- a/gfx/layers/wr/WebRenderImageLayer.cpp +++ b/gfx/layers/wr/WebRenderImageLayer.cpp @@ -80,7 +80,7 @@ WebRenderImageLayer::ClearCachedResources() } void -WebRenderImageLayer::RenderLayer() +WebRenderImageLayer::RenderLayer(wr::DisplayListBuilder& aBuilder) { if (!mContainer) { return; @@ -165,21 +165,20 @@ WebRenderImageLayer::RenderLayer() Stringify(mixBlendMode).c_str()); } - WrBridge()->AddWebRenderCommand( - OpDPPushStackingContext(wr::ToWrRect(relBounds), - wr::ToWrRect(overflow), - mask, - 1.0f, - GetAnimations(), - transform, - mixBlendMode, - FrameMetrics::NULL_SCROLL_ID)); WrImageKey key; key.mNamespace = WrBridge()->GetNamespace(); key.mHandle = WrBridge()->GetNextResourceId(); WrBridge()->AddWebRenderParentCommand(OpAddExternalImage(mExternalImageId, key)); - WrBridge()->AddWebRenderCommand(OpDPPushImage(wr::ToWrRect(rect), wr::ToWrRect(clip), Nothing(), filter, key)); - WrBridge()->AddWebRenderCommand(OpDPPopStackingContext()); + + aBuilder.PushStackingContext(wr::ToWrRect(relBounds), + wr::ToWrRect(overflow), + mask.ptrOr(nullptr), + 1.0f, + //GetAnimations(), + transform, + mixBlendMode); + aBuilder.PushImage(wr::ToWrRect(rect), wr::ToWrRect(clip), nullptr, filter, key); + aBuilder.PopStackingContext(); //mContainer->SetImageFactory(originalIF); } diff --git a/gfx/layers/wr/WebRenderImageLayer.h b/gfx/layers/wr/WebRenderImageLayer.h index 2252612a58f2..96aab5fe7103 100644 --- a/gfx/layers/wr/WebRenderImageLayer.h +++ b/gfx/layers/wr/WebRenderImageLayer.h @@ -32,7 +32,7 @@ protected: public: Layer* GetLayer() override { return this; } - void RenderLayer() override; + void RenderLayer(wr::DisplayListBuilder& aBuilder) override; protected: CompositableType GetImageClientType(); diff --git a/gfx/layers/wr/WebRenderLayerManager.cpp b/gfx/layers/wr/WebRenderLayerManager.cpp index 309139358830..3faa0fe94681 100644 --- a/gfx/layers/wr/WebRenderLayerManager.cpp +++ b/gfx/layers/wr/WebRenderLayerManager.cpp @@ -317,12 +317,13 @@ WebRenderLayerManager::EndTransaction(DrawPaintedLayerCallback aCallback, return; } - WebRenderLayer::ToWebRenderLayer(mRoot)->RenderLayer(); + wr::DisplayListBuilder builder(WrBridge()->GetPipeline()); + WebRenderLayer::ToWebRenderLayer(mRoot)->RenderLayer(builder); bool sync = mTarget != nullptr; mLatestTransactionId = mTransactionIdAllocator->GetTransactionId(); - WrBridge()->DPEnd(size.ToUnknownSize(), sync, mLatestTransactionId); + WrBridge()->DPEnd(builder, size.ToUnknownSize(), sync, mLatestTransactionId); MakeSnapshotIfRequired(size); diff --git a/gfx/layers/wr/WebRenderLayerManager.h b/gfx/layers/wr/WebRenderLayerManager.h index 907b122d8e88..f9a847234f02 100644 --- a/gfx/layers/wr/WebRenderLayerManager.h +++ b/gfx/layers/wr/WebRenderLayerManager.h @@ -11,6 +11,7 @@ #include "mozilla/layers/TransactionIdAllocator.h" #include "mozilla/webrender/webrender_ffi.h" #include "mozilla/webrender/WebRenderTypes.h" +#include "mozilla/webrender/WebRenderAPI.h" class nsIWidget; @@ -28,7 +29,7 @@ class WebRenderLayer { public: virtual Layer* GetLayer() = 0; - virtual void RenderLayer() = 0; + virtual void RenderLayer(wr::DisplayListBuilder& aBuilder) = 0; virtual already_AddRefed GetAsSourceSurface() { return nullptr; } static inline WebRenderLayer* diff --git a/gfx/layers/wr/WebRenderPaintedLayer.cpp b/gfx/layers/wr/WebRenderPaintedLayer.cpp index 30c4cef40f49..67e1727076bb 100644 --- a/gfx/layers/wr/WebRenderPaintedLayer.cpp +++ b/gfx/layers/wr/WebRenderPaintedLayer.cpp @@ -114,7 +114,7 @@ WebRenderPaintedLayer::RenderLayerWithReadback(ReadbackProcessor *aReadback) } void -WebRenderPaintedLayer::RenderLayer() +WebRenderPaintedLayer::RenderLayer(wr::DisplayListBuilder& aBuilder) { // XXX We won't keep using ContentClient for WebRenderPaintedLayer in the future and // there is a crash problem for ContentClient on MacOS. So replace ContentClient with @@ -224,21 +224,19 @@ WebRenderPaintedLayer::RenderLayer() Stringify(mixBlendMode).c_str()); } - WrBridge()->AddWebRenderCommand( - OpDPPushStackingContext(wr::ToWrRect(relBounds), - wr::ToWrRect(overflow), - mask, - 1.0f, - GetAnimations(), - transform, - mixBlendMode, - FrameMetrics::NULL_SCROLL_ID)); WrImageKey key; key.mNamespace = WrBridge()->GetNamespace(); key.mHandle = WrBridge()->GetNextResourceId(); WrBridge()->AddWebRenderParentCommand(OpAddExternalImage(mExternalImageId, key)); - WrBridge()->AddWebRenderCommand(OpDPPushImage(wr::ToWrRect(rect), wr::ToWrRect(clip), Nothing(), wr::ImageRendering::Auto, key)); - WrBridge()->AddWebRenderCommand(OpDPPopStackingContext()); + aBuilder.PushStackingContext(wr::ToWrRect(relBounds), + wr::ToWrRect(overflow), + mask.ptrOr(nullptr), + 1.0f, + //GetAnimations(), + transform, + mixBlendMode); + aBuilder.PushImage(wr::ToWrRect(rect), wr::ToWrRect(clip), nullptr, wr::ImageRendering::Auto, key); + aBuilder.PopStackingContext(); } } // namespace layers diff --git a/gfx/layers/wr/WebRenderPaintedLayer.h b/gfx/layers/wr/WebRenderPaintedLayer.h index 63893182a05b..4867762d6f30 100644 --- a/gfx/layers/wr/WebRenderPaintedLayer.h +++ b/gfx/layers/wr/WebRenderPaintedLayer.h @@ -51,7 +51,7 @@ public: } Layer* GetLayer() override { return this; } - void RenderLayer() override; + void RenderLayer(wr::DisplayListBuilder& aBuilder) override; void PaintThebes(nsTArray* aReadbackUpdates); void RenderLayerWithReadback(ReadbackProcessor *aReadback); RefPtr mContentClient; diff --git a/gfx/layers/wr/WebRenderTextLayer.cpp b/gfx/layers/wr/WebRenderTextLayer.cpp index 566f74e88c3b..83f6f1afea31 100644 --- a/gfx/layers/wr/WebRenderTextLayer.cpp +++ b/gfx/layers/wr/WebRenderTextLayer.cpp @@ -18,7 +18,7 @@ namespace layers { using namespace mozilla::gfx; void -WebRenderTextLayer::RenderLayer() +WebRenderTextLayer::RenderLayer(wr::DisplayListBuilder& aBuilder) { if (mBounds.IsEmpty()) { return; @@ -39,10 +39,8 @@ WebRenderTextLayer::RenderLayer() Stringify(clip).c_str()); } - nsTArray commands; - mGlyphHelper.BuildWebRenderCommands(WrBridge(), commands, mGlyphs, mFont, + mGlyphHelper.BuildWebRenderCommands(WrBridge(), aBuilder, mGlyphs, mFont, GetOffsetToParent(), rect, clip); - WrBridge()->AddWebRenderCommands(commands); } } // namespace layers diff --git a/gfx/layers/wr/WebRenderTextLayer.h b/gfx/layers/wr/WebRenderTextLayer.h index 74a41f93924c..889ed49c49a2 100644 --- a/gfx/layers/wr/WebRenderTextLayer.h +++ b/gfx/layers/wr/WebRenderTextLayer.h @@ -31,7 +31,7 @@ protected: public: Layer* GetLayer() override { return this; } - void RenderLayer() override; + void RenderLayer(wr::DisplayListBuilder& aBuilder) override; protected: gfx::WebRenderGlyphHelper mGlyphHelper; @@ -40,4 +40,4 @@ protected: } // namespace layers } // namespace mozilla -#endif // GFX_WEBRENDERTEXTLAYER_H \ No newline at end of file +#endif // GFX_WEBRENDERTEXTLAYER_H diff --git a/gfx/thebes/gfxUtils.cpp b/gfx/thebes/gfxUtils.cpp index fbff24b85d5e..c68b82f8916e 100644 --- a/gfx/thebes/gfxUtils.cpp +++ b/gfx/thebes/gfxUtils.cpp @@ -27,6 +27,7 @@ #include "mozilla/UniquePtrExtensions.h" #include "mozilla/Vector.h" #include "mozilla/webrender/WebRenderTypes.h" +#include "mozilla/webrender/WebRenderAPI.h" #include "mozilla/layers/WebRenderBridgeChild.h" #include "nsComponentManagerUtils.h" #include "nsIClipboardHelper.h" @@ -1460,7 +1461,7 @@ WriteFontFileData(const uint8_t* aData, uint32_t aLength, uint32_t aIndex, void WebRenderGlyphHelper::BuildWebRenderCommands(WebRenderBridgeChild* aBridge, - nsTArray& aCommands, + wr::DisplayListBuilder& aBuilder, const nsTArray& aGlyphs, ScaledFont* aFont, const Point& aOffset, @@ -1481,30 +1482,26 @@ WebRenderGlyphHelper::BuildWebRenderCommands(WebRenderBridgeChild* aBridge, aBridge->SendAddRawFont(key, fontBuffer, mIndex); - nsTArray wr_glyphs; - wr_glyphs.SetLength(aGlyphs.Length()); - for (size_t i = 0; i < aGlyphs.Length(); i++) { GlyphArray glyph_array = aGlyphs[i]; nsTArray& glyphs = glyph_array.glyphs(); - nsTArray& wr_glyph_instances = wr_glyphs[i].glyphs; + nsTArray wr_glyph_instances; wr_glyph_instances.SetLength(glyphs.Length()); - wr_glyphs[i].color = glyph_array.color().value(); for (size_t j = 0; j < glyphs.Length(); j++) { wr_glyph_instances[j].index = glyphs[j].mIndex; wr_glyph_instances[j].x = glyphs[j].mPosition.x - aOffset.x; wr_glyph_instances[j].y = glyphs[j].mPosition.y - aOffset.y; } - } + aBuilder.PushText(wr::ToWrRect(aBounds), + wr::ToWrRect(aClip), + glyph_array.color().value(), + key, + Range(wr_glyph_instances.Elements(), wr_glyph_instances.Length()), + mGlyphSize); - aCommands.AppendElement(OpDPPushText( - wr::ToWrRect(aBounds), - wr::ToWrRect(aClip), - wr_glyphs, - mGlyphSize, - key)); + } } } // namespace gfx diff --git a/gfx/thebes/gfxUtils.h b/gfx/thebes/gfxUtils.h index 1d34d092f5d8..313571b966b6 100644 --- a/gfx/thebes/gfxUtils.h +++ b/gfx/thebes/gfxUtils.h @@ -35,6 +35,9 @@ class WebRenderCommand; namespace image { class ImageRegion; } // namespace image +namespace wr { +class DisplayListBuilder; +} // namespace wr } // namespace mozilla class gfxUtils { @@ -328,7 +331,7 @@ public: } void BuildWebRenderCommands(layers::WebRenderBridgeChild* aChild, - nsTArray& aCommands, + wr::DisplayListBuilder& aBuilder, const nsTArray& aGlyphs, ScaledFont* aFont, const Point& aOffset, diff --git a/gfx/webrender_bindings/WebRenderAPI.cpp b/gfx/webrender_bindings/WebRenderAPI.cpp index 414882433cf3..c1f7ab338038 100644 --- a/gfx/webrender_bindings/WebRenderAPI.cpp +++ b/gfx/webrender_bindings/WebRenderAPI.cpp @@ -384,17 +384,16 @@ DisplayListBuilder::End() wr_dp_end(mWrState); } -void -DisplayListBuilder::Finalize(WrBuiltDisplayListDescriptor& dl_descriptor, - wr::VecU8& dl_data, - WrAuxiliaryListsDescriptor& aux_descriptor, - wr::VecU8& aux_data) +BuiltDisplayList +DisplayListBuilder::Finalize() { - wr_api_finalize_builder(mWrState, - dl_descriptor, - dl_data.inner, - aux_descriptor, - aux_data.inner); + BuiltDisplayList dl; + wr_api_finalize_builder(mWrState, + dl.dl_desc, + dl.dl.inner, + dl.aux_desc, + dl.aux.inner); + return dl; } void @@ -415,6 +414,16 @@ DisplayListBuilder::PopStackingContext() wr_dp_pop_stacking_context(mWrState); } +void +DisplayListBuilder::PushBuiltDisplayList(BuiltDisplayList dl) +{ + wr_dp_push_built_display_list(mWrState, + dl.dl_desc, + dl.dl.Extract(), + dl.aux_desc, + dl.aux.Extract()); +} + void DisplayListBuilder::PushScrollLayer(const WrRect& aBounds, const WrRect& aOverflow, diff --git a/gfx/webrender_bindings/WebRenderAPI.h b/gfx/webrender_bindings/WebRenderAPI.h index a40e56bdc3c9..9c94b29dcff4 100644 --- a/gfx/webrender_bindings/WebRenderAPI.h +++ b/gfx/webrender_bindings/WebRenderAPI.h @@ -11,6 +11,7 @@ #include "mozilla/Range.h" #include "mozilla/webrender/webrender_ffi.h" #include "mozilla/webrender/WebRenderTypes.h" +#include "GLTypes.h" #include "Units.h" namespace mozilla { @@ -127,10 +128,7 @@ public: void Begin(const LayerIntSize& aSize); void End(); - void Finalize(WrBuiltDisplayListDescriptor& dl_descriptor, - wr::VecU8& dl_data, - WrAuxiliaryListsDescriptor& aux_descriptor, - wr::VecU8& aux_data); + wr::BuiltDisplayList Finalize(); void PushStackingContext(const WrRect& aBounds, // TODO: We should work with strongly typed rects const WrRect& aOverflow, @@ -141,6 +139,8 @@ public: void PopStackingContext(); + void PushBuiltDisplayList(wr::BuiltDisplayList dl); + void PushScrollLayer(const WrRect& aBounds, // TODO: We should work with strongly typed rects const WrRect& aOverflow, const WrImageMask* aMask); // TODO: needs a wrapper. diff --git a/gfx/webrender_bindings/WebRenderTypes.h b/gfx/webrender_bindings/WebRenderTypes.h index 1e9480ed88e1..68daddbdba62 100644 --- a/gfx/webrender_bindings/WebRenderTypes.h +++ b/gfx/webrender_bindings/WebRenderTypes.h @@ -258,6 +258,22 @@ struct VecU8 { src.inner.capacity = 0; } + VecU8& + operator=(VecU8&& src) { + inner = src.inner; + src.inner.data = nullptr; + src.inner.capacity = 0; + return *this; + } + + WrVecU8 + Extract() { + WrVecU8 ret = inner; + inner.data = nullptr; + inner.capacity = 0; + return ret; + } + ~VecU8() { if (inner.data) { wr_vec_u8_free(inner); diff --git a/gfx/webrender_bindings/src/bindings.rs b/gfx/webrender_bindings/src/bindings.rs index cc6a2f2518fe..b72fa07f9706 100644 --- a/gfx/webrender_bindings/src/bindings.rs +++ b/gfx/webrender_bindings/src/bindings.rs @@ -221,6 +221,22 @@ pub unsafe extern fn wr_api_finalize_builder(state: &mut WrState, *aux_descriptor = aux.descriptor().clone(); } +#[no_mangle] +pub unsafe extern fn wr_dp_push_built_display_list(state: &mut WrState, + dl_descriptor: BuiltDisplayListDescriptor, + dl_data: WrVecU8, + aux_descriptor: AuxiliaryListsDescriptor, + aux_data: WrVecU8) +{ + let dl_vec = dl_data.to_vec(); + let aux_vec = aux_data.to_vec(); + + let dl = BuiltDisplayList::from_data(dl_vec, dl_descriptor); + let aux = AuxiliaryLists::from_data(aux_vec, aux_descriptor); + + state.frame_builder.dl_builder.push_built_display_list(dl, aux); +} + #[no_mangle] pub unsafe extern fn wr_api_set_root_display_list(api: &mut RenderApi, epoch: Epoch, diff --git a/gfx/webrender_bindings/webrender_ffi.h b/gfx/webrender_bindings/webrender_ffi.h index 10746a98b442..b503e241bb5b 100644 --- a/gfx/webrender_bindings/webrender_ffi.h +++ b/gfx/webrender_bindings/webrender_ffi.h @@ -603,6 +603,14 @@ wr_api_finalize_builder(WrState* wrState, WrVecU8& aux_data) WR_FUNC; +WR_INLINE void +wr_dp_push_built_display_list(WrState* wrState, + WrBuiltDisplayListDescriptor dl_descriptor, + WrVecU8 dl_data, + WrAuxiliaryListsDescriptor aux_descriptor, + WrVecU8 aux_data) +WR_FUNC; + WR_INLINE void wr_vec_u8_free(WrVecU8 dl_data) WR_FUNC; diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp index e0989d409370..0cec257be4c6 100644 --- a/layout/generic/nsBulletFrame.cpp +++ b/layout/generic/nsBulletFrame.cpp @@ -228,7 +228,7 @@ public: void CreateWebRenderCommands(nsDisplayItem* aItem, - nsTArray& aCommands, + wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, layers::WebRenderDisplayItemLayer* aLayer); @@ -275,18 +275,18 @@ public: private: void CreateWebRenderCommandsForImage(nsDisplayItem* aItem, - nsTArray& aCommands, + wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, layers::WebRenderDisplayItemLayer* aLayer); void CreateWebRenderCommandsForPath(nsDisplayItem* aItem, - nsTArray& aCommands, + wr::DisplayListBuilder& aBuilder, layers::WebRenderDisplayItemLayer* aLayer); void CreateWebRenderCommandsForText(nsDisplayItem* aItem, - nsTArray& aCommands, + wr::DisplayListBuilder& aBuilder, layers::WebRenderDisplayItemLayer* aLayer); private: @@ -317,17 +317,17 @@ private: void BulletRenderer::CreateWebRenderCommands(nsDisplayItem* aItem, - nsTArray& aCommands, + wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, layers::WebRenderDisplayItemLayer* aLayer) { if (IsImageType()) { - CreateWebRenderCommandsForImage(aItem, aCommands, aParentCommands, aLayer); + CreateWebRenderCommandsForImage(aItem, aBuilder, aParentCommands, aLayer); } else if (IsPathType()) { - CreateWebRenderCommandsForPath(aItem, aCommands, aLayer); + CreateWebRenderCommandsForPath(aItem, aBuilder, aLayer); } else { MOZ_ASSERT(IsTextType()); - CreateWebRenderCommandsForText(aItem, aCommands, aLayer); + CreateWebRenderCommandsForText(aItem, aBuilder, aLayer); } } @@ -435,7 +435,7 @@ BulletRenderer::IsImageContainerAvailable(layers::LayerManager* aManager, uint32 void BulletRenderer::CreateWebRenderCommandsForImage(nsDisplayItem* aItem, - nsTArray& aCommands, + wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, layers::WebRenderDisplayItemLayer* aLayer) { @@ -471,19 +471,16 @@ BulletRenderer::CreateWebRenderCommandsForImage(nsDisplayItem* aItem, aParentCommands.AppendElement(layers::OpAddExternalImage( externalImageId, key)); - aCommands.AppendElement(layers::OpDPPushImage( - wr::ToWrRect(dest), - wr::ToWrRect(dest), - Nothing(), - WrImageRendering::Auto, - key)); - - + aBuilder.PushImage(wr::ToWrRect(dest), + wr::ToWrRect(dest), + nullptr, + WrImageRendering::Auto, + key); } void BulletRenderer::CreateWebRenderCommandsForPath(nsDisplayItem* aItem, - nsTArray& aCommands, + wr::DisplayListBuilder& aBuilder, layers::WebRenderDisplayItemLayer* aLayer) { MOZ_ASSERT(IsPathType()); @@ -493,7 +490,7 @@ BulletRenderer::CreateWebRenderCommandsForPath(nsDisplayItem* aItem, void BulletRenderer::CreateWebRenderCommandsForText(nsDisplayItem* aItem, - nsTArray& aCommands, + wr::DisplayListBuilder& aBuilder, layers::WebRenderDisplayItemLayer* aLayer) { MOZ_ASSERT(IsTextType()); @@ -508,7 +505,7 @@ BulletRenderer::CreateWebRenderCommandsForText(nsDisplayItem* aItem, NSRectToRect(aItem->GetBounds(builder, &dummy), appUnitsPerDevPixel); Rect destRectTransformed = aLayer->RelativeToParent(destRect); - mGlyphHelper.BuildWebRenderCommands(layer->WrBridge(), aCommands, mGlyphs, mFont, aLayer->GetOffsetToParent(), + mGlyphHelper.BuildWebRenderCommands(layer->WrBridge(), aBuilder, mGlyphs, mFont, aLayer->GetOffsetToParent(), destRectTransformed, destRectTransformed); } @@ -541,7 +538,7 @@ public: LayerManager* aManager, const ContainerLayerParameters& aParameters) override; - virtual void CreateWebRenderCommands(nsTArray& aCommands, + virtual void CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, layers::WebRenderDisplayItemLayer* aLayer) override; @@ -655,14 +652,14 @@ nsDisplayBullet::BuildLayer(nsDisplayListBuilder* aBuilder, } void -nsDisplayBullet::CreateWebRenderCommands(nsTArray& aCommands, +nsDisplayBullet::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, layers::WebRenderDisplayItemLayer* aLayer) { if (!mBulletRenderer) return; - mBulletRenderer->CreateWebRenderCommands(this, aCommands, aParentCommands, aLayer); + mBulletRenderer->CreateWebRenderCommands(this, aBuilder, aParentCommands, aLayer); } void nsDisplayBullet::Paint(nsDisplayListBuilder* aBuilder, diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index b1f583d7bd8c..25ce4c990cc0 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -4147,7 +4147,7 @@ nsDisplayOutline::BuildLayer(nsDisplayListBuilder* aBuilder, } void -nsDisplayOutline::CreateWebRenderCommands(nsTArray& aCommands, +nsDisplayOutline::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, WebRenderDisplayItemLayer* aLayer) { @@ -4164,10 +4164,10 @@ nsDisplayOutline::CreateWebRenderCommands(nsTArray& aCommands, LayerSize(br->mBorderRadii[1].width, br->mBorderRadii[1].height), LayerSize(br->mBorderRadii[3].width, br->mBorderRadii[3].height), LayerSize(br->mBorderRadii[2].width, br->mBorderRadii[2].height)); - aCommands.AppendElement(OpDPPushBorder(wr::ToWrRect(outlineTransformedRect), - wr::ToWrRect(outlineTransformedRect), - side[0], side[1], side[2], side[3], - borderRadius)); + aBuilder.PushBorder(wr::ToWrRect(outlineTransformedRect), + wr::ToWrRect(outlineTransformedRect), + side[0], side[1], side[2], side[3], + borderRadius); } bool @@ -4427,7 +4427,7 @@ nsDisplayCaret::Paint(nsDisplayListBuilder* aBuilder, } void -nsDisplayCaret::CreateWebRenderCommands(nsTArray& aCommands, +nsDisplayCaret::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, WebRenderDisplayItemLayer* aLayer) { using namespace mozilla::layers; @@ -4457,16 +4457,14 @@ nsDisplayCaret::CreateWebRenderCommands(nsTArray& aCommands, IntRect hook = RoundedToInt(hookTransformedRect); // Note, WR will pixel snap anything that is layout aligned. - aCommands.AppendElement(OpDPPushRect( - wr::ToWrRect(caret), - wr::ToWrRect(caret), - wr::ToWrColor(color))); + aBuilder.PushRect(wr::ToWrRect(caret), + wr::ToWrRect(caret), + wr::ToWrColor(color)); if (!devHookRect.IsEmpty()) { - aCommands.AppendElement(OpDPPushRect( - wr::ToWrRect(hook), - wr::ToWrRect(hook), - wr::ToWrColor(color))); + aBuilder.PushRect(wr::ToWrRect(hook), + wr::ToWrRect(hook), + wr::ToWrColor(color)); } } @@ -4836,7 +4834,7 @@ nsDisplayBoxShadowOuter::BuildLayer(nsDisplayListBuilder* aBuilder, } void -nsDisplayBoxShadowOuter::CreateWebRenderCommands(nsTArray& aCommands, +nsDisplayBoxShadowOuter::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, WebRenderDisplayItemLayer* aLayer) { @@ -4902,17 +4900,15 @@ nsDisplayBoxShadowOuter::CreateWebRenderCommands(nsTArray& aCo : 0.0; float spreadRadius = float(shadow->mSpread) / float(appUnitsPerDevPixel); - aCommands.AppendElement(OpDPPushBoxShadow( - wr::ToWrRect(deviceBoxRect), - wr::ToWrRect(deviceClipRect), - wr::ToWrRect(deviceBoxRect), - wr::ToWrPoint(shadowOffset), - wr::ToWrColor(shadowColor), - blurRadius, - spreadRadius, - borderRadius, - WrBoxShadowClipMode::Outset - )); + aBuilder.PushBoxShadow(wr::ToWrRect(deviceBoxRect), + wr::ToWrRect(deviceClipRect), + wr::ToWrRect(deviceBoxRect), + wr::ToWrPoint(shadowOffset), + wr::ToWrColor(shadowColor), + blurRadius, + spreadRadius, + borderRadius, + WrBoxShadowClipMode::Outset); } } } @@ -4990,7 +4986,7 @@ nsDisplayBoxShadowInner::BuildLayer(nsDisplayListBuilder* aBuilder, } void -nsDisplayBoxShadowInner::CreateWebRenderCommands(nsTArray& aCommands, +nsDisplayBoxShadowInner::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, WebRenderDisplayItemLayer* aLayer) { @@ -5037,17 +5033,15 @@ nsDisplayBoxShadowInner::CreateWebRenderCommands(nsTArray& aCo // NOTE: Any spread radius > 0 will render nothing. WR Bug. float spreadRadius = float(shadowItem->mSpread) / float(appUnitsPerDevPixel); - aCommands.AppendElement(OpDPPushBoxShadow( - wr::ToWrRect(deviceBoxRect), - wr::ToWrRect(deviceClipRect), - wr::ToWrRect(deviceBoxRect), - wr::ToWrPoint(shadowOffset), - wr::ToWrColor(shadowColor), - blurRadius, - spreadRadius, - borderRadius, - WrBoxShadowClipMode::Inset - )); + aBuilder.PushBoxShadow(wr::ToWrRect(deviceBoxRect), + wr::ToWrRect(deviceClipRect), + wr::ToWrRect(deviceBoxRect), + wr::ToWrPoint(shadowOffset), + wr::ToWrColor(shadowColor), + blurRadius, + spreadRadius, + borderRadius, + WrBoxShadowClipMode::Inset); } } } diff --git a/layout/painting/nsDisplayList.h b/layout/painting/nsDisplayList.h index 68e037d6711a..385e8dce65b7 100644 --- a/layout/painting/nsDisplayList.h +++ b/layout/painting/nsDisplayList.h @@ -62,6 +62,9 @@ class WebRenderCommand; class WebRenderParentCommand; class WebRenderDisplayItemLayer; } // namespace layers +namespace wr { +class DisplayListBuilder; +} // namespace wr } // namespace mozilla // A set of blend modes, that never includes OP_OVER (since it's @@ -1927,7 +1930,7 @@ public: * The layer this item is in is passed in as rects must be relative * to their parent. */ - virtual void CreateWebRenderCommands(nsTArray& aCommands, + virtual void CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, WebRenderDisplayItemLayer* aLayer) {} /** @@ -2824,9 +2827,9 @@ public: virtual already_AddRefed BuildLayer(nsDisplayListBuilder* aBuilder, LayerManager* aManager, const ContainerLayerParameters& aContainerParameters) override; - virtual void CreateWebRenderCommands(nsTArray& aCommands, + virtual void CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, - WebRenderDisplayItemLayer* aLayer) override; + WebRenderDisplayItemLayer* aLayer) override; protected: RefPtr mCaret; @@ -3387,7 +3390,7 @@ public: virtual already_AddRefed BuildLayer(nsDisplayListBuilder* aBuilder, LayerManager* aManager, const ContainerLayerParameters& aContainerParameters) override; - virtual void CreateWebRenderCommands(nsTArray& aCommands, + virtual void CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, WebRenderDisplayItemLayer* aLayer) override; @@ -3443,7 +3446,7 @@ public: virtual already_AddRefed BuildLayer(nsDisplayListBuilder* aBuilder, LayerManager* aManager, const ContainerLayerParameters& aContainerParameters) override; - virtual void CreateWebRenderCommands(nsTArray& aCommands, + virtual void CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommand, WebRenderDisplayItemLayer* aLayer) override; @@ -3472,7 +3475,7 @@ public: virtual already_AddRefed BuildLayer(nsDisplayListBuilder* aBuilder, LayerManager* aManager, const ContainerLayerParameters& aContainerParameters) override; - virtual void CreateWebRenderCommands(nsTArray& aCommands, + virtual void CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, nsTArray& aParentCommands, mozilla::layers::WebRenderDisplayItemLayer* aLayer) override; virtual bool IsInvisibleInRect(const nsRect& aRect) override;