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

Side by Side Diff: cc/surfaces/surface_hittest_unittest.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
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 "cc/output/compositor_frame.h"
6 #include "cc/output/delegated_frame_data.h"
7 #include "cc/quads/render_pass.h"
8 #include "cc/quads/render_pass_id.h"
9 #include "cc/quads/surface_draw_quad.h"
10 #include "cc/surfaces/surface.h"
11 #include "cc/surfaces/surface_factory.h"
12 #include "cc/surfaces/surface_factory_client.h"
13 #include "cc/surfaces/surface_hittest.h"
14 #include "cc/surfaces/surface_id_allocator.h"
15 #include "cc/surfaces/surface_manager.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/gfx/geometry/size.h"
18
19 namespace cc {
20
21 class EmptySurfaceFactoryClient : public SurfaceFactoryClient {
22 public:
23 void ReturnResources(const ReturnedResourceArray& resources) override {}
24 };
25
26 TEST(SurfaceHittestTest, Hittest_SingleSurface) {
27 SurfaceManager manager;
28 EmptySurfaceFactoryClient client;
29 SurfaceFactory factory(&manager, &client);
30 SurfaceIdAllocator root_allocator(2);
31
32 // Creates a root surface.
33 SurfaceId root_surface_id = root_allocator.GenerateId();
34 factory.Create(root_surface_id);
35 gfx::Rect rect(300, 300);
36 RenderPassId id(1, 1);
37 scoped_ptr<RenderPass> pass = RenderPass::Create();
38 pass->SetNew(id, rect, rect, gfx::Transform());
39 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
40 delegated_frame_data->render_pass_list.push_back(pass.Pass());
41 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
42 root_frame->delegated_frame_data = delegated_frame_data.Pass();
43 factory.SubmitFrame(root_surface_id, root_frame.Pass(),
44 SurfaceFactory::DrawCallback());
45
46 {
47 SurfaceHittest hittest(&manager);
48 gfx::Point transformed_point;
49 EXPECT_EQ(root_surface_id,
50 hittest.Hittest(root_surface_id, gfx::Point(100, 100),
51 &transformed_point));
52 EXPECT_EQ(gfx::Point(100, 100), transformed_point);
53 }
54
55 factory.Destroy(root_surface_id);
56 }
57
58 TEST(SurfaceHittestTest, Hittest_ChildSurface) {
59 SurfaceManager manager;
60 EmptySurfaceFactoryClient client;
61 SurfaceFactory factory(&manager, &client);
62 SurfaceIdAllocator root_allocator(2);
63 SurfaceIdAllocator child_allocator(3);
64
65 SurfaceId root_surface_id = root_allocator.GenerateId();
66 SurfaceId child_surface_id = child_allocator.GenerateId();
67 gfx::Size root_size(300, 300);
68 gfx::Rect root_rect(root_size);
69 gfx::Size child_size(200, 200);
70 gfx::Rect child_rect(child_size);
71
72 // Creates a root surface.
73 factory.Create(root_surface_id);
74 RenderPassId root_id(1, 1);
75 scoped_ptr<RenderPass> root_pass = RenderPass::Create();
76 root_pass->SetNew(root_id, root_rect, root_rect, gfx::Transform());
77
78 // Add a reference to the child surface on the root surface.
79 SharedQuadState* shared_state = root_pass->CreateAndAppendSharedQuadState();
80 shared_state->SetAll(gfx::Transform(1.0f, 0.0f, 0.0f, 50.0f,
81 0.0f, 1.0f, 0.0f, 50.0f,
82 0.0f, 0.0f, 1.0f, 0.0f,
83 0.0f, 0.0f, 0.0f, 1.0f),
84 root_size, root_rect, root_rect, false, 1.0f,
85 SkXfermode::kSrcOver_Mode, 0);
86 SurfaceDrawQuad* surface_quad =
87 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
88 surface_quad->SetNew(root_pass->shared_quad_state_list.back(), child_rect,
89 child_rect, child_surface_id);
90
91 // Submit the root frame.
92 scoped_ptr<DelegatedFrameData> root_delegated_frame_data(
93 new DelegatedFrameData);
94 root_delegated_frame_data->render_pass_list.push_back(root_pass.Pass());
95 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
96 root_frame->delegated_frame_data = root_delegated_frame_data.Pass();
97 factory.SubmitFrame(root_surface_id, root_frame.Pass(),
98 SurfaceFactory::DrawCallback());
99
100 // Creates a child surface.
101 factory.Create(child_surface_id);
102 RenderPassId child_id(1, 1);
103 scoped_ptr<RenderPass> child_pass = RenderPass::Create();
104 child_pass->SetNew(child_id, child_rect, child_rect, gfx::Transform());
105
106 // Submit the frame.
107 scoped_ptr<DelegatedFrameData> child_delegated_frame_data(
108 new DelegatedFrameData);
109 child_delegated_frame_data->render_pass_list.push_back(child_pass.Pass());
110 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
111 child_frame->delegated_frame_data = child_delegated_frame_data.Pass();
112 factory.SubmitFrame(child_surface_id, child_frame.Pass(),
113 SurfaceFactory::DrawCallback());
114
115 {
116 SurfaceHittest hittest(&manager);
117 gfx::Point transformed_point;
118 EXPECT_EQ(root_surface_id,
119 hittest.Hittest(root_surface_id, gfx::Point(10, 10),
120 &transformed_point));
121 EXPECT_EQ(gfx::Point(10, 10), transformed_point);
122 EXPECT_EQ(root_surface_id,
123 hittest.Hittest(root_surface_id, gfx::Point(50, 50),
124 &transformed_point));
125 EXPECT_EQ(gfx::Point(50, 50), transformed_point);
126 EXPECT_EQ(child_surface_id,
127 hittest.Hittest(root_surface_id, gfx::Point(51, 51),
128 &transformed_point));
129 EXPECT_EQ(gfx::Point(1, 1), transformed_point);
130 EXPECT_EQ(child_surface_id,
131 hittest.Hittest(root_surface_id, gfx::Point(100, 100),
132 &transformed_point));
133 EXPECT_EQ(gfx::Point(50, 50), transformed_point);
134 EXPECT_EQ(child_surface_id,
135 hittest.Hittest(root_surface_id, gfx::Point(249, 249),
136 &transformed_point));
137 EXPECT_EQ(gfx::Point(199, 199), transformed_point);
138 EXPECT_EQ(root_surface_id,
139 hittest.Hittest(root_surface_id, gfx::Point(250, 250),
140 &transformed_point));
141 EXPECT_EQ(gfx::Point(250, 250), transformed_point);
142 EXPECT_EQ(root_surface_id,
143 hittest.Hittest(root_surface_id, gfx::Point(290, 290),
144 &transformed_point));
145 EXPECT_EQ(gfx::Point(290, 290), transformed_point);
146 }
147
148 factory.Destroy(root_surface_id);
149 factory.Destroy(child_surface_id);
150 }
151
152 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698