DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (d38398e5144e)

VCS Links

AutoSetOperator

BasicReadbackLayer

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
/* -*- 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 http://mozilla.org/MPL/2.0/. */

#ifndef GFX_BASICLAYERSIMPL_H
#define GFX_BASICLAYERSIMPL_H

#include "BasicImplData.h"              // for BasicImplData
#include "BasicLayers.h"                // for BasicLayerManager
#include "ReadbackLayer.h"              // for ReadbackLayer
#include "gfxContext.h"                 // for gfxContext, etc
#include "mozilla/Attributes.h"         // for MOZ_STACK_CLASS
#include "mozilla/Maybe.h"              // for Maybe
#include "nsDebug.h"                    // for NS_ASSERTION
#include "nsISupportsImpl.h"            // for gfxContext::Release, etc
#include "nsRegion.h"                   // for nsIntRegion

namespace mozilla {
namespace gfx {
class DrawTarget;
} // namespace gfx

namespace layers {

class AutoMoz2DMaskData;
class Layer;

class AutoSetOperator {
  typedef mozilla::gfx::CompositionOp CompositionOp;
public:
  AutoSetOperator(gfxContext* aContext, CompositionOp aOperator) {
    if (aOperator != CompositionOp::OP_OVER) {
      aContext->SetOp(aOperator);
      mContext = aContext;
    }
  }
  ~AutoSetOperator() {
    if (mContext) {
      mContext->SetOp(CompositionOp::OP_OVER);
    }
  }
private:
  RefPtr<gfxContext> mContext;
};

class BasicReadbackLayer : public ReadbackLayer,
                           public BasicImplData
{
public:
  explicit BasicReadbackLayer(BasicLayerManager* aLayerManager) :
    ReadbackLayer(aLayerManager, static_cast<BasicImplData*>(this))
  {
    MOZ_COUNT_CTOR(BasicReadbackLayer);
  }

protected:
  virtual ~BasicReadbackLayer()
  {
    MOZ_COUNT_DTOR(BasicReadbackLayer);
  }

public:
  virtual void SetVisibleRegion(const LayerIntRegion& aRegion)
  {
    NS_ASSERTION(BasicManager()->InConstruction(),
                 "Can only set properties in construction phase");
    ReadbackLayer::SetVisibleRegion(aRegion);
  }

protected:
  BasicLayerManager* BasicManager()
  {
    return static_cast<BasicLayerManager*>(mManager);
  }
};

/*
 * Extract a mask surface for a mask layer
 * Returns true and through outparams a surface for the mask layer if
 * a mask layer is present and has a valid surface and transform;
 * false otherwise.
 * The transform for the layer will be put in aMaskData
 */
bool
GetMaskData(Layer* aMaskLayer,
            const gfx::Point& aDeviceOffset,
            AutoMoz2DMaskData* aMaskData);

already_AddRefed<gfx::SourceSurface> GetMaskForLayer(Layer* aLayer, gfx::Matrix* aMaskTransform);

// Paint the current source to a context using a mask, if present
void
PaintWithMask(gfxContext* aContext, float aOpacity, Layer* aMaskLayer);

// Fill the rect with the source, using a mask and opacity, if present
void
FillRectWithMask(gfx::DrawTarget* aDT,
                 const gfx::Rect& aRect,
                 const gfx::Color& aColor,
                 const gfx::DrawOptions& aOptions,
                 gfx::SourceSurface* aMaskSource = nullptr,
                 const gfx::Matrix* aMaskTransform = nullptr);
void
FillRectWithMask(gfx::DrawTarget* aDT,
                 const gfx::Rect& aRect,
                 gfx::SourceSurface* aSurface,
                 gfx::SamplingFilter aSamplingFilter,
                 const gfx::DrawOptions& aOptions,
                 gfx::ExtendMode aExtendMode,
                 gfx::SourceSurface* aMaskSource = nullptr,
                 const gfx::Matrix* aMaskTransform = nullptr,
                 const gfx::Matrix* aSurfaceTransform = nullptr);
void
FillRectWithMask(gfx::DrawTarget* aDT,
                 const gfx::Point& aDeviceOffset,
                 const gfx::Rect& aRect,
                 gfx::SourceSurface* aSurface,
                 gfx::SamplingFilter aSamplingFilter,
                 const gfx::DrawOptions& aOptions,
                 Layer* aMaskLayer);
void
FillRectWithMask(gfx::DrawTarget* aDT,
                 const gfx::Point& aDeviceOffset,
                 const gfx::Rect& aRect,
                 const gfx::Color& aColor,
                 const gfx::DrawOptions& aOptions,
                 Layer* aMaskLayer);

void
FillPathWithMask(gfx::DrawTarget* aDT,
                 const gfx::Path* aPath,
                 const gfx::Rect& aClipRect,
                 const gfx::Color& aColor,
                 const gfx::DrawOptions& aOptions,
                 gfx::SourceSurface* aMaskSource = nullptr,
                 const gfx::Matrix* aMaskTransform = nullptr);
void
FillPathWithMask(gfx::DrawTarget* aDT,
                 const gfx::Path* aPath,
                 const gfx::Rect& aClipRect,
                 gfx::SourceSurface* aSurface,
                 gfx::SamplingFilter aSamplingFilter,
                 const gfx::DrawOptions& aOptions,
                 gfx::ExtendMode aExtendMode,
                 gfx::SourceSurface* aMaskSource,
                 const gfx::Matrix* aMaskTransform,
                 const gfx::Matrix* aSurfaceTransform);

BasicImplData*
ToData(Layer* aLayer);

/**
 * Returns the operator to be used when blending and compositing this layer.
 * Currently there is no way to specify both a blending and a compositing
 * operator other than normal and source over respectively.
 *
 * If the layer has
 * an effective blend mode operator other than normal, as returned by
 * GetEffectiveMixBlendMode, this operator is used for blending, and source
 * over is used for compositing.
 * If the blend mode for this layer is normal, the compositing operator
 * returned by GetOperator is used.
 */
gfx::CompositionOp
GetEffectiveOperator(Layer* aLayer);

} // namespace layers
} // namespace mozilla

#endif