Bug 1655184 [wpt PR 24743] - [LCP] Ignore paints with opacity 0, a=testonly
[gecko.git] / image / ImageMetadata.h
blob33e95d850f44c49b514abe0507e859eb89ba4555
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 "mozilla/Maybe.h"
12 #include "nsSize.h"
13 #include "nsTArray.h"
14 #include "Orientation.h"
15 #include "FrameTimeout.h"
17 namespace mozilla {
18 namespace image {
20 // The metadata about an image that decoders accumulate as they decode.
21 class ImageMetadata {
22 public:
23 ImageMetadata()
24 : mLoopCount(-1),
25 mFirstFrameTimeout(FrameTimeout::Forever()),
26 mHasAnimation(false) {}
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 width, int32_t height, Orientation orientation) {
57 if (!HasSize()) {
58 mSize.emplace(nsIntSize(width, height));
59 mOrientation.emplace(orientation);
62 nsIntSize GetSize() const { return *mSize; }
63 bool HasSize() const { return mSize.isSome(); }
65 void AddNativeSize(const nsIntSize& aSize) {
66 mNativeSizes.AppendElement(aSize);
69 const nsTArray<nsIntSize>& GetNativeSizes() const { return mNativeSizes; }
71 Orientation GetOrientation() const { return *mOrientation; }
72 bool HasOrientation() const { return mOrientation.isSome(); }
74 void SetHasAnimation() { mHasAnimation = true; }
75 bool HasAnimation() const { return mHasAnimation; }
77 private:
78 /// The hotspot found on cursors, if present.
79 Maybe<gfx::IntPoint> mHotspot;
81 /// The loop count for animated images, or -1 for infinite loop.
82 int32_t mLoopCount;
84 // The total length of a single loop through an animated image.
85 Maybe<FrameTimeout> mLoopLength;
87 /// The timeout of an animated image's first frame.
88 FrameTimeout mFirstFrameTimeout;
90 // The area of the image that needs to be invalidated when the animation
91 // loops.
92 Maybe<gfx::IntRect> mFirstFrameRefreshArea;
94 Maybe<nsIntSize> mSize;
95 Maybe<Orientation> mOrientation;
97 // Sizes the image can natively decode to.
98 CopyableTArray<nsIntSize> mNativeSizes;
100 bool mHasAnimation : 1;
103 } // namespace image
104 } // namespace mozilla
106 #endif // mozilla_image_ImageMetadata_h