| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/aura/mus/window_compositor_frame_sink.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "cc/output/compositor_frame_sink_client.h" | |
| 10 #include "gpu/ipc/client/gpu_channel_host.h" | |
| 11 | |
| 12 namespace aura { | |
| 13 | |
| 14 // static | |
| 15 std::unique_ptr<WindowCompositorFrameSink> WindowCompositorFrameSink::Create( | |
| 16 const cc::FrameSinkId& frame_sink_id, | |
| 17 scoped_refptr<cc::ContextProvider> context_provider, | |
| 18 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
| 19 std::unique_ptr<WindowCompositorFrameSinkBinding>* | |
| 20 compositor_frame_sink_binding) { | |
| 21 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink; | |
| 22 cc::mojom::MojoCompositorFrameSinkClientPtr compositor_frame_sink_client; | |
| 23 cc::mojom::MojoCompositorFrameSinkClientRequest | |
| 24 compositor_frame_sink_client_request = | |
| 25 MakeRequest(&compositor_frame_sink_client); | |
| 26 | |
| 27 compositor_frame_sink_binding->reset(new WindowCompositorFrameSinkBinding( | |
| 28 MakeRequest(&compositor_frame_sink), | |
| 29 compositor_frame_sink_client.PassInterface())); | |
| 30 return base::WrapUnique(new WindowCompositorFrameSink( | |
| 31 frame_sink_id, std::move(context_provider), gpu_memory_buffer_manager, | |
| 32 compositor_frame_sink.PassInterface(), | |
| 33 std::move(compositor_frame_sink_client_request))); | |
| 34 } | |
| 35 | |
| 36 WindowCompositorFrameSink::~WindowCompositorFrameSink() {} | |
| 37 | |
| 38 bool WindowCompositorFrameSink::BindToClient( | |
| 39 cc::CompositorFrameSinkClient* client) { | |
| 40 if (!cc::CompositorFrameSink::BindToClient(client)) | |
| 41 return false; | |
| 42 | |
| 43 DCHECK(!thread_checker_); | |
| 44 thread_checker_.reset(new base::ThreadChecker()); | |
| 45 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_)); | |
| 46 client_binding_.reset( | |
| 47 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>( | |
| 48 this, std::move(client_request_))); | |
| 49 | |
| 50 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); | |
| 51 | |
| 52 client->SetBeginFrameSource(begin_frame_source_.get()); | |
| 53 return true; | |
| 54 } | |
| 55 | |
| 56 void WindowCompositorFrameSink::DetachFromClient() { | |
| 57 client_->SetBeginFrameSource(nullptr); | |
| 58 begin_frame_source_.reset(); | |
| 59 compositor_frame_sink_.reset(); | |
| 60 cc::CompositorFrameSink::DetachFromClient(); | |
| 61 } | |
| 62 | |
| 63 void WindowCompositorFrameSink::SubmitCompositorFrame( | |
| 64 cc::CompositorFrame frame) { | |
| 65 DCHECK(thread_checker_); | |
| 66 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 67 if (!compositor_frame_sink_) | |
| 68 return; | |
| 69 | |
| 70 gfx::Size frame_size = last_submitted_frame_size_; | |
| 71 if (!frame.render_pass_list.empty()) | |
| 72 frame_size = frame.render_pass_list[0]->output_rect.size(); | |
| 73 if (!local_frame_id_.is_valid() || frame_size != last_submitted_frame_size_) | |
| 74 local_frame_id_ = id_allocator_.GenerateId(); | |
| 75 | |
| 76 compositor_frame_sink_->SubmitCompositorFrame(local_frame_id_, | |
| 77 std::move(frame)); | |
| 78 | |
| 79 last_submitted_frame_size_ = frame_size; | |
| 80 } | |
| 81 | |
| 82 WindowCompositorFrameSink::WindowCompositorFrameSink( | |
| 83 const cc::FrameSinkId& frame_sink_id, | |
| 84 scoped_refptr<cc::ContextProvider> context_provider, | |
| 85 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
| 86 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info, | |
| 87 cc::mojom::MojoCompositorFrameSinkClientRequest client_request) | |
| 88 : cc::CompositorFrameSink(std::move(context_provider), | |
| 89 nullptr, | |
| 90 gpu_memory_buffer_manager, | |
| 91 nullptr), | |
| 92 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)), | |
| 93 client_request_(std::move(client_request)), | |
| 94 frame_sink_id_(frame_sink_id) {} | |
| 95 | |
| 96 void WindowCompositorFrameSink::DidReceiveCompositorFrameAck() { | |
| 97 DCHECK(thread_checker_); | |
| 98 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 99 if (!client_) | |
| 100 return; | |
| 101 client_->DidReceiveCompositorFrameAck(); | |
| 102 } | |
| 103 | |
| 104 void WindowCompositorFrameSink::OnBeginFrame( | |
| 105 const cc::BeginFrameArgs& begin_frame_args) { | |
| 106 begin_frame_source_->OnBeginFrame(begin_frame_args); | |
| 107 } | |
| 108 | |
| 109 void WindowCompositorFrameSink::ReclaimResources( | |
| 110 const cc::ReturnedResourceArray& resources) { | |
| 111 DCHECK(thread_checker_); | |
| 112 DCHECK(thread_checker_->CalledOnValidThread()); | |
| 113 if (!client_) | |
| 114 return; | |
| 115 client_->ReclaimResources(resources); | |
| 116 } | |
| 117 | |
| 118 void WindowCompositorFrameSink::WillDrawSurface() { | |
| 119 // TODO(fsamuel, staraz): Implement this. | |
| 120 } | |
| 121 | |
| 122 void WindowCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) { | |
| 123 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames); | |
| 124 } | |
| 125 | |
| 126 WindowCompositorFrameSinkBinding::~WindowCompositorFrameSinkBinding() {} | |
| 127 | |
| 128 WindowCompositorFrameSinkBinding::WindowCompositorFrameSinkBinding( | |
| 129 cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink_request, | |
| 130 mojo::InterfacePtrInfo<cc::mojom::MojoCompositorFrameSinkClient> | |
| 131 compositor_frame_sink_client) | |
| 132 : compositor_frame_sink_request_(std::move(compositor_frame_sink_request)), | |
| 133 compositor_frame_sink_client_(std::move(compositor_frame_sink_client)) {} | |
| 134 | |
| 135 } // namespace aura | |
| OLD | NEW |