Chromium Code Reviews| 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_id.h" | |
| 9 #include "cc/surfaces/surface_observer.h" | |
| 10 #include "components/viz/common/hit_test/display_hit_test_data.h" | |
| 11 #include "components/viz/service/hit_test/display_hit_test_data_factory.h" | |
| 12 #include "components/viz/service/viz_service_export.h" | |
| 13 #include "services/viz/hit_test/public/interfaces/hit_test_data.mojom.h" | |
| 14 | |
| 15 namespace viz { | |
| 16 namespace hit_test { | |
| 17 | |
| 18 namespace test { | |
| 19 class HitTestAggregatorTest; | |
| 20 } | |
| 21 | |
| 22 // HitTestAggregator maintains maping between display regions and associated | |
| 23 // surfaces in 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 | |
| 28 using HitTestDataMap = std::map<cc::SurfaceId, hit_test::mojom::HitTestDataPtr>; | |
|
varkha
2017/06/20 19:56:59
Does this need to be visible publicly?
gklassen
2017/06/26 21:55:20
Done.
| |
| 29 | |
| 30 class VIZ_SERVICE_EXPORT HitTestAggregator : public cc::SurfaceObserver { | |
| 31 public: | |
| 32 HitTestAggregator( | |
| 33 std::unique_ptr<DisplayHitTestDataFactory> display_hit_test_data_factory); | |
| 34 ~HitTestAggregator(); | |
| 35 | |
| 36 // Called when HitTestData is submitted along with every call | |
| 37 // to SubmitCompositorFrame. This is collected in pending_ until | |
| 38 // surfaces are aggregated and put on the display. | |
| 39 void SubmitHitTestData(hit_test::mojom::HitTestDataPtr hit_test_data); | |
| 40 | |
| 41 // Called after surfaces have been aggregated into the DisplayFrame. | |
| 42 // In this call HitTestData structures received from active surfaces | |
| 43 // are aggregated into the DisplayHitTestData structure in | |
| 44 // shared memory used for event targetting. | |
| 45 void Aggregate(cc::SurfaceId display_surface_id); | |
|
varkha
2017/06/20 19:56:59
Q: Do both Aggregate and PostTaskAggregate need to
gklassen
2017/06/26 21:55:20
Done.
| |
| 46 | |
| 47 // Performs the work of Aggregate by creating a PostTask so that | |
| 48 // the work is not directly on the call. | |
| 49 void PostTaskAggregate(cc::SurfaceId display_surface_id); | |
| 50 | |
| 51 // Called at BeginFrame. Swaps buffers in shared memory. | |
| 52 void Swap(); | |
| 53 | |
| 54 // Returns a pointer to the DisplayHitTestRegion list currently | |
| 55 // used for hit-testing. | |
| 56 DisplayHitTestRegion* GetCurrentRegions(); | |
| 57 | |
| 58 private: | |
| 59 friend class test::HitTestAggregatorTest; | |
| 60 | |
| 61 // Allocates memory for the DisplayHitTestData Structure. | |
| 62 void AllocateDisplayHitTestData(); | |
| 63 void AllocateDisplayHitTestData(int length); | |
| 64 | |
| 65 // Resizes the memory for the DisplayHitTestData Structure. | |
| 66 // Copies current data and marks the current structure as old. | |
| 67 void ResizeDisplayHitTestData(int length); | |
| 68 | |
| 69 int GetBackIndex(); | |
|
varkha
2017/06/20 19:56:59
nit: doc.
gklassen
2017/06/26 21:55:19
Done.
| |
| 70 | |
| 71 // Appends the root element to the DisplayHitTestData structure. | |
| 72 int AppendRoot(cc::SurfaceId surface_id, int index); | |
| 73 | |
| 74 // Appends a region to the DisplayHitTestData structure to recursively | |
| 75 // build the tree. | |
| 76 int AppendRegion(const hit_test::mojom::HitTestRegionPtr& region, int index); | |
| 77 | |
| 78 // cc:SurfaceObserver | |
|
varkha
2017/06/20 19:56:59
nit: cc::SurfaceObserver:
gklassen
2017/06/26 21:55:20
Done.
| |
| 79 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override {} | |
| 80 void OnSurfaceDestroyed(const cc::SurfaceId& surface_id) override {} | |
| 81 bool OnSurfaceDamaged(const cc::SurfaceId& surface_id, | |
| 82 const cc::BeginFrameAck& ack) override; | |
| 83 void OnSurfaceDiscarded(const cc::SurfaceId& surface_id) override; | |
| 84 void OnSurfaceDamageExpected(const cc::SurfaceId& surface_id, | |
| 85 const cc::BeginFrameArgs& args) override {} | |
| 86 | |
| 87 // Called when a surface has been aggregated and added to the | |
| 88 // display frame. HitTestData objects are held but ignored until | |
| 89 // this happens. HitTestData for the surface is copied from |pending_| | |
| 90 // to |active_| in this method. | |
| 91 void OnSurfaceWillDraw(const cc::SurfaceId& surface_id) override; | |
| 92 | |
| 93 // The collection of received HitTestData objects that have not yet | |
| 94 // been added to the DisplayFrame ( OnSurfaceWillDraw has not been called ). | |
| 95 HitTestDataMap pending_; | |
| 96 | |
| 97 // The collection of HitTestData objects that have need added to the | |
| 98 // DisplayFrame ( OnSurfaceWillDraw has been called ). | |
| 99 HitTestDataMap active_; | |
| 100 | |
| 101 // Keeps track of the number of regions in the active list | |
| 102 // so that we know when we exceed the available length. | |
| 103 int active_region_count_; | |
| 104 | |
| 105 // The object used to allocate memory for the DisplayHitTestData structure. | |
| 106 std::unique_ptr<DisplayHitTestDataFactory> display_hit_test_data_factory_; | |
| 107 | |
| 108 DisplayHitTestData* display_hit_test_data_; | |
| 109 | |
| 110 // WeakPtr to handle the case when this object is deleted after | |
| 111 // the PostTaskAggregation call is scheduled but before invocation. | |
| 112 base::WeakPtrFactory<HitTestAggregator> weak_ptr_factory_; | |
| 113 | |
| 114 DISALLOW_COPY_AND_ASSIGN(HitTestAggregator); | |
| 115 }; | |
| 116 | |
| 117 } // namespace hit_test | |
| 118 } // namespace viz | |
| 119 | |
| 120 #endif // COMPONENTS_VIZ_SERVICE_HIT_TEST_HIT_TEST_AGGREGATOR_H_ | |
|
varkha
2017/06/20 19:56:59
nit: extra space after //
varkha
2017/06/20 19:56:59
nit: extra space after //
gklassen
2017/06/26 21:55:20
Done.
gklassen
2017/06/26 21:55:20
Done.
| |
| OLD | NEW |