Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: components/viz/hit_test/hit_test_aggregator.cc

Issue 2908783002: WIP Hittest Component.
Patch Set: fix z-order in use case tests ( background rects at the back ) Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "components/viz/hit_test/hit_test_aggregator.h"
6 #include "base/logging.h"
7 #include "display_hit_test_data.h"
8
9 namespace viz {
10 namespace hit_test {
11
12 namespace {
13 // TODO: Review and select appropriate initial size ( based on telemetry? ).
rjkroege 2017/06/09 15:47:08 convention is TODO(gklassen): i.e.: every TODO i
gklassen 2017/06/12 16:30:41 Done. Thank you. I like that.
14 constexpr int kInitialSize = 1024;
15 }
16
17 HitTestAggregator::HitTestAggregator() : weak_ptr_factory_(this) {
18 AllocateDisplayHitTestData();
19 }
20 HitTestAggregator::~HitTestAggregator() {}
21
22 void HitTestAggregator::SubmitHitTestData(
23 hit_test::mojom::HitTestDataPtr hit_test_data) {
24 // TODO: Review what to do if the submitted data is invalid.
25 pending_[hit_test_data->surface_id_] = std::move(hit_test_data);
26 }
27
28 void HitTestAggregator::OnSurfaceDiscarded(const cc::SurfaceId& surface_id) {
29 pending_.erase(surface_id);
30 active_.erase(surface_id);
31 }
32 void HitTestAggregator::OnSurfaceWillDraw(const cc::SurfaceId& surface_id) {
rjkroege 2017/06/09 15:47:08 I like a blank line between defns
gklassen 2017/06/12 16:30:41 Me too. Thanks for the catch. Done.
33 auto search = pending_.find(surface_id);
34 if (search == pending_.end()) {
35 // Have already activated pending hit_test_data objects for this surface.
36 return;
37 }
38 active_[surface_id] = std::move(pending_[surface_id]);
rjkroege 2017/06/09 15:47:08 DCHECK that active_[surface_id] exists
gklassen 2017/06/12 16:30:41 It may not exist though? pending_ must exist but
39 pending_.erase(surface_id);
40 }
41
42 void HitTestAggregator::AllocateDisplayHitTestData() {
43 AllocateDisplayHitTestData(kInitialSize);
44 }
45
46 void HitTestAggregator::AllocateDisplayHitTestData(int size) {
47 int cb = sizeof(DisplayHitTestData) + size * sizeof(DisplayHitTestRegion);
48 display_hit_test_data_ = (DisplayHitTestData*)::operator new(cb);
rjkroege 2017/06/09 15:47:08 i don't understand this line. And assuming that I
gklassen 2017/06/12 16:30:41 Agreed. As discussed I've updated this code moder
49
50 display_hit_test_data_->size_ = size;
51 display_hit_test_data_->read_offset_ = 0;
52 display_hit_test_data_->regions_[0].child_count_ = kEndOfList;
53 display_hit_test_data_->regions_[size << 2].child_count_ = kEndOfList;
54 }
55
56 void HitTestAggregator::PostTaskAggregate(cc::SurfaceId display_surface_id) {
57 base::ThreadTaskRunnerHandle::Get()->PostTask(
58 FROM_HERE,
59 base::BindOnce(&HitTestAggregator::Aggregate,
60 weak_ptr_factory_.GetWeakPtr(), display_surface_id));
61 }
62
63 void HitTestAggregator::Aggregate(cc::SurfaceId display_surface_id) {
64 int index = GetBackIndex();
65 int last_index = Append(display_surface_id, index);
66 display_hit_test_data_->regions_[last_index].child_count_ = kEndOfList;
67 }
68
69 int HitTestAggregator::Append(cc::SurfaceId surface_id, int index) {
70 auto search = active_.find(surface_id);
71 if (search == active_.end()) {
72 // Referenced surface not found ( it may be late ).
73 return index;
74 }
75 hit_test::mojom::HitTestData* hit_test_data = search->second.get();
76
77 for (auto& region : hit_test_data->regions_) {
78 index = Append(region, index);
79 }
80 return index;
81 }
82
83 int HitTestAggregator::Append(const hit_test::mojom::HitTestRegionPtr& region,
rjkroege 2017/06/09 15:47:08 You need to make certain that you handle what happ
84 int index) {
85 DisplayHitTestRegion* element = &display_hit_test_data_->regions_[index];
86
87 element->frame_sink_id_ = region->surface_id_.frame_sink_id();
rjkroege 2017/06/09 15:47:08 Observation: not very C++-ish. Some might complain
gklassen 2017/06/12 16:30:41 Suggestions welcome - how can I make this more C++
rjkroege 2017/06/12 18:13:00 not clear. leave it
88 element->flags_ = region->flags_;
89 element->rect_ = region->rect_;
90 element->transform_ = region->transform_;
91
92 int parent_index = index++;
93
94 if (region->flags_ ==
rjkroege 2017/06/09 15:47:08 have to &. Multiple flags can be simultaneously d
gklassen 2017/06/12 16:30:41 Acknowledged.
rjkroege 2017/06/12 18:13:00 but... you didn't change the code?
95 hit_test::mojom::HitTestRegionFlags::HIT_TEST_CHILD_SURFACE) {
96 index = Append(region->surface_id_, index);
97 }
98
99 element->child_count_ = index - parent_index - 1;
100 return index;
101 }
102
103 void HitTestAggregator::Swap() {
104 display_hit_test_data_->read_offset_ = GetBackIndex();
105 }
106
107 int HitTestAggregator::GetBackIndex() {
108 if (display_hit_test_data_->read_offset_ == 0)
109 return display_hit_test_data_->size_ / 2;
110 return 0;
111 }
112
113 DisplayHitTestRegion* HitTestAggregator::GetCurrentRegions() {
114 return display_hit_test_data_->regions_ +
115 display_hit_test_data_->read_offset_;
116 }
117
118 } // namespace hit_test
119 } // namespace viz
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698