OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_VIZ_SERVICE_HIT_TEST_HIT_TEST_AGGREGATOR_H_ | |
6 #define COMPONENTS_VIZ_SERVICE_HIT_TEST_HIT_TEST_AGGREGATOR_H_ | |
7 | |
8 #include "cc/surfaces/surface_observer.h" | |
9 #include "components/viz/common/aggregated_hit_test_region.h" | |
10 #include "components/viz/common/surface_id.h" | |
11 #include "components/viz/service/viz_service_export.h" | |
12 #include "services/viz/public/interfaces/hit_test_region_list.mojom.h" | |
13 | |
14 namespace viz { | |
15 namespace hit_test { | |
danakj
2017/07/13 15:39:38
just use viz namespace here.
gklassen
2017/07/13 19:59:14
Done.
| |
16 | |
17 namespace test { | |
18 class HitTestAggregatorTest; | |
danakj
2017/07/13 15:39:38
tests are found in the same namespace as the class
gklassen
2017/07/13 19:59:14
Done.
| |
19 } | |
20 | |
21 // HitTestAggregator collects HitTestRegionList objects from surfaces and | |
22 // aggregates them into a DisplayHitTesData structue made available in | |
23 // shared memory to enable efficient hit testing across processes. | |
24 // | |
25 // This is intended to be created in the viz or GPU process. For mus+ash this | |
26 // will be true after the mus process split. | |
27 | |
danakj
2017/07/13 15:39:39
nit: remove whitespace
gklassen
2017/07/13 19:59:14
Done.
| |
28 class VIZ_SERVICE_EXPORT HitTestAggregator : public cc::SurfaceObserver { | |
29 public: | |
30 HitTestAggregator(); | |
31 ~HitTestAggregator(); | |
32 | |
33 // Called when HitTestRegionList is submitted along with every call | |
34 // to SubmitCompositorFrame. This is collected in pending_ until | |
35 // surfaces are aggregated and put on the display. | |
36 void SubmitHitTestRegionList( | |
37 hit_test::mojom::HitTestRegionListPtr hit_test_region_list); | |
38 | |
39 // Called after surfaces have been aggregated into the DisplayFrame. | |
40 // In this call HitTestRegionList structures received from active surfaces | |
41 // are aggregated into the HitTestRegionList structure in | |
42 // shared memory used for event targetting. | |
43 void Aggregate(SurfaceId display_surface_id); | |
44 | |
45 // Performs the work of Aggregate by creating a PostTask so that | |
46 // the work is not directly on the call. | |
47 void PostTaskAggregate(SurfaceId display_surface_id); | |
48 | |
49 // Called at BeginFrame. Swaps buffers in shared memory. | |
50 void Swap(); | |
51 | |
52 private: | |
53 friend class test::HitTestAggregatorTest; | |
danakj
2017/07/13 15:39:39
There are nicer ways to expose things to tests tha
gklassen
2017/07/13 19:59:14
Thank you. I've looked at this a few times and th
danakj
2017/07/14 15:27:37
I wouldn't block you from this, but I just don't r
gklassen
2017/07/14 16:54:45
Thank you. Using a friend class bothered Rob as w
| |
54 | |
55 // Allocates memory for the AggregatedHitTestRegion array. | |
56 void AllocateHitTestRegionArray(); | |
57 void AllocateHitTestRegionArray(int length); | |
58 | |
59 // Appends the root element to the AggregatedHitTestRegion array. | |
60 void AppendRoot(SurfaceId surface_id); | |
61 | |
62 // Appends a region to the HitTestRegionList structure to recursively | |
63 // build the tree. | |
64 int AppendRegion(AggregatedHitTestRegion* regions, | |
65 const hit_test::mojom::HitTestRegionPtr& region, | |
66 int index); | |
danakj
2017/07/13 15:39:38
nit: i'd group index and regions together since it
gklassen
2017/07/13 19:59:14
Done.
| |
67 | |
68 // cc::SurfaceObserver: | |
69 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override {} | |
70 void OnSurfaceDestroyed(const SurfaceId& surface_id) override {} | |
71 bool OnSurfaceDamaged(const SurfaceId& surface_id, | |
72 const cc::BeginFrameAck& ack) override; | |
73 void OnSurfaceDiscarded(const SurfaceId& surface_id) override; | |
74 void OnSurfaceDamageExpected(const SurfaceId& surface_id, | |
75 const cc::BeginFrameArgs& args) override {} | |
76 | |
77 // Called when a surface has been aggregated and added to the | |
78 // display frame. HitTestRegionList objects are held but ignored until | |
79 // this happens. HitTestRegionList for the surface is copied from |pending_| | |
80 // to |active_| in this method. | |
81 void OnSurfaceWillDraw(const SurfaceId& surface_id) override; | |
82 | |
83 using HitTestRegionListMap = | |
danakj
2017/07/13 15:39:39
nit: Now that we have auto, usually I think it's b
gklassen
2017/07/13 19:59:14
Done.
| |
84 std::map<SurfaceId, hit_test::mojom::HitTestRegionListPtr>; | |
danakj
2017/07/13 15:39:38
How big is this going to be, what is the usage pat
gklassen
2017/07/13 19:59:14
Thank you. After review std::map still seems like
| |
85 | |
86 // The collection of received HitTestRegionList objects that have not yet | |
87 // been added to the DisplayFrame (OnSurfaceWillDraw has not been called). | |
88 HitTestRegionListMap pending_; | |
89 | |
90 // The collection of HitTestRegionList objects that have been added to the | |
91 // DisplayFrame (OnSurfaceWillDraw has been called). | |
92 HitTestRegionListMap active_; | |
93 | |
94 // Keeps track of the number of regions in the active list | |
95 // so that we know when we exceed the available length. | |
96 int active_region_count_; | |
97 | |
98 mojo::ScopedSharedBufferHandle read_handle_; | |
99 mojo::ScopedSharedBufferHandle write_handle_; | |
100 | |
101 // The number of elements allocated. | |
102 int read_size_; | |
103 int write_size_; | |
104 | |
105 mojo::ScopedSharedBufferMapping read_buffer_; | |
106 mojo::ScopedSharedBufferMapping write_buffer_; | |
107 | |
108 // Handles the case when this object is deleted after | |
109 // the PostTaskAggregation call is scheduled but before invocation. | |
110 base::WeakPtrFactory<HitTestAggregator> weak_ptr_factory_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(HitTestAggregator); | |
113 }; | |
114 | |
115 } // namespace hit_test | |
116 } // namespace viz | |
117 | |
118 #endif // COMPONENTS_VIZ_SERVICE_HIT_TEST_HIT_TEST_AGGREGATOR_H_ | |
OLD | NEW |