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