author Andreas Pehrson <>
Tue, 28 Mar 2017 16:03:21 +0200
changeset 405001 bce76b2df8cc5a22cadfc3c06c61b94533308586
parent 404103 fbc54f707dc421f8132340e45fa2719dbdc9621b
child 407172 f3460d42d23cb21093146a2ace98009d581bd77a
permissions -rw-r--r--
Bug 1320994 - Re-enable tests. r=florian MozReview-Commit-ID: KGe95JhBoVD

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */


#include "mozilla/Attributes.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Pair.h"
#include "gfxPattern.h"
#include "gfxMatrix.h"
#include "nsSVGContainerFrame.h"
#include "nsSVGUtils.h"

class gfxContext;

 * Byte offsets of channels in a native packed gfxColor or cairo image surface.
#define GFX_ARGB32_OFFSET_A 0
#define GFX_ARGB32_OFFSET_R 1
#define GFX_ARGB32_OFFSET_G 2
#define GFX_ARGB32_OFFSET_B 3
#define GFX_ARGB32_OFFSET_A 3
#define GFX_ARGB32_OFFSET_R 2
#define GFX_ARGB32_OFFSET_G 1
#define GFX_ARGB32_OFFSET_B 0

class nsSVGMaskFrame final : public nsSVGContainerFrame
  friend nsIFrame*
  NS_NewSVGMaskFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);

  typedef mozilla::gfx::Matrix Matrix;
  typedef mozilla::gfx::SourceSurface SourceSurface;
  typedef mozilla::image::DrawResult DrawResult;

  explicit nsSVGMaskFrame(nsStyleContext* aContext)
    : nsSVGContainerFrame(aContext, mozilla::LayoutFrameType::SVGMask)
    , mInUse(false)


  struct MaskParams {
    gfxContext* ctx;
    nsIFrame* maskedFrame;
    const gfxMatrix& toUserSpace;
    float opacity;
    Matrix* maskTransform;
    uint8_t maskMode;
    uint32_t flags;  // Image flags of the imgIContainer::FLAG_* variety.

    explicit MaskParams(gfxContext* aCtx, nsIFrame* aMaskedFrame,
                        const gfxMatrix& aToUserSpace, float aOpacity,
                        Matrix* aMaskTransform, uint8_t aMaskMode,
                        uint32_t aFlags)
    : ctx(aCtx), maskedFrame(aMaskedFrame), toUserSpace(aToUserSpace),
      opacity(aOpacity), maskTransform(aMaskTransform), maskMode(aMaskMode),
    { }

  // nsSVGMaskFrame method:
  mozilla::Pair<DrawResult, RefPtr<SourceSurface>>
  GetMaskForMaskedFrame(MaskParams& aParams);

  GetMaskArea(nsIFrame* aMaskedFrame);

  virtual nsresult AttributeChanged(int32_t         aNameSpaceID,
                                    nsIAtom*        aAttribute,
                                    int32_t         aModType) override;

#ifdef DEBUG
  virtual void Init(nsIContent*       aContent,
                    nsContainerFrame* aParent,
                    nsIFrame*         aPrevInFlow) override;

  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                                const nsRect&           aDirtyRect,
                                const nsDisplayListSet& aLists) override {}

  virtual nsresult GetFrameName(nsAString& aResult) const override
    return MakeFrameName(NS_LITERAL_STRING("SVGMask"), aResult);

   * If the mask element transforms its children due to
   * maskContentUnits="objectBoundingBox" being set on it, this function
   * returns the resulting transform.
  gfxMatrix GetMaskTransform(nsIFrame* aMaskedFrame);

  gfxMatrix mMatrixForChildren;
  // recursion prevention flag
  bool mInUse;

  // nsSVGContainerFrame methods:
  virtual gfxMatrix GetCanvasTM() override;