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_ClippedImage_h
7 #define mozilla_image_ClippedImage_h
9 #include "ImageWrapper.h"
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/Maybe.h"
12 #include "mozilla/RefPtr.h"
13 #include "mozilla/UniquePtr.h"
20 class ClippedImageCachedSurface
;
21 class DrawSingleTileCallback
;
24 * An Image wrapper that clips an image against a rectangle. Right now only
25 * absolute coordinates in pixels are supported.
27 * XXX(seth): There a known (performance, not correctness) issue with
28 * GetImageContainer. See the comments for that method for more information.
30 class ClippedImage
: public ImageWrapper
{
31 typedef gfx::SourceSurface SourceSurface
;
34 NS_INLINE_DECL_REFCOUNTING_INHERITED(ClippedImage
, ImageWrapper
)
36 NS_IMETHOD
GetWidth(int32_t* aWidth
) override
;
37 NS_IMETHOD
GetHeight(int32_t* aHeight
) override
;
38 NS_IMETHOD
GetIntrinsicSize(nsSize
* aSize
) override
;
39 Maybe
<AspectRatio
> GetIntrinsicRatio() override
;
40 NS_IMETHOD_(already_AddRefed
<SourceSurface
>)
41 GetFrame(uint32_t aWhichFrame
, uint32_t aFlags
) override
;
42 NS_IMETHOD_(already_AddRefed
<SourceSurface
>)
43 GetFrameAtSize(const gfx::IntSize
& aSize
, uint32_t aWhichFrame
,
44 uint32_t aFlags
) override
;
46 IsImageContainerAvailable(layers::LayerManager
* aManager
,
47 uint32_t aFlags
) override
;
48 NS_IMETHOD_(already_AddRefed
<layers::ImageContainer
>)
49 GetImageContainer(WindowRenderer
* aRenderer
, uint32_t aFlags
) override
;
51 IsImageContainerAvailableAtSize(layers::LayerManager
* aManager
,
52 const gfx::IntSize
& aSize
,
53 uint32_t aFlags
) override
;
54 NS_IMETHOD_(ImgDrawResult
)
55 GetImageContainerAtSize(WindowRenderer
* aRenderer
, const gfx::IntSize
& aSize
,
56 const Maybe
<SVGImageContext
>& aSVGContext
,
57 const Maybe
<ImageIntRegion
>& aRegion
, uint32_t aFlags
,
58 layers::ImageContainer
** aOutContainer
) override
;
59 NS_IMETHOD_(ImgDrawResult
)
60 Draw(gfxContext
* aContext
, const nsIntSize
& aSize
, const ImageRegion
& aRegion
,
61 uint32_t aWhichFrame
, gfx::SamplingFilter aSamplingFilter
,
62 const Maybe
<SVGImageContext
>& aSVGContext
, uint32_t aFlags
,
63 float aOpacity
) override
;
64 NS_IMETHOD
RequestDiscard() override
;
65 NS_IMETHOD_(Orientation
) GetOrientation() override
;
66 NS_IMETHOD_(nsIntRect
)
67 GetImageSpaceInvalidationRect(const nsIntRect
& aRect
) override
;
68 nsIntSize
OptimalImageSizeForDest(const gfxSize
& aDest
, uint32_t aWhichFrame
,
69 gfx::SamplingFilter aSamplingFilter
,
70 uint32_t aFlags
) override
;
73 ClippedImage(Image
* aImage
, nsIntRect aClip
,
74 const Maybe
<nsSize
>& aSVGViewportSize
);
76 virtual ~ClippedImage();
79 std::pair
<ImgDrawResult
, RefPtr
<SourceSurface
>> GetFrameInternal(
80 const nsIntSize
& aSize
, const Maybe
<SVGImageContext
>& aSVGContext
,
81 const Maybe
<ImageIntRegion
>& aRegion
, uint32_t aWhichFrame
,
82 uint32_t aFlags
, float aOpacity
);
84 ImgDrawResult
DrawSingleTile(gfxContext
* aContext
, const nsIntSize
& aSize
,
85 const ImageRegion
& aRegion
, uint32_t aWhichFrame
,
86 gfx::SamplingFilter aSamplingFilter
,
87 const Maybe
<SVGImageContext
>& aSVGContext
,
88 uint32_t aFlags
, float aOpacity
);
90 // If we are forced to draw a temporary surface, we cache it here.
91 UniquePtr
<ClippedImageCachedSurface
> mCachedSurface
;
93 nsIntRect mClip
; // The region to clip to.
94 Maybe
<bool> mShouldClip
; // Memoized ShouldClip() if present.
95 Maybe
<nsIntSize
> mSVGViewportSize
; // If we're clipping a VectorImage, this
96 // is the size of viewport of that image.
97 friend class DrawSingleTileCallback
;
98 friend class ImageOps
;
102 } // namespace mozilla
104 #endif // mozilla_image_ClippedImage_h