imgIContainer.idl 23 KB

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