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/. */
6 
7 #ifndef MOZILLA_LAYERS_COMPOSITABLEFORWARDER
8 #define MOZILLA_LAYERS_COMPOSITABLEFORWARDER
9 
10 #include <stdint.h>  // for int32_t, uint64_t
11 #include "gfxTypes.h"
12 #include "mozilla/Attributes.h"  // for override
13 #include "mozilla/UniquePtr.h"
14 #include "mozilla/layers/CompositableClient.h"  // for CompositableClient
15 #include "mozilla/layers/CompositorTypes.h"
16 #include "mozilla/layers/ISurfaceAllocator.h"  // for ISurfaceAllocator
17 #include "mozilla/layers/LayersTypes.h"        // for LayersBackend
18 #include "mozilla/layers/TextureClient.h"      // for TextureClient
19 #include "mozilla/layers/TextureForwarder.h"   // for TextureForwarder
20 #include "nsRegion.h"                          // for nsIntRegion
21 #include "mozilla/gfx/Rect.h"
22 #include "nsHashKeys.h"
23 #include "nsTHashtable.h"
24 
25 namespace mozilla {
26 namespace layers {
27 
28 class CompositableClient;
29 class ImageContainer;
30 class SurfaceDescriptor;
31 class SurfaceDescriptorTiles;
32 class ThebesBufferData;
33 class PTextureChild;
34 
35 /**
36  * A transaction is a set of changes that happenned on the content side, that
37  * should be sent to the compositor side.
38  * CompositableForwarder is an interface to manage a transaction of
39  * compositable objetcs.
40  *
41  * ShadowLayerForwarder is an example of a CompositableForwarder (that can
42  * additionally forward modifications of the Layer tree).
43  * ImageBridgeChild is another CompositableForwarder.
44  *
45  * CompositableForwarder implements KnowsCompositor for simplicity as all
46  * implementations of CompositableForwarder currently also implement
47  * KnowsCompositor. This dependency could be split if we add new use cases.
48  */
49 class CompositableForwarder : public KnowsCompositor {
50  public:
51   /**
52    * Setup the IPDL actor for aCompositable to be part of layers
53    * transactions.
54    */
55   virtual void Connect(CompositableClient* aCompositable,
56                        ImageContainer* aImageContainer = nullptr) = 0;
57 
58   /**
59    * Tell the CompositableHost on the compositor side what TiledLayerBuffer to
60    * use for the next composition.
61    */
62   virtual void UseTiledLayerBuffer(
63       CompositableClient* aCompositable,
64       const SurfaceDescriptorTiles& aTiledDescriptor) = 0;
65 
66   /**
67    * Communicate to the compositor that aRegion in the texture identified by
68    * aCompositable and aIdentifier has been updated to aThebesBuffer.
69    */
70   virtual void UpdateTextureRegion(CompositableClient* aCompositable,
71                                    const ThebesBufferData& aThebesBufferData,
72                                    const nsIntRegion& aUpdatedRegion) = 0;
73 
74   virtual void ReleaseCompositable(const CompositableHandle& aHandle) = 0;
75   virtual bool DestroyInTransaction(PTextureChild* aTexture) = 0;
76 
77   /**
78    * Tell the CompositableHost on the compositor side to remove the texture
79    * from the CompositableHost.
80    * This function does not delete the TextureHost corresponding to the
81    * TextureClient passed in parameter.
82    * When the TextureClient has TEXTURE_DEALLOCATE_CLIENT flag,
83    * the transaction becomes synchronous.
84    */
85   virtual void RemoveTextureFromCompositable(CompositableClient* aCompositable,
86                                              TextureClient* aTexture) = 0;
87 
88   struct TimedTextureClient {
TimedTextureClientTimedTextureClient89     TimedTextureClient()
90         : mTextureClient(nullptr), mFrameID(0), mProducerID(0) {}
91 
92     TextureClient* mTextureClient;
93     TimeStamp mTimeStamp;
94     nsIntRect mPictureRect;
95     int32_t mFrameID;
96     int32_t mProducerID;
97   };
98   /**
99    * Tell the CompositableHost on the compositor side what textures to use for
100    * the next composition.
101    */
102   virtual void UseTextures(CompositableClient* aCompositable,
103                            const nsTArray<TimedTextureClient>& aTextures) = 0;
104   virtual void UseComponentAlphaTextures(CompositableClient* aCompositable,
105                                          TextureClient* aClientOnBlack,
106                                          TextureClient* aClientOnWhite) = 0;
107 
108   virtual void UpdateFwdTransactionId() = 0;
109   virtual uint64_t GetFwdTransactionId() = 0;
110 
111   virtual bool InForwarderThread() = 0;
112 
AssertInForwarderThread()113   void AssertInForwarderThread() { MOZ_ASSERT(InForwarderThread()); }
114 
115   static uint32_t GetMaxFileDescriptorsPerMessage();
116 
AsLayerForwarder()117   virtual ShadowLayerForwarder* AsLayerForwarder() { return nullptr; }
118 
119  protected:
120   nsTArray<RefPtr<TextureClient>> mTexturesToRemove;
121   nsTArray<RefPtr<CompositableClient>> mCompositableClientsToRemove;
122 };
123 
124 }  // namespace layers
125 }  // namespace mozilla
126 
127 #endif
128