/src/mozilla-central/image/DynamicImage.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | #include "DynamicImage.h" |
7 | | #include "gfxPlatform.h" |
8 | | #include "gfxUtils.h" |
9 | | #include "mozilla/gfx/2D.h" |
10 | | #include "mozilla/gfx/Logging.h" |
11 | | #include "mozilla/RefPtr.h" |
12 | | #include "ImageRegion.h" |
13 | | #include "Orientation.h" |
14 | | #include "SVGImageContext.h" |
15 | | |
16 | | #include "mozilla/MemoryReporting.h" |
17 | | |
18 | | using namespace mozilla; |
19 | | using namespace mozilla::gfx; |
20 | | using mozilla::layers::LayerManager; |
21 | | using mozilla::layers::ImageContainer; |
22 | | |
23 | | namespace mozilla { |
24 | | namespace image { |
25 | | |
26 | | // Inherited methods from Image. |
27 | | |
28 | | already_AddRefed<ProgressTracker> |
29 | | DynamicImage::GetProgressTracker() |
30 | 0 | { |
31 | 0 | return nullptr; |
32 | 0 | } |
33 | | |
34 | | size_t |
35 | | DynamicImage::SizeOfSourceWithComputedFallback(SizeOfState& aState) const |
36 | 0 | { |
37 | 0 | return 0; |
38 | 0 | } |
39 | | |
40 | | void |
41 | | DynamicImage::CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters, |
42 | | MallocSizeOf aMallocSizeOf) const |
43 | 0 | { |
44 | 0 | // We can't report anything useful because gfxDrawable doesn't expose this |
45 | 0 | // information. |
46 | 0 | } |
47 | | |
48 | | void |
49 | | DynamicImage::IncrementAnimationConsumers() |
50 | 0 | { } |
51 | | |
52 | | void |
53 | | DynamicImage::DecrementAnimationConsumers() |
54 | 0 | { } |
55 | | |
56 | | #ifdef DEBUG |
57 | | uint32_t |
58 | | DynamicImage::GetAnimationConsumers() |
59 | | { |
60 | | return 0; |
61 | | } |
62 | | #endif |
63 | | |
64 | | nsresult |
65 | | DynamicImage::OnImageDataAvailable(nsIRequest* aRequest, |
66 | | nsISupports* aContext, |
67 | | nsIInputStream* aInStr, |
68 | | uint64_t aSourceOffset, |
69 | | uint32_t aCount) |
70 | 0 | { |
71 | 0 | return NS_OK; |
72 | 0 | } |
73 | | |
74 | | nsresult |
75 | | DynamicImage::OnImageDataComplete(nsIRequest* aRequest, |
76 | | nsISupports* aContext, |
77 | | nsresult aStatus, |
78 | | bool aLastPart) |
79 | 0 | { |
80 | 0 | return NS_OK; |
81 | 0 | } |
82 | | |
83 | | void |
84 | | DynamicImage::OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) |
85 | 0 | { } |
86 | | |
87 | | void |
88 | | DynamicImage::SetInnerWindowID(uint64_t aInnerWindowId) |
89 | 0 | { } |
90 | | |
91 | | uint64_t |
92 | | DynamicImage::InnerWindowID() const |
93 | 0 | { |
94 | 0 | return 0; |
95 | 0 | } |
96 | | |
97 | | bool |
98 | | DynamicImage::HasError() |
99 | 0 | { |
100 | 0 | return !mDrawable; |
101 | 0 | } |
102 | | |
103 | | void |
104 | | DynamicImage::SetHasError() |
105 | 0 | { } |
106 | | |
107 | | nsIURI* |
108 | | DynamicImage::GetURI() const |
109 | 0 | { |
110 | 0 | return nullptr; |
111 | 0 | } |
112 | | |
113 | | // Methods inherited from XPCOM interfaces. |
114 | | |
115 | | NS_IMPL_ISUPPORTS(DynamicImage, imgIContainer) |
116 | | |
117 | | NS_IMETHODIMP |
118 | | DynamicImage::GetWidth(int32_t* aWidth) |
119 | 0 | { |
120 | 0 | *aWidth = mDrawable->Size().width; |
121 | 0 | return NS_OK; |
122 | 0 | } |
123 | | |
124 | | NS_IMETHODIMP |
125 | | DynamicImage::GetHeight(int32_t* aHeight) |
126 | 0 | { |
127 | 0 | *aHeight = mDrawable->Size().height; |
128 | 0 | return NS_OK; |
129 | 0 | } |
130 | | |
131 | | nsresult |
132 | | DynamicImage::GetNativeSizes(nsTArray<IntSize>& aNativeSizes) const |
133 | 0 | { |
134 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
135 | 0 | } |
136 | | |
137 | | size_t |
138 | | DynamicImage::GetNativeSizesLength() const |
139 | 0 | { |
140 | 0 | return 0; |
141 | 0 | } |
142 | | |
143 | | NS_IMETHODIMP |
144 | | DynamicImage::GetIntrinsicSize(nsSize* aSize) |
145 | 0 | { |
146 | 0 | IntSize intSize(mDrawable->Size()); |
147 | 0 | *aSize = nsSize(intSize.width, intSize.height); |
148 | 0 | return NS_OK; |
149 | 0 | } |
150 | | |
151 | | NS_IMETHODIMP |
152 | | DynamicImage::GetIntrinsicRatio(nsSize* aSize) |
153 | 0 | { |
154 | 0 | IntSize intSize(mDrawable->Size()); |
155 | 0 | *aSize = nsSize(intSize.width, intSize.height); |
156 | 0 | return NS_OK; |
157 | 0 | } |
158 | | |
159 | | NS_IMETHODIMP_(Orientation) |
160 | | DynamicImage::GetOrientation() |
161 | 0 | { |
162 | 0 | return Orientation(); |
163 | 0 | } |
164 | | |
165 | | NS_IMETHODIMP |
166 | | DynamicImage::GetType(uint16_t* aType) |
167 | 0 | { |
168 | 0 | *aType = imgIContainer::TYPE_RASTER; |
169 | 0 | return NS_OK; |
170 | 0 | } |
171 | | |
172 | | NS_IMETHODIMP |
173 | | DynamicImage::GetAnimated(bool* aAnimated) |
174 | 0 | { |
175 | 0 | *aAnimated = false; |
176 | 0 | return NS_OK; |
177 | 0 | } |
178 | | |
179 | | NS_IMETHODIMP_(already_AddRefed<SourceSurface>) |
180 | | DynamicImage::GetFrame(uint32_t aWhichFrame, |
181 | | uint32_t aFlags) |
182 | 0 | { |
183 | 0 | IntSize size(mDrawable->Size()); |
184 | 0 | return GetFrameAtSize(IntSize(size.width, size.height), |
185 | 0 | aWhichFrame, |
186 | 0 | aFlags); |
187 | 0 | } |
188 | | |
189 | | NS_IMETHODIMP_(already_AddRefed<SourceSurface>) |
190 | | DynamicImage::GetFrameAtSize(const IntSize& aSize, |
191 | | uint32_t aWhichFrame, |
192 | | uint32_t aFlags) |
193 | 0 | { |
194 | 0 | RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()-> |
195 | 0 | CreateOffscreenContentDrawTarget(aSize, SurfaceFormat::B8G8R8A8); |
196 | 0 | if (!dt || !dt->IsValid()) { |
197 | 0 | gfxWarning() << |
198 | 0 | "DynamicImage::GetFrame failed in CreateOffscreenContentDrawTarget"; |
199 | 0 | return nullptr; |
200 | 0 | } |
201 | 0 | RefPtr<gfxContext> context = gfxContext::CreateOrNull(dt); |
202 | 0 | MOZ_ASSERT(context); // already checked the draw target above |
203 | 0 |
|
204 | 0 | auto result = Draw(context, aSize, ImageRegion::Create(aSize), |
205 | 0 | aWhichFrame, SamplingFilter::POINT, Nothing(), aFlags, |
206 | 0 | 1.0); |
207 | 0 |
|
208 | 0 | return result == ImgDrawResult::SUCCESS ? dt->Snapshot() : nullptr; |
209 | 0 | } |
210 | | |
211 | | NS_IMETHODIMP_(bool) |
212 | | DynamicImage::WillDrawOpaqueNow() |
213 | 0 | { |
214 | 0 | return false; |
215 | 0 | } |
216 | | |
217 | | NS_IMETHODIMP_(bool) |
218 | | DynamicImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags) |
219 | 0 | { |
220 | 0 | return false; |
221 | 0 | } |
222 | | |
223 | | NS_IMETHODIMP_(already_AddRefed<ImageContainer>) |
224 | | DynamicImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags) |
225 | 0 | { |
226 | 0 | return nullptr; |
227 | 0 | } |
228 | | |
229 | | NS_IMETHODIMP_(bool) |
230 | | DynamicImage::IsImageContainerAvailableAtSize(LayerManager* aManager, |
231 | | const IntSize& aSize, |
232 | | uint32_t aFlags) |
233 | 0 | { |
234 | 0 | return false; |
235 | 0 | } |
236 | | |
237 | | NS_IMETHODIMP_(ImgDrawResult) |
238 | | DynamicImage::GetImageContainerAtSize(layers::LayerManager* aManager, |
239 | | const gfx::IntSize& aSize, |
240 | | const Maybe<SVGImageContext>& aSVGContext, |
241 | | uint32_t aFlags, |
242 | | layers::ImageContainer** aContainer) |
243 | 0 | { |
244 | 0 | return ImgDrawResult::NOT_SUPPORTED; |
245 | 0 | } |
246 | | |
247 | | NS_IMETHODIMP_(ImgDrawResult) |
248 | | DynamicImage::Draw(gfxContext* aContext, |
249 | | const nsIntSize& aSize, |
250 | | const ImageRegion& aRegion, |
251 | | uint32_t aWhichFrame, |
252 | | SamplingFilter aSamplingFilter, |
253 | | const Maybe<SVGImageContext>& aSVGContext, |
254 | | uint32_t aFlags, |
255 | | float aOpacity) |
256 | 0 | { |
257 | 0 | MOZ_ASSERT(!aSize.IsEmpty(), "Unexpected empty size"); |
258 | 0 |
|
259 | 0 | IntSize drawableSize(mDrawable->Size()); |
260 | 0 |
|
261 | 0 | if (aSize == drawableSize) { |
262 | 0 | gfxUtils::DrawPixelSnapped(aContext, mDrawable, SizeDouble(drawableSize), aRegion, |
263 | 0 | SurfaceFormat::B8G8R8A8, aSamplingFilter, |
264 | 0 | aOpacity); |
265 | 0 | return ImgDrawResult::SUCCESS; |
266 | 0 | } |
267 | 0 | |
268 | 0 | gfxSize scale(double(aSize.width) / drawableSize.width, |
269 | 0 | double(aSize.height) / drawableSize.height); |
270 | 0 |
|
271 | 0 | ImageRegion region(aRegion); |
272 | 0 | region.Scale(1.0 / scale.width, 1.0 / scale.height); |
273 | 0 |
|
274 | 0 | gfxContextMatrixAutoSaveRestore saveMatrix(aContext); |
275 | 0 | aContext->Multiply(gfxMatrix::Scaling(scale.width, scale.height)); |
276 | 0 |
|
277 | 0 | gfxUtils::DrawPixelSnapped(aContext, mDrawable, SizeDouble(drawableSize), region, |
278 | 0 | SurfaceFormat::B8G8R8A8, aSamplingFilter, |
279 | 0 | aOpacity); |
280 | 0 | return ImgDrawResult::SUCCESS; |
281 | 0 | } |
282 | | |
283 | | NS_IMETHODIMP |
284 | | DynamicImage::StartDecoding(uint32_t aFlags) |
285 | 0 | { |
286 | 0 | return NS_OK; |
287 | 0 | } |
288 | | |
289 | | bool |
290 | | DynamicImage::StartDecodingWithResult(uint32_t aFlags) |
291 | 0 | { |
292 | 0 | return true; |
293 | 0 | } |
294 | | |
295 | | NS_IMETHODIMP |
296 | | DynamicImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags) |
297 | 0 | { |
298 | 0 | return NS_OK; |
299 | 0 | } |
300 | | |
301 | | NS_IMETHODIMP |
302 | | DynamicImage::LockImage() |
303 | 0 | { |
304 | 0 | return NS_OK; |
305 | 0 | } |
306 | | |
307 | | NS_IMETHODIMP |
308 | | DynamicImage::UnlockImage() |
309 | 0 | { |
310 | 0 | return NS_OK; |
311 | 0 | } |
312 | | |
313 | | NS_IMETHODIMP |
314 | | DynamicImage::RequestDiscard() |
315 | 0 | { |
316 | 0 | return NS_OK; |
317 | 0 | } |
318 | | |
319 | | NS_IMETHODIMP_(void) |
320 | | DynamicImage::RequestRefresh(const mozilla::TimeStamp& aTime) |
321 | 0 | { } |
322 | | |
323 | | NS_IMETHODIMP |
324 | | DynamicImage::GetAnimationMode(uint16_t* aAnimationMode) |
325 | 0 | { |
326 | 0 | *aAnimationMode = kNormalAnimMode; |
327 | 0 | return NS_OK; |
328 | 0 | } |
329 | | |
330 | | NS_IMETHODIMP |
331 | | DynamicImage::SetAnimationMode(uint16_t aAnimationMode) |
332 | 0 | { |
333 | 0 | return NS_OK; |
334 | 0 | } |
335 | | |
336 | | NS_IMETHODIMP |
337 | | DynamicImage::ResetAnimation() |
338 | 0 | { |
339 | 0 | return NS_OK; |
340 | 0 | } |
341 | | |
342 | | NS_IMETHODIMP_(float) |
343 | | DynamicImage::GetFrameIndex(uint32_t aWhichFrame) |
344 | 0 | { |
345 | 0 | return 0; |
346 | 0 | } |
347 | | |
348 | | NS_IMETHODIMP_(int32_t) |
349 | | DynamicImage::GetFirstFrameDelay() |
350 | 0 | { |
351 | 0 | return 0; |
352 | 0 | } |
353 | | |
354 | | NS_IMETHODIMP_(void) |
355 | | DynamicImage::SetAnimationStartTime(const mozilla::TimeStamp& aTime) |
356 | 0 | { } |
357 | | |
358 | | nsIntSize |
359 | | DynamicImage::OptimalImageSizeForDest(const gfxSize& aDest, |
360 | | uint32_t aWhichFrame, |
361 | | SamplingFilter aSamplingFilter, |
362 | | uint32_t aFlags) |
363 | 0 | { |
364 | 0 | IntSize size(mDrawable->Size()); |
365 | 0 | return nsIntSize(size.width, size.height); |
366 | 0 | } |
367 | | |
368 | | NS_IMETHODIMP_(nsIntRect) |
369 | | DynamicImage::GetImageSpaceInvalidationRect(const nsIntRect& aRect) |
370 | 0 | { |
371 | 0 | return aRect; |
372 | 0 | } |
373 | | |
374 | | already_AddRefed<imgIContainer> |
375 | | DynamicImage::Unwrap() |
376 | 0 | { |
377 | 0 | nsCOMPtr<imgIContainer> self(this); |
378 | 0 | return self.forget(); |
379 | 0 | } |
380 | | |
381 | | void |
382 | | DynamicImage::PropagateUseCounters(nsIDocument*) |
383 | 0 | { |
384 | 0 | // No use counters. |
385 | 0 | } |
386 | | |
387 | | } // namespace image |
388 | | } // namespace mozilla |