Chromium Code Reviews| 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_.reset(new base::ThreadChecker()); | |
|
msw
2017/03/10 20:08:40
nit: = base::MakeUnique
Alex Z.
2017/03/11 03:52:20
Done.
| |
| 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_); | |
|
msw
2017/03/10 20:08:40
nit: these are not really needed right before the
Alex Z.
2017/03/11 03:52:20
Done. These are there because I copied them from C
| |
| 48 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 49 if (!compositor_frame_sink_) | |
| 50 return; | |
| 51 | |
| 52 gfx::Size frame_size = last_submitted_frame_size_; | |
| 53 if (!frame.render_pass_list.empty()) | |
| 54 frame_size = frame.render_pass_list.back()->output_rect.size(); | |
| 55 | |
| 56 if (!local_surface_id_.is_valid() || | |
| 57 frame_size != last_submitted_frame_size_) { | |
| 58 local_surface_id_ = id_allocator_.GenerateId(); | |
| 59 display_private_->ResizeDisplay(frame_size); | |
| 60 } | |
| 61 display_private_->SetLocalSurfaceId(local_surface_id_, | |
| 62 frame.metadata.device_scale_factor); | |
| 63 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_, | |
| 64 std::move(frame)); | |
| 65 last_submitted_frame_size_ = frame_size; | |
| 66 } | |
| 67 | |
| 68 void DisplayClientCompositorFrameSink::DidReceiveCompositorFrameAck() { | |
| 69 DCHECK(thread_checker_); | |
| 70 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 71 if (!client_) | |
| 72 return; | |
| 73 client_->DidReceiveCompositorFrameAck(); | |
| 74 } | |
| 75 | |
| 76 void DisplayClientCompositorFrameSink::OnBeginFrame( | |
| 77 const cc::BeginFrameArgs& begin_frame_args) { | |
| 78 DCHECK(thread_checker_); | |
| 79 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 80 begin_frame_source_->OnBeginFrame(begin_frame_args); | |
| 81 } | |
| 82 | |
| 83 void DisplayClientCompositorFrameSink::ReclaimResources( | |
| 84 const cc::ReturnedResourceArray& resources) { | |
| 85 DCHECK(thread_checker_); | |
| 86 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 87 if (!client_) | |
| 88 return; | |
| 89 client_->ReclaimResources(resources); | |
| 90 } | |
| 91 | |
| 92 void DisplayClientCompositorFrameSink::WillDrawSurface( | |
| 93 const cc::LocalSurfaceId& local_surface_id, | |
| 94 const gfx::Rect& damage_rect) { | |
| 95 // TODO(fsamuel, staraz): Implement this. | |
| 96 } | |
| 97 | |
| 98 void DisplayClientCompositorFrameSink::OnNeedsBeginFrames( | |
| 99 bool needs_begin_frames) { | |
| 100 DCHECK(thread_checker_); | |
| 101 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 102 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); | |
| 103 } | |
| 104 | |
| 105 void DisplayClientCompositorFrameSink::OnDidFinishFrame( | |
| 106 const cc::BeginFrameAck& ack) { | |
| 107 // TODO(eseckler): Pass on the ack to compositor_frame_sink_. | |
|
msw
2017/03/10 20:08:40
optional nit: CC eseckler@ and use vertical bars:
| |
| 108 } | |
| 109 | |
| 110 } // namespace ws | |
| 111 } // namespace ui | |
| OLD | NEW |