2013-04-06 01:14:32 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#ifndef mozilla_image_ClippedImage_h
|
|
|
|
#define mozilla_image_ClippedImage_h
|
2013-04-06 01:14:32 +04:00
|
|
|
|
|
|
|
#include "ImageWrapper.h"
|
2014-04-15 22:02:23 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-08-28 02:10:28 +04:00
|
|
|
#include "mozilla/Maybe.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-10-17 13:53:28 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2013-04-06 01:14:32 +04:00
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2013-04-06 01:14:32 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
|
2013-04-26 02:58:32 +04:00
|
|
|
class ClippedImageCachedSurface;
|
2013-04-06 01:14:32 +04:00
|
|
|
class DrawSingleTileCallback;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An Image wrapper that clips an image against a rectangle. Right now only
|
|
|
|
* absolute coordinates in pixels are supported.
|
|
|
|
*
|
|
|
|
* XXX(seth): There a known (performance, not correctness) issue with
|
|
|
|
* GetImageContainer. See the comments for that method for more information.
|
|
|
|
*/
|
|
|
|
class ClippedImage : public ImageWrapper {
|
2014-07-10 19:00:31 +04:00
|
|
|
typedef gfx::SourceSurface SourceSurface;
|
2014-04-15 22:02:23 +04:00
|
|
|
|
2013-04-06 01:14:32 +04:00
|
|
|
public:
|
2018-02-12 23:44:40 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(ClippedImage, ImageWrapper)
|
2013-04-06 01:14:32 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD GetWidth(int32_t* aWidth) override;
|
|
|
|
NS_IMETHOD GetHeight(int32_t* aHeight) override;
|
|
|
|
NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
|
2019-05-03 02:28:21 +03:00
|
|
|
Maybe<AspectRatio> GetIntrinsicRatio() override;
|
2015-06-17 17:00:52 +03:00
|
|
|
NS_IMETHOD_(already_AddRefed<SourceSurface>)
|
2015-03-21 19:28:04 +03:00
|
|
|
GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
|
2015-09-19 23:34:09 +03:00
|
|
|
NS_IMETHOD_(already_AddRefed<SourceSurface>)
|
|
|
|
GetFrameAtSize(const gfx::IntSize& aSize, uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags) override;
|
2015-05-13 10:23:44 +03:00
|
|
|
NS_IMETHOD_(bool)
|
|
|
|
IsImageContainerAvailable(layers::LayerManager* aManager,
|
|
|
|
uint32_t aFlags) override;
|
2015-03-18 05:40:16 +03:00
|
|
|
NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
|
|
|
|
GetImageContainer(layers::LayerManager* aManager, uint32_t aFlags) override;
|
2017-11-17 14:45:26 +03:00
|
|
|
NS_IMETHOD_(bool)
|
|
|
|
IsImageContainerAvailableAtSize(layers::LayerManager* aManager,
|
|
|
|
const gfx::IntSize& aSize,
|
|
|
|
uint32_t aFlags) override;
|
2018-09-14 02:48:21 +03:00
|
|
|
NS_IMETHOD_(ImgDrawResult)
|
2017-11-17 14:45:26 +03:00
|
|
|
GetImageContainerAtSize(layers::LayerManager* aManager,
|
|
|
|
const gfx::IntSize& aSize,
|
2017-11-17 22:08:52 +03:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2018-09-14 02:48:21 +03:00
|
|
|
uint32_t aFlags,
|
|
|
|
layers::ImageContainer** aOutContainer) override;
|
2017-12-11 18:37:59 +03:00
|
|
|
NS_IMETHOD_(ImgDrawResult)
|
2015-02-05 00:50:56 +03:00
|
|
|
Draw(gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion,
|
2016-05-25 19:01:18 +03:00
|
|
|
uint32_t aWhichFrame, gfx::SamplingFilter aSamplingFilter,
|
2015-02-05 00:50:56 +03:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
|
2017-01-03 08:53:22 +03:00
|
|
|
float aOpacity) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD RequestDiscard() override;
|
|
|
|
NS_IMETHOD_(Orientation) GetOrientation() override;
|
2015-04-04 22:57:00 +03:00
|
|
|
NS_IMETHOD_(nsIntRect)
|
|
|
|
GetImageSpaceInvalidationRect(const nsIntRect& aRect) override;
|
2014-07-29 01:27:40 +04:00
|
|
|
nsIntSize OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame,
|
2016-05-25 19:01:18 +03:00
|
|
|
gfx::SamplingFilter aSamplingFilter,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aFlags) override;
|
2013-04-06 01:14:32 +04:00
|
|
|
|
|
|
|
protected:
|
2016-03-08 10:54:13 +03:00
|
|
|
ClippedImage(Image* aImage, nsIntRect aClip,
|
|
|
|
const Maybe<nsSize>& aSVGViewportSize);
|
2013-04-06 01:14:32 +04:00
|
|
|
|
2014-06-23 22:49:08 +04:00
|
|
|
virtual ~ClippedImage();
|
|
|
|
|
2013-04-06 01:14:32 +04:00
|
|
|
private:
|
2020-03-17 15:42:12 +03:00
|
|
|
std::pair<ImgDrawResult, RefPtr<SourceSurface>> GetFrameInternal(
|
2014-08-23 00:12:38 +04:00
|
|
|
const nsIntSize& aSize, const Maybe<SVGImageContext>& aSVGContext,
|
2014-04-15 22:02:23 +04:00
|
|
|
uint32_t aWhichFrame, uint32_t aFlags, float aOpacity);
|
2013-04-06 01:14:32 +04:00
|
|
|
bool ShouldClip();
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult DrawSingleTile(gfxContext* aContext, const nsIntSize& aSize,
|
2015-02-05 00:50:56 +03:00
|
|
|
const ImageRegion& aRegion, uint32_t aWhichFrame,
|
2016-05-25 19:01:18 +03:00
|
|
|
gfx::SamplingFilter aSamplingFilter,
|
2015-02-05 00:50:56 +03:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2017-01-03 08:53:22 +03:00
|
|
|
uint32_t aFlags, float aOpacity);
|
2013-04-06 01:14:32 +04:00
|
|
|
|
2013-04-26 02:58:32 +04:00
|
|
|
// If we are forced to draw a temporary surface, we cache it here.
|
2015-10-17 13:53:28 +03:00
|
|
|
UniquePtr<ClippedImageCachedSurface> mCachedSurface;
|
2013-04-26 02:58:32 +04:00
|
|
|
|
2016-03-08 10:54:13 +03:00
|
|
|
nsIntRect mClip; // The region to clip to.
|
|
|
|
Maybe<bool> mShouldClip; // Memoized ShouldClip() if present.
|
|
|
|
Maybe<nsIntSize> mSVGViewportSize; // If we're clipping a VectorImage, this
|
|
|
|
// is the size of viewport of that image.
|
2013-04-06 01:14:32 +04:00
|
|
|
friend class DrawSingleTileCallback;
|
2013-04-06 01:14:34 +04:00
|
|
|
friend class ImageOps;
|
2013-04-06 01:14:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif // mozilla_image_ClippedImage_h
|