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"
10 #include "mozilla/image/Resolution.h"
12 #include "mozilla/MemoryReporting.h"
18 using gfx::SamplingFilter
;
19 using gfx::SourceSurface
;
20 using layers::ImageContainer
;
24 // Inherited methods from Image.
26 already_AddRefed
<ProgressTracker
> ImageWrapper::GetProgressTracker() {
27 return mInnerImage
->GetProgressTracker();
30 size_t ImageWrapper::SizeOfSourceWithComputedFallback(
31 SizeOfState
& aState
) const {
32 return mInnerImage
->SizeOfSourceWithComputedFallback(aState
);
35 void ImageWrapper::CollectSizeOfSurfaces(
36 nsTArray
<SurfaceMemoryCounter
>& aCounters
,
37 MallocSizeOf aMallocSizeOf
) const {
38 mInnerImage
->CollectSizeOfSurfaces(aCounters
, aMallocSizeOf
);
41 void ImageWrapper::IncrementAnimationConsumers() {
42 MOZ_ASSERT(NS_IsMainThread(),
43 "Main thread only to encourage serialization "
44 "with DecrementAnimationConsumers");
45 mInnerImage
->IncrementAnimationConsumers();
48 void ImageWrapper::DecrementAnimationConsumers() {
49 MOZ_ASSERT(NS_IsMainThread(),
50 "Main thread only to encourage serialization "
51 "with IncrementAnimationConsumers");
52 mInnerImage
->DecrementAnimationConsumers();
56 uint32_t ImageWrapper::GetAnimationConsumers() {
57 return mInnerImage
->GetAnimationConsumers();
61 nsresult
ImageWrapper::OnImageDataAvailable(nsIRequest
* aRequest
,
62 nsIInputStream
* aInStr
,
63 uint64_t aSourceOffset
,
65 return mInnerImage
->OnImageDataAvailable(aRequest
, aInStr
, aSourceOffset
,
69 nsresult
ImageWrapper::OnImageDataComplete(nsIRequest
* aRequest
,
70 nsresult aStatus
, bool aLastPart
) {
71 return mInnerImage
->OnImageDataComplete(aRequest
, aStatus
, aLastPart
);
74 void ImageWrapper::OnSurfaceDiscarded(const SurfaceKey
& aSurfaceKey
) {
75 return mInnerImage
->OnSurfaceDiscarded(aSurfaceKey
);
78 void ImageWrapper::SetInnerWindowID(uint64_t aInnerWindowId
) {
79 mInnerImage
->SetInnerWindowID(aInnerWindowId
);
82 uint64_t ImageWrapper::InnerWindowID() const {
83 return mInnerImage
->InnerWindowID();
86 bool ImageWrapper::HasError() { return mInnerImage
->HasError(); }
88 void ImageWrapper::SetHasError() { mInnerImage
->SetHasError(); }
90 nsIURI
* ImageWrapper::GetURI() const { return mInnerImage
->GetURI(); }
92 // Methods inherited from XPCOM interfaces.
94 NS_IMPL_ISUPPORTS(ImageWrapper
, imgIContainer
)
97 ImageWrapper::GetWidth(int32_t* aWidth
) {
98 return mInnerImage
->GetWidth(aWidth
);
102 ImageWrapper::GetHeight(int32_t* aHeight
) {
103 return mInnerImage
->GetHeight(aHeight
);
106 void ImageWrapper::MediaFeatureValuesChangedAllDocuments(
107 const mozilla::MediaFeatureChange
& aChange
) {}
109 nsresult
ImageWrapper::GetNativeSizes(nsTArray
<IntSize
>& aNativeSizes
) {
110 return mInnerImage
->GetNativeSizes(aNativeSizes
);
113 size_t ImageWrapper::GetNativeSizesLength() {
114 return mInnerImage
->GetNativeSizesLength();
118 ImageWrapper::GetIntrinsicSize(nsSize
* aSize
) {
119 return mInnerImage
->GetIntrinsicSize(aSize
);
122 Maybe
<AspectRatio
> ImageWrapper::GetIntrinsicRatio() {
123 return mInnerImage
->GetIntrinsicRatio();
126 nsresult
ImageWrapper::GetHotspotX(int32_t* aX
) {
127 return Image::GetHotspotX(aX
);
130 nsresult
ImageWrapper::GetHotspotY(int32_t* aY
) {
131 return Image::GetHotspotY(aY
);
134 NS_IMETHODIMP_(Orientation
)
135 ImageWrapper::GetOrientation() { return mInnerImage
->GetOrientation(); }
137 NS_IMETHODIMP_(Resolution
)
138 ImageWrapper::GetResolution() { return mInnerImage
->GetResolution(); }
141 ImageWrapper::GetType(uint16_t* aType
) { return mInnerImage
->GetType(aType
); }
144 ImageWrapper::GetProviderId(uint32_t* aId
) {
145 return mInnerImage
->GetProviderId(aId
);
149 ImageWrapper::GetAnimated(bool* aAnimated
) {
150 return mInnerImage
->GetAnimated(aAnimated
);
153 NS_IMETHODIMP_(already_AddRefed
<SourceSurface
>)
154 ImageWrapper::GetFrame(uint32_t aWhichFrame
, uint32_t aFlags
) {
155 return mInnerImage
->GetFrame(aWhichFrame
, aFlags
);
158 NS_IMETHODIMP_(already_AddRefed
<SourceSurface
>)
159 ImageWrapper::GetFrameAtSize(const IntSize
& aSize
, uint32_t aWhichFrame
,
161 return mInnerImage
->GetFrameAtSize(aSize
, aWhichFrame
, aFlags
);
165 ImageWrapper::WillDrawOpaqueNow() { return mInnerImage
->WillDrawOpaqueNow(); }
168 ImageWrapper::IsImageContainerAvailable(WindowRenderer
* aRenderer
,
170 return mInnerImage
->IsImageContainerAvailable(aRenderer
, aFlags
);
173 NS_IMETHODIMP_(ImgDrawResult
)
174 ImageWrapper::GetImageProvider(WindowRenderer
* aRenderer
,
175 const gfx::IntSize
& aSize
,
176 const SVGImageContext
& aSVGContext
,
177 const Maybe
<ImageIntRegion
>& aRegion
,
179 WebRenderImageProvider
** aProvider
) {
180 return mInnerImage
->GetImageProvider(aRenderer
, aSize
, aSVGContext
, aRegion
,
184 NS_IMETHODIMP_(ImgDrawResult
)
185 ImageWrapper::Draw(gfxContext
* aContext
, const nsIntSize
& aSize
,
186 const ImageRegion
& aRegion
, uint32_t aWhichFrame
,
187 SamplingFilter aSamplingFilter
,
188 const SVGImageContext
& aSVGContext
, uint32_t aFlags
,
190 return mInnerImage
->Draw(aContext
, aSize
, aRegion
, aWhichFrame
,
191 aSamplingFilter
, aSVGContext
, aFlags
, aOpacity
);
195 ImageWrapper::StartDecoding(uint32_t aFlags
, uint32_t aWhichFrame
) {
196 return mInnerImage
->StartDecoding(aFlags
, aWhichFrame
);
199 bool ImageWrapper::StartDecodingWithResult(uint32_t aFlags
,
200 uint32_t aWhichFrame
) {
201 return mInnerImage
->StartDecodingWithResult(aFlags
, aWhichFrame
);
204 bool ImageWrapper::HasDecodedPixels() {
205 return InnerImage()->HasDecodedPixels();
208 imgIContainer::DecodeResult
ImageWrapper::RequestDecodeWithResult(
209 uint32_t aFlags
, uint32_t aWhichFrame
) {
210 return mInnerImage
->RequestDecodeWithResult(aFlags
, aWhichFrame
);
214 ImageWrapper::RequestDecodeForSize(const nsIntSize
& aSize
, uint32_t aFlags
,
215 uint32_t aWhichFrame
) {
216 return mInnerImage
->RequestDecodeForSize(aSize
, aFlags
, aWhichFrame
);
220 ImageWrapper::LockImage() {
221 MOZ_ASSERT(NS_IsMainThread(),
222 "Main thread to encourage serialization with UnlockImage");
223 return mInnerImage
->LockImage();
227 ImageWrapper::UnlockImage() {
228 MOZ_ASSERT(NS_IsMainThread(),
229 "Main thread to encourage serialization with LockImage");
230 return mInnerImage
->UnlockImage();
234 ImageWrapper::RequestDiscard() { return mInnerImage
->RequestDiscard(); }
237 ImageWrapper::RequestRefresh(const TimeStamp
& aTime
) {
238 return mInnerImage
->RequestRefresh(aTime
);
242 ImageWrapper::GetAnimationMode(uint16_t* aAnimationMode
) {
243 return mInnerImage
->GetAnimationMode(aAnimationMode
);
247 ImageWrapper::SetAnimationMode(uint16_t aAnimationMode
) {
248 return mInnerImage
->SetAnimationMode(aAnimationMode
);
252 ImageWrapper::ResetAnimation() { return mInnerImage
->ResetAnimation(); }
254 NS_IMETHODIMP_(float)
255 ImageWrapper::GetFrameIndex(uint32_t aWhichFrame
) {
256 return mInnerImage
->GetFrameIndex(aWhichFrame
);
259 NS_IMETHODIMP_(int32_t)
260 ImageWrapper::GetFirstFrameDelay() { return mInnerImage
->GetFirstFrameDelay(); }
263 ImageWrapper::SetAnimationStartTime(const TimeStamp
& aTime
) {
264 mInnerImage
->SetAnimationStartTime(aTime
);
267 void ImageWrapper::PropagateUseCounters(Document
* aReferencingDocument
) {
268 mInnerImage
->PropagateUseCounters(aReferencingDocument
);
271 nsIntSize
ImageWrapper::OptimalImageSizeForDest(const gfxSize
& aDest
,
272 uint32_t aWhichFrame
,
273 SamplingFilter aSamplingFilter
,
275 return mInnerImage
->OptimalImageSizeForDest(aDest
, aWhichFrame
,
276 aSamplingFilter
, aFlags
);
279 NS_IMETHODIMP_(nsIntRect
)
280 ImageWrapper::GetImageSpaceInvalidationRect(const nsIntRect
& aRect
) {
281 return mInnerImage
->GetImageSpaceInvalidationRect(aRect
);
284 already_AddRefed
<imgIContainer
> ImageWrapper::Unwrap() {
285 return mInnerImage
->Unwrap();
289 } // namespace mozilla