Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: components/viz/hit_test/hit_test_aggregator.h

Issue 2908783002: WIP Hittest Component.
Patch Set: change HitTestFlags to constants so we can mix and match and convert to struct naming convention Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_HIT_TEST_HIT_TEST_AGGREGATOR_H_
6 #define COMPONENTS_VIZ_HIT_TEST_HIT_TEST_AGGREGATOR_H_
7
8 #include <stdint.h>
9
10 #include <map>
11 #include <memory>
12
13 #include "cc/surfaces/surface_id.h"
14 #include "cc/surfaces/surface_observer.h"
15 #include "components/viz/hit_test/display_hit_test_data.h"
16 #include "components/viz/hit_test/display_hit_test_data_factory.h"
17 #include "components/viz/hit_test/hit_test_export.h"
18 #include "components/viz/hit_test/public/interfaces/hit_test_data.mojom.h"
19 #include "ui/gfx/geometry/quad_f.h"
20
21 namespace viz {
22 namespace hit_test {
23
24 namespace test {
25 class HitTestAggregatorTest;
26 }
27
28 // HitTest maintains maping between display regions and associated surfaces
29 // in shared memory to enable efficient hit testing across processes.
30 //
31 // This is intended to be created in the viz or GPU process. For mus+ash this
32 // will be true after the mus process split.
33
34 using HitTestDataMap = std::map<cc::SurfaceId, hit_test::mojom::HitTestDataPtr>;
35
36 class HIT_TEST_EXPORT HitTestAggregator : public cc::SurfaceObserver {
37 public:
38 HitTestAggregator(
39 std::unique_ptr<DisplayHitTestDataFactory> display_hit_test_data_factory);
40 ~HitTestAggregator();
41
42 // Called when HitTestData is submitted along with every call
43 // to SubmitCompositorFrame. This is collected in pending_ until
44 // surfaces are aggregated and put on the display.
45 void SubmitHitTestData(hit_test::mojom::HitTestDataPtr hit_test_data);
46
47 // Called after surfaces have been aggregated into the DisplayFrame.
48 // In this call HitTestData structures received from active surfaces
49 // are aggregated into the DisplayHitTestData structure in
50 // shared memory used for event targetting.
51 void PostTaskAggregate(cc::SurfaceId display_surface_id);
52 void Aggregate(cc::SurfaceId display_surface_id);
53
54 // Called at BeginFrame to swap buffers in shared memory.
55 void Swap();
56
57 // SurfaceObserver
58 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override {}
59 void OnSurfaceDestroyed(const cc::SurfaceId& surface_id) override {}
60 void OnSurfaceDamaged(const cc::SurfaceId& surface_id,
61 const cc::BeginFrameAck& ack,
62 bool* changed) override {}
63 void OnSurfaceDiscarded(const cc::SurfaceId& surface_id) override;
64 void OnSurfaceDamageExpected(const cc::SurfaceId& surface_id,
65 const cc::BeginFrameArgs& args) override {}
66 // Called when a surface has been aggregated and added to the
67 // display frame. HitTestData objects are held but ignored until
68 // this happens. HitTestData for the surface is copied from pending_
69 // to active_ in this method.
70 void OnSurfaceWillDraw(const cc::SurfaceId& surface_id) override;
71
72 DisplayHitTestData* GetDisplayHitTestData();
73 DisplayHitTestRegion* GetCurrentRegions();
74
75 private:
76 friend class viz::hit_test::test::HitTestAggregatorTest;
77
78 HitTestDataMap pending_;
79 HitTestDataMap active_;
80
81 // Keep track of the number of regions in the active list
82 // so that we know when we exceed the available length.
83 int active_region_count_;
84
85 std::unique_ptr<DisplayHitTestDataFactory> display_hit_test_data_factory_;
86
87 DisplayHitTestData* display_hit_test_data_;
88
89 // Allocates memory for the DisplayHitTestData Structure.
90 void AllocateDisplayHitTestData();
91 void AllocateDisplayHitTestData(int length);
92
93 // Resize the memory for the DispalyHitTestData Structure.
94 // Copies current data and marks the structure
95 void ResizeDisplayHitTestData(int length);
96
97 int GetBackIndex();
98
99 int Append(cc::SurfaceId surface_id, int index);
100 int Append(const hit_test::mojom::HitTestRegionPtr& region, int index);
101
102 // WeakPtr to handle the case when this object is deleted after
103 // the PostTaskAggregation call is scheduled but before invocation.
104 base::WeakPtrFactory<HitTestAggregator> weak_ptr_factory_;
105
106 DISALLOW_COPY_AND_ASSIGN(HitTestAggregator);
107 };
108
109 } // namespace hit_test
110 } // namespace viz
111
112 #endif // COMPONENTS_VIZ_HIT_TEST_HIT_TEST_AGGREGATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698