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

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

Issue 2136413002: Update Surface ID Terminology (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix webkit_unit_tests Created 4 years, 5 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "cc/output/compositor_frame.h" 7 #include "cc/output/compositor_frame.h"
8 #include "cc/surfaces/surface.h" 8 #include "cc/surfaces/surface.h"
9 #include "cc/surfaces/surface_factory.h" 9 #include "cc/surfaces/surface_factory.h"
10 #include "cc/surfaces/surface_factory_client.h" 10 #include "cc/surfaces/surface_factory_client.h"
11 #include "cc/surfaces/surface_hittest.h" 11 #include "cc/surfaces/surface_hittest.h"
12 #include "cc/surfaces/surface_id_allocator.h" 12 #include "cc/surfaces/surface_id_allocator.h"
13 #include "cc/surfaces/surface_manager.h" 13 #include "cc/surfaces/surface_manager.h"
14 #include "cc/test/surface_hittest_test_helpers.h" 14 #include "cc/test/surface_hittest_test_helpers.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/skia/include/core/SkColor.h" 16 #include "third_party/skia/include/core/SkColor.h"
17 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
18 18
19 namespace cc { 19 namespace cc {
20 20
21 namespace { 21 namespace {
22 22
23 static constexpr uint32_t kArbitraryGpuId = 0;
24
23 struct TestCase { 25 struct TestCase {
24 SurfaceId input_surface_id; 26 SurfaceId input_surface_id;
25 gfx::Point input_point; 27 gfx::Point input_point;
26 SurfaceId expected_output_surface_id; 28 SurfaceId expected_output_surface_id;
27 gfx::Point expected_output_point; 29 gfx::Point expected_output_point;
28 }; 30 };
29 31
30 void RunTests(SurfaceHittestDelegate* delegate, 32 void RunTests(SurfaceHittestDelegate* delegate,
31 SurfaceManager* manager, 33 SurfaceManager* manager,
32 TestCase* tests, 34 TestCase* tests,
(...skipping 29 matching lines...) Expand all
62 SurfaceManager manager; 64 SurfaceManager manager;
63 EmptySurfaceFactoryClient client; 65 EmptySurfaceFactoryClient client;
64 SurfaceFactory factory(&manager, &client); 66 SurfaceFactory factory(&manager, &client);
65 67
66 // Creates a root surface. 68 // Creates a root surface.
67 gfx::Rect root_rect(300, 300); 69 gfx::Rect root_rect(300, 300);
68 RenderPass* root_pass = nullptr; 70 RenderPass* root_pass = nullptr;
69 CompositorFrame root_frame = CreateCompositorFrame(root_rect, &root_pass); 71 CompositorFrame root_frame = CreateCompositorFrame(root_rect, &root_pass);
70 72
71 // Add a reference to a non-existant child surface on the root surface. 73 // Add a reference to a non-existant child surface on the root surface.
72 SurfaceId child_surface_id(3, 0xdeadbeef, 0); 74 SurfaceId child_surface_id(kArbitraryGpuId, 3, 0xdeadbeef, 0);
73 gfx::Rect child_rect(200, 200); 75 gfx::Rect child_rect(200, 200);
74 CreateSurfaceDrawQuad(root_pass, 76 CreateSurfaceDrawQuad(root_pass,
75 gfx::Transform(), 77 gfx::Transform(),
76 root_rect, 78 root_rect,
77 child_rect, 79 child_rect,
78 child_surface_id); 80 child_surface_id);
79 81
80 // Submit the root frame. 82 // Submit the root frame.
81 SurfaceIdAllocator root_allocator(2); 83 SurfaceIdAllocator root_allocator(kArbitraryGpuId, 2);
82 SurfaceId root_surface_id = root_allocator.GenerateId(); 84 SurfaceId root_surface_id = root_allocator.GenerateId();
83 factory.Create(root_surface_id); 85 factory.Create(root_surface_id);
84 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame), 86 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame),
85 SurfaceFactory::DrawCallback()); 87 SurfaceFactory::DrawCallback());
86 88
87 { 89 {
88 SurfaceHittest hittest(nullptr, &manager); 90 SurfaceHittest hittest(nullptr, &manager);
89 // It is expected this test will complete without crashes. 91 // It is expected this test will complete without crashes.
90 gfx::Transform transform; 92 gfx::Transform transform;
91 EXPECT_EQ(root_surface_id, 93 EXPECT_EQ(root_surface_id,
92 hittest.GetTargetSurfaceAtPoint( 94 hittest.GetTargetSurfaceAtPoint(
93 root_surface_id, gfx::Point(100, 100), &transform)); 95 root_surface_id, gfx::Point(100, 100), &transform));
94 } 96 }
95 97
96 factory.Destroy(root_surface_id); 98 factory.Destroy(root_surface_id);
97 } 99 }
98 100
99 TEST(SurfaceHittestTest, Hittest_SingleSurface) { 101 TEST(SurfaceHittestTest, Hittest_SingleSurface) {
100 SurfaceManager manager; 102 SurfaceManager manager;
101 EmptySurfaceFactoryClient client; 103 EmptySurfaceFactoryClient client;
102 SurfaceFactory factory(&manager, &client); 104 SurfaceFactory factory(&manager, &client);
103 105
104 // Creates a root surface. 106 // Creates a root surface.
105 gfx::Rect root_rect(300, 300); 107 gfx::Rect root_rect(300, 300);
106 RenderPass* root_pass = nullptr; 108 RenderPass* root_pass = nullptr;
107 CompositorFrame root_frame = CreateCompositorFrame(root_rect, &root_pass); 109 CompositorFrame root_frame = CreateCompositorFrame(root_rect, &root_pass);
108 110
109 // Submit the root frame. 111 // Submit the root frame.
110 SurfaceIdAllocator root_allocator(2); 112 SurfaceIdAllocator root_allocator(kArbitraryGpuId, 2);
111 SurfaceId root_surface_id = root_allocator.GenerateId(); 113 SurfaceId root_surface_id = root_allocator.GenerateId();
112 factory.Create(root_surface_id); 114 factory.Create(root_surface_id);
113 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame), 115 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame),
114 SurfaceFactory::DrawCallback()); 116 SurfaceFactory::DrawCallback());
115 TestCase tests[] = { 117 TestCase tests[] = {
116 { 118 {
117 root_surface_id, 119 root_surface_id,
118 gfx::Point(100, 100), 120 gfx::Point(100, 100),
119 root_surface_id, 121 root_surface_id,
120 gfx::Point(100, 100) 122 gfx::Point(100, 100)
121 }, 123 },
122 }; 124 };
123 125
124 RunTests(nullptr, &manager, tests, arraysize(tests)); 126 RunTests(nullptr, &manager, tests, arraysize(tests));
125 127
126 factory.Destroy(root_surface_id); 128 factory.Destroy(root_surface_id);
127 } 129 }
128 130
129 TEST(SurfaceHittestTest, Hittest_ChildSurface) { 131 TEST(SurfaceHittestTest, Hittest_ChildSurface) {
130 SurfaceManager manager; 132 SurfaceManager manager;
131 EmptySurfaceFactoryClient client; 133 EmptySurfaceFactoryClient client;
132 SurfaceFactory factory(&manager, &client); 134 SurfaceFactory factory(&manager, &client);
133 135
134 // Creates a root surface. 136 // Creates a root surface.
135 gfx::Rect root_rect(300, 300); 137 gfx::Rect root_rect(300, 300);
136 RenderPass* root_pass = nullptr; 138 RenderPass* root_pass = nullptr;
137 CompositorFrame root_frame = CreateCompositorFrame(root_rect, &root_pass); 139 CompositorFrame root_frame = CreateCompositorFrame(root_rect, &root_pass);
138 140
139 // Add a reference to the child surface on the root surface. 141 // Add a reference to the child surface on the root surface.
140 SurfaceIdAllocator child_allocator(3); 142 SurfaceIdAllocator child_allocator(kArbitraryGpuId, 3);
141 SurfaceId child_surface_id = child_allocator.GenerateId(); 143 SurfaceId child_surface_id = child_allocator.GenerateId();
142 gfx::Rect child_rect(200, 200); 144 gfx::Rect child_rect(200, 200);
143 CreateSurfaceDrawQuad(root_pass, 145 CreateSurfaceDrawQuad(root_pass,
144 gfx::Transform(1.0f, 0.0f, 0.0f, 50.0f, 146 gfx::Transform(1.0f, 0.0f, 0.0f, 50.0f,
145 0.0f, 1.0f, 0.0f, 50.0f, 147 0.0f, 1.0f, 0.0f, 50.0f,
146 0.0f, 0.0f, 1.0f, 0.0f, 148 0.0f, 0.0f, 1.0f, 0.0f,
147 0.0f, 0.0f, 0.0f, 1.0f), 149 0.0f, 0.0f, 0.0f, 1.0f),
148 root_rect, 150 root_rect,
149 child_rect, 151 child_rect,
150 child_surface_id); 152 child_surface_id);
151 153
152 // Submit the root frame. 154 // Submit the root frame.
153 SurfaceIdAllocator root_allocator(2); 155 SurfaceIdAllocator root_allocator(kArbitraryGpuId, 2);
154 SurfaceId root_surface_id = root_allocator.GenerateId(); 156 SurfaceId root_surface_id = root_allocator.GenerateId();
155 factory.Create(root_surface_id); 157 factory.Create(root_surface_id);
156 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame), 158 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame),
157 SurfaceFactory::DrawCallback()); 159 SurfaceFactory::DrawCallback());
158 160
159 // Creates a child surface. 161 // Creates a child surface.
160 RenderPass* child_pass = nullptr; 162 RenderPass* child_pass = nullptr;
161 CompositorFrame child_frame = CreateCompositorFrame(child_rect, &child_pass); 163 CompositorFrame child_frame = CreateCompositorFrame(child_rect, &child_pass);
162 164
163 // Add a solid quad in the child surface. 165 // Add a solid quad in the child surface.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 CompositorFrame root_frame = CreateCompositorFrame(root_rect, &root_pass); 270 CompositorFrame root_frame = CreateCompositorFrame(root_rect, &root_pass);
269 271
270 // Create a RenderPassDrawQuad to a non-existant RenderPass. 272 // Create a RenderPassDrawQuad to a non-existant RenderPass.
271 CreateRenderPassDrawQuad(root_pass, 273 CreateRenderPassDrawQuad(root_pass,
272 gfx::Transform(), 274 gfx::Transform(),
273 root_rect, 275 root_rect,
274 root_rect, 276 root_rect,
275 RenderPassId(1337, 1337)); 277 RenderPassId(1337, 1337));
276 278
277 // Add a reference to the child surface on the root surface. 279 // Add a reference to the child surface on the root surface.
278 SurfaceIdAllocator child_allocator(3); 280 SurfaceIdAllocator child_allocator(kArbitraryGpuId, 3);
279 SurfaceId child_surface_id = child_allocator.GenerateId(); 281 SurfaceId child_surface_id = child_allocator.GenerateId();
280 gfx::Rect child_rect(200, 200); 282 gfx::Rect child_rect(200, 200);
281 CreateSurfaceDrawQuad(root_pass, 283 CreateSurfaceDrawQuad(root_pass,
282 gfx::Transform(1.0f, 0.0f, 0.0f, 50.0f, 284 gfx::Transform(1.0f, 0.0f, 0.0f, 50.0f,
283 0.0f, 1.0f, 0.0f, 50.0f, 285 0.0f, 1.0f, 0.0f, 50.0f,
284 0.0f, 0.0f, 1.0f, 0.0f, 286 0.0f, 0.0f, 1.0f, 0.0f,
285 0.0f, 0.0f, 0.0f, 1.0f), 287 0.0f, 0.0f, 0.0f, 1.0f),
286 root_rect, 288 root_rect,
287 child_rect, 289 child_rect,
288 child_surface_id); 290 child_surface_id);
289 291
290 // Submit the root frame. 292 // Submit the root frame.
291 SurfaceIdAllocator root_allocator(2); 293 SurfaceIdAllocator root_allocator(kArbitraryGpuId, 2);
292 SurfaceId root_surface_id = root_allocator.GenerateId(); 294 SurfaceId root_surface_id = root_allocator.GenerateId();
293 factory.Create(root_surface_id); 295 factory.Create(root_surface_id);
294 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame), 296 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame),
295 SurfaceFactory::DrawCallback()); 297 SurfaceFactory::DrawCallback());
296 298
297 // Creates a child surface. 299 // Creates a child surface.
298 RenderPass* child_pass = nullptr; 300 RenderPass* child_pass = nullptr;
299 CompositorFrame child_frame = CreateCompositorFrame(child_rect, &child_pass); 301 CompositorFrame child_frame = CreateCompositorFrame(child_rect, &child_pass);
300 302
301 // Add a solid quad in the child surface. 303 // Add a solid quad in the child surface.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // Add a solid quad in the child render pass. 401 // Add a solid quad in the child render pass.
400 RenderPass* child_render_pass = 402 RenderPass* child_render_pass =
401 root_frame.delegated_frame_data->render_pass_list.front().get(); 403 root_frame.delegated_frame_data->render_pass_list.front().get();
402 gfx::Rect child_solid_quad_rect(100, 100); 404 gfx::Rect child_solid_quad_rect(100, 100);
403 CreateSolidColorDrawQuad(child_render_pass, 405 CreateSolidColorDrawQuad(child_render_pass,
404 gfx::Transform(), 406 gfx::Transform(),
405 gfx::Rect(100, 100), 407 gfx::Rect(100, 100),
406 child_solid_quad_rect); 408 child_solid_quad_rect);
407 409
408 // Submit the root frame. 410 // Submit the root frame.
409 SurfaceIdAllocator root_allocator(1); 411 SurfaceIdAllocator root_allocator(kArbitraryGpuId, 1);
410 SurfaceId root_surface_id = root_allocator.GenerateId(); 412 SurfaceId root_surface_id = root_allocator.GenerateId();
411 factory.Create(root_surface_id); 413 factory.Create(root_surface_id);
412 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame), 414 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame),
413 SurfaceFactory::DrawCallback()); 415 SurfaceFactory::DrawCallback());
414 416
415 TestCase tests[] = { 417 TestCase tests[] = {
416 // These tests just miss the RenderPassDrawQuad. 418 // These tests just miss the RenderPassDrawQuad.
417 { 419 {
418 root_surface_id, 420 root_surface_id,
419 gfx::Point(49, 49), 421 gfx::Point(49, 49),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 SurfaceManager manager; 467 SurfaceManager manager;
466 EmptySurfaceFactoryClient client; 468 EmptySurfaceFactoryClient client;
467 SurfaceFactory factory(&manager, &client); 469 SurfaceFactory factory(&manager, &client);
468 470
469 // Creates a root surface. 471 // Creates a root surface.
470 gfx::Rect root_rect(300, 300); 472 gfx::Rect root_rect(300, 300);
471 RenderPass* root_pass = nullptr; 473 RenderPass* root_pass = nullptr;
472 CompositorFrame root_frame = CreateCompositorFrame(root_rect, &root_pass); 474 CompositorFrame root_frame = CreateCompositorFrame(root_rect, &root_pass);
473 475
474 // Add a reference to the child surface on the root surface. 476 // Add a reference to the child surface on the root surface.
475 SurfaceIdAllocator child_allocator(3); 477 SurfaceIdAllocator child_allocator(kArbitraryGpuId, 3);
476 SurfaceId child_surface_id = child_allocator.GenerateId(); 478 SurfaceId child_surface_id = child_allocator.GenerateId();
477 gfx::Rect child_rect(200, 200); 479 gfx::Rect child_rect(200, 200);
478 CreateSurfaceDrawQuad( 480 CreateSurfaceDrawQuad(
479 root_pass, 481 root_pass,
480 gfx::Transform(1.0f, 0.0f, 0.0f, 50.0f, 482 gfx::Transform(1.0f, 0.0f, 0.0f, 50.0f,
481 0.0f, 1.0f, 0.0f, 50.0f, 483 0.0f, 1.0f, 0.0f, 50.0f,
482 0.0f, 0.0f, 1.0f, 0.0f, 484 0.0f, 0.0f, 1.0f, 0.0f,
483 0.0f, 0.0f, 0.0f, 1.0f), 485 0.0f, 0.0f, 0.0f, 1.0f),
484 root_rect, child_rect, child_surface_id); 486 root_rect, child_rect, child_surface_id);
485 487
486 // Submit the root frame. 488 // Submit the root frame.
487 SurfaceIdAllocator root_allocator(2); 489 SurfaceIdAllocator root_allocator(kArbitraryGpuId, 2);
488 SurfaceId root_surface_id = root_allocator.GenerateId(); 490 SurfaceId root_surface_id = root_allocator.GenerateId();
489 factory.Create(root_surface_id); 491 factory.Create(root_surface_id);
490 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame), 492 factory.SubmitCompositorFrame(root_surface_id, std::move(root_frame),
491 SurfaceFactory::DrawCallback()); 493 SurfaceFactory::DrawCallback());
492 494
493 // Creates a child surface. 495 // Creates a child surface.
494 RenderPass* child_pass = nullptr; 496 RenderPass* child_pass = nullptr;
495 CompositorFrame child_frame = CreateCompositorFrame(child_rect, &child_pass); 497 CompositorFrame child_frame = CreateCompositorFrame(child_rect, &child_pass);
496 498
497 // Add a solid quad in the child surface. 499 // Add a solid quad in the child surface.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 arraysize(test_expectations_with_accept_insets)); 583 arraysize(test_expectations_with_accept_insets));
582 584
583 // Verify that insets have affected hit targeting. 585 // Verify that insets have affected hit targeting.
584 EXPECT_EQ(0, accept_delegate.reject_target_overrides()); 586 EXPECT_EQ(0, accept_delegate.reject_target_overrides());
585 EXPECT_EQ(2, accept_delegate.accept_target_overrides()); 587 EXPECT_EQ(2, accept_delegate.accept_target_overrides());
586 588
587 factory.Destroy(root_surface_id); 589 factory.Destroy(root_surface_id);
588 } 590 }
589 591
590 } // namespace cc 592 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698