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_aggregator_unittest.cc

Issue 2938833002: Add SurfaceWillDraw notification (Closed)
Patch Set: add unit test to verify that OnSurfaceWillDraw is called only for surfaces added to the CompositorF… Created 3 years, 6 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.cc ('k') | cc/surfaces/surface_manager.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/surfaces/surface_aggregator.h" 5 #include "cc/surfaces/surface_aggregator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "cc/output/compositor_frame.h" 14 #include "cc/output/compositor_frame.h"
15 #include "cc/quads/render_pass.h" 15 #include "cc/quads/render_pass.h"
16 #include "cc/quads/render_pass_draw_quad.h" 16 #include "cc/quads/render_pass_draw_quad.h"
17 #include "cc/quads/solid_color_draw_quad.h" 17 #include "cc/quads/solid_color_draw_quad.h"
18 #include "cc/quads/surface_draw_quad.h" 18 #include "cc/quads/surface_draw_quad.h"
19 #include "cc/quads/texture_draw_quad.h" 19 #include "cc/quads/texture_draw_quad.h"
20 #include "cc/resources/shared_bitmap_manager.h" 20 #include "cc/resources/shared_bitmap_manager.h"
21 #include "cc/surfaces/compositor_frame_sink_support.h" 21 #include "cc/surfaces/compositor_frame_sink_support.h"
22 #include "cc/surfaces/local_surface_id_allocator.h" 22 #include "cc/surfaces/local_surface_id_allocator.h"
23 #include "cc/surfaces/surface.h" 23 #include "cc/surfaces/surface.h"
24 #include "cc/surfaces/surface_manager.h" 24 #include "cc/surfaces/surface_manager.h"
25 #include "cc/test/compositor_frame_helpers.h" 25 #include "cc/test/compositor_frame_helpers.h"
26 #include "cc/test/fake_compositor_frame_sink_support_client.h" 26 #include "cc/test/fake_compositor_frame_sink_support_client.h"
27 #include "cc/test/fake_resource_provider.h" 27 #include "cc/test/fake_resource_provider.h"
28 #include "cc/test/fake_surface_observer.h"
28 #include "cc/test/render_pass_test_utils.h" 29 #include "cc/test/render_pass_test_utils.h"
29 #include "cc/test/surface_aggregator_test_helpers.h" 30 #include "cc/test/surface_aggregator_test_helpers.h"
30 #include "cc/test/test_shared_bitmap_manager.h" 31 #include "cc/test/test_shared_bitmap_manager.h"
31 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
33 #include "third_party/skia/include/core/SkColor.h" 34 #include "third_party/skia/include/core/SkColor.h"
34 35
35 namespace cc { 36 namespace cc {
36 namespace { 37 namespace {
37 38
(...skipping 16 matching lines...) Expand all
54 } 55 }
55 56
56 gfx::Size SurfaceSize() { 57 gfx::Size SurfaceSize() {
57 static gfx::Size size(100, 100); 58 static gfx::Size size(100, 100);
58 return size; 59 return size;
59 } 60 }
60 61
61 class SurfaceAggregatorTest : public testing::Test { 62 class SurfaceAggregatorTest : public testing::Test {
62 public: 63 public:
63 explicit SurfaceAggregatorTest(bool use_damage_rect) 64 explicit SurfaceAggregatorTest(bool use_damage_rect)
64 : support_( 65 : observer_(false),
66 support_(
65 CompositorFrameSinkSupport::Create(&fake_client_, 67 CompositorFrameSinkSupport::Create(&fake_client_,
66 &manager_, 68 &manager_,
67 kArbitraryRootFrameSinkId, 69 kArbitraryRootFrameSinkId,
68 kRootIsRoot, 70 kRootIsRoot,
69 kHandlesFrameSinkIdInvalidation, 71 kHandlesFrameSinkIdInvalidation,
70 kNeedsSyncPoints)), 72 kNeedsSyncPoints)),
71 aggregator_(&manager_, NULL, use_damage_rect) {} 73 aggregator_(&manager_, NULL, use_damage_rect) {
74 manager_.AddObserver(&observer_);
75 }
72 76
73 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} 77 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {}
74 78
75 void TearDown() override { 79 void TearDown() override {
80 observer_.Reset();
76 support_->EvictCurrentSurface(); 81 support_->EvictCurrentSurface();
77 testing::Test::TearDown(); 82 testing::Test::TearDown();
78 } 83 }
79 84
80 protected: 85 protected:
81 SurfaceManager manager_; 86 SurfaceManager manager_;
87 FakeSurfaceObserver observer_;
82 FakeCompositorFrameSinkSupportClient fake_client_; 88 FakeCompositorFrameSinkSupportClient fake_client_;
83 std::unique_ptr<CompositorFrameSinkSupport> support_; 89 std::unique_ptr<CompositorFrameSinkSupport> support_;
84 SurfaceAggregator aggregator_; 90 SurfaceAggregator aggregator_;
85 }; 91 };
86 92
87 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { 93 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest {
88 public: 94 public:
89 explicit SurfaceAggregatorValidSurfaceTest(bool use_damage_rect) 95 explicit SurfaceAggregatorValidSurfaceTest(bool use_damage_rect)
90 : SurfaceAggregatorTest(use_damage_rect), 96 : SurfaceAggregatorTest(use_damage_rect),
91 child_support_( 97 child_support_(
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 root_local_surface_id_); 187 root_local_surface_id_);
182 188
183 SurfaceId root_surface_id(support_->frame_sink_id(), root_local_surface_id_); 189 SurfaceId root_surface_id(support_->frame_sink_id(), root_local_surface_id_);
184 SurfaceId ids[] = {root_surface_id}; 190 SurfaceId ids[] = {root_surface_id};
185 191
186 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids)); 192 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids));
187 193
188 // Check that WillDrawSurface was called. 194 // Check that WillDrawSurface was called.
189 EXPECT_EQ(gfx::Rect(SurfaceSize()), fake_client_.last_damage_rect()); 195 EXPECT_EQ(gfx::Rect(SurfaceSize()), fake_client_.last_damage_rect());
190 EXPECT_EQ(root_local_surface_id_, fake_client_.last_local_surface_id()); 196 EXPECT_EQ(root_local_surface_id_, fake_client_.last_local_surface_id());
197
198 // Check that SurfaceObserver::OnSurfaceWillDraw was called.
199 EXPECT_TRUE(observer_.SurfaceWillDrawCalled(root_surface_id));
191 } 200 }
192 201
193 TEST_F(SurfaceAggregatorValidSurfaceTest, OpacityCopied) { 202 TEST_F(SurfaceAggregatorValidSurfaceTest, OpacityCopied) {
194 std::unique_ptr<CompositorFrameSinkSupport> embedded_support( 203 std::unique_ptr<CompositorFrameSinkSupport> embedded_support(
195 CompositorFrameSinkSupport::Create( 204 CompositorFrameSinkSupport::Create(
196 nullptr, &manager_, kArbitraryFrameSinkId1, kRootIsRoot, 205 nullptr, &manager_, kArbitraryFrameSinkId1, kRootIsRoot,
197 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints)); 206 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints));
198 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId(); 207 LocalSurfaceId embedded_local_surface_id = allocator_.GenerateId();
199 SurfaceId embedded_surface_id(embedded_support->frame_sink_id(), 208 SurfaceId embedded_surface_id(embedded_support->frame_sink_id(),
200 embedded_local_surface_id); 209 embedded_local_surface_id);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 test::Quad expected_quads1[] = {test::Quad::SolidColorQuad(SK_ColorRED)}; 397 test::Quad expected_quads1[] = {test::Quad::SolidColorQuad(SK_ColorRED)};
389 test::Pass expected_passes1[] = { 398 test::Pass expected_passes1[] = {
390 test::Pass(expected_quads1, arraysize(expected_quads1))}; 399 test::Pass(expected_quads1, arraysize(expected_quads1))};
391 400
392 SurfaceId root_surface_id(support_->frame_sink_id(), root_local_surface_id_); 401 SurfaceId root_surface_id(support_->frame_sink_id(), root_local_surface_id_);
393 SurfaceId ids[] = {root_surface_id, primary_child_surface_id, 402 SurfaceId ids[] = {root_surface_id, primary_child_surface_id,
394 fallback_child_surface_id}; 403 fallback_child_surface_id};
395 AggregateAndVerify(expected_passes1, arraysize(expected_passes1), ids, 404 AggregateAndVerify(expected_passes1, arraysize(expected_passes1), ids,
396 arraysize(ids)); 405 arraysize(ids));
397 406
407 // Check that SurfaceObserver::OnSurfaceWillDraw was called only
408 // for the fallback surface.
409 EXPECT_FALSE(observer_.SurfaceWillDrawCalled(primary_child_surface_id));
410 EXPECT_TRUE(observer_.SurfaceWillDrawCalled(fallback_child_surface_id));
411
412 observer_.Reset();
413
398 test::Quad primary_child_quads[] = { 414 test::Quad primary_child_quads[] = {
399 test::Quad::SolidColorQuad(SK_ColorGREEN)}; 415 test::Quad::SolidColorQuad(SK_ColorGREEN)};
400 test::Pass primary_child_passes[] = { 416 test::Pass primary_child_passes[] = {
401 test::Pass(primary_child_quads, arraysize(primary_child_quads))}; 417 test::Pass(primary_child_quads, arraysize(primary_child_quads))};
402 418
403 // Submit a CompositorFrame to the primary Surface containing a green 419 // Submit a CompositorFrame to the primary Surface containing a green
404 // SolidColorDrawQuad. 420 // SolidColorDrawQuad.
405 SubmitCompositorFrame(primary_child_support.get(), primary_child_passes, 421 SubmitCompositorFrame(primary_child_support.get(), primary_child_passes,
406 arraysize(primary_child_passes), 422 arraysize(primary_child_passes),
407 primary_child_local_surface_id); 423 primary_child_local_surface_id);
408 424
409 // Now that the primary Surface has a CompositorFrame, we expect 425 // Now that the primary Surface has a CompositorFrame, we expect
410 // SurfaceAggregator to embed the primary Surface, and drop the fallback 426 // SurfaceAggregator to embed the primary Surface, and drop the fallback
411 // Surface. 427 // Surface.
412 test::Quad expected_quads2[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)}; 428 test::Quad expected_quads2[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
413 test::Pass expected_passes2[] = { 429 test::Pass expected_passes2[] = {
414 test::Pass(expected_quads2, arraysize(expected_quads2))}; 430 test::Pass(expected_quads2, arraysize(expected_quads2))};
415 AggregateAndVerify(expected_passes2, arraysize(expected_passes2), ids, 431 AggregateAndVerify(expected_passes2, arraysize(expected_passes2), ids,
416 arraysize(ids)); 432 arraysize(ids));
417 433
434 // Check that SurfaceObserver::OnSurfaceWillDraw was called only
435 // for the primary surface.
436 EXPECT_TRUE(observer_.SurfaceWillDrawCalled(primary_child_surface_id));
437 EXPECT_FALSE(observer_.SurfaceWillDrawCalled(fallback_child_surface_id));
438
418 primary_child_support->EvictCurrentSurface(); 439 primary_child_support->EvictCurrentSurface();
419 fallback_child_support->EvictCurrentSurface(); 440 fallback_child_support->EvictCurrentSurface();
420 } 441 }
421 442
422 // This test verifies that in the presence of both primary Surface and fallback 443 // This test verifies that in the presence of both primary Surface and fallback
423 // Surface, the fallback will not be used. 444 // Surface, the fallback will not be used.
424 TEST_F(SurfaceAggregatorValidSurfaceTest, FallbackSurfaceReferenceWithPrimary) { 445 TEST_F(SurfaceAggregatorValidSurfaceTest, FallbackSurfaceReferenceWithPrimary) {
425 std::unique_ptr<CompositorFrameSinkSupport> primary_child_support = 446 std::unique_ptr<CompositorFrameSinkSupport> primary_child_support =
426 CompositorFrameSinkSupport::Create( 447 CompositorFrameSinkSupport::Create(
427 nullptr, &manager_, kArbitraryFrameSinkId1, kChildIsRoot, 448 nullptr, &manager_, kArbitraryFrameSinkId1, kChildIsRoot,
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after
2270 aggregated_frame = aggregator_.Aggregate(surface_id); 2291 aggregated_frame = aggregator_.Aggregate(surface_id);
2271 EXPECT_EQ(3u, aggregated_frame.render_pass_list.size()); 2292 EXPECT_EQ(3u, aggregated_frame.render_pass_list.size());
2272 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[0]->color_space); 2293 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[0]->color_space);
2273 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[1]->color_space); 2294 EXPECT_EQ(color_space1, aggregated_frame.render_pass_list[1]->color_space);
2274 EXPECT_EQ(color_space3, aggregated_frame.render_pass_list[2]->color_space); 2295 EXPECT_EQ(color_space3, aggregated_frame.render_pass_list[2]->color_space);
2275 } 2296 }
2276 2297
2277 } // namespace 2298 } // namespace
2278 } // namespace cc 2299 } // namespace cc
2279 2300
OLDNEW
« no previous file with comments | « cc/surfaces/surface_aggregator.cc ('k') | cc/surfaces/surface_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698