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 GFX_LAYERSTYPES_H
8 #define GFX_LAYERSTYPES_H
10 #include <iosfwd> // for ostream
11 #include <stdint.h> // for uint32_t
12 #include <stdio.h> // FILE
16 #include "mozilla/DefineEnum.h" // for MOZ_DEFINE_ENUM_CLASS_WITH_BASE
17 #include "mozilla/Maybe.h"
18 #include "mozilla/TimeStamp.h" // for TimeStamp
20 #include "mozilla/EnumSet.h"
22 #ifndef MOZ_LAYERS_HAVE_LOG
23 # define MOZ_LAYERS_HAVE_LOG
25 #define MOZ_LAYERS_LOG(_args) \
26 MOZ_LOG(LayerManager::GetLog(), LogLevel::Debug, _args)
27 #define MOZ_LAYERS_LOG_IF_SHADOWABLE(layer, _args)
29 #define INVALID_OVERLAY -1
31 // #define ENABLE_FRAME_LATENCY_LOG
40 enum class StyleBorderStyle
: uint8_t;
52 bool IsValid() const { return mId
!= 0; }
54 // Allow explicit cast to a uint64_t for now
55 explicit operator uint64_t() const { return mId
; }
57 // Implement some operators so this class can be used as a key in
59 bool operator<(const LayersId
& aOther
) const { return mId
< aOther
.mId
; }
61 bool operator==(const LayersId
& aOther
) const { return mId
== aOther
.mId
; }
63 bool operator!=(const LayersId
& aOther
) const { return !(*this == aOther
); }
65 friend std::ostream
& operator<<(std::ostream
& aStream
, const LayersId
& aId
);
67 // Helper struct that allow this class to be used as a key in
68 // std::unordered_map like so:
69 // std::unordered_map<LayersId, ValueType, LayersId::HashFn> myMap;
71 std::size_t operator()(const LayersId
& aKey
) const {
72 return std::hash
<uint64_t>{}(aKey
.mId
);
78 struct BaseTransactionId
{
81 bool IsValid() const { return mId
!= 0; }
83 [[nodiscard
]] BaseTransactionId
<T
> Next() const {
84 return BaseTransactionId
<T
>{mId
+ 1};
87 [[nodiscard
]] BaseTransactionId
<T
> Prev() const {
88 return BaseTransactionId
<T
>{mId
- 1};
91 int64_t operator-(const BaseTransactionId
<T
>& aOther
) const {
92 return mId
- aOther
.mId
;
95 // Allow explicit cast to a uint64_t for now
96 explicit operator uint64_t() const { return mId
; }
98 bool operator<(const BaseTransactionId
<T
>& aOther
) const {
99 return mId
< aOther
.mId
;
102 bool operator<=(const BaseTransactionId
<T
>& aOther
) const {
103 return mId
<= aOther
.mId
;
106 bool operator>(const BaseTransactionId
<T
>& aOther
) const {
107 return mId
> aOther
.mId
;
110 bool operator>=(const BaseTransactionId
<T
>& aOther
) const {
111 return mId
>= aOther
.mId
;
114 bool operator==(const BaseTransactionId
<T
>& aOther
) const {
115 return mId
== aOther
.mId
;
118 bool operator!=(const BaseTransactionId
<T
>& aOther
) const {
119 return mId
!= aOther
.mId
;
123 class TransactionIdType
{};
124 typedef BaseTransactionId
<TransactionIdType
> TransactionId
;
126 struct LayersObserverEpoch
{
129 [[nodiscard
]] LayersObserverEpoch
Next() const {
130 return LayersObserverEpoch
{mId
+ 1};
133 bool operator<=(const LayersObserverEpoch
& aOther
) const {
134 return mId
<= aOther
.mId
;
137 bool operator>=(const LayersObserverEpoch
& aOther
) const {
138 return mId
>= aOther
.mId
;
141 bool operator==(const LayersObserverEpoch
& aOther
) const {
142 return mId
== aOther
.mId
;
145 bool operator!=(const LayersObserverEpoch
& aOther
) const {
146 return mId
!= aOther
.mId
;
150 // CompositionOpportunityId is a counter that goes up every time we have an
151 // opportunity to composite. It increments even on no-op composites (if nothing
152 // has changed) and while compositing is paused. It does not skip values if a
153 // composite is delayed. It is meaningful per window.
154 // This counter is used to differentiate intentionally-skipped video frames from
155 // unintentionally-skipped video frames: If CompositionOpportunityIds are
156 // observed by the video in +1 increments, then the video was onscreen the
157 // entire time and compositing was not paused. But if gaps in
158 // CompositionOpportunityIds are observed, that must mean that the video was not
159 // considered during some composition opportunities, because compositing was
160 // paused or because the video was not part of the on-screen scene.
161 class CompositionOpportunityType
{};
162 typedef BaseTransactionId
<CompositionOpportunityType
> CompositionOpportunityId
;
164 /// We make different decisions about resource allocation sizes in WebRender
165 /// depending on whether we are going to render web pages or simpler
166 /// content in the window.
167 enum class WindowKind
: int8_t { MAIN
= 0, SECONDARY
, LAST
};
169 enum class LayersBackend
: int8_t { LAYERS_NONE
= 0, LAYERS_WR
, LAYERS_LAST
};
171 enum class WebRenderBackend
: int8_t { HARDWARE
= 0, SOFTWARE
, LAST
};
173 enum class WebRenderCompositor
: int8_t {
184 const char* GetLayersBackendName(LayersBackend aBackend
);
186 enum class TextureType
: int8_t {
191 AndroidHardwareBuffer
,
197 enum class BufferMode
: int8_t { BUFFER_NONE
, BUFFERED
};
199 enum class DrawRegionClip
: int8_t { DRAW
, NONE
};
201 enum class SurfaceMode
: int8_t {
204 SURFACE_SINGLE_CHANNEL_ALPHA
,
205 SURFACE_COMPONENT_ALPHA
209 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(
213 // Unimplemented - PRESERVE_ASPECT_RATIO_CONTAIN
217 // Bit flags that go on a RefLayer and override the
218 // event regions in the entire subtree below. This is needed for propagating
219 // various flags across processes since the child-process layout code doesn't
220 // know about parent-process listeners or CSS rules.
221 enum EventRegionsOverride
{
222 // The default, no flags set
224 // Treat all hit regions in the subtree as dispatch-to-content
225 ForceDispatchToContent
= (1 << 0),
226 // Treat all hit regions in the subtree as empty
227 ForceEmptyHitRegion
= (1 << 1),
228 // OR union of all valid bit flags, for use in BitFlagsEnumSerializer
229 ALL_BITS
= (1 << 2) - 1
232 MOZ_ALWAYS_INLINE EventRegionsOverride
operator|(EventRegionsOverride a
,
233 EventRegionsOverride b
) {
234 return (EventRegionsOverride
)((int)a
| (int)b
);
237 MOZ_ALWAYS_INLINE EventRegionsOverride
& operator|=(EventRegionsOverride
& a
,
238 EventRegionsOverride b
) {
243 // Flags used as an argument to functions that dump textures.
244 enum TextureDumpMode
{
245 Compress
, // dump texture with LZ4 compression
246 DoNotCompress
// dump texture uncompressed
249 // Corresponding bit masks for allowed touch behaviors
250 // are defined in AllowedTouchBehavior
251 typedef uint32_t TouchBehaviorFlags
;
253 // Some specialized typedefs of Matrix4x4Typed.
254 typedef gfx::Matrix4x4Typed
<LayerPixel
, CSSTransformedLayerPixel
>
256 // Several different async transforms can contribute to a layer's transform
257 // (specifically, an async animation can contribute a transform, and each APZC
258 // that scrolls a layer can contribute async scroll/zoom and overscroll
260 // To try to model this with typed units, we represent individual async
261 // transforms as ParentLayer -> ParentLayer transforms (aliased as
262 // AsyncTransformComponentMatrix), and we represent the product of all of them
263 // as a CSSTransformLayer -> ParentLayer transform (aliased as
264 // AsyncTransformMatrix). To create an AsyncTransformMatrix from component
265 // matrices, a ViewAs operation is needed. A MultipleAsyncTransforms
266 // PixelCastJustification is provided for this purpose.
267 typedef gfx::Matrix4x4Typed
<ParentLayerPixel
, ParentLayerPixel
>
268 AsyncTransformComponentMatrix
;
269 typedef gfx::Matrix4x4Typed
<CSSTransformedLayerPixel
, ParentLayerPixel
>
270 AsyncTransformMatrix
;
272 typedef Array
<gfx::DeviceColor
, 4> BorderColors
;
273 typedef Array
<LayerSize
, 4> BorderCorners
;
274 typedef Array
<LayerCoord
, 4> BorderWidths
;
275 typedef Array
<StyleBorderStyle
, 4> BorderStyles
;
277 typedef Maybe
<LayerRect
> MaybeLayerRect
;
279 // This is used to communicate Layers across IPC channels. The Handle is valid
280 // for layers in the same PLayerTransaction. Handles are created by
281 // ClientLayerManager, and are cached in LayerTransactionParent on first use.
282 class LayerHandle final
{
283 friend struct IPC::ParamTraits
<mozilla::layers::LayerHandle
>;
286 LayerHandle() : mHandle(0) {}
287 LayerHandle(const LayerHandle
& aOther
) = default;
288 explicit LayerHandle(uint64_t aHandle
) : mHandle(aHandle
) {}
289 bool IsValid() const { return mHandle
!= 0; }
290 explicit operator bool() const { return IsValid(); }
291 bool operator==(const LayerHandle
& aOther
) const {
292 return mHandle
== aOther
.mHandle
;
294 uint64_t Value() const { return mHandle
; }
300 // This is used to communicate Compositables across IPC channels. The Handle is
301 // valid for layers in the same PLayerTransaction or PImageBridge. Handles are
302 // created by ClientLayerManager or ImageBridgeChild, and are cached in the
303 // parent side on first use.
304 class CompositableHandle final
{
305 friend struct IPC::ParamTraits
<mozilla::layers::CompositableHandle
>;
308 static CompositableHandle
GetNext();
310 CompositableHandle() : mHandle(0) {}
311 CompositableHandle(const CompositableHandle
& aOther
) = default;
312 explicit CompositableHandle(uint64_t aHandle
) : mHandle(aHandle
) {}
313 bool IsValid() const { return mHandle
!= 0; }
314 explicit operator bool() const { return IsValid(); }
315 explicit operator uint64_t() const { return mHandle
; }
316 bool operator==(const CompositableHandle
& aOther
) const {
317 return mHandle
== aOther
.mHandle
;
319 bool operator!=(const CompositableHandle
& aOther
) const {
320 return !(*this == aOther
);
322 uint64_t Value() const { return mHandle
; }
328 enum class CompositableHandleOwner
: uint8_t {
333 struct RemoteTextureId
{
336 auto MutTiedFields() { return std::tie(mId
); }
338 static RemoteTextureId
GetNext();
340 static constexpr RemoteTextureId
Max() { return RemoteTextureId
{UINT64_MAX
}; }
342 bool IsValid() const { return mId
!= 0; }
344 // Allow explicit cast to a uint64_t for now
345 explicit operator uint64_t() const { return mId
; }
347 // Implement some operators so this class can be used as a key in
349 bool operator<(const RemoteTextureId
& aOther
) const {
350 return mId
< aOther
.mId
;
353 bool operator>(const RemoteTextureId
& aOther
) const {
354 return mId
> aOther
.mId
;
357 bool operator==(const RemoteTextureId
& aOther
) const {
358 return mId
== aOther
.mId
;
361 bool operator!=(const RemoteTextureId
& aOther
) const {
362 return !(*this == aOther
);
365 bool operator>=(const RemoteTextureId
& aOther
) const {
366 return mId
>= aOther
.mId
;
369 // Helper struct that allow this class to be used as a key in
370 // std::unordered_map like so:
371 // std::unordered_map<RemoteTextureId, ValueType, RemoteTextureId::HashFn>
374 std::size_t operator()(const RemoteTextureId aKey
) const {
375 return std::hash
<uint64_t>{}(aKey
.mId
);
380 struct RemoteTextureOwnerId
{
383 auto MutTiedFields() { return std::tie(mId
); }
385 static RemoteTextureOwnerId
GetNext();
387 bool IsValid() const { return mId
!= 0; }
389 // Allow explicit cast to a uint64_t for now
390 explicit operator uint64_t() const { return mId
; }
392 // Implement some operators so this class can be used as a key in
394 bool operator<(const RemoteTextureOwnerId
& aOther
) const {
395 return mId
< aOther
.mId
;
398 bool operator==(const RemoteTextureOwnerId
& aOther
) const {
399 return mId
== aOther
.mId
;
402 bool operator!=(const RemoteTextureOwnerId
& aOther
) const {
403 return !(*this == aOther
);
406 // Helper struct that allow this class to be used as a key in
407 // std::unordered_map like so:
408 // std::unordered_map<RemoteTextureOwnerId, ValueType,
409 // RemoteTextureOwnerId::HashFn> myMap;
411 std::size_t operator()(const RemoteTextureOwnerId aKey
) const {
412 return std::hash
<uint64_t>{}(aKey
.mId
);
417 // TextureId allocated in GPU process
418 struct GpuProcessTextureId
{
421 static GpuProcessTextureId
GetNext();
423 bool IsValid() const { return mId
!= 0; }
425 // Allow explicit cast to a uint64_t for now
426 explicit operator uint64_t() const { return mId
; }
428 bool operator==(const GpuProcessTextureId
& aOther
) const {
429 return mId
== aOther
.mId
;
432 bool operator!=(const GpuProcessTextureId
& aOther
) const {
433 return !(*this == aOther
);
436 // Helper struct that allow this class to be used as a key in
437 // std::unordered_map like so:
438 // std::unordered_map<GpuProcessTextureId, ValueType,
439 // GpuProcessTextureId::HashFn> myMap;
441 std::size_t operator()(const GpuProcessTextureId aKey
) const {
442 return std::hash
<uint64_t>{}(aKey
.mId
);
448 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollDirection
, uint8_t, (
453 using ScrollDirections
= EnumSet
<ScrollDirection
, uint8_t>;
455 constexpr ScrollDirections
EitherScrollDirection(ScrollDirection::eVertical
,ScrollDirection::eHorizontal
);
456 constexpr ScrollDirections
HorizontalScrollDirection(ScrollDirection::eHorizontal
);
457 constexpr ScrollDirections
VerticalScrollDirection(ScrollDirection::eVertical
);
459 // Return the scroll directions which have a nonzero component in |aDelta|.
460 template <typename Point
>
461 ScrollDirections
DirectionsInDelta(const Point
& aDelta
) {
462 ScrollDirections result
;
464 result
+= ScrollDirection::eHorizontal
;
467 result
+= ScrollDirection::eVertical
;
472 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(CompositionPayloadType
, uint8_t, (
474 * A |CompositionPayload| with this type indicates a key press happened
475 * before composition and will be used to determine latency between key press
476 * and presentation in |mozilla::Telemetry::KEYPRESS_PRESENT_LATENCY|
481 * A |CompositionPayload| with this type indicates that an APZ scroll event
482 * occurred that will be included in the composition.
487 * A |CompositionPayload| with this type indicates that an APZ pinch-to-zoom
488 * event occurred that will be included in the composition.
493 * A |CompositionPayload| with this type indicates that content was painted
494 * that will be included in the composition.
499 * A |CompositionPayload| with this type indicates a mouse up (which caused
500 * a click to happen) happened before composition and will be used to determine latency
501 * between mouse up and presentation in
502 * |mozilla::Telemetry::MOUSEUP_FOLLOWED_BY_CLICK_PRESENT_LATENCY|
504 eMouseUpFollowedByClick
508 extern const char* kCompositionPayloadTypeNames
[kCompositionPayloadTypeCount
];
510 struct CompositionPayload
{
511 bool operator==(const CompositionPayload
& aOther
) const {
512 return mType
== aOther
.mType
&& mTimeStamp
== aOther
.mTimeStamp
;
514 /* The type of payload that is in this composition */
515 CompositionPayloadType mType
;
516 /* When this payload was generated */
517 TimeStamp mTimeStamp
;
520 } // namespace layers
521 } // namespace mozilla
523 #endif /* GFX_LAYERSTYPES_H */