/src/mozilla-central/gfx/layers/basic/BasicLayersImpl.h
Line | Count | Source (jump to first uncovered line) |
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 | | public: |
33 | 0 | AutoSetOperator(gfxContext* aContext, CompositionOp aOperator) { |
34 | 0 | if (aOperator != CompositionOp::OP_OVER) { |
35 | 0 | aContext->SetOp(aOperator); |
36 | 0 | mContext = aContext; |
37 | 0 | } |
38 | 0 | } |
39 | 0 | ~AutoSetOperator() { |
40 | 0 | if (mContext) { |
41 | 0 | mContext->SetOp(CompositionOp::OP_OVER); |
42 | 0 | } |
43 | 0 | } |
44 | | private: |
45 | | RefPtr<gfxContext> mContext; |
46 | | }; |
47 | | |
48 | | class BasicReadbackLayer : public ReadbackLayer, |
49 | | public BasicImplData |
50 | | { |
51 | | public: |
52 | | explicit BasicReadbackLayer(BasicLayerManager* aLayerManager) : |
53 | | ReadbackLayer(aLayerManager, static_cast<BasicImplData*>(this)) |
54 | 0 | { |
55 | 0 | MOZ_COUNT_CTOR(BasicReadbackLayer); |
56 | 0 | } |
57 | | |
58 | | protected: |
59 | | virtual ~BasicReadbackLayer() |
60 | 0 | { |
61 | 0 | MOZ_COUNT_DTOR(BasicReadbackLayer); |
62 | 0 | } |
63 | | |
64 | | public: |
65 | | virtual void SetVisibleRegion(const LayerIntRegion& aRegion) override |
66 | 0 | { |
67 | 0 | NS_ASSERTION(BasicManager()->InConstruction(), |
68 | 0 | "Can only set properties in construction phase"); |
69 | 0 | ReadbackLayer::SetVisibleRegion(aRegion); |
70 | 0 | } |
71 | | |
72 | | protected: |
73 | | BasicLayerManager* BasicManager() |
74 | 0 | { |
75 | 0 | return static_cast<BasicLayerManager*>(mManager); |
76 | 0 | } |
77 | | }; |
78 | | |
79 | | /* |
80 | | * Extract a mask surface for a mask layer |
81 | | * Returns true and through outparams a surface for the mask layer if |
82 | | * a mask layer is present and has a valid surface and transform; |
83 | | * false otherwise. |
84 | | * The transform for the layer will be put in aMaskData |
85 | | */ |
86 | | bool |
87 | | GetMaskData(Layer* aMaskLayer, |
88 | | const gfx::Point& aDeviceOffset, |
89 | | AutoMoz2DMaskData* aMaskData); |
90 | | |
91 | | already_AddRefed<gfx::SourceSurface> GetMaskForLayer(Layer* aLayer, gfx::Matrix* aMaskTransform); |
92 | | |
93 | | // Paint the current source to a context using a mask, if present |
94 | | void |
95 | | PaintWithMask(gfxContext* aContext, float aOpacity, Layer* aMaskLayer); |
96 | | |
97 | | // Fill the rect with the source, using a mask and opacity, if present |
98 | | void |
99 | | FillRectWithMask(gfx::DrawTarget* aDT, |
100 | | const gfx::Rect& aRect, |
101 | | const gfx::Color& aColor, |
102 | | const gfx::DrawOptions& aOptions, |
103 | | gfx::SourceSurface* aMaskSource = nullptr, |
104 | | const gfx::Matrix* aMaskTransform = nullptr); |
105 | | void |
106 | | FillRectWithMask(gfx::DrawTarget* aDT, |
107 | | const gfx::Rect& aRect, |
108 | | gfx::SourceSurface* aSurface, |
109 | | gfx::SamplingFilter aSamplingFilter, |
110 | | const gfx::DrawOptions& aOptions, |
111 | | gfx::ExtendMode aExtendMode, |
112 | | gfx::SourceSurface* aMaskSource = nullptr, |
113 | | const gfx::Matrix* aMaskTransform = nullptr, |
114 | | const gfx::Matrix* aSurfaceTransform = nullptr); |
115 | | void |
116 | | FillRectWithMask(gfx::DrawTarget* aDT, |
117 | | const gfx::Point& aDeviceOffset, |
118 | | const gfx::Rect& aRect, |
119 | | gfx::SourceSurface* aSurface, |
120 | | gfx::SamplingFilter aSamplingFilter, |
121 | | const gfx::DrawOptions& aOptions, |
122 | | Layer* aMaskLayer); |
123 | | void |
124 | | FillRectWithMask(gfx::DrawTarget* aDT, |
125 | | const gfx::Point& aDeviceOffset, |
126 | | const gfx::Rect& aRect, |
127 | | const gfx::Color& aColor, |
128 | | const gfx::DrawOptions& aOptions, |
129 | | Layer* aMaskLayer); |
130 | | |
131 | | void |
132 | | FillPathWithMask(gfx::DrawTarget* aDT, |
133 | | const gfx::Path* aPath, |
134 | | const gfx::Rect& aClipRect, |
135 | | const gfx::Color& aColor, |
136 | | const gfx::DrawOptions& aOptions, |
137 | | gfx::SourceSurface* aMaskSource = nullptr, |
138 | | const gfx::Matrix* aMaskTransform = nullptr); |
139 | | void |
140 | | FillPathWithMask(gfx::DrawTarget* aDT, |
141 | | const gfx::Path* aPath, |
142 | | const gfx::Rect& aClipRect, |
143 | | gfx::SourceSurface* aSurface, |
144 | | gfx::SamplingFilter aSamplingFilter, |
145 | | const gfx::DrawOptions& aOptions, |
146 | | gfx::ExtendMode aExtendMode, |
147 | | gfx::SourceSurface* aMaskSource, |
148 | | const gfx::Matrix* aMaskTransform, |
149 | | const gfx::Matrix* aSurfaceTransform); |
150 | | |
151 | | BasicImplData* |
152 | | ToData(Layer* aLayer); |
153 | | |
154 | | /** |
155 | | * Returns the operator to be used when blending and compositing this layer. |
156 | | * Currently there is no way to specify both a blending and a compositing |
157 | | * operator other than normal and source over respectively. |
158 | | * |
159 | | * If the layer has |
160 | | * an effective blend mode operator other than normal, as returned by |
161 | | * GetEffectiveMixBlendMode, this operator is used for blending, and source |
162 | | * over is used for compositing. |
163 | | * If the blend mode for this layer is normal, the compositing operator |
164 | | * returned by GetOperator is used. |
165 | | */ |
166 | | gfx::CompositionOp |
167 | | GetEffectiveOperator(Layer* aLayer); |
168 | | |
169 | | } // namespace layers |
170 | | } // namespace mozilla |
171 | | |
172 | | #endif |