Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/image/ImageMetadata.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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/. */
6
7
#ifndef mozilla_image_ImageMetadata_h
8
#define mozilla_image_ImageMetadata_h
9
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"
16
17
namespace mozilla {
18
namespace image {
19
20
// The metadata about an image that decoders accumulate as they decode.
21
class ImageMetadata
22
{
23
public:
24
  ImageMetadata()
25
    : mLoopCount(-1)
26
    , mFirstFrameTimeout(FrameTimeout::Forever())
27
    , mHasAnimation(false)
28
0
  { }
29
30
  void SetHotspot(uint16_t aHotspotX, uint16_t aHotspotY)
31
0
  {
32
0
    mHotspot = Some(gfx::IntPoint(aHotspotX, aHotspotY));
33
0
  }
34
0
  gfx::IntPoint GetHotspot() const { return *mHotspot; }
35
0
  bool HasHotspot() const { return mHotspot.isSome(); }
36
37
  void SetLoopCount(int32_t loopcount)
38
0
  {
39
0
    mLoopCount = loopcount;
40
0
  }
41
0
  int32_t GetLoopCount() const { return mLoopCount; }
42
43
0
  void SetLoopLength(FrameTimeout aLength) { mLoopLength = Some(aLength); }
44
0
  FrameTimeout GetLoopLength() const { return *mLoopLength; }
45
0
  bool HasLoopLength() const { return mLoopLength.isSome(); }
46
47
0
  void SetFirstFrameTimeout(FrameTimeout aTimeout) { mFirstFrameTimeout = aTimeout; }
48
0
  FrameTimeout GetFirstFrameTimeout() const { return mFirstFrameTimeout; }
49
50
  void SetFirstFrameRefreshArea(const gfx::IntRect& aRefreshArea)
51
0
  {
52
0
    mFirstFrameRefreshArea = Some(aRefreshArea);
53
0
  }
54
0
  gfx::IntRect GetFirstFrameRefreshArea() const { return *mFirstFrameRefreshArea; }
55
0
  bool HasFirstFrameRefreshArea() const { return mFirstFrameRefreshArea.isSome(); }
56
57
  void SetSize(int32_t width, int32_t height, Orientation orientation)
58
0
  {
59
0
    if (!HasSize()) {
60
0
      mSize.emplace(nsIntSize(width, height));
61
0
      mOrientation.emplace(orientation);
62
0
    }
63
0
  }
64
0
  nsIntSize GetSize() const { return *mSize; }
65
0
  bool HasSize() const { return mSize.isSome(); }
66
67
  void AddNativeSize(const nsIntSize& aSize)
68
0
  {
69
0
    mNativeSizes.AppendElement(aSize);
70
0
  }
71
72
0
  const nsTArray<nsIntSize>& GetNativeSizes() const { return mNativeSizes; }
73
74
0
  Orientation GetOrientation() const { return *mOrientation; }
75
0
  bool HasOrientation() const { return mOrientation.isSome(); }
76
77
0
  void SetHasAnimation() { mHasAnimation = true; }
78
0
  bool HasAnimation() const { return mHasAnimation; }
79
80
private:
81
  /// The hotspot found on cursors, if present.
82
  Maybe<gfx::IntPoint> mHotspot;
83
84
  /// The loop count for animated images, or -1 for infinite loop.
85
  int32_t mLoopCount;
86
87
  // The total length of a single loop through an animated image.
88
  Maybe<FrameTimeout> mLoopLength;
89
90
  /// The timeout of an animated image's first frame.
91
  FrameTimeout mFirstFrameTimeout;
92
93
  // The area of the image that needs to be invalidated when the animation
94
  // loops.
95
  Maybe<gfx::IntRect> mFirstFrameRefreshArea;
96
97
  Maybe<nsIntSize> mSize;
98
  Maybe<Orientation> mOrientation;
99
100
  // Sizes the image can natively decode to.
101
  nsTArray<nsIntSize> mNativeSizes;
102
103
  bool mHasAnimation : 1;
104
};
105
106
} // namespace image
107
} // namespace mozilla
108
109
#endif // mozilla_image_ImageMetadata_h