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 collects HitTestData objects from surfaces and |
| 23 // aggregates them into a DisplayHitTesData structue made available in |
| 24 // shared memory to enable efficient hit testing across processes. |
| 25 // |
| 26 // This is intended to be created in the viz or GPU process. For mus+ash this |
| 27 // will be true after the mus process split. |
| 28 |
| 29 using HitTestDataMap = std::map<cc::SurfaceId, hit_test::mojom::HitTestDataPtr>; |
| 30 |
| 31 class VIZ_SERVICE_EXPORT HitTestAggregator : public cc::SurfaceObserver { |
| 32 public: |
| 33 HitTestAggregator( |
| 34 std::unique_ptr<DisplayHitTestDataFactory> display_hit_test_data_factory); |
| 35 ~HitTestAggregator(); |
| 36 |
| 37 // Called when HitTestData is submitted along with every call |
| 38 // to SubmitCompositorFrame. This is collected in pending_ until |
| 39 // surfaces are aggregated and put on the display. |
| 40 void SubmitHitTestData(hit_test::mojom::HitTestDataPtr hit_test_data); |
| 41 |
| 42 // Called after surfaces have been aggregated into the DisplayFrame. |
| 43 // In this call HitTestData structures received from active surfaces |
| 44 // are aggregated into the DisplayHitTestData structure in |
| 45 // shared memory used for event targetting. |
| 46 void Aggregate(cc::SurfaceId display_surface_id); |
| 47 |
| 48 // Performs the work of Aggregate by creating a PostTask so that |
| 49 // the work is not directly on the call. |
| 50 void PostTaskAggregate(cc::SurfaceId display_surface_id); |
| 51 |
| 52 // Called at BeginFrame. Swaps buffers in shared memory. |
| 53 void Swap(); |
| 54 |
| 55 // Returns a pointer to the DisplayHitTestRegion list currently |
| 56 // used for hit-testing. |
| 57 DisplayHitTestRegion* GetCurrentRegions(); |
| 58 |
| 59 private: |
| 60 friend class test::HitTestAggregatorTest; |
| 61 |
| 62 // Allocates memory for the DisplayHitTestData Structure. |
| 63 void AllocateDisplayHitTestData(); |
| 64 void AllocateDisplayHitTestData(int length); |
| 65 |
| 66 // Appends the root element to the DisplayHitTestData structure. |
| 67 void AppendRoot(cc::SurfaceId surface_id); |
| 68 |
| 69 // Appends a region to the DisplayHitTestData structure to recursively |
| 70 // build the tree. |
| 71 int AppendRegion(const hit_test::mojom::HitTestRegionPtr& region, int index); |
| 72 |
| 73 // cc:SurfaceObserver |
| 74 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override {} |
| 75 void OnSurfaceDestroyed(const cc::SurfaceId& surface_id) override {} |
| 76 bool OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 77 const cc::BeginFrameAck& ack) override; |
| 78 void OnSurfaceDiscarded(const cc::SurfaceId& surface_id) override; |
| 79 void OnSurfaceDamageExpected(const cc::SurfaceId& surface_id, |
| 80 const cc::BeginFrameArgs& args) override {} |
| 81 |
| 82 // Called when a surface has been aggregated and added to the |
| 83 // display frame. HitTestData objects are held but ignored until |
| 84 // this happens. HitTestData for the surface is copied from |pending_| |
| 85 // to |active_| in this method. |
| 86 void OnSurfaceWillDraw(const cc::SurfaceId& surface_id) override; |
| 87 |
| 88 // The collection of received HitTestData objects that have not yet |
| 89 // been added to the DisplayFrame ( OnSurfaceWillDraw has not been called ). |
| 90 HitTestDataMap pending_; |
| 91 |
| 92 // The collection of HitTestData objects that have need added to the |
| 93 // DisplayFrame ( OnSurfaceWillDraw has been called ). |
| 94 HitTestDataMap active_; |
| 95 |
| 96 // Keeps track of the number of regions in the active list |
| 97 // so that we know when we exceed the available length. |
| 98 int active_region_count_; |
| 99 |
| 100 // The object used to allocate memory for the DisplayHitTestData structure. |
| 101 std::unique_ptr<DisplayHitTestDataFactory> display_hit_test_data_factory_; |
| 102 |
| 103 DisplayHitTestData* read_display_hit_test_data_; |
| 104 DisplayHitTestData* write_display_hit_test_data_; |
| 105 |
| 106 // WeakPtr to handle the case when this object is deleted after |
| 107 // the PostTaskAggregation call is scheduled but before invocation. |
| 108 base::WeakPtrFactory<HitTestAggregator> weak_ptr_factory_; |
| 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(HitTestAggregator); |
| 111 }; |
| 112 |
| 113 } // namespace hit_test |
| 114 } // namespace viz |
| 115 |
| 116 #endif // COMPONENTS_VIZ_SERVICE_HIT_TEST_HIT_TEST_AGGREGATOR_H_ |
OLD | NEW |