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
;
15 void FrozenImage::IncrementAnimationConsumers() {
16 // Do nothing. This will prevent animation from starting if there are no other
17 // instances of this image.
20 void FrozenImage::DecrementAnimationConsumers() {
25 FrozenImage::GetAnimated(bool* aAnimated
) {
27 nsresult rv
= InnerImage()->GetAnimated(&dummy
);
28 if (NS_SUCCEEDED(rv
)) {
34 NS_IMETHODIMP_(already_AddRefed
<SourceSurface
>)
35 FrozenImage::GetFrame(uint32_t aWhichFrame
, uint32_t aFlags
) {
36 return InnerImage()->GetFrame(FRAME_FIRST
, aFlags
);
39 NS_IMETHODIMP_(already_AddRefed
<SourceSurface
>)
40 FrozenImage::GetFrameAtSize(const IntSize
& aSize
, uint32_t aWhichFrame
,
42 return InnerImage()->GetFrameAtSize(aSize
, FRAME_FIRST
, aFlags
);
45 bool FrozenImage::IsNonAnimated() const {
46 // We usually don't create frozen images for non-animated images, but it might
47 // happen if we don't have enough data at the time of the creation to
48 // determine whether the image is actually animated.
49 bool animated
= false;
50 return NS_SUCCEEDED(InnerImage()->GetAnimated(&animated
)) && !animated
;
54 FrozenImage::IsImageContainerAvailable(WindowRenderer
* aRenderer
,
56 if (IsNonAnimated()) {
57 return InnerImage()->IsImageContainerAvailable(aRenderer
, aFlags
);
62 NS_IMETHODIMP_(ImgDrawResult
)
63 FrozenImage::GetImageProvider(WindowRenderer
* aRenderer
,
64 const gfx::IntSize
& aSize
,
65 const SVGImageContext
& aSVGContext
,
66 const Maybe
<ImageIntRegion
>& aRegion
,
68 WebRenderImageProvider
** aProvider
) {
69 if (IsNonAnimated()) {
70 return InnerImage()->GetImageProvider(aRenderer
, aSize
, aSVGContext
,
71 aRegion
, aFlags
, aProvider
);
74 // XXX(seth): GetImageContainer does not currently support anything but the
75 // current frame. We work around this by always returning null, but if it ever
76 // turns out that FrozenImage is widely used on codepaths that can actually
77 // benefit from GetImageContainer, it would be a good idea to fix that method
78 // for performance reasons.
79 return ImgDrawResult::NOT_SUPPORTED
;
82 NS_IMETHODIMP_(ImgDrawResult
)
83 FrozenImage::Draw(gfxContext
* aContext
, const nsIntSize
& aSize
,
84 const ImageRegion
& aRegion
,
85 uint32_t /* aWhichFrame - ignored */,
86 SamplingFilter aSamplingFilter
,
87 const SVGImageContext
& aSVGContext
, uint32_t aFlags
,
89 return InnerImage()->Draw(aContext
, aSize
, aRegion
, FRAME_FIRST
,
90 aSamplingFilter
, aSVGContext
, aFlags
, aOpacity
);
94 FrozenImage::StartDecoding(uint32_t aFlags
, uint32_t aWhichFrame
) {
95 return InnerImage()->StartDecoding(aFlags
, FRAME_FIRST
);
98 bool FrozenImage::StartDecodingWithResult(uint32_t aFlags
,
99 uint32_t aWhichFrame
) {
100 return InnerImage()->StartDecodingWithResult(aFlags
, FRAME_FIRST
);
103 bool FrozenImage::HasDecodedPixels() {
104 return InnerImage()->HasDecodedPixels();
107 imgIContainer::DecodeResult
FrozenImage::RequestDecodeWithResult(
108 uint32_t aFlags
, uint32_t aWhichFrame
) {
109 return InnerImage()->RequestDecodeWithResult(aFlags
, FRAME_FIRST
);
113 FrozenImage::RequestDecodeForSize(const nsIntSize
& aSize
, uint32_t aFlags
,
114 uint32_t aWhichFrame
) {
115 return InnerImage()->RequestDecodeForSize(aSize
, aFlags
, FRAME_FIRST
);
119 FrozenImage::RequestRefresh(const TimeStamp
& aTime
) {
124 FrozenImage::GetAnimationMode(uint16_t* aAnimationMode
) {
125 *aAnimationMode
= kNormalAnimMode
;
130 FrozenImage::SetAnimationMode(uint16_t aAnimationMode
) {
136 FrozenImage::ResetAnimation() {
141 NS_IMETHODIMP_(float)
142 FrozenImage::GetFrameIndex(uint32_t aWhichFrame
) {
143 MOZ_ASSERT(aWhichFrame
<= FRAME_MAX_VALUE
, "Invalid argument");
148 } // namespace mozilla