| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" |
| 11 #include "base/id_map.h" |
| 12 #include "base/lazy_instance.h" |
| 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/trace_event/trace_event.h" |
| 15 #include "build/build_config.h" |
| 16 #include "content/browser/compositor/gpu_process_transport_factory.h" |
| 17 #include "content/browser/field_trial_recorder.h" |
| 18 #include "content/browser/gpu/compositor_util.h" |
| 19 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 20 #include "content/browser/gpu/gpu_process_host.h" |
| 21 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 22 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 23 #include "content/browser/renderer_host/render_widget_helper.h" |
| 24 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "gpu/ipc/common/memory_stats.h" |
| 27 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.h" |
| 28 #include "ui/gfx/swap_result.h" |
| 29 |
| 30 #if defined(OS_ANDROID) |
| 31 #include "content/public/browser/android/java_interfaces.h" |
| 32 #include "media/mojo/interfaces/android_overlay.mojom.h" |
| 33 #include "services/service_manager/public/cpp/binder_registry.h" |
| 34 #include "services/service_manager/public/cpp/interface_provider.h" |
| 35 #endif |
| 36 |
| 37 #if defined(USE_OZONE) |
| 38 #include "ui/ozone/public/gpu_platform_support_host.h" |
| 39 #include "ui/ozone/public/ozone_platform.h" |
| 40 #endif |
| 41 |
| 42 namespace content { |
| 43 |
| 44 namespace { |
| 45 |
| 46 base::LazyInstance<IDMap<GpuProcessHostUIShim*>>::Leaky g_hosts_by_id = |
| 47 LAZY_INSTANCE_INITIALIZER; |
| 48 |
| 49 #if defined(OS_ANDROID) |
| 50 template <typename Interface> |
| 51 void BindJavaInterface(mojo::InterfaceRequest<Interface> request) { |
| 52 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 53 content::GetGlobalJavaInterfaces()->GetInterface(std::move(request)); |
| 54 } |
| 55 #endif |
| 56 |
| 57 } // namespace |
| 58 |
| 59 void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg) { |
| 60 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id); |
| 61 if (ui_shim) |
| 62 ui_shim->OnMessageReceived(msg); |
| 63 } |
| 64 |
| 65 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id) |
| 66 : host_id_(host_id) { |
| 67 g_hosts_by_id.Pointer()->AddWithID(this, host_id_); |
| 68 #if defined(USE_OZONE) |
| 69 ui::OzonePlatform::GetInstance() |
| 70 ->GetGpuPlatformSupportHost() |
| 71 ->OnChannelEstablished(); |
| 72 #endif |
| 73 } |
| 74 |
| 75 // static |
| 76 GpuProcessHostUIShim* GpuProcessHostUIShim::Create(int host_id) { |
| 77 DCHECK(!FromID(host_id)); |
| 78 return new GpuProcessHostUIShim(host_id); |
| 79 } |
| 80 |
| 81 // static |
| 82 void GpuProcessHostUIShim::Destroy(int host_id, const std::string& message) { |
| 83 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 84 |
| 85 GpuDataManagerImpl::GetInstance()->AddLogMessage( |
| 86 logging::LOG_ERROR, "GpuProcessHostUIShim", |
| 87 message); |
| 88 |
| 89 #if defined(USE_OZONE) |
| 90 ui::OzonePlatform::GetInstance() |
| 91 ->GetGpuPlatformSupportHost() |
| 92 ->OnChannelDestroyed(host_id); |
| 93 #endif |
| 94 |
| 95 delete FromID(host_id); |
| 96 } |
| 97 |
| 98 // static |
| 99 GpuProcessHostUIShim* GpuProcessHostUIShim::FromID(int host_id) { |
| 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 101 return g_hosts_by_id.Pointer()->Lookup(host_id); |
| 102 } |
| 103 |
| 104 void GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { |
| 105 DCHECK(CalledOnValidThread()); |
| 106 |
| 107 #if defined(USE_OZONE) |
| 108 if (ui::OzonePlatform::GetInstance() |
| 109 ->GetGpuPlatformSupportHost() |
| 110 ->OnMessageReceived(message)) |
| 111 return; |
| 112 #endif |
| 113 |
| 114 if (message.routing_id() == MSG_ROUTING_CONTROL) { |
| 115 NOTREACHED() << "Invalid message with type = " << message.type(); |
| 116 } |
| 117 } |
| 118 |
| 119 GpuProcessHostUIShim::~GpuProcessHostUIShim() { |
| 120 DCHECK(CalledOnValidThread()); |
| 121 g_hosts_by_id.Pointer()->Remove(host_id_); |
| 122 } |
| 123 |
| 124 // static |
| 125 void GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces( |
| 126 service_manager::BinderRegistry* registry) { |
| 127 auto task_runner = BrowserThread::GetTaskRunnerForThread(BrowserThread::UI); |
| 128 |
| 129 registry->AddInterface(base::Bind(&FieldTrialRecorder::Create), task_runner); |
| 130 registry->AddInterface( |
| 131 base::Bind( |
| 132 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, |
| 133 base::Unretained( |
| 134 memory_instrumentation::CoordinatorImpl::GetInstance())), |
| 135 task_runner); |
| 136 #if defined(OS_ANDROID) |
| 137 registry->AddInterface( |
| 138 base::Bind(&BindJavaInterface<media::mojom::AndroidOverlayProvider>), |
| 139 task_runner); |
| 140 #endif |
| 141 } |
| 142 |
| 143 } // namespace content |
| OLD | NEW |