Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / image / src / ClippedImage.h
blobdcf4690805638155e70e56df67ebaef371667a76
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_IMAGELIB_CLIPPEDIMAGE_H_
7 #define MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_
9 #include "ImageWrapper.h"
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/Maybe.h"
12 #include "mozilla/RefPtr.h"
14 namespace mozilla {
15 namespace image {
17 class ClippedImageCachedSurface;
18 class DrawSingleTileCallback;
20 /**
21 * An Image wrapper that clips an image against a rectangle. Right now only
22 * absolute coordinates in pixels are supported.
24 * XXX(seth): There a known (performance, not correctness) issue with
25 * GetImageContainer. See the comments for that method for more information.
27 class ClippedImage : public ImageWrapper
29 typedef gfx::SourceSurface SourceSurface;
31 public:
32 NS_DECL_ISUPPORTS_INHERITED
34 virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
36 NS_IMETHOD GetWidth(int32_t* aWidth) MOZ_OVERRIDE;
37 NS_IMETHOD GetHeight(int32_t* aHeight) MOZ_OVERRIDE;
38 NS_IMETHOD GetIntrinsicSize(nsSize* aSize) MOZ_OVERRIDE;
39 NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) MOZ_OVERRIDE;
40 NS_IMETHOD_(TemporaryRef<SourceSurface>)
41 GetFrame(uint32_t aWhichFrame, uint32_t aFlags) MOZ_OVERRIDE;
42 NS_IMETHOD GetImageContainer(layers::LayerManager* aManager,
43 layers::ImageContainer** _retval) MOZ_OVERRIDE;
44 NS_IMETHOD Draw(gfxContext* aContext,
45 const nsIntSize& aSize,
46 const ImageRegion& aRegion,
47 uint32_t aWhichFrame,
48 GraphicsFilter aFilter,
49 const Maybe<SVGImageContext>& aSVGContext,
50 uint32_t aFlags) MOZ_OVERRIDE;
51 NS_IMETHOD RequestDiscard() MOZ_OVERRIDE;
52 NS_IMETHOD_(Orientation) GetOrientation() MOZ_OVERRIDE;
53 NS_IMETHOD_(nsIntRect) GetImageSpaceInvalidationRect(const nsIntRect& aRect) MOZ_OVERRIDE;
54 nsIntSize OptimalImageSizeForDest(const gfxSize& aDest,
55 uint32_t aWhichFrame,
56 GraphicsFilter aFilter,
57 uint32_t aFlags) MOZ_OVERRIDE;
59 protected:
60 ClippedImage(Image* aImage, nsIntRect aClip);
62 virtual ~ClippedImage();
64 private:
65 TemporaryRef<SourceSurface>
66 GetFrameInternal(const nsIntSize& aSize,
67 const Maybe<SVGImageContext>& aSVGContext,
68 uint32_t aWhichFrame,
69 uint32_t aFlags);
70 bool ShouldClip();
71 nsresult DrawSingleTile(gfxContext* aContext,
72 const nsIntSize& aSize,
73 const ImageRegion& aRegion,
74 uint32_t aWhichFrame,
75 GraphicsFilter aFilter,
76 const Maybe<SVGImageContext>& aSVGContext,
77 uint32_t aFlags);
79 // If we are forced to draw a temporary surface, we cache it here.
80 nsAutoPtr<ClippedImageCachedSurface> mCachedSurface;
82 nsIntRect mClip; // The region to clip to.
83 Maybe<bool> mShouldClip; // Memoized ShouldClip() if present.
85 friend class DrawSingleTileCallback;
86 friend class ImageOps;
89 } // namespace image
90 } // namespace mozilla
92 #endif // MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_