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

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

Issue 1422783002: cc: Move surfaces hittesting test helpers out to a separate file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GN DEPS I hope Created 5 years, 2 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_aggregator_unittest.cc ('k') | cc/test/surface_aggregator_test_helpers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "cc/output/compositor_frame.h" 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_draw_quad.h"
9 #include "cc/quads/render_pass_id.h"
10 #include "cc/quads/solid_color_draw_quad.h"
11 #include "cc/quads/surface_draw_quad.h"
12 #include "cc/surfaces/surface.h" 6 #include "cc/surfaces/surface.h"
13 #include "cc/surfaces/surface_factory.h" 7 #include "cc/surfaces/surface_factory.h"
14 #include "cc/surfaces/surface_factory_client.h" 8 #include "cc/surfaces/surface_factory_client.h"
15 #include "cc/surfaces/surface_hittest.h" 9 #include "cc/surfaces/surface_hittest.h"
16 #include "cc/surfaces/surface_id_allocator.h" 10 #include "cc/surfaces/surface_id_allocator.h"
17 #include "cc/surfaces/surface_manager.h" 11 #include "cc/surfaces/surface_manager.h"
12 #include "cc/test/surface_hittest_test_helpers.h"
18 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/gfx/geometry/size.h" 15 #include "ui/gfx/geometry/size.h"
21 16
22 namespace cc { 17 namespace cc {
23 18
24 namespace { 19 namespace {
25 20
26 struct TestCase { 21 struct TestCase {
27 SurfaceId input_surface_id; 22 SurfaceId input_surface_id;
(...skipping 17 matching lines...) Expand all
45 // Verify that GetTransformToTargetSurface returns true and returns the same 40 // Verify that GetTransformToTargetSurface returns true and returns the same
46 // transform as returned by GetTargetSurfaceAtPoint. 41 // transform as returned by GetTargetSurfaceAtPoint.
47 gfx::Transform target_transform; 42 gfx::Transform target_transform;
48 EXPECT_TRUE(hittest.GetTransformToTargetSurface( 43 EXPECT_TRUE(hittest.GetTransformToTargetSurface(
49 test.input_surface_id, test.expected_output_surface_id, 44 test.input_surface_id, test.expected_output_surface_id,
50 &target_transform)); 45 &target_transform));
51 EXPECT_EQ(transform, target_transform); 46 EXPECT_EQ(transform, target_transform);
52 } 47 }
53 } 48 }
54 49
55 class EmptySurfaceFactoryClient : public SurfaceFactoryClient {
56 public:
57 void ReturnResources(const ReturnedResourceArray& resources) override {}
58 void SetBeginFrameSource(SurfaceId surface_id,
59 BeginFrameSource* begin_frame_source) override {}
60 };
61
62 void CreateSharedQuadState(RenderPass* pass,
63 const gfx::Transform& transform,
64 const gfx::Rect& root_rect) {
65 SharedQuadState* child_shared_state =
66 pass->CreateAndAppendSharedQuadState();
67 child_shared_state->SetAll(transform,
68 root_rect.size(),
69 root_rect, root_rect, false, 1.0f,
70 SkXfermode::kSrcOver_Mode, 0);
71 }
72
73 void CreateSolidColorDrawQuad(RenderPass* pass,
74 const gfx::Transform& transform,
75 const gfx::Rect& root_rect,
76 const gfx::Rect& quad_rect) {
77 CreateSharedQuadState(pass, transform, root_rect);
78 SolidColorDrawQuad* color_quad =
79 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
80 color_quad->SetNew(pass->shared_quad_state_list.back(),
81 quad_rect, quad_rect,
82 SK_ColorYELLOW, false);
83 }
84
85 void CreateRenderPassDrawQuad(RenderPass* pass,
86 const gfx::Transform& transform,
87 const gfx::Rect& root_rect,
88 const gfx::Rect& quad_rect,
89 const RenderPassId& render_pass_id) {
90 CreateSharedQuadState(pass, transform, root_rect);
91 RenderPassDrawQuad* render_pass_quad =
92 pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
93 render_pass_quad->SetNew(pass->shared_quad_state_list.back(),
94 quad_rect, quad_rect,
95 render_pass_id,
96 ResourceId(),
97 gfx::Vector2dF(),
98 gfx::Size(),
99 FilterOperations(),
100 gfx::Vector2dF(),
101 FilterOperations());
102 }
103
104 void CreateSurfaceDrawQuad(RenderPass* pass,
105 const gfx::Transform& transform,
106 const gfx::Rect& root_rect,
107 const gfx::Rect& quad_rect,
108 SurfaceId surface_id) {
109 CreateSharedQuadState(pass, transform, root_rect);
110 SurfaceDrawQuad* surface_quad =
111 pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
112 surface_quad->SetNew(pass->shared_quad_state_list.back(),
113 quad_rect, quad_rect,
114 surface_id);
115 }
116
117 void CreateRenderPass(const RenderPassId& render_pass_id,
118 const gfx::Rect& rect,
119 const gfx::Transform& transform_to_root_target,
120 RenderPassList* render_pass_list) {
121 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
122 render_pass->SetNew(render_pass_id, rect, rect, transform_to_root_target);
123 render_pass_list->push_back(render_pass.Pass());
124 }
125
126 scoped_ptr<CompositorFrame> CreateCompositorFrameWithRenderPassList(
127 RenderPassList* render_pass_list) {
128 scoped_ptr<DelegatedFrameData> root_delegated_frame_data(
129 new DelegatedFrameData);
130 root_delegated_frame_data->render_pass_list.swap(*render_pass_list);
131 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
132 root_frame->delegated_frame_data = root_delegated_frame_data.Pass();
133 return root_frame.Pass();
134 }
135
136 scoped_ptr<CompositorFrame> CreateCompositorFrame(
137 const gfx::Rect& root_rect,
138 RenderPass** render_pass) {
139 RenderPassList render_pass_list;
140 RenderPassId root_id(1, 1);
141 CreateRenderPass(root_id, root_rect, gfx::Transform(), &render_pass_list);
142
143 scoped_ptr<CompositorFrame> root_frame =
144 CreateCompositorFrameWithRenderPassList(&render_pass_list);
145
146 *render_pass = root_frame->delegated_frame_data->render_pass_list.back();
147 return root_frame.Pass();
148 }
149
150 } // namespace 50 } // namespace
151 51
52 using namespace test;
53
152 // This test verifies that hit testing on a surface that does not exist does 54 // This test verifies that hit testing on a surface that does not exist does
153 // not crash. 55 // not crash.
154 TEST(SurfaceHittestTest, Hittest_BadCompositorFrameDoesNotCrash) { 56 TEST(SurfaceHittestTest, Hittest_BadCompositorFrameDoesNotCrash) {
155 SurfaceManager manager; 57 SurfaceManager manager;
156 EmptySurfaceFactoryClient client; 58 EmptySurfaceFactoryClient client;
157 SurfaceFactory factory(&manager, &client); 59 SurfaceFactory factory(&manager, &client);
158 60
159 // Creates a root surface. 61 // Creates a root surface.
160 gfx::Rect root_rect(300, 300); 62 gfx::Rect root_rect(300, 300);
161 RenderPass* root_pass = nullptr; 63 RenderPass* root_pass = nullptr;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 SurfaceFactory::DrawCallback()); 113 SurfaceFactory::DrawCallback());
212 TestCase tests[] = { 114 TestCase tests[] = {
213 { 115 {
214 root_surface_id, 116 root_surface_id,
215 gfx::Point(100, 100), 117 gfx::Point(100, 100),
216 root_surface_id, 118 root_surface_id,
217 gfx::Point(100, 100) 119 gfx::Point(100, 100)
218 }, 120 },
219 }; 121 };
220 122
221 RunTests(&manager, tests, sizeof(tests) / sizeof(*tests)); 123 RunTests(&manager, tests, arraysize(tests));
222 124
223 factory.Destroy(root_surface_id); 125 factory.Destroy(root_surface_id);
224 } 126 }
225 127
226 TEST(SurfaceHittestTest, Hittest_ChildSurface) { 128 TEST(SurfaceHittestTest, Hittest_ChildSurface) {
227 SurfaceManager manager; 129 SurfaceManager manager;
228 EmptySurfaceFactoryClient client; 130 EmptySurfaceFactoryClient client;
229 SurfaceFactory factory(&manager, &client); 131 SurfaceFactory factory(&manager, &client);
230 132
231 // Creates a root surface. 133 // Creates a root surface.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 gfx::Point(200, 200) 208 gfx::Point(200, 200)
307 }, 209 },
308 { 210 {
309 root_surface_id, 211 root_surface_id,
310 gfx::Point(290, 290), 212 gfx::Point(290, 290),
311 root_surface_id, 213 root_surface_id,
312 gfx::Point(290, 290) 214 gfx::Point(290, 290)
313 } 215 }
314 }; 216 };
315 217
316 RunTests(&manager, tests, sizeof(tests) / sizeof(*tests)); 218 RunTests(&manager, tests, arraysize(tests));
317 219
318 // Submit another root frame, with a slightly perturbed child Surface. 220 // Submit another root frame, with a slightly perturbed child Surface.
319 root_frame = CreateCompositorFrame(root_rect, &root_pass); 221 root_frame = CreateCompositorFrame(root_rect, &root_pass);
320 CreateSurfaceDrawQuad(root_pass, 222 CreateSurfaceDrawQuad(root_pass,
321 gfx::Transform(1.0f, 0.0f, 0.0f, 75.0f, 223 gfx::Transform(1.0f, 0.0f, 0.0f, 75.0f,
322 0.0f, 1.0f, 0.0f, 75.0f, 224 0.0f, 1.0f, 0.0f, 75.0f,
323 0.0f, 0.0f, 1.0f, 0.0f, 225 0.0f, 0.0f, 1.0f, 0.0f,
324 0.0f, 0.0f, 0.0f, 1.0f), 226 0.0f, 0.0f, 0.0f, 1.0f),
325 root_rect, 227 root_rect,
326 child_rect, 228 child_rect,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 gfx::Point(200, 200) 348 gfx::Point(200, 200)
447 }, 349 },
448 { 350 {
449 root_surface_id, 351 root_surface_id,
450 gfx::Point(290, 290), 352 gfx::Point(290, 290),
451 root_surface_id, 353 root_surface_id,
452 gfx::Point(290, 290) 354 gfx::Point(290, 290)
453 } 355 }
454 }; 356 };
455 357
456 RunTests(&manager, tests, sizeof(tests) / sizeof(*tests)); 358 RunTests(&manager, tests, arraysize(tests));
457 359
458 factory.Destroy(root_surface_id); 360 factory.Destroy(root_surface_id);
459 factory.Destroy(child_surface_id); 361 factory.Destroy(child_surface_id);
460 } 362 }
461 363
462 TEST(SurfaceHittestTest, Hittest_RenderPassDrawQuad) { 364 TEST(SurfaceHittestTest, Hittest_RenderPassDrawQuad) {
463 SurfaceManager manager; 365 SurfaceManager manager;
464 EmptySurfaceFactoryClient client; 366 EmptySurfaceFactoryClient client;
465 SurfaceFactory factory(&manager, &client); 367 SurfaceFactory factory(&manager, &client);
466 368
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 gfx::Point(99, 99) 452 gfx::Point(99, 99)
551 }, 453 },
552 { 454 {
553 root_surface_id, 455 root_surface_id,
554 gfx::Point(100, 100), 456 gfx::Point(100, 100),
555 root_surface_id, 457 root_surface_id,
556 gfx::Point(100, 100) 458 gfx::Point(100, 100)
557 } 459 }
558 }; 460 };
559 461
560 RunTests(&manager, tests, sizeof(tests) / sizeof(*tests)); 462 RunTests(&manager, tests, arraysize(tests));
561 463
562 factory.Destroy(root_surface_id); 464 factory.Destroy(root_surface_id);
563 } 465 }
564 466
565 } // namespace cc 467 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_aggregator_unittest.cc ('k') | cc/test/surface_aggregator_test_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698