Bug 1704628 Part 1: Make selectContextMenuItem use .activateItem() semantics. r=ochameau
[gecko.git] / image / FrozenImage.cpp
blob0db6dd41a150e545f0f20ab6ecea4fa5f98a8665
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;
12 using layers::LayerManager;
14 namespace image {
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() {
22 // Do nothing.
25 NS_IMETHODIMP
26 FrozenImage::GetAnimated(bool* aAnimated) {
27 bool dummy;
28 nsresult rv = InnerImage()->GetAnimated(&dummy);
29 if (NS_SUCCEEDED(rv)) {
30 *aAnimated = false;
32 return 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,
42 uint32_t aFlags) {
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;
54 NS_IMETHODIMP_(bool)
55 FrozenImage::IsImageContainerAvailable(LayerManager* aManager,
56 uint32_t aFlags) {
57 if (IsNonAnimated()) {
58 return InnerImage()->IsImageContainerAvailable(aManager, aFlags);
60 return false;
63 NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
64 FrozenImage::GetImageContainer(layers::LayerManager* aManager,
65 uint32_t aFlags) {
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.
74 return nullptr;
77 NS_IMETHODIMP_(bool)
78 FrozenImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
79 const IntSize& aSize,
80 uint32_t aFlags) {
81 if (IsNonAnimated()) {
82 return InnerImage()->IsImageContainerAvailableAtSize(aManager, aSize,
83 aFlags);
85 return false;
88 NS_IMETHODIMP_(ImgDrawResult)
89 FrozenImage::GetImageContainerAtSize(layers::LayerManager* aManager,
90 const gfx::IntSize& aSize,
91 const Maybe<SVGImageContext>& aSVGContext,
92 uint32_t aFlags,
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,
113 float aOpacity) {
114 return InnerImage()->Draw(aContext, aSize, aRegion, FRAME_FIRST,
115 aSamplingFilter, aSVGContext, aFlags, aOpacity);
118 NS_IMETHODIMP
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);
133 NS_IMETHODIMP
134 FrozenImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags,
135 uint32_t aWhichFrame) {
136 return InnerImage()->RequestDecodeForSize(aSize, aFlags, FRAME_FIRST);
139 NS_IMETHODIMP_(void)
140 FrozenImage::RequestRefresh(const TimeStamp& aTime) {
141 // Do nothing.
144 NS_IMETHODIMP
145 FrozenImage::GetAnimationMode(uint16_t* aAnimationMode) {
146 *aAnimationMode = kNormalAnimMode;
147 return NS_OK;
150 NS_IMETHODIMP
151 FrozenImage::SetAnimationMode(uint16_t aAnimationMode) {
152 // Do nothing.
153 return NS_OK;
156 NS_IMETHODIMP
157 FrozenImage::ResetAnimation() {
158 // Do nothing.
159 return NS_OK;
162 NS_IMETHODIMP_(float)
163 FrozenImage::GetFrameIndex(uint32_t aWhichFrame) {
164 MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
165 return 0;
168 } // namespace image
169 } // namespace mozilla