image/src/ClippedImage.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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.
    23  *
    24  * XXX(seth): There a known (performance, not correctness) issue with
    25  * GetImageContainer. See the comments for that method for more information.
    26  */
    27 class ClippedImage : public ImageWrapper
    28 {
    29   typedef mozilla::gfx::SourceSurface SourceSurface;
    31 public:
    32   NS_DECL_ISUPPORTS
    34   virtual ~ClippedImage();
    36   virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
    38   NS_IMETHOD GetWidth(int32_t* aWidth) MOZ_OVERRIDE;
    39   NS_IMETHOD GetHeight(int32_t* aHeight) MOZ_OVERRIDE;
    40   NS_IMETHOD GetIntrinsicSize(nsSize* aSize) MOZ_OVERRIDE;
    41   NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) MOZ_OVERRIDE;
    42   NS_IMETHOD_(mozilla::TemporaryRef<SourceSurface>)
    43     GetFrame(uint32_t aWhichFrame, uint32_t aFlags) MOZ_OVERRIDE;
    44   NS_IMETHOD GetImageContainer(mozilla::layers::LayerManager* aManager,
    45                                mozilla::layers::ImageContainer** _retval) MOZ_OVERRIDE;
    46   NS_IMETHOD Draw(gfxContext* aContext,
    47                   GraphicsFilter aFilter,
    48                   const gfxMatrix& aUserSpaceToImageSpace,
    49                   const gfxRect& aFill,
    50                   const nsIntRect& aSubimage,
    51                   const nsIntSize& aViewportSize,
    52                   const SVGImageContext* aSVGContext,
    53                   uint32_t aWhichFrame,
    54                   uint32_t aFlags) MOZ_OVERRIDE;
    55   NS_IMETHOD RequestDiscard() MOZ_OVERRIDE;
    56   NS_IMETHOD_(Orientation) GetOrientation() MOZ_OVERRIDE;
    58 protected:
    59   ClippedImage(Image* aImage, nsIntRect aClip);
    61 private:
    62   mozilla::TemporaryRef<SourceSurface>
    63     GetFrameInternal(const nsIntSize& aViewportSize,
    64                      const SVGImageContext* aSVGContext,
    65                      uint32_t aWhichFrame,
    66                      uint32_t aFlags);
    67   bool ShouldClip();
    68   bool MustCreateSurface(gfxContext* aContext,
    69                          const gfxMatrix& aTransform,
    70                          const gfxRect& aSourceRect,
    71                          const nsIntRect& aSubimage,
    72                          const uint32_t aFlags) const;
    73   gfxFloat ClampFactor(const gfxFloat aToClamp, const int aReference) const;
    74   nsresult DrawSingleTile(gfxContext* aContext,
    75                           GraphicsFilter aFilter,
    76                           const gfxMatrix& aUserSpaceToImageSpace,
    77                           const gfxRect& aFill,
    78                           const nsIntRect& aSubimage,
    79                           const nsIntSize& aViewportSize,
    80                           const SVGImageContext* aSVGContext,
    81                           uint32_t aWhichFrame,
    82                           uint32_t aFlags);
    84   // If we are forced to draw a temporary surface, we cache it here.
    85   nsAutoPtr<ClippedImageCachedSurface> mCachedSurface;
    87   nsIntRect   mClip;              // The region to clip to.
    88   Maybe<bool> mShouldClip;        // Memoized ShouldClip() if present.
    90   friend class DrawSingleTileCallback;
    91   friend class ImageOps;
    92 };
    94 } // namespace image
    95 } // namespace mozilla
    97 #endif // MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_

mercurial