Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/renderer/render_widget_mus_connection.h" | 5 #include "content/renderer/render_widget_mus_connection.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | |
| 10 #include "components/mus/public/cpp/context_provider.h" | 11 #include "components/mus/public/cpp/context_provider.h" |
| 11 #include "components/mus/public/cpp/output_surface.h" | 12 #include "components/mus/public/cpp/output_surface.h" |
| 12 #include "components/mus/public/interfaces/command_buffer.mojom.h" | 13 #include "components/mus/public/interfaces/command_buffer.mojom.h" |
| 13 #include "components/mus/public/interfaces/compositor_frame.mojom.h" | 14 #include "components/mus/public/interfaces/compositor_frame.mojom.h" |
| 14 #include "components/mus/public/interfaces/gpu.mojom.h" | 15 #include "components/mus/public/interfaces/gpu.mojom.h" |
| 15 #include "components/mus/public/interfaces/window_tree.mojom.h" | 16 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 16 #include "content/public/common/mojo_shell_connection.h" | 17 #include "content/public/common/mojo_shell_connection.h" |
| 18 #include "content/renderer/compositor_mus_connection.h" | |
| 19 #include "content/renderer/render_thread_impl.h" | |
| 20 #include "content/renderer/render_view_impl.h" | |
| 17 #include "mojo/application/public/cpp/application_impl.h" | 21 #include "mojo/application/public/cpp/application_impl.h" |
| 18 #include "mojo/converters/geometry/geometry_type_converters.h" | 22 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 19 #include "mojo/converters/surfaces/surfaces_utils.h" | 23 #include "mojo/converters/surfaces/surfaces_utils.h" |
| 20 | 24 |
| 21 namespace content { | 25 namespace content { |
| 22 | 26 |
| 23 namespace { | 27 namespace { |
| 24 | 28 |
| 25 typedef std::map<int, RenderWidgetMusConnection*> ConnectionMap; | 29 typedef std::map<int, RenderWidgetMusConnection*> ConnectionMap; |
| 26 base::LazyInstance<ConnectionMap>::Leaky g_connections = | 30 base::LazyInstance<ConnectionMap>::Leaky g_connections = |
| 27 LAZY_INSTANCE_INITIALIZER; | 31 LAZY_INSTANCE_INITIALIZER; |
| 28 } | 32 } |
| 29 | 33 |
| 30 RenderWidgetMusConnection::RenderWidgetMusConnection(int routing_id) | |
| 31 : routing_id_(routing_id), root_(nullptr) { | |
| 32 DCHECK(routing_id); | |
| 33 } | |
| 34 | |
| 35 RenderWidgetMusConnection::~RenderWidgetMusConnection() {} | |
| 36 | |
| 37 void RenderWidgetMusConnection::Bind( | 34 void RenderWidgetMusConnection::Bind( |
| 38 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) { | 35 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) { |
| 39 DCHECK(!root_); | 36 DCHECK(thread_checker_.CalledOnValidThread()); |
| 40 mus::WindowTreeConnection::Create( | 37 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 41 this, request.Pass(), | 38 compositor_mus_connection_ = new CompositorMusConnection( |
| 42 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | 39 routing_id_, render_thread->GetCompositorMainThreadTaskRunner(), |
| 40 render_thread->compositor_task_runner(), request.Pass(), | |
| 41 render_thread->input_handler_manager()); | |
| 42 if (window_surface_binding_) { | |
| 43 compositor_mus_connection_->AttachSurfaceOnMainThread( | |
| 44 window_surface_binding_.Pass()); | |
| 45 } | |
| 43 } | 46 } |
| 44 | 47 |
| 45 scoped_ptr<cc::OutputSurface> RenderWidgetMusConnection::CreateOutputSurface() { | 48 scoped_ptr<cc::OutputSurface> RenderWidgetMusConnection::CreateOutputSurface() { |
| 49 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 46 DCHECK(!window_surface_binding_); | 50 DCHECK(!window_surface_binding_); |
| 47 mus::mojom::GpuPtr gpu_service; | 51 mus::mojom::GpuPtr gpu_service; |
| 48 MojoShellConnection::Get()->GetApplication()->ConnectToService("mojo:mus", | 52 MojoShellConnection::Get()->GetApplication()->ConnectToService("mojo:mus", |
| 49 &gpu_service); | 53 &gpu_service); |
| 50 mus::mojom::CommandBufferPtr cb; | 54 mus::mojom::CommandBufferPtr cb; |
| 51 gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb)); | 55 gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb)); |
| 52 scoped_refptr<cc::ContextProvider> context_provider( | 56 scoped_refptr<cc::ContextProvider> context_provider( |
| 53 new mus::ContextProvider(cb.PassInterface().PassHandle())); | 57 new mus::ContextProvider(cb.PassInterface().PassHandle())); |
| 54 scoped_ptr<cc::OutputSurface> output_surface(new mus::OutputSurface( | 58 scoped_ptr<cc::OutputSurface> surface(new mus::OutputSurface( |
| 55 context_provider, mus::WindowSurface::Create(&window_surface_binding_))); | 59 context_provider, mus::WindowSurface::Create(&window_surface_binding_))); |
| 56 if (root_) { | 60 if (compositor_mus_connection_) { |
| 57 root_->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, | 61 compositor_mus_connection_->AttachSurfaceOnMainThread( |
| 58 window_surface_binding_.Pass()); | 62 window_surface_binding_.Pass()); |
| 59 } | 63 } |
| 60 return output_surface.Pass(); | 64 return surface; |
| 65 } | |
| 66 | |
| 67 // static | |
| 68 RenderWidgetMusConnection* RenderWidgetMusConnection::Get(int routing_id) { | |
| 69 auto it = g_connections.Get().find(routing_id); | |
| 70 if (it != g_connections.Get().end()) | |
| 71 return it->second; | |
| 72 return nullptr; | |
| 61 } | 73 } |
| 62 | 74 |
| 63 // static | 75 // static |
| 64 RenderWidgetMusConnection* RenderWidgetMusConnection::GetOrCreate( | 76 RenderWidgetMusConnection* RenderWidgetMusConnection::GetOrCreate( |
| 65 int routing_id) { | 77 int routing_id) { |
| 66 auto it = g_connections.Get().find(routing_id); | 78 RenderWidgetMusConnection* connection = Get(routing_id); |
| 67 if (it != g_connections.Get().end()) | 79 if (!connection) { |
| 68 return it->second; | 80 connection = new RenderWidgetMusConnection(routing_id); |
| 69 | 81 g_connections.Get().insert(std::make_pair(routing_id, connection)); |
| 70 RenderWidgetMusConnection* connection = | 82 } |
| 71 new RenderWidgetMusConnection(routing_id); | |
| 72 g_connections.Get().insert(std::make_pair(routing_id, connection)); | |
| 73 return connection; | 83 return connection; |
| 74 } | 84 } |
| 75 | 85 |
| 76 void RenderWidgetMusConnection::OnConnectionLost( | 86 RenderWidgetMusConnection::RenderWidgetMusConnection(int routing_id) |
| 77 mus::WindowTreeConnection* connection) { | 87 : routing_id_(routing_id) { |
| 88 DCHECK(routing_id); | |
| 89 } | |
| 90 | |
| 91 RenderWidgetMusConnection::~RenderWidgetMusConnection() {} | |
| 92 | |
| 93 void RenderWidgetMusConnection::OnConnectionLost() { | |
| 94 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 78 g_connections.Get().erase(routing_id_); | 95 g_connections.Get().erase(routing_id_); |
| 79 delete this; | 96 delete this; |
| 80 } | 97 } |
| 81 | 98 |
| 82 void RenderWidgetMusConnection::OnEmbed(mus::Window* root) { | 99 void RenderWidgetMusConnection::OnWindowInputEvent( |
| 83 root_ = root; | 100 scoped_ptr<blink::WebInputEvent> input_event, |
| 84 root_->AddObserver(this); | 101 const base::Closure& ack) { |
| 85 if (window_surface_binding_) { | 102 DCHECK(thread_checker_.CalledOnValidThread()); |
| 86 root->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, | 103 // TODO(fsamuel): Implement this once the following is complete: |
| 87 window_surface_binding_.Pass()); | 104 // 1. The Mus client lib support manual event ACKing. |
|
Ben Goodger (Google)
2015/12/03 06:35:53
supports
Fady Samuel
2015/12/03 16:42:12
Done.
| |
| 88 } | 105 // 2. Mus supports event coalescing. |
| 89 } | 106 // 3. RenderWidget is refactored so that we don't send ACKs to the browser |
| 90 | 107 // process. |
| 91 void RenderWidgetMusConnection::OnUnembed() {} | 108 ack.Run(); |
| 92 | |
| 93 void RenderWidgetMusConnection::OnWindowBoundsChanged( | |
| 94 mus::Window* window, | |
| 95 const gfx::Rect& old_bounds, | |
| 96 const gfx::Rect& new_bounds) { | |
| 97 } | 109 } |
| 98 | 110 |
| 99 } // namespace content | 111 } // namespace content |
| OLD | NEW |