Chromium Code Reviews| Index: cc/surfaces/surface_hittest.cc |
| diff --git a/cc/surfaces/surface_hittest.cc b/cc/surfaces/surface_hittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..04d8f987d30c590b4c99cbe71ef5f704be9108a1 |
| --- /dev/null |
| +++ b/cc/surfaces/surface_hittest.cc |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/surfaces/surface_hittest.h" |
| + |
| +#include "cc/output/compositor_frame.h" |
| +#include "cc/output/delegated_frame_data.h" |
| +#include "cc/quads/draw_quad.h" |
| +#include "cc/quads/surface_draw_quad.h" |
| +#include "cc/surfaces/surface.h" |
| +#include "cc/surfaces/surface_manager.h" |
| +#include "ui/gfx/geometry/point.h" |
| +#include "ui/gfx/transform.h" |
| + |
| +namespace cc { |
| +SurfaceHittest::SurfaceHittest(SurfaceManager* manager) : manager_(manager) {} |
| + |
| +SurfaceHittest::~SurfaceHittest() {} |
| + |
| +SurfaceId SurfaceHittest::Hittest(SurfaceId surface_id, |
| + const gfx::Point& point) { |
| + Surface* surface = manager_->GetSurfaceForId(surface_id); |
| + |
| + const CompositorFrame* surface_frame = surface->GetEligibleFrame(); |
|
jbauman
2015/07/31 22:00:28
To avoid infinite recursion, this should check tha
lfg
2015/08/04 21:21:42
Done.
|
| + if (!surface_frame) |
| + return surface_id; |
| + const DelegatedFrameData* frame_data = |
| + surface_frame->delegated_frame_data.get(); |
| + |
| + for (const auto& render_pass : frame_data->render_pass_list) { |
|
jbauman
2015/07/31 22:00:28
It would probably be best to look at the root pass
lfg
2015/08/04 21:21:42
Done.
|
| + for (const auto& quad : render_pass->quad_list) { |
|
jbauman
2015/07/31 22:00:28
This should go from the end of the list to the beg
lfg
2015/08/04 21:21:42
This is the only point I'm not sure about. For ren
|
| + if (quad->material == DrawQuad::SURFACE_CONTENT) { |
| + const SurfaceDrawQuad* surface_quad = |
| + SurfaceDrawQuad::MaterialCast(quad); |
| + gfx::Transform root_to_surface_transform; |
| + if (gfx::Transform( |
| + render_pass->transform_to_root_target, |
| + surface_quad->shared_quad_state->quad_to_target_transform) |
| + .GetInverse(&root_to_surface_transform)) { |
| + gfx::Point transformed_point(point); |
| + root_to_surface_transform.TransformPoint(&transformed_point); |
| + |
| + if (transformed_point.x() > 0 && transformed_point.y() > 0 && |
| + transformed_point.x() < surface_quad->rect.width() && |
| + transformed_point.y() < surface_quad->rect.height()) { |
|
jbauman
2015/07/31 22:00:28
Should check clip rect as well.
lfg
2015/08/04 21:21:42
I've added the check to clip rect, but I'm wonderi
|
| + return Hittest(surface_quad->surface_id, transformed_point); |
| + } |
| + } |
| + } |
| + } |
| + } |
| + |
| + return surface_id; |
| +} |
| +} // namespace cc |