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