Bug 1733135 [wpt PR 30930] - Update wpt metadata, a=testonly
[gecko.git] / image / ImageMetadata.h
blob03513084813acbd3bcc23f3ccdda71b6cf314027
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(nsIntSize(aWidth, aHeight));
60 mOrientation.emplace(aOrientation);
61 mResolution = aResolution;
64 nsIntSize GetSize() const { return *mSize; }
65 bool HasSize() const { return mSize.isSome(); }
67 void AddNativeSize(const nsIntSize& aSize) {
68 mNativeSizes.AppendElement(aSize);
71 Resolution GetResolution() const { return mResolution; }
73 const nsTArray<nsIntSize>& GetNativeSizes() const { return mNativeSizes; }
75 Orientation GetOrientation() const { return *mOrientation; }
76 bool HasOrientation() const { return mOrientation.isSome(); }
78 void SetHasAnimation() { mHasAnimation = true; }
79 bool HasAnimation() const { return mHasAnimation; }
81 private:
82 /// The hotspot found on cursors, if present.
83 Maybe<gfx::IntPoint> mHotspot;
85 /// The loop count for animated images, or -1 for infinite loop.
86 int32_t mLoopCount = -1;
88 /// The resolution of the image in dppx.
89 Resolution mResolution;
91 // The total length of a single loop through an animated image.
92 Maybe<FrameTimeout> mLoopLength;
94 /// The timeout of an animated image's first frame.
95 FrameTimeout mFirstFrameTimeout = FrameTimeout::Forever();
97 // The area of the image that needs to be invalidated when the animation
98 // loops.
99 Maybe<gfx::IntRect> mFirstFrameRefreshArea;
101 Maybe<nsIntSize> mSize;
102 Maybe<Orientation> mOrientation;
104 // Sizes the image can natively decode to.
105 CopyableTArray<nsIntSize> mNativeSizes;
107 bool mHasAnimation = false;
110 } // namespace mozilla::image
112 #endif // mozilla_image_ImageMetadata_h