michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_ michael@0: #define MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_ michael@0: michael@0: #include "ImageWrapper.h" michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "mozilla/Maybe.h" michael@0: #include "mozilla/RefPtr.h" michael@0: michael@0: namespace mozilla { michael@0: namespace image { michael@0: michael@0: class ClippedImageCachedSurface; michael@0: class DrawSingleTileCallback; michael@0: michael@0: /** michael@0: * An Image wrapper that clips an image against a rectangle. Right now only michael@0: * absolute coordinates in pixels are supported. michael@0: * michael@0: * XXX(seth): There a known (performance, not correctness) issue with michael@0: * GetImageContainer. See the comments for that method for more information. michael@0: */ michael@0: class ClippedImage : public ImageWrapper michael@0: { michael@0: typedef mozilla::gfx::SourceSurface SourceSurface; michael@0: michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: virtual ~ClippedImage(); michael@0: michael@0: virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD GetWidth(int32_t* aWidth) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetHeight(int32_t* aHeight) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetIntrinsicSize(nsSize* aSize) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) MOZ_OVERRIDE; michael@0: NS_IMETHOD_(mozilla::TemporaryRef) michael@0: GetFrame(uint32_t aWhichFrame, uint32_t aFlags) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetImageContainer(mozilla::layers::LayerManager* aManager, michael@0: mozilla::layers::ImageContainer** _retval) MOZ_OVERRIDE; michael@0: NS_IMETHOD Draw(gfxContext* aContext, michael@0: GraphicsFilter aFilter, michael@0: const gfxMatrix& aUserSpaceToImageSpace, michael@0: const gfxRect& aFill, michael@0: const nsIntRect& aSubimage, michael@0: const nsIntSize& aViewportSize, michael@0: const SVGImageContext* aSVGContext, michael@0: uint32_t aWhichFrame, michael@0: uint32_t aFlags) MOZ_OVERRIDE; michael@0: NS_IMETHOD RequestDiscard() MOZ_OVERRIDE; michael@0: NS_IMETHOD_(Orientation) GetOrientation() MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: ClippedImage(Image* aImage, nsIntRect aClip); michael@0: michael@0: private: michael@0: mozilla::TemporaryRef michael@0: GetFrameInternal(const nsIntSize& aViewportSize, michael@0: const SVGImageContext* aSVGContext, michael@0: uint32_t aWhichFrame, michael@0: uint32_t aFlags); michael@0: bool ShouldClip(); michael@0: bool MustCreateSurface(gfxContext* aContext, michael@0: const gfxMatrix& aTransform, michael@0: const gfxRect& aSourceRect, michael@0: const nsIntRect& aSubimage, michael@0: const uint32_t aFlags) const; michael@0: gfxFloat ClampFactor(const gfxFloat aToClamp, const int aReference) const; michael@0: nsresult DrawSingleTile(gfxContext* aContext, michael@0: GraphicsFilter aFilter, michael@0: const gfxMatrix& aUserSpaceToImageSpace, michael@0: const gfxRect& aFill, michael@0: const nsIntRect& aSubimage, michael@0: const nsIntSize& aViewportSize, michael@0: const SVGImageContext* aSVGContext, michael@0: uint32_t aWhichFrame, michael@0: uint32_t aFlags); michael@0: michael@0: // If we are forced to draw a temporary surface, we cache it here. michael@0: nsAutoPtr mCachedSurface; michael@0: michael@0: nsIntRect mClip; // The region to clip to. michael@0: Maybe mShouldClip; // Memoized ShouldClip() if present. michael@0: michael@0: friend class DrawSingleTileCallback; michael@0: friend class ImageOps; michael@0: }; michael@0: michael@0: } // namespace image michael@0: } // namespace mozilla michael@0: michael@0: #endif // MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_