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"
16 using gfx::DataSourceSurface
;
18 using gfx::SamplingFilter
;
19 using gfx::SourceSurface
;
20 using layers::ImageContainer
;
21 using layers::LayerManager
;
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();
57 uint32_t ImageWrapper::GetAnimationConsumers() {
58 return mInnerImage
->GetAnimationConsumers();
62 nsresult
ImageWrapper::OnImageDataAvailable(nsIRequest
* aRequest
,
63 nsISupports
* aContext
,
64 nsIInputStream
* aInStr
,
65 uint64_t aSourceOffset
,
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
,
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
)
101 ImageWrapper::GetWidth(int32_t* aWidth
) {
102 return mInnerImage
->GetWidth(aWidth
);
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();
119 ImageWrapper::GetIntrinsicSize(nsSize
* aSize
) {
120 return mInnerImage
->GetIntrinsicSize(aSize
);
123 Maybe
<AspectRatio
> ImageWrapper::GetIntrinsicRatio() {
124 return mInnerImage
->GetIntrinsicRatio();
127 NS_IMETHODIMP_(Orientation
)
128 ImageWrapper::GetOrientation() { return mInnerImage
->GetOrientation(); }
131 ImageWrapper::GetType(uint16_t* aType
) { return mInnerImage
->GetType(aType
); }
134 ImageWrapper::GetProducerId(uint32_t* aId
) {
135 return mInnerImage
->GetProducerId(aId
);
139 ImageWrapper::GetAnimated(bool* aAnimated
) {
140 return mInnerImage
->GetAnimated(aAnimated
);
143 NS_IMETHODIMP_(already_AddRefed
<SourceSurface
>)
144 ImageWrapper::GetFrame(uint32_t aWhichFrame
, uint32_t aFlags
) {
145 return mInnerImage
->GetFrame(aWhichFrame
, aFlags
);
148 NS_IMETHODIMP_(already_AddRefed
<SourceSurface
>)
149 ImageWrapper::GetFrameAtSize(const IntSize
& aSize
, uint32_t aWhichFrame
,
151 return mInnerImage
->GetFrameAtSize(aSize
, aWhichFrame
, aFlags
);
155 ImageWrapper::WillDrawOpaqueNow() { return mInnerImage
->WillDrawOpaqueNow(); }
158 ImageWrapper::IsImageContainerAvailable(LayerManager
* aManager
,
160 return mInnerImage
->IsImageContainerAvailable(aManager
, aFlags
);
163 NS_IMETHODIMP_(already_AddRefed
<ImageContainer
>)
164 ImageWrapper::GetImageContainer(LayerManager
* aManager
, uint32_t aFlags
) {
165 return mInnerImage
->GetImageContainer(aManager
, aFlags
);
169 ImageWrapper::IsImageContainerAvailableAtSize(LayerManager
* aManager
,
170 const IntSize
& aSize
,
172 return mInnerImage
->IsImageContainerAvailableAtSize(aManager
, aSize
, aFlags
);
175 NS_IMETHODIMP_(ImgDrawResult
)
176 ImageWrapper::GetImageContainerAtSize(layers::LayerManager
* aManager
,
177 const gfx::IntSize
& aSize
,
178 const Maybe
<SVGImageContext
>& aSVGContext
,
180 layers::ImageContainer
** aOutContainer
) {
181 return mInnerImage
->GetImageContainerAtSize(aManager
, aSize
, aSVGContext
,
182 aFlags
, aOutContainer
);
185 NS_IMETHODIMP_(ImgDrawResult
)
186 ImageWrapper::Draw(gfxContext
* aContext
, const nsIntSize
& aSize
,
187 const ImageRegion
& aRegion
, uint32_t aWhichFrame
,
188 SamplingFilter aSamplingFilter
,
189 const Maybe
<SVGImageContext
>& aSVGContext
, uint32_t aFlags
,
191 return mInnerImage
->Draw(aContext
, aSize
, aRegion
, aWhichFrame
,
192 aSamplingFilter
, aSVGContext
, aFlags
, aOpacity
);
196 ImageWrapper::StartDecoding(uint32_t aFlags
, uint32_t aWhichFrame
) {
197 return mInnerImage
->StartDecoding(aFlags
, aWhichFrame
);
200 bool ImageWrapper::StartDecodingWithResult(uint32_t aFlags
,
201 uint32_t aWhichFrame
) {
202 return mInnerImage
->StartDecodingWithResult(aFlags
, aWhichFrame
);
205 bool ImageWrapper::RequestDecodeWithResult(uint32_t aFlags
,
206 uint32_t aWhichFrame
) {
207 return mInnerImage
->RequestDecodeWithResult(aFlags
, aWhichFrame
);
211 ImageWrapper::RequestDecodeForSize(const nsIntSize
& aSize
, uint32_t aFlags
,
212 uint32_t aWhichFrame
) {
213 return mInnerImage
->RequestDecodeForSize(aSize
, aFlags
, aWhichFrame
);
217 ImageWrapper::LockImage() {
218 MOZ_ASSERT(NS_IsMainThread(),
219 "Main thread to encourage serialization with UnlockImage");
220 return mInnerImage
->LockImage();
224 ImageWrapper::UnlockImage() {
225 MOZ_ASSERT(NS_IsMainThread(),
226 "Main thread to encourage serialization with LockImage");
227 return mInnerImage
->UnlockImage();
231 ImageWrapper::RequestDiscard() { return mInnerImage
->RequestDiscard(); }
234 ImageWrapper::RequestRefresh(const TimeStamp
& aTime
) {
235 return mInnerImage
->RequestRefresh(aTime
);
239 ImageWrapper::GetAnimationMode(uint16_t* aAnimationMode
) {
240 return mInnerImage
->GetAnimationMode(aAnimationMode
);
244 ImageWrapper::SetAnimationMode(uint16_t aAnimationMode
) {
245 return mInnerImage
->SetAnimationMode(aAnimationMode
);
249 ImageWrapper::ResetAnimation() { return mInnerImage
->ResetAnimation(); }
251 NS_IMETHODIMP_(float)
252 ImageWrapper::GetFrameIndex(uint32_t aWhichFrame
) {
253 return mInnerImage
->GetFrameIndex(aWhichFrame
);
256 NS_IMETHODIMP_(int32_t)
257 ImageWrapper::GetFirstFrameDelay() { return mInnerImage
->GetFirstFrameDelay(); }
260 ImageWrapper::SetAnimationStartTime(const TimeStamp
& aTime
) {
261 mInnerImage
->SetAnimationStartTime(aTime
);
264 void ImageWrapper::PropagateUseCounters(Document
* aParentDocument
) {
265 mInnerImage
->PropagateUseCounters(aParentDocument
);
268 nsIntSize
ImageWrapper::OptimalImageSizeForDest(const gfxSize
& aDest
,
269 uint32_t aWhichFrame
,
270 SamplingFilter aSamplingFilter
,
272 return mInnerImage
->OptimalImageSizeForDest(aDest
, aWhichFrame
,
273 aSamplingFilter
, aFlags
);
276 NS_IMETHODIMP_(nsIntRect
)
277 ImageWrapper::GetImageSpaceInvalidationRect(const nsIntRect
& aRect
) {
278 return mInnerImage
->GetImageSpaceInvalidationRect(aRect
);
281 already_AddRefed
<imgIContainer
> ImageWrapper::Unwrap() {
282 return mInnerImage
->Unwrap();
286 } // namespace mozilla