OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
6 | 6 |
7 #include "cc/surfaces/surface.h" | |
8 #include "cc/surfaces/surface_factory.h" | |
9 #include "cc/surfaces/surface_manager.h" | |
10 #include "cc/surfaces/surface_sequence.h" | |
7 #include "content/browser/accessibility/browser_accessibility_manager.h" | 11 #include "content/browser/accessibility/browser_accessibility_manager.h" |
8 #include "content/browser/frame_host/cross_process_frame_connector.h" | 12 #include "content/browser/frame_host/cross_process_frame_connector.h" |
13 #include "content/browser/gpu/compositor_util.h" | |
9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
10 #include "content/common/gpu/gpu_messages.h" | 15 #include "content/common/gpu/gpu_messages.h" |
11 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
12 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
13 | 18 |
14 namespace content { | 19 namespace content { |
15 | 20 |
16 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame( | 21 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame( |
17 RenderWidgetHost* widget_host) | 22 RenderWidgetHost* widget_host) |
18 : host_(RenderWidgetHostImpl::From(widget_host)), | 23 : host_(RenderWidgetHostImpl::From(widget_host)), |
24 use_surfaces_(UseSurfacesEnabled()), | |
25 next_surface_sequence_(1u), | |
26 last_output_surface_id_(0), | |
27 current_surface_scale_factor_(1.f), | |
28 ack_pending_count_(0), | |
19 frame_connector_(NULL) { | 29 frame_connector_(NULL) { |
30 #if !defined(OS_ANDROID) | |
31 if (use_surfaces_) { | |
32 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
33 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); | |
34 } | |
35 #endif // !defined(OS_ANDROID) | |
36 | |
20 host_->SetView(this); | 37 host_->SetView(this); |
21 } | 38 } |
22 | 39 |
23 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { | 40 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { |
41 if (!surface_id_.is_null()) | |
42 surface_factory_->Destroy(surface_id_); | |
24 } | 43 } |
25 | 44 |
26 void RenderWidgetHostViewChildFrame::InitAsChild( | 45 void RenderWidgetHostViewChildFrame::InitAsChild( |
27 gfx::NativeView parent_view) { | 46 gfx::NativeView parent_view) { |
28 NOTREACHED(); | 47 NOTREACHED(); |
29 } | 48 } |
30 | 49 |
31 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const { | 50 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const { |
32 return host_; | 51 return host_; |
33 } | 52 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 } | 198 } |
180 | 199 |
181 #if defined(OS_ANDROID) | 200 #if defined(OS_ANDROID) |
182 void RenderWidgetHostViewChildFrame::LockCompositingSurface() { | 201 void RenderWidgetHostViewChildFrame::LockCompositingSurface() { |
183 } | 202 } |
184 | 203 |
185 void RenderWidgetHostViewChildFrame::UnlockCompositingSurface() { | 204 void RenderWidgetHostViewChildFrame::UnlockCompositingSurface() { |
186 } | 205 } |
187 #endif | 206 #endif |
188 | 207 |
208 void RenderWidgetHostViewChildFrame::SurfaceDrawn(uint32 output_surface_id, | |
209 cc::SurfaceDrawStatus drawn) { | |
210 cc::CompositorFrameAck ack; | |
211 DCHECK(ack_pending_count_ > 0); | |
212 if (!surface_returned_resources_.empty()) | |
213 ack.resources.swap(surface_returned_resources_); | |
214 if (host_) | |
215 host_->Send(new ViewMsg_SwapCompositorFrameAck(host_->GetRoutingID(), | |
216 output_surface_id, ack)); | |
217 ack_pending_count_--; | |
218 } | |
219 | |
189 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( | 220 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( |
190 uint32 output_surface_id, | 221 uint32 output_surface_id, |
191 scoped_ptr<cc::CompositorFrame> frame) { | 222 scoped_ptr<cc::CompositorFrame> frame) { |
192 last_scroll_offset_ = frame->metadata.root_scroll_offset; | 223 last_scroll_offset_ = frame->metadata.root_scroll_offset; |
193 if (frame_connector_) { | 224 |
225 if (!frame_connector_) | |
226 return; | |
227 | |
228 // When not using surfaces, the frame just gets proxied to | |
229 // the embedder's renderer to be composited. | |
230 if (!frame->delegated_frame_data || !use_surfaces_) { | |
194 frame_connector_->ChildFrameCompositorFrameSwapped( | 231 frame_connector_->ChildFrameCompositorFrameSwapped( |
195 output_surface_id, | 232 output_surface_id, |
196 host_->GetProcess()->GetID(), | 233 host_->GetProcess()->GetID(), |
197 host_->GetRoutingID(), | 234 host_->GetRoutingID(), |
198 frame.Pass()); | 235 frame.Pass()); |
236 return; | |
199 } | 237 } |
238 | |
239 #if !defined(OS_ANDROID) | |
240 cc::RenderPass* root_pass = | |
241 frame->delegated_frame_data->render_pass_list.back(); | |
242 | |
243 gfx::Size frame_size = root_pass->output_rect.size(); | |
244 float scale_factor = frame->metadata.device_scale_factor; | |
245 | |
246 // Check whether we need to recreate the cc::Surface, which means the child | |
247 // frame renderer has changed its output surface, or size, or scale factor. | |
248 if (output_surface_id != last_output_surface_id_ && surface_factory_) { | |
249 surface_factory_->Destroy(surface_id_); | |
250 surface_factory_.reset(); | |
251 } | |
252 if (output_surface_id != last_output_surface_id_ || | |
253 frame_size != current_surface_size_ || | |
254 scale_factor != current_surface_scale_factor_) { | |
255 surface_id_ = cc::SurfaceId(); | |
jbauman
2015/05/28 20:08:59
if (surface_factory_ && !surface_id_.is_null())
kenrb
2015/05/28 20:17:52
Done.
| |
256 last_output_surface_id_ = output_surface_id; | |
257 current_surface_size_ = frame_size; | |
258 current_surface_scale_factor_ = scale_factor; | |
259 } | |
260 | |
261 if (!surface_factory_) { | |
262 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
263 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | |
264 surface_factory_ = make_scoped_ptr(new cc::SurfaceFactory(manager, this)); | |
265 } | |
266 | |
267 if (surface_id_.is_null()) { | |
268 surface_id_ = id_allocator_->GenerateId(); | |
269 surface_factory_->Create(surface_id_); | |
270 | |
271 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
272 cc::SurfaceSequence sequence = cc::SurfaceSequence( | |
273 id_allocator_->id_namespace(), next_surface_sequence_++); | |
274 // The renderer will satisfy this dependency when it creates a | |
275 // SurfaceLayer. | |
276 factory->GetSurfaceManager() | |
277 ->GetSurfaceForId(surface_id_) | |
278 ->AddDestructionDependency(sequence); | |
279 frame_connector_->SetChildFrameSurface(surface_id_, frame_size, | |
280 scale_factor, sequence); | |
281 } | |
282 | |
283 cc::SurfaceFactory::DrawCallback ack_callback = | |
284 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), | |
285 output_surface_id); | |
286 ack_pending_count_++; | |
287 surface_factory_->SubmitFrame(surface_id_, frame.Pass(), ack_callback); | |
288 #endif // !defined(OS_ANDROID) | |
200 } | 289 } |
201 | 290 |
202 void RenderWidgetHostViewChildFrame::GetScreenInfo( | 291 void RenderWidgetHostViewChildFrame::GetScreenInfo( |
203 blink::WebScreenInfo* results) { | 292 blink::WebScreenInfo* results) { |
204 } | 293 } |
205 | 294 |
206 gfx::Rect RenderWidgetHostViewChildFrame::GetBoundsInRootWindow() { | 295 gfx::Rect RenderWidgetHostViewChildFrame::GetBoundsInRootWindow() { |
207 // We do not have any root window specific parts in this view. | 296 // We do not have any root window specific parts in this view. |
208 return GetViewBounds(); | 297 return GetViewBounds(); |
209 } | 298 } |
210 | 299 |
211 #if defined(USE_AURA) | 300 #if defined(USE_AURA) |
212 void RenderWidgetHostViewChildFrame::ProcessAckedTouchEvent( | 301 void RenderWidgetHostViewChildFrame::ProcessAckedTouchEvent( |
213 const TouchEventWithLatencyInfo& touch, | 302 const TouchEventWithLatencyInfo& touch, |
214 InputEventAckState ack_result) { | 303 InputEventAckState ack_result) { |
215 } | 304 } |
216 #endif // defined(USE_AURA) | 305 #endif // defined(USE_AURA) |
217 | 306 |
218 bool RenderWidgetHostViewChildFrame::LockMouse() { | 307 bool RenderWidgetHostViewChildFrame::LockMouse() { |
219 return false; | 308 return false; |
220 } | 309 } |
221 | 310 |
222 void RenderWidgetHostViewChildFrame::UnlockMouse() { | 311 void RenderWidgetHostViewChildFrame::UnlockMouse() { |
223 } | 312 } |
224 | 313 |
225 uint32_t RenderWidgetHostViewChildFrame::GetSurfaceIdNamespace() { | 314 uint32_t RenderWidgetHostViewChildFrame::GetSurfaceIdNamespace() { |
226 // TODO(kenrb): Create SurfaceFactory here when RWHVChildFrame | 315 if (!use_surfaces_) |
227 // gets compositor surface support. | 316 return 0; |
228 return 0; | 317 |
318 return id_allocator_->id_namespace(); | |
229 } | 319 } |
230 | 320 |
231 #if defined(OS_MACOSX) | 321 #if defined(OS_MACOSX) |
232 void RenderWidgetHostViewChildFrame::SetActive(bool active) { | 322 void RenderWidgetHostViewChildFrame::SetActive(bool active) { |
233 } | 323 } |
234 | 324 |
235 void RenderWidgetHostViewChildFrame::SetWindowVisibility(bool visible) { | 325 void RenderWidgetHostViewChildFrame::SetWindowVisibility(bool visible) { |
236 } | 326 } |
237 | 327 |
238 void RenderWidgetHostViewChildFrame::WindowFrameChanged() { | 328 void RenderWidgetHostViewChildFrame::WindowFrameChanged() { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 void RenderWidgetHostViewChildFrame::SetParentNativeViewAccessible( | 384 void RenderWidgetHostViewChildFrame::SetParentNativeViewAccessible( |
295 gfx::NativeViewAccessible accessible_parent) { | 385 gfx::NativeViewAccessible accessible_parent) { |
296 } | 386 } |
297 | 387 |
298 gfx::NativeViewId RenderWidgetHostViewChildFrame::GetParentForWindowlessPlugin() | 388 gfx::NativeViewId RenderWidgetHostViewChildFrame::GetParentForWindowlessPlugin() |
299 const { | 389 const { |
300 return NULL; | 390 return NULL; |
301 } | 391 } |
302 #endif // defined(OS_WIN) | 392 #endif // defined(OS_WIN) |
303 | 393 |
394 // cc::SurfaceFactoryClient implementation. | |
395 void RenderWidgetHostViewChildFrame::ReturnResources( | |
396 const cc::ReturnedResourceArray& resources) { | |
397 if (resources.empty()) | |
398 return; | |
399 | |
400 if (!ack_pending_count_ && host_) { | |
401 cc::CompositorFrameAck ack; | |
402 std::copy(resources.begin(), resources.end(), | |
403 std::back_inserter(ack.resources)); | |
404 host_->Send(new ViewMsg_ReclaimCompositorResources( | |
405 host_->GetRoutingID(), last_output_surface_id_, ack)); | |
406 return; | |
407 } | |
408 | |
409 std::copy(resources.begin(), resources.end(), | |
410 std::back_inserter(surface_returned_resources_)); | |
411 } | |
412 | |
304 BrowserAccessibilityManager* | 413 BrowserAccessibilityManager* |
305 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( | 414 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( |
306 BrowserAccessibilityDelegate* delegate) { | 415 BrowserAccessibilityDelegate* delegate) { |
307 return BrowserAccessibilityManager::Create( | 416 return BrowserAccessibilityManager::Create( |
308 BrowserAccessibilityManager::GetEmptyDocument(), delegate); | 417 BrowserAccessibilityManager::GetEmptyDocument(), delegate); |
309 } | 418 } |
310 | 419 |
311 } // namespace content | 420 } // namespace content |
OLD | NEW |