michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_BASICLAYERSIMPL_H michael@0: #define GFX_BASICLAYERSIMPL_H michael@0: michael@0: #include "BasicImplData.h" // for BasicImplData michael@0: #include "BasicLayers.h" // for BasicLayerManager michael@0: #include "ReadbackLayer.h" // for ReadbackLayer michael@0: #include "gfxContext.h" // for gfxContext, etc michael@0: #include "mozilla/Attributes.h" // for MOZ_DELETE, MOZ_STACK_CLASS michael@0: #include "mozilla/Maybe.h" // for Maybe michael@0: #include "nsAutoPtr.h" // for nsRefPtr michael@0: #include "nsDebug.h" // for NS_ASSERTION michael@0: #include "nsISupportsImpl.h" // for gfxContext::Release, etc michael@0: #include "nsRegion.h" // for nsIntRegion michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: class DrawTarget; michael@0: } michael@0: michael@0: namespace layers { michael@0: michael@0: class AutoMoz2DMaskData; michael@0: class BasicContainerLayer; michael@0: class Layer; michael@0: michael@0: class AutoSetOperator { michael@0: public: michael@0: AutoSetOperator(gfxContext* aContext, gfxContext::GraphicsOperator aOperator) { michael@0: if (aOperator != gfxContext::OPERATOR_OVER) { michael@0: aContext->SetOperator(aOperator); michael@0: mContext = aContext; michael@0: } michael@0: } michael@0: ~AutoSetOperator() { michael@0: if (mContext) { michael@0: mContext->SetOperator(gfxContext::OPERATOR_OVER); michael@0: } michael@0: } michael@0: private: michael@0: nsRefPtr mContext; michael@0: }; michael@0: michael@0: class BasicReadbackLayer : public ReadbackLayer, michael@0: public BasicImplData michael@0: { michael@0: public: michael@0: BasicReadbackLayer(BasicLayerManager* aLayerManager) : michael@0: ReadbackLayer(aLayerManager, michael@0: static_cast(MOZ_THIS_IN_INITIALIZER_LIST())) michael@0: { michael@0: MOZ_COUNT_CTOR(BasicReadbackLayer); michael@0: } michael@0: virtual ~BasicReadbackLayer() michael@0: { michael@0: MOZ_COUNT_DTOR(BasicReadbackLayer); michael@0: } michael@0: michael@0: virtual void SetVisibleRegion(const nsIntRegion& aRegion) michael@0: { michael@0: NS_ASSERTION(BasicManager()->InConstruction(), michael@0: "Can only set properties in construction phase"); michael@0: ReadbackLayer::SetVisibleRegion(aRegion); michael@0: } michael@0: michael@0: protected: michael@0: BasicLayerManager* BasicManager() michael@0: { michael@0: return static_cast(mManager); michael@0: } michael@0: }; michael@0: michael@0: /* michael@0: * Extract a mask surface for a mask layer michael@0: * Returns true and through outparams a surface for the mask layer if michael@0: * a mask layer is present and has a valid surface and transform; michael@0: * false otherwise. michael@0: * The transform for the layer will be put in aMaskData michael@0: */ michael@0: bool michael@0: GetMaskData(Layer* aMaskLayer, michael@0: const gfx::Point& aDeviceOffset, michael@0: AutoMoz2DMaskData* aMaskData); michael@0: michael@0: // Paint the current source to a context using a mask, if present michael@0: void michael@0: PaintWithMask(gfxContext* aContext, float aOpacity, Layer* aMaskLayer); michael@0: michael@0: // Fill the rect with the source, using a mask and opacity, if present michael@0: void michael@0: FillRectWithMask(gfx::DrawTarget* aDT, michael@0: const gfx::Rect& aRect, michael@0: const gfx::Color& aColor, michael@0: const gfx::DrawOptions& aOptions, michael@0: gfx::SourceSurface* aMaskSource = nullptr, michael@0: const gfx::Matrix* aMaskTransform = nullptr); michael@0: void michael@0: FillRectWithMask(gfx::DrawTarget* aDT, michael@0: const gfx::Rect& aRect, michael@0: gfx::SourceSurface* aSurface, michael@0: gfx::Filter aFilter, michael@0: const gfx::DrawOptions& aOptions, michael@0: gfx::ExtendMode aExtendMode, michael@0: gfx::SourceSurface* aMaskSource = nullptr, michael@0: const gfx::Matrix* aMaskTransform = nullptr, michael@0: const gfx::Matrix* aSurfaceTransform = nullptr); michael@0: void michael@0: FillRectWithMask(gfx::DrawTarget* aDT, michael@0: const gfx::Point& aDeviceOffset, michael@0: const gfx::Rect& aRect, michael@0: gfx::SourceSurface* aSurface, michael@0: gfx::Filter aFilter, michael@0: const gfx::DrawOptions& aOptions, michael@0: Layer* aMaskLayer); michael@0: void michael@0: FillRectWithMask(gfx::DrawTarget* aDT, michael@0: const gfx::Point& aDeviceOffset, michael@0: const gfx::Rect& aRect, michael@0: const gfx::Color& aColor, michael@0: const gfx::DrawOptions& aOptions, michael@0: Layer* aMaskLayer); michael@0: michael@0: BasicImplData* michael@0: ToData(Layer* aLayer); michael@0: michael@0: /** michael@0: * Returns the operator to be used when blending and compositing this layer. michael@0: * Currently there is no way to specify both a blending and a compositing michael@0: * operator other than normal and source over respectively. michael@0: * michael@0: * If the layer has michael@0: * an effective blend mode operator other than normal, as returned by michael@0: * GetEffectiveMixBlendMode, this operator is used for blending, and source michael@0: * over is used for compositing. michael@0: * If the blend mode for this layer is normal, the compositing operator michael@0: * returned by GetOperator is used. michael@0: */ michael@0: gfx::CompositionOp michael@0: GetEffectiveOperator(Layer* aLayer); michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif