| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer_host/render_view_host_factory.h" | 5 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/browser/gpu/gpu_surface_tracker.h" | |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 | 9 |
| 11 namespace content { | 10 namespace content { |
| 12 | 11 |
| 13 // static | 12 // static |
| 14 RenderViewHostFactory* RenderViewHostFactory::factory_ = NULL; | 13 RenderViewHostFactory* RenderViewHostFactory::factory_ = NULL; |
| 15 | 14 |
| 16 // static | 15 // static |
| 17 RenderViewHost* RenderViewHostFactory::Create( | 16 RenderViewHost* RenderViewHostFactory::Create( |
| 18 SiteInstance* instance, | 17 SiteInstance* instance, |
| 19 RenderViewHostDelegate* delegate, | 18 RenderViewHostDelegate* delegate, |
| 20 RenderWidgetHostDelegate* widget_delegate, | 19 RenderWidgetHostDelegate* widget_delegate, |
| 21 int32 routing_id, | 20 int32 routing_id, |
| 22 int32 main_frame_routing_id, | 21 int32 main_frame_routing_id, |
| 23 bool swapped_out, | 22 bool swapped_out, |
| 24 bool hidden) { | 23 bool hidden) { |
| 25 int32 surface_id; | |
| 26 // RenderViewHost creation can be either browser-driven (by the user opening a | 24 // RenderViewHost creation can be either browser-driven (by the user opening a |
| 27 // new tab) or renderer-driven (by script calling window.open, etc). | 25 // new tab) or renderer-driven (by script calling window.open, etc). |
| 28 // | 26 // |
| 29 // In the browser-driven case, the routing ID of the view is lazily assigned: | 27 // In the browser-driven case, the routing ID of the view is lazily assigned: |
| 30 // this is signified by passing MSG_ROUTING_NONE for |routing_id|. | 28 // this is signified by passing MSG_ROUTING_NONE for |routing_id|. |
| 31 if (routing_id == MSG_ROUTING_NONE) { | 29 if (routing_id == MSG_ROUTING_NONE) { |
| 32 routing_id = instance->GetProcess()->GetNextRoutingID(); | 30 routing_id = instance->GetProcess()->GetNextRoutingID(); |
| 33 // No surface has yet been created for the RVH. | |
| 34 surface_id = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | |
| 35 instance->GetProcess()->GetID(), routing_id); | |
| 36 } else { | 31 } else { |
| 37 // Otherwise, in the renderer-driven case, the routing ID of the view is | 32 // Otherwise, in the renderer-driven case, the routing ID of the view is |
| 38 // already set. This is due to the fact that a sync render->browser IPC is | 33 // already set. This is due to the fact that a sync render->browser IPC is |
| 39 // involved. In order to quickly reply to the sync IPC, the routing IDs are | 34 // involved. In order to quickly reply to the sync IPC, the routing IDs are |
| 40 // assigned as early as possible. The IO thread immediately sends a reply to | 35 // assigned as early as possible. The IO thread immediately sends a reply to |
| 41 // the sync IPC, while deferring the creation of the actual Host objects to | 36 // the sync IPC, while deferring the creation of the actual Host objects to |
| 42 // the UI thread. In this case, a surface already exists for the RVH. | 37 // the UI thread. |
| 43 surface_id = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( | |
| 44 instance->GetProcess()->GetID(), routing_id); | |
| 45 } | 38 } |
| 46 if (factory_) { | 39 if (factory_) { |
| 47 return factory_->CreateRenderViewHost(instance, delegate, widget_delegate, | 40 return factory_->CreateRenderViewHost(instance, delegate, widget_delegate, |
| 48 routing_id, surface_id, | 41 routing_id, main_frame_routing_id, |
| 49 main_frame_routing_id, swapped_out); | 42 swapped_out); |
| 50 } | 43 } |
| 51 return new RenderViewHostImpl(instance, delegate, widget_delegate, routing_id, | 44 return new RenderViewHostImpl(instance, delegate, widget_delegate, routing_id, |
| 52 surface_id, main_frame_routing_id, swapped_out, | 45 main_frame_routing_id, swapped_out, hidden, |
| 53 hidden, true /* has_initialized_audio_host */); | 46 true /* has_initialized_audio_host */); |
| 54 } | 47 } |
| 55 | 48 |
| 56 // static | 49 // static |
| 57 void RenderViewHostFactory::RegisterFactory(RenderViewHostFactory* factory) { | 50 void RenderViewHostFactory::RegisterFactory(RenderViewHostFactory* factory) { |
| 58 DCHECK(!factory_) << "Can't register two factories at once."; | 51 DCHECK(!factory_) << "Can't register two factories at once."; |
| 59 factory_ = factory; | 52 factory_ = factory; |
| 60 } | 53 } |
| 61 | 54 |
| 62 // static | 55 // static |
| 63 void RenderViewHostFactory::UnregisterFactory() { | 56 void RenderViewHostFactory::UnregisterFactory() { |
| 64 DCHECK(factory_) << "No factory to unregister."; | 57 DCHECK(factory_) << "No factory to unregister."; |
| 65 factory_ = NULL; | 58 factory_ = NULL; |
| 66 } | 59 } |
| 67 | 60 |
| 68 } // namespace content | 61 } // namespace content |
| OLD | NEW |