1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GFX_RENDERROOTSTATEMANAGER_H
8 #define GFX_RENDERROOTSTATEMANAGER_H
10 #include "mozilla/webrender/WebRenderAPI.h"
12 #include "mozilla/layers/IpcResourceUpdateQueue.h"
13 #include "mozilla/layers/SharedSurfacesChild.h"
14 #include "mozilla/layers/WebRenderCommandBuilder.h"
20 class RenderRootStateManager
{
21 typedef nsTHashtable
<nsRefPtrHashKey
<WebRenderUserData
>>
22 WebRenderUserDataRefTable
;
28 RenderRootStateManager()
29 : mLayerManager(nullptr),
30 mRenderRoot(wr::RenderRoot::Default
),
34 bool IsDestroyed() { return mDestroyed
; }
35 wr::RenderRoot
GetRenderRoot() { return mRenderRoot
; }
36 wr::IpcResourceUpdateQueue
& AsyncResourceUpdates();
37 WebRenderBridgeChild
* WrBridge() const;
38 WebRenderCommandBuilder
& CommandBuilder();
39 WebRenderUserDataRefTable
* GetWebRenderUserDataTable();
40 WebRenderLayerManager
* LayerManager() { return mLayerManager
; }
42 void AddImageKeyForDiscard(wr::ImageKey key
);
43 void AddBlobImageKeyForDiscard(wr::BlobImageKey key
);
44 void DiscardImagesInTransaction(wr::IpcResourceUpdateQueue
& aResources
);
45 void DiscardLocalImages();
47 void ClearCachedResources();
49 // Methods to manage the compositor animation ids. Active animations are still
50 // going, and when they end we discard them and remove them from the active
52 void AddActiveCompositorAnimationId(uint64_t aId
);
53 void AddCompositorAnimationsIdForDiscard(uint64_t aId
);
54 void DiscardCompositorAnimations();
56 void RegisterAsyncAnimation(const wr::ImageKey
& aKey
,
57 SharedSurfacesAnimation
* aAnimation
);
58 void DeregisterAsyncAnimation(const wr::ImageKey
& aKey
);
59 void ClearAsyncAnimations();
60 void WrReleasedImages(const nsTArray
<wr::ExternalImageKeyPair
>& aPairs
);
62 void AddWebRenderParentCommand(const WebRenderParentCommand
& aCmd
);
63 void UpdateResources(wr::IpcResourceUpdateQueue
& aResources
);
64 void AddPipelineIdForAsyncCompositable(const wr::PipelineId
& aPipelineId
,
65 const CompositableHandle
& aHandlee
);
66 void AddPipelineIdForCompositable(const wr::PipelineId
& aPipelineId
,
67 const CompositableHandle
& aHandlee
);
68 void RemovePipelineIdForCompositable(const wr::PipelineId
& aPipelineId
);
69 /// Release TextureClient that is bounded to ImageKey.
70 /// It is used for recycling TextureClient.
71 void ReleaseTextureOfImage(const wr::ImageKey
& aKey
);
72 Maybe
<wr::FontInstanceKey
> GetFontKeyForScaledFont(
73 gfx::ScaledFont
* aScaledFont
,
74 wr::IpcResourceUpdateQueue
* aResources
= nullptr);
75 Maybe
<wr::FontKey
> GetFontKeyForUnscaledFont(
76 gfx::UnscaledFont
* aUnscaledFont
,
77 wr::IpcResourceUpdateQueue
* aResources
= nullptr);
79 void FlushAsyncResourceUpdates();
82 WebRenderLayerManager
* mLayerManager
;
83 Maybe
<wr::IpcResourceUpdateQueue
> mAsyncResourceUpdates
;
84 nsTArray
<wr::ImageKey
> mImageKeysToDelete
;
85 nsTArray
<wr::BlobImageKey
> mBlobImageKeysToDelete
;
86 std::unordered_map
<uint64_t, RefPtr
<SharedSurfacesAnimation
>>
89 // Set of compositor animation ids for which there are active animations (as
90 // of the last transaction) on the compositor side.
91 std::unordered_set
<uint64_t> mActiveCompositorAnimationIds
;
92 // Compositor animation ids for animations that are done now and that we want
93 // the compositor to discard information for.
94 nsTArray
<uint64_t> mDiscardedCompositorAnimationsIds
;
96 wr::RenderRoot mRenderRoot
;
99 friend class WebRenderLayerManager
;
102 } // namespace layers
103 } // namespace mozilla
105 #endif /* GFX_RENDERROOTSTATEMANAGER_H */