/work/obj-fuzz/dist/include/mozilla/layers/WebRenderCommandBuilder.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_WEBRENDERCOMMANDBUILDER_H |
8 | | #define GFX_WEBRENDERCOMMANDBUILDER_H |
9 | | |
10 | | #include "mozilla/webrender/WebRenderAPI.h" |
11 | | #include "mozilla/layers/ClipManager.h" |
12 | | #include "mozilla/layers/WebRenderMessages.h" |
13 | | #include "mozilla/layers/WebRenderScrollData.h" |
14 | | #include "mozilla/layers/WebRenderUserData.h" |
15 | | #include "nsDisplayList.h" |
16 | | #include "nsIFrame.h" |
17 | | |
18 | | namespace mozilla { |
19 | | |
20 | | namespace layers { |
21 | | |
22 | | class CanvasLayer; |
23 | | class ImageClient; |
24 | | class ImageContainer; |
25 | | class WebRenderBridgeChild; |
26 | | class WebRenderCanvasData; |
27 | | class WebRenderCanvasRendererAsync; |
28 | | class WebRenderImageData; |
29 | | class WebRenderFallbackData; |
30 | | class WebRenderParentCommand; |
31 | | class WebRenderUserData; |
32 | | |
33 | | class WebRenderCommandBuilder { |
34 | | typedef nsTHashtable<nsRefPtrHashKey<WebRenderUserData>> WebRenderUserDataRefTable; |
35 | | typedef nsTHashtable<nsRefPtrHashKey<WebRenderCanvasData>> CanvasDataSet; |
36 | | |
37 | | public: |
38 | | explicit WebRenderCommandBuilder(WebRenderLayerManager* aManager) |
39 | | : mManager(aManager) |
40 | | , mLastAsr(nullptr) |
41 | | , mBuilderDumpIndex(0) |
42 | | , mDumpIndent(0) |
43 | | , mDoGrouping(false) |
44 | | , mContainsSVGGroup(false) |
45 | | {} |
46 | | |
47 | | void Destroy(); |
48 | | |
49 | | void EmptyTransaction(); |
50 | | |
51 | | bool NeedsEmptyTransaction(); |
52 | | |
53 | | void BuildWebRenderCommands(wr::DisplayListBuilder& aBuilder, |
54 | | wr::IpcResourceUpdateQueue& aResourceUpdates, |
55 | | nsDisplayList* aDisplayList, |
56 | | nsDisplayListBuilder* aDisplayListBuilder, |
57 | | WebRenderScrollData& aScrollData, |
58 | | wr::LayoutSize& aContentSize, |
59 | | const nsTArray<wr::WrFilterOp>& aFilters); |
60 | | |
61 | | void PushOverrideForASR(const ActiveScrolledRoot* aASR, |
62 | | const Maybe<wr::WrClipId>& aClipId); |
63 | | void PopOverrideForASR(const ActiveScrolledRoot* aASR); |
64 | | |
65 | | Maybe<wr::ImageKey> CreateImageKey(nsDisplayItem* aItem, |
66 | | ImageContainer* aContainer, |
67 | | mozilla::wr::DisplayListBuilder& aBuilder, |
68 | | mozilla::wr::IpcResourceUpdateQueue& aResources, |
69 | | mozilla::wr::ImageRendering aRendering, |
70 | | const StackingContextHelper& aSc, |
71 | | gfx::IntSize& aSize, |
72 | | const Maybe<LayoutDeviceRect>& aAsyncImageBounds); |
73 | | |
74 | | WebRenderUserDataRefTable* GetWebRenderUserDataTable() { return &mWebRenderUserDatas; } |
75 | | |
76 | | bool PushImage(nsDisplayItem* aItem, |
77 | | ImageContainer* aContainer, |
78 | | mozilla::wr::DisplayListBuilder& aBuilder, |
79 | | mozilla::wr::IpcResourceUpdateQueue& aResources, |
80 | | const StackingContextHelper& aSc, |
81 | | const LayoutDeviceRect& aRect); |
82 | | |
83 | | Maybe<wr::WrImageMask> BuildWrMaskImage(nsDisplayItem* aItem, |
84 | | wr::DisplayListBuilder& aBuilder, |
85 | | wr::IpcResourceUpdateQueue& aResources, |
86 | | const StackingContextHelper& aSc, |
87 | | nsDisplayListBuilder* aDisplayListBuilder, |
88 | | const LayoutDeviceRect& aBounds); |
89 | | |
90 | | bool PushItemAsImage(nsDisplayItem* aItem, |
91 | | wr::DisplayListBuilder& aBuilder, |
92 | | wr::IpcResourceUpdateQueue& aResources, |
93 | | const StackingContextHelper& aSc, |
94 | | nsDisplayListBuilder* aDisplayListBuilder); |
95 | | |
96 | | void CreateWebRenderCommandsFromDisplayList(nsDisplayList* aDisplayList, |
97 | | nsDisplayItem* aOuterItem, |
98 | | nsDisplayListBuilder* aDisplayListBuilder, |
99 | | const StackingContextHelper& aSc, |
100 | | wr::DisplayListBuilder& aBuilder, |
101 | | wr::IpcResourceUpdateQueue& aResources); |
102 | | |
103 | | // aWrappingItem has to be non-null. |
104 | | void DoGroupingForDisplayList(nsDisplayList* aDisplayList, |
105 | | nsDisplayItem* aWrappingItem, |
106 | | nsDisplayListBuilder* aDisplayListBuilder, |
107 | | const StackingContextHelper& aSc, |
108 | | wr::DisplayListBuilder& aBuilder, |
109 | | wr::IpcResourceUpdateQueue& aResources); |
110 | | |
111 | | already_AddRefed<WebRenderFallbackData> GenerateFallbackData(nsDisplayItem* aItem, |
112 | | wr::DisplayListBuilder& aBuilder, |
113 | | wr::IpcResourceUpdateQueue& aResources, |
114 | | const StackingContextHelper& aSc, |
115 | | nsDisplayListBuilder* aDisplayListBuilder, |
116 | | LayoutDeviceRect& aImageRect); |
117 | | |
118 | | void RemoveUnusedAndResetWebRenderUserData(); |
119 | | void ClearCachedResources(); |
120 | | |
121 | | bool ShouldDumpDisplayList(); |
122 | | wr::usize GetBuilderDumpIndex() { return mBuilderDumpIndex; } |
123 | | |
124 | | bool GetContainsSVGGroup() { return mContainsSVGGroup; } |
125 | | |
126 | | // Those are data that we kept between transactions. We used to cache some |
127 | | // data in the layer. But in layers free mode, we don't have layer which |
128 | | // means we need some other place to cached the data between transaction. |
129 | | // We store the data in frame's property. |
130 | | template<class T> already_AddRefed<T> |
131 | | CreateOrRecycleWebRenderUserData(nsDisplayItem* aItem, |
132 | | bool* aOutIsRecycled = nullptr) |
133 | 0 | { |
134 | 0 | MOZ_ASSERT(aItem); |
135 | 0 | nsIFrame* frame = aItem->Frame(); |
136 | 0 | if (aOutIsRecycled) { |
137 | 0 | *aOutIsRecycled = true; |
138 | 0 | } |
139 | 0 |
|
140 | 0 | WebRenderUserDataTable* userDataTable = |
141 | 0 | frame->GetProperty(WebRenderUserDataProperty::Key()); |
142 | 0 |
|
143 | 0 | if (!userDataTable) { |
144 | 0 | userDataTable = new WebRenderUserDataTable(); |
145 | 0 | frame->AddProperty(WebRenderUserDataProperty::Key(), userDataTable); |
146 | 0 | } |
147 | 0 |
|
148 | 0 | RefPtr<WebRenderUserData>& data = userDataTable->GetOrInsert(WebRenderUserDataKey(aItem->GetPerFrameKey(), T::Type())); |
149 | 0 | if (!data) { |
150 | 0 | // To recreate a new user data, we should remove the data from the table first. |
151 | 0 | if (data) { |
152 | 0 | data->RemoveFromTable(); |
153 | 0 | } |
154 | 0 | data = new T(mManager, aItem); |
155 | 0 | mWebRenderUserDatas.PutEntry(data); |
156 | 0 | if (aOutIsRecycled) { |
157 | 0 | *aOutIsRecycled = false; |
158 | 0 | } |
159 | 0 | } |
160 | 0 |
|
161 | 0 | MOZ_ASSERT(data); |
162 | 0 | MOZ_ASSERT(data->GetType() == T::Type()); |
163 | 0 |
|
164 | 0 | // Mark the data as being used. We will remove unused user data in the end of EndTransaction. |
165 | 0 | data->SetUsed(true); |
166 | 0 |
|
167 | 0 | if (T::Type() == WebRenderUserData::UserDataType::eCanvas) { |
168 | 0 | mLastCanvasDatas.PutEntry(data->AsCanvasData()); |
169 | 0 | } |
170 | 0 | RefPtr<T> res = static_cast<T*>(data.get()); |
171 | 0 | return res.forget(); |
172 | 0 | } Unexecuted instantiation: already_AddRefed<mozilla::layers::WebRenderCanvasData> mozilla::layers::WebRenderCommandBuilder::CreateOrRecycleWebRenderUserData<mozilla::layers::WebRenderCanvasData>(nsDisplayItem*, bool*) Unexecuted instantiation: already_AddRefed<mozilla::layers::WebRenderAnimationData> mozilla::layers::WebRenderCommandBuilder::CreateOrRecycleWebRenderUserData<mozilla::layers::WebRenderAnimationData>(nsDisplayItem*, bool*) |
173 | | |
174 | | WebRenderLayerManager* mManager; |
175 | | |
176 | | private: |
177 | | ClipManager mClipManager; |
178 | | |
179 | | // We use this as a temporary data structure while building the mScrollData |
180 | | // inside a layers-free transaction. |
181 | | std::vector<WebRenderLayerScrollData> mLayerScrollData; |
182 | | // We use this as a temporary data structure to track the current display |
183 | | // item's ASR as we recurse in CreateWebRenderCommandsFromDisplayList. We |
184 | | // need this so that WebRenderLayerScrollData items that deeper in the |
185 | | // tree don't duplicate scroll metadata that their ancestors already have. |
186 | | std::vector<const ActiveScrolledRoot*> mAsrStack; |
187 | | const ActiveScrolledRoot* mLastAsr; |
188 | | |
189 | | WebRenderUserDataRefTable mWebRenderUserDatas; |
190 | | |
191 | | // Store of WebRenderCanvasData objects for use in empty transactions |
192 | | CanvasDataSet mLastCanvasDatas; |
193 | | |
194 | | wr::usize mBuilderDumpIndex; |
195 | | wr::usize mDumpIndent; |
196 | | public: |
197 | | // Whether consecutive inactive display items should be grouped into one |
198 | | // blob image. |
199 | | bool mDoGrouping; |
200 | | |
201 | | // True if the most recently build display list contained an svg that |
202 | | // we did grouping for. |
203 | | bool mContainsSVGGroup; |
204 | | }; |
205 | | |
206 | | } // namespace layers |
207 | | } // namespace mozilla |
208 | | |
209 | | #endif /* GFX_WEBRENDERCOMMANDBUILDER_H */ |