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