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/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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 compositor_frame_sink_client.PassInterface())); | 30 compositor_frame_sink_client.PassInterface())); |
31 return base::WrapUnique(new ClientCompositorFrameSink( | 31 return base::WrapUnique(new ClientCompositorFrameSink( |
32 std::move(context_provider), gpu_memory_buffer_manager, | 32 std::move(context_provider), gpu_memory_buffer_manager, |
33 compositor_frame_sink.PassInterface(), | 33 compositor_frame_sink.PassInterface(), |
34 std::move(compositor_frame_sink_client_request), | 34 std::move(compositor_frame_sink_client_request), |
35 enable_surface_synchronization)); | 35 enable_surface_synchronization)); |
36 } | 36 } |
37 | 37 |
38 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} | 38 ClientCompositorFrameSink::~ClientCompositorFrameSink() {} |
39 | 39 |
| 40 void ClientCompositorFrameSink::SetSurfaceChangedCallback( |
| 41 const SurfaceChangedCallback& callback) { |
| 42 DCHECK(!surface_changed_callback_); |
| 43 surface_changed_callback_ = callback; |
| 44 } |
| 45 |
40 bool ClientCompositorFrameSink::BindToClient( | 46 bool ClientCompositorFrameSink::BindToClient( |
41 cc::CompositorFrameSinkClient* client) { | 47 cc::CompositorFrameSinkClient* client) { |
42 if (!cc::CompositorFrameSink::BindToClient(client)) | 48 if (!cc::CompositorFrameSink::BindToClient(client)) |
43 return false; | 49 return false; |
44 | 50 |
45 DCHECK(!thread_checker_); | 51 DCHECK(!thread_checker_); |
46 thread_checker_.reset(new base::ThreadChecker()); | 52 thread_checker_.reset(new base::ThreadChecker()); |
47 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); | 53 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); |
48 client_binding_.reset( | 54 client_binding_.reset( |
49 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( | 55 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( |
50 this, std::move(client_request_))); | 56 this, std::move(client_request_))); |
51 | 57 |
52 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); | 58 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); |
53 | 59 |
54 client->SetBeginFrameSource(begin_frame_source_.get()); | 60 client->SetBeginFrameSource(begin_frame_source_.get()); |
55 return true; | 61 return true; |
56 } | 62 } |
57 | 63 |
58 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()); |
59 client_->SetBeginFrameSource(nullptr); | 67 client_->SetBeginFrameSource(nullptr); |
60 begin_frame_source_.reset(); | 68 begin_frame_source_.reset(); |
61 client_binding_.reset(); | 69 client_binding_.reset(); |
62 compositor_frame_sink_.reset(); | 70 compositor_frame_sink_.reset(); |
63 cc::CompositorFrameSink::DetachFromClient(); | 71 cc::CompositorFrameSink::DetachFromClient(); |
64 } | 72 } |
65 | 73 |
66 void ClientCompositorFrameSink::SetLocalSurfaceId( | 74 void ClientCompositorFrameSink::SetLocalSurfaceId( |
67 const cc::LocalSurfaceId& local_surface_id) { | 75 const cc::LocalSurfaceId& local_surface_id) { |
68 DCHECK(local_surface_id.is_valid()); | 76 DCHECK(local_surface_id.is_valid()); |
69 DCHECK(enable_surface_synchronization_); | 77 DCHECK(enable_surface_synchronization_); |
70 local_surface_id_ = local_surface_id; | 78 local_surface_id_ = local_surface_id; |
71 } | 79 } |
72 | 80 |
73 void ClientCompositorFrameSink::SubmitCompositorFrame( | 81 void ClientCompositorFrameSink::SubmitCompositorFrame( |
74 cc::CompositorFrame frame) { | 82 cc::CompositorFrame frame) { |
75 DCHECK(thread_checker_); | 83 DCHECK(thread_checker_); |
76 DCHECK(thread_checker_->CalledOnValidThread()); | 84 DCHECK(thread_checker_->CalledOnValidThread()); |
77 if (!compositor_frame_sink_) | 85 if (!compositor_frame_sink_) |
78 return; | 86 return; |
79 | 87 |
80 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, | 88 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, |
81 frame.metadata.begin_frame_ack.sequence_number); | 89 frame.metadata.begin_frame_ack.sequence_number); |
82 | 90 |
| 91 bool surface_changed = false; |
83 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(); |
84 if (!local_surface_id_.is_valid() || | 93 if (!local_surface_id_.is_valid() || |
85 frame_size != last_submitted_frame_size_) { | 94 frame_size != last_submitted_frame_size_) { |
86 last_submitted_frame_size_ = frame_size; | 95 last_submitted_frame_size_ = frame_size; |
87 if (!enable_surface_synchronization_) | 96 if (!enable_surface_synchronization_) { |
88 local_surface_id_ = id_allocator_.GenerateId(); | 97 local_surface_id_ = id_allocator_.GenerateId(); |
| 98 surface_changed = true; |
| 99 } |
89 } | 100 } |
90 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, | 101 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, |
91 std::move(frame)); | 102 std::move(frame)); |
| 103 if (surface_changed && surface_changed_callback_) |
| 104 surface_changed_callback_.Run(local_surface_id_, frame_size); |
92 } | 105 } |
93 | 106 |
94 ClientCompositorFrameSink::ClientCompositorFrameSink( | 107 ClientCompositorFrameSink::ClientCompositorFrameSink( |
95 scoped_refptr<cc::ContextProvider> context_provider, | 108 scoped_refptr<cc::ContextProvider> context_provider, |
96 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 109 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
97 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, | 110 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, |
98 cc::mojom::MojoCompositorFrameSinkClientRequest client_request, | 111 cc::mojom::MojoCompositorFrameSinkClientRequest client_request, |
99 bool enable_surface_synchronization) | 112 bool enable_surface_synchronization) |
100 : cc::CompositorFrameSink(std::move(context_provider), | 113 : cc::CompositorFrameSink(std::move(context_provider), |
101 nullptr, | 114 nullptr, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 ClientCompositorFrameSinkBinding::TakeFrameSinkRequest() { | 165 ClientCompositorFrameSinkBinding::TakeFrameSinkRequest() { |
153 return std::move(compositor_frame_sink_request_); | 166 return std::move(compositor_frame_sink_request_); |
154 } | 167 } |
155 | 168 |
156 cc::mojom::MojoCompositorFrameSinkClientPtrInfo | 169 cc::mojom::MojoCompositorFrameSinkClientPtrInfo |
157 ClientCompositorFrameSinkBinding::TakeFrameSinkClient() { | 170 ClientCompositorFrameSinkBinding::TakeFrameSinkClient() { |
158 return std::move(compositor_frame_sink_client_); | 171 return std::move(compositor_frame_sink_client_); |
159 } | 172 } |
160 | 173 |
161 } // namespace ui | 174 } // namespace ui |
OLD | NEW |