1 /** -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include
"nsISupports.idl"
12 #include
"ImgDrawResult.h"
14 #include
"mozilla/gfx/Types.h"
15 #include
"mozilla/AspectRatio.h"
16 #include
"mozilla/Maybe.h"
17 #include
"mozilla/RefPtr.h"
42 class SVGImageContext
;
43 struct MediaFeatureChange
;
51 class WebRenderImageProvider
;
60 native MaybeAspectRatio
(mozilla
::Maybe<mozilla
::AspectRatio
>);
61 native ImgDrawResult
(mozilla
::image
::ImgDrawResult
);
62 [ptr] native gfxContext
(gfxContext
);
63 [ref] native gfxMatrix
(gfxMatrix
);
64 [ref] native gfxRect
(gfxRect
);
65 [ref] native gfxSize
(gfxSize
);
66 native SamplingFilter
(mozilla
::gfx
::SamplingFilter
);
67 [ref] native nsIntRect
(nsIntRect
);
68 native nsIntRectByVal
(nsIntRect
);
69 [ref] native nsIntSize
(nsIntSize
);
70 native nsSize
(nsSize
);
71 [ptr] native nsIFrame
(nsIFrame
);
72 native TempRefImageContainer
(already_AddRefed
<mozilla
::layers
::ImageContainer
>);
73 [ptr] native ImageContainer
(mozilla
::layers
::ImageContainer
);
74 [ptr] native WebRenderImageProvider
(mozilla
::image
::WebRenderImageProvider
);
75 [ref] native ImageRegion
(mozilla
::image
::ImageRegion
);
76 [ptr] native WindowRenderer
(mozilla
::WindowRenderer
);
77 native Orientation
(mozilla
::image
::Orientation
);
78 native ImageResolution
(mozilla
::image
::Resolution
);
79 [ref] native TimeStamp
(mozilla
::TimeStamp
);
80 [ref] native SVGImageContext
(mozilla
::SVGImageContext
);
81 [ref] native MaybeImageIntRegion
(mozilla
::Maybe<mozilla
::image
::ImageIntRegion
>);
82 native TempRefSourceSurface
(already_AddRefed
<mozilla
::gfx
::SourceSurface
>);
83 native TempRefImgIContainer
(already_AddRefed
<imgIContainer
>);
84 native nsIntSizeByVal
(nsIntSize
);
85 [ref] native MediaFeatureChange
(mozilla
::MediaFeatureChange
);
89 * imgIContainer is the interface that represents an image. It allows
90 * access to frames as Thebes surfaces. It also allows drawing of images
91 * onto Thebes contexts.
93 * Internally, imgIContainer also manages animation of images.
95 [scriptable
, builtinclass
, uuid(a8dbee24
-ff86
-4755-b40e
-51175caf31af
)]
96 interface imgIContainer
: nsISupports
99 * The width of the container rectangle. In the case of any error,
100 * zero is returned, and an exception will be thrown.
102 readonly attribute int32_t width
;
105 * The height of the container rectangle. In the case of any error,
106 * zero is returned, and an exception will be thrown.
108 readonly attribute int32_t height
;
111 * The intrinsic size of this image in appunits. If the image has no intrinsic
112 * size in a dimension, -1 will be returned for that dimension. In the case of
113 * any error, an exception will be thrown.
115 [noscript
] readonly attribute nsSize intrinsicSize
;
118 * The (dimensionless) intrinsic ratio of this image. In the case of any
119 * error, Nothing() will be returned.
121 [notxpcom
, nostdcall
] readonly attribute MaybeAspectRatio intrinsicRatio
;
124 * The x coordinate of the image's hotspot, or 0 if there is no hotspot.
126 readonly attribute int32_t hotspotX
;
129 * The y coordinate of the image's hotspot, or 0 if there is no hotspot.
131 readonly attribute int32_t hotspotY
;
134 * Given a size at which this image will be displayed, and the drawing
135 * parameters affecting how it will be drawn, returns the image size which
136 * should be used to draw to produce the highest quality result. This is the
137 * appropriate size, for example, to use as an input to the pixel snapping
140 * For best results the size returned by this method should not be cached. It
141 * can change over time due to changes in the internal state of the image.
143 * @param aDest The size of the destination rect into which this image will be
144 * drawn, in device pixels.
145 * @param aWhichFrame Frame specifier of the FRAME_* variety.
146 * @param aSamplingFilter The filter to be used if we're scaling the image.
147 * @param aFlags Flags of the FLAG_* variety
149 [notxpcom
, nostdcall
] nsIntSizeByVal
150 optimalImageSizeForDest
([const] in gfxSize aDest
, in uint32_t aWhichFrame
,
151 in SamplingFilter aSamplingFilter
, in uint32_t aFlags
);
154 * Enumerated values for the 'type' attribute (below).
156 const unsigned short TYPE_RASTER
= 0;
157 const unsigned short TYPE_VECTOR
= 1;
158 const unsigned short TYPE_REQUEST
= 2;
161 * The type of this image (one of the TYPE_* values above).
163 [infallible
] readonly attribute
unsigned short type
;
166 * Whether this image is animated. You can only be guaranteed that querying
167 * this will not throw if STATUS_DECODE_COMPLETE is set on the imgIRequest.
169 * @throws NS_ERROR_NOT_AVAILABLE if the animated state cannot be determined.
171 readonly attribute
boolean animated
;
174 * Provider ID for image providers created by this image.
176 [infallible
] readonly attribute
unsigned long providerId
;
179 * Flags for imgIContainer operations.
183 * FLAG_NONE: Lack of flags.
185 * FLAG_SYNC_DECODE: Forces synchronous/non-progressive decode of all
186 * available data before the call returns.
188 * FLAG_SYNC_DECODE_IF_FAST: Like FLAG_SYNC_DECODE, but requests a sync decode
189 * be performed only if ImageLib estimates it can be completed very quickly.
191 * FLAG_ASYNC_NOTIFY: Send notifications asynchronously, even if we decode
192 * synchronously because of FLAG_SYNC_DECODE or FLAG_SYNC_DECODE_IF_FAST.
194 * FLAG_DECODE_NO_PREMULTIPLY_ALPHA: Do not premultiply alpha if
195 * it's not already premultiplied in the image data.
197 * FLAG_DECODE_NO_COLORSPACE_CONVERSION: Do not do any colorspace conversion;
198 * ignore any embedded profiles, and don't convert to any particular
201 * FLAG_CLAMP: Extend the image to the fill area by clamping image sample
202 * coordinates instead of by tiling. This only affects 'draw'.
204 * FLAG_HIGH_QUALITY_SCALING: A hint as to whether this image should be
205 * scaled using the high quality scaler. Do not set this if not drawing to
206 * a window or not listening to invalidations. Passing this flag will do two
207 * things: 1) request a decode of the image at the size asked for by the
208 * caller if one isn't already started or complete, and 2) allows a decoded
209 * frame of any size (it could be neither the requested size, nor the
210 * intrinsic size) to be substituted.
212 * FLAG_BYPASS_SURFACE_CACHE: Forces drawing to happen rather than taking
213 * cached rendering from the surface cache. This is used when we are printing,
214 * for example, where we want the vector commands from VectorImages to end up
215 * in the PDF output rather than a cached rendering at screen resolution.
217 * FLAG_FORCE_PRESERVEASPECTRATIO_NONE: Force scaling this image
218 * non-uniformly if necessary. This flag is for vector image only. A raster
219 * image should ignore this flag. While drawing a vector image with this
220 * flag, do not force uniform scaling even if its root <svg> node has a
221 * preserveAspectRatio attribute that would otherwise require uniform
222 * scaling , such as xMinYMin/ xMidYMin. Always scale the graphic content of
223 * the given image non-uniformly if necessary such that the image's
224 * viewBox (if specified or implied by height/width attributes) exactly
225 * matches the viewport rectangle.
227 * FLAG_FORCE_UNIFORM_SCALING: Signal to ClippedImage::OptimalSizeForDest that
228 * its returned size can only scale the image's size *uniformly* (by the same
229 * factor in each dimension). We need this flag when painting border-image
230 * section with SVG image source-data, if the SVG image has no viewBox and no
231 * intrinsic size. In such a case, we synthesize a viewport for the SVG image
232 * (a "window into SVG space") based on the border image area, and we need to
233 * be sure we don't subsequently scale that viewport in a way that distorts
234 * its contents by stretching them more in one dimension than the other.
236 * FLAG_AVOID_REDECODE_FOR_SIZE: If there is already a raster surface
237 * available for this image, but it is not the same size as requested, skip
238 * starting a new decode for said size.
240 * FLAG_DECODE_TO_SRGB_COLORSPACE: Instead of converting the colorspace to
241 * the display's colorspace, use sRGB.
243 * FLAG_RECORD_BLOB: Instead of rasterizing an SVG image on the main thread,
244 * record the drawing commands using blob images.
246 const unsigned long FLAG_NONE
= 0x0;
247 const unsigned long FLAG_SYNC_DECODE
= 0x1;
248 const unsigned long FLAG_SYNC_DECODE_IF_FAST
= 0x2;
249 const unsigned long FLAG_ASYNC_NOTIFY
= 0x4;
250 const unsigned long FLAG_DECODE_NO_PREMULTIPLY_ALPHA
= 0x8;
251 const unsigned long FLAG_DECODE_NO_COLORSPACE_CONVERSION
= 0x10;
252 const unsigned long FLAG_CLAMP
= 0x20;
253 const unsigned long FLAG_HIGH_QUALITY_SCALING
= 0x40;
254 const unsigned long FLAG_BYPASS_SURFACE_CACHE
= 0x80;
255 const unsigned long FLAG_FORCE_PRESERVEASPECTRATIO_NONE
= 0x100;
256 const unsigned long FLAG_FORCE_UNIFORM_SCALING
= 0x200;
257 const unsigned long FLAG_AVOID_REDECODE_FOR_SIZE
= 0x400;
258 const unsigned long FLAG_DECODE_TO_SRGB_COLORSPACE
= 0x800;
259 const unsigned long FLAG_RECORD_BLOB
= 0x1000;
262 * A constant specifying the default set of decode flags (i.e., the default
263 * values for FLAG_DECODE_*).
265 const unsigned long DECODE_FLAGS_DEFAULT
= 0;
268 * A constant specifying the decode flags recommended to be used when
269 * re-encoding an image, or with the clipboard.
271 const unsigned long DECODE_FLAGS_FOR_REENCODE
=
272 FLAG_DECODE_NO_PREMULTIPLY_ALPHA | FLAG_DECODE_TO_SRGB_COLORSPACE
;
275 * Constants for specifying various "special" frames.
277 * FRAME_FIRST: The first frame
278 * FRAME_CURRENT: The current frame
280 * FRAME_MAX_VALUE should be set to the value of the maximum constant above,
281 * as it is used for ensuring that a valid value was passed in.
283 const unsigned long FRAME_FIRST
= 0;
284 const unsigned long FRAME_CURRENT
= 1;
285 const unsigned long FRAME_MAX_VALUE
= 1;
288 * Get a surface for the given frame. This may be a platform-native,
289 * optimized surface, so you cannot inspect its pixel data. If you
290 * need that, use SourceSurface::GetDataSurface.
292 * @param aWhichFrame Frame specifier of the FRAME_* variety.
293 * @param aFlags Flags of the FLAG_* variety
295 [noscript
, notxpcom
] TempRefSourceSurface getFrame
(in uint32_t aWhichFrame
,
299 * Get a surface for the given frame at the specified size. Matching the
300 * requested size is best effort; it's not guaranteed that the surface you get
301 * will be a perfect match. (Some reasons you may get a surface of a different
302 * size include: if you requested upscaling, if downscale-during-decode is
303 * disabled, or if you didn't request the first frame.)
305 * @param aSize The desired size.
306 * @param aWhichFrame Frame specifier of the FRAME_* variety.
307 * @param aFlags Flags of the FLAG_* variety
309 [noscript
, notxpcom
] TempRefSourceSurface getFrameAtSize
([const] in nsIntSize aSize
,
310 in uint32_t aWhichFrame
,
314 * Returns true if this image will draw opaquely right now if asked to draw
315 * with FLAG_HIGH_QUALITY_SCALING and otherwise default flags. If this image
316 * (when decoded) is opaque but no decoded frames are available then
317 * willDrawOpaqueNow will return false.
319 [noscript
, notxpcom
] boolean willDrawOpaqueNow
();
322 * Returns true if this image has a frame and the frame currently has a
323 * least 1 decoded pixel. Only valid for raster images.
325 [noscript
, notxpcom
] boolean hasDecodedPixels
();
328 * @return true if getImageContainer() is expected to return a valid
329 * ImageContainer when passed the given @Renderer and @Flags
332 [noscript
, notxpcom
] boolean isImageContainerAvailable
(in WindowRenderer aRenderer
,
336 * Attempts to find a WebRenderImageProvider containing the current frame at
337 * the given size. Match the requested size is best effort; it's not
338 * guaranteed that the surface you get will be a perfect match. (Some reasons
339 * you may get a surface of a different size include: if you requested
340 * upscaling, or if downscale-during-decode is disabled.)
342 * @param aRenderer The WindowRenderer which will be used to render the
344 * @param aSVGContext If specified, SVG-related rendering context, such as
345 * overridden attributes on the image document's root <svg>
346 * node, and the size of the viewport that the full image
347 * would occupy. Ignored for raster images.
348 * @param aFlags Decoding / drawing flags (in other words, FLAG_* flags).
349 * Currently only FLAG_SYNC_DECODE and FLAG_SYNC_DECODE_IF_FAST
351 * @param aProvider Return value for WebRenderImageProvider for the current
352 * frame. May be null depending on the draw result.
353 * @return The draw result for the current frame.
355 [noscript
, notxpcom
] ImgDrawResult getImageProvider
(in WindowRenderer aRenderer
,
356 [const] in nsIntSize aSize
,
357 [const] in SVGImageContext aSVGContext
,
358 [const] in MaybeImageIntRegion aRegion
,
360 out WebRenderImageProvider aProvider
);
363 * Draw the requested frame of this image onto the context specified.
365 * Drawing an image involves scaling it to a certain size (which may be
366 * implemented as a "smart" scale by substituting an HQ-scaled frame or
367 * rendering at a high DPI), and then selecting a region of that image to
368 * draw. That region is drawn onto the graphics context and in the process
369 * transformed by the context matrix, which determines the final area that is
370 * filled. The basic process looks like this:
372 * +------------------+
375 * | intrinsic width |
377 * | intrinsic height |
378 * +------------------+
381 * / (scale to aSize) \
383 * +----------------------------+
386 * | aSize.width X aSize.height |
391 * +-------(---------(----------+
398 * +---------------------+
402 * +---------------------+
404 * The region may extend outside of the scaled image's boundaries. It's
405 * actually a region in tiled image space, which is formed by tiling the
406 * scaled image infinitely in every direction. Drawing with a region larger
407 * than the scaled image thus causes the filled area to contain multiple tiled
408 * copies of the image, which looks like this:
410 * ....................................................
412 * : Tile : Tile : Tile :
413 * : +------------[aRegion]------------+ :
414 * :........|.......:................:........|.......:
416 * : Ti|le : Scaled Image : Ti|le :
418 * :........|.......:................:........|.......:
419 * : +---------------------------------+ :
420 * : Ti|le : Tile : Ti|le :
422 * :......(.........:................:..........).....:
425 * | (transform by aContext matrix) |
427 * +---------------------------------------------+
429 * |.....:.................................:.....|
433 * |.....:.................................:.....|
435 * +---------------------------------------------+
438 * @param aContext The Thebes context to draw the image to.
439 * @param aSize The size to which the image should be scaled before drawing.
440 * This requirement may be satisfied using HQ scaled frames,
441 * selecting from different resolution layers, drawing at a
442 * higher DPI, or just performing additional scaling on the
443 * graphics context. Callers can use optimalImageSizeForDest()
444 * to determine the best choice for this parameter if they have
445 * no special size requirements.
446 * @param aRegion The region in tiled image space which will be drawn onto the
447 * graphics context. aRegion is in the coordinate space of the
448 * image after it has been scaled to aSize - that is, the image
449 * is scaled first, and then aRegion is applied. When aFlags
450 * includes FLAG_CLAMP, the image will be extended to this area
451 * by clamping image sample coordinates. Otherwise, the image
452 * will be automatically tiled as necessary. aRegion can also
453 * optionally contain a second region which restricts the set
454 * of pixels we're allowed to sample from when drawing; this
455 * is only of use to callers which need to draw with pixel
457 * @param aWhichFrame Frame specifier of the FRAME_* variety.
458 * @param aSamplingFilter The filter to be used if we're scaling the image.
459 * @param aSVGContext If specified, SVG-related rendering context, such as
460 * overridden attributes on the image document's root <svg>
461 * node, and the size of the viewport that the full image
462 * would occupy. Ignored for raster images.
463 * @param aFlags Flags of the FLAG_* variety
464 * @return A ImgDrawResult value indicating whether and to what degree the
465 * drawing operation was successful.
467 [noscript
, notxpcom
] ImgDrawResult
468 draw
(in gfxContext aContext
,
469 [const] in nsIntSize aSize
,
470 [const] in ImageRegion aRegion
,
471 in uint32_t aWhichFrame
,
472 in SamplingFilter aSamplingFilter
,
473 [const] in SVGImageContext aSVGContext
,
478 * Ensures that an image is decoding. Calling this function guarantees that
479 * the image will at some point fire off decode notifications. Images that
480 * can be decoded "quickly" according to some heuristic will be decoded
483 * @param aFlags Flags of the FLAG_* variety. Only FLAG_ASYNC_NOTIFY
484 * is accepted; all others are ignored.
485 * @param aWhichFrame Frame specifier of the FRAME_* variety.
487 [noscript
] void startDecoding
(in uint32_t aFlags
, in uint32_t aWhichFrame
);
490 nsresult StartDecoding
(uint32_t aFlags
) {
491 return StartDecoding
(aFlags
, FRAME_CURRENT
);
496 * Exactly like startDecoding above except returns whether the current frame
497 * of the image is complete or not.
499 * @param aFlags Flags of the FLAG_* variety. Only FLAG_ASYNC_NOTIFY
500 * is accepted; all others are ignored.
501 * @param aWhichFrame Frame specifier of the FRAME_* variety.
503 [noscript
, notxpcom
] boolean startDecodingWithResult
(in uint32_t aFlags
, in uint32_t aWhichFrame
);
506 bool StartDecodingWithResult
(uint32_t aFlags
) {
507 return StartDecodingWithResult
(aFlags
, FRAME_CURRENT
);
512 * This method triggers decoding for an image, but unlike startDecoding() it
513 * enables the caller to provide more detailed information about the decode
516 * @param aFlags Flags of the FLAG_* variety.
517 * @param aWhichFrame Frame specifier of the FRAME_* variety.
518 * @return DECODE_SURFACE_AVAILABLE if is a surface that satisfies the
519 * request and it is fully decoded.
520 * DECODE_REQUESTED if we requested a decode.
521 * DECODE_REQUEST_FAILED if we failed to request a decode. This means
522 * that either there is an error in the image or we cannot allocate a
525 cenum DecodeResult
: 8 {
526 DECODE_SURFACE_AVAILABLE
= 0,
527 DECODE_REQUESTED
= 1,
528 DECODE_REQUEST_FAILED
= 2
530 [noscript
, notxpcom
] imgIContainer_DecodeResult requestDecodeWithResult
(in uint32_t aFlags
, in uint32_t aWhichFrame
);
533 DecodeResult RequestDecodeWithResult
(uint32_t aFlags
) {
534 return RequestDecodeWithResult
(aFlags
, FRAME_CURRENT
);
539 * This method triggers decoding for an image, but unlike startDecoding() it
540 * enables the caller to provide more detailed information about the decode
543 * @param aSize The size to which the image should be scaled while decoding,
544 * if possible. If the image cannot be scaled to this size while
545 * being decoded, it will be decoded at its intrinsic size.
546 * @param aFlags Flags of the FLAG_* variety.
547 * @param aWhichFrame Frame specifier of the FRAME_* variety.
549 [noscript
] void requestDecodeForSize
([const] in nsIntSize aSize
,
551 in uint32_t aWhichFrame
);
554 nsresult RequestDecodeForSize
(const nsIntSize
& aSize
, uint32_t aFlags
) {
555 return RequestDecodeForSize
(aSize
, aFlags
, FRAME_CURRENT
);
560 * Increments the lock count on the image. An image will not be discarded
561 * as long as the lock count is nonzero. Note that it is still possible for
562 * the image to be undecoded if decode-on-draw is enabled and the image
565 * Upon instantiation images have a lock count of zero.
570 * Decreases the lock count on the image. If the lock count drops to zero,
571 * the image is allowed to discard its frame data to save memory.
573 * Upon instantiation images have a lock count of zero. It is an error to
574 * call this method without first having made a matching lockImage() call.
575 * In other words, the lock count is not allowed to be negative.
580 * If this image is unlocked, discard its decoded data. If the image is
581 * locked or has already been discarded, do nothing.
583 void requestDiscard
();
586 * Indicates that this imgIContainer has been triggered to update
587 * its internal animation state. Likely this should only be called
588 * from within nsImageFrame or objects of similar type.
590 [notxpcom
] void requestRefresh
([const] in TimeStamp aTime
);
593 * Animation mode Constants
598 const short kNormalAnimMode
= 0;
599 const short kDontAnimMode
= 1;
600 const short kLoopOnceAnimMode
= 2;
602 attribute
unsigned short animationMode
;
604 /* Methods to control animation */
605 void resetAnimation
();
608 * Returns an index for the requested animation frame (either FRAME_FIRST or
611 * The units of the index aren't specified, and may vary between different
612 * types of images. What you can rely on is that on all occasions when
613 * getFrameIndex(FRAME_CURRENT) returns a certain value,
614 * draw(..FRAME_CURRENT..) will draw the same frame. The same holds for
615 * FRAME_FIRST as well.
617 * @param aWhichFrame Frame specifier of the FRAME_* variety.
619 [notxpcom
] float getFrameIndex
(in uint32_t aWhichFrame
);
622 * Returns the inherent orientation of the image, as described in the image's
623 * metadata (e.g. EXIF).
625 [notxpcom
] Orientation getOrientation
();
628 * Returns the intrinsic resolution of the image, or 1.0 if the image doesn't
631 [notxpcom
] ImageResolution getResolution
();
634 * Returns the delay, in ms, between the first and second frame. If this
635 * returns 0, there is no delay between first and second frame (i.e., this
636 * image could render differently whenever it draws).
638 * If this image is not animated, or not known to be animated (see attribute
639 * animated), returns -1.
641 [notxpcom
] int32_t getFirstFrameDelay
();
644 * If this is an animated image that hasn't started animating already, this
645 * sets the animation's start time to the indicated time.
647 * This has no effect if the image isn't animated or it has started animating
648 * already; it also has no effect if the image format doesn't care about
649 * animation start time.
651 * In all cases, animation does not actually begin until startAnimation(),
652 * resetAnimation(), or requestRefresh() is called for the first time.
654 [notxpcom
] void setAnimationStartTime
([const] in TimeStamp aTime
);
657 * Given an invalidation rect in the coordinate system used by the decoder,
658 * returns an invalidation rect in image space.
660 * This is the identity transformation in most cases, but the result can
661 * differ if the image is wrapped by an ImageWrapper that changes its size
664 [notxpcom
] nsIntRectByVal
665 getImageSpaceInvalidationRect
([const] in nsIntRect aRect
);
668 * Removes any ImageWrappers and returns the unwrapped base image.
670 [notxpcom
, nostdcall
] TempRefImgIContainer unwrap
();
673 * Propagate the use counters (if any) from this container to the passed in
676 [noscript
, notxpcom
] void propagateUseCounters
(in Document aReferencingDocument
);
679 * Called when media feature values that apply to all documents (such as
680 * those based on system metrics) have changed. If this image is a type
681 * that can respond to media queries (i.e., an SVG image), this function
682 * is overridden to handle restyling and invalidating the image.
684 [notxpcom
, nostdcall
] void mediaFeatureValuesChangedAllDocuments
([const] in MediaFeatureChange aChange
);
687 * Get the set of sizes the image can decode to natively.
689 [nostdcall
] Array
<nsIntSizeByVal
> getNativeSizes
();
691 [nostdcall
, notxpcom
] size_t getNativeSizesLength
();