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/hit_test/aggregated_hit_test_region.h" |
| 10 #include "components/viz/common/surfaces/surface_id.h" |
| 11 #include "components/viz/service/viz_service_export.h" |
| 12 #include "services/viz/hit_test/public/interfaces/hit_test_region_list.mojom.h" |
| 13 |
| 14 namespace viz { |
| 15 |
| 16 // HitTestAggregator collects HitTestRegionList objects from surfaces and |
| 17 // aggregates them into a DisplayHitTesData structue made available in |
| 18 // shared memory to enable efficient hit testing across processes. |
| 19 // |
| 20 // This is intended to be created in the viz or GPU process. For mus+ash this |
| 21 // will be true after the mus process split. |
| 22 class VIZ_SERVICE_EXPORT HitTestAggregator : public cc::SurfaceObserver { |
| 23 public: |
| 24 HitTestAggregator(); |
| 25 ~HitTestAggregator(); |
| 26 |
| 27 // Called when HitTestRegionList is submitted along with every call |
| 28 // to SubmitCompositorFrame. This is collected in pending_ until |
| 29 // surfaces are aggregated and put on the display. |
| 30 void SubmitHitTestRegionList( |
| 31 mojom::HitTestRegionListPtr hit_test_region_list); |
| 32 |
| 33 // Called after surfaces have been aggregated into the DisplayFrame. |
| 34 // In this call HitTestRegionList structures received from active surfaces |
| 35 // are aggregated into the HitTestRegionList structure in |
| 36 // shared memory used for event targetting. |
| 37 void Aggregate(SurfaceId display_surface_id); |
| 38 |
| 39 // Performs the work of Aggregate by creating a PostTask so that |
| 40 // the work is not directly on the call. |
| 41 void PostTaskAggregate(SurfaceId display_surface_id); |
| 42 |
| 43 // Called at BeginFrame. Swaps buffers in shared memory. |
| 44 void Swap(); |
| 45 |
| 46 protected: |
| 47 // cc::SurfaceObserver: |
| 48 void OnSurfaceCreated(const SurfaceInfo& surface_info) override {} |
| 49 void OnSurfaceDestroyed(const SurfaceId& surface_id) override {} |
| 50 bool OnSurfaceDamaged(const SurfaceId& surface_id, |
| 51 const cc::BeginFrameAck& ack) override; |
| 52 void OnSurfaceDiscarded(const SurfaceId& surface_id) override; |
| 53 void OnSurfaceDamageExpected(const SurfaceId& surface_id, |
| 54 const cc::BeginFrameArgs& args) override {} |
| 55 |
| 56 // Called when a surface has been aggregated and added to the |
| 57 // display frame. HitTestRegionList objects are held but ignored until |
| 58 // this happens. HitTestRegionList for the surface is copied from |pending_| |
| 59 // to |active_| in this method. |
| 60 void OnSurfaceWillDraw(const SurfaceId& surface_id) override; |
| 61 |
| 62 // The collection of received HitTestRegionList objects that have not yet |
| 63 // been added to the DisplayFrame (OnSurfaceWillDraw has not been called). |
| 64 std::map<SurfaceId, mojom::HitTestRegionListPtr> pending_; |
| 65 |
| 66 // The collection of HitTestRegionList objects that have been added to the |
| 67 // DisplayFrame (OnSurfaceWillDraw has been called). |
| 68 std::map<SurfaceId, mojom::HitTestRegionListPtr> active_; |
| 69 |
| 70 // Keeps track of the number of regions in the active list |
| 71 // so that we know when we exceed the available length. |
| 72 int active_region_count_ = 0; |
| 73 |
| 74 mojo::ScopedSharedBufferHandle read_handle_; |
| 75 mojo::ScopedSharedBufferHandle write_handle_; |
| 76 |
| 77 // The number of elements allocated. |
| 78 int read_size_ = 0; |
| 79 int write_size_ = 0; |
| 80 |
| 81 mojo::ScopedSharedBufferMapping read_buffer_; |
| 82 mojo::ScopedSharedBufferMapping write_buffer_; |
| 83 |
| 84 private: |
| 85 // Allocates memory for the AggregatedHitTestRegion array. |
| 86 void AllocateHitTestRegionArray(); |
| 87 void AllocateHitTestRegionArray(int length); |
| 88 |
| 89 // Appends the root element to the AggregatedHitTestRegion array. |
| 90 void AppendRoot(SurfaceId surface_id); |
| 91 |
| 92 // Appends a region to the HitTestRegionList structure to recursively |
| 93 // build the tree. |
| 94 int AppendRegion(AggregatedHitTestRegion* regions, |
| 95 int region_index, |
| 96 const mojom::HitTestRegionPtr& region); |
| 97 |
| 98 // Handles the case when this object is deleted after |
| 99 // the PostTaskAggregation call is scheduled but before invocation. |
| 100 base::WeakPtrFactory<HitTestAggregator> weak_ptr_factory_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(HitTestAggregator); |
| 103 }; |
| 104 |
| 105 } // namespace viz |
| 106 |
| 107 #endif // COMPONENTS_VIZ_SERVICE_HIT_TEST_HIT_TEST_AGGREGATOR_H_ |
OLD | NEW |