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

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

Issue 2795683003: [cc]Replace use of SurfaceFactory with CompositorFrameSinkSupport in tests (Closed)
Patch Set: Update returned_resources_ in FakeCompositorFrameSinkSupportClient::DidReceiveCompositorFrameAck Created 3 years, 8 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 "cc/surfaces/display.h" 5 #include "cc/surfaces/display.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/test/null_task_runner.h" 10 #include "base/test/null_task_runner.h"
11 #include "cc/output/compositor_frame.h" 11 #include "cc/output/compositor_frame.h"
12 #include "cc/output/copy_output_result.h" 12 #include "cc/output/copy_output_result.h"
13 #include "cc/output/texture_mailbox_deleter.h" 13 #include "cc/output/texture_mailbox_deleter.h"
14 #include "cc/quads/render_pass.h" 14 #include "cc/quads/render_pass.h"
15 #include "cc/resources/shared_bitmap_manager.h" 15 #include "cc/resources/shared_bitmap_manager.h"
16 #include "cc/scheduler/begin_frame_source.h" 16 #include "cc/scheduler/begin_frame_source.h"
17 #include "cc/surfaces/compositor_frame_sink_support.h"
17 #include "cc/surfaces/display_client.h" 18 #include "cc/surfaces/display_client.h"
18 #include "cc/surfaces/display_scheduler.h" 19 #include "cc/surfaces/display_scheduler.h"
19 #include "cc/surfaces/frame_sink_id.h" 20 #include "cc/surfaces/frame_sink_id.h"
20 #include "cc/surfaces/local_surface_id_allocator.h" 21 #include "cc/surfaces/local_surface_id_allocator.h"
21 #include "cc/surfaces/surface.h" 22 #include "cc/surfaces/surface.h"
22 #include "cc/surfaces/surface_factory.h"
23 #include "cc/surfaces/surface_factory_client.h"
24 #include "cc/surfaces/surface_manager.h" 23 #include "cc/surfaces/surface_manager.h"
25 #include "cc/test/fake_output_surface.h" 24 #include "cc/test/fake_output_surface.h"
26 #include "cc/test/scheduler_test_common.h" 25 #include "cc/test/scheduler_test_common.h"
27 #include "cc/test/test_shared_bitmap_manager.h" 26 #include "cc/test/test_shared_bitmap_manager.h"
28 #include "gpu/GLES2/gl2extchromium.h" 27 #include "gpu/GLES2/gl2extchromium.h"
29 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
31 30
32 using testing::AnyNumber; 31 using testing::AnyNumber;
33 32
34 namespace cc { 33 namespace cc {
35 namespace { 34 namespace {
36 35
37 static constexpr FrameSinkId kArbitraryFrameSinkId(3, 3); 36 static constexpr FrameSinkId kArbitraryFrameSinkId(3, 3);
38 37
39 class FakeSurfaceFactoryClient : public SurfaceFactoryClient {
40 public:
41 FakeSurfaceFactoryClient() : begin_frame_source_(nullptr) {}
42
43 void ReturnResources(const ReturnedResourceArray& resources) override {}
44
45 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {
46 begin_frame_source_ = begin_frame_source;
47 }
48
49 BeginFrameSource* begin_frame_source() { return begin_frame_source_; }
50
51 private:
52 BeginFrameSource* begin_frame_source_;
53 };
54
55 class TestSoftwareOutputDevice : public SoftwareOutputDevice { 38 class TestSoftwareOutputDevice : public SoftwareOutputDevice {
56 public: 39 public:
57 TestSoftwareOutputDevice() {} 40 TestSoftwareOutputDevice() {}
58 41
59 gfx::Rect damage_rect() const { return damage_rect_; } 42 gfx::Rect damage_rect() const { return damage_rect_; }
60 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; } 43 gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; }
61 }; 44 };
62 45
63 class TestDisplayScheduler : public DisplayScheduler { 46 class TestDisplayScheduler : public DisplayScheduler {
64 public: 47 public:
(...skipping 27 matching lines...) Expand all
92 75
93 bool damaged; 76 bool damaged;
94 bool display_resized_; 77 bool display_resized_;
95 bool has_new_root_surface; 78 bool has_new_root_surface;
96 bool swapped; 79 bool swapped;
97 }; 80 };
98 81
99 class DisplayTest : public testing::Test { 82 class DisplayTest : public testing::Test {
100 public: 83 public:
101 DisplayTest() 84 DisplayTest()
102 : factory_(kArbitraryFrameSinkId, &manager_, &surface_factory_client_), 85 : support_(CompositorFrameSinkSupport::Create(
103 task_runner_(new base::NullTaskRunner) { 86 nullptr,
104 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); 87 &manager_,
105 } 88 kArbitraryFrameSinkId,
89 true /* is_root */,
90 true /* handles_frame_sink_id_invalidation */,
91 true /* needs_sync_points */)),
92 task_runner_(new base::NullTaskRunner) {}
106 93
107 ~DisplayTest() override { 94 ~DisplayTest() override { support_->EvictFrame(); }
108 manager_.InvalidateFrameSinkId(kArbitraryFrameSinkId);
109 factory_.EvictSurface();
110 }
111 95
112 void SetUpDisplay(const RendererSettings& settings, 96 void SetUpDisplay(const RendererSettings& settings,
113 std::unique_ptr<TestWebGraphicsContext3D> context) { 97 std::unique_ptr<TestWebGraphicsContext3D> context) {
114 begin_frame_source_.reset(new StubBeginFrameSource); 98 begin_frame_source_.reset(new StubBeginFrameSource);
115 99
116 std::unique_ptr<FakeOutputSurface> output_surface; 100 std::unique_ptr<FakeOutputSurface> output_surface;
117 if (context) { 101 if (context) {
118 auto provider = TestContextProvider::Create(std::move(context)); 102 auto provider = TestContextProvider::Create(std::move(context));
119 provider->BindToCurrentThread(); 103 provider->BindToCurrentThread();
120 output_surface = FakeOutputSurface::Create3d(std::move(provider)); 104 output_surface = FakeOutputSurface::Create3d(std::move(provider));
(...skipping 16 matching lines...) Expand all
137 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get())); 121 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get()));
138 display_->SetVisible(true); 122 display_->SetVisible(true);
139 } 123 }
140 124
141 protected: 125 protected:
142 void SubmitCompositorFrame(RenderPassList* pass_list, 126 void SubmitCompositorFrame(RenderPassList* pass_list,
143 const LocalSurfaceId& local_surface_id) { 127 const LocalSurfaceId& local_surface_id) {
144 CompositorFrame frame; 128 CompositorFrame frame;
145 pass_list->swap(frame.render_pass_list); 129 pass_list->swap(frame.render_pass_list);
146 130
147 factory_.SubmitCompositorFrame(local_surface_id, std::move(frame), 131 support_->SubmitCompositorFrame(local_surface_id, std::move(frame));
148 SurfaceFactory::DrawCallback());
149 } 132 }
150 133
151 SurfaceManager manager_; 134 SurfaceManager manager_;
152 FakeSurfaceFactoryClient surface_factory_client_; 135 std::unique_ptr<CompositorFrameSinkSupport> support_;
153 SurfaceFactory factory_;
154 LocalSurfaceIdAllocator id_allocator_; 136 LocalSurfaceIdAllocator id_allocator_;
155 scoped_refptr<base::NullTaskRunner> task_runner_; 137 scoped_refptr<base::NullTaskRunner> task_runner_;
156 TestSharedBitmapManager shared_bitmap_manager_; 138 TestSharedBitmapManager shared_bitmap_manager_;
157 std::unique_ptr<BeginFrameSource> begin_frame_source_; 139 std::unique_ptr<BeginFrameSource> begin_frame_source_;
158 std::unique_ptr<Display> display_; 140 std::unique_ptr<Display> display_;
159 TestSoftwareOutputDevice* software_output_device_ = nullptr; 141 TestSoftwareOutputDevice* software_output_device_ = nullptr;
160 FakeOutputSurface* output_surface_ = nullptr; 142 FakeOutputSurface* output_surface_ = nullptr;
161 TestDisplayScheduler* scheduler_ = nullptr; 143 TestDisplayScheduler* scheduler_ = nullptr;
162 }; 144 };
163 145
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 pass->damage_rect = gfx::Rect(10, 10, 0, 0); 327 pass->damage_rect = gfx::Rect(10, 10, 0, 0);
346 pass->id = 1; 328 pass->id = 1;
347 329
348 pass_list.push_back(std::move(pass)); 330 pass_list.push_back(std::move(pass));
349 scheduler_->ResetDamageForTest(); 331 scheduler_->ResetDamageForTest();
350 332
351 CompositorFrame frame; 333 CompositorFrame frame;
352 pass_list.swap(frame.render_pass_list); 334 pass_list.swap(frame.render_pass_list);
353 frame.metadata.latency_info.push_back(ui::LatencyInfo()); 335 frame.metadata.latency_info.push_back(ui::LatencyInfo());
354 336
355 factory_.SubmitCompositorFrame(local_surface_id, std::move(frame), 337 support_->SubmitCompositorFrame(local_surface_id, std::move(frame));
356 SurfaceFactory::DrawCallback());
357 EXPECT_TRUE(scheduler_->damaged); 338 EXPECT_TRUE(scheduler_->damaged);
358 EXPECT_FALSE(scheduler_->display_resized_); 339 EXPECT_FALSE(scheduler_->display_resized_);
359 EXPECT_FALSE(scheduler_->has_new_root_surface); 340 EXPECT_FALSE(scheduler_->has_new_root_surface);
360 341
361 scheduler_->swapped = false; 342 scheduler_->swapped = false;
362 display_->DrawAndSwap(); 343 display_->DrawAndSwap();
363 EXPECT_TRUE(scheduler_->swapped); 344 EXPECT_TRUE(scheduler_->swapped);
364 EXPECT_EQ(4u, output_surface_->num_sent_frames()); 345 EXPECT_EQ(4u, output_surface_->num_sent_frames());
365 } 346 }
366 347
367 // Resize should cause a swap if no frame was swapped at the previous size. 348 // Resize should cause a swap if no frame was swapped at the previous size.
368 { 349 {
369 scheduler_->swapped = false; 350 scheduler_->swapped = false;
370 display_->Resize(gfx::Size(200, 200)); 351 display_->Resize(gfx::Size(200, 200));
371 EXPECT_FALSE(scheduler_->swapped); 352 EXPECT_FALSE(scheduler_->swapped);
372 EXPECT_EQ(4u, output_surface_->num_sent_frames()); 353 EXPECT_EQ(4u, output_surface_->num_sent_frames());
373 354
374 pass = RenderPass::Create(); 355 pass = RenderPass::Create();
375 pass->output_rect = gfx::Rect(0, 0, 200, 200); 356 pass->output_rect = gfx::Rect(0, 0, 200, 200);
376 pass->damage_rect = gfx::Rect(10, 10, 10, 10); 357 pass->damage_rect = gfx::Rect(10, 10, 10, 10);
377 pass->id = 1; 358 pass->id = 1;
378 359
379 pass_list.push_back(std::move(pass)); 360 pass_list.push_back(std::move(pass));
380 scheduler_->ResetDamageForTest(); 361 scheduler_->ResetDamageForTest();
381 362
382 CompositorFrame frame; 363 CompositorFrame frame;
383 pass_list.swap(frame.render_pass_list); 364 pass_list.swap(frame.render_pass_list);
384 365
385 factory_.SubmitCompositorFrame(local_surface_id, std::move(frame), 366 support_->SubmitCompositorFrame(local_surface_id, std::move(frame));
386 SurfaceFactory::DrawCallback());
387 EXPECT_TRUE(scheduler_->damaged); 367 EXPECT_TRUE(scheduler_->damaged);
388 EXPECT_FALSE(scheduler_->display_resized_); 368 EXPECT_FALSE(scheduler_->display_resized_);
389 EXPECT_FALSE(scheduler_->has_new_root_surface); 369 EXPECT_FALSE(scheduler_->has_new_root_surface);
390 370
391 scheduler_->swapped = false; 371 scheduler_->swapped = false;
392 display_->Resize(gfx::Size(100, 100)); 372 display_->Resize(gfx::Size(100, 100));
393 EXPECT_TRUE(scheduler_->swapped); 373 EXPECT_TRUE(scheduler_->swapped);
394 EXPECT_EQ(5u, output_surface_->num_sent_frames()); 374 EXPECT_EQ(5u, output_surface_->num_sent_frames());
395 375
396 // Latency info from previous frame should be sent now. 376 // Latency info from previous frame should be sent now.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 // Verify DidLoseOutputSurface callback is hooked up correctly. 495 // Verify DidLoseOutputSurface callback is hooked up correctly.
516 EXPECT_EQ(0, client.loss_count()); 496 EXPECT_EQ(0, client.loss_count());
517 output_surface_->context_provider()->ContextGL()->LoseContextCHROMIUM( 497 output_surface_->context_provider()->ContextGL()->LoseContextCHROMIUM(
518 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); 498 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
519 output_surface_->context_provider()->ContextGL()->Flush(); 499 output_surface_->context_provider()->ContextGL()->Flush();
520 EXPECT_EQ(1, client.loss_count()); 500 EXPECT_EQ(1, client.loss_count());
521 } 501 }
522 502
523 } // namespace 503 } // namespace
524 } // namespace cc 504 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/compositor_frame_sink_support.cc ('k') | cc/surfaces/surface_aggregator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698