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

Side by Side Diff: components/viz/client/client_compositor_frame_sink.cc

Issue 2903853002: Make RendererCompositorFrameSink derive from ClientCompositorFrameSink (Closed)
Patch Set: c 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/viz/client/client_compositor_frame_sink.h" 5 #include "components/viz/client/client_compositor_frame_sink.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "cc/output/begin_frame_args.h" 9 #include "cc/output/begin_frame_args.h"
10 #include "cc/output/compositor_frame.h" 10 #include "cc/output/compositor_frame.h"
11 #include "cc/output/compositor_frame_sink_client.h" 11 #include "cc/output/compositor_frame_sink_client.h"
12 12
13 namespace viz { 13 namespace viz {
14 14
15 ClientCompositorFrameSink::ClientCompositorFrameSink( 15 ClientCompositorFrameSink::ClientCompositorFrameSink(
16 scoped_refptr<cc::ContextProvider> context_provider, 16 scoped_refptr<cc::ContextProvider> context_provider,
17 scoped_refptr<cc::ContextProvider> worker_context_provider,
17 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 18 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
19 cc::SharedBitmapManager* shared_bitmap_manager,
20 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source,
18 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, 21 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info,
19 cc::mojom::MojoCompositorFrameSinkClientRequest client_request, 22 cc::mojom::MojoCompositorFrameSinkClientRequest client_request,
20 bool enable_surface_synchronization) 23 bool enable_surface_synchronization)
21 : cc::CompositorFrameSink(std::move(context_provider), 24 : cc::CompositorFrameSink(std::move(context_provider),
22 nullptr, 25 std::move(worker_context_provider),
23 gpu_memory_buffer_manager, 26 gpu_memory_buffer_manager,
24 nullptr), 27 shared_bitmap_manager),
28 synthetic_begin_frame_source_(std::move(synthetic_begin_frame_source)),
25 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)), 29 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)),
26 client_request_(std::move(client_request)), 30 client_request_(std::move(client_request)),
31 client_binding_(this),
27 enable_surface_synchronization_(enable_surface_synchronization) { 32 enable_surface_synchronization_(enable_surface_synchronization) {
28 DETACH_FROM_THREAD(thread_checker_); 33 DETACH_FROM_THREAD(thread_checker_);
29 } 34 }
35
36 ClientCompositorFrameSink::ClientCompositorFrameSink(
37 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider,
38 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source,
39 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info,
40 cc::mojom::MojoCompositorFrameSinkClientRequest client_request,
41 bool enable_surface_synchronization)
42 : cc::CompositorFrameSink(std::move(vulkan_context_provider)),
43 synthetic_begin_frame_source_(std::move(synthetic_begin_frame_source)),
44 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)),
45 client_request_(std::move(client_request)),
46 client_binding_(this),
47 enable_surface_synchronization_(enable_surface_synchronization) {
48 DETACH_FROM_THREAD(thread_checker_);
49 }
30 50
31 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} 51 ClientCompositorFrameSink::~ClientCompositorFrameSink() {}
32 52
33 bool ClientCompositorFrameSink::BindToClient( 53 bool ClientCompositorFrameSink::BindToClient(
34 cc::CompositorFrameSinkClient* client) { 54 cc::CompositorFrameSinkClient* client) {
55 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
56
35 if (!cc::CompositorFrameSink::BindToClient(client)) 57 if (!cc::CompositorFrameSink::BindToClient(client))
36 return false; 58 return false;
37 59
38 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 60 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
piman 2017/05/26 21:34:02 nit: duplicate of the above?
Saman Sami 2017/05/29 15:24:45 Done.
39 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); 61 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_));
40 client_binding_.reset( 62 client_binding_.Bind(std::move(client_request_));
41 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>(
42 this, std::move(client_request_)));
43 63
44 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); 64 if (synthetic_begin_frame_source_) {
65 client->SetBeginFrameSource(synthetic_begin_frame_source_.get());
66 } else {
67 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this);
68 client->SetBeginFrameSource(begin_frame_source_.get());
69 }
45 70
46 client->SetBeginFrameSource(begin_frame_source_.get());
47 return true; 71 return true;
48 } 72 }
49 73
50 void ClientCompositorFrameSink::DetachFromClient() { 74 void ClientCompositorFrameSink::DetachFromClient() {
75 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
51 client_->SetBeginFrameSource(nullptr); 76 client_->SetBeginFrameSource(nullptr);
52 begin_frame_source_.reset(); 77 begin_frame_source_.reset();
53 client_binding_.reset(); 78 synthetic_begin_frame_source_.reset();
79 client_binding_.Close();
54 compositor_frame_sink_.reset(); 80 compositor_frame_sink_.reset();
55 cc::CompositorFrameSink::DetachFromClient(); 81 cc::CompositorFrameSink::DetachFromClient();
56 } 82 }
57 83
58 void ClientCompositorFrameSink::SetLocalSurfaceId( 84 void ClientCompositorFrameSink::SetLocalSurfaceId(
59 const cc::LocalSurfaceId& local_surface_id) { 85 const cc::LocalSurfaceId& local_surface_id) {
60 DCHECK(local_surface_id.is_valid()); 86 DCHECK(local_surface_id.is_valid());
61 DCHECK(enable_surface_synchronization_); 87 DCHECK(enable_surface_synchronization_);
62 local_surface_id_ = local_surface_id; 88 local_surface_id_ = local_surface_id;
63 } 89 }
64 90
65 void ClientCompositorFrameSink::SubmitCompositorFrame( 91 void ClientCompositorFrameSink::SubmitCompositorFrame(
66 cc::CompositorFrame frame) { 92 cc::CompositorFrame frame) {
67 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 93 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
68 if (!compositor_frame_sink_)
69 return;
70
71 DCHECK(frame.metadata.begin_frame_ack.has_damage); 94 DCHECK(frame.metadata.begin_frame_ack.has_damage);
72 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, 95 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber,
73 frame.metadata.begin_frame_ack.sequence_number); 96 frame.metadata.begin_frame_ack.sequence_number);
74 97
75 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); 98 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size();
76 if (!local_surface_id_.is_valid() || 99 if (!local_surface_id_.is_valid() ||
77 frame_size != last_submitted_frame_size_) { 100 frame_size != last_submitted_frame_size_) {
78 last_submitted_frame_size_ = frame_size; 101 last_submitted_frame_size_ = frame_size;
79 if (!enable_surface_synchronization_) 102 if (!enable_surface_synchronization_)
80 local_surface_id_ = id_allocator_.GenerateId(); 103 local_surface_id_ = id_allocator_.GenerateId();
81 } 104 }
82 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, 105 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_,
83 std::move(frame)); 106 std::move(frame));
84 } 107 }
85 108
86 void ClientCompositorFrameSink::DidNotProduceFrame( 109 void ClientCompositorFrameSink::DidNotProduceFrame(
87 const cc::BeginFrameAck& ack) { 110 const cc::BeginFrameAck& ack) {
88 DCHECK(!ack.has_damage); 111 DCHECK(!ack.has_damage);
89 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number); 112 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number);
90 compositor_frame_sink_->DidNotProduceFrame(ack); 113 compositor_frame_sink_->DidNotProduceFrame(ack);
91 } 114 }
92 115
93 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck( 116 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck(
94 const cc::ReturnedResourceArray& resources) { 117 const cc::ReturnedResourceArray& resources) {
95 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 118 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
96 if (!client_)
97 return;
98 client_->ReclaimResources(resources); 119 client_->ReclaimResources(resources);
99 client_->DidReceiveCompositorFrameAck(); 120 client_->DidReceiveCompositorFrameAck();
100 } 121 }
101 122
102 void ClientCompositorFrameSink::OnBeginFrame( 123 void ClientCompositorFrameSink::OnBeginFrame(
103 const cc::BeginFrameArgs& begin_frame_args) { 124 const cc::BeginFrameArgs& begin_frame_args) {
104 begin_frame_source_->OnBeginFrame(begin_frame_args); 125 if (begin_frame_source_)
126 begin_frame_source_->OnBeginFrame(begin_frame_args);
105 } 127 }
106 128
107 void ClientCompositorFrameSink::ReclaimResources( 129 void ClientCompositorFrameSink::ReclaimResources(
108 const cc::ReturnedResourceArray& resources) { 130 const cc::ReturnedResourceArray& resources) {
109 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 131 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
110 if (!client_)
111 return;
112 client_->ReclaimResources(resources); 132 client_->ReclaimResources(resources);
113 } 133 }
114 134
115 void ClientCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { 135 void ClientCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) {
116 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); 136 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames);
117 } 137 }
118 138
119 } // namespace viz 139 } // namespace viz
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698