Bug 1708243 - Part 2: stop using sender data from the child process r=robwu,agi
[gecko.git] / image / OrientedImage.h
blobd59430687e642fe49f0b949950be7d41d580a966
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 #ifndef mozilla_image_OrientedImage_h
7 #define mozilla_image_OrientedImage_h
9 #include "ImageWrapper.h"
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/RefPtr.h"
12 #include "Orientation.h"
14 namespace mozilla {
15 namespace image {
17 /**
18 * An Image wrapper that rotates and/or flips an image according to a specified
19 * Orientation.
21 * XXX(seth): There a known (performance, not correctness) issue with
22 * GetImageContainer. See the comments for that method for more information.
24 class OrientedImage : public ImageWrapper {
25 typedef gfx::SourceSurface SourceSurface;
27 public:
28 NS_INLINE_DECL_REFCOUNTING_INHERITED(OrientedImage, ImageWrapper)
30 NS_IMETHOD GetWidth(int32_t* aWidth) override;
31 NS_IMETHOD GetHeight(int32_t* aHeight) override;
32 nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) const override;
33 NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
34 Maybe<AspectRatio> GetIntrinsicRatio() override;
35 NS_IMETHOD_(already_AddRefed<SourceSurface>)
36 GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
37 NS_IMETHOD_(already_AddRefed<SourceSurface>)
38 GetFrameAtSize(const gfx::IntSize& aSize, uint32_t aWhichFrame,
39 uint32_t aFlags) override;
40 NS_IMETHOD_(bool)
41 IsImageContainerAvailable(layers::LayerManager* aManager,
42 uint32_t aFlags) override;
43 NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
44 GetImageContainer(WindowRenderer* aRenderer, uint32_t aFlags) override;
45 NS_IMETHOD_(bool)
46 IsImageContainerAvailableAtSize(layers::LayerManager* aManager,
47 const gfx::IntSize& aSize,
48 uint32_t aFlags) override;
49 NS_IMETHOD_(ImgDrawResult)
50 GetImageContainerAtSize(WindowRenderer* aRenderer, const gfx::IntSize& aSize,
51 const Maybe<SVGImageContext>& aSVGContext,
52 const Maybe<ImageIntRegion>& aRegion, uint32_t aFlags,
53 layers::ImageContainer** aOutContainer) override;
54 NS_IMETHOD_(ImgDrawResult)
55 Draw(gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion,
56 uint32_t aWhichFrame, gfx::SamplingFilter aSamplingFilter,
57 const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
58 float aOpacity) override;
59 NS_IMETHOD_(nsIntRect)
60 GetImageSpaceInvalidationRect(const nsIntRect& aRect) override;
61 nsIntSize OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame,
62 gfx::SamplingFilter aSamplingFilter,
63 uint32_t aFlags) override;
65 /**
66 * Computes a matrix that applies the rotation and reflection specified by
67 * aOrientation, or that matrix's inverse if aInvert is true.
69 * @param aSize The scaled size of the inner image. (When outside code
70 * specifies the scaled size, as with imgIContainer::Draw and its aSize
71 * parameter, it's necessary to swap the width and height if
72 * mOrientation.SwapsWidthAndHeight() is true.)
74 * @param aInvert If true, compute the inverse of the orientation matrix.
75 * Prefer this approach to OrientationMatrix(..).Invert(), because it's more
76 * numerically accurate.
78 static gfxMatrix OrientationMatrix(Orientation aOrientation,
79 const nsIntSize& aSize,
80 bool aInvert = false);
82 /**
83 * Returns a SourceSurface that is the result of rotating and flipping
84 * aSurface according to aOrientation.
86 static already_AddRefed<SourceSurface> OrientSurface(Orientation aOrientation,
87 SourceSurface* aSurface);
89 protected:
90 OrientedImage(Image* aImage, Orientation aOrientation)
91 : ImageWrapper(aImage), mOrientation(aOrientation) {}
93 virtual ~OrientedImage() {}
95 gfxMatrix OrientationMatrix(const nsIntSize& aSize, bool aInvert = false) {
96 return OrientationMatrix(mOrientation, aSize, aInvert);
99 private:
100 Orientation mOrientation;
102 friend class ImageOps;
105 } // namespace image
106 } // namespace mozilla
108 #endif // mozilla_image_OrientedImage_h