Bug 1827705 - Add application version, and name to Talos performance data. r=perftest...
[gecko.git] / image / ClippedImage.h
blob43295a53f6bbfe353ba395a1c70c43b194af0ef4
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 #include <utility>
17 namespace mozilla {
18 namespace image {
20 class ClippedImageCachedSurface;
21 class DrawSingleTileCallback;
23 /**
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;
33 public:
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;
45 NS_IMETHOD_(bool)
46 IsImageContainerAvailable(WindowRenderer* aRenderer,
47 uint32_t aFlags) override;
48 NS_IMETHOD_(ImgDrawResult)
49 GetImageProvider(WindowRenderer* aRenderer, const gfx::IntSize& aSize,
50 const SVGImageContext& aSVGContext,
51 const Maybe<ImageIntRegion>& aRegion, uint32_t aFlags,
52 WebRenderImageProvider** aProvider) override;
53 NS_IMETHOD_(ImgDrawResult)
54 Draw(gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion,
55 uint32_t aWhichFrame, gfx::SamplingFilter aSamplingFilter,
56 const SVGImageContext& aSVGContext, uint32_t aFlags,
57 float aOpacity) override;
58 NS_IMETHOD RequestDiscard() override;
59 NS_IMETHOD_(Orientation) GetOrientation() override;
60 NS_IMETHOD_(nsIntRect)
61 GetImageSpaceInvalidationRect(const nsIntRect& aRect) override;
62 nsIntSize OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame,
63 gfx::SamplingFilter aSamplingFilter,
64 uint32_t aFlags) override;
66 protected:
67 ClippedImage(Image* aImage, nsIntRect aClip,
68 const Maybe<nsSize>& aSVGViewportSize);
70 virtual ~ClippedImage();
72 private:
73 std::pair<ImgDrawResult, RefPtr<SourceSurface>> GetFrameInternal(
74 const nsIntSize& aSize, const SVGImageContext& aSVGContext,
75 const Maybe<ImageIntRegion>& aRegion, uint32_t aWhichFrame,
76 uint32_t aFlags, float aOpacity);
77 bool ShouldClip();
78 ImgDrawResult DrawSingleTile(gfxContext* aContext, const nsIntSize& aSize,
79 const ImageRegion& aRegion, uint32_t aWhichFrame,
80 gfx::SamplingFilter aSamplingFilter,
81 const SVGImageContext& aSVGContext,
82 uint32_t aFlags, float aOpacity);
84 // If we are forced to draw a temporary surface, we cache it here.
85 UniquePtr<ClippedImageCachedSurface> mCachedSurface;
87 nsIntRect mClip; // The region to clip to.
88 Maybe<bool> mShouldClip; // Memoized ShouldClip() if present.
89 Maybe<nsIntSize> mSVGViewportSize; // If we're clipping a VectorImage, this
90 // is the size of viewport of that image.
91 friend class DrawSingleTileCallback;
92 friend class ImageOps;
95 } // namespace image
96 } // namespace mozilla
98 #endif // mozilla_image_ClippedImage_h