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> | |
| 8 | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "components/mus/public/cpp/context_provider.h" | |
| 11 #include "components/mus/public/cpp/output_surface.h" | |
| 12 #include "components/mus/public/interfaces/command_buffer.mojom.h" | |
| 7 #include "components/mus/public/interfaces/compositor_frame.mojom.h" | 13 #include "components/mus/public/interfaces/compositor_frame.mojom.h" |
| 14 #include "components/mus/public/interfaces/gpu.mojom.h" | |
| 8 #include "components/mus/public/interfaces/window_tree.mojom.h" | 15 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 9 #include "content/public/common/mojo_shell_connection.h" | 16 #include "content/public/common/mojo_shell_connection.h" |
| 10 #include "mojo/application/public/cpp/application_impl.h" | 17 #include "mojo/application/public/cpp/application_impl.h" |
| 11 #include "mojo/converters/geometry/geometry_type_converters.h" | 18 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 12 #include "mojo/converters/surfaces/surfaces_utils.h" | 19 #include "mojo/converters/surfaces/surfaces_utils.h" |
| 13 | 20 |
| 14 namespace content { | 21 namespace content { |
| 15 | 22 |
| 16 RenderWidgetMusConnection::RenderWidgetMusConnection( | 23 namespace { |
| 17 int routing_id, | 24 |
| 18 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) | 25 typedef std::map<int, RenderWidgetMusConnection*> ConnectionMap; |
| 26 base::LazyInstance<ConnectionMap>::Leaky g_connections = | |
| 27 LAZY_INSTANCE_INITIALIZER; | |
| 28 } | |
| 29 | |
| 30 RenderWidgetMusConnection::RenderWidgetMusConnection(int routing_id) | |
| 19 : routing_id_(routing_id), root_(nullptr) { | 31 : routing_id_(routing_id), root_(nullptr) { |
| 20 // TODO(fsamuel): We should probably introduce a | 32 DCHECK(routing_id); |
| 21 // RenderWidgetMusConnection::FromRoutingID that's usable from RenderWidget. | 33 } |
| 34 | |
| 35 RenderWidgetMusConnection::~RenderWidgetMusConnection() {} | |
| 36 | |
| 37 void RenderWidgetMusConnection::Bind( | |
| 38 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) { | |
| 22 // TODO(fsamuel): We probably want to pause processing of incoming | 39 // TODO(fsamuel): We probably want to pause processing of incoming |
| 23 // messages until we have an associated RenderWidget. | 40 // messages until we have an associated RenderWidget. |
|
Fady Samuel
2015/12/02 16:20:33
nit: remove this TODO.
Peng
2015/12/02 16:33:32
Done.
| |
| 41 DCHECK(!root_); | |
| 24 mus::WindowTreeConnection::Create( | 42 mus::WindowTreeConnection::Create( |
| 25 this, request.Pass(), | 43 this, request.Pass(), |
| 26 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | 44 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); |
| 27 } | 45 } |
| 28 | 46 |
| 29 RenderWidgetMusConnection::~RenderWidgetMusConnection() {} | 47 scoped_ptr<cc::OutputSurface> RenderWidgetMusConnection::CreateOutputSurface() { |
| 48 DCHECK(!window_surface_binding_); | |
| 49 mus::mojom::GpuPtr gpu_service; | |
| 50 MojoShellConnection::Get()->GetApplication()->ConnectToService("mojo:mus", | |
| 51 &gpu_service); | |
| 52 mus::mojom::CommandBufferPtr cb; | |
| 53 gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb)); | |
| 54 scoped_refptr<cc::ContextProvider> context_provider( | |
| 55 new mus::ContextProvider(cb.PassInterface().PassHandle())); | |
| 56 scoped_ptr<cc::OutputSurface> output_surface(new mus::OutputSurface( | |
| 57 context_provider, mus::WindowSurface::Create(&window_surface_binding_))); | |
| 58 if (root_) { | |
| 59 root_->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, | |
| 60 window_surface_binding_.Pass()); | |
| 61 } | |
| 62 return output_surface.Pass(); | |
| 63 } | |
| 30 | 64 |
| 31 void RenderWidgetMusConnection::SubmitCompositorFrame() { | 65 // static |
| 32 const gfx::Rect bounds(root_->bounds()); | 66 RenderWidgetMusConnection* RenderWidgetMusConnection::GetOrCreate( |
| 33 mus::mojom::PassPtr pass = mojo::CreateDefaultPass(1, bounds); | 67 int routing_id) { |
| 34 mus::mojom::CompositorFramePtr frame = mus::mojom::CompositorFrame::New(); | 68 auto it = g_connections.Get().find(routing_id); |
| 69 if (it != g_connections.Get().end()) | |
| 70 return it->second; | |
| 35 | 71 |
| 36 mus::mojom::CompositorFrameMetadataPtr meta = | 72 RenderWidgetMusConnection* connection = |
| 37 mus::mojom::CompositorFrameMetadata::New(); | 73 new RenderWidgetMusConnection(routing_id); |
| 38 meta->device_scale_factor = 1.0f; | 74 g_connections.Get().insert(std::make_pair(routing_id, connection)); |
| 39 frame->metadata = meta.Pass(); | 75 return connection; |
| 40 | |
| 41 frame->resources.resize(0u); | |
| 42 | |
| 43 pass->quads.resize(0u); | |
| 44 pass->shared_quad_states.push_back(mojo::CreateDefaultSQS(bounds.size())); | |
| 45 | |
| 46 mus::mojom::QuadPtr quad = mus::mojom::Quad::New(); | |
| 47 quad->material = mus::mojom::MATERIAL_SOLID_COLOR; | |
| 48 quad->rect = mojo::Rect::From(bounds); | |
| 49 quad->opaque_rect = mojo::Rect::New(); | |
| 50 quad->visible_rect = mojo::Rect::From(bounds); | |
| 51 quad->needs_blending = false; | |
| 52 quad->shared_quad_state_index = 0u; | |
| 53 | |
| 54 mus::mojom::SolidColorQuadStatePtr color_state = | |
| 55 mus::mojom::SolidColorQuadState::New(); | |
| 56 color_state->color = mus::mojom::Color::New(); | |
| 57 color_state->color->rgba = 0xff00ff00; | |
| 58 color_state->force_anti_aliasing_off = false; | |
| 59 | |
| 60 quad->solid_color_quad_state = color_state.Pass(); | |
| 61 pass->quads.push_back(quad.Pass()); | |
| 62 frame->passes.push_back(pass.Pass()); | |
| 63 surface_->SubmitCompositorFrame(frame.Pass(), mojo::Closure()); | |
| 64 } | 76 } |
| 65 | 77 |
| 66 void RenderWidgetMusConnection::OnConnectionLost( | 78 void RenderWidgetMusConnection::OnConnectionLost( |
| 67 mus::WindowTreeConnection* connection) { | 79 mus::WindowTreeConnection* connection) { |
| 80 g_connections.Get().erase(routing_id_); | |
| 68 delete this; | 81 delete this; |
| 69 } | 82 } |
| 70 | 83 |
| 71 void RenderWidgetMusConnection::OnEmbed(mus::Window* root) { | 84 void RenderWidgetMusConnection::OnEmbed(mus::Window* root) { |
| 72 root_ = root; | 85 root_ = root; |
| 73 root_->AddObserver(this); | 86 root_->AddObserver(this); |
| 74 surface_ = root_->RequestSurface(mus::mojom::SURFACE_TYPE_DEFAULT); | 87 if (window_surface_binding_) { |
| 75 surface_->BindToThread(); | 88 root->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, |
| 76 SubmitCompositorFrame(); | 89 window_surface_binding_.Pass()); |
| 90 } | |
| 77 } | 91 } |
| 78 | 92 |
| 79 void RenderWidgetMusConnection::OnUnembed() {} | 93 void RenderWidgetMusConnection::OnUnembed() {} |
| 80 | 94 |
| 81 void RenderWidgetMusConnection::OnWindowBoundsChanged( | 95 void RenderWidgetMusConnection::OnWindowBoundsChanged( |
| 82 mus::Window* window, | 96 mus::Window* window, |
| 83 const gfx::Rect& old_bounds, | 97 const gfx::Rect& old_bounds, |
| 84 const gfx::Rect& new_bounds) { | 98 const gfx::Rect& new_bounds) { |
| 85 SubmitCompositorFrame(); | |
| 86 } | 99 } |
| 87 | 100 |
| 88 } // namespace content | 101 } // namespace content |
| OLD | NEW |