Bug 1454184 [wpt PR 10474] - [Resource Timing] Align TAO parsing to spec, a=testonly
[gecko.git] / image / ClippedImage.h
blob53d2dbfd58d698b68bddd44a4ea4020cc2d149ea
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"
15 namespace mozilla {
16 namespace image {
18 class ClippedImageCachedSurface;
19 class DrawSingleTileCallback;
21 /**
22 * An Image wrapper that clips an image against a rectangle. Right now only
23 * absolute coordinates in pixels are supported.
25 * XXX(seth): There a known (performance, not correctness) issue with
26 * GetImageContainer. See the comments for that method for more information.
28 class ClippedImage : public ImageWrapper
30 typedef gfx::SourceSurface SourceSurface;
32 public:
33 NS_INLINE_DECL_REFCOUNTING_INHERITED(ClippedImage, ImageWrapper)
35 NS_IMETHOD GetWidth(int32_t* aWidth) override;
36 NS_IMETHOD GetHeight(int32_t* aHeight) override;
37 NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
38 NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) override;
39 NS_IMETHOD_(already_AddRefed<SourceSurface>)
40 GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
41 NS_IMETHOD_(already_AddRefed<SourceSurface>)
42 GetFrameAtSize(const gfx::IntSize& aSize,
43 uint32_t aWhichFrame,
44 uint32_t aFlags) override;
45 NS_IMETHOD_(bool) IsImageContainerAvailable(layers::LayerManager* aManager,
46 uint32_t aFlags) override;
47 NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
48 GetImageContainer(layers::LayerManager* aManager,
49 uint32_t aFlags) override;
50 NS_IMETHOD_(bool)
51 IsImageContainerAvailableAtSize(layers::LayerManager* aManager,
52 const gfx::IntSize& aSize,
53 uint32_t aFlags) override;
54 NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
55 GetImageContainerAtSize(layers::LayerManager* aManager,
56 const gfx::IntSize& aSize,
57 const Maybe<SVGImageContext>& aSVGContext,
58 uint32_t aFlags) override;
59 NS_IMETHOD_(ImgDrawResult) Draw(gfxContext* aContext,
60 const nsIntSize& aSize,
61 const ImageRegion& aRegion,
62 uint32_t aWhichFrame,
63 gfx::SamplingFilter aSamplingFilter,
64 const Maybe<SVGImageContext>& aSVGContext,
65 uint32_t aFlags,
66 float aOpacity) override;
67 NS_IMETHOD RequestDiscard() override;
68 NS_IMETHOD_(Orientation) GetOrientation() override;
69 NS_IMETHOD_(nsIntRect) GetImageSpaceInvalidationRect(const nsIntRect& aRect)
70 override;
71 nsIntSize OptimalImageSizeForDest(const gfxSize& aDest,
72 uint32_t aWhichFrame,
73 gfx::SamplingFilter aSamplingFilter,
74 uint32_t aFlags) override;
76 protected:
77 ClippedImage(Image* aImage, nsIntRect aClip,
78 const Maybe<nsSize>& aSVGViewportSize);
80 virtual ~ClippedImage();
82 private:
83 Pair<ImgDrawResult, RefPtr<SourceSurface>>
84 GetFrameInternal(const nsIntSize& aSize,
85 const Maybe<SVGImageContext>& aSVGContext,
86 uint32_t aWhichFrame,
87 uint32_t aFlags,
88 float aOpacity);
89 bool ShouldClip();
90 ImgDrawResult DrawSingleTile(gfxContext* aContext,
91 const nsIntSize& aSize,
92 const ImageRegion& aRegion,
93 uint32_t aWhichFrame,
94 gfx::SamplingFilter aSamplingFilter,
95 const Maybe<SVGImageContext>& aSVGContext,
96 uint32_t aFlags,
97 float aOpacity);
99 // If we are forced to draw a temporary surface, we cache it here.
100 UniquePtr<ClippedImageCachedSurface> mCachedSurface;
102 nsIntRect mClip; // The region to clip to.
103 Maybe<bool> mShouldClip; // Memoized ShouldClip() if present.
104 Maybe<nsIntSize> mSVGViewportSize; // If we're clipping a VectorImage, this
105 // is the size of viewport of that image.
106 friend class DrawSingleTileCallback;
107 friend class ImageOps;
110 } // namespace image
111 } // namespace mozilla
113 #endif // mozilla_image_ClippedImage_h