1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef GFX_BASICLAYERSIMPL_H 8 #define GFX_BASICLAYERSIMPL_H 9 10 #include "BasicImplData.h" // for BasicImplData 11 #include "BasicLayers.h" // for BasicLayerManager 12 #include "ReadbackLayer.h" // for ReadbackLayer 13 #include "gfxContext.h" // for gfxContext, etc 14 #include "mozilla/Attributes.h" // for MOZ_STACK_CLASS 15 #include "mozilla/Maybe.h" // for Maybe 16 #include "nsDebug.h" // for NS_ASSERTION 17 #include "nsISupportsImpl.h" // for gfxContext::Release, etc 18 #include "nsRegion.h" // for nsIntRegion 19 20 namespace mozilla { 21 namespace gfx { 22 class DrawTarget; 23 } // namespace gfx 24 25 namespace layers { 26 27 class AutoMoz2DMaskData; 28 class Layer; 29 30 class AutoSetOperator { 31 typedef mozilla::gfx::CompositionOp CompositionOp; 32 33 public: AutoSetOperator(gfxContext * aContext,CompositionOp aOperator)34 AutoSetOperator(gfxContext* aContext, CompositionOp aOperator) { 35 if (aOperator != CompositionOp::OP_OVER) { 36 aContext->SetOp(aOperator); 37 mContext = aContext; 38 } 39 } ~AutoSetOperator()40 ~AutoSetOperator() { 41 if (mContext) { 42 mContext->SetOp(CompositionOp::OP_OVER); 43 } 44 } 45 46 private: 47 RefPtr<gfxContext> mContext; 48 }; 49 50 class BasicReadbackLayer : public ReadbackLayer, public BasicImplData { 51 public: BasicReadbackLayer(BasicLayerManager * aLayerManager)52 explicit BasicReadbackLayer(BasicLayerManager* aLayerManager) 53 : ReadbackLayer(aLayerManager, static_cast<BasicImplData*>(this)) { 54 MOZ_COUNT_CTOR(BasicReadbackLayer); 55 } 56 57 protected: MOZ_COUNTED_DTOR_OVERRIDE(BasicReadbackLayer)58 MOZ_COUNTED_DTOR_OVERRIDE(BasicReadbackLayer) 59 60 public: 61 void SetVisibleRegion(const LayerIntRegion& aRegion) override { 62 NS_ASSERTION(BasicManager()->InConstruction(), 63 "Can only set properties in construction phase"); 64 ReadbackLayer::SetVisibleRegion(aRegion); 65 } 66 67 protected: BasicManager()68 BasicLayerManager* BasicManager() { 69 return static_cast<BasicLayerManager*>(mManager); 70 } 71 }; 72 73 /* 74 * Extract a mask surface for a mask layer 75 * Returns true and through outparams a surface for the mask layer if 76 * a mask layer is present and has a valid surface and transform; 77 * false otherwise. 78 * The transform for the layer will be put in aMaskData 79 */ 80 bool GetMaskData(Layer* aMaskLayer, const gfx::Point& aDeviceOffset, 81 AutoMoz2DMaskData* aMaskData); 82 83 already_AddRefed<gfx::SourceSurface> GetMaskForLayer( 84 Layer* aLayer, gfx::Matrix* aMaskTransform); 85 86 // Paint the current source to a context using a mask, if present 87 void PaintWithMask(gfxContext* aContext, float aOpacity, Layer* aMaskLayer); 88 89 // Fill the rect with the source, using a mask and opacity, if present 90 void FillRectWithMask(gfx::DrawTarget* aDT, const gfx::Rect& aRect, 91 const gfx::DeviceColor& aColor, 92 const gfx::DrawOptions& aOptions, 93 gfx::SourceSurface* aMaskSource = nullptr, 94 const gfx::Matrix* aMaskTransform = nullptr); 95 void FillRectWithMask(gfx::DrawTarget* aDT, const gfx::Rect& aRect, 96 gfx::SourceSurface* aSurface, 97 gfx::SamplingFilter aSamplingFilter, 98 const gfx::DrawOptions& aOptions, 99 gfx::ExtendMode aExtendMode, 100 gfx::SourceSurface* aMaskSource = nullptr, 101 const gfx::Matrix* aMaskTransform = nullptr, 102 const gfx::Matrix* aSurfaceTransform = nullptr); 103 void FillRectWithMask(gfx::DrawTarget* aDT, const gfx::Point& aDeviceOffset, 104 const gfx::Rect& aRect, gfx::SourceSurface* aSurface, 105 gfx::SamplingFilter aSamplingFilter, 106 const gfx::DrawOptions& aOptions, Layer* aMaskLayer); 107 void FillRectWithMask(gfx::DrawTarget* aDT, const gfx::Point& aDeviceOffset, 108 const gfx::Rect& aRect, const gfx::DeviceColor& aColor, 109 const gfx::DrawOptions& aOptions, Layer* aMaskLayer); 110 111 void FillPathWithMask(gfx::DrawTarget* aDT, const gfx::Path* aPath, 112 const gfx::Rect& aClipRect, 113 const gfx::DeviceColor& aColor, 114 const gfx::DrawOptions& aOptions, 115 gfx::SourceSurface* aMaskSource = nullptr, 116 const gfx::Matrix* aMaskTransform = nullptr); 117 void FillPathWithMask(gfx::DrawTarget* aDT, const gfx::Path* aPath, 118 const gfx::Rect& aClipRect, gfx::SourceSurface* aSurface, 119 gfx::SamplingFilter aSamplingFilter, 120 const gfx::DrawOptions& aOptions, 121 gfx::ExtendMode aExtendMode, 122 gfx::SourceSurface* aMaskSource, 123 const gfx::Matrix* aMaskTransform, 124 const gfx::Matrix* aSurfaceTransform); 125 126 BasicImplData* ToData(Layer* aLayer); 127 128 /** 129 * Returns the operator to be used when blending and compositing this layer. 130 * Currently there is no way to specify both a blending and a compositing 131 * operator other than normal and source over respectively. 132 * 133 * If the layer has 134 * an effective blend mode operator other than normal, as returned by 135 * GetEffectiveMixBlendMode, this operator is used for blending, and source 136 * over is used for compositing. 137 * If the blend mode for this layer is normal, the compositing operator 138 * returned by GetOperator is used. 139 */ 140 gfx::CompositionOp GetEffectiveOperator(Layer* aLayer); 141 142 } // namespace layers 143 } // namespace mozilla 144 145 #endif 146