Bug 1585126 [wpt PR 19411] - Support clamp() in CSSNumericValue.parse(), a=testonly
[gecko.git] / image / ImageWrapper.cpp
blob01463925e2ea289867175db97ae7abe87ce937c1
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 NS_IMETHODIMP_(Orientation)
128 ImageWrapper::GetOrientation() { return mInnerImage->GetOrientation(); }
130 NS_IMETHODIMP
131 ImageWrapper::GetType(uint16_t* aType) { return mInnerImage->GetType(aType); }
133 NS_IMETHODIMP
134 ImageWrapper::GetProducerId(uint32_t* aId) {
135 return mInnerImage->GetProducerId(aId);
138 NS_IMETHODIMP
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,
150 uint32_t aFlags) {
151 return mInnerImage->GetFrameAtSize(aSize, aWhichFrame, aFlags);
154 NS_IMETHODIMP_(bool)
155 ImageWrapper::WillDrawOpaqueNow() { return mInnerImage->WillDrawOpaqueNow(); }
157 NS_IMETHODIMP_(bool)
158 ImageWrapper::IsImageContainerAvailable(LayerManager* aManager,
159 uint32_t aFlags) {
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);
168 NS_IMETHODIMP_(bool)
169 ImageWrapper::IsImageContainerAvailableAtSize(LayerManager* aManager,
170 const IntSize& aSize,
171 uint32_t aFlags) {
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,
179 uint32_t aFlags,
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,
190 float aOpacity) {
191 return mInnerImage->Draw(aContext, aSize, aRegion, aWhichFrame,
192 aSamplingFilter, aSVGContext, aFlags, aOpacity);
195 NS_IMETHODIMP
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);
210 NS_IMETHODIMP
211 ImageWrapper::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags,
212 uint32_t aWhichFrame) {
213 return mInnerImage->RequestDecodeForSize(aSize, aFlags, aWhichFrame);
216 NS_IMETHODIMP
217 ImageWrapper::LockImage() {
218 MOZ_ASSERT(NS_IsMainThread(),
219 "Main thread to encourage serialization with UnlockImage");
220 return mInnerImage->LockImage();
223 NS_IMETHODIMP
224 ImageWrapper::UnlockImage() {
225 MOZ_ASSERT(NS_IsMainThread(),
226 "Main thread to encourage serialization with LockImage");
227 return mInnerImage->UnlockImage();
230 NS_IMETHODIMP
231 ImageWrapper::RequestDiscard() { return mInnerImage->RequestDiscard(); }
233 NS_IMETHODIMP_(void)
234 ImageWrapper::RequestRefresh(const TimeStamp& aTime) {
235 return mInnerImage->RequestRefresh(aTime);
238 NS_IMETHODIMP
239 ImageWrapper::GetAnimationMode(uint16_t* aAnimationMode) {
240 return mInnerImage->GetAnimationMode(aAnimationMode);
243 NS_IMETHODIMP
244 ImageWrapper::SetAnimationMode(uint16_t aAnimationMode) {
245 return mInnerImage->SetAnimationMode(aAnimationMode);
248 NS_IMETHODIMP
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(); }
259 NS_IMETHODIMP_(void)
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,
271 uint32_t aFlags) {
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();
285 } // namespace image
286 } // namespace mozilla