/work/obj-fuzz/dist/include/mozilla/layers/TiledContentHost.h
Line | Count | Source (jump to first uncovered line) |
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 GFX_TILEDCONTENTHOST_H |
8 | | #define GFX_TILEDCONTENTHOST_H |
9 | | |
10 | | #include <stdint.h> // for uint16_t |
11 | | #include <stdio.h> // for FILE |
12 | | #include <algorithm> // for swap |
13 | | #include "ContentHost.h" // for ContentHost |
14 | | #include "TiledLayerBuffer.h" // for TiledLayerBuffer, etc |
15 | | #include "CompositableHost.h" |
16 | | #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
17 | | #include "mozilla/Attributes.h" // for override |
18 | | #include "mozilla/RefPtr.h" // for RefPtr |
19 | | #include "mozilla/gfx/MatrixFwd.h" // for Matrix4x4 |
20 | | #include "mozilla/gfx/Point.h" // for Point |
21 | | #include "mozilla/gfx/Rect.h" // for Rect |
22 | | #include "mozilla/gfx/Types.h" // for SamplingFilter |
23 | | #include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc |
24 | | #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor |
25 | | #include "mozilla/layers/LayersTypes.h" // for LayerRenderState, etc |
26 | | #include "mozilla/layers/TextureHost.h" // for TextureHost |
27 | | #include "mozilla/layers/TextureClient.h" |
28 | | #include "mozilla/mozalloc.h" // for operator delete |
29 | | #include "nsRegion.h" // for nsIntRegion |
30 | | #include "nscore.h" // for nsACString |
31 | | |
32 | | namespace mozilla { |
33 | | |
34 | | namespace layers { |
35 | | |
36 | | class Compositor; |
37 | | class ISurfaceAllocator; |
38 | | class Layer; |
39 | | class ThebesBufferData; |
40 | | class TextureReadLock; |
41 | | struct EffectChain; |
42 | | |
43 | | |
44 | | class TileHost { |
45 | | public: |
46 | | // Constructs a placeholder TileHost. See the comments above |
47 | | // TiledLayerBuffer for more information on what this is used for; |
48 | | // essentially, this is a sentinel used to represent an invalid or blank |
49 | | // tile. |
50 | | TileHost() |
51 | 0 | {} |
52 | | |
53 | | // Constructs a TileHost from a TextureReadLock and TextureHost. |
54 | | TileHost(TextureReadLock* aSharedLock, |
55 | | TextureHost* aTextureHost, |
56 | | TextureHost* aTextureHostOnWhite, |
57 | | TextureSource* aSource, |
58 | | TextureSource* aSourceOnWhite) |
59 | | : mTextureHost(aTextureHost) |
60 | | , mTextureHostOnWhite(aTextureHostOnWhite) |
61 | | , mTextureSource(aSource) |
62 | | , mTextureSourceOnWhite(aSourceOnWhite) |
63 | 0 | {} |
64 | | |
65 | 0 | TileHost(const TileHost& o) { |
66 | 0 | mTextureHost = o.mTextureHost; |
67 | 0 | mTextureHostOnWhite = o.mTextureHostOnWhite; |
68 | 0 | mTextureSource = o.mTextureSource; |
69 | 0 | mTextureSourceOnWhite = o.mTextureSourceOnWhite; |
70 | 0 | mTileCoord = o.mTileCoord; |
71 | 0 | } |
72 | 0 | TileHost& operator=(const TileHost& o) { |
73 | 0 | if (this == &o) { |
74 | 0 | return *this; |
75 | 0 | } |
76 | 0 | mTextureHost = o.mTextureHost; |
77 | 0 | mTextureHostOnWhite = o.mTextureHostOnWhite; |
78 | 0 | mTextureSource = o.mTextureSource; |
79 | 0 | mTextureSourceOnWhite = o.mTextureSourceOnWhite; |
80 | 0 | mTileCoord = o.mTileCoord; |
81 | 0 | return *this; |
82 | 0 | } |
83 | | |
84 | 0 | bool operator== (const TileHost& o) const { |
85 | 0 | return mTextureHost == o.mTextureHost; |
86 | 0 | } |
87 | 0 | bool operator!= (const TileHost& o) const { |
88 | 0 | return mTextureHost != o.mTextureHost; |
89 | 0 | } |
90 | | |
91 | 0 | bool IsPlaceholderTile() const { return mTextureHost == nullptr; } |
92 | | |
93 | 0 | void Dump(std::stringstream& aStream) { |
94 | 0 | aStream << "TileHost(...)"; // fill in as needed |
95 | 0 | } |
96 | | |
97 | 0 | void DumpTexture(std::stringstream& aStream, TextureDumpMode /* aCompress, ignored for host tiles */) { |
98 | 0 | // TODO We should combine the OnWhite/OnBlack here an just output a single image. |
99 | 0 | CompositableHost::DumpTextureHost(aStream, mTextureHost); |
100 | 0 | } |
101 | | |
102 | | RefPtr<TextureSource> AcquireTextureSource() const; |
103 | | RefPtr<TextureSource> AcquireTextureSourceOnWhite() const; |
104 | | |
105 | | /** |
106 | | * This does a linear tween of the passed opacity (which is assumed |
107 | | * to be between 0.0 and 1.0). The duration of the fade is controlled |
108 | | * by the 'layers.tiles.fade-in.duration-ms' preference. It is enabled |
109 | | * via 'layers.tiles.fade-in.enabled' |
110 | | */ |
111 | | float GetFadeInOpacity(float aOpacity); |
112 | | |
113 | | CompositableTextureHostRef mTextureHost; |
114 | | CompositableTextureHostRef mTextureHostOnWhite; |
115 | | mutable CompositableTextureSourceRef mTextureSource; |
116 | | mutable CompositableTextureSourceRef mTextureSourceOnWhite; |
117 | | // This is not strictly necessary but makes debugging whole lot easier. |
118 | | TileCoordIntPoint mTileCoord; |
119 | | TimeStamp mFadeStart; |
120 | | }; |
121 | | |
122 | | class TiledLayerBufferComposite |
123 | | : public TiledLayerBuffer<TiledLayerBufferComposite, TileHost> |
124 | | { |
125 | | friend class TiledLayerBuffer<TiledLayerBufferComposite, TileHost>; |
126 | | |
127 | | public: |
128 | | TiledLayerBufferComposite(); |
129 | | ~TiledLayerBufferComposite(); |
130 | | |
131 | | bool UseTiles(const SurfaceDescriptorTiles& aTileDescriptors, |
132 | | HostLayerManager* aLayerManager, |
133 | | ISurfaceAllocator* aAllocator); |
134 | | |
135 | | void Clear(); |
136 | | |
137 | 0 | TileHost GetPlaceholderTile() const { return TileHost(); } |
138 | | |
139 | | // Stores the absolute resolution of the containing frame, calculated |
140 | | // by the sum of the resolutions of all parent layers' FrameMetrics. |
141 | 0 | const CSSToParentLayerScale2D& GetFrameResolution() { return mFrameResolution; } |
142 | | |
143 | | void SetTextureSourceProvider(TextureSourceProvider* aProvider); |
144 | | |
145 | | void AddAnimationInvalidation(nsIntRegion& aRegion); |
146 | | protected: |
147 | | |
148 | | CSSToParentLayerScale2D mFrameResolution; |
149 | | }; |
150 | | |
151 | | /** |
152 | | * ContentHost for tiled PaintedLayers. Since tiled layers are special snow |
153 | | * flakes, we have a unique update process. All the textures that back the |
154 | | * tiles are added in the usual way, but Updated is called on the host side |
155 | | * in response to a message that describes the transaction for every tile. |
156 | | * Composition happens in the normal way. |
157 | | * |
158 | | * TiledContentHost has a TiledLayerBufferComposite which keeps hold of the tiles. |
159 | | * Each tile has a reference to a texture host. During the layers transaction, we |
160 | | * receive a list of descriptors for the client-side tile buffer tiles |
161 | | * (UseTiledLayerBuffer). If we receive two transactions before a composition, |
162 | | * we immediately unlock and discard the unused buffer. |
163 | | * |
164 | | * When the content host is composited, we first validate the TiledLayerBuffer |
165 | | * (Upload), which calls Updated on each tile's texture host to make sure the |
166 | | * texture data has been uploaded. For single-buffered tiles, we unlock at this |
167 | | * point, for double-buffered tiles we unlock and discard the last composited |
168 | | * buffer after compositing a new one. Rendering takes us to RenderTile which |
169 | | * is similar to Composite for non-tiled ContentHosts. |
170 | | */ |
171 | | class TiledContentHost : public ContentHost |
172 | | { |
173 | | public: |
174 | | explicit TiledContentHost(const TextureInfo& aTextureInfo); |
175 | | |
176 | | protected: |
177 | | ~TiledContentHost(); |
178 | | |
179 | | public: |
180 | | // Generate effect for layerscope when using hwc. |
181 | | virtual already_AddRefed<TexturedEffect> GenEffect(const gfx::SamplingFilter aSamplingFilter) override; |
182 | | |
183 | | virtual bool UpdateThebes(const ThebesBufferData& aData, |
184 | | const nsIntRegion& aUpdated, |
185 | | const nsIntRegion& aOldValidRegionBack) override |
186 | 0 | { |
187 | 0 | NS_ERROR("N/A for tiled layers"); |
188 | 0 | return false; |
189 | 0 | } |
190 | | |
191 | | const nsIntRegion& GetValidLowPrecisionRegion() const |
192 | 0 | { |
193 | 0 | return mLowPrecisionTiledBuffer.GetValidRegion(); |
194 | 0 | } |
195 | | |
196 | | const nsIntRegion& GetValidRegion() const |
197 | 0 | { |
198 | 0 | return mTiledBuffer.GetValidRegion(); |
199 | 0 | } |
200 | | |
201 | | virtual void SetTextureSourceProvider(TextureSourceProvider* aProvider) override |
202 | 0 | { |
203 | 0 | CompositableHost::SetTextureSourceProvider(aProvider); |
204 | 0 | mTiledBuffer.SetTextureSourceProvider(aProvider); |
205 | 0 | mLowPrecisionTiledBuffer.SetTextureSourceProvider(aProvider); |
206 | 0 | } |
207 | | |
208 | | bool UseTiledLayerBuffer(ISurfaceAllocator* aAllocator, |
209 | | const SurfaceDescriptorTiles& aTiledDescriptor); |
210 | | |
211 | | virtual void Composite(Compositor* aCompositor, |
212 | | LayerComposite* aLayer, |
213 | | EffectChain& aEffectChain, |
214 | | float aOpacity, |
215 | | const gfx::Matrix4x4& aTransform, |
216 | | const gfx::SamplingFilter aSamplingFilter, |
217 | | const gfx::IntRect& aClipRect, |
218 | | const nsIntRegion* aVisibleRegion = nullptr, |
219 | | const Maybe<gfx::Polygon>& aGeometry = Nothing()) override; |
220 | | |
221 | 0 | virtual CompositableType GetType() override { return CompositableType::CONTENT_TILED; } |
222 | | |
223 | 0 | virtual TiledContentHost* AsTiledContentHost() override { return this; } |
224 | | |
225 | | virtual void Attach(Layer* aLayer, |
226 | | TextureSourceProvider* aProvider, |
227 | | AttachFlags aFlags = NO_FLAGS) override; |
228 | | |
229 | | virtual void Detach(Layer* aLayer = nullptr, |
230 | | AttachFlags aFlags = NO_FLAGS) override; |
231 | | |
232 | | virtual void Dump(std::stringstream& aStream, |
233 | | const char* aPrefix="", |
234 | | bool aDumpHtml=false) override; |
235 | | |
236 | | virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override; |
237 | | |
238 | | virtual void AddAnimationInvalidation(nsIntRegion& aRegion) override; |
239 | | |
240 | 0 | TiledLayerBufferComposite& GetLowResBuffer() { |
241 | 0 | return mLowPrecisionTiledBuffer; |
242 | 0 | } |
243 | 0 | TiledLayerBufferComposite& GetHighResBuffer() { |
244 | 0 | return mTiledBuffer; |
245 | 0 | } |
246 | | |
247 | | private: |
248 | | |
249 | | void RenderLayerBuffer(TiledLayerBufferComposite& aLayerBuffer, |
250 | | Compositor* aCompositor, |
251 | | const gfx::Color* aBackgroundColor, |
252 | | EffectChain& aEffectChain, |
253 | | float aOpacity, |
254 | | const gfx::SamplingFilter aSamplingFilter, |
255 | | const gfx::IntRect& aClipRect, |
256 | | nsIntRegion aMaskRegion, |
257 | | gfx::Matrix4x4 aTransform, |
258 | | const Maybe<gfx::Polygon>& aGeometry); |
259 | | |
260 | | // Renders a single given tile. |
261 | | void RenderTile(TileHost& aTile, |
262 | | Compositor* aCompositor, |
263 | | EffectChain& aEffectChain, |
264 | | float aOpacity, |
265 | | const gfx::Matrix4x4& aTransform, |
266 | | const gfx::SamplingFilter aSamplingFilter, |
267 | | const gfx::IntRect& aClipRect, |
268 | | const nsIntRegion& aScreenRegion, |
269 | | const gfx::IntPoint& aTextureOffset, |
270 | | const gfx::IntSize& aTextureBounds, |
271 | | const gfx::Rect& aVisibleRect, |
272 | | const Maybe<gfx::Polygon>& aGeometry); |
273 | | |
274 | 0 | void EnsureTileStore() {} |
275 | | |
276 | | TiledLayerBufferComposite mTiledBuffer; |
277 | | TiledLayerBufferComposite mLowPrecisionTiledBuffer; |
278 | | }; |
279 | | |
280 | | } // namespace layers |
281 | | } // namespace mozilla |
282 | | |
283 | | #endif |