Bug 1444460 [wpt PR 9948] - gyroscope: Rename LocalCoordinateSystem to GyroscopeLocal...
[gecko.git] / image / imgIContainer.idl
blob3015c2d6ac64b72797c82eef991d160cacead95d
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"
9 %{C++
10 #include "ImgDrawResult.h"
11 #include "gfxContext.h"
12 #include "gfxMatrix.h"
13 #include "gfxRect.h"
14 #include "mozilla/gfx/2D.h"
15 #include "mozilla/Maybe.h"
16 #include "mozilla/RefPtr.h"
17 #include "nsRect.h"
18 #include "nsSize.h"
19 #include "limits.h"
21 class nsIDocument;
23 namespace mozilla {
24 namespace layers {
25 class LayerManager;
26 class ImageContainer;
30 class nsIFrame;
32 namespace mozilla {
33 class TimeStamp;
34 class SVGImageContext;
37 namespace mozilla {
38 namespace image {
40 class ImageRegion;
41 struct Orientation;
48 native ImgDrawResult(mozilla::image::ImgDrawResult);
49 [ptr] native gfxContext(gfxContext);
50 [ref] native gfxMatrix(gfxMatrix);
51 [ref] native gfxRect(gfxRect);
52 [ref] native gfxSize(gfxSize);
53 native SamplingFilter(mozilla::gfx::SamplingFilter);
54 [ref] native nsIntRect(nsIntRect);
55 native nsIntRectByVal(nsIntRect);
56 [ref] native nsIntSize(nsIntSize);
57 native nsSize(nsSize);
58 [ptr] native nsIFrame(nsIFrame);
59 native TempRefImageContainer(already_AddRefed<mozilla::layers::ImageContainer>);
60 [ref] native ImageRegion(mozilla::image::ImageRegion);
61 [ptr] native LayerManager(mozilla::layers::LayerManager);
62 native Orientation(mozilla::image::Orientation);
63 [ref] native TimeStamp(mozilla::TimeStamp);
64 [ref] native MaybeSVGImageContext(mozilla::Maybe<mozilla::SVGImageContext>);
65 native TempRefSourceSurface(already_AddRefed<mozilla::gfx::SourceSurface>);
66 native TempRefImgIContainer(already_AddRefed<imgIContainer>);
67 native nsIntSizeByVal(nsIntSize);
68 [ptr] native nsIDocument(nsIDocument);
71 /**
72 * imgIContainer is the interface that represents an image. It allows
73 * access to frames as Thebes surfaces. It also allows drawing of images
74 * onto Thebes contexts.
76 * Internally, imgIContainer also manages animation of images.
78 [scriptable, builtinclass, uuid(a8dbee24-ff86-4755-b40e-51175caf31af)]
79 interface imgIContainer : nsISupports
81 /**
82 * The width of the container rectangle. In the case of any error,
83 * zero is returned, and an exception will be thrown.
85 readonly attribute int32_t width;
87 /**
88 * The height of the container rectangle. In the case of any error,
89 * zero is returned, and an exception will be thrown.
91 readonly attribute int32_t height;
93 /**
94 * The intrinsic size of this image in appunits. If the image has no intrinsic
95 * size in a dimension, -1 will be returned for that dimension. In the case of
96 * any error, an exception will be thrown.
98 [noscript] readonly attribute nsSize intrinsicSize;
101 * The (dimensionless) intrinsic ratio of this image. In the case of any
102 * error, an exception will be thrown.
104 [noscript] readonly attribute nsSize intrinsicRatio;
107 * Given a size at which this image will be displayed, and the drawing
108 * parameters affecting how it will be drawn, returns the image size which
109 * should be used to draw to produce the highest quality result. This is the
110 * appropriate size, for example, to use as an input to the pixel snapping
111 * algorithm.
113 * For best results the size returned by this method should not be cached. It
114 * can change over time due to changes in the internal state of the image.
116 * @param aDest The size of the destination rect into which this image will be
117 * drawn, in device pixels.
118 * @param aWhichFrame Frame specifier of the FRAME_* variety.
119 * @param aSamplingFilter The filter to be used if we're scaling the image.
120 * @param aFlags Flags of the FLAG_* variety
122 [notxpcom, nostdcall] nsIntSizeByVal
123 optimalImageSizeForDest([const] in gfxSize aDest, in uint32_t aWhichFrame,
124 in SamplingFilter aSamplingFilter, in uint32_t aFlags);
127 * Enumerated values for the 'type' attribute (below).
129 const unsigned short TYPE_RASTER = 0;
130 const unsigned short TYPE_VECTOR = 1;
133 * The type of this image (one of the TYPE_* values above).
135 [infallible] readonly attribute unsigned short type;
138 * Whether this image is animated. You can only be guaranteed that querying
139 * this will not throw if STATUS_DECODE_COMPLETE is set on the imgIRequest.
141 * @throws NS_ERROR_NOT_AVAILABLE if the animated state cannot be determined.
143 readonly attribute boolean animated;
146 * Flags for imgIContainer operations.
148 * Meanings:
150 * FLAG_NONE: Lack of flags.
152 * FLAG_SYNC_DECODE: Forces synchronous/non-progressive decode of all
153 * available data before the call returns.
155 * FLAG_SYNC_DECODE_IF_FAST: Like FLAG_SYNC_DECODE, but requests a sync decode
156 * be performed only if ImageLib estimates it can be completed very quickly.
158 * FLAG_ASYNC_NOTIFY: Send notifications asynchronously, even if we decode
159 * synchronously beause of FLAG_SYNC_DECODE or FLAG_SYNC_DECODE_IF_FAST.
161 * FLAG_DECODE_NO_PREMULTIPLY_ALPHA: Do not premultiply alpha if
162 * it's not already premultiplied in the image data.
164 * FLAG_DECODE_NO_COLORSPACE_CONVERSION: Do not do any colorspace conversion;
165 * ignore any embedded profiles, and don't convert to any particular
166 * destination space.
168 * FLAG_CLAMP: Extend the image to the fill area by clamping image sample
169 * coordinates instead of by tiling. This only affects 'draw'.
171 * FLAG_HIGH_QUALITY_SCALING: A hint as to whether this image should be
172 * scaled using the high quality scaler. Do not set this if not drawing to
173 * a window or not listening to invalidations. Passing this flag will do two
174 * things: 1) request a decode of the image at the size asked for by the
175 * caller if one isn't already started or complete, and 2) allows a decoded
176 * frame of any size (it could be neither the requested size, nor the
177 * intrinsic size) to be substituted.
179 * FLAG_WANT_DATA_SURFACE: Can be passed to GetFrame when the caller wants a
180 * DataSourceSurface instead of a hardware accelerated surface. This can be
181 * important for performance (by avoiding an upload to/readback from the GPU)
182 * when the caller knows they want a SourceSurface of type DATA.
184 * FLAG_BYPASS_SURFACE_CACHE: Forces drawing to happen rather than taking
185 * cached rendering from the surface cache. This is used when we are printing,
186 * for example, where we want the vector commands from VectorImages to end up
187 * in the PDF output rather than a cached rendering at screen resolution.
189 * FLAG_FORCE_PRESERVEASPECTRATIO_NONE: Force scaling this image
190 * non-uniformly if necessary. This flag is for vector image only. A raster
191 * image should ignore this flag. While drawing a vector image with this
192 * flag, do not force uniform scaling even if its root <svg> node has a
193 * preserveAspectRatio attribute that would otherwise require uniform
194 * scaling , such as xMinYMin/ xMidYMin. Always scale the graphic content of
195 * the given image non-uniformly if necessary such that the image's
196 * viewBox (if specified or implied by height/width attributes) exactly
197 * matches the viewport rectangle.
199 * FLAG_FORCE_UNIFORM_SCALING: Signal to ClippedImage::OptimalSizeForDest that
200 * its returned size can only scale the image's size *uniformly* (by the same
201 * factor in each dimension). We need this flag when painting border-image
202 * section with SVG image source-data, if the SVG image has no viewBox and no
203 * intrinsic size. In such a case, we synthesize a viewport for the SVG image
204 * (a "window into SVG space") based on the border image area, and we need to
205 * be sure we don't subsequently scale that viewport in a way that distorts
206 * its contents by stretching them more in one dimension than the other.
208 const unsigned long FLAG_NONE = 0x0;
209 const unsigned long FLAG_SYNC_DECODE = 0x1;
210 const unsigned long FLAG_SYNC_DECODE_IF_FAST = 0x2;
211 const unsigned long FLAG_ASYNC_NOTIFY = 0x4;
212 const unsigned long FLAG_DECODE_NO_PREMULTIPLY_ALPHA = 0x8;
213 const unsigned long FLAG_DECODE_NO_COLORSPACE_CONVERSION = 0x10;
214 const unsigned long FLAG_CLAMP = 0x20;
215 const unsigned long FLAG_HIGH_QUALITY_SCALING = 0x40;
216 const unsigned long FLAG_WANT_DATA_SURFACE = 0x80;
217 const unsigned long FLAG_BYPASS_SURFACE_CACHE = 0x100;
218 const unsigned long FLAG_FORCE_PRESERVEASPECTRATIO_NONE = 0x200;
219 const unsigned long FLAG_FORCE_UNIFORM_SCALING = 0x400;
222 * A constant specifying the default set of decode flags (i.e., the default
223 * values for FLAG_DECODE_*).
225 const unsigned long DECODE_FLAGS_DEFAULT = 0;
228 * Constants for specifying various "special" frames.
230 * FRAME_FIRST: The first frame
231 * FRAME_CURRENT: The current frame
233 * FRAME_MAX_VALUE should be set to the value of the maximum constant above,
234 * as it is used for ensuring that a valid value was passed in.
236 const unsigned long FRAME_FIRST = 0;
237 const unsigned long FRAME_CURRENT = 1;
238 const unsigned long FRAME_MAX_VALUE = 1;
241 * Get a surface for the given frame. This may be a platform-native,
242 * optimized surface, so you cannot inspect its pixel data. If you
243 * need that, use SourceSurface::GetDataSurface.
245 * @param aWhichFrame Frame specifier of the FRAME_* variety.
246 * @param aFlags Flags of the FLAG_* variety
248 [noscript, notxpcom] TempRefSourceSurface getFrame(in uint32_t aWhichFrame,
249 in uint32_t aFlags);
252 * Get a surface for the given frame at the specified size. Matching the
253 * requested size is best effort; it's not guaranteed that the surface you get
254 * will be a perfect match. (Some reasons you may get a surface of a different
255 * size include: if you requested upscaling, if downscale-during-decode is
256 * disabled, or if you didn't request the first frame.)
258 * @param aSize The desired size.
259 * @param aWhichFrame Frame specifier of the FRAME_* variety.
260 * @param aFlags Flags of the FLAG_* variety
262 [noscript, notxpcom] TempRefSourceSurface getFrameAtSize([const] in nsIntSize aSize,
263 in uint32_t aWhichFrame,
264 in uint32_t aFlags);
267 * Returns true if this image will draw opaquely right now if asked to draw
268 * with FLAG_HIGH_QUALITY_SCALING and otherwise default flags. If this image
269 * (when decoded) is opaque but no decoded frames are available then
270 * willDrawOpaqueNow will return false.
272 [noscript, notxpcom] boolean willDrawOpaqueNow();
275 * @return true if getImageContainer() is expected to return a valid
276 * ImageContainer when passed the given @Manager and @Flags
277 * parameters.
279 [noscript, notxpcom] boolean isImageContainerAvailable(in LayerManager aManager,
280 in uint32_t aFlags);
282 * Attempts to create an ImageContainer (and Image) containing the current
283 * frame at its native size.
285 * Avoid calling this unless you're actually going to layerize this image.
287 * @param aManager The LayerManager which will be used to create the
288 * ImageContainer.
289 * @param aFlags Decoding / drawing flags (in other words, FLAG_* flags).
290 * Currently only FLAG_SYNC_DECODE and FLAG_SYNC_DECODE_IF_FAST
291 * are supported.
292 * @return An ImageContainer for the current frame, or nullptr if one could
293 * not be created.
295 [noscript, notxpcom] TempRefImageContainer getImageContainer(in LayerManager aManager,
296 in uint32_t aFlags);
299 * @return true if getImageContainer() is expected to return a valid
300 * ImageContainer when passed the given @Manager, @Size and @Flags
301 * parameters.
303 [noscript, notxpcom] boolean isImageContainerAvailableAtSize(in LayerManager aManager,
304 [const] in nsIntSize aSize,
305 in uint32_t aFlags);
308 * Attempts to create an ImageContainer (and Image) containing the current
309 * frame at the given size. Match the requested size is best effort; it's
310 * not guaranteed that the surface you get will be a perfect match. (Some
311 * reasons you may get a surface of a different size include: if you
312 * requested upscaling, or if downscale-during-decode is disabled.)
314 * Avoid calling this unless you're actually going to layerize this image.
316 * @param aManager The LayerManager which will be used to create the
317 * ImageContainer.
318 * @param aSVGContext If specified, SVG-related rendering context, such as
319 * overridden attributes on the image document's root <svg>
320 * node, and the size of the viewport that the full image
321 * would occupy. Ignored for raster images.
322 * @param aFlags Decoding / drawing flags (in other words, FLAG_* flags).
323 * Currently only FLAG_SYNC_DECODE and FLAG_SYNC_DECODE_IF_FAST
324 * are supported.
325 * @return An ImageContainer for the current frame, or nullptr if one could
326 * not be created.
328 [noscript, notxpcom] TempRefImageContainer getImageContainerAtSize(in LayerManager aManager,
329 [const] in nsIntSize aSize,
330 [const] in MaybeSVGImageContext aSVGContext,
331 in uint32_t aFlags);
334 * Draw the requested frame of this image onto the context specified.
336 * Drawing an image involves scaling it to a certain size (which may be
337 * implemented as a "smart" scale by substituting an HQ-scaled frame or
338 * rendering at a high DPI), and then selecting a region of that image to
339 * draw. That region is drawn onto the graphics context and in the process
340 * transformed by the context matrix, which determines the final area that is
341 * filled. The basic process looks like this:
343 * +------------------+
344 * | Image |
345 * | |
346 * | intrinsic width |
347 * | X |
348 * | intrinsic height |
349 * +------------------+
350 * / \
351 * / \
352 * / (scale to aSize) \
353 * / \
354 * +----------------------------+
355 * | |
356 * | Scaled Image |
357 * | aSize.width X aSize.height |
358 * | |
359 * | +---------+ |
360 * | | aRegion | |
361 * | +---------+ |
362 * +-------(---------(----------+
363 * | |
364 * / \
365 * | (transform |
366 * / by aContext \
367 * | matrix) |
368 * / \
369 * +---------------------+
370 * | |
371 * | Fill Rect |
372 * | |
373 * +---------------------+
375 * The region may extend outside of the scaled image's boundaries. It's
376 * actually a region in tiled image space, which is formed by tiling the
377 * scaled image infinitely in every direction. Drawing with a region larger
378 * than the scaled image thus causes the filled area to contain multiple tiled
379 * copies of the image, which looks like this:
381 * ....................................................
382 * : : : :
383 * : Tile : Tile : Tile :
384 * : +------------[aRegion]------------+ :
385 * :........|.......:................:........|.......:
386 * : | : : | :
387 * : Ti|le : Scaled Image : Ti|le :
388 * : | : : | :
389 * :........|.......:................:........|.......:
390 * : +---------------------------------+ :
391 * : Ti|le : Tile : Ti|le :
392 * : / : : \ :
393 * :......(.........:................:..........).....:
394 * | |
395 * / \
396 * | (transform by aContext matrix) |
397 * / \
398 * +---------------------------------------------+
399 * | : : |
400 * |.....:.................................:.....|
401 * | : : |
402 * | : Tiled Fill : |
403 * | : : |
404 * |.....:.................................:.....|
405 * | : : |
406 * +---------------------------------------------+
409 * @param aContext The Thebes context to draw the image to.
410 * @param aSize The size to which the image should be scaled before drawing.
411 * This requirement may be satisfied using HQ scaled frames,
412 * selecting from different resolution layers, drawing at a
413 * higher DPI, or just performing additional scaling on the
414 * graphics context. Callers can use optimalImageSizeForDest()
415 * to determine the best choice for this parameter if they have
416 * no special size requirements.
417 * @param aRegion The region in tiled image space which will be drawn onto the
418 * graphics context. aRegion is in the coordinate space of the
419 * image after it has been scaled to aSize - that is, the image
420 * is scaled first, and then aRegion is applied. When aFlags
421 * includes FLAG_CLAMP, the image will be extended to this area
422 * by clamping image sample coordinates. Otherwise, the image
423 * will be automatically tiled as necessary. aRegion can also
424 * optionally contain a second region which restricts the set
425 * of pixels we're allowed to sample from when drawing; this
426 * is only of use to callers which need to draw with pixel
427 * snapping.
428 * @param aWhichFrame Frame specifier of the FRAME_* variety.
429 * @param aSamplingFilter The filter to be used if we're scaling the image.
430 * @param aSVGContext If specified, SVG-related rendering context, such as
431 * overridden attributes on the image document's root <svg>
432 * node, and the size of the viewport that the full image
433 * would occupy. Ignored for raster images.
434 * @param aFlags Flags of the FLAG_* variety
435 * @return A ImgDrawResult value indicating whether and to what degree the
436 * drawing operation was successful.
438 [noscript, notxpcom] ImgDrawResult
439 draw(in gfxContext aContext,
440 [const] in nsIntSize aSize,
441 [const] in ImageRegion aRegion,
442 in uint32_t aWhichFrame,
443 in SamplingFilter aSamplingFilter,
444 [const] in MaybeSVGImageContext aSVGContext,
445 in uint32_t aFlags,
446 in float aOpacity);
449 * Ensures that an image is decoding. Calling this function guarantees that
450 * the image will at some point fire off decode notifications. Images that
451 * can be decoded "quickly" according to some heuristic will be decoded
452 * synchronously.
454 * @param aFlags Flags of the FLAG_* variety. Only FLAG_ASYNC_NOTIFY
455 * is accepted; all others are ignored.
457 [noscript] void startDecoding(in uint32_t aFlags);
460 * Exactly like startDecoding above except returns whether the current frame
461 * of the image is complete or not.
463 * @param aFlags Flags of the FLAG_* variety. Only FLAG_ASYNC_NOTIFY
464 * is accepted; all others are ignored.
466 [noscript, notxpcom] boolean startDecodingWithResult(in uint32_t aFlags);
469 * This method triggers decoding for an image, but unlike startDecoding() it
470 * enables the caller to provide more detailed information about the decode
471 * request.
473 * @param aSize The size to which the image should be scaled while decoding,
474 * if possible. If the image cannot be scaled to this size while
475 * being decoded, it will be decoded at its intrinsic size.
476 * @param aFlags Flags of the FLAG_* variety. Only the decode flags
477 * (FLAG_DECODE_*) and FLAG_SYNC_DECODE (which will
478 * synchronously decode images that can be decoded "quickly",
479 * just like startDecoding() does) are accepted; others will be
480 * ignored.
482 [noscript] void requestDecodeForSize([const] in nsIntSize aSize,
483 in uint32_t aFlags);
486 * Increments the lock count on the image. An image will not be discarded
487 * as long as the lock count is nonzero. Note that it is still possible for
488 * the image to be undecoded if decode-on-draw is enabled and the image
489 * was never drawn.
491 * Upon instantiation images have a lock count of zero.
493 void lockImage();
496 * Decreases the lock count on the image. If the lock count drops to zero,
497 * the image is allowed to discard its frame data to save memory.
499 * Upon instantiation images have a lock count of zero. It is an error to
500 * call this method without first having made a matching lockImage() call.
501 * In other words, the lock count is not allowed to be negative.
503 void unlockImage();
506 * If this image is unlocked, discard its decoded data. If the image is
507 * locked or has already been discarded, do nothing.
509 void requestDiscard();
512 * Indicates that this imgIContainer has been triggered to update
513 * its internal animation state. Likely this should only be called
514 * from within nsImageFrame or objects of similar type.
516 [notxpcom] void requestRefresh([const] in TimeStamp aTime);
519 * Animation mode Constants
520 * 0 = normal
521 * 1 = don't animate
522 * 2 = loop once
524 const short kNormalAnimMode = 0;
525 const short kDontAnimMode = 1;
526 const short kLoopOnceAnimMode = 2;
528 attribute unsigned short animationMode;
530 /* Methods to control animation */
531 void resetAnimation();
534 * Returns an index for the requested animation frame (either FRAME_FIRST or
535 * FRAME_CURRENT).
537 * The units of the index aren't specified, and may vary between different
538 * types of images. What you can rely on is that on all occasions when
539 * getFrameIndex(FRAME_CURRENT) returns a certain value,
540 * draw(..FRAME_CURRENT..) will draw the same frame. The same holds for
541 * FRAME_FIRST as well.
543 * @param aWhichFrame Frame specifier of the FRAME_* variety.
545 [notxpcom] float getFrameIndex(in uint32_t aWhichFrame);
548 * Returns the inherent orientation of the image, as described in the image's
549 * metadata (e.g. EXIF).
551 [notxpcom] Orientation getOrientation();
554 * Returns the delay, in ms, between the first and second frame. If this
555 * returns 0, there is no delay between first and second frame (i.e., this
556 * image could render differently whenever it draws).
558 * If this image is not animated, or not known to be animated (see attribute
559 * animated), returns -1.
561 [notxpcom] int32_t getFirstFrameDelay();
564 * If this is an animated image that hasn't started animating already, this
565 * sets the animation's start time to the indicated time.
567 * This has no effect if the image isn't animated or it has started animating
568 * already; it also has no effect if the image format doesn't care about
569 * animation start time.
571 * In all cases, animation does not actually begin until startAnimation(),
572 * resetAnimation(), or requestRefresh() is called for the first time.
574 [notxpcom] void setAnimationStartTime([const] in TimeStamp aTime);
577 * Given an invalidation rect in the coordinate system used by the decoder,
578 * returns an invalidation rect in image space.
580 * This is the identity transformation in most cases, but the result can
581 * differ if the image is wrapped by an ImageWrapper that changes its size
582 * or orientation.
584 [notxpcom] nsIntRectByVal
585 getImageSpaceInvalidationRect([const] in nsIntRect aRect);
588 * Removes any ImageWrappers and returns the unwrapped base image.
590 [notxpcom, nostdcall] TempRefImgIContainer unwrap();
593 * Propagate the use counters (if any) from this container to the passed in
594 * document.
596 [noscript, notxpcom] void propagateUseCounters(in nsIDocument aDocument);
598 %{C++
600 * Get the set of sizes the image can decode to natively.
602 virtual nsresult GetNativeSizes(nsTArray<nsIntSize>& aNativeSizes) const = 0;
604 virtual size_t GetNativeSizesLength() const = 0;