Chromium Code Reviews| Index: content/renderer/mus/renderer_window_tree_client.cc |
| diff --git a/content/renderer/mus/renderer_window_tree_client.cc b/content/renderer/mus/renderer_window_tree_client.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..70f7e6b153040dbe7f7fac0248d4fdf0b2841ae4 |
| --- /dev/null |
| +++ b/content/renderer/mus/renderer_window_tree_client.cc |
| @@ -0,0 +1,135 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/mus/renderer_window_tree_client.h" |
| + |
| +#include <map> |
| + |
| +#include "base/lazy_instance.h" |
| +#include "services/ui/public/cpp/window_compositor_frame_sink.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| +typedef std::map<int, RendererWindowTreeClient*> ConnectionMap; |
| +base::LazyInstance<ConnectionMap>::Leaky g_connections = |
| + LAZY_INSTANCE_INITIALIZER; |
| +} // namespace |
| + |
| +// static |
| +RendererWindowTreeClient* RendererWindowTreeClient::Get(int routing_id) { |
| + auto it = g_connections.Get().find(routing_id); |
| + if (it != g_connections.Get().end()) |
| + return it->second; |
| + return nullptr; |
| +} |
| + |
| +// static |
| +void RendererWindowTreeClient::Create(int routing_id) { |
| + DCHECK(g_connections.Get().find(routing_id) == g_connections.Get().end()); |
| + RendererWindowTreeClient* connection = |
| + new RendererWindowTreeClient(routing_id); |
| + g_connections.Get().insert(std::make_pair(routing_id, connection)); |
| +} |
| + |
| +RendererWindowTreeClient::RendererWindowTreeClient(int routing_id) |
| + : routing_id_(routing_id), binding_(this) {} |
| + |
| +RendererWindowTreeClient::~RendererWindowTreeClient() { |
| + g_connections.Get().erase(routing_id_); |
| +} |
| + |
| +void RendererWindowTreeClient::Bind( |
| + ui::mojom::WindowTreeClientRequest request) { |
| + binding_.Bind(std::move(request)); |
| +} |
| + |
| +std::unique_ptr<cc::CompositorFrameSink> |
| +RendererWindowTreeClient::CreateCompositorFrameSink( |
| + const cc::FrameSinkId& frame_sink_id, |
| + scoped_refptr<cc::ContextProvider> context_provider, |
| + gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { |
| + std::unique_ptr<ui::WindowCompositorFrameSinkBinding> frame_sink_binding; |
| + auto frame_sink = ui::WindowCompositorFrameSink::Create( |
| + frame_sink_id, std::move(context_provider), gpu_memory_buffer_manager, |
| + &frame_sink_binding); |
| + if (tree_) { |
| + tree_->AttachCompositorFrameSink( |
| + root_window_id_, frame_sink_binding->TakeFrameSinkRequest(), |
| + mojo::MakeProxy(frame_sink_binding->TakeFrameSinkClient())); |
| + } else { |
| + pending_frame_sink_ = std::move(frame_sink_binding); |
| + } |
| + return std::move(frame_sink); |
| +} |
| + |
| +void RendererWindowTreeClient::DestroySelf() { |
| + delete this; |
| +} |
| + |
| +void RendererWindowTreeClient::OnEmbed(ui::ClientSpecificId client_id, |
| + ui::mojom::WindowDataPtr root, |
| + ui::mojom::WindowTreePtr tree, |
| + int64_t display_id, |
| + ui::Id focused_window_id, |
| + bool drawn) { |
| + root_window_id_ = root->window_id; |
| + tree_ = std::move(tree); |
| + if (pending_frame_sink_) { |
| + tree_->AttachCompositorFrameSink( |
| + root_window_id_, pending_frame_sink_->TakeFrameSinkRequest(), |
| + mojo::MakeProxy(pending_frame_sink_->TakeFrameSinkClient())); |
| + pending_frame_sink_ = nullptr; |
| + } |
| +} |
| + |
| +void RendererWindowTreeClient::OnEmbeddedAppDisconnected(ui::Id window_id) { |
| + // TODO(sad): Embedded mus-client (oopif) is gone. Figure out what to do. |
| +} |
| + |
| +void RendererWindowTreeClient::OnUnembed(ui::Id window_id) { |
| + CHECK_EQ(window_id, root_window_id_); |
| + DestroySelf(); |
| +} |
| + |
| +void RendererWindowTreeClient::OnTopLevelCreated(uint32_t change_id, |
| + ui::mojom::WindowDataPtr data, |
| + int64_t display_id, |
| + bool drawn) { |
| + NOTREACHED(); |
| +} |
| + |
| +void RendererWindowTreeClient::OnWindowDeleted(ui::Id window_id) { |
| + // TODO(sad): With OOPIF, |window_id| may not be |root_window_id_|. We need to |
| + // make sure that works correctly. |
| + CHECK_EQ(window_id, root_window_id_); |
| + DestroySelf(); |
| +} |
| + |
| +void RendererWindowTreeClient::OnWindowInputEvent( |
| + uint32_t event_id, |
| + ui::Id window_id, |
| + std::unique_ptr<ui::Event> event, |
| + bool matches_pointer_watcher) { |
| + NOTREACHED(); |
| +} |
| + |
| +void RendererWindowTreeClient::OnPointerEventObserved( |
| + std::unique_ptr<ui::Event> event, |
| + uint32_t window_id) { |
| + NOTREACHED(); |
| +} |
| + |
| +void RendererWindowTreeClient::OnWindowSurfaceChanged( |
| + ui::Id window_id, |
| + const cc::SurfaceInfo& surface_info) { |
| + NOTIMPLEMENTED(); |
|
Fady Samuel
2017/01/24 02:04:38
We would get to here when an OOPIF submits a Compo
sadrul
2017/01/24 18:02:41
Acknowledged.
|
| +} |
| + |
| +void RendererWindowTreeClient::GetWindowManager( |
| + mojo::AssociatedInterfaceRequest<ui::mojom::WindowManager> internal) { |
| + NOTREACHED(); |
| +} |
| + |
| +} // namespace content |