| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "services/ui/public/cpp/display_client_compositor_frame_sink.h" |
| 6 |
| 7 #include "base/threading/thread_checker.h" |
| 8 #include "cc/output/compositor_frame_sink_client.h" |
| 9 #include "services/ui/public/cpp/client_compositor_frame_sink.h" |
| 10 |
| 11 namespace ui { |
| 12 |
| 13 DisplayClientCompositorFrameSink::DisplayClientCompositorFrameSink( |
| 14 const cc::FrameSinkId& frame_sink_id, |
| 15 cc::mojom::MojoCompositorFrameSinkAssociatedPtrInfo |
| 16 compositor_frame_sink_info, |
| 17 cc::mojom::DisplayPrivateAssociatedPtrInfo display_private_info, |
| 18 cc::mojom::MojoCompositorFrameSinkClientRequest client_request) |
| 19 : cc::CompositorFrameSink(nullptr, nullptr, nullptr, nullptr), |
| 20 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)), |
| 21 client_request_(std::move(client_request)), |
| 22 display_private_info_(std::move(display_private_info)), |
| 23 frame_sink_id_(frame_sink_id) {} |
| 24 |
| 25 DisplayClientCompositorFrameSink::~DisplayClientCompositorFrameSink() {} |
| 26 |
| 27 bool DisplayClientCompositorFrameSink::BindToClient( |
| 28 cc::CompositorFrameSinkClient* client) { |
| 29 if (!cc::CompositorFrameSink::BindToClient(client)) |
| 30 return false; |
| 31 DCHECK(!thread_checker_); |
| 32 thread_checker_.reset(new base::ThreadChecker()); |
| 33 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); |
| 34 display_private_.Bind(std::move(display_private_info_)); |
| 35 client_binding_.reset( |
| 36 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( |
| 37 this, std::move(client_request_))); |
| 38 |
| 39 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); |
| 40 |
| 41 client->SetBeginFrameSource(begin_frame_source_.get()); |
| 42 return true; |
| 43 } |
| 44 |
| 45 void DisplayClientCompositorFrameSink::DetachFromClient() { |
| 46 client_->SetBeginFrameSource(nullptr); |
| 47 begin_frame_source_.reset(); |
| 48 client_binding_.reset(); |
| 49 compositor_frame_sink_.reset(); |
| 50 display_private_.reset(); |
| 51 cc::CompositorFrameSink::DetachFromClient(); |
| 52 } |
| 53 |
| 54 void DisplayClientCompositorFrameSink::SubmitCompositorFrame( |
| 55 cc::CompositorFrame frame) { |
| 56 DCHECK(thread_checker_); |
| 57 DCHECK(thread_checker_->CalledOnValidThread()); |
| 58 if (!compositor_frame_sink_) |
| 59 return; |
| 60 |
| 61 gfx::Size frame_size = last_submitted_frame_size_; |
| 62 if (!frame.render_pass_list.empty()) |
| 63 frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 64 |
| 65 if (!local_surface_id_.is_valid() || |
| 66 frame_size != last_submitted_frame_size_) { |
| 67 local_surface_id_ = id_allocator_.GenerateId(); |
| 68 display_private_->ResizeDisplay(frame_size); |
| 69 } |
| 70 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, |
| 71 std::move(frame)); |
| 72 } |
| 73 |
| 74 void DisplayClientCompositorFrameSink::DidReceiveCompositorFrameAck() { |
| 75 DCHECK(thread_checker_); |
| 76 DCHECK(thread_checker_->CalledOnValidThread()); |
| 77 if (!client_) |
| 78 return; |
| 79 client_->DidReceiveCompositorFrameAck(); |
| 80 } |
| 81 |
| 82 void DisplayClientCompositorFrameSink::OnBeginFrame( |
| 83 const cc::BeginFrameArgs& begin_frame_args) { |
| 84 begin_frame_source_->OnBeginFrame(begin_frame_args); |
| 85 } |
| 86 |
| 87 void DisplayClientCompositorFrameSink::ReclaimResources( |
| 88 const cc::ReturnedResourceArray& resources) { |
| 89 DCHECK(thread_checker_); |
| 90 DCHECK(thread_checker_->CalledOnValidThread()); |
| 91 if (!client_) |
| 92 return; |
| 93 client_->ReclaimResources(resources); |
| 94 } |
| 95 |
| 96 void DisplayClientCompositorFrameSink::WillDrawSurface( |
| 97 const cc::LocalSurfaceId& local_surface_id, |
| 98 const gfx::Rect& damage_rect) { |
| 99 // TODO(fsamuel, staraz): Implement this. |
| 100 } |
| 101 |
| 102 void DisplayClientCompositorFrameSink::OnNeedsBeginFrames( |
| 103 bool needs_begin_frames) { |
| 104 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); |
| 105 } |
| 106 |
| 107 void DisplayClientCompositorFrameSink::OnDidFinishFrame( |
| 108 const cc::BeginFrameAck& ack) { |
| 109 // TODO(eseckler): Pass on the ack to compositor_frame_sink_. |
| 110 } |
| 111 |
| 112 } // namespace ui |
| OLD | NEW |