OLD | NEW |
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 "services/ui/public/cpp/client_compositor_frame_sink.h" | 5 #include "services/ui/public/cpp/client_compositor_frame_sink.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "cc/base/switches.h" | 10 #include "cc/base/switches.h" |
11 #include "cc/output/begin_frame_args.h" | 11 #include "cc/output/begin_frame_args.h" |
12 #include "cc/output/compositor_frame.h" | 12 #include "cc/output/compositor_frame.h" |
13 #include "cc/output/compositor_frame_sink_client.h" | 13 #include "cc/output/compositor_frame_sink_client.h" |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 | 16 |
17 // static | 17 // static |
18 std::unique_ptr<ClientCompositorFrameSink> ClientCompositorFrameSink::Create( | 18 std::unique_ptr<ClientCompositorFrameSink> ClientCompositorFrameSink::Create( |
19 const cc::FrameSinkId& frame_sink_id, | |
20 scoped_refptr<cc::ContextProvider> context_provider, | 19 scoped_refptr<cc::ContextProvider> context_provider, |
21 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 20 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
22 std::unique_ptr<ClientCompositorFrameSinkBinding>* | 21 std::unique_ptr<ClientCompositorFrameSinkBinding>* |
23 compositor_frame_sink_binding) { | 22 compositor_frame_sink_binding) { |
24 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink; | 23 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink; |
25 cc::mojom::MojoCompositorFrameSinkClientPtr compositor_frame_sink_client; | 24 cc::mojom::MojoCompositorFrameSinkClientPtr compositor_frame_sink_client; |
26 cc::mojom::MojoCompositorFrameSinkClientRequest | 25 cc::mojom::MojoCompositorFrameSinkClientRequest |
27 compositor_frame_sink_client_request = | 26 compositor_frame_sink_client_request = |
28 MakeRequest(&compositor_frame_sink_client); | 27 MakeRequest(&compositor_frame_sink_client); |
29 | 28 |
30 compositor_frame_sink_binding->reset(new ClientCompositorFrameSinkBinding( | 29 compositor_frame_sink_binding->reset(new ClientCompositorFrameSinkBinding( |
31 MakeRequest(&compositor_frame_sink), | 30 MakeRequest(&compositor_frame_sink), |
32 compositor_frame_sink_client.PassInterface())); | 31 compositor_frame_sink_client.PassInterface())); |
33 return base::WrapUnique(new ClientCompositorFrameSink( | 32 return base::WrapUnique(new ClientCompositorFrameSink( |
34 frame_sink_id, std::move(context_provider), gpu_memory_buffer_manager, | 33 std::move(context_provider), gpu_memory_buffer_manager, |
35 compositor_frame_sink.PassInterface(), | 34 compositor_frame_sink.PassInterface(), |
36 std::move(compositor_frame_sink_client_request))); | 35 std::move(compositor_frame_sink_client_request))); |
37 } | 36 } |
38 | 37 |
39 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} | 38 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} |
40 | 39 |
| 40 void ClientCompositorFrameSink::SetSurfaceChangedCallback( |
| 41 const SurfaceChangedCallback& callback) { |
| 42 DCHECK(!surface_changed_callback_); |
| 43 surface_changed_callback_ = callback; |
| 44 } |
| 45 |
41 bool ClientCompositorFrameSink::BindToClient( | 46 bool ClientCompositorFrameSink::BindToClient( |
42 cc::CompositorFrameSinkClient* client) { | 47 cc::CompositorFrameSinkClient* client) { |
43 if (!cc::CompositorFrameSink::BindToClient(client)) | 48 if (!cc::CompositorFrameSink::BindToClient(client)) |
44 return false; | 49 return false; |
45 | 50 |
46 DCHECK(!thread_checker_); | 51 DCHECK(!thread_checker_); |
47 thread_checker_.reset(new base::ThreadChecker()); | 52 thread_checker_.reset(new base::ThreadChecker()); |
48 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); | 53 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); |
49 client_binding_.reset( | 54 client_binding_.reset( |
50 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( | 55 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( |
51 this, std::move(client_request_))); | 56 this, std::move(client_request_))); |
52 | 57 |
53 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); | 58 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); |
54 | 59 |
55 client->SetBeginFrameSource(begin_frame_source_.get()); | 60 client->SetBeginFrameSource(begin_frame_source_.get()); |
56 return true; | 61 return true; |
57 } | 62 } |
58 | 63 |
59 void ClientCompositorFrameSink::DetachFromClient() { | 64 void ClientCompositorFrameSink::DetachFromClient() { |
| 65 if (surface_changed_callback_ && local_surface_id_.is_valid()) |
| 66 surface_changed_callback_.Run(cc::LocalSurfaceId(), gfx::Size()); |
60 client_->SetBeginFrameSource(nullptr); | 67 client_->SetBeginFrameSource(nullptr); |
61 begin_frame_source_.reset(); | 68 begin_frame_source_.reset(); |
62 client_binding_.reset(); | 69 client_binding_.reset(); |
63 compositor_frame_sink_.reset(); | 70 compositor_frame_sink_.reset(); |
64 cc::CompositorFrameSink::DetachFromClient(); | 71 cc::CompositorFrameSink::DetachFromClient(); |
65 } | 72 } |
66 | 73 |
67 void ClientCompositorFrameSink::SetLocalSurfaceId( | 74 void ClientCompositorFrameSink::SetLocalSurfaceId( |
68 const cc::LocalSurfaceId& local_surface_id) { | 75 const cc::LocalSurfaceId& local_surface_id) { |
69 DCHECK(local_surface_id.is_valid()); | 76 DCHECK(local_surface_id.is_valid()); |
70 DCHECK(enable_surface_synchronization_); | 77 DCHECK(enable_surface_synchronization_); |
71 local_surface_id_ = local_surface_id; | 78 local_surface_id_ = local_surface_id; |
72 } | 79 } |
73 | 80 |
74 void ClientCompositorFrameSink::SubmitCompositorFrame( | 81 void ClientCompositorFrameSink::SubmitCompositorFrame( |
75 cc::CompositorFrame frame) { | 82 cc::CompositorFrame frame) { |
76 DCHECK(thread_checker_); | 83 DCHECK(thread_checker_); |
77 DCHECK(thread_checker_->CalledOnValidThread()); | 84 DCHECK(thread_checker_->CalledOnValidThread()); |
78 if (!compositor_frame_sink_) | 85 if (!compositor_frame_sink_) |
79 return; | 86 return; |
80 | 87 |
81 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, | 88 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, |
82 frame.metadata.begin_frame_ack.sequence_number); | 89 frame.metadata.begin_frame_ack.sequence_number); |
83 | 90 |
| 91 bool surface_changed = false; |
84 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 92 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
85 if (!enable_surface_synchronization_ && | 93 if (!enable_surface_synchronization_ && |
86 (!local_surface_id_.is_valid() || | 94 (!local_surface_id_.is_valid() || |
87 frame_size != last_submitted_frame_size_)) { | 95 frame_size != last_submitted_frame_size_)) { |
88 local_surface_id_ = id_allocator_.GenerateId(); | 96 local_surface_id_ = id_allocator_.GenerateId(); |
| 97 last_submitted_frame_size_ = frame_size; |
| 98 surface_changed = true; |
89 } | 99 } |
90 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, | 100 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, |
91 std::move(frame)); | 101 std::move(frame)); |
92 last_submitted_frame_size_ = frame_size; | 102 if (surface_changed && surface_changed_callback_) { |
| 103 surface_changed_callback_.Run(local_surface_id_, frame_size); |
| 104 } |
93 } | 105 } |
94 | 106 |
95 ClientCompositorFrameSink::ClientCompositorFrameSink( | 107 ClientCompositorFrameSink::ClientCompositorFrameSink( |
96 const cc::FrameSinkId& frame_sink_id, | |
97 scoped_refptr<cc::ContextProvider> context_provider, | 108 scoped_refptr<cc::ContextProvider> context_provider, |
98 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 109 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
99 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, | 110 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, |
100 cc::mojom::MojoCompositorFrameSinkClientRequest client_request) | 111 cc::mojom::MojoCompositorFrameSinkClientRequest client_request) |
101 : cc::CompositorFrameSink(std::move(context_provider), | 112 : cc::CompositorFrameSink(std::move(context_provider), |
102 nullptr, | 113 nullptr, |
103 gpu_memory_buffer_manager, | 114 gpu_memory_buffer_manager, |
104 nullptr), | 115 nullptr), |
105 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)), | 116 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)), |
106 client_request_(std::move(client_request)), | 117 client_request_(std::move(client_request)) { |
107 frame_sink_id_(frame_sink_id) { | |
108 enable_surface_synchronization_ = | 118 enable_surface_synchronization_ = |
109 base::CommandLine::ForCurrentProcess()->HasSwitch( | 119 base::CommandLine::ForCurrentProcess()->HasSwitch( |
110 cc::switches::kEnableSurfaceSynchronization); | 120 cc::switches::kEnableSurfaceSynchronization); |
111 } | 121 } |
112 | 122 |
113 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck( | 123 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck( |
114 const cc::ReturnedResourceArray& resources) { | 124 const cc::ReturnedResourceArray& resources) { |
115 DCHECK(thread_checker_); | 125 DCHECK(thread_checker_); |
116 DCHECK(thread_checker_->CalledOnValidThread()); | 126 DCHECK(thread_checker_->CalledOnValidThread()); |
117 if (!client_) | 127 if (!client_) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 ClientCompositorFrameSinkBinding::TakeFrameSinkRequest() { | 167 ClientCompositorFrameSinkBinding::TakeFrameSinkRequest() { |
158 return std::move(compositor_frame_sink_request_); | 168 return std::move(compositor_frame_sink_request_); |
159 } | 169 } |
160 | 170 |
161 cc::mojom::MojoCompositorFrameSinkClientPtrInfo | 171 cc::mojom::MojoCompositorFrameSinkClientPtrInfo |
162 ClientCompositorFrameSinkBinding::TakeFrameSinkClient() { | 172 ClientCompositorFrameSinkBinding::TakeFrameSinkClient() { |
163 return std::move(compositor_frame_sink_client_); | 173 return std::move(compositor_frame_sink_client_); |
164 } | 174 } |
165 | 175 |
166 } // namespace ui | 176 } // namespace ui |
OLD | NEW |