2013-04-05 14:14:32 -07: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-14 20:52:05 -07:00
|
|
|
#ifndef mozilla_image_ClippedImage_h
|
|
|
|
#define mozilla_image_ClippedImage_h
|
2013-04-05 14:14:32 -07:00
|
|
|
|
|
|
|
#include "ImageWrapper.h"
|
2014-04-15 11:02:23 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-08-27 15:10:28 -07:00
|
|
|
#include "mozilla/Maybe.h"
|
2015-10-17 22:24:48 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
2013-04-05 14:14:32 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
|
2013-04-25 15:58:32 -07:00
|
|
|
class ClippedImageCachedSurface;
|
2013-04-05 14:14:32 -07: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 08:00:31 -07:00
|
|
|
typedef gfx::SourceSurface SourceSurface;
|
2014-04-15 11:02:23 -07:00
|
|
|
|
2013-04-05 14:14:32 -07:00
|
|
|
public:
|
2014-07-14 12:21:34 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2013-04-05 14:14:32 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD GetWidth(int32_t* aWidth) override;
|
|
|
|
NS_IMETHOD GetHeight(int32_t* aHeight) override;
|
|
|
|
NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
|
|
|
|
NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) override;
|
2015-06-17 07:00:52 -07:00
|
|
|
NS_IMETHOD_(already_AddRefed<SourceSurface>)
|
2015-03-21 09:28:04 -07:00
|
|
|
GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
|
2015-09-19 13:34:09 -07:00
|
|
|
NS_IMETHOD_(already_AddRefed<SourceSurface>)
|
|
|
|
GetFrameAtSize(const gfx::IntSize& aSize,
|
|
|
|
uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags) override;
|
2015-05-13 00:23:44 -07:00
|
|
|
NS_IMETHOD_(bool) IsImageContainerAvailable(layers::LayerManager* aManager,
|
|
|
|
uint32_t aFlags) override;
|
2015-03-17 19:40:16 -07:00
|
|
|
NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
|
|
|
|
GetImageContainer(layers::LayerManager* aManager,
|
2015-03-21 09:28:04 -07:00
|
|
|
uint32_t aFlags) override;
|
2015-02-04 13:50:56 -08:00
|
|
|
NS_IMETHOD_(DrawResult) Draw(gfxContext* aContext,
|
|
|
|
const nsIntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
|
|
|
uint32_t aWhichFrame,
|
2015-10-05 17:18:10 -07:00
|
|
|
gfx::Filter aFilter,
|
2015-02-04 13:50:56 -08:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2015-03-21 09:28:04 -07:00
|
|
|
uint32_t aFlags) override;
|
|
|
|
NS_IMETHOD RequestDiscard() override;
|
|
|
|
NS_IMETHOD_(Orientation) GetOrientation() override;
|
2015-04-04 12:57:00 -07:00
|
|
|
NS_IMETHOD_(nsIntRect) GetImageSpaceInvalidationRect(const nsIntRect& aRect)
|
|
|
|
override;
|
2014-07-28 14:27:40 -07:00
|
|
|
nsIntSize OptimalImageSizeForDest(const gfxSize& aDest,
|
|
|
|
uint32_t aWhichFrame,
|
2015-10-05 17:18:10 -07:00
|
|
|
gfx::Filter aFilter,
|
2015-03-21 09:28:04 -07:00
|
|
|
uint32_t aFlags) override;
|
2013-04-05 14:14:32 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ClippedImage(Image* aImage, nsIntRect aClip);
|
|
|
|
|
2014-06-23 11:49:08 -07:00
|
|
|
virtual ~ClippedImage();
|
|
|
|
|
2013-04-05 14:14:32 -07:00
|
|
|
private:
|
2015-10-17 22:24:48 -07:00
|
|
|
Pair<DrawResult, RefPtr<SourceSurface>>
|
2014-08-22 13:12:38 -07:00
|
|
|
GetFrameInternal(const nsIntSize& aSize,
|
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2014-04-15 11:02:23 -07:00
|
|
|
uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags);
|
2013-04-05 14:14:32 -07:00
|
|
|
bool ShouldClip();
|
2015-02-04 13:50:56 -08:00
|
|
|
DrawResult DrawSingleTile(gfxContext* aContext,
|
|
|
|
const nsIntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
|
|
|
uint32_t aWhichFrame,
|
2015-10-05 17:18:10 -07:00
|
|
|
gfx::Filter aFilter,
|
2015-02-04 13:50:56 -08:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
|
|
uint32_t aFlags);
|
2013-04-05 14:14:32 -07:00
|
|
|
|
2013-04-25 15:58:32 -07:00
|
|
|
// If we are forced to draw a temporary surface, we cache it here.
|
|
|
|
nsAutoPtr<ClippedImageCachedSurface> mCachedSurface;
|
|
|
|
|
2013-04-05 14:14:32 -07:00
|
|
|
nsIntRect mClip; // The region to clip to.
|
|
|
|
Maybe<bool> mShouldClip; // Memoized ShouldClip() if present.
|
|
|
|
|
|
|
|
friend class DrawSingleTileCallback;
|
2013-04-05 14:14:34 -07:00
|
|
|
friend class ImageOps;
|
2013-04-05 14:14:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-05-14 20:52:05 -07:00
|
|
|
#endif // mozilla_image_ClippedImage_h
|