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