/work/obj-fuzz/dist/include/BasicLayers.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_BASICLAYERS_H |
8 | | #define GFX_BASICLAYERS_H |
9 | | |
10 | | #include <stdint.h> // for INT32_MAX, int32_t |
11 | | #include "Layers.h" // for Layer (ptr only), etc |
12 | | #include "gfxTypes.h" |
13 | | #include "gfxContext.h" // for gfxContext |
14 | | #include "mozilla/Attributes.h" // for override |
15 | | #include "mozilla/WidgetUtils.h" // for ScreenRotation |
16 | | #include "mozilla/layers/LayersTypes.h" // for BufferMode, LayersBackend, etc |
17 | | #include "mozilla/TimeStamp.h" |
18 | | #include "nsAString.h" |
19 | | #include "nsCOMPtr.h" // for already_AddRefed |
20 | | #include "nsISupportsImpl.h" // for gfxContext::AddRef, etc |
21 | | #include "nsRegion.h" // for nsIntRegion |
22 | | #include "nscore.h" // for nsAString, etc |
23 | | |
24 | | class nsIWidget; |
25 | | |
26 | | namespace mozilla { |
27 | | namespace layers { |
28 | | |
29 | | class ImageFactory; |
30 | | class ImageLayer; |
31 | | class PaintLayerContext; |
32 | | class ReadbackLayer; |
33 | | |
34 | | /** |
35 | | * This is a cairo/Thebes-only, main-thread-only implementation of layers. |
36 | | * |
37 | | * In each transaction, the client sets up the layer tree and then during |
38 | | * the drawing phase, each PaintedLayer is painted directly into the target |
39 | | * context (with appropriate clipping and Push/PopGroups performed |
40 | | * between layers). |
41 | | */ |
42 | | class BasicLayerManager final : |
43 | | public LayerManager |
44 | | { |
45 | | public: |
46 | | enum BasicLayerManagerType { |
47 | | BLM_WIDGET, |
48 | | BLM_OFFSCREEN, |
49 | | BLM_INACTIVE |
50 | | }; |
51 | | /** |
52 | | * Construct a BasicLayerManager which will have no default |
53 | | * target context. SetDefaultTarget or BeginTransactionWithTarget |
54 | | * must be called for any rendering to happen. PaintedLayers will not |
55 | | * be retained. |
56 | | */ |
57 | | explicit BasicLayerManager(BasicLayerManagerType aType); |
58 | | /** |
59 | | * Construct a BasicLayerManager which will have no default |
60 | | * target context. SetDefaultTarget or BeginTransactionWithTarget |
61 | | * must be called for any rendering to happen. PaintedLayers will be |
62 | | * retained; that is, we will try to retain the visible contents of |
63 | | * PaintedLayers as cairo surfaces. We create PaintedLayer buffers by |
64 | | * creating similar surfaces to the default target context, or to |
65 | | * aWidget's GetThebesSurface if there is no default target context, or |
66 | | * to the passed-in context if there is no widget and no default |
67 | | * target context. |
68 | | * |
69 | | * This does not keep a strong reference to the widget, so the caller |
70 | | * must ensure that the widget outlives the layer manager or call |
71 | | * ClearWidget before the widget dies. |
72 | | */ |
73 | | explicit BasicLayerManager(nsIWidget* aWidget); |
74 | | |
75 | | protected: |
76 | | virtual ~BasicLayerManager(); |
77 | | |
78 | | public: |
79 | | BasicLayerManager* AsBasicLayerManager() override { return this; } |
80 | | |
81 | | /** |
82 | | * Set the default target context that will be used when BeginTransaction |
83 | | * is called. This can only be called outside a transaction. |
84 | | * |
85 | | * aDoubleBuffering can request double-buffering for drawing to the |
86 | | * default target. When BUFFERED, the layer manager avoids blitting |
87 | | * temporary results to aContext and then overpainting them with final |
88 | | * results, by using a temporary buffer when necessary. In BUFFERED |
89 | | * mode we always completely overwrite the contents of aContext's |
90 | | * destination surface (within the clip region) using OP_SOURCE. |
91 | | */ |
92 | | void SetDefaultTarget(gfxContext* aContext); |
93 | | virtual void SetDefaultTargetConfiguration(BufferMode aDoubleBuffering, ScreenRotation aRotation); |
94 | | gfxContext* GetDefaultTarget() { return mDefaultTarget; } |
95 | | |
96 | | nsIWidget* GetRetainerWidget() { return mWidget; } |
97 | 0 | void ClearRetainerWidget() { mWidget = nullptr; } |
98 | | |
99 | | virtual bool IsWidgetLayerManager() override { return mWidget != nullptr; } |
100 | | virtual bool IsInactiveLayerManager() override { return mType == BLM_INACTIVE; } |
101 | | |
102 | | virtual bool BeginTransaction() override; |
103 | | virtual bool BeginTransactionWithTarget(gfxContext* aTarget) override; |
104 | | virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT) override; |
105 | | virtual void EndTransaction(DrawPaintedLayerCallback aCallback, |
106 | | void* aCallbackData, |
107 | | EndTransactionFlags aFlags = END_DEFAULT) override; |
108 | | void AbortTransaction(); |
109 | | |
110 | | virtual void SetRoot(Layer* aLayer) override; |
111 | | |
112 | | virtual already_AddRefed<PaintedLayer> CreatePaintedLayer() override; |
113 | | virtual already_AddRefed<ContainerLayer> CreateContainerLayer() override; |
114 | | virtual already_AddRefed<ImageLayer> CreateImageLayer() override; |
115 | | virtual already_AddRefed<CanvasLayer> CreateCanvasLayer() override; |
116 | | virtual already_AddRefed<ColorLayer> CreateColorLayer() override; |
117 | | virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer() override; |
118 | | virtual ImageFactory *GetImageFactory(); |
119 | | |
120 | | virtual LayersBackend GetBackendType() override { return LayersBackend::LAYERS_BASIC; } |
121 | | virtual void GetBackendName(nsAString& name) override { name.AssignLiteral("Basic"); } |
122 | | |
123 | | bool InConstruction() { return mPhase == PHASE_CONSTRUCTION; } |
124 | | #ifdef DEBUG |
125 | | bool InDrawing() { return mPhase == PHASE_DRAWING; } |
126 | | bool InForward() { return mPhase == PHASE_FORWARD; } |
127 | | #endif |
128 | 0 | bool InTransaction() { return mPhase != PHASE_NONE; } |
129 | | |
130 | 0 | gfxContext* GetTarget() { return mTarget; } |
131 | 0 | void SetTarget(gfxContext* aTarget) { mUsingDefaultTarget = false; mTarget = aTarget; } |
132 | | bool IsRetained() { return mWidget != nullptr; } |
133 | | |
134 | | virtual const char* Name() const override { return "Basic"; } |
135 | | |
136 | | // Clear the cached contents of this layer tree. |
137 | | virtual void ClearCachedResources(Layer* aSubtree = nullptr) override; |
138 | | |
139 | | void SetTransactionIncomplete() { mTransactionIncomplete = true; } |
140 | | bool IsTransactionIncomplete() { return mTransactionIncomplete; } |
141 | | |
142 | | struct PushedGroup |
143 | | { |
144 | | PushedGroup() : mFinalTarget(nullptr), mNeedsClipToVisibleRegion(false), mOperator(gfx::CompositionOp::OP_COUNT), mOpacity(0.0f){} |
145 | | gfxContext* mFinalTarget; |
146 | | RefPtr<gfxContext> mGroupTarget; |
147 | | nsIntRegion mVisibleRegion; |
148 | | bool mNeedsClipToVisibleRegion; |
149 | | gfx::IntPoint mGroupOffset; |
150 | | gfx::CompositionOp mOperator; |
151 | | gfx::Float mOpacity; |
152 | | RefPtr<gfx::SourceSurface> mMaskSurface; |
153 | | gfx::Matrix mMaskTransform; |
154 | | }; |
155 | | |
156 | | // Construct a PushedGroup for a specific layer. |
157 | | // Return false if it has some errors in PushGroupForLayer(). Then, the |
158 | | // "aGroupResult" is unavailable for future using. |
159 | | bool PushGroupForLayer(gfxContext* aContext, Layer* aLayerContext, const nsIntRegion& aRegion, PushedGroup& aGroupResult); |
160 | | |
161 | | void PopGroupForLayer(PushedGroup& aGroup); |
162 | | |
163 | | virtual bool IsCompositingCheap() override { return false; } |
164 | | virtual int32_t GetMaxTextureSize() const override { return INT32_MAX; } |
165 | | bool CompositorMightResample() { return mCompositorMightResample; } |
166 | | |
167 | | TimeStamp GetCompositionTime() const |
168 | | { |
169 | | return mCompositionTime; |
170 | | } |
171 | | |
172 | | protected: |
173 | | enum TransactionPhase { |
174 | | PHASE_NONE, PHASE_CONSTRUCTION, PHASE_DRAWING, PHASE_FORWARD |
175 | | }; |
176 | | TransactionPhase mPhase; |
177 | | |
178 | | // This is the main body of the PaintLayer routine which will if it has |
179 | | // children, recurse into PaintLayer() otherwise it will paint using the |
180 | | // underlying Paint() method of the Layer. It will not do both. |
181 | | void PaintSelfOrChildren(PaintLayerContext& aPaintContext, gfxContext* aGroupTarget); |
182 | | |
183 | | // Paint the group onto the underlying target. This is used by PaintLayer to |
184 | | // flush the group to the underlying target. |
185 | | void FlushGroup(PaintLayerContext& aPaintContext, bool aNeedsClipToVisibleRegion); |
186 | | |
187 | | // Paints aLayer to mTarget. |
188 | | void PaintLayer(gfxContext* aTarget, |
189 | | Layer* aLayer, |
190 | | DrawPaintedLayerCallback aCallback, |
191 | | void* aCallbackData); |
192 | | |
193 | | // Clear the contents of a layer |
194 | | void ClearLayer(Layer* aLayer); |
195 | | |
196 | | bool EndTransactionInternal(DrawPaintedLayerCallback aCallback, |
197 | | void* aCallbackData, |
198 | | EndTransactionFlags aFlags = END_DEFAULT); |
199 | | |
200 | | void FlashWidgetUpdateArea(gfxContext* aContext); |
201 | | |
202 | | void SetCompositionTime(TimeStamp aTimeStamp) |
203 | | { |
204 | | mCompositionTime = aTimeStamp; |
205 | | } |
206 | | |
207 | | // Widget whose surface should be used as the basis for PaintedLayer |
208 | | // buffers. |
209 | | nsIWidget* mWidget; |
210 | | // The default context for BeginTransaction. |
211 | | RefPtr<gfxContext> mDefaultTarget; |
212 | | // The context to draw into. |
213 | | RefPtr<gfxContext> mTarget; |
214 | | // Image factory we use. |
215 | | RefPtr<ImageFactory> mFactory; |
216 | | |
217 | | BufferMode mDoubleBuffering; |
218 | | BasicLayerManagerType mType; |
219 | | bool mUsingDefaultTarget; |
220 | | bool mTransactionIncomplete; |
221 | | bool mCompositorMightResample; |
222 | | |
223 | | TimeStamp mCompositionTime; |
224 | | }; |
225 | | |
226 | | } // namespace layers |
227 | | } // namespace mozilla |
228 | | |
229 | | #endif /* GFX_BASICLAYERS_H */ |