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 #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 | |
11 namespace { | |
12 constexpr int kInitialSize = 1024; | |
rjkroege
2017/06/07 21:19:05
need a TODO() to figure out what a good initial si
gklassen
2017/06/08 20:33:21
Done.
| |
13 } | |
14 | |
15 using namespace hit_test::mojom; | |
rjkroege
2017/06/07 21:19:05
I'm not keen on this.
gklassen
2017/06/08 20:33:20
Ok. Removed. Done.
| |
16 | |
17 HitTestAggregator::HitTestAggregator() { | |
18 AllocateDisplayHitTestData(); | |
19 } | |
20 HitTestAggregator::~HitTestAggregator() {} | |
21 | |
22 void HitTestAggregator::SubmitHitTestData(HitTestDataPtr hit_test_data) { | |
23 pending_[hit_test_data->surface_id_] = std::move(hit_test_data); | |
24 } | |
25 | |
26 void HitTestAggregator::OnSurfaceDiscarded(const cc::SurfaceId& surface_id) { | |
27 pending_.erase(surface_id); | |
28 active_.erase(surface_id); | |
29 } | |
30 void HitTestAggregator::OnSurfaceWillDraw(const cc::SurfaceId& surface_id) { | |
31 active_[surface_id] = std::move(pending_[surface_id]); | |
rjkroege
2017/06/07 21:19:05
so... when you get another OnSurfaceWillDraw re-u
gklassen
2017/06/08 20:33:20
Thanks. Code added to explicitly check and handle
| |
32 } | |
33 | |
34 void HitTestAggregator::AllocateDisplayHitTestData() { | |
35 AllocateDisplayHitTestData(kInitialSize); | |
36 } | |
37 | |
38 void HitTestAggregator::AllocateDisplayHitTestData(int size) { | |
39 int cb = sizeof(DisplayHitTestData) + size * sizeof(DisplayHitTestRegion); | |
40 display_hit_test_data_ = (DisplayHitTestData*)::operator new(cb); | |
41 | |
42 display_hit_test_data_->size_ = size; | |
rjkroege
2017/06/07 21:19:04
DisplayHitTestData could have a constructor?
gklassen
2017/06/08 20:33:21
It's now a struct ( based on earlier discussion an
| |
43 display_hit_test_data_->front_offset_ = 0; | |
44 display_hit_test_data_->regions_[0].child_count_ = kEndOfList; | |
45 display_hit_test_data_->regions_[size << 2].child_count_ = kEndOfList; | |
rjkroege
2017/06/07 21:19:05
Why do you init it?
gklassen
2017/06/08 20:33:21
It's using child_count == kEndOfList to indicate t
rjkroege
2017/06/09 15:47:07
struct declaration could init (is C++11-ism appare
| |
46 } | |
47 | |
48 void HitTestAggregator::Aggregate(cc::SurfaceId display_surface_id) { | |
49 int index = GetBackIndex(); | |
50 int last_index = Append(display_surface_id, index); | |
51 display_hit_test_data_->regions_[last_index].child_count_ = kEndOfList; | |
52 } | |
53 | |
54 int HitTestAggregator::Append(cc::SurfaceId surface_id, int index) { | |
rjkroege
2017/06/07 21:19:05
completely private methods could be in an anonymou
gklassen
2017/06/08 20:33:21
Thanks. This method currently accesses some membe
rjkroege
2017/06/09 15:47:07
Acknowledged.
| |
55 auto search = active_.find(surface_id); | |
56 if (search == active_.end()) { | |
57 // referenced surface not found! | |
rjkroege
2017/06/07 21:19:05
this indicates a bug in SurfaceAggregator yes? The
gklassen
2017/06/08 20:33:21
Based on earlier conversations I believe it's poss
| |
58 return index; | |
59 } | |
60 HitTestData* hit_test_data = search->second.get(); | |
61 | |
62 if (hit_test_data->regions_.size() == 0) { | |
rjkroege
2017/06/07 21:19:04
we must have at least 1 region for valid data yes?
gklassen
2017/06/08 20:33:21
A surface with no children may have no sub-regions
rjkroege
2017/06/09 15:47:07
A HTD can have HTRs without any of them having the
gklassen
2017/06/12 16:30:41
Right.
| |
63 // if there are no sub-regions then we don't need a bounds check entry | |
64 return index; | |
65 } | |
66 | |
67 DisplayHitTestRegion* element = &display_hit_test_data_->regions_[index]; | |
68 | |
69 int parent_index = index++; | |
70 | |
71 element->frame_sink_id_ = hit_test_data->surface_id_.frame_sink_id(); | |
72 element->flags_ = HitTestRegionFlags::HIT_TEST_BOUNDS; | |
rjkroege
2017/06/07 21:19:04
You have a separate region for the bounds? Why?
gklassen
2017/06/08 20:33:21
After review and discussion this morning I think y
| |
73 element->rect_ = hit_test_data->bounds_; | |
74 | |
75 for (auto& region : hit_test_data->regions_) { | |
76 index = Append(region, index); | |
77 } | |
78 | |
79 element->child_count_ = index - parent_index - 1; | |
rjkroege
2017/06/07 21:19:05
Assumptions here should be wrapped in DCHECK
gklassen
2017/06/08 20:33:21
Agreed. Do you have suggestions for assumptions t
rjkroege
2017/06/09 15:47:07
this one. I'll note all the others that occur to m
gklassen
2017/06/12 16:30:40
Done.
| |
80 return index; | |
81 } | |
82 | |
83 int HitTestAggregator::Append(const HitTestRegionPtr& region, int index) { | |
84 DisplayHitTestRegion* element = &display_hit_test_data_->regions_[index]; | |
85 | |
86 element->frame_sink_id_ = region->surface_id_.frame_sink_id(); | |
87 element->flags_ = region->flags_; | |
88 element->rect_ = region->rect_; | |
89 element->transform_ = region->transform_; | |
90 | |
91 int parent_index = index++; | |
92 | |
93 if (region->flags_ == HitTestRegionFlags::HIT_TEST_CHILD_SURFACE) { | |
94 index = Append(region->surface_id_, index); | |
95 } | |
96 | |
97 element->child_count_ = index - parent_index - 1; | |
98 return index; | |
99 } | |
100 | |
101 void HitTestAggregator::Swap() { | |
102 display_hit_test_data_->front_offset_ = GetBackIndex(); | |
103 } | |
104 | |
105 int HitTestAggregator::GetBackIndex() { | |
106 return display_hit_test_data_->front_offset_ == 0 | |
rjkroege
2017/06/07 21:19:05
if is easier to read?
gklassen
2017/06/08 20:33:20
I wrote it both ways. I think I agree with you.
| |
107 ? display_hit_test_data_->size_ / 2 | |
108 : 0; | |
109 } | |
110 | |
111 DisplayHitTestRegion* HitTestAggregator::GetCurrentRegions() { | |
112 return display_hit_test_data_->regions_ + | |
113 display_hit_test_data_->front_offset_; | |
114 } | |
115 | |
116 } // namespace viz | |
OLD | NEW |