/work/obj-fuzz/dist/include/mozilla/layers/ContentHost.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_CONTENTHOST_H |
8 | | #define GFX_CONTENTHOST_H |
9 | | |
10 | | #include <stdint.h> // for uint32_t |
11 | | #include <stdio.h> // for FILE |
12 | | #include "mozilla-config.h" // for MOZ_DUMP_PAINTING |
13 | | #include "CompositableHost.h" // for CompositableHost, etc |
14 | | #include "RotatedBuffer.h" // for RotatedBuffer, etc |
15 | | #include "mozilla/Attributes.h" // for override |
16 | | #include "mozilla/RefPtr.h" // for RefPtr |
17 | | #include "mozilla/gfx/BasePoint.h" // for BasePoint |
18 | | #include "mozilla/gfx/MatrixFwd.h" // for Matrix4x4 |
19 | | #include "mozilla/gfx/Point.h" // for Point |
20 | | #include "mozilla/gfx/Polygon.h" // for Polygon |
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/ContentClient.h" // for ContentClient |
25 | | #include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator |
26 | | #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor |
27 | | #include "mozilla/layers/LayersTypes.h" // for etc |
28 | | #include "mozilla/layers/TextureHost.h" // for TextureHost |
29 | | #include "mozilla/mozalloc.h" // for operator delete |
30 | | #include "mozilla/UniquePtr.h" // for UniquePtr |
31 | | #include "nsCOMPtr.h" // for already_AddRefed |
32 | | #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc |
33 | | #include "nsPoint.h" // for nsIntPoint |
34 | | #include "nsRect.h" // for mozilla::gfx::IntRect |
35 | | #include "nsRegion.h" // for nsIntRegion |
36 | | #include "nsTArray.h" // for nsTArray |
37 | | #include "nscore.h" // for nsACString |
38 | | |
39 | | namespace mozilla { |
40 | | namespace layers { |
41 | | class Compositor; |
42 | | class ThebesBufferData; |
43 | | struct EffectChain; |
44 | | |
45 | | struct TexturedEffect; |
46 | | |
47 | | /** |
48 | | * ContentHosts are used for compositing Painted layers, always matched by a |
49 | | * ContentClient of the same type. |
50 | | * |
51 | | * ContentHosts support only UpdateThebes(), not Update(). |
52 | | */ |
53 | | class ContentHost : public CompositableHost |
54 | | { |
55 | | public: |
56 | | virtual bool UpdateThebes(const ThebesBufferData& aData, |
57 | | const nsIntRegion& aUpdated, |
58 | | const nsIntRegion& aOldValidRegionBack) override = 0; |
59 | | |
60 | 0 | virtual void SetPaintWillResample(bool aResample) { mPaintWillResample = aResample; } |
61 | 0 | bool PaintWillResample() { return mPaintWillResample; } |
62 | | |
63 | | // We use this to allow TiledContentHost to invalidate regions where |
64 | | // tiles are fading in. |
65 | 0 | virtual void AddAnimationInvalidation(nsIntRegion& aRegion) { } |
66 | | |
67 | 0 | virtual gfx::IntRect GetBufferRect() { |
68 | 0 | MOZ_ASSERT_UNREACHABLE("Must be implemented in derived class"); |
69 | 0 | return gfx::IntRect(); |
70 | 0 | } |
71 | | |
72 | 0 | virtual ContentHost* AsContentHost() override { return this; } |
73 | | |
74 | | protected: |
75 | | explicit ContentHost(const TextureInfo& aTextureInfo) |
76 | | : CompositableHost(aTextureInfo) |
77 | | , mPaintWillResample(false) |
78 | 0 | {} |
79 | | |
80 | | bool mPaintWillResample; |
81 | | }; |
82 | | |
83 | | /** |
84 | | * Base class for non-tiled ContentHosts. |
85 | | * |
86 | | * Ownership of the SurfaceDescriptor and the resources it represents is passed |
87 | | * from the ContentClient to the ContentHost when the TextureClient/Hosts are |
88 | | * created, that is recevied here by SetTextureHosts which assigns one or two |
89 | | * texture hosts (for single and double buffering) to the ContentHost. |
90 | | * |
91 | | * It is the responsibility of the ContentHost to destroy its resources when |
92 | | * they are recreated or the ContentHost dies. |
93 | | */ |
94 | | class ContentHostBase : public ContentHost |
95 | | { |
96 | | public: |
97 | | typedef ContentClient::ContentType ContentType; |
98 | | typedef ContentClient::PaintState PaintState; |
99 | | |
100 | | explicit ContentHostBase(const TextureInfo& aTextureInfo); |
101 | | virtual ~ContentHostBase(); |
102 | | |
103 | 0 | virtual gfx::IntRect GetBufferRect() override { return mBufferRect; } |
104 | | |
105 | | virtual nsIntPoint GetOriginOffset() |
106 | 0 | { |
107 | 0 | return mBufferRect.TopLeft() - mBufferRotation; |
108 | 0 | } |
109 | | |
110 | | gfx::IntPoint GetBufferRotation() |
111 | 0 | { |
112 | 0 | return mBufferRotation.ToUnknownPoint(); |
113 | 0 | } |
114 | | |
115 | | protected: |
116 | | gfx::IntRect mBufferRect; |
117 | | nsIntPoint mBufferRotation; |
118 | | bool mInitialised; |
119 | | }; |
120 | | |
121 | | /** |
122 | | * Shared ContentHostBase implementation for content hosts that |
123 | | * use up to two TextureHosts. |
124 | | */ |
125 | | class ContentHostTexture : public ContentHostBase |
126 | | { |
127 | | public: |
128 | | explicit ContentHostTexture(const TextureInfo& aTextureInfo) |
129 | | : ContentHostBase(aTextureInfo) |
130 | | , mLocked(false) |
131 | | , mReceivedNewHost(false) |
132 | 0 | { } |
133 | | |
134 | | virtual void Composite(Compositor* aCompositor, |
135 | | LayerComposite* aLayer, |
136 | | EffectChain& aEffectChain, |
137 | | float aOpacity, |
138 | | const gfx::Matrix4x4& aTransform, |
139 | | const gfx::SamplingFilter aSamplingFilter, |
140 | | const gfx::IntRect& aClipRect, |
141 | | const nsIntRegion* aVisibleRegion = nullptr, |
142 | | const Maybe<gfx::Polygon>& aGeometry = Nothing()) override; |
143 | | |
144 | | virtual void SetTextureSourceProvider(TextureSourceProvider* aProvider) override; |
145 | | |
146 | | virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override; |
147 | | |
148 | | virtual void Dump(std::stringstream& aStream, |
149 | | const char* aPrefix="", |
150 | | bool aDumpHtml=false) override; |
151 | | |
152 | | virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override; |
153 | | |
154 | | virtual void UseTextureHost(const nsTArray<TimedTexture>& aTextures) override; |
155 | | virtual void UseComponentAlphaTextures(TextureHost* aTextureOnBlack, |
156 | | TextureHost* aTextureOnWhite) override; |
157 | | |
158 | 0 | virtual bool Lock() override { |
159 | 0 | MOZ_ASSERT(!mLocked); |
160 | 0 | if (!mTextureHost) { |
161 | 0 | return false; |
162 | 0 | } |
163 | 0 | if (!mTextureHost->Lock()) { |
164 | 0 | return false; |
165 | 0 | } |
166 | 0 | |
167 | 0 | if (mTextureHostOnWhite && !mTextureHostOnWhite->Lock()) { |
168 | 0 | return false; |
169 | 0 | } |
170 | 0 | |
171 | 0 | mLocked = true; |
172 | 0 | return true; |
173 | 0 | } |
174 | 0 | virtual void Unlock() override { |
175 | 0 | MOZ_ASSERT(mLocked); |
176 | 0 | mTextureHost->Unlock(); |
177 | 0 | if (mTextureHostOnWhite) { |
178 | 0 | mTextureHostOnWhite->Unlock(); |
179 | 0 | } |
180 | 0 | mLocked = false; |
181 | 0 | } |
182 | | |
183 | 0 | bool HasComponentAlpha() const { |
184 | 0 | return !!mTextureHostOnWhite; |
185 | 0 | } |
186 | | |
187 | | RefPtr<TextureSource> AcquireTextureSource(); |
188 | | RefPtr<TextureSource> AcquireTextureSourceOnWhite(); |
189 | | |
190 | 0 | ContentHostTexture* AsContentHostTexture() override { return this; } |
191 | | |
192 | | virtual already_AddRefed<TexturedEffect> GenEffect(const gfx::SamplingFilter aSamplingFilter) override; |
193 | | |
194 | | protected: |
195 | | CompositableTextureHostRef mTextureHost; |
196 | | CompositableTextureHostRef mTextureHostOnWhite; |
197 | | CompositableTextureSourceRef mTextureSource; |
198 | | CompositableTextureSourceRef mTextureSourceOnWhite; |
199 | | bool mLocked; |
200 | | bool mReceivedNewHost; |
201 | | }; |
202 | | |
203 | | /** |
204 | | * Double buffering is implemented by swapping the front and back TextureHosts. |
205 | | * We assume that whenever we use double buffering, then we have |
206 | | * render-to-texture and thus no texture upload to do. |
207 | | */ |
208 | | class ContentHostDoubleBuffered : public ContentHostTexture |
209 | | { |
210 | | public: |
211 | | explicit ContentHostDoubleBuffered(const TextureInfo& aTextureInfo) |
212 | | : ContentHostTexture(aTextureInfo) |
213 | 0 | {} |
214 | | |
215 | 0 | virtual ~ContentHostDoubleBuffered() {} |
216 | | |
217 | 0 | virtual CompositableType GetType() override { return CompositableType::CONTENT_DOUBLE; } |
218 | | |
219 | | virtual bool UpdateThebes(const ThebesBufferData& aData, |
220 | | const nsIntRegion& aUpdated, |
221 | | const nsIntRegion& aOldValidRegionBack) override; |
222 | | |
223 | | protected: |
224 | | nsIntRegion mValidRegionForNextBackBuffer; |
225 | | }; |
226 | | |
227 | | /** |
228 | | * Single buffered, therefore we must synchronously upload the image from the |
229 | | * TextureHost in the layers transaction (i.e., in UpdateThebes). |
230 | | */ |
231 | | class ContentHostSingleBuffered : public ContentHostTexture |
232 | | { |
233 | | public: |
234 | | explicit ContentHostSingleBuffered(const TextureInfo& aTextureInfo) |
235 | | : ContentHostTexture(aTextureInfo) |
236 | 0 | {} |
237 | 0 | virtual ~ContentHostSingleBuffered() {} |
238 | | |
239 | 0 | virtual CompositableType GetType() override { return CompositableType::CONTENT_SINGLE; } |
240 | | |
241 | | virtual bool UpdateThebes(const ThebesBufferData& aData, |
242 | | const nsIntRegion& aUpdated, |
243 | | const nsIntRegion& aOldValidRegionBack) override; |
244 | | }; |
245 | | |
246 | | } // namespace layers |
247 | | } // namespace mozilla |
248 | | |
249 | | #endif |