/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef GFX_WEBRENDERLAYERMANAGER_H #define GFX_WEBRENDERLAYERMANAGER_H #include "Layers.h" #include "mozilla/ipc/MessageChannel.h" #include "mozilla/MozPromise.h" #include "mozilla/layers/TransactionIdAllocator.h" #include "mozilla/webrender/WebRenderTypes.h" class nsIWidget; namespace mozilla { namespace layers { class CompositorBridgeChild; class KnowsCompositor; class PCompositorBridgeChild; class WebRenderBridgeChild; typedef MozPromise PipelineIdPromise; class WebRenderLayerManager final : public LayerManager { typedef nsTArray > LayerRefArray; public: explicit WebRenderLayerManager(nsIWidget* aWidget); void Initialize(PCompositorBridgeChild* aCBChild, wr::PipelineId aLayersId, TextureFactoryIdentifier* aTextureFactoryIdentifier); virtual void Destroy() override; protected: virtual ~WebRenderLayerManager(); public: virtual KnowsCompositor* AsKnowsCompositor() override; WebRenderLayerManager* AsWebRenderLayerManager() override { return this; } virtual CompositorBridgeChild* GetCompositorBridgeChild() override; virtual int32_t GetMaxTextureSize() const override; virtual bool BeginTransactionWithTarget(gfxContext* aTarget) override; virtual bool BeginTransaction() override; virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT) override; virtual void EndTransaction(DrawPaintedLayerCallback aCallback, void* aCallbackData, EndTransactionFlags aFlags = END_DEFAULT) override; virtual LayersBackend GetBackendType() override { return LayersBackend::LAYERS_WR; } virtual void GetBackendName(nsAString& name) override { name.AssignLiteral("WebRender"); } virtual const char* Name() const override { return "WebRender"; } virtual void SetRoot(Layer* aLayer) override; virtual already_AddRefed CreatePaintedLayer() override; virtual already_AddRefed CreateContainerLayer() override; virtual already_AddRefed CreateImageLayer() override; virtual already_AddRefed CreateCanvasLayer() override; virtual already_AddRefed CreateReadbackLayer() override; virtual already_AddRefed CreateColorLayer() override; virtual already_AddRefed CreateRefLayer() override; virtual already_AddRefed CreateTextLayer() override; virtual already_AddRefed CreateBorderLayer() override; virtual already_AddRefed CreateDisplayItemLayer() override; virtual bool NeedsWidgetInvalidation() override { return false; } virtual void SetLayerObserverEpoch(uint64_t aLayerObserverEpoch) override; virtual void DidComposite(uint64_t aTransactionId, const mozilla::TimeStamp& aCompositeStart, const mozilla::TimeStamp& aCompositeEnd) override; virtual void ClearCachedResources(Layer* aSubtree = nullptr) override; virtual void UpdateTextureFactoryIdentifier(const TextureFactoryIdentifier& aNewIdentifier, uint64_t aDeviceResetSeqNo) override; virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() override; virtual void SetTransactionIdAllocator(TransactionIdAllocator* aAllocator) override { mTransactionIdAllocator = aAllocator; } virtual void AddDidCompositeObserver(DidCompositeObserver* aObserver) override; virtual void RemoveDidCompositeObserver(DidCompositeObserver* aObserver) override; virtual void FlushRendering() override; virtual void SendInvalidRegion(const nsIntRegion& aRegion) override; virtual void Composite() override; virtual void SetNeedsComposite(bool aNeedsComposite) override { mNeedsComposite = aNeedsComposite; } virtual bool NeedsComposite() const override { return mNeedsComposite; } virtual void SetIsFirstPaint() override { mIsFirstPaint = true; } DrawPaintedLayerCallback GetPaintedLayerCallback() const { return mPaintedLayerCallback; } void* GetPaintedLayerCallbackData() const { return mPaintedLayerCallbackData; } // adds an imagekey to a list of keys that will be discarded on the next // transaction or destruction void AddImageKeyForDiscard(wr::ImageKey); void DiscardImages(); void DiscardLocalImages(); // Before destroying a layer with animations, add its compositorAnimationsId // to a list of ids that will be discarded on the next transaction void AddCompositorAnimationsIdForDiscard(uint64_t aId); void DiscardCompositorAnimations(); WebRenderBridgeChild* WrBridge() const { return mWrChild; } virtual void Mutated(Layer* aLayer) override; virtual void MutatedSimple(Layer* aLayer) override; void Hold(Layer* aLayer); void SetTransactionIncomplete() { mTransactionIncomplete = true; } bool IsMutatedLayer(Layer* aLayer); RefPtr AllocPipelineId(); private: /** * Take a snapshot of the parent context, and copy * it into mTarget. */ void MakeSnapshotIfRequired(LayoutDeviceIntSize aSize); void ClearLayer(Layer* aLayer); bool EndTransactionInternal(DrawPaintedLayerCallback aCallback, void* aCallbackData, EndTransactionFlags aFlags); private: nsIWidget* MOZ_NON_OWNING_REF mWidget; std::vector mImageKeys; std::vector mDiscardedCompositorAnimationsIds; /* PaintedLayer callbacks; valid at the end of a transaciton, * while rendering */ DrawPaintedLayerCallback mPaintedLayerCallback; void *mPaintedLayerCallbackData; RefPtr mWrChild; RefPtr mTransactionIdAllocator; uint64_t mLatestTransactionId; nsTArray mDidCompositeObservers; LayerRefArray mKeepAlive; // Layers that have been mutated. If we have an empty transaction // then a display item layer will no longer be valid // if it was a mutated layers. void AddMutatedLayer(Layer* aLayer); void ClearMutatedLayers(); LayerRefArray mMutatedLayers; bool mTransactionIncomplete; bool mNeedsComposite; bool mIsFirstPaint; // When we're doing a transaction in order to draw to a non-default // target, the layers transaction is only performed in order to send // a PLayers:Update. We save the original non-default target to // mTarget, and then perform the transaction. After the transaction ends, // we send a message to our remote side to capture the actual pixels // being drawn to the default target, and then copy those pixels // back to mTarget. RefPtr mTarget; }; } // namespace layers } // namespace mozilla #endif /* GFX_WEBRENDERLAYERMANAGER_H */