1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "FrozenImage.h"
11 using layers::ImageContainer
;
12 using layers::LayerManager
;
16 void FrozenImage::IncrementAnimationConsumers() {
17 // Do nothing. This will prevent animation from starting if there are no other
18 // instances of this image.
21 void FrozenImage::DecrementAnimationConsumers() {
26 FrozenImage::GetAnimated(bool* aAnimated
) {
28 nsresult rv
= InnerImage()->GetAnimated(&dummy
);
29 if (NS_SUCCEEDED(rv
)) {
35 NS_IMETHODIMP_(already_AddRefed
<SourceSurface
>)
36 FrozenImage::GetFrame(uint32_t aWhichFrame
, uint32_t aFlags
) {
37 return InnerImage()->GetFrame(FRAME_FIRST
, aFlags
);
40 NS_IMETHODIMP_(already_AddRefed
<SourceSurface
>)
41 FrozenImage::GetFrameAtSize(const IntSize
& aSize
, uint32_t aWhichFrame
,
43 return InnerImage()->GetFrameAtSize(aSize
, FRAME_FIRST
, aFlags
);
46 bool FrozenImage::IsNonAnimated() const {
47 // We usually don't create frozen images for non-animated images, but it might
48 // happen if we don't have enough data at the time of the creation to
49 // determine whether the image is actually animated.
50 bool animated
= false;
51 return NS_SUCCEEDED(InnerImage()->GetAnimated(&animated
)) && !animated
;
55 FrozenImage::IsImageContainerAvailable(LayerManager
* aManager
,
57 if (IsNonAnimated()) {
58 return InnerImage()->IsImageContainerAvailable(aManager
, aFlags
);
63 NS_IMETHODIMP_(already_AddRefed
<ImageContainer
>)
64 FrozenImage::GetImageContainer(layers::LayerManager
* aManager
,
66 if (IsNonAnimated()) {
67 return InnerImage()->GetImageContainer(aManager
, aFlags
);
69 // XXX(seth): GetImageContainer does not currently support anything but the
70 // current frame. We work around this by always returning null, but if it ever
71 // turns out that FrozenImage is widely used on codepaths that can actually
72 // benefit from GetImageContainer, it would be a good idea to fix that method
73 // for performance reasons.
78 FrozenImage::IsImageContainerAvailableAtSize(LayerManager
* aManager
,
81 if (IsNonAnimated()) {
82 return InnerImage()->IsImageContainerAvailableAtSize(aManager
, aSize
,
88 NS_IMETHODIMP_(ImgDrawResult
)
89 FrozenImage::GetImageContainerAtSize(layers::LayerManager
* aManager
,
90 const gfx::IntSize
& aSize
,
91 const Maybe
<SVGImageContext
>& aSVGContext
,
93 layers::ImageContainer
** aOutContainer
) {
94 if (IsNonAnimated()) {
95 return InnerImage()->GetImageContainerAtSize(aManager
, aSize
, aSVGContext
,
96 aFlags
, aOutContainer
);
99 // XXX(seth): GetImageContainer does not currently support anything but the
100 // current frame. We work around this by always returning null, but if it ever
101 // turns out that FrozenImage is widely used on codepaths that can actually
102 // benefit from GetImageContainer, it would be a good idea to fix that method
103 // for performance reasons.
104 return ImgDrawResult::NOT_SUPPORTED
;
107 NS_IMETHODIMP_(ImgDrawResult
)
108 FrozenImage::Draw(gfxContext
* aContext
, const nsIntSize
& aSize
,
109 const ImageRegion
& aRegion
,
110 uint32_t /* aWhichFrame - ignored */,
111 SamplingFilter aSamplingFilter
,
112 const Maybe
<SVGImageContext
>& aSVGContext
, uint32_t aFlags
,
114 return InnerImage()->Draw(aContext
, aSize
, aRegion
, FRAME_FIRST
,
115 aSamplingFilter
, aSVGContext
, aFlags
, aOpacity
);
119 FrozenImage::StartDecoding(uint32_t aFlags
, uint32_t aWhichFrame
) {
120 return InnerImage()->StartDecoding(aFlags
, FRAME_FIRST
);
123 bool FrozenImage::StartDecodingWithResult(uint32_t aFlags
,
124 uint32_t aWhichFrame
) {
125 return InnerImage()->StartDecodingWithResult(aFlags
, FRAME_FIRST
);
128 imgIContainer::DecodeResult
FrozenImage::RequestDecodeWithResult(
129 uint32_t aFlags
, uint32_t aWhichFrame
) {
130 return InnerImage()->RequestDecodeWithResult(aFlags
, FRAME_FIRST
);
134 FrozenImage::RequestDecodeForSize(const nsIntSize
& aSize
, uint32_t aFlags
,
135 uint32_t aWhichFrame
) {
136 return InnerImage()->RequestDecodeForSize(aSize
, aFlags
, FRAME_FIRST
);
140 FrozenImage::RequestRefresh(const TimeStamp
& aTime
) {
145 FrozenImage::GetAnimationMode(uint16_t* aAnimationMode
) {
146 *aAnimationMode
= kNormalAnimMode
;
151 FrozenImage::SetAnimationMode(uint16_t aAnimationMode
) {
157 FrozenImage::ResetAnimation() {
162 NS_IMETHODIMP_(float)
163 FrozenImage::GetFrameIndex(uint32_t aWhichFrame
) {
164 MOZ_ASSERT(aWhichFrame
<= FRAME_MAX_VALUE
, "Invalid argument");
169 } // namespace mozilla