Bug 1869092 - Fix timeouts in browser_PanelMultiView.js. r=twisniewski,test-only
[gecko.git] / image / ImageMetadata.h
blob0648812339af194e8ee158f749a07e666166bf3a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 mozilla_image_ImageMetadata_h
8 #define mozilla_image_ImageMetadata_h
10 #include <stdint.h>
11 #include <utility>
12 #include "FrameTimeout.h"
13 #include "Orientation.h"
14 #include "mozilla/Maybe.h"
15 #include "mozilla/gfx/Point.h"
16 #include "mozilla/gfx/Rect.h"
17 #include "mozilla/image/Resolution.h"
18 #include "nsSize.h"
19 #include "nsTArray.h"
21 namespace mozilla::image {
23 // The metadata about an image that decoders accumulate as they decode.
24 class ImageMetadata {
25 public:
26 ImageMetadata() = default;
28 void SetHotspot(uint16_t aHotspotX, uint16_t aHotspotY) {
29 mHotspot = Some(gfx::IntPoint(aHotspotX, aHotspotY));
31 gfx::IntPoint GetHotspot() const { return *mHotspot; }
32 bool HasHotspot() const { return mHotspot.isSome(); }
34 void SetLoopCount(int32_t loopcount) { mLoopCount = loopcount; }
35 int32_t GetLoopCount() const { return mLoopCount; }
37 void SetLoopLength(FrameTimeout aLength) { mLoopLength = Some(aLength); }
38 FrameTimeout GetLoopLength() const { return *mLoopLength; }
39 bool HasLoopLength() const { return mLoopLength.isSome(); }
41 void SetFirstFrameTimeout(FrameTimeout aTimeout) {
42 mFirstFrameTimeout = aTimeout;
44 FrameTimeout GetFirstFrameTimeout() const { return mFirstFrameTimeout; }
46 void SetFirstFrameRefreshArea(const gfx::IntRect& aRefreshArea) {
47 mFirstFrameRefreshArea = Some(aRefreshArea);
49 gfx::IntRect GetFirstFrameRefreshArea() const {
50 return *mFirstFrameRefreshArea;
52 bool HasFirstFrameRefreshArea() const {
53 return mFirstFrameRefreshArea.isSome();
56 void SetSize(int32_t aWidth, int32_t aHeight, Orientation aOrientation,
57 Resolution aResolution) {
58 if (!HasSize()) {
59 mSize.emplace(
60 aOrientation.ToOriented(UnorientedIntSize(aWidth, aHeight)));
61 mOrientation.emplace(aOrientation);
62 mResolution = aResolution;
65 OrientedIntSize GetSize() const { return *mSize; }
66 bool HasSize() const { return mSize.isSome(); }
68 void AddNativeSize(const OrientedIntSize& aSize) {
69 mNativeSizes.AppendElement(aSize);
72 Resolution GetResolution() const { return mResolution; }
74 const nsTArray<OrientedIntSize>& GetNativeSizes() const {
75 return mNativeSizes;
78 Orientation GetOrientation() const { return *mOrientation; }
79 bool HasOrientation() const { return mOrientation.isSome(); }
81 void SetHasAnimation() { mHasAnimation = true; }
82 bool HasAnimation() const { return mHasAnimation; }
84 private:
85 /// The hotspot found on cursors, if present.
86 Maybe<gfx::IntPoint> mHotspot;
88 /// The loop count for animated images, or -1 for infinite loop.
89 int32_t mLoopCount = -1;
91 /// The resolution of the image in dppx.
92 Resolution mResolution;
94 // The total length of a single loop through an animated image.
95 Maybe<FrameTimeout> mLoopLength;
97 /// The timeout of an animated image's first frame.
98 FrameTimeout mFirstFrameTimeout = FrameTimeout::Forever();
100 // The area of the image that needs to be invalidated when the animation
101 // loops.
102 Maybe<gfx::IntRect> mFirstFrameRefreshArea;
104 Maybe<OrientedIntSize> mSize;
105 Maybe<Orientation> mOrientation;
107 // Sizes the image can natively decode to.
108 CopyableTArray<OrientedIntSize> mNativeSizes;
110 bool mHasAnimation = false;
113 } // namespace mozilla::image
115 #endif // mozilla_image_ImageMetadata_h