Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_ |
michael@0 | 7 | #define MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "ImageWrapper.h" |
michael@0 | 10 | #include "mozilla/gfx/2D.h" |
michael@0 | 11 | #include "mozilla/Maybe.h" |
michael@0 | 12 | #include "mozilla/RefPtr.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | namespace image { |
michael@0 | 16 | |
michael@0 | 17 | class ClippedImageCachedSurface; |
michael@0 | 18 | class DrawSingleTileCallback; |
michael@0 | 19 | |
michael@0 | 20 | /** |
michael@0 | 21 | * An Image wrapper that clips an image against a rectangle. Right now only |
michael@0 | 22 | * absolute coordinates in pixels are supported. |
michael@0 | 23 | * |
michael@0 | 24 | * XXX(seth): There a known (performance, not correctness) issue with |
michael@0 | 25 | * GetImageContainer. See the comments for that method for more information. |
michael@0 | 26 | */ |
michael@0 | 27 | class ClippedImage : public ImageWrapper |
michael@0 | 28 | { |
michael@0 | 29 | typedef mozilla::gfx::SourceSurface SourceSurface; |
michael@0 | 30 | |
michael@0 | 31 | public: |
michael@0 | 32 | NS_DECL_ISUPPORTS |
michael@0 | 33 | |
michael@0 | 34 | virtual ~ClippedImage(); |
michael@0 | 35 | |
michael@0 | 36 | virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE; |
michael@0 | 37 | |
michael@0 | 38 | NS_IMETHOD GetWidth(int32_t* aWidth) MOZ_OVERRIDE; |
michael@0 | 39 | NS_IMETHOD GetHeight(int32_t* aHeight) MOZ_OVERRIDE; |
michael@0 | 40 | NS_IMETHOD GetIntrinsicSize(nsSize* aSize) MOZ_OVERRIDE; |
michael@0 | 41 | NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) MOZ_OVERRIDE; |
michael@0 | 42 | NS_IMETHOD_(mozilla::TemporaryRef<SourceSurface>) |
michael@0 | 43 | GetFrame(uint32_t aWhichFrame, uint32_t aFlags) MOZ_OVERRIDE; |
michael@0 | 44 | NS_IMETHOD GetImageContainer(mozilla::layers::LayerManager* aManager, |
michael@0 | 45 | mozilla::layers::ImageContainer** _retval) MOZ_OVERRIDE; |
michael@0 | 46 | NS_IMETHOD Draw(gfxContext* aContext, |
michael@0 | 47 | GraphicsFilter aFilter, |
michael@0 | 48 | const gfxMatrix& aUserSpaceToImageSpace, |
michael@0 | 49 | const gfxRect& aFill, |
michael@0 | 50 | const nsIntRect& aSubimage, |
michael@0 | 51 | const nsIntSize& aViewportSize, |
michael@0 | 52 | const SVGImageContext* aSVGContext, |
michael@0 | 53 | uint32_t aWhichFrame, |
michael@0 | 54 | uint32_t aFlags) MOZ_OVERRIDE; |
michael@0 | 55 | NS_IMETHOD RequestDiscard() MOZ_OVERRIDE; |
michael@0 | 56 | NS_IMETHOD_(Orientation) GetOrientation() MOZ_OVERRIDE; |
michael@0 | 57 | |
michael@0 | 58 | protected: |
michael@0 | 59 | ClippedImage(Image* aImage, nsIntRect aClip); |
michael@0 | 60 | |
michael@0 | 61 | private: |
michael@0 | 62 | mozilla::TemporaryRef<SourceSurface> |
michael@0 | 63 | GetFrameInternal(const nsIntSize& aViewportSize, |
michael@0 | 64 | const SVGImageContext* aSVGContext, |
michael@0 | 65 | uint32_t aWhichFrame, |
michael@0 | 66 | uint32_t aFlags); |
michael@0 | 67 | bool ShouldClip(); |
michael@0 | 68 | bool MustCreateSurface(gfxContext* aContext, |
michael@0 | 69 | const gfxMatrix& aTransform, |
michael@0 | 70 | const gfxRect& aSourceRect, |
michael@0 | 71 | const nsIntRect& aSubimage, |
michael@0 | 72 | const uint32_t aFlags) const; |
michael@0 | 73 | gfxFloat ClampFactor(const gfxFloat aToClamp, const int aReference) const; |
michael@0 | 74 | nsresult DrawSingleTile(gfxContext* aContext, |
michael@0 | 75 | GraphicsFilter aFilter, |
michael@0 | 76 | const gfxMatrix& aUserSpaceToImageSpace, |
michael@0 | 77 | const gfxRect& aFill, |
michael@0 | 78 | const nsIntRect& aSubimage, |
michael@0 | 79 | const nsIntSize& aViewportSize, |
michael@0 | 80 | const SVGImageContext* aSVGContext, |
michael@0 | 81 | uint32_t aWhichFrame, |
michael@0 | 82 | uint32_t aFlags); |
michael@0 | 83 | |
michael@0 | 84 | // If we are forced to draw a temporary surface, we cache it here. |
michael@0 | 85 | nsAutoPtr<ClippedImageCachedSurface> mCachedSurface; |
michael@0 | 86 | |
michael@0 | 87 | nsIntRect mClip; // The region to clip to. |
michael@0 | 88 | Maybe<bool> mShouldClip; // Memoized ShouldClip() if present. |
michael@0 | 89 | |
michael@0 | 90 | friend class DrawSingleTileCallback; |
michael@0 | 91 | friend class ImageOps; |
michael@0 | 92 | }; |
michael@0 | 93 | |
michael@0 | 94 | } // namespace image |
michael@0 | 95 | } // namespace mozilla |
michael@0 | 96 | |
michael@0 | 97 | #endif // MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_ |