Index: content/renderer/render_widget_mus_connection.cc |
diff --git a/content/renderer/render_widget_mus_connection.cc b/content/renderer/render_widget_mus_connection.cc |
index 297e0f226e08fdac531d99642ad617ba1a39444b..607918007b7e9f931307379e0fff003efc3695a8 100644 |
--- a/content/renderer/render_widget_mus_connection.cc |
+++ b/content/renderer/render_widget_mus_connection.cc |
@@ -4,76 +4,94 @@ |
#include "content/renderer/render_widget_mus_connection.h" |
+#include <map> |
+ |
+#include "base/lazy_instance.h" |
+#include "components/mus/public/cpp/context_provider.h" |
+#include "components/mus/public/cpp/output_surface.h" |
+#include "components/mus/public/interfaces/command_buffer.mojom.h" |
#include "components/mus/public/interfaces/compositor_frame.mojom.h" |
+#include "components/mus/public/interfaces/gpu.mojom.h" |
#include "components/mus/public/interfaces/window_tree.mojom.h" |
#include "content/public/common/mojo_shell_connection.h" |
+#include "content/renderer/render_view_impl.h" |
Fady Samuel
2015/11/30 23:06:54
Do you need this?
Peng
2015/12/01 15:22:47
Done.
|
#include "mojo/application/public/cpp/application_impl.h" |
#include "mojo/converters/geometry/geometry_type_converters.h" |
#include "mojo/converters/surfaces/surfaces_utils.h" |
namespace content { |
+namespace { |
+ |
+typedef std::map<int, RenderWidgetMusConnection*> ConnectionMap; |
+base::LazyInstance<ConnectionMap>::Leaky g_connections = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
+} |
+ |
RenderWidgetMusConnection::RenderWidgetMusConnection( |
- int routing_id, |
- mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) |
- : routing_id_(routing_id), root_(nullptr) { |
- // TODO(fsamuel): We should probably introduce a |
- // RenderWidgetMusConnection::FromRoutingID that's usable from RenderWidget. |
+ int routing_id) |
+ : routing_id_(routing_id), connected_(false), root_(nullptr) { |
+ DCHECK(routing_id); |
+} |
+ |
+RenderWidgetMusConnection::~RenderWidgetMusConnection() { |
+} |
+ |
+void RenderWidgetMusConnection::Connect( |
+ mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) { |
// TODO(fsamuel): We probably want to pause processing of incoming |
// messages until we have an associated RenderWidget. |
+ DCHECK(!connected_); |
Fady Samuel
2015/11/30 23:06:54
Just check if you have a root. You don't need this
Peng
2015/12/01 15:22:47
Done.
|
mus::WindowTreeConnection::Create( |
this, request.Pass(), |
mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); |
+ connected_ = true; |
} |
-RenderWidgetMusConnection::~RenderWidgetMusConnection() {} |
- |
-void RenderWidgetMusConnection::SubmitCompositorFrame() { |
- const gfx::Rect bounds(root_->bounds()); |
- mus::mojom::PassPtr pass = mojo::CreateDefaultPass(1, bounds); |
- mus::mojom::CompositorFramePtr frame = mus::mojom::CompositorFrame::New(); |
- |
- mus::mojom::CompositorFrameMetadataPtr meta = |
- mus::mojom::CompositorFrameMetadata::New(); |
- meta->device_scale_factor = 1.0f; |
- frame->metadata = meta.Pass(); |
- |
- frame->resources.resize(0u); |
- |
- pass->quads.resize(0u); |
- pass->shared_quad_states.push_back(mojo::CreateDefaultSQS(bounds.size())); |
- |
- mus::mojom::QuadPtr quad = mus::mojom::Quad::New(); |
- quad->material = mus::mojom::MATERIAL_SOLID_COLOR; |
- quad->rect = mojo::Rect::From(bounds); |
- quad->opaque_rect = mojo::Rect::New(); |
- quad->visible_rect = mojo::Rect::From(bounds); |
- quad->needs_blending = false; |
- quad->shared_quad_state_index = 0u; |
- |
- mus::mojom::SolidColorQuadStatePtr color_state = |
- mus::mojom::SolidColorQuadState::New(); |
- color_state->color = mus::mojom::Color::New(); |
- color_state->color->rgba = 0xff00ff00; |
- color_state->force_anti_aliasing_off = false; |
- |
- quad->solid_color_quad_state = color_state.Pass(); |
- pass->quads.push_back(quad.Pass()); |
- frame->passes.push_back(pass.Pass()); |
- surface_->SubmitCompositorFrame(frame.Pass(), mojo::Closure()); |
+scoped_ptr<cc::OutputSurface> RenderWidgetMusConnection::CreateOutputSurface() { |
+ DCHECK(!window_surface_binding_); |
+ mus::mojom::GpuPtr gpu_service; |
+ MojoShellConnection::Get()->GetApplication()->ConnectToService( |
+ "mojo:mus", &gpu_service); |
+ mus::mojom::CommandBufferPtr cb; |
+ gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb)); |
+ scoped_refptr<cc::ContextProvider> context_provider( |
+ new mus::ContextProvider(cb.PassInterface().PassHandle())); |
+ scoped_ptr<cc::OutputSurface> output_surface(new mus::OutputSurface( |
+ context_provider, |
+ mus::WindowSurface::Create(&window_surface_binding_))); |
+ if (root_) { |
+ root_->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, |
+ window_surface_binding_.Pass()); |
+ } |
+ return output_surface.Pass(); |
+} |
+ |
+RenderWidgetMusConnection* RenderWidgetMusConnection::Get(int routing_id) { |
Fady Samuel
2015/11/30 23:06:54
Add // static above.
Peng
2015/12/01 15:22:47
Done.
|
+ auto it = g_connections.Get().find(routing_id); |
+ if (it != g_connections.Get().end()) |
+ return it->second; |
+ |
+ RenderWidgetMusConnection* connection = new RenderWidgetMusConnection( |
+ routing_id); |
+ g_connections.Get().insert(std::make_pair(routing_id, connection)); |
+ return connection; |
} |
void RenderWidgetMusConnection::OnConnectionLost( |
mus::WindowTreeConnection* connection) { |
+ g_connections.Get().erase(routing_id_); |
delete this; |
} |
void RenderWidgetMusConnection::OnEmbed(mus::Window* root) { |
root_ = root; |
root_->AddObserver(this); |
- surface_ = root_->RequestSurface(mus::mojom::SURFACE_TYPE_DEFAULT); |
- surface_->BindToThread(); |
- SubmitCompositorFrame(); |
+ if (window_surface_binding_) { |
+ root->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT, |
+ window_surface_binding_.Pass()); |
+ } |
} |
void RenderWidgetMusConnection::OnUnembed() {} |
@@ -82,7 +100,6 @@ void RenderWidgetMusConnection::OnWindowBoundsChanged( |
mus::Window* window, |
const gfx::Rect& old_bounds, |
const gfx::Rect& new_bounds) { |
- SubmitCompositorFrame(); |
} |
} // namespace content |