/src/mozilla-central/gfx/layers/apz/test/gtest/APZCTreeManagerTester.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 mozilla_layers_APZCTreeManagerTester_h |
8 | | #define mozilla_layers_APZCTreeManagerTester_h |
9 | | |
10 | | /** |
11 | | * Defines a test fixture used for testing multiple APZCs interacting in |
12 | | * an APZCTreeManager. |
13 | | */ |
14 | | |
15 | | #include "APZTestCommon.h" |
16 | | #include "gfxPlatform.h" |
17 | | #include "gfxPrefs.h" |
18 | | #include "mozilla/layers/APZSampler.h" |
19 | | #include "mozilla/layers/APZUpdater.h" |
20 | | |
21 | | class APZCTreeManagerTester : public APZCTesterBase { |
22 | | protected: |
23 | 0 | virtual void SetUp() { |
24 | 0 | gfxPrefs::GetSingleton(); |
25 | 0 | gfxPlatform::GetPlatform(); |
26 | 0 | APZThreadUtils::SetThreadAssertionsEnabled(false); |
27 | 0 | APZThreadUtils::SetControllerThread(MessageLoop::current()); |
28 | 0 |
|
29 | 0 | manager = new TestAPZCTreeManager(mcc); |
30 | 0 | updater = new APZUpdater(manager, false); |
31 | 0 | sampler = new APZSampler(manager, false); |
32 | 0 | } |
33 | | |
34 | 0 | virtual void TearDown() { |
35 | 0 | while (mcc->RunThroughDelayedTasks()); |
36 | 0 | manager->ClearTree(); |
37 | 0 | manager->ClearContentController(); |
38 | 0 | } |
39 | | |
40 | | /** |
41 | | * Sample animations once for all APZCs, 1 ms later than the last sample. |
42 | | */ |
43 | 0 | void SampleAnimationsOnce() { |
44 | 0 | const TimeDuration increment = TimeDuration::FromMilliseconds(1); |
45 | 0 | ParentLayerPoint pointOut; |
46 | 0 | AsyncTransform viewTransformOut; |
47 | 0 | mcc->AdvanceBy(increment); |
48 | 0 |
|
49 | 0 | for (const RefPtr<Layer>& layer : layers) { |
50 | 0 | if (TestAsyncPanZoomController* apzc = ApzcOf(layer)) { |
51 | 0 | apzc->SampleContentTransformForFrame(&viewTransformOut, pointOut); |
52 | 0 | } |
53 | 0 | } |
54 | 0 | } |
55 | | |
56 | | nsTArray<RefPtr<Layer> > layers; |
57 | | RefPtr<LayerManager> lm; |
58 | | RefPtr<Layer> root; |
59 | | |
60 | | RefPtr<TestAPZCTreeManager> manager; |
61 | | RefPtr<APZSampler> sampler; |
62 | | RefPtr<APZUpdater> updater; |
63 | | |
64 | | protected: |
65 | | static ScrollMetadata BuildScrollMetadata(FrameMetrics::ViewID aScrollId, |
66 | | const CSSRect& aScrollableRect, |
67 | | const ParentLayerRect& aCompositionBounds) |
68 | 0 | { |
69 | 0 | ScrollMetadata metadata; |
70 | 0 | FrameMetrics& metrics = metadata.GetMetrics(); |
71 | 0 | metrics.SetScrollId(aScrollId); |
72 | 0 | // By convention in this test file, START_SCROLL_ID is the root, so mark it as such. |
73 | 0 | if (aScrollId == FrameMetrics::START_SCROLL_ID) { |
74 | 0 | metadata.SetIsLayersIdRoot(true); |
75 | 0 | } |
76 | 0 | metrics.SetCompositionBounds(aCompositionBounds); |
77 | 0 | metrics.SetScrollableRect(aScrollableRect); |
78 | 0 | metrics.SetScrollOffset(CSSPoint(0, 0)); |
79 | 0 | metadata.SetPageScrollAmount(LayoutDeviceIntSize(50, 100)); |
80 | 0 | metadata.SetLineScrollAmount(LayoutDeviceIntSize(5, 10)); |
81 | 0 | return metadata; |
82 | 0 | } |
83 | | |
84 | | static void SetEventRegionsBasedOnBottommostMetrics(Layer* aLayer) |
85 | 0 | { |
86 | 0 | const FrameMetrics& metrics = aLayer->GetScrollMetadata(0).GetMetrics(); |
87 | 0 | CSSRect scrollableRect = metrics.GetScrollableRect(); |
88 | 0 | if (!scrollableRect.IsEqualEdges(CSSRect(-1, -1, -1, -1))) { |
89 | 0 | // The purpose of this is to roughly mimic what layout would do in the |
90 | 0 | // case of a scrollable frame with the event regions and clip. This lets |
91 | 0 | // us exercise the hit-testing code in APZCTreeManager |
92 | 0 | EventRegions er = aLayer->GetEventRegions(); |
93 | 0 | IntRect scrollRect = RoundedToInt( |
94 | 0 | scrollableRect * metrics.LayersPixelsPerCSSPixel()).ToUnknownRect(); |
95 | 0 | er.mHitRegion = nsIntRegion(IntRect( |
96 | 0 | RoundedToInt(metrics.GetCompositionBounds().TopLeft().ToUnknownPoint()), |
97 | 0 | scrollRect.Size())); |
98 | 0 | aLayer->SetEventRegions(er); |
99 | 0 | } |
100 | 0 | } |
101 | | |
102 | | static void SetScrollableFrameMetrics(Layer* aLayer, FrameMetrics::ViewID aScrollId, |
103 | 0 | CSSRect aScrollableRect = CSSRect(-1, -1, -1, -1)) { |
104 | 0 | ParentLayerIntRect compositionBounds = |
105 | 0 | RoundedToInt(aLayer->GetLocalTransformTyped(). |
106 | 0 | TransformBounds(LayerRect(aLayer->GetVisibleRegion().GetBounds()))); |
107 | 0 | ScrollMetadata metadata = BuildScrollMetadata(aScrollId, aScrollableRect, |
108 | 0 | ParentLayerRect(compositionBounds)); |
109 | 0 | aLayer->SetScrollMetadata(metadata); |
110 | 0 | aLayer->SetClipRect(Some(compositionBounds)); |
111 | 0 | SetEventRegionsBasedOnBottommostMetrics(aLayer); |
112 | 0 | } |
113 | | |
114 | 0 | void SetScrollHandoff(Layer* aChild, Layer* aParent) { |
115 | 0 | ScrollMetadata metadata = aChild->GetScrollMetadata(0); |
116 | 0 | metadata.SetScrollParentId(aParent->GetFrameMetrics(0).GetScrollId()); |
117 | 0 | aChild->SetScrollMetadata(metadata); |
118 | 0 | } |
119 | | |
120 | 0 | static TestAsyncPanZoomController* ApzcOf(Layer* aLayer) { |
121 | 0 | EXPECT_EQ(1u, aLayer->GetScrollMetadataCount()); |
122 | 0 | return (TestAsyncPanZoomController*)aLayer->GetAsyncPanZoomController(0); |
123 | 0 | } |
124 | | |
125 | 0 | static TestAsyncPanZoomController* ApzcOf(Layer* aLayer, uint32_t aIndex) { |
126 | 0 | EXPECT_LT(aIndex, aLayer->GetScrollMetadataCount()); |
127 | 0 | return (TestAsyncPanZoomController*)aLayer->GetAsyncPanZoomController(aIndex); |
128 | 0 | } |
129 | | |
130 | 0 | void CreateSimpleScrollingLayer() { |
131 | 0 | const char* layerTreeSyntax = "t"; |
132 | 0 | nsIntRegion layerVisibleRegion[] = { |
133 | 0 | nsIntRegion(IntRect(0,0,200,200)), |
134 | 0 | }; |
135 | 0 | root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion, nullptr, lm, layers); |
136 | 0 | SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID, CSSRect(0, 0, 500, 500)); |
137 | 0 | } |
138 | | |
139 | 0 | void CreateSimpleDTCScrollingLayer() { |
140 | 0 | const char* layerTreeSyntax = "t"; |
141 | 0 | nsIntRegion layerVisibleRegion[] = { |
142 | 0 | nsIntRegion(IntRect(0,0,200,200)), |
143 | 0 | }; |
144 | 0 | root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion, nullptr, lm, layers); |
145 | 0 | SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID, CSSRect(0, 0, 500, 500)); |
146 | 0 |
|
147 | 0 | EventRegions regions; |
148 | 0 | regions.mHitRegion = nsIntRegion(IntRect(0, 0, 200, 200)); |
149 | 0 | regions.mDispatchToContentHitRegion = regions.mHitRegion; |
150 | 0 | layers[0]->SetEventRegions(regions); |
151 | 0 | } |
152 | | |
153 | 0 | void CreateSimpleMultiLayerTree() { |
154 | 0 | const char* layerTreeSyntax = "c(tt)"; |
155 | 0 | // LayerID 0 12 |
156 | 0 | nsIntRegion layerVisibleRegion[] = { |
157 | 0 | nsIntRegion(IntRect(0,0,100,100)), |
158 | 0 | nsIntRegion(IntRect(0,0,100,50)), |
159 | 0 | nsIntRegion(IntRect(0,50,100,50)), |
160 | 0 | }; |
161 | 0 | root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion, nullptr, lm, layers); |
162 | 0 | } |
163 | | |
164 | 0 | void CreatePotentiallyLeakingTree() { |
165 | 0 | const char* layerTreeSyntax = "c(c(c(t))c(c(t)))"; |
166 | 0 | // LayerID 0 1 2 3 4 5 6 |
167 | 0 | root = CreateLayerTree(layerTreeSyntax, nullptr, nullptr, lm, layers); |
168 | 0 | SetScrollableFrameMetrics(layers[0], FrameMetrics::START_SCROLL_ID); |
169 | 0 | SetScrollableFrameMetrics(layers[2], FrameMetrics::START_SCROLL_ID + 1); |
170 | 0 | SetScrollableFrameMetrics(layers[5], FrameMetrics::START_SCROLL_ID + 1); |
171 | 0 | SetScrollableFrameMetrics(layers[3], FrameMetrics::START_SCROLL_ID + 2); |
172 | 0 | SetScrollableFrameMetrics(layers[6], FrameMetrics::START_SCROLL_ID + 3); |
173 | 0 | } |
174 | | |
175 | 0 | void CreateBug1194876Tree() { |
176 | 0 | const char* layerTreeSyntax = "c(t)"; |
177 | 0 | // LayerID 0 1 |
178 | 0 | nsIntRegion layerVisibleRegion[] = { |
179 | 0 | nsIntRegion(IntRect(0,0,100,100)), |
180 | 0 | nsIntRegion(IntRect(0,0,100,100)), |
181 | 0 | }; |
182 | 0 | root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion, nullptr, lm, layers); |
183 | 0 | SetScrollableFrameMetrics(layers[0], FrameMetrics::START_SCROLL_ID); |
184 | 0 | SetScrollableFrameMetrics(layers[1], FrameMetrics::START_SCROLL_ID + 1); |
185 | 0 | SetScrollHandoff(layers[1], layers[0]); |
186 | 0 |
|
187 | 0 | // Make layers[1] the root content |
188 | 0 | ScrollMetadata childMetadata = layers[1]->GetScrollMetadata(0); |
189 | 0 | childMetadata.GetMetrics().SetIsRootContent(true); |
190 | 0 | layers[1]->SetScrollMetadata(childMetadata); |
191 | 0 |
|
192 | 0 | // Both layers are fully dispatch-to-content |
193 | 0 | EventRegions regions; |
194 | 0 | regions.mHitRegion = nsIntRegion(IntRect(0, 0, 100, 100)); |
195 | 0 | regions.mDispatchToContentHitRegion = regions.mHitRegion; |
196 | 0 | layers[0]->SetEventRegions(regions); |
197 | 0 | layers[1]->SetEventRegions(regions); |
198 | 0 | } |
199 | | }; |
200 | | |
201 | | #endif // mozilla_layers_APZCTreeManagerTester_h |