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/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 base::FilePath media_path; | 399 base::FilePath media_path; |
400 PathService::Get(DIR_MEDIA_LIBS, &media_path); | 400 PathService::Get(DIR_MEDIA_LIBS, &media_path); |
401 if (!media_path.empty()) | 401 if (!media_path.empty()) |
402 media::InitializeMediaLibrary(media_path); | 402 media::InitializeMediaLibrary(media_path); |
403 | 403 |
404 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 404 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
405 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); | 405 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); |
406 | 406 |
407 renderer_process_id_ = base::kNullProcessId; | 407 renderer_process_id_ = base::kNullProcessId; |
408 | 408 |
| 409 // AllocateGpuMemoryBuffer must be used exclusively on one thread but |
| 410 // it doesn't have to be the same thread RenderThreadImpl is created on. |
| 411 allocate_gpu_memory_buffer_thread_checker_.DetachFromThread(); |
| 412 |
409 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, ""); | 413 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, ""); |
410 } | 414 } |
411 | 415 |
412 RenderThreadImpl::~RenderThreadImpl() { | 416 RenderThreadImpl::~RenderThreadImpl() { |
413 } | 417 } |
414 | 418 |
415 void RenderThreadImpl::Shutdown() { | 419 void RenderThreadImpl::Shutdown() { |
416 FOR_EACH_OBSERVER( | 420 FOR_EACH_OBSERVER( |
417 RenderProcessObserver, observers_, OnRenderProcessShutdown()); | 421 RenderProcessObserver, observers_, OnRenderProcessShutdown()); |
418 | 422 |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 } | 1067 } |
1064 | 1068 |
1065 void RenderThreadImpl::DeleteImage(int32 image_id, int32 sync_point) { | 1069 void RenderThreadImpl::DeleteImage(int32 image_id, int32 sync_point) { |
1066 NOTREACHED(); | 1070 NOTREACHED(); |
1067 } | 1071 } |
1068 | 1072 |
1069 scoped_ptr<gfx::GpuMemoryBuffer> RenderThreadImpl::AllocateGpuMemoryBuffer( | 1073 scoped_ptr<gfx::GpuMemoryBuffer> RenderThreadImpl::AllocateGpuMemoryBuffer( |
1070 size_t width, | 1074 size_t width, |
1071 size_t height, | 1075 size_t height, |
1072 unsigned internalformat) { | 1076 unsigned internalformat) { |
| 1077 DCHECK(allocate_gpu_memory_buffer_thread_checker_.CalledOnValidThread()); |
| 1078 |
1073 if (!GpuMemoryBufferImpl::IsFormatValid(internalformat)) | 1079 if (!GpuMemoryBufferImpl::IsFormatValid(internalformat)) |
1074 return scoped_ptr<gfx::GpuMemoryBuffer>(); | 1080 return scoped_ptr<gfx::GpuMemoryBuffer>(); |
1075 | 1081 |
1076 size_t size = width * height * | |
1077 GpuMemoryBufferImpl::BytesPerPixel(internalformat); | |
1078 if (size > static_cast<size_t>(std::numeric_limits<int>::max())) | |
1079 return scoped_ptr<gfx::GpuMemoryBuffer>(); | |
1080 | |
1081 gfx::GpuMemoryBufferHandle handle; | 1082 gfx::GpuMemoryBufferHandle handle; |
1082 bool success; | 1083 bool success; |
1083 IPC::Message* message = | 1084 IPC::Message* message = |
1084 new ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer(size, &handle); | 1085 new ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer(width, |
| 1086 height, |
| 1087 internalformat, |
| 1088 &handle); |
1085 | 1089 |
1086 // Allow calling this from the compositor thread. | 1090 // Allow calling this from the compositor thread. |
1087 if (base::MessageLoop::current() == message_loop()) | 1091 if (base::MessageLoop::current() == message_loop()) |
1088 success = ChildThread::Send(message); | 1092 success = ChildThread::Send(message); |
1089 else | 1093 else |
1090 success = sync_message_filter()->Send(message); | 1094 success = sync_message_filter()->Send(message); |
1091 | 1095 |
1092 if (!success) | 1096 if (!success) |
1093 return scoped_ptr<gfx::GpuMemoryBuffer>(); | 1097 return scoped_ptr<gfx::GpuMemoryBuffer>(); |
1094 | 1098 |
1095 // Currently, shared memory is the only supported buffer type. | 1099 return GpuMemoryBufferImpl::Create( |
1096 if (handle.type != gfx::SHARED_MEMORY_BUFFER) | 1100 handle, |
1097 return scoped_ptr<gfx::GpuMemoryBuffer>(); | 1101 gfx::Size(width, height), |
1098 | 1102 internalformat).PassAs<gfx::GpuMemoryBuffer>(); |
1099 if (!base::SharedMemory::IsHandleValid(handle.handle)) | |
1100 return scoped_ptr<gfx::GpuMemoryBuffer>(); | |
1101 | |
1102 return make_scoped_ptr<gfx::GpuMemoryBuffer>( | |
1103 new GpuMemoryBufferImpl( | |
1104 make_scoped_ptr(new base::SharedMemory(handle.handle, false)), | |
1105 width, | |
1106 height, | |
1107 internalformat)); | |
1108 } | 1103 } |
1109 | 1104 |
1110 void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { | 1105 void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { |
1111 suspend_webkit_shared_timer_ = false; | 1106 suspend_webkit_shared_timer_ = false; |
1112 } | 1107 } |
1113 | 1108 |
1114 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { | 1109 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { |
1115 notify_webkit_of_modal_loop_ = false; | 1110 notify_webkit_of_modal_loop_ = false; |
1116 } | 1111 } |
1117 | 1112 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 if (!gamepad_shared_memory_reader_) | 1365 if (!gamepad_shared_memory_reader_) |
1371 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); | 1366 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); |
1372 gamepad_shared_memory_reader_->SampleGamepads(*data); | 1367 gamepad_shared_memory_reader_->SampleGamepads(*data); |
1373 } | 1368 } |
1374 | 1369 |
1375 base::ProcessId RenderThreadImpl::renderer_process_id() const { | 1370 base::ProcessId RenderThreadImpl::renderer_process_id() const { |
1376 return renderer_process_id_; | 1371 return renderer_process_id_; |
1377 } | 1372 } |
1378 | 1373 |
1379 } // namespace content | 1374 } // namespace content |
OLD | NEW |