Bug 1567650 [wpt PR 17950] - [ElementTiming] Replace responseEnd with loadTime, a...
[gecko.git] / image / ClippedImage.h
blobd2d8683ee142457d97db05042db590c59203d26e
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 {
29 typedef gfx::SourceSurface SourceSurface;
31 public:
32 NS_INLINE_DECL_REFCOUNTING_INHERITED(ClippedImage, ImageWrapper)
34 NS_IMETHOD GetWidth(int32_t* aWidth) override;
35 NS_IMETHOD GetHeight(int32_t* aHeight) override;
36 NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
37 Maybe<AspectRatio> GetIntrinsicRatio() override;
38 NS_IMETHOD_(already_AddRefed<SourceSurface>)
39 GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
40 NS_IMETHOD_(already_AddRefed<SourceSurface>)
41 GetFrameAtSize(const gfx::IntSize& aSize, uint32_t aWhichFrame,
42 uint32_t aFlags) override;
43 NS_IMETHOD_(bool)
44 IsImageContainerAvailable(layers::LayerManager* aManager,
45 uint32_t aFlags) override;
46 NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
47 GetImageContainer(layers::LayerManager* aManager, uint32_t aFlags) override;
48 NS_IMETHOD_(bool)
49 IsImageContainerAvailableAtSize(layers::LayerManager* aManager,
50 const gfx::IntSize& aSize,
51 uint32_t aFlags) override;
52 NS_IMETHOD_(ImgDrawResult)
53 GetImageContainerAtSize(layers::LayerManager* aManager,
54 const gfx::IntSize& aSize,
55 const Maybe<SVGImageContext>& aSVGContext,
56 uint32_t aFlags,
57 layers::ImageContainer** aOutContainer) override;
58 NS_IMETHOD_(ImgDrawResult)
59 Draw(gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion,
60 uint32_t aWhichFrame, gfx::SamplingFilter aSamplingFilter,
61 const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
62 float aOpacity) override;
63 NS_IMETHOD RequestDiscard() override;
64 NS_IMETHOD_(Orientation) GetOrientation() override;
65 NS_IMETHOD_(nsIntRect)
66 GetImageSpaceInvalidationRect(const nsIntRect& aRect) override;
67 nsIntSize OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame,
68 gfx::SamplingFilter aSamplingFilter,
69 uint32_t aFlags) override;
71 protected:
72 ClippedImage(Image* aImage, nsIntRect aClip,
73 const Maybe<nsSize>& aSVGViewportSize);
75 virtual ~ClippedImage();
77 private:
78 Pair<ImgDrawResult, RefPtr<SourceSurface>> GetFrameInternal(
79 const nsIntSize& aSize, const Maybe<SVGImageContext>& aSVGContext,
80 uint32_t aWhichFrame, uint32_t aFlags, float aOpacity);
81 bool ShouldClip();
82 ImgDrawResult DrawSingleTile(gfxContext* aContext, const nsIntSize& aSize,
83 const ImageRegion& aRegion, uint32_t aWhichFrame,
84 gfx::SamplingFilter aSamplingFilter,
85 const Maybe<SVGImageContext>& aSVGContext,
86 uint32_t aFlags, float aOpacity);
88 // If we are forced to draw a temporary surface, we cache it here.
89 UniquePtr<ClippedImageCachedSurface> mCachedSurface;
91 nsIntRect mClip; // The region to clip to.
92 Maybe<bool> mShouldClip; // Memoized ShouldClip() if present.
93 Maybe<nsIntSize> mSVGViewportSize; // If we're clipping a VectorImage, this
94 // is the size of viewport of that image.
95 friend class DrawSingleTileCallback;
96 friend class ImageOps;
99 } // namespace image
100 } // namespace mozilla
102 #endif // mozilla_image_ClippedImage_h