Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 302443008: content: Always allocate GpuMemoryBuffers on UI thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: one more android build fix Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Represents the browser side of the browser <--> renderer communication 5 // Represents the browser side of the browser <--> renderer communication
6 // channel. There will be one RenderProcessHost per renderer process. 6 // channel. There will be one RenderProcessHost per renderer process.
7 7
8 #include "content/browser/renderer_host/render_process_host_impl.h" 8 #include "content/browser/renderer_host/render_process_host_impl.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <limits> 11 #include <limits>
12 #include <vector> 12 #include <vector>
13 13
14 #if defined(OS_POSIX) 14 #if defined(OS_POSIX)
15 #include <utility> // for pair<> 15 #include <utility> // for pair<>
16 #endif 16 #endif
17 17
18 #include "base/base_switches.h" 18 #include "base/base_switches.h"
19 #include "base/bind.h" 19 #include "base/bind.h"
20 #include "base/bind_helpers.h" 20 #include "base/bind_helpers.h"
21 #include "base/callback.h" 21 #include "base/callback.h"
22 #include "base/command_line.h" 22 #include "base/command_line.h"
23 #include "base/debug/trace_event.h" 23 #include "base/debug/trace_event.h"
24 #include "base/files/file.h" 24 #include "base/files/file.h"
25 #include "base/lazy_instance.h" 25 #include "base/lazy_instance.h"
26 #include "base/logging.h" 26 #include "base/logging.h"
27 #include "base/metrics/field_trial.h" 27 #include "base/metrics/field_trial.h"
28 #include "base/metrics/histogram.h" 28 #include "base/metrics/histogram.h"
29 #include "base/numerics/safe_math.h"
29 #include "base/path_service.h" 30 #include "base/path_service.h"
30 #include "base/rand_util.h" 31 #include "base/rand_util.h"
31 #include "base/stl_util.h" 32 #include "base/stl_util.h"
32 #include "base/strings/string_util.h" 33 #include "base/strings/string_util.h"
33 #include "base/supports_user_data.h" 34 #include "base/supports_user_data.h"
34 #include "base/sys_info.h" 35 #include "base/sys_info.h"
35 #include "base/threading/thread.h" 36 #include "base/threading/thread.h"
36 #include "base/threading/thread_restrictions.h" 37 #include "base/threading/thread_restrictions.h"
37 #include "base/tracked_objects.h" 38 #include "base/tracked_objects.h"
38 #include "cc/base/switches.h" 39 #include "cc/base/switches.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 #include "content/browser/storage_partition_impl.h" 105 #include "content/browser/storage_partition_impl.h"
105 #include "content/browser/streams/stream_context.h" 106 #include "content/browser/streams/stream_context.h"
106 #include "content/browser/tracing/trace_message_filter.h" 107 #include "content/browser/tracing/trace_message_filter.h"
107 #include "content/browser/vibration/vibration_message_filter.h" 108 #include "content/browser/vibration/vibration_message_filter.h"
108 #include "content/browser/webui/web_ui_controller_factory_registry.h" 109 #include "content/browser/webui/web_ui_controller_factory_registry.h"
109 #include "content/browser/worker_host/worker_message_filter.h" 110 #include "content/browser/worker_host/worker_message_filter.h"
110 #include "content/browser/worker_host/worker_storage_partition.h" 111 #include "content/browser/worker_host/worker_storage_partition.h"
111 #include "content/common/child_process_host_impl.h" 112 #include "content/common/child_process_host_impl.h"
112 #include "content/common/child_process_messages.h" 113 #include "content/common/child_process_messages.h"
113 #include "content/common/content_switches_internal.h" 114 #include "content/common/content_switches_internal.h"
115 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
116 #include "content/common/gpu/client/gpu_memory_buffer_impl_shm.h"
114 #include "content/common/gpu/gpu_messages.h" 117 #include "content/common/gpu/gpu_messages.h"
115 #include "content/common/mojo/mojo_messages.h" 118 #include "content/common/mojo/mojo_messages.h"
116 #include "content/common/resource_messages.h" 119 #include "content/common/resource_messages.h"
117 #include "content/common/view_messages.h" 120 #include "content/common/view_messages.h"
118 #include "content/public/browser/browser_context.h" 121 #include "content/public/browser/browser_context.h"
119 #include "content/public/browser/content_browser_client.h" 122 #include "content/public/browser/content_browser_client.h"
120 #include "content/public/browser/notification_service.h" 123 #include "content/public/browser/notification_service.h"
121 #include "content/public/browser/notification_types.h" 124 #include "content/public/browser/notification_types.h"
122 #include "content/public/browser/render_process_host_factory.h" 125 #include "content/public/browser/render_process_host_factory.h"
123 #include "content/public/browser/render_process_host_observer.h" 126 #include "content/public/browser/render_process_host_observer.h"
(...skipping 21 matching lines...) Expand all
145 #include "ui/base/ui_base_switches.h" 148 #include "ui/base/ui_base_switches.h"
146 #include "ui/events/event_switches.h" 149 #include "ui/events/event_switches.h"
147 #include "ui/gfx/switches.h" 150 #include "ui/gfx/switches.h"
148 #include "ui/gl/gl_switches.h" 151 #include "ui/gl/gl_switches.h"
149 #include "ui/native_theme/native_theme_switches.h" 152 #include "ui/native_theme/native_theme_switches.h"
150 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" 153 #include "webkit/browser/fileapi/sandbox_file_system_backend.h"
151 #include "webkit/common/resource_type.h" 154 #include "webkit/common/resource_type.h"
152 155
153 #if defined(OS_ANDROID) 156 #if defined(OS_ANDROID)
154 #include "content/browser/media/android/browser_demuxer_android.h" 157 #include "content/browser/media/android/browser_demuxer_android.h"
158 #include "content/browser/renderer_host/compositor_impl_android.h"
159 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
160 #endif
161
162 #if defined(OS_MACOSX)
163 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
164 #include "ui/gl/io_surface_support_mac.h"
155 #endif 165 #endif
156 166
157 #if defined(OS_WIN) 167 #if defined(OS_WIN)
158 #include "base/win/scoped_com_initializer.h" 168 #include "base/win/scoped_com_initializer.h"
159 #include "content/common/font_cache_dispatcher_win.h" 169 #include "content/common/font_cache_dispatcher_win.h"
160 #include "content/common/sandbox_win.h" 170 #include "content/common/sandbox_win.h"
161 #endif 171 #endif
162 172
163 #if defined(ENABLE_WEBRTC) 173 #if defined(ENABLE_WEBRTC)
164 #include "content/browser/media/webrtc_internals.h" 174 #include "content/browser/media/webrtc_internals.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return ipc_fd_; 329 return ipc_fd_;
320 } 330 }
321 #endif // OS_WIN 331 #endif // OS_WIN
322 332
323 private: 333 private:
324 #if defined(OS_POSIX) 334 #if defined(OS_POSIX)
325 int ipc_fd_; 335 int ipc_fd_;
326 #endif // OS_POSIX 336 #endif // OS_POSIX
327 }; 337 };
328 338
339 #if defined(OS_MACOSX)
340 void AddBooleanValue(CFMutableDictionaryRef dictionary,
341 const CFStringRef key,
342 bool value) {
343 CFDictionaryAddValue(
344 dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse);
345 }
346
347 void AddIntegerValue(CFMutableDictionaryRef dictionary,
348 const CFStringRef key,
349 int32 value) {
350 base::ScopedCFTypeRef<CFNumberRef> number(
351 CFNumberCreate(NULL, kCFNumberSInt32Type, &value));
352 CFDictionaryAddValue(dictionary, key, number.get());
353 }
354 #endif
355
329 } // namespace 356 } // namespace
330 357
331 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; 358 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL;
332 359
333 base::MessageLoop* g_in_process_thread; 360 base::MessageLoop* g_in_process_thread;
334 361
335 base::MessageLoop* 362 base::MessageLoop*
336 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { 363 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() {
337 return g_in_process_thread; 364 return g_in_process_thread;
338 } 365 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 queued_messages_.pop(); 520 queued_messages_.pop();
494 } 521 }
495 522
496 UnregisterHost(GetID()); 523 UnregisterHost(GetID());
497 524
498 if (!CommandLine::ForCurrentProcess()->HasSwitch( 525 if (!CommandLine::ForCurrentProcess()->HasSwitch(
499 switches::kDisableGpuShaderDiskCache)) { 526 switches::kDisableGpuShaderDiskCache)) {
500 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 527 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
501 base::Bind(&RemoveShaderInfo, GetID())); 528 base::Bind(&RemoveShaderInfo, GetID()));
502 } 529 }
530
531 #if defined(OS_ANDROID)
532 CompositorImpl::DestroyAllSurfaceTextures(GetID());
533 #endif
503 } 534 }
504 535
505 void RenderProcessHostImpl::EnableSendQueue() { 536 void RenderProcessHostImpl::EnableSendQueue() {
506 is_initialized_ = false; 537 is_initialized_ = false;
507 } 538 }
508 539
509 bool RenderProcessHostImpl::Init() { 540 bool RenderProcessHostImpl::Init() {
510 // calling Init() more than once does nothing, this makes it more convenient 541 // calling Init() more than once does nothing, this makes it more convenient
511 // for the view host which may not be sure in some cases 542 // for the view host which may not be sure in some cases
512 if (channel_) 543 if (channel_)
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 IPC_BEGIN_MESSAGE_MAP(RenderProcessHostImpl, msg) 1338 IPC_BEGIN_MESSAGE_MAP(RenderProcessHostImpl, msg)
1308 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ShutdownRequest, 1339 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ShutdownRequest,
1309 OnShutdownRequest) 1340 OnShutdownRequest)
1310 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DumpHandlesDone, 1341 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DumpHandlesDone,
1311 OnDumpHandlesDone) 1342 OnDumpHandlesDone)
1312 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, 1343 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged,
1313 SuddenTerminationChanged) 1344 SuddenTerminationChanged)
1314 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, 1345 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction,
1315 OnUserMetricsRecordAction) 1346 OnUserMetricsRecordAction)
1316 IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML) 1347 IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML)
1348 IPC_MESSAGE_HANDLER_DELAY_REPLY(
1349 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer,
1350 OnAllocateGpuMemoryBuffer)
1317 // Adding single handlers for your service here is fine, but once your 1351 // Adding single handlers for your service here is fine, but once your
1318 // service needs more than one handler, please extract them into a new 1352 // service needs more than one handler, please extract them into a new
1319 // message filter and add that filter to CreateMessageFilters(). 1353 // message filter and add that filter to CreateMessageFilters().
1320 IPC_END_MESSAGE_MAP() 1354 IPC_END_MESSAGE_MAP()
1321 1355
1322 return true; 1356 return true;
1323 } 1357 }
1324 1358
1325 // Dispatch incoming messages to the appropriate IPC::Listener. 1359 // Dispatch incoming messages to the appropriate IPC::Listener.
1326 IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); 1360 IPC::Listener* listener = listeners_.Lookup(msg.routing_id());
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 mojo::ScopedMessagePipeHandle handle) { 2140 mojo::ScopedMessagePipeHandle handle) {
2107 mojo_activation_required_ = true; 2141 mojo_activation_required_ = true;
2108 MaybeActivateMojo(); 2142 MaybeActivateMojo();
2109 2143
2110 mojo_application_host_->service_provider()->ConnectToService( 2144 mojo_application_host_->service_provider()->ConnectToService(
2111 mojo::String::From(service_name), 2145 mojo::String::From(service_name),
2112 std::string(), 2146 std::string(),
2113 handle.Pass()); 2147 handle.Pass());
2114 } 2148 }
2115 2149
2150 void RenderProcessHostImpl::OnAllocateGpuMemoryBuffer(uint32 width,
2151 uint32 height,
2152 uint32 internalformat,
2153 uint32 usage,
2154 IPC::Message* reply) {
2155 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2156 if (!GpuMemoryBufferImpl::IsFormatValid(internalformat) ||
2157 !GpuMemoryBufferImpl::IsUsageValid(usage)) {
2158 GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle());
2159 return;
2160 }
2161 base::CheckedNumeric<int> size = width;
2162 size *= height;
2163 if (!size.IsValid()) {
2164 GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle());
2165 return;
2166 }
2167
2168 #if defined(OS_MACOSX)
2169 // TODO(reveman): This should be moved to
2170 // GpuMemoryBufferImpl::AllocateForChildProcess and
2171 // GpuMemoryBufferImplIOSurface. crbug.com/325045, crbug.com/323304
2172 if (GpuMemoryBufferImplIOSurface::IsConfigurationSupported(internalformat,
2173 usage)) {
2174 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize();
2175 if (io_surface_support) {
2176 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties;
2177 properties.reset(
2178 CFDictionaryCreateMutable(kCFAllocatorDefault,
2179 0,
2180 &kCFTypeDictionaryKeyCallBacks,
2181 &kCFTypeDictionaryValueCallBacks));
2182 AddIntegerValue(
2183 properties, io_surface_support->GetKIOSurfaceWidth(), width);
2184 AddIntegerValue(
2185 properties, io_surface_support->GetKIOSurfaceHeight(), height);
2186 AddIntegerValue(properties,
2187 io_surface_support->GetKIOSurfaceBytesPerElement(),
2188 GpuMemoryBufferImpl::BytesPerPixel(internalformat));
2189 AddIntegerValue(
2190 properties,
2191 io_surface_support->GetKIOSurfacePixelFormat(),
2192 GpuMemoryBufferImplIOSurface::PixelFormat(internalformat));
2193 // TODO(reveman): Remove this when using a mach_port_t to transfer
2194 // IOSurface to renderer process. crbug.com/323304
2195 AddBooleanValue(
2196 properties, io_surface_support->GetKIOSurfaceIsGlobal(), true);
2197
2198 base::ScopedCFTypeRef<CFTypeRef> io_surface(
2199 io_surface_support->IOSurfaceCreate(properties));
2200 if (io_surface) {
2201 gfx::GpuMemoryBufferHandle handle;
2202 handle.type = gfx::IO_SURFACE_BUFFER;
2203 handle.io_surface_id = io_surface_support->IOSurfaceGetID(io_surface);
2204
2205 // TODO(reveman): This makes the assumption that the renderer will
2206 // grab a reference to the surface before sending another message.
2207 // crbug.com/325045
2208 last_io_surface_ = io_surface;
2209 GpuMemoryBufferAllocated(reply, handle);
2210 return;
2211 }
2212 }
2213 }
2214 #endif
2215
2216 #if defined(OS_ANDROID)
2217 // TODO(reveman): This should be moved to
2218 // GpuMemoryBufferImpl::AllocateForChildProcess and
2219 // GpuMemoryBufferImplSurfaceTexture when adding support for out-of-process
2220 // GPU service. crbug.com/368716
2221 if (GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(
2222 internalformat, usage)) {
2223 // Each surface texture is associated with a render process id. This allows
2224 // the GPU service and Java Binder IPC to verify that a renderer is not
2225 // trying to use a surface texture it doesn't own.
2226 int surface_texture_id = CompositorImpl::CreateSurfaceTexture(GetID());
2227 if (surface_texture_id != -1) {
2228 gfx::GpuMemoryBufferHandle handle;
2229 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
2230 handle.surface_texture_id =
2231 gfx::SurfaceTextureId(surface_texture_id, GetID());
2232 GpuMemoryBufferAllocated(reply, handle);
2233 return;
2234 }
2235 }
2236 #endif
2237
2238 GpuMemoryBufferImpl::AllocateForChildProcess(
2239 gfx::Size(width, height),
2240 internalformat,
2241 usage,
2242 GetHandle(),
2243 base::Bind(&RenderProcessHostImpl::GpuMemoryBufferAllocated,
2244 weak_factory_.GetWeakPtr(),
2245 reply));
2246 }
2247
2248 void RenderProcessHostImpl::GpuMemoryBufferAllocated(
2249 IPC::Message* reply,
2250 const gfx::GpuMemoryBufferHandle& handle) {
2251 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2252 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply,
2253 handle);
2254 Send(reply);
2255 }
2256
2116 } // namespace content 2257 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698