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

Side by Side Diff: cc/surfaces/surface_hittest.cc

Issue 1265013003: Adds support for hittesting points on surface quads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: recursing into RenderPassDrawQuads, checking for clipped_rect, checking for occluded quads Created 5 years, 4 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
« no previous file with comments | « cc/surfaces/surface_hittest.h ('k') | cc/surfaces/surface_hittest_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 <iostream>
jbauman 2015/08/05 23:33:22 Remove this.
lfg 2015/08/06 18:28:12 Oops. Done.
6
7 #include "cc/surfaces/surface_hittest.h"
8
9 #include "cc/output/compositor_frame.h"
10 #include "cc/output/delegated_frame_data.h"
11 #include "cc/quads/draw_quad.h"
12 #include "cc/quads/render_pass_draw_quad.h"
13 #include "cc/quads/surface_draw_quad.h"
14 #include "cc/surfaces/surface.h"
15 #include "cc/surfaces/surface_manager.h"
16 #include "ui/gfx/geometry/point.h"
17 #include "ui/gfx/transform.h"
18
19 namespace cc {
20 namespace {
21 const RenderPass* GetRootRenderPass(SurfaceManager* manager,
22 SurfaceId surface_id) {
23 Surface* surface = manager->GetSurfaceForId(surface_id);
24
25 const CompositorFrame* surface_frame = surface->GetEligibleFrame();
26 if (!surface_frame)
27 return nullptr;
28
29 const DelegatedFrameData* frame_data =
30 surface_frame->delegated_frame_data.get();
31 return frame_data->render_pass_list.empty()
32 ? nullptr
33 : frame_data->render_pass_list.back();
34 }
35 }
36
37 SurfaceHittest::SurfaceHittest(SurfaceManager* manager) : manager_(manager) {}
38
39 SurfaceHittest::~SurfaceHittest() {}
40
41 SurfaceId SurfaceHittest::Hittest(SurfaceId surface_id,
42 const gfx::Point& point,
43 gfx::Point* transformed_point) {
44 SurfaceId hittest_surface_id = surface_id;
45
46 if (transformed_point)
47 *transformed_point = point;
48
49 hittest_surface_id =
50 HittestInternal(surface_id, GetRootRenderPass(manager_, surface_id),
51 point, transformed_point);
52
53 referenced_surfaces_.clear();
54
55 return hittest_surface_id;
56 }
57
58 SurfaceId SurfaceHittest::HittestInternal(SurfaceId surface_id,
59 const RenderPass* render_pass,
60 const gfx::Point& point,
61 gfx::Point* out_transformed_point) {
62 gfx::Transform transform_from_root_target;
63 if (!render_pass ||
64 !render_pass->transform_to_root_target.GetInverse(
65 &transform_from_root_target)) {
66 return surface_id;
67 }
68
69 gfx::Point point_in_target_space(point);
70 transform_from_root_target.TransformPoint(&point_in_target_space);
71
72 for (const auto* quad : render_pass->quad_list) {
73 // First we test against the clip_rect. The clip_rect is in target space, so
74 // we can test the point directly.
75 if (!quad->shared_quad_state->is_clipped ||
76 (point_in_target_space.x() > quad->shared_quad_state->clip_rect.x() &&
jbauman 2015/08/05 23:33:22 quad->shared_quad_state->clip_rect.Contains(point_
lfg 2015/08/06 18:28:12 Done. Just a note: in the previous code I was also
77 point_in_target_space.y() > quad->shared_quad_state->clip_rect.y() &&
78 point_in_target_space.x() <=
79 quad->shared_quad_state->clip_rect.x() +
80 quad->shared_quad_state->clip_rect.width() &&
81 point_in_target_space.y() <=
82 quad->shared_quad_state->clip_rect.y() +
83 quad->shared_quad_state->clip_rect.height())) {
84 // We now transform the point to content space and test if it hits the
85 // rect.
86 gfx::Transform target_to_quad_transform;
87 if (quad->shared_quad_state->quad_to_target_transform.GetInverse(
88 &target_to_quad_transform)) {
89 gfx::Point transformed_point(point_in_target_space);
90 target_to_quad_transform.TransformPoint(&transformed_point);
91
92 if (transformed_point.x() > quad->rect.x() &&
jbauman 2015/08/05 23:33:22 Contains here too.
lfg 2015/08/06 18:28:12 Done.
93 transformed_point.y() > quad->rect.y() &&
94 transformed_point.x() <= quad->rect.x() + quad->rect.width() &&
95 transformed_point.y() <= quad->rect.y() + quad->rect.height()) {
96 if (quad->material == DrawQuad::SURFACE_CONTENT) {
97 // We've hit a SurfaceDrawQuad, we need to recurse into this
98 // Surface.
99 const SurfaceDrawQuad* surface_quad =
100 SurfaceDrawQuad::MaterialCast(quad);
101
102 // To avoid an infinite recursion, we need to skip the surface if
103 // it's already been referenced.
104 if (referenced_surfaces_.find(surface_quad->surface_id) !=
105 referenced_surfaces_.end())
106 continue;
107 referenced_surfaces_.insert(surface_quad->surface_id);
jbauman 2015/08/05 23:33:22 The root surface could still have a reference to i
lfg 2015/08/06 18:28:12 I've fixed it when moving to use referenced passes
108
109 if (out_transformed_point)
110 *out_transformed_point = transformed_point;
111
112 const RenderPass* last_pass =
113 GetRootRenderPass(manager_, surface_quad->surface_id);
114 return HittestInternal(surface_quad->surface_id, last_pass,
115 transformed_point, out_transformed_point);
116 } else if (quad->material == DrawQuad::RENDER_PASS) {
117 // We've hit a RenderPassDrawQuad, we need to recurse into this
118 // RenderPass.
119 const RenderPassDrawQuad* render_quad =
120 RenderPassDrawQuad::MaterialCast(quad);
121
122 Surface* surface = manager_->GetSurfaceForId(surface_id);
123 const CompositorFrame* surface_frame =
124 surface->GetEligibleFrame();
125 DCHECK(surface_frame);
126 const DelegatedFrameData* frame_data =
127 surface_frame->delegated_frame_data.get();
128
129 const RenderPass* quad_render_pass;
130 for (const auto* render_pass : frame_data->render_pass_list) {
131 if (render_pass->id == render_quad->render_pass_id) {
132 quad_render_pass = render_pass;
jbauman 2015/08/05 23:33:22 It's possible that two passes could have RenderPas
lfg 2015/08/06 18:28:12 Done.
133 break;
134 }
135 }
136
137 return HittestInternal(surface_id, quad_render_pass,
jbauman 2015/08/05 23:33:22 Just thought of one last possible issue - it's pos
lfg 2015/08/06 18:28:12 Done. This was a bit more complicated, as I have t
138 point_in_target_space,
139 out_transformed_point);
140 } else {
141 // We've hit a different type of quad in the current Surface,
142 // there's no need to iterate anymore, this is the quad that
143 // receives the event;
144 return surface_id;
145 }
146 }
147 }
148 }
149 }
150
151 return surface_id;
152 }
153 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_hittest.h ('k') | cc/surfaces/surface_hittest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698