Bug 1876318 - set shipping-product for push-bundle tasks. r=bhearsum,releng-reviewers
[gecko.git] / gfx / layers / LayersTypes.h
blob340ea76fa59b2cf0a0ae5eebd942bcbbd0e03b07
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
13 #include <tuple>
15 #include "Units.h"
16 #include "mozilla/DefineEnum.h" // for MOZ_DEFINE_ENUM_CLASS_WITH_BASE
17 #include "mozilla/Maybe.h"
18 #include "mozilla/TimeStamp.h" // for TimeStamp
19 #include "nsRegion.h"
20 #include "mozilla/EnumSet.h"
22 #ifndef MOZ_LAYERS_HAVE_LOG
23 # define MOZ_LAYERS_HAVE_LOG
24 #endif
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
33 namespace IPC {
34 template <typename T>
35 struct ParamTraits;
36 } // namespace IPC
38 namespace mozilla {
40 enum class StyleBorderStyle : uint8_t;
42 namespace layers {
44 class TextureHost;
46 #undef NONE
47 #undef OPAQUE
49 struct LayersId {
50 uint64_t mId = 0;
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
58 // stdlib classes.
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;
70 struct HashFn {
71 std::size_t operator()(const LayersId& aKey) const {
72 return std::hash<uint64_t>{}(aKey.mId);
77 template <typename T>
78 struct BaseTransactionId {
79 uint64_t mId = 0;
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 // CompositionOpportunityId is a counter that goes up every time we have an
127 // opportunity to composite. It increments even on no-op composites (if nothing
128 // has changed) and while compositing is paused. It does not skip values if a
129 // composite is delayed. It is meaningful per window.
130 // This counter is used to differentiate intentionally-skipped video frames from
131 // unintentionally-skipped video frames: If CompositionOpportunityIds are
132 // observed by the video in +1 increments, then the video was onscreen the
133 // entire time and compositing was not paused. But if gaps in
134 // CompositionOpportunityIds are observed, that must mean that the video was not
135 // considered during some composition opportunities, because compositing was
136 // paused or because the video was not part of the on-screen scene.
137 class CompositionOpportunityType {};
138 typedef BaseTransactionId<CompositionOpportunityType> CompositionOpportunityId;
140 /// We make different decisions about resource allocation sizes in WebRender
141 /// depending on whether we are going to render web pages or simpler
142 /// content in the window.
143 enum class WindowKind : int8_t { MAIN = 0, SECONDARY, LAST };
145 enum class LayersBackend : int8_t { LAYERS_NONE = 0, LAYERS_WR, LAYERS_LAST };
147 enum class WebRenderBackend : int8_t { HARDWARE = 0, SOFTWARE, LAST };
149 enum class WebRenderCompositor : int8_t {
150 DRAW = 0,
151 DIRECT_COMPOSITION,
152 CORE_ANIMATION,
153 SOFTWARE,
154 D3D11,
155 OPENGL,
156 WAYLAND,
157 LAST
160 const char* GetLayersBackendName(LayersBackend aBackend);
162 enum class TextureType : int8_t {
163 Unknown = 0,
164 D3D11,
165 MacIOSurface,
166 AndroidNativeWindow,
167 AndroidHardwareBuffer,
168 DMABUF,
169 EGLImage,
170 Last
173 enum class BufferMode : int8_t { BUFFER_NONE, BUFFERED };
175 enum class DrawRegionClip : int8_t { DRAW, NONE };
177 enum class SurfaceMode : int8_t {
178 SURFACE_NONE = 0,
179 SURFACE_OPAQUE,
180 SURFACE_SINGLE_CHANNEL_ALPHA,
181 SURFACE_COMPONENT_ALPHA
184 // clang-format off
185 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(
186 ScaleMode, int8_t, (
187 SCALE_NONE,
188 STRETCH
189 // Unimplemented - PRESERVE_ASPECT_RATIO_CONTAIN
191 // clang-format on
193 // Bit flags that go on a RefLayer and override the
194 // event regions in the entire subtree below. This is needed for propagating
195 // various flags across processes since the child-process layout code doesn't
196 // know about parent-process listeners or CSS rules.
197 enum EventRegionsOverride {
198 // The default, no flags set
199 NoOverride = 0,
200 // Treat all hit regions in the subtree as dispatch-to-content
201 ForceDispatchToContent = (1 << 0),
202 // Treat all hit regions in the subtree as empty
203 ForceEmptyHitRegion = (1 << 1),
204 // OR union of all valid bit flags, for use in BitFlagsEnumSerializer
205 ALL_BITS = (1 << 2) - 1
208 MOZ_ALWAYS_INLINE EventRegionsOverride operator|(EventRegionsOverride a,
209 EventRegionsOverride b) {
210 return (EventRegionsOverride)((int)a | (int)b);
213 MOZ_ALWAYS_INLINE EventRegionsOverride& operator|=(EventRegionsOverride& a,
214 EventRegionsOverride b) {
215 a = a | b;
216 return a;
219 // Flags used as an argument to functions that dump textures.
220 enum TextureDumpMode {
221 Compress, // dump texture with LZ4 compression
222 DoNotCompress // dump texture uncompressed
225 // Corresponding bit masks for allowed touch behaviors
226 // are defined in AllowedTouchBehavior
227 typedef uint32_t TouchBehaviorFlags;
229 // Some specialized typedefs of Matrix4x4Typed.
230 typedef gfx::Matrix4x4Typed<LayerPixel, CSSTransformedLayerPixel>
231 CSSTransformMatrix;
232 // Several different async transforms can contribute to a layer's transform
233 // (specifically, an async animation can contribute a transform, and each APZC
234 // that scrolls a layer can contribute async scroll/zoom and overscroll
235 // transforms).
236 // To try to model this with typed units, we represent individual async
237 // transforms as ParentLayer -> ParentLayer transforms (aliased as
238 // AsyncTransformComponentMatrix), and we represent the product of all of them
239 // as a CSSTransformLayer -> ParentLayer transform (aliased as
240 // AsyncTransformMatrix). To create an AsyncTransformMatrix from component
241 // matrices, a ViewAs operation is needed. A MultipleAsyncTransforms
242 // PixelCastJustification is provided for this purpose.
243 typedef gfx::Matrix4x4Typed<ParentLayerPixel, ParentLayerPixel>
244 AsyncTransformComponentMatrix;
245 typedef gfx::Matrix4x4Typed<CSSTransformedLayerPixel, ParentLayerPixel>
246 AsyncTransformMatrix;
248 typedef Array<gfx::DeviceColor, 4> BorderColors;
249 typedef Array<LayerSize, 4> BorderCorners;
250 typedef Array<LayerCoord, 4> BorderWidths;
251 typedef Array<StyleBorderStyle, 4> BorderStyles;
253 typedef Maybe<LayerRect> MaybeLayerRect;
255 // This is used to communicate Layers across IPC channels. The Handle is valid
256 // for layers in the same PLayerTransaction. Handles are created by
257 // ClientLayerManager, and are cached in LayerTransactionParent on first use.
258 class LayerHandle final {
259 friend struct IPC::ParamTraits<mozilla::layers::LayerHandle>;
261 public:
262 LayerHandle() : mHandle(0) {}
263 LayerHandle(const LayerHandle& aOther) = default;
264 explicit LayerHandle(uint64_t aHandle) : mHandle(aHandle) {}
265 bool IsValid() const { return mHandle != 0; }
266 explicit operator bool() const { return IsValid(); }
267 bool operator==(const LayerHandle& aOther) const {
268 return mHandle == aOther.mHandle;
270 uint64_t Value() const { return mHandle; }
272 private:
273 uint64_t mHandle;
276 // This is used to communicate Compositables across IPC channels. The Handle is
277 // valid for layers in the same PLayerTransaction or PImageBridge. Handles are
278 // created by ClientLayerManager or ImageBridgeChild, and are cached in the
279 // parent side on first use.
280 class CompositableHandle final {
281 friend struct IPC::ParamTraits<mozilla::layers::CompositableHandle>;
283 public:
284 static CompositableHandle GetNext();
286 CompositableHandle() : mHandle(0) {}
287 CompositableHandle(const CompositableHandle& aOther) = default;
288 explicit CompositableHandle(uint64_t aHandle) : mHandle(aHandle) {}
289 bool IsValid() const { return mHandle != 0; }
290 explicit operator bool() const { return IsValid(); }
291 explicit operator uint64_t() const { return mHandle; }
292 bool operator==(const CompositableHandle& aOther) const {
293 return mHandle == aOther.mHandle;
295 bool operator!=(const CompositableHandle& aOther) const {
296 return !(*this == aOther);
298 uint64_t Value() const { return mHandle; }
300 private:
301 uint64_t mHandle;
304 enum class CompositableHandleOwner : uint8_t {
305 WebRenderBridge,
306 ImageBridge,
309 struct RemoteTextureId {
310 uint64_t mId = 0;
312 auto MutTiedFields() { return std::tie(mId); }
314 static RemoteTextureId GetNext();
316 static constexpr RemoteTextureId Max() { return RemoteTextureId{UINT64_MAX}; }
318 bool IsValid() const { return mId != 0; }
320 // Allow explicit cast to a uint64_t for now
321 explicit operator uint64_t() const { return mId; }
323 // Implement some operators so this class can be used as a key in
324 // stdlib classes.
325 bool operator<(const RemoteTextureId& aOther) const {
326 return mId < aOther.mId;
329 bool operator>(const RemoteTextureId& aOther) const {
330 return mId > aOther.mId;
333 bool operator==(const RemoteTextureId& aOther) const {
334 return mId == aOther.mId;
337 bool operator!=(const RemoteTextureId& aOther) const {
338 return !(*this == aOther);
341 bool operator>=(const RemoteTextureId& aOther) const {
342 return mId >= aOther.mId;
345 // Helper struct that allow this class to be used as a key in
346 // std::unordered_map like so:
347 // std::unordered_map<RemoteTextureId, ValueType, RemoteTextureId::HashFn>
348 // myMap;
349 struct HashFn {
350 std::size_t operator()(const RemoteTextureId aKey) const {
351 return std::hash<uint64_t>{}(aKey.mId);
356 struct RemoteTextureOwnerId {
357 uint64_t mId = 0;
359 auto MutTiedFields() { return std::tie(mId); }
361 static RemoteTextureOwnerId GetNext();
363 bool IsValid() const { return mId != 0; }
365 // Allow explicit cast to a uint64_t for now
366 explicit operator uint64_t() const { return mId; }
368 // Implement some operators so this class can be used as a key in
369 // stdlib classes.
370 bool operator<(const RemoteTextureOwnerId& aOther) const {
371 return mId < aOther.mId;
374 bool operator==(const RemoteTextureOwnerId& aOther) const {
375 return mId == aOther.mId;
378 bool operator!=(const RemoteTextureOwnerId& aOther) const {
379 return !(*this == aOther);
382 // Helper struct that allow this class to be used as a key in
383 // std::unordered_map like so:
384 // std::unordered_map<RemoteTextureOwnerId, ValueType,
385 // RemoteTextureOwnerId::HashFn> myMap;
386 struct HashFn {
387 std::size_t operator()(const RemoteTextureOwnerId aKey) const {
388 return std::hash<uint64_t>{}(aKey.mId);
393 typedef uint32_t RemoteTextureTxnType;
394 typedef uint64_t RemoteTextureTxnId;
396 // TextureId allocated in GPU process
397 struct GpuProcessTextureId {
398 uint64_t mId = 0;
400 static GpuProcessTextureId GetNext();
402 bool IsValid() const { return mId != 0; }
404 // Allow explicit cast to a uint64_t for now
405 explicit operator uint64_t() const { return mId; }
407 bool operator==(const GpuProcessTextureId& aOther) const {
408 return mId == aOther.mId;
411 bool operator!=(const GpuProcessTextureId& aOther) const {
412 return !(*this == aOther);
415 // Helper struct that allow this class to be used as a key in
416 // std::unordered_map like so:
417 // std::unordered_map<GpuProcessTextureId, ValueType,
418 // GpuProcessTextureId::HashFn> myMap;
419 struct HashFn {
420 std::size_t operator()(const GpuProcessTextureId aKey) const {
421 return std::hash<uint64_t>{}(aKey.mId);
426 // QueryId allocated in GPU process
427 struct GpuProcessQueryId {
428 uint64_t mId = 0;
430 static GpuProcessQueryId GetNext();
432 bool IsValid() const { return mId != 0; }
434 // Allow explicit cast to a uint64_t for now
435 explicit operator uint64_t() const { return mId; }
437 bool operator==(const GpuProcessQueryId& aOther) const {
438 return mId == aOther.mId;
441 bool operator!=(const GpuProcessQueryId& aOther) const {
442 return !(*this == aOther);
445 // Helper struct that allow this class to be used as a key in
446 // std::unordered_map like so:
447 // std::unordered_map<GpuProcessQueryId, ValueType,
448 // GpuProcessQueryId::HashFn> myMap;
449 struct HashFn {
450 std::size_t operator()(const GpuProcessQueryId aKey) const {
451 return std::hash<uint64_t>{}(aKey.mId);
456 // clang-format off
457 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollDirection, uint8_t, (
458 eVertical,
459 eHorizontal
462 using ScrollDirections = EnumSet<ScrollDirection, uint8_t>;
464 constexpr ScrollDirections EitherScrollDirection(ScrollDirection::eVertical,ScrollDirection::eHorizontal);
465 constexpr ScrollDirections HorizontalScrollDirection(ScrollDirection::eHorizontal);
466 constexpr ScrollDirections VerticalScrollDirection(ScrollDirection::eVertical);
468 // Return the scroll directions which have a nonzero component in |aDelta|.
469 template <typename Point>
470 ScrollDirections DirectionsInDelta(const Point& aDelta) {
471 ScrollDirections result;
472 if (aDelta.x != 0) {
473 result += ScrollDirection::eHorizontal;
475 if (aDelta.y != 0) {
476 result += ScrollDirection::eVertical;
478 return result;
481 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(CompositionPayloadType, uint8_t, (
483 * A |CompositionPayload| with this type indicates a key press happened
484 * before composition and will be used to determine latency between key press
485 * and presentation in |mozilla::Telemetry::KEYPRESS_PRESENT_LATENCY|
487 eKeyPress,
490 * A |CompositionPayload| with this type indicates that an APZ scroll event
491 * occurred that will be included in the composition.
493 eAPZScroll,
496 * A |CompositionPayload| with this type indicates that an APZ pinch-to-zoom
497 * event occurred that will be included in the composition.
499 eAPZPinchZoom,
502 * A |CompositionPayload| with this type indicates that content was painted
503 * that will be included in the composition.
505 eContentPaint,
508 * A |CompositionPayload| with this type indicates a mouse up (which caused
509 * a click to happen) happened before composition and will be used to determine latency
510 * between mouse up and presentation in
511 * |mozilla::Telemetry::MOUSEUP_FOLLOWED_BY_CLICK_PRESENT_LATENCY|
513 eMouseUpFollowedByClick
515 // clang-format on
517 extern const char* kCompositionPayloadTypeNames[kCompositionPayloadTypeCount];
519 struct CompositionPayload {
520 bool operator==(const CompositionPayload& aOther) const {
521 return mType == aOther.mType && mTimeStamp == aOther.mTimeStamp;
523 /* The type of payload that is in this composition */
524 CompositionPayloadType mType;
525 /* When this payload was generated */
526 TimeStamp mTimeStamp;
529 } // namespace layers
530 } // namespace mozilla
532 #endif /* GFX_LAYERSTYPES_H */