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/viz_service_export.h" |
| 12 #include "services/viz/hit_test/public/interfaces/hit_test_data.mojom.h" |
| 13 |
| 14 namespace viz { |
| 15 namespace hit_test { |
| 16 |
| 17 namespace test { |
| 18 class HitTestAggregatorTest; |
| 19 } |
| 20 |
| 21 // HitTestAggregator collects HitTestData 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 HitTestData 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 SubmitHitTestData(hit_test::mojom::HitTestDataPtr hit_test_data); |
| 37 |
| 38 // Called after surfaces have been aggregated into the DisplayFrame. |
| 39 // In this call HitTestData structures received from active surfaces |
| 40 // are aggregated into the DisplayHitTestData structure in |
| 41 // shared memory used for event targetting. |
| 42 void Aggregate(cc::SurfaceId display_surface_id); |
| 43 |
| 44 // Performs the work of Aggregate by creating a PostTask so that |
| 45 // the work is not directly on the call. |
| 46 void PostTaskAggregate(cc::SurfaceId display_surface_id); |
| 47 |
| 48 // Called at BeginFrame. Swaps buffers in shared memory. |
| 49 void Swap(); |
| 50 |
| 51 private: |
| 52 friend class test::HitTestAggregatorTest; |
| 53 |
| 54 // Allocates memory for the DisplayHitTestData Structure. |
| 55 void AllocateDisplayHitTestData(); |
| 56 void AllocateDisplayHitTestData(int length); |
| 57 |
| 58 // Appends the root element to the DisplayHitTestData structure. |
| 59 void AppendRoot(cc::SurfaceId surface_id); |
| 60 |
| 61 // Appends a region to the DisplayHitTestData structure to recursively |
| 62 // build the tree. |
| 63 int AppendRegion(DisplayHitTestRegion* regions, |
| 64 const hit_test::mojom::HitTestRegionPtr& region, |
| 65 int index); |
| 66 |
| 67 // cc:SurfaceObserver: |
| 68 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override {} |
| 69 void OnSurfaceDestroyed(const cc::SurfaceId& surface_id) override {} |
| 70 bool OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 71 const cc::BeginFrameAck& ack) override; |
| 72 void OnSurfaceDiscarded(const cc::SurfaceId& surface_id) override; |
| 73 void OnSurfaceDamageExpected(const cc::SurfaceId& surface_id, |
| 74 const cc::BeginFrameArgs& args) override {} |
| 75 |
| 76 // Called when a surface has been aggregated and added to the |
| 77 // display frame. HitTestData objects are held but ignored until |
| 78 // this happens. HitTestData for the surface is copied from |pending_| |
| 79 // to |active_| in this method. |
| 80 void OnSurfaceWillDraw(const cc::SurfaceId& surface_id) override; |
| 81 |
| 82 using HitTestDataMap = |
| 83 std::map<cc::SurfaceId, hit_test::mojom::HitTestDataPtr>; |
| 84 |
| 85 // The collection of received HitTestData objects that have not yet |
| 86 // been added to the DisplayFrame ( OnSurfaceWillDraw has not been called ). |
| 87 HitTestDataMap pending_; |
| 88 |
| 89 // The collection of HitTestData objects that have need added to the |
| 90 // DisplayFrame ( OnSurfaceWillDraw has been called ). |
| 91 HitTestDataMap active_; |
| 92 |
| 93 // Keeps track of the number of regions in the active list |
| 94 // so that we know when we exceed the available length. |
| 95 int active_region_count_; |
| 96 |
| 97 mojo::ScopedSharedBufferHandle read_handle_; |
| 98 mojo::ScopedSharedBufferHandle write_handle_; |
| 99 |
| 100 int read_size_; |
| 101 int write_size_; |
| 102 |
| 103 mojo::ScopedSharedBufferMapping MapReadBuffer(); |
| 104 mojo::ScopedSharedBufferMapping MapWriteBuffer(); |
| 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 |