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

Side by Side Diff: blimp/client/core/compositor/blimp_compositor.cc

Issue 2241623002: blimp: Move compositing, input and render widget feature to client/core. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments from #7 Created 4 years, 4 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 2015 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 "blimp/client/core/compositor/blimp_compositor.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/command_line.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/numerics/safe_conversions.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread.h"
13 #include "base/threading/thread_local.h"
14 #include "base/threading/thread_restrictions.h"
15 #include "base/threading/thread_task_runner_handle.h"
16 #include "cc/animation/animation_host.h"
17 #include "cc/layers/layer.h"
18 #include "cc/output/output_surface.h"
19 #include "cc/proto/compositor_message.pb.h"
20 #include "cc/trees/layer_tree_host.h"
21 #include "cc/trees/layer_tree_settings.h"
22
23 namespace blimp {
24 namespace client {
25
26 BlimpCompositor::BlimpCompositor(
27 cc::TaskGraphRunner* task_graph_runner,
28 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
29 cc::ImageSerializationProcessor* image_serialization_processor,
30 cc::LayerTreeSettings* settings,
31 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
32 BlimpCompositorClient* client)
33 : task_graph_runner_(task_graph_runner),
34 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
35 image_serialization_processor_(image_serialization_processor),
36 settings_(settings),
37 compositor_task_runner_(compositor_task_runner),
38 client_(client),
39 host_should_be_visible_(false),
40 remote_proto_channel_receiver_(nullptr) {
41 DCHECK(client_);
42 // TODO(khushalsagar): The BlimpCompositor is the remote counterpart to the
43 // RenderWidgetCompositor, and should have a 1:1 mapping with the
44 // LayerTreeHost, and we should be creating it when we create the host.
45 // Clean up this mess... D:
46 }
47
48 BlimpCompositor::~BlimpCompositor() {
49 if (host_) {
50 DestroyLayerTreeHost();
51 }
52 }
53
54 void BlimpCompositor::SetVisible(bool visible) {
55 host_should_be_visible_ = visible;
56 if (host_) {
57 host_->SetVisible(visible);
58 }
59 }
60
61 bool BlimpCompositor::IsVisible() const {
62 return host_should_be_visible_;
63 }
64
65 void BlimpCompositor::SetOutputSurface(
66 std::unique_ptr<cc::OutputSurface> output_surface) {
67 if (host_) {
68 host_->SetOutputSurface(std::move(output_surface));
69 }
70 }
71
72 void BlimpCompositor::ReleaseOutputSurface() {
73 if (!host_ || host_->output_surface_lost()) {
74 return;
75 }
76
77 host_->ReleaseOutputSurface();
78 }
79
80 void BlimpCompositor::WillBeginMainFrame() {}
81
82 void BlimpCompositor::DidBeginMainFrame() {}
83
84 void BlimpCompositor::BeginMainFrame(const cc::BeginFrameArgs& args) {}
85
86 void BlimpCompositor::BeginMainFrameNotExpectedSoon() {}
87
88 void BlimpCompositor::UpdateLayerTreeHost() {}
89
90 void BlimpCompositor::ApplyViewportDeltas(
91 const gfx::Vector2dF& inner_delta,
92 const gfx::Vector2dF& outer_delta,
93 const gfx::Vector2dF& elastic_overscroll_delta,
94 float page_scale,
95 float top_controls_delta) {}
96
97 void BlimpCompositor::RequestNewOutputSurface() {
98 client_->RequestOutputSurface();
99 }
100
101 void BlimpCompositor::DidInitializeOutputSurface() {}
102
103 void BlimpCompositor::DidFailToInitializeOutputSurface() {}
104
105 void BlimpCompositor::WillCommit() {}
106
107 void BlimpCompositor::DidCommit() {}
108
109 void BlimpCompositor::DidCommitAndDrawFrame() {
110 client_->DidCommitAndDrawFrame();
111 }
112
113 void BlimpCompositor::DidCompleteSwapBuffers() {
114 client_->DidCompleteSwapBuffers();
115 }
116
117 void BlimpCompositor::DidCompletePageScaleAnimation() {}
118
119 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) {
120 remote_proto_channel_receiver_ = receiver;
121 }
122
123 void BlimpCompositor::SendCompositorProto(
124 const cc::proto::CompositorMessage& proto) {
125 client_->SendCompositorMessage(proto);
126 }
127
128 void BlimpCompositor::OnCompositorMessageReceived(
129 std::unique_ptr<cc::proto::CompositorMessage> message) {
130 DCHECK(message->has_to_impl());
131 const cc::proto::CompositorMessageToImpl& to_impl_proto = message->to_impl();
132
133 DCHECK(to_impl_proto.has_message_type());
134 switch (to_impl_proto.message_type()) {
135 case cc::proto::CompositorMessageToImpl::UNKNOWN:
136 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type";
137 break;
138 case cc::proto::CompositorMessageToImpl::INITIALIZE_IMPL:
139 DCHECK(!host_);
140 DCHECK(to_impl_proto.has_initialize_impl_message());
141
142 // Create the remote client LayerTreeHost for the compositor.
143 CreateLayerTreeHost();
144 break;
145 case cc::proto::CompositorMessageToImpl::CLOSE_IMPL:
146 DCHECK(host_);
147
148 // Destroy the remote client LayerTreeHost for the compositor.
149 DestroyLayerTreeHost();
150 break;
151 default:
152 // We should have a receiver if we're getting compositor messages that
153 // are not INITIALIZE_IMPL or CLOSE_IMPL.
154 DCHECK(remote_proto_channel_receiver_);
155 remote_proto_channel_receiver_->OnProtoReceived(std::move(message));
156 }
157 }
158
159 void BlimpCompositor::SendWebGestureEvent(
160 const blink::WebGestureEvent& gesture_event) {
161 client_->SendWebGestureEvent(gesture_event);
162 }
163
164 void BlimpCompositor::CreateLayerTreeHost() {
165 DCHECK(!host_);
166 VLOG(1) << "Creating LayerTreeHost";
167
168 cc::LayerTreeHost::InitParams host_params;
169 host_params.client = this;
170 host_params.task_graph_runner = task_graph_runner_;
171 host_params.gpu_memory_buffer_manager = gpu_memory_buffer_manager_;
172 host_params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
173 host_params.image_serialization_processor = image_serialization_processor_;
174 host_params.settings = settings_;
175 host_params.animation_host = cc::AnimationHost::CreateMainInstance();
176
177 // Create the LayerTreeHost
178 host_ = cc::LayerTreeHost::CreateRemoteClient(
179 this /* remote_proto_channel */, compositor_task_runner_, &host_params);
180
181 host_->SetVisible(host_should_be_visible_);
182
183 DCHECK(!input_manager_);
184 input_manager_ = BlimpInputManager::Create(
185 this, base::ThreadTaskRunnerHandle::Get(), compositor_task_runner_,
186 host_->GetInputHandler());
187 }
188
189 void BlimpCompositor::DestroyLayerTreeHost() {
190 DCHECK(host_);
191 VLOG(1) << "Destroying LayerTreeHost";
192
193 // Destroy the old LayerTreeHost state.
194 host_.reset();
195
196 // Destroy the old input manager state.
197 // It is important to destroy the LayerTreeHost before destroying the input
198 // manager as it has a reference to the cc::InputHandlerClient owned by the
199 // BlimpInputManager.
200 input_manager_.reset();
201
202 // Make sure we don't have a receiver at this point.
203 DCHECK(!remote_proto_channel_receiver_);
204 }
205
206 } // namespace client
207 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698