OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/ws/gpu_service_proxy.h" | 5 #include "services/ui/ws/gpu_service_proxy.h" |
6 | 6 |
7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 mojom::GpuServiceInternal* gpu_service_internal) | 36 mojom::GpuServiceInternal* gpu_service_internal) |
37 : client_id_(client_id), | 37 : client_id_(client_id), |
38 gpu_info_(gpu_info), | 38 gpu_info_(gpu_info), |
39 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 39 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
40 gpu_service_internal_(gpu_service_internal) { | 40 gpu_service_internal_(gpu_service_internal) { |
41 DCHECK(gpu_memory_buffer_manager_); | 41 DCHECK(gpu_memory_buffer_manager_); |
42 DCHECK(gpu_service_internal_); | 42 DCHECK(gpu_service_internal_); |
43 } | 43 } |
44 ~GpuServiceImpl() override {} | 44 ~GpuServiceImpl() override {} |
45 | 45 |
| 46 void reset_gpu_service_internal(mojom::GpuServiceInternal* connection) { |
| 47 gpu_service_internal_ = connection; |
| 48 } |
| 49 |
46 private: | 50 private: |
47 void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback, | 51 void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback, |
48 mojo::ScopedMessagePipeHandle channel_handle) { | 52 mojo::ScopedMessagePipeHandle channel_handle) { |
49 callback.Run(client_id_, std::move(channel_handle), *gpu_info_); | 53 callback.Run(client_id_, std::move(channel_handle), *gpu_info_); |
50 } | 54 } |
51 | 55 |
52 // mojom::GpuService overrides: | 56 // mojom::GpuService overrides: |
53 void EstablishGpuChannel( | 57 void EstablishGpuChannel( |
54 const EstablishGpuChannelCallback& callback) override { | 58 const EstablishGpuChannelCallback& callback) override { |
55 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful | 59 // TODO(sad): crbug.com/617415 figure out how to generate a meaningful |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } // namespace | 98 } // namespace |
95 | 99 |
96 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) | 100 GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate) |
97 : delegate_(delegate), | 101 : delegate_(delegate), |
98 next_client_id_(kInternalGpuChannelClientId + 1), | 102 next_client_id_(kInternalGpuChannelClientId + 1), |
99 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) { | 103 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) { |
100 gpu_main_.OnStart(); | 104 gpu_main_.OnStart(); |
101 // TODO(sad): Once GPU process is split, this would look like: | 105 // TODO(sad): Once GPU process is split, this would look like: |
102 // connector->ConnectToInterface("gpu", &gpu_service_); | 106 // connector->ConnectToInterface("gpu", &gpu_service_); |
103 gpu_main_.Create(GetProxy(&gpu_service_)); | 107 gpu_main_.Create(GetProxy(&gpu_service_)); |
| 108 gpu_service_.set_connection_error_handler( |
| 109 base::Bind(&GpuServiceProxy::OnGpuConnectionGone, |
| 110 base::Unretained(this))); |
104 gpu_service_->Initialize( | 111 gpu_service_->Initialize( |
105 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); | 112 base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this))); |
106 gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>( | 113 gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>( |
107 gpu_service_.get(), next_client_id_++); | 114 gpu_service_.get(), next_client_id_++); |
108 } | 115 } |
109 | 116 |
110 GpuServiceProxy::~GpuServiceProxy() { | 117 GpuServiceProxy::~GpuServiceProxy() { |
111 } | 118 } |
112 | 119 |
113 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { | 120 void GpuServiceProxy::Add(mojom::GpuServiceRequest request) { |
114 mojo::MakeStrongBinding( | 121 clients_.push_back(mojo::MakeStrongBinding( |
115 base::MakeUnique<GpuServiceImpl>(next_client_id_++, &gpu_info_, | 122 base::MakeUnique<GpuServiceImpl>(next_client_id_++, &gpu_info_, |
116 gpu_memory_buffer_manager_.get(), | 123 gpu_memory_buffer_manager_.get(), |
117 gpu_service_.get()), | 124 gpu_service_.get()), |
118 std::move(request)); | 125 std::move(request))); |
119 } | 126 } |
120 | 127 |
121 void GpuServiceProxy::CreateDisplayCompositor( | 128 void GpuServiceProxy::CreateDisplayCompositor( |
122 cc::mojom::DisplayCompositorRequest request, | 129 cc::mojom::DisplayCompositorRequest request, |
123 cc::mojom::DisplayCompositorClientPtr client) { | 130 cc::mojom::DisplayCompositorClientPtr client) { |
124 gpu_service_->CreateDisplayCompositor(std::move(request), std::move(client)); | 131 gpu_service_->CreateDisplayCompositor(std::move(request), std::move(client)); |
125 } | 132 } |
126 | 133 |
127 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { | 134 void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) { |
128 gpu_info_ = gpu_info; | 135 gpu_info_ = gpu_info; |
129 delegate_->OnGpuServiceInitialized(); | 136 delegate_->OnGpuServiceInitialized(); |
130 } | 137 } |
131 | 138 |
| 139 void GpuServiceProxy::OnGpuConnectionGone() { |
| 140 // TODO(sad): Once GPU process is split, this would look like: |
| 141 // connector->ConnectToInterface("gpu", &gpu_service_); |
| 142 gpu_main_.Create(GetProxy(&gpu_service_)); |
| 143 gpu_service_.set_connection_error_handler( |
| 144 base::Bind(&GpuServiceProxy::OnGpuConnectionGone, |
| 145 base::Unretained(this))); |
| 146 for (auto& weak_ptr : clients_) { |
| 147 GpuServiceImpl* client = static_cast<GpuServiceImpl*>(weak_ptr->impl()); |
| 148 client->reset_gpu_service_internal(gpu_service_.get()); |
| 149 } |
| 150 } |
| 151 |
132 } // namespace ws | 152 } // namespace ws |
133 } // namespace ui | 153 } // namespace ui |
OLD | NEW |