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

Side by Side Diff: services/ui/public/cpp/client_compositor_frame_sink.cc

Issue 2907683004: Move ClientCompositorFrameSink to components/viz (Closed)
Patch Set: c Created 3 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
« no previous file with comments | « services/ui/public/cpp/client_compositor_frame_sink.h ('k') | ui/aura/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "services/ui/public/cpp/client_compositor_frame_sink.h"
6
7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h"
9 #include "cc/output/begin_frame_args.h"
10 #include "cc/output/compositor_frame.h"
11 #include "cc/output/compositor_frame_sink_client.h"
12
13 namespace ui {
14
15 ClientCompositorFrameSink::ClientCompositorFrameSink(
16 scoped_refptr<cc::ContextProvider> context_provider,
17 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
18 cc::mojom::MojoCompositorFrameSinkPtrInfo compositor_frame_sink_info,
19 cc::mojom::MojoCompositorFrameSinkClientRequest client_request,
20 bool enable_surface_synchronization)
21 : cc::CompositorFrameSink(std::move(context_provider),
22 nullptr,
23 gpu_memory_buffer_manager,
24 nullptr),
25 compositor_frame_sink_info_(std::move(compositor_frame_sink_info)),
26 client_request_(std::move(client_request)),
27 enable_surface_synchronization_(enable_surface_synchronization) {}
28
29 ClientCompositorFrameSink::~ClientCompositorFrameSink() {}
30
31 bool ClientCompositorFrameSink::BindToClient(
32 cc::CompositorFrameSinkClient* client) {
33 if (!cc::CompositorFrameSink::BindToClient(client))
34 return false;
35
36 DCHECK(!thread_checker_);
37 thread_checker_.reset(new base::ThreadChecker());
38 compositor_frame_sink_.Bind(std::move(compositor_frame_sink_info_));
39 client_binding_.reset(
40 new mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient>(
41 this, std::move(client_request_)));
42
43 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this);
44
45 client->SetBeginFrameSource(begin_frame_source_.get());
46 return true;
47 }
48
49 void ClientCompositorFrameSink::DetachFromClient() {
50 client_->SetBeginFrameSource(nullptr);
51 begin_frame_source_.reset();
52 client_binding_.reset();
53 compositor_frame_sink_.reset();
54 cc::CompositorFrameSink::DetachFromClient();
55 }
56
57 void ClientCompositorFrameSink::SetLocalSurfaceId(
58 const cc::LocalSurfaceId& local_surface_id) {
59 DCHECK(local_surface_id.is_valid());
60 DCHECK(enable_surface_synchronization_);
61 local_surface_id_ = local_surface_id;
62 }
63
64 void ClientCompositorFrameSink::SubmitCompositorFrame(
65 cc::CompositorFrame frame) {
66 DCHECK(thread_checker_);
67 DCHECK(thread_checker_->CalledOnValidThread());
68 if (!compositor_frame_sink_)
69 return;
70
71 DCHECK(frame.metadata.begin_frame_ack.has_damage);
72 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber,
73 frame.metadata.begin_frame_ack.sequence_number);
74
75 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size();
76 if (!local_surface_id_.is_valid() ||
77 frame_size != last_submitted_frame_size_) {
78 last_submitted_frame_size_ = frame_size;
79 if (!enable_surface_synchronization_)
80 local_surface_id_ = id_allocator_.GenerateId();
81 }
82 compositor_frame_sink_->SubmitCompositorFrame(local_surface_id_,
83 std::move(frame));
84 }
85
86 void ClientCompositorFrameSink::DidNotProduceFrame(
87 const cc::BeginFrameAck& ack) {
88 DCHECK(!ack.has_damage);
89 DCHECK_LE(cc::BeginFrameArgs::kStartingFrameNumber, ack.sequence_number);
90 compositor_frame_sink_->DidNotProduceFrame(ack);
91 }
92
93 void ClientCompositorFrameSink::DidReceiveCompositorFrameAck(
94 const cc::ReturnedResourceArray& resources) {
95 DCHECK(thread_checker_);
96 DCHECK(thread_checker_->CalledOnValidThread());
97 if (!client_)
98 return;
99 client_->ReclaimResources(resources);
100 client_->DidReceiveCompositorFrameAck();
101 }
102
103 void ClientCompositorFrameSink::OnBeginFrame(
104 const cc::BeginFrameArgs& begin_frame_args) {
105 begin_frame_source_->OnBeginFrame(begin_frame_args);
106 }
107
108 void ClientCompositorFrameSink::ReclaimResources(
109 const cc::ReturnedResourceArray& resources) {
110 DCHECK(thread_checker_);
111 DCHECK(thread_checker_->CalledOnValidThread());
112 if (!client_)
113 return;
114 client_->ReclaimResources(resources);
115 }
116
117 void ClientCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) {
118 compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frames);
119 }
120
121 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/client_compositor_frame_sink.h ('k') | ui/aura/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698