| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/gpu/gpu_process_host_ui_shim.h" | 5 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/id_map.h" | 11 #include "base/id_map.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "content/browser/compositor/gpu_process_transport_factory.h" | 16 #include "content/browser/compositor/gpu_process_transport_factory.h" |
| 17 #include "content/browser/field_trial_recorder.h" |
| 17 #include "content/browser/gpu/compositor_util.h" | 18 #include "content/browser/gpu/compositor_util.h" |
| 18 #include "content/browser/gpu/gpu_data_manager_impl.h" | 19 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 19 #include "content/browser/gpu/gpu_process_host.h" | 20 #include "content/browser/gpu/gpu_process_host.h" |
| 20 #include "content/browser/renderer_host/render_process_host_impl.h" | 21 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 21 #include "content/browser/renderer_host/render_view_host_impl.h" | 22 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 22 #include "content/browser/renderer_host/render_widget_helper.h" | 23 #include "content/browser/renderer_host/render_widget_helper.h" |
| 23 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 24 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 24 #include "content/common/gpu_host_messages.h" | |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "gpu/ipc/common/memory_stats.h" | 26 #include "gpu/ipc/common/memory_stats.h" |
| 27 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.h" |
| 27 #include "ui/gfx/swap_result.h" | 28 #include "ui/gfx/swap_result.h" |
| 28 | 29 |
| 29 #if defined(OS_ANDROID) | 30 #if defined(OS_ANDROID) |
| 30 #include "content/public/browser/android/java_interfaces.h" | 31 #include "content/public/browser/android/java_interfaces.h" |
| 31 #include "media/mojo/interfaces/android_overlay.mojom.h" | 32 #include "media/mojo/interfaces/android_overlay.mojom.h" |
| 32 #include "services/service_manager/public/cpp/binder_registry.h" | 33 #include "services/service_manager/public/cpp/binder_registry.h" |
| 33 #include "services/service_manager/public/cpp/interface_provider.h" | 34 #include "services/service_manager/public/cpp/interface_provider.h" |
| 34 #endif | 35 #endif |
| 35 | 36 |
| 36 #if defined(USE_OZONE) | 37 #if defined(USE_OZONE) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 | 50 |
| 50 base::LazyInstance<IDMap<GpuProcessHostUIShim*>>::DestructorAtExit | 51 base::LazyInstance<IDMap<GpuProcessHostUIShim*>>::DestructorAtExit |
| 51 g_hosts_by_id = LAZY_INSTANCE_INITIALIZER; | 52 g_hosts_by_id = LAZY_INSTANCE_INITIALIZER; |
| 52 | 53 |
| 53 #if defined(OS_ANDROID) | 54 #if defined(OS_ANDROID) |
| 54 template <typename Interface> | 55 template <typename Interface> |
| 55 void BindJavaInterface(mojo::InterfaceRequest<Interface> request) { | 56 void BindJavaInterface(mojo::InterfaceRequest<Interface> request) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 57 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 57 content::GetGlobalJavaInterfaces()->GetInterface(std::move(request)); | 58 content::GetGlobalJavaInterfaces()->GetInterface(std::move(request)); |
| 58 } | 59 } |
| 59 | |
| 60 // Binder which posts each request to the UI thread. | |
| 61 template <typename Interface> | |
| 62 void BindJavaInterfaceOnUIThread(mojo::InterfaceRequest<Interface> request) { | |
| 63 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI) | |
| 64 ->PostTask(FROM_HERE, base::Bind(&BindJavaInterface<Interface>, | |
| 65 base::Passed(&request))); | |
| 66 } | |
| 67 #endif | 60 #endif |
| 68 | 61 |
| 69 } // namespace | 62 } // namespace |
| 70 | 63 |
| 71 void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg) { | 64 void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg) { |
| 72 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id); | 65 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id); |
| 73 if (ui_shim) | 66 if (ui_shim) |
| 74 ui_shim->OnMessageReceived(msg); | 67 ui_shim->OnMessageReceived(msg); |
| 75 } | 68 } |
| 76 | 69 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 130 |
| 138 NOTREACHED() << "Invalid message with type = " << message.type(); | 131 NOTREACHED() << "Invalid message with type = " << message.type(); |
| 139 return true; | 132 return true; |
| 140 } | 133 } |
| 141 | 134 |
| 142 GpuProcessHostUIShim::~GpuProcessHostUIShim() { | 135 GpuProcessHostUIShim::~GpuProcessHostUIShim() { |
| 143 DCHECK(CalledOnValidThread()); | 136 DCHECK(CalledOnValidThread()); |
| 144 g_hosts_by_id.Pointer()->Remove(host_id_); | 137 g_hosts_by_id.Pointer()->Remove(host_id_); |
| 145 } | 138 } |
| 146 | 139 |
| 147 #if defined(OS_ANDROID) | |
| 148 // static | 140 // static |
| 149 void GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces( | 141 void GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces( |
| 150 service_manager::BinderRegistry* registry) { | 142 service_manager::BinderRegistry* registry) { |
| 151 registry->AddInterface(base::Bind( | 143 auto task_runner = BrowserThread::GetTaskRunnerForThread(BrowserThread::UI); |
| 152 &BindJavaInterfaceOnUIThread<media::mojom::AndroidOverlayProvider>)); | 144 |
| 145 registry->AddInterface(base::Bind(&FieldTrialRecorder::Create), task_runner); |
| 146 registry->AddInterface( |
| 147 base::Bind( |
| 148 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, |
| 149 base::Unretained( |
| 150 memory_instrumentation::CoordinatorImpl::GetInstance())), |
| 151 task_runner); |
| 152 #if defined(OS_ANDROID) |
| 153 registry->AddInterface( |
| 154 base::Bind(&BindJavaInterface<media::mojom::AndroidOverlayProvider>), |
| 155 task_runner); |
| 156 #endif |
| 153 } | 157 } |
| 154 #endif | |
| 155 | 158 |
| 156 } // namespace content | 159 } // namespace content |
| OLD | NEW |