Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: components/mus/surfaces/compositor_frame_sink_impl.cc

Issue 1989693002: Introduce DisplayCompositor Mojo API for Mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix client_id Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/cpp/surfaces/surfaces_type_converters.h"
9 #include "components/mus/public/interfaces/compositor_frame.mojom.h"
10 #include "components/mus/surfaces/compositor_frame_sink_delegate.h"
11
12 namespace mus {
13 namespace gpu {
14
15 namespace {
16
17 void CallCallback(
18 const mojo::Callback<void(mojom::CompositorFrameDrawStatus)>& callback,
19 cc::SurfaceDrawStatus draw_status) {
20 callback.Run(static_cast<mojom::CompositorFrameDrawStatus>(draw_status));
21 }
22 }
23
24 CompositorFrameSinkImpl::CompositorFrameSinkImpl(
25 CompositorFrameSinkDelegate* delegate,
26 int sink_id,
27 const scoped_refptr<SurfacesState>& surfaces_state,
28 mojo::InterfaceRequest<mojom::CompositorFrameSink> request,
29 mojom::CompositorFrameSinkClientPtr client)
30 : delegate_(delegate),
31 surfaces_state_(surfaces_state),
32 sink_id_(sink_id),
33 begin_frame_source_(nullptr),
34 needs_begin_frame_(false),
35 factory_(surfaces_state->manager(), this),
36 client_(std::move(client)),
37 binding_(this, std::move(request)) {
38 DCHECK(delegate_);
39 binding_.set_connection_error_handler(base::Bind(
40 &CompositorFrameSinkImpl::OnConnectionLost, base::Unretained(this)));
41 }
42
43 CompositorFrameSinkImpl::~CompositorFrameSinkImpl() {}
44
45 void CompositorFrameSinkImpl::SetNeedsBeginFrame(bool needs_begin_frame) {
46 if (needs_begin_frame_ == needs_begin_frame)
47 return;
48
49 needs_begin_frame_ = needs_begin_frame;
50 if (begin_frame_source_) {
51 if (needs_begin_frame_)
52 begin_frame_source_->AddObserver(this);
53 else
54 begin_frame_source_->RemoveObserver(this);
55 }
56 }
57
58 void CompositorFrameSinkImpl::SubmitCompositorFrame(
59 mus::mojom::CompositorFramePtr frame,
60 const SubmitCompositorFrameCallback& callback) {
61 // TODO(fsamuel): Validate that SurfaceDrawQuad refer to allowable surface
62 // IDs.
63 std::unique_ptr<cc::CompositorFrame> compositor_frame =
64 ConvertToCompositorFrame(frame, nullptr);
65 gfx::Size frame_size =
66 compositor_frame->delegated_frame_data->render_pass_list.back()
67 ->output_rect.size();
68 if (frame_size.IsEmpty() || frame_size != last_submitted_frame_size_) {
69 if (!surface_id_.is_null())
70 factory_.Destroy(surface_id_);
71 // TODO(fsamuel): The allocator should live on CompositorFrameSinkFactory.
72 surface_id_ = delegate_->GenerateSurfaceId();
73 factory_.Create(surface_id_);
74 last_submitted_frame_size_ = frame_size;
75 }
76 factory_.SubmitCompositorFrame(surface_id_, std::move(compositor_frame),
77 base::Bind(&CallCallback, callback));
78 }
79
80 void CompositorFrameSinkImpl::ReturnResources(
81 const cc::ReturnedResourceArray& resources) {
82 if (!client_)
83 return;
84
85 client_->ReturnResources(
86 mojo::Array<mus::mojom::ReturnedResourcePtr>::From(resources));
87 }
88
89 void CompositorFrameSinkImpl::WillDrawSurface(cc::SurfaceId surface_id,
90 const gfx::Rect& damage_rect) {
91 NOTIMPLEMENTED();
92 }
93
94 void CompositorFrameSinkImpl::SetBeginFrameSource(
95 cc::BeginFrameSource* begin_frame_source) {
96 begin_frame_source_ = begin_frame_source;
97 }
98
99 void CompositorFrameSinkImpl::OnBeginFrame(const cc::BeginFrameArgs& args) {
100 // TODO(fsamuel): Implement this.
101 }
102
103 const cc::BeginFrameArgs& CompositorFrameSinkImpl::LastUsedBeginFrameArgs()
104 const {
105 // TODO(fsamuel): Implement this.
106 return last_used_begin_frame_args_;
107 }
108
109 void CompositorFrameSinkImpl::OnBeginFrameSourcePausedChanged(bool paused) {
110 // TODO(fsamuel): Implement this.
111 }
112
113 void CompositorFrameSinkImpl::OnConnectionLost() {
114 delegate_->CompositorFrameSinkConnectionLost(sink_id_);
115 }
116
117 } // namespace gpu
118 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/surfaces/compositor_frame_sink_impl.h ('k') | components/mus/surfaces/display_compositor_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698