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

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

Powered by Google App Engine
This is Rietveld 408576698