Bug 1645920 [wpt PR 24157] - [AspectRatio] Make intrinsic sizes respect aspect-ratio...
[gecko.git] / image / ImageWrapper.cpp
blob220978c683245521546a19a071c71fd16824cbf0
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 "ImageWrapper.h"
7 #include "mozilla/gfx/2D.h"
8 #include "mozilla/RefPtr.h"
9 #include "Orientation.h"
11 #include "mozilla/MemoryReporting.h"
13 namespace mozilla {
15 using dom::Document;
16 using gfx::DataSourceSurface;
17 using gfx::IntSize;
18 using gfx::SamplingFilter;
19 using gfx::SourceSurface;
20 using layers::ImageContainer;
21 using layers::LayerManager;
23 namespace image {
25 // Inherited methods from Image.
27 already_AddRefed<ProgressTracker> ImageWrapper::GetProgressTracker() {
28 return mInnerImage->GetProgressTracker();
31 size_t ImageWrapper::SizeOfSourceWithComputedFallback(
32 SizeOfState& aState) const {
33 return mInnerImage->SizeOfSourceWithComputedFallback(aState);
36 void ImageWrapper::CollectSizeOfSurfaces(
37 nsTArray<SurfaceMemoryCounter>& aCounters,
38 MallocSizeOf aMallocSizeOf) const {
39 mInnerImage->CollectSizeOfSurfaces(aCounters, aMallocSizeOf);
42 void ImageWrapper::IncrementAnimationConsumers() {
43 MOZ_ASSERT(NS_IsMainThread(),
44 "Main thread only to encourage serialization "
45 "with DecrementAnimationConsumers");
46 mInnerImage->IncrementAnimationConsumers();
49 void ImageWrapper::DecrementAnimationConsumers() {
50 MOZ_ASSERT(NS_IsMainThread(),
51 "Main thread only to encourage serialization "
52 "with IncrementAnimationConsumers");
53 mInnerImage->DecrementAnimationConsumers();
56 #ifdef DEBUG
57 uint32_t ImageWrapper::GetAnimationConsumers() {
58 return mInnerImage->GetAnimationConsumers();
60 #endif
62 nsresult ImageWrapper::OnImageDataAvailable(nsIRequest* aRequest,
63 nsISupports* aContext,
64 nsIInputStream* aInStr,
65 uint64_t aSourceOffset,
66 uint32_t aCount) {
67 return mInnerImage->OnImageDataAvailable(aRequest, aContext, aInStr,
68 aSourceOffset, aCount);
71 nsresult ImageWrapper::OnImageDataComplete(nsIRequest* aRequest,
72 nsISupports* aContext,
73 nsresult aStatus, bool aLastPart) {
74 return mInnerImage->OnImageDataComplete(aRequest, aContext, aStatus,
75 aLastPart);
78 void ImageWrapper::OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) {
79 return mInnerImage->OnSurfaceDiscarded(aSurfaceKey);
82 void ImageWrapper::SetInnerWindowID(uint64_t aInnerWindowId) {
83 mInnerImage->SetInnerWindowID(aInnerWindowId);
86 uint64_t ImageWrapper::InnerWindowID() const {
87 return mInnerImage->InnerWindowID();
90 bool ImageWrapper::HasError() { return mInnerImage->HasError(); }
92 void ImageWrapper::SetHasError() { mInnerImage->SetHasError(); }
94 nsIURI* ImageWrapper::GetURI() const { return mInnerImage->GetURI(); }
96 // Methods inherited from XPCOM interfaces.
98 NS_IMPL_ISUPPORTS(ImageWrapper, imgIContainer)
100 NS_IMETHODIMP
101 ImageWrapper::GetWidth(int32_t* aWidth) {
102 return mInnerImage->GetWidth(aWidth);
105 NS_IMETHODIMP
106 ImageWrapper::GetHeight(int32_t* aHeight) {
107 return mInnerImage->GetHeight(aHeight);
110 nsresult ImageWrapper::GetNativeSizes(nsTArray<IntSize>& aNativeSizes) const {
111 return mInnerImage->GetNativeSizes(aNativeSizes);
114 size_t ImageWrapper::GetNativeSizesLength() const {
115 return mInnerImage->GetNativeSizesLength();
118 NS_IMETHODIMP
119 ImageWrapper::GetIntrinsicSize(nsSize* aSize) {
120 return mInnerImage->GetIntrinsicSize(aSize);
123 Maybe<AspectRatio> ImageWrapper::GetIntrinsicRatio() {
124 return mInnerImage->GetIntrinsicRatio();
127 nsresult ImageWrapper::GetHotspotX(int32_t* aX) {
128 return Image::GetHotspotX(aX);
131 nsresult ImageWrapper::GetHotspotY(int32_t* aY) {
132 return Image::GetHotspotY(aY);
135 NS_IMETHODIMP_(Orientation)
136 ImageWrapper::GetOrientation() { return mInnerImage->GetOrientation(); }
138 NS_IMETHODIMP_(bool)
139 ImageWrapper::HandledOrientation() { return mInnerImage->HandledOrientation(); }
141 NS_IMETHODIMP
142 ImageWrapper::GetType(uint16_t* aType) { return mInnerImage->GetType(aType); }
144 NS_IMETHODIMP
145 ImageWrapper::GetProducerId(uint32_t* aId) {
146 return mInnerImage->GetProducerId(aId);
149 NS_IMETHODIMP
150 ImageWrapper::GetAnimated(bool* aAnimated) {
151 return mInnerImage->GetAnimated(aAnimated);
154 NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
155 ImageWrapper::GetFrame(uint32_t aWhichFrame, uint32_t aFlags) {
156 return mInnerImage->GetFrame(aWhichFrame, aFlags);
159 NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
160 ImageWrapper::GetFrameAtSize(const IntSize& aSize, uint32_t aWhichFrame,
161 uint32_t aFlags) {
162 return mInnerImage->GetFrameAtSize(aSize, aWhichFrame, aFlags);
165 NS_IMETHODIMP_(bool)
166 ImageWrapper::WillDrawOpaqueNow() { return mInnerImage->WillDrawOpaqueNow(); }
168 NS_IMETHODIMP_(bool)
169 ImageWrapper::IsImageContainerAvailable(LayerManager* aManager,
170 uint32_t aFlags) {
171 return mInnerImage->IsImageContainerAvailable(aManager, aFlags);
174 NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
175 ImageWrapper::GetImageContainer(LayerManager* aManager, uint32_t aFlags) {
176 return mInnerImage->GetImageContainer(aManager, aFlags);
179 NS_IMETHODIMP_(bool)
180 ImageWrapper::IsImageContainerAvailableAtSize(LayerManager* aManager,
181 const IntSize& aSize,
182 uint32_t aFlags) {
183 return mInnerImage->IsImageContainerAvailableAtSize(aManager, aSize, aFlags);
186 NS_IMETHODIMP_(ImgDrawResult)
187 ImageWrapper::GetImageContainerAtSize(layers::LayerManager* aManager,
188 const gfx::IntSize& aSize,
189 const Maybe<SVGImageContext>& aSVGContext,
190 uint32_t aFlags,
191 layers::ImageContainer** aOutContainer) {
192 return mInnerImage->GetImageContainerAtSize(aManager, aSize, aSVGContext,
193 aFlags, aOutContainer);
196 NS_IMETHODIMP_(ImgDrawResult)
197 ImageWrapper::Draw(gfxContext* aContext, const nsIntSize& aSize,
198 const ImageRegion& aRegion, uint32_t aWhichFrame,
199 SamplingFilter aSamplingFilter,
200 const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
201 float aOpacity) {
202 return mInnerImage->Draw(aContext, aSize, aRegion, aWhichFrame,
203 aSamplingFilter, aSVGContext, aFlags, aOpacity);
206 NS_IMETHODIMP
207 ImageWrapper::StartDecoding(uint32_t aFlags, uint32_t aWhichFrame) {
208 return mInnerImage->StartDecoding(aFlags, aWhichFrame);
211 bool ImageWrapper::StartDecodingWithResult(uint32_t aFlags,
212 uint32_t aWhichFrame) {
213 return mInnerImage->StartDecodingWithResult(aFlags, aWhichFrame);
216 imgIContainer::DecodeResult ImageWrapper::RequestDecodeWithResult(
217 uint32_t aFlags, uint32_t aWhichFrame) {
218 return mInnerImage->RequestDecodeWithResult(aFlags, aWhichFrame);
221 NS_IMETHODIMP
222 ImageWrapper::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags,
223 uint32_t aWhichFrame) {
224 return mInnerImage->RequestDecodeForSize(aSize, aFlags, aWhichFrame);
227 NS_IMETHODIMP
228 ImageWrapper::LockImage() {
229 MOZ_ASSERT(NS_IsMainThread(),
230 "Main thread to encourage serialization with UnlockImage");
231 return mInnerImage->LockImage();
234 NS_IMETHODIMP
235 ImageWrapper::UnlockImage() {
236 MOZ_ASSERT(NS_IsMainThread(),
237 "Main thread to encourage serialization with LockImage");
238 return mInnerImage->UnlockImage();
241 NS_IMETHODIMP
242 ImageWrapper::RequestDiscard() { return mInnerImage->RequestDiscard(); }
244 NS_IMETHODIMP_(void)
245 ImageWrapper::RequestRefresh(const TimeStamp& aTime) {
246 return mInnerImage->RequestRefresh(aTime);
249 NS_IMETHODIMP
250 ImageWrapper::GetAnimationMode(uint16_t* aAnimationMode) {
251 return mInnerImage->GetAnimationMode(aAnimationMode);
254 NS_IMETHODIMP
255 ImageWrapper::SetAnimationMode(uint16_t aAnimationMode) {
256 return mInnerImage->SetAnimationMode(aAnimationMode);
259 NS_IMETHODIMP
260 ImageWrapper::ResetAnimation() { return mInnerImage->ResetAnimation(); }
262 NS_IMETHODIMP_(float)
263 ImageWrapper::GetFrameIndex(uint32_t aWhichFrame) {
264 return mInnerImage->GetFrameIndex(aWhichFrame);
267 NS_IMETHODIMP_(int32_t)
268 ImageWrapper::GetFirstFrameDelay() { return mInnerImage->GetFirstFrameDelay(); }
270 NS_IMETHODIMP_(void)
271 ImageWrapper::SetAnimationStartTime(const TimeStamp& aTime) {
272 mInnerImage->SetAnimationStartTime(aTime);
275 void ImageWrapper::PropagateUseCounters(Document* aParentDocument) {
276 mInnerImage->PropagateUseCounters(aParentDocument);
279 nsIntSize ImageWrapper::OptimalImageSizeForDest(const gfxSize& aDest,
280 uint32_t aWhichFrame,
281 SamplingFilter aSamplingFilter,
282 uint32_t aFlags) {
283 return mInnerImage->OptimalImageSizeForDest(aDest, aWhichFrame,
284 aSamplingFilter, aFlags);
287 NS_IMETHODIMP_(nsIntRect)
288 ImageWrapper::GetImageSpaceInvalidationRect(const nsIntRect& aRect) {
289 return mInnerImage->GetImageSpaceInvalidationRect(aRect);
292 already_AddRefed<imgIContainer> ImageWrapper::Unwrap() {
293 return mInnerImage->Unwrap();
296 } // namespace image
297 } // namespace mozilla