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