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" | |
17 #include "content/renderer/render_view_impl.h" | 20 #include "content/renderer/render_view_impl.h" |
18 #include "mojo/application/public/cpp/application_impl.h" | 21 #include "mojo/application/public/cpp/application_impl.h" |
19 #include "mojo/converters/geometry/geometry_type_converters.h" | 22 #include "mojo/converters/geometry/geometry_type_converters.h" |
20 #include "mojo/converters/surfaces/surfaces_utils.h" | 23 #include "mojo/converters/surfaces/surfaces_utils.h" |
21 | 24 |
22 namespace content { | 25 namespace content { |
23 | 26 |
24 namespace { | 27 namespace { |
25 | 28 |
26 typedef std::map<int, RenderWidgetMusConnection*> ConnectionMap; | 29 typedef std::map<int, RenderWidgetMusConnection*> ConnectionMap; |
27 base::LazyInstance<ConnectionMap>::Leaky g_connections = | 30 base::LazyInstance<ConnectionMap>::Leaky g_connections = |
28 LAZY_INSTANCE_INITIALIZER; | 31 LAZY_INSTANCE_INITIALIZER; |
29 | |
30 } | 32 } |
31 | 33 |
32 RenderWidgetMusConnection::RenderWidgetMusConnection( | 34 void RenderWidgetMusConnection::Bind( |
33 int routing_id) | |
34 : routing_id_(routing_id), connected_(false), root_(nullptr) { | |
35 DCHECK(routing_id); | |
36 } | |
37 | |
38 RenderWidgetMusConnection::~RenderWidgetMusConnection() { | |
39 } | |
40 | |
41 void RenderWidgetMusConnection::Connect( | |
42 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) { | 35 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) { |
43 // TODO(fsamuel): We probably want to pause processing of incoming | 36 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
44 // messages until we have an associated RenderWidget. | 37 compositor_mus_connection_ = new CompositorMusConnection( |
45 DCHECK(!connected_); | 38 routing_id_, render_thread->GetCompositorMainThreadTaskRunner(), |
46 mus::WindowTreeConnection::Create( | 39 render_thread->compositor_task_runner(), request.Pass(), |
47 this, request.Pass(), | 40 render_thread->input_handler_manager()); |
48 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | 41 if (window_surface_binding_) { |
49 connected_ = true; | 42 compositor_mus_connection_->AttachSurfaceOnMainThread( |
43 window_surface_binding_.Pass()); | |
44 } | |
50 } | 45 } |
51 | 46 |
52 scoped_ptr<cc::OutputSurface> RenderWidgetMusConnection::CreateOutputSurface() { | 47 scoped_ptr<cc::OutputSurface> RenderWidgetMusConnection::CreateOutputSurface() { |
53 DCHECK(!window_surface_binding_); | |
54 mus::mojom::GpuPtr gpu_service; | 48 mus::mojom::GpuPtr gpu_service; |
sadrul
2015/12/02 18:20:57
Is there a reason to remove the DCHECK()?
Fady Samuel
2015/12/02 21:30:28
No, restored.
| |
55 MojoShellConnection::Get()->GetApplication()->ConnectToService( | 49 MojoShellConnection::Get()->GetApplication()->ConnectToService("mojo:mus", |
56 "mojo:mus", &gpu_service); | 50 &gpu_service); |
57 mus::mojom::CommandBufferPtr cb; | 51 mus::mojom::CommandBufferPtr cb; |
58 gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb)); | 52 gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb)); |
59 scoped_refptr<cc::ContextProvider> context_provider( | 53 scoped_refptr<cc::ContextProvider> context_provider( |
60 new mus::ContextProvider(cb.PassInterface().PassHandle())); | 54 new mus::ContextProvider(cb.PassInterface().PassHandle())); |
61 scoped_ptr<cc::OutputSurface> output_surface(new mus::OutputSurface( | 55 scoped_ptr<cc::OutputSurface> surface(new mus::OutputSurface( |
62 context_provider, | 56 context_provider, mus::WindowSurface::Create(&window_surface_binding_))); |
63 mus::WindowSurface::Create(&window_surface_binding_))); | 57 if (compositor_mus_connection_) { |
64 if (root_) { | 58 compositor_mus_connection_->AttachSurfaceOnMainThread( |
65 root_->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, | 59 window_surface_binding_.Pass()); |
66 window_surface_binding_.Pass()); | |
67 } | 60 } |
68 return output_surface.Pass(); | 61 return surface; |
sadrul
2015/12/02 18:20:57
Should RenderWidgetMusConnection also check that i
Fady Samuel
2015/12/02 21:30:28
Sure. That's a good idea. I added a ThreadChecker
| |
69 } | 62 } |
70 | 63 |
64 // static | |
71 RenderWidgetMusConnection* RenderWidgetMusConnection::Get(int routing_id) { | 65 RenderWidgetMusConnection* RenderWidgetMusConnection::Get(int routing_id) { |
72 auto it = g_connections.Get().find(routing_id); | 66 auto it = g_connections.Get().find(routing_id); |
73 if (it != g_connections.Get().end()) | 67 if (it != g_connections.Get().end()) |
74 return it->second; | 68 return it->second; |
69 return nullptr; | |
70 } | |
75 | 71 |
76 RenderWidgetMusConnection* connection = new RenderWidgetMusConnection( | 72 // static |
77 routing_id); | 73 RenderWidgetMusConnection* RenderWidgetMusConnection::GetOrCreate( |
78 g_connections.Get().insert(std::make_pair(routing_id, connection)); | 74 int routing_id) { |
75 RenderWidgetMusConnection* connection = Get(routing_id); | |
76 if (!connection) { | |
77 connection = new RenderWidgetMusConnection(routing_id); | |
78 g_connections.Get().insert(std::make_pair(routing_id, connection)); | |
79 } | |
79 return connection; | 80 return connection; |
80 } | 81 } |
81 | 82 |
82 void RenderWidgetMusConnection::OnConnectionLost( | 83 RenderWidgetMusConnection::RenderWidgetMusConnection(int routing_id) |
83 mus::WindowTreeConnection* connection) { | 84 : routing_id_(routing_id) { |
85 DCHECK(routing_id); | |
86 } | |
87 | |
88 RenderWidgetMusConnection::~RenderWidgetMusConnection() {} | |
89 | |
90 void RenderWidgetMusConnection::OnConnectionLost() { | |
84 g_connections.Get().erase(routing_id_); | 91 g_connections.Get().erase(routing_id_); |
85 delete this; | 92 delete this; |
86 } | 93 } |
87 | 94 |
88 void RenderWidgetMusConnection::OnEmbed(mus::Window* root) { | 95 void RenderWidgetMusConnection::OnWindowInputEvent( |
89 root_ = root; | 96 scoped_ptr<blink::WebInputEvent> input_event) { |
90 root_->AddObserver(this); | 97 // TODO(fsamuel): Implement this once the following is complete: |
91 if (window_surface_binding_) { | 98 // 1. The Mus client lib support manual event ACKing. |
92 root->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, | 99 // 2. Mus supports event coalescing. |
93 window_surface_binding_.Pass()); | 100 // 3. RenderWidget is refactored so that we don't send ACKs to the browser |
94 } | 101 // process. |
95 } | |
96 | |
97 void RenderWidgetMusConnection::OnUnembed() {} | |
98 | |
99 void RenderWidgetMusConnection::OnWindowBoundsChanged( | |
100 mus::Window* window, | |
101 const gfx::Rect& old_bounds, | |
102 const gfx::Rect& new_bounds) { | |
103 } | 102 } |
104 | 103 |
105 } // namespace content | 104 } // namespace content |
OLD | NEW |