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/display_hit_test_region.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 { |
| 16 |
| 17 namespace test { |
| 18 class HitTestAggregatorTest; |
| 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 |
| 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 DisplayHitTestRegionList structure in |
| 42 // shared memory used for event targetting. |
| 43 void Aggregate(cc::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(cc::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; |
| 54 |
| 55 // Allocates memory for the DisplayHitTestRegionList Structure. |
| 56 void AllocateDisplayHitTestRegionList(); |
| 57 void AllocateDisplayHitTestRegionList(int length); |
| 58 |
| 59 // Appends the root element to the DisplayHitTestRegionList structure. |
| 60 void AppendRoot(cc::SurfaceId surface_id); |
| 61 |
| 62 // Appends a region to the DisplayHitTestRegionList structure to recursively |
| 63 // build the tree. |
| 64 int AppendRegion(DisplayHitTestRegion* regions, |
| 65 const hit_test::mojom::HitTestRegionPtr& region, |
| 66 int index); |
| 67 |
| 68 // cc::SurfaceObserver: |
| 69 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override {} |
| 70 void OnSurfaceDestroyed(const cc::SurfaceId& surface_id) override {} |
| 71 bool OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 72 const cc::BeginFrameAck& ack) override; |
| 73 void OnSurfaceDiscarded(const cc::SurfaceId& surface_id) override; |
| 74 void OnSurfaceDamageExpected(const cc::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 cc::SurfaceId& surface_id) override; |
| 82 |
| 83 using HitTestRegionListMap = |
| 84 std::map<cc::SurfaceId, hit_test::mojom::HitTestRegionListPtr>; |
| 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 |