OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "components/mus/surfaces/compositor_frame_sink_impl.h" |
| 6 |
| 7 #include "cc/surfaces/surface_factory.h" |
| 8 #include "components/mus/public/interfaces/compositor_frame.mojom.h" |
| 9 #include "components/mus/surfaces/compositor_frame_sink_delegate.h" |
| 10 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 11 |
| 12 namespace mus { |
| 13 |
| 14 namespace { |
| 15 |
| 16 void CallCallback( |
| 17 const mojo::Callback<void(mojom::CompositorFrameDrawStatus)>& callback, |
| 18 cc::SurfaceDrawStatus draw_status) { |
| 19 callback.Run(static_cast<mojom::CompositorFrameDrawStatus>(draw_status)); |
| 20 } |
| 21 } |
| 22 |
| 23 CompositorFrameSinkImpl::CompositorFrameSinkImpl( |
| 24 CompositorFrameSinkDelegate* delegate, |
| 25 int sink_id, |
| 26 const scoped_refptr<SurfacesState>& surfaces_state, |
| 27 mojo::InterfaceRequest<mojom::CompositorFrameSink> request, |
| 28 mojom::CompositorFrameSinkClientPtr client) |
| 29 : delegate_(delegate), |
| 30 surfaces_state_(surfaces_state), |
| 31 sink_id_(sink_id), |
| 32 begin_frame_source_(nullptr), |
| 33 needs_begin_frame_(false), |
| 34 factory_(surfaces_state->manager(), this), |
| 35 client_(std::move(client)), |
| 36 binding_(this, std::move(request)) { |
| 37 DCHECK(delegate_); |
| 38 binding_.set_connection_error_handler(base::Bind( |
| 39 &CompositorFrameSinkImpl::OnConnectionLost, base::Unretained(this))); |
| 40 } |
| 41 |
| 42 CompositorFrameSinkImpl::~CompositorFrameSinkImpl() {} |
| 43 |
| 44 void CompositorFrameSinkImpl::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 45 if (needs_begin_frame_ == needs_begin_frame) |
| 46 return; |
| 47 |
| 48 needs_begin_frame_ = needs_begin_frame; |
| 49 if (begin_frame_source_) { |
| 50 if (needs_begin_frame_) |
| 51 begin_frame_source_->AddObserver(this); |
| 52 else |
| 53 begin_frame_source_->RemoveObserver(this); |
| 54 } |
| 55 } |
| 56 |
| 57 void CompositorFrameSinkImpl::SubmitCompositorFrame( |
| 58 mojom::CompositorFramePtr frame, |
| 59 const SubmitCompositorFrameCallback& callback) { |
| 60 // TODO(fsamuel): Validate that SurfaceDrawQuad refer to allowable surface |
| 61 // IDs. |
| 62 std::unique_ptr<cc::CompositorFrame> compositor_frame = |
| 63 ConvertToCompositorFrame(frame, nullptr); |
| 64 gfx::Size frame_size = |
| 65 compositor_frame->delegated_frame_data->render_pass_list.back() |
| 66 ->output_rect.size(); |
| 67 if (frame_size.IsEmpty() || frame_size != last_submitted_frame_size_) { |
| 68 if (!surface_id_.is_null()) |
| 69 factory_.Destroy(surface_id_); |
| 70 // TODO(fsamuel): The allocator should live on CompositorFrameSinkFactory. |
| 71 surface_id_ = delegate_->GenerateSurfaceId(); |
| 72 factory_.Create(surface_id_); |
| 73 last_submitted_frame_size_ = frame_size; |
| 74 } |
| 75 factory_.SubmitCompositorFrame(surface_id_, std::move(compositor_frame), |
| 76 base::Bind(&CallCallback, callback)); |
| 77 } |
| 78 |
| 79 void CompositorFrameSinkImpl::ReturnResources( |
| 80 const cc::ReturnedResourceArray& resources) { |
| 81 if (!client_) |
| 82 return; |
| 83 |
| 84 client_->ReturnResources( |
| 85 mojo::Array<mojom::ReturnedResourcePtr>::From(resources)); |
| 86 } |
| 87 |
| 88 void CompositorFrameSinkImpl::SetBeginFrameSource( |
| 89 cc::BeginFrameSource* begin_frame_source) { |
| 90 begin_frame_source_ = begin_frame_source; |
| 91 } |
| 92 |
| 93 void CompositorFrameSinkImpl::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 94 // TODO(fsamuel): Implement this. |
| 95 } |
| 96 |
| 97 const cc::BeginFrameArgs& CompositorFrameSinkImpl::LastUsedBeginFrameArgs() |
| 98 const { |
| 99 // TODO(fsamuel): Implement this. |
| 100 return last_used_begin_frame_args_; |
| 101 } |
| 102 |
| 103 void CompositorFrameSinkImpl::OnBeginFrameSourcePausedChanged(bool paused) { |
| 104 // TODO(fsamuel): Implement this. |
| 105 } |
| 106 |
| 107 void CompositorFrameSinkImpl::OnConnectionLost() { |
| 108 delegate_->CompositorFrameSinkConnectionLost(sink_id_); |
| 109 } |
| 110 |
| 111 } // namespace mus |
OLD | NEW |