image/src/ClippedImage.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/image/src/ClippedImage.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_
    1.10 +#define MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_
    1.11 +
    1.12 +#include "ImageWrapper.h"
    1.13 +#include "mozilla/gfx/2D.h"
    1.14 +#include "mozilla/Maybe.h"
    1.15 +#include "mozilla/RefPtr.h"
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace image {
    1.19 +
    1.20 +class ClippedImageCachedSurface;
    1.21 +class DrawSingleTileCallback;
    1.22 +
    1.23 +/**
    1.24 + * An Image wrapper that clips an image against a rectangle. Right now only
    1.25 + * absolute coordinates in pixels are supported.
    1.26 + *
    1.27 + * XXX(seth): There a known (performance, not correctness) issue with
    1.28 + * GetImageContainer. See the comments for that method for more information.
    1.29 + */
    1.30 +class ClippedImage : public ImageWrapper
    1.31 +{
    1.32 +  typedef mozilla::gfx::SourceSurface SourceSurface;
    1.33 +
    1.34 +public:
    1.35 +  NS_DECL_ISUPPORTS
    1.36 +
    1.37 +  virtual ~ClippedImage();
    1.38 +
    1.39 +  virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
    1.40 +
    1.41 +  NS_IMETHOD GetWidth(int32_t* aWidth) MOZ_OVERRIDE;
    1.42 +  NS_IMETHOD GetHeight(int32_t* aHeight) MOZ_OVERRIDE;
    1.43 +  NS_IMETHOD GetIntrinsicSize(nsSize* aSize) MOZ_OVERRIDE;
    1.44 +  NS_IMETHOD GetIntrinsicRatio(nsSize* aRatio) MOZ_OVERRIDE;
    1.45 +  NS_IMETHOD_(mozilla::TemporaryRef<SourceSurface>)
    1.46 +    GetFrame(uint32_t aWhichFrame, uint32_t aFlags) MOZ_OVERRIDE;
    1.47 +  NS_IMETHOD GetImageContainer(mozilla::layers::LayerManager* aManager,
    1.48 +                               mozilla::layers::ImageContainer** _retval) MOZ_OVERRIDE;
    1.49 +  NS_IMETHOD Draw(gfxContext* aContext,
    1.50 +                  GraphicsFilter aFilter,
    1.51 +                  const gfxMatrix& aUserSpaceToImageSpace,
    1.52 +                  const gfxRect& aFill,
    1.53 +                  const nsIntRect& aSubimage,
    1.54 +                  const nsIntSize& aViewportSize,
    1.55 +                  const SVGImageContext* aSVGContext,
    1.56 +                  uint32_t aWhichFrame,
    1.57 +                  uint32_t aFlags) MOZ_OVERRIDE;
    1.58 +  NS_IMETHOD RequestDiscard() MOZ_OVERRIDE;
    1.59 +  NS_IMETHOD_(Orientation) GetOrientation() MOZ_OVERRIDE;
    1.60 +
    1.61 +protected:
    1.62 +  ClippedImage(Image* aImage, nsIntRect aClip);
    1.63 +
    1.64 +private:
    1.65 +  mozilla::TemporaryRef<SourceSurface>
    1.66 +    GetFrameInternal(const nsIntSize& aViewportSize,
    1.67 +                     const SVGImageContext* aSVGContext,
    1.68 +                     uint32_t aWhichFrame,
    1.69 +                     uint32_t aFlags);
    1.70 +  bool ShouldClip();
    1.71 +  bool MustCreateSurface(gfxContext* aContext,
    1.72 +                         const gfxMatrix& aTransform,
    1.73 +                         const gfxRect& aSourceRect,
    1.74 +                         const nsIntRect& aSubimage,
    1.75 +                         const uint32_t aFlags) const;
    1.76 +  gfxFloat ClampFactor(const gfxFloat aToClamp, const int aReference) const;
    1.77 +  nsresult DrawSingleTile(gfxContext* aContext,
    1.78 +                          GraphicsFilter aFilter,
    1.79 +                          const gfxMatrix& aUserSpaceToImageSpace,
    1.80 +                          const gfxRect& aFill,
    1.81 +                          const nsIntRect& aSubimage,
    1.82 +                          const nsIntSize& aViewportSize,
    1.83 +                          const SVGImageContext* aSVGContext,
    1.84 +                          uint32_t aWhichFrame,
    1.85 +                          uint32_t aFlags);
    1.86 +
    1.87 +  // If we are forced to draw a temporary surface, we cache it here.
    1.88 +  nsAutoPtr<ClippedImageCachedSurface> mCachedSurface;
    1.89 +
    1.90 +  nsIntRect   mClip;              // The region to clip to.
    1.91 +  Maybe<bool> mShouldClip;        // Memoized ShouldClip() if present.
    1.92 +
    1.93 +  friend class DrawSingleTileCallback;
    1.94 +  friend class ImageOps;
    1.95 +};
    1.96 +
    1.97 +} // namespace image
    1.98 +} // namespace mozilla
    1.99 +
   1.100 +#endif // MOZILLA_IMAGELIB_CLIPPEDIMAGE_H_

mercurial