Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 MOZILLA_LAYERS_COMPOSITABLEFORWARDER
8 #define MOZILLA_LAYERS_COMPOSITABLEFORWARDER
10 #include <stdint.h> // for int32_t, uint64_t
11 #include "gfxTypes.h"
12 #include "mozilla/Attributes.h" // for MOZ_OVERRIDE
13 #include "mozilla/layers/CompositorTypes.h"
14 #include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator
15 #include "mozilla/layers/LayersTypes.h" // for LayersBackend
16 #include "mozilla/layers/TextureClient.h" // for TextureClient
17 #include "nsRegion.h" // for nsIntRegion
19 struct nsIntPoint;
20 struct nsIntRect;
22 namespace mozilla {
23 namespace layers {
25 class CompositableClient;
26 class TextureFactoryIdentifier;
27 class SurfaceDescriptor;
28 class SurfaceDescriptorTiles;
29 class ThebesBufferData;
30 class ClientTiledLayerBuffer;
31 class PTextureChild;
33 /**
34 * A transaction is a set of changes that happenned on the content side, that
35 * should be sent to the compositor side.
36 * CompositableForwarder is an interface to manage a transaction of
37 * compositable objetcs.
38 *
39 * ShadowLayerForwarder is an example of a CompositableForwarder (that can
40 * additionally forward modifications of the Layer tree).
41 * ImageBridgeChild is another CompositableForwarder.
42 */
43 class CompositableForwarder : public ISurfaceAllocator
44 {
45 public:
47 CompositableForwarder()
48 : mSerial(++sSerialCounter)
49 {}
51 /**
52 * Setup the IPDL actor for aCompositable to be part of layers
53 * transactions.
54 */
55 virtual void Connect(CompositableClient* aCompositable) = 0;
57 /**
58 * Notify the CompositableHost that it should create host-side-only
59 * texture(s), that we will update incrementally using UpdateTextureIncremental.
60 */
61 virtual void CreatedIncrementalBuffer(CompositableClient* aCompositable,
62 const TextureInfo& aTextureInfo,
63 const nsIntRect& aBufferRect) = 0;
65 /**
66 * Tell the CompositableHost on the compositor side what TiledLayerBuffer to
67 * use for the next composition.
68 */
69 virtual void UseTiledLayerBuffer(CompositableClient* aCompositable,
70 const SurfaceDescriptorTiles& aTiledDescriptor) = 0;
72 /**
73 * Create a TextureChild/Parent pair as as well as the TextureHost on the parent side.
74 */
75 virtual PTextureChild* CreateTexture(const SurfaceDescriptor& aSharedData, TextureFlags aFlags) = 0;
77 /**
78 * Communicate to the compositor that aRegion in the texture identified by
79 * aCompositable and aIdentifier has been updated to aThebesBuffer.
80 */
81 virtual void UpdateTextureRegion(CompositableClient* aCompositable,
82 const ThebesBufferData& aThebesBufferData,
83 const nsIntRegion& aUpdatedRegion) = 0;
85 /**
86 * Notify the compositor to update aTextureId using aDescriptor, and take
87 * ownership of aDescriptor.
88 *
89 * aDescriptor only contains the pixels for aUpdatedRegion, and is relative
90 * to aUpdatedRegion.TopLeft().
91 *
92 * aBufferRect/aBufferRotation define the new valid region contained
93 * within the texture after the update has been applied.
94 */
95 virtual void UpdateTextureIncremental(CompositableClient* aCompositable,
96 TextureIdentifier aTextureId,
97 SurfaceDescriptor& aDescriptor,
98 const nsIntRegion& aUpdatedRegion,
99 const nsIntRect& aBufferRect,
100 const nsIntPoint& aBufferRotation) = 0;
102 /**
103 * Communicate the picture rect of a YUV image in aLayer to the compositor
104 */
105 virtual void UpdatePictureRect(CompositableClient* aCompositable,
106 const nsIntRect& aRect) = 0;
108 /**
109 * Tell the CompositableHost on the compositor side to remove the texture.
110 * This function does not delete the TextureHost corresponding to the
111 * TextureClient passed in parameter.
112 */
113 virtual void RemoveTextureFromCompositable(CompositableClient* aCompositable,
114 TextureClient* aTexture) = 0;
116 /**
117 * Tell the compositor side to delete the TextureHost corresponding to the
118 * TextureClient passed in parameter.
119 */
120 virtual void RemoveTexture(TextureClient* aTexture) = 0;
122 /**
123 * Holds a reference to a TextureClient until after the next
124 * compositor transaction, and then drops it.
125 */
126 virtual void HoldUntilTransaction(TextureClient* aClient)
127 {
128 if (aClient) {
129 mTexturesToRemove.AppendElement(aClient);
130 }
131 }
133 /**
134 * Forcibly remove texture data from TextureClient
135 * This function needs to be called after a tansaction with Compositor.
136 */
137 virtual void RemoveTexturesIfNecessary()
138 {
139 mTexturesToRemove.Clear();
140 }
142 /**
143 * Tell the CompositableHost on the compositor side what texture to use for
144 * the next composition.
145 */
146 virtual void UseTexture(CompositableClient* aCompositable,
147 TextureClient* aClient) = 0;
148 virtual void UseComponentAlphaTextures(CompositableClient* aCompositable,
149 TextureClient* aClientOnBlack,
150 TextureClient* aClientOnWhite) = 0;
152 /**
153 * Tell the compositor side that the shared data has been modified so that
154 * it can react accordingly (upload textures, etc.).
155 */
156 virtual void UpdatedTexture(CompositableClient* aCompositable,
157 TextureClient* aTexture,
158 nsIntRegion* aRegion) = 0;
160 void IdentifyTextureHost(const TextureFactoryIdentifier& aIdentifier);
162 virtual int32_t GetMaxTextureSize() const MOZ_OVERRIDE
163 {
164 return mTextureFactoryIdentifier.mMaxTextureSize;
165 }
167 bool IsOnCompositorSide() const MOZ_OVERRIDE { return false; }
169 /**
170 * Returns the type of backend that is used off the main thread.
171 * We only don't allow changing the backend type at runtime so this value can
172 * be queried once and will not change until Gecko is restarted.
173 */
174 virtual LayersBackend GetCompositorBackendType() const MOZ_OVERRIDE
175 {
176 return mTextureFactoryIdentifier.mParentBackend;
177 }
179 bool SupportsTextureBlitting() const
180 {
181 return mTextureFactoryIdentifier.mSupportsTextureBlitting;
182 }
184 bool SupportsPartialUploads() const
185 {
186 return mTextureFactoryIdentifier.mSupportsPartialUploads;
187 }
189 const TextureFactoryIdentifier& GetTextureFactoryIdentifier() const
190 {
191 return mTextureFactoryIdentifier;
192 }
194 int32_t GetSerial() { return mSerial; }
196 protected:
197 TextureFactoryIdentifier mTextureFactoryIdentifier;
198 nsTArray<RefPtr<TextureClient> > mTexturesToRemove;
199 const int32_t mSerial;
200 static mozilla::Atomic<int32_t> sSerialCounter;
201 };
203 } // namespace
204 } // namespace
206 #endif