Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef GFX_LAYERSTYPES_H
7 : #define GFX_LAYERSTYPES_H
8 :
9 : #include <stdint.h> // for uint32_t
10 :
11 : #include "Units.h"
12 : #include "mozilla/DefineEnum.h" // for MOZ_DEFINE_ENUM
13 : #include "mozilla/gfx/Point.h" // for IntPoint
14 : #include "mozilla/Maybe.h"
15 : #include "mozilla/TypedEnumBits.h"
16 : #include "nsRegion.h"
17 :
18 : #include <stdio.h> // FILE
19 : #include "mozilla/Logging.h" // for PR_LOG
20 :
21 : #ifndef MOZ_LAYERS_HAVE_LOG
22 : # define MOZ_LAYERS_HAVE_LOG
23 : #endif
24 : #define MOZ_LAYERS_LOG(_args) \
25 : MOZ_LOG(LayerManager::GetLog(), LogLevel::Debug, _args)
26 : #define MOZ_LAYERS_LOG_IF_SHADOWABLE(layer, _args) \
27 : do { if (layer->AsShadowableLayer()) { MOZ_LOG(LayerManager::GetLog(), LogLevel::Debug, _args); } } while (0)
28 :
29 : #define INVALID_OVERLAY -1
30 :
31 : namespace IPC {
32 : template <typename T> struct ParamTraits;
33 : } // namespace IPC
34 :
35 : namespace android {
36 : class MOZ_EXPORT GraphicBuffer;
37 : } // namespace android
38 :
39 : struct nsStyleFilter;
40 :
41 : namespace mozilla {
42 : namespace layers {
43 :
44 : class TextureHost;
45 :
46 : #undef NONE
47 : #undef OPAQUE
48 :
49 : enum class LayersBackend : int8_t {
50 : LAYERS_NONE = 0,
51 : LAYERS_BASIC,
52 : LAYERS_OPENGL,
53 : LAYERS_D3D11,
54 : LAYERS_CLIENT,
55 : LAYERS_WR,
56 : LAYERS_LAST
57 : };
58 :
59 : enum class BufferMode : int8_t {
60 : BUFFER_NONE,
61 : BUFFERED
62 : };
63 :
64 : enum class DrawRegionClip : int8_t {
65 : DRAW,
66 : NONE
67 : };
68 :
69 : enum class SurfaceMode : int8_t {
70 : SURFACE_NONE = 0,
71 : SURFACE_OPAQUE,
72 : SURFACE_SINGLE_CHANNEL_ALPHA,
73 : SURFACE_COMPONENT_ALPHA
74 : };
75 :
76 : MOZ_DEFINE_ENUM_CLASS_WITH_BASE(
77 : ScaleMode, int8_t, (
78 : SCALE_NONE,
79 : STRETCH
80 : // Unimplemented - PRESERVE_ASPECT_RATIO_CONTAIN
81 : ));
82 :
83 1636 : struct EventRegions {
84 : // The hit region for a layer contains all areas on the layer that are
85 : // sensitive to events. This region is an over-approximation and may
86 : // contain regions that are not actually sensitive, but any such regions
87 : // will be included in the mDispatchToContentHitRegion.
88 : nsIntRegion mHitRegion;
89 : // The mDispatchToContentHitRegion for a layer contains all areas for
90 : // which the main-thread must be consulted before responding to events.
91 : // This region will be a subregion of mHitRegion.
92 : nsIntRegion mDispatchToContentHitRegion;
93 :
94 : // The following regions represent the touch-action areas of this layer.
95 : // All of these regions are approximations to the true region, but any
96 : // variance between the approximation and the true region is guaranteed
97 : // to be included in the mDispatchToContentHitRegion.
98 : nsIntRegion mNoActionRegion;
99 : nsIntRegion mHorizontalPanRegion;
100 : nsIntRegion mVerticalPanRegion;
101 :
102 742 : EventRegions()
103 742 : {
104 742 : }
105 :
106 0 : explicit EventRegions(nsIntRegion aHitRegion)
107 0 : : mHitRegion(aHitRegion)
108 : {
109 0 : }
110 :
111 266 : bool operator==(const EventRegions& aRegions) const
112 : {
113 466 : return mHitRegion == aRegions.mHitRegion &&
114 394 : mDispatchToContentHitRegion == aRegions.mDispatchToContentHitRegion &&
115 388 : mNoActionRegion == aRegions.mNoActionRegion &&
116 654 : mHorizontalPanRegion == aRegions.mHorizontalPanRegion &&
117 460 : mVerticalPanRegion == aRegions.mVerticalPanRegion;
118 : }
119 266 : bool operator!=(const EventRegions& aRegions) const
120 : {
121 266 : return !(*this == aRegions);
122 : }
123 :
124 115 : void ApplyTranslationAndScale(float aXTrans, float aYTrans, float aXScale, float aYScale)
125 : {
126 115 : mHitRegion.ScaleRoundOut(aXScale, aYScale);
127 115 : mDispatchToContentHitRegion.ScaleRoundOut(aXScale, aYScale);
128 115 : mNoActionRegion.ScaleRoundOut(aXScale, aYScale);
129 115 : mHorizontalPanRegion.ScaleRoundOut(aXScale, aYScale);
130 115 : mVerticalPanRegion.ScaleRoundOut(aXScale, aYScale);
131 :
132 115 : mHitRegion.MoveBy(aXTrans, aYTrans);
133 115 : mDispatchToContentHitRegion.MoveBy(aXTrans, aYTrans);
134 115 : mNoActionRegion.MoveBy(aXTrans, aYTrans);
135 115 : mHorizontalPanRegion.MoveBy(aXTrans, aYTrans);
136 115 : mVerticalPanRegion.MoveBy(aXTrans, aYTrans);
137 115 : }
138 :
139 : void Transform(const gfx::Matrix4x4& aTransform)
140 : {
141 : mHitRegion.Transform(aTransform);
142 : mDispatchToContentHitRegion.Transform(aTransform);
143 : mNoActionRegion.Transform(aTransform);
144 : mHorizontalPanRegion.Transform(aTransform);
145 : mVerticalPanRegion.Transform(aTransform);
146 : }
147 :
148 0 : bool IsEmpty() const
149 : {
150 0 : return mHitRegion.IsEmpty()
151 0 : && mDispatchToContentHitRegion.IsEmpty()
152 0 : && mNoActionRegion.IsEmpty()
153 0 : && mHorizontalPanRegion.IsEmpty()
154 0 : && mVerticalPanRegion.IsEmpty();
155 : }
156 :
157 0 : nsCString ToString() const
158 : {
159 0 : nsCString result = mHitRegion.ToString();
160 0 : result.AppendLiteral(";dispatchToContent=");
161 0 : result.Append(mDispatchToContentHitRegion.ToString());
162 0 : return result;
163 : }
164 : };
165 :
166 : // Bit flags that go on a ContainerLayer (or RefLayer) and override the
167 : // event regions in the entire subtree below. This is needed for propagating
168 : // various flags across processes since the child-process layout code doesn't
169 : // know about parent-process listeners or CSS rules.
170 : enum EventRegionsOverride {
171 : // The default, no flags set
172 : NoOverride = 0,
173 : // Treat all hit regions in the subtree as dispatch-to-content
174 : ForceDispatchToContent = (1 << 0),
175 : // Treat all hit regions in the subtree as empty
176 : ForceEmptyHitRegion = (1 << 1),
177 : // OR union of all valid bit flags, for use in BitFlagsEnumSerializer
178 : ALL_BITS = (1 << 2) - 1
179 : };
180 :
181 : MOZ_ALWAYS_INLINE EventRegionsOverride
182 183 : operator|(EventRegionsOverride a, EventRegionsOverride b)
183 : {
184 183 : return (EventRegionsOverride)((int)a | (int)b);
185 : }
186 :
187 : MOZ_ALWAYS_INLINE EventRegionsOverride&
188 183 : operator|=(EventRegionsOverride& a, EventRegionsOverride b)
189 : {
190 183 : a = a | b;
191 183 : return a;
192 : }
193 :
194 : // Flags used as an argument to functions that dump textures.
195 : enum TextureDumpMode {
196 : Compress, // dump texture with LZ4 compression
197 : DoNotCompress // dump texture uncompressed
198 : };
199 :
200 : // Some specialized typedefs of Matrix4x4Typed.
201 : typedef gfx::Matrix4x4Typed<LayerPixel, CSSTransformedLayerPixel> CSSTransformMatrix;
202 : // Several different async transforms can contribute to a layer's transform
203 : // (specifically, an async animation can contribute a transform, and each APZC
204 : // that scrolls a layer can contribute async scroll/zoom and overscroll
205 : // transforms).
206 : // To try to model this with typed units, we represent individual async
207 : // transforms as ParentLayer -> ParentLayer transforms (aliased as
208 : // AsyncTransformComponentMatrix), and we represent the product of all of them
209 : // as a CSSTransformLayer -> ParentLayer transform (aliased as
210 : // AsyncTransformMatrix). To create an AsyncTransformMatrix from component
211 : // matrices, a ViewAs operation is needed. A MultipleAsyncTransforms
212 : // PixelCastJustification is provided for this purpose.
213 : typedef gfx::Matrix4x4Typed<ParentLayerPixel, ParentLayerPixel> AsyncTransformComponentMatrix;
214 : typedef gfx::Matrix4x4Typed<CSSTransformedLayerPixel, ParentLayerPixel> AsyncTransformMatrix;
215 :
216 : typedef Array<gfx::Color, 4> BorderColors;
217 : typedef Array<LayerSize, 4> BorderCorners;
218 : typedef Array<LayerCoord, 4> BorderWidths;
219 : typedef Array<uint8_t, 4> BorderStyles;
220 :
221 : typedef Maybe<LayerRect> MaybeLayerRect;
222 :
223 : // This is used to communicate Layers across IPC channels. The Handle is valid
224 : // for layers in the same PLayerTransaction. Handles are created by ClientLayerManager,
225 : // and are cached in LayerTransactionParent on first use.
226 : class LayerHandle
227 : {
228 : friend struct IPC::ParamTraits<mozilla::layers::LayerHandle>;
229 : public:
230 1864 : LayerHandle() : mHandle(0)
231 1864 : {}
232 124 : LayerHandle(const LayerHandle& aOther) : mHandle(aOther.mHandle)
233 124 : {}
234 31 : explicit LayerHandle(uint64_t aHandle) : mHandle(aHandle)
235 31 : {}
236 772 : bool IsValid() const {
237 772 : return mHandle != 0;
238 : }
239 554 : explicit operator bool() const {
240 554 : return IsValid();
241 : }
242 0 : bool operator ==(const LayerHandle& aOther) const {
243 0 : return mHandle == aOther.mHandle;
244 : }
245 345 : uint64_t Value() const {
246 345 : return mHandle;
247 : }
248 : private:
249 : uint64_t mHandle;
250 : };
251 :
252 : // This is used to communicate Compositables across IPC channels. The Handle is valid
253 : // for layers in the same PLayerTransaction or PImageBridge. Handles are created by
254 : // ClientLayerManager or ImageBridgeChild, and are cached in the parent side on first
255 : // use.
256 : class CompositableHandle
257 : {
258 : friend struct IPC::ParamTraits<mozilla::layers::CompositableHandle>;
259 : public:
260 568 : CompositableHandle() : mHandle(0)
261 568 : {}
262 140 : CompositableHandle(const CompositableHandle& aOther) : mHandle(aOther.mHandle)
263 140 : {}
264 22 : explicit CompositableHandle(uint64_t aHandle) : mHandle(aHandle)
265 22 : {}
266 260 : bool IsValid() const {
267 260 : return mHandle != 0;
268 : }
269 260 : explicit operator bool() const {
270 260 : return IsValid();
271 : }
272 0 : bool operator ==(const CompositableHandle& aOther) const {
273 0 : return mHandle == aOther.mHandle;
274 : }
275 170 : uint64_t Value() const {
276 170 : return mHandle;
277 : }
278 : private:
279 : uint64_t mHandle;
280 : };
281 :
282 : class ReadLockHandle
283 : {
284 : friend struct IPC::ParamTraits<mozilla::layers::ReadLockHandle>;
285 : public:
286 396 : ReadLockHandle() : mHandle(0)
287 396 : {}
288 : ReadLockHandle(const ReadLockHandle& aOther) : mHandle(aOther.mHandle)
289 : {}
290 33 : explicit ReadLockHandle(uint64_t aHandle) : mHandle(aHandle)
291 33 : {}
292 : bool IsValid() const {
293 : return mHandle != 0;
294 : }
295 : explicit operator bool() const {
296 : return IsValid();
297 : }
298 0 : bool operator ==(const ReadLockHandle& aOther) const {
299 0 : return mHandle == aOther.mHandle;
300 : }
301 99 : uint64_t Value() const {
302 99 : return mHandle;
303 : }
304 : private:
305 : uint64_t mHandle;
306 : };
307 :
308 : MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollDirection, uint32_t, (
309 : NONE,
310 : VERTICAL,
311 : HORIZONTAL
312 : ));
313 :
314 : enum class CSSFilterType : int8_t {
315 : BLUR,
316 : BRIGHTNESS,
317 : CONTRAST,
318 : GRAYSCALE,
319 : HUE_ROTATE,
320 : INVERT,
321 : OPACITY,
322 : SATURATE,
323 : SEPIA,
324 : };
325 :
326 : struct CSSFilter {
327 : CSSFilterType type;
328 : float argument;
329 : };
330 :
331 : CSSFilter ToCSSFilter(const nsStyleFilter& filter);
332 :
333 : } // namespace layers
334 : } // namespace mozilla
335 :
336 : #endif /* GFX_LAYERSTYPES_H */
|