Backed out changeset 0f0edda611cf (bug 1874454) for causing bp-nu bustages in CocoaHe...
[gecko.git] / image / FrozenImage.cpp
blobbb82aaedd61cd85371dfab1131b9f62d805bc11d
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"
8 namespace mozilla {
10 using namespace gfx;
11 using layers::ImageContainer;
13 namespace image {
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() {
21 // Do nothing.
24 NS_IMETHODIMP
25 FrozenImage::GetAnimated(bool* aAnimated) {
26 bool dummy;
27 nsresult rv = InnerImage()->GetAnimated(&dummy);
28 if (NS_SUCCEEDED(rv)) {
29 *aAnimated = false;
31 return 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,
41 uint32_t aFlags) {
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;
53 NS_IMETHODIMP_(bool)
54 FrozenImage::IsImageContainerAvailable(WindowRenderer* aRenderer,
55 uint32_t aFlags) {
56 if (IsNonAnimated()) {
57 return InnerImage()->IsImageContainerAvailable(aRenderer, aFlags);
59 return false;
62 NS_IMETHODIMP_(ImgDrawResult)
63 FrozenImage::GetImageProvider(WindowRenderer* aRenderer,
64 const gfx::IntSize& aSize,
65 const SVGImageContext& aSVGContext,
66 const Maybe<ImageIntRegion>& aRegion,
67 uint32_t aFlags,
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,
88 float aOpacity) {
89 return InnerImage()->Draw(aContext, aSize, aRegion, FRAME_FIRST,
90 aSamplingFilter, aSVGContext, aFlags, aOpacity);
93 NS_IMETHODIMP
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);
112 NS_IMETHODIMP
113 FrozenImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags,
114 uint32_t aWhichFrame) {
115 return InnerImage()->RequestDecodeForSize(aSize, aFlags, FRAME_FIRST);
118 NS_IMETHODIMP_(void)
119 FrozenImage::RequestRefresh(const TimeStamp& aTime) {
120 // Do nothing.
123 NS_IMETHODIMP
124 FrozenImage::GetAnimationMode(uint16_t* aAnimationMode) {
125 *aAnimationMode = kNormalAnimMode;
126 return NS_OK;
129 NS_IMETHODIMP
130 FrozenImage::SetAnimationMode(uint16_t aAnimationMode) {
131 // Do nothing.
132 return NS_OK;
135 NS_IMETHODIMP
136 FrozenImage::ResetAnimation() {
137 // Do nothing.
138 return NS_OK;
141 NS_IMETHODIMP_(float)
142 FrozenImage::GetFrameIndex(uint32_t aWhichFrame) {
143 MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
144 return 0;
147 } // namespace image
148 } // namespace mozilla