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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 } | 1071 } |
1068 | 1072 |
1069 void RenderThreadImpl::DeleteImage(int32 image_id, int32 sync_point) { | 1073 void RenderThreadImpl::DeleteImage(int32 image_id, int32 sync_point) { |
1070 NOTREACHED(); | 1074 NOTREACHED(); |
1071 } | 1075 } |
1072 | 1076 |
1073 scoped_ptr<gfx::GpuMemoryBuffer> RenderThreadImpl::AllocateGpuMemoryBuffer( | 1077 scoped_ptr<gfx::GpuMemoryBuffer> RenderThreadImpl::AllocateGpuMemoryBuffer( |
1074 size_t width, | 1078 size_t width, |
1075 size_t height, | 1079 size_t height, |
1076 unsigned internalformat) { | 1080 unsigned internalformat) { |
| 1081 DCHECK(allocate_gpu_memory_buffer_thread_checker_.CalledOnValidThread()); |
| 1082 |
1077 if (!GpuMemoryBufferImpl::IsFormatValid(internalformat)) | 1083 if (!GpuMemoryBufferImpl::IsFormatValid(internalformat)) |
1078 return scoped_ptr<gfx::GpuMemoryBuffer>(); | 1084 return scoped_ptr<gfx::GpuMemoryBuffer>(); |
1079 | 1085 |
1080 size_t size = width * height * | |
1081 GpuMemoryBufferImpl::BytesPerPixel(internalformat); | |
1082 if (size > static_cast<size_t>(std::numeric_limits<int>::max())) | |
1083 return scoped_ptr<gfx::GpuMemoryBuffer>(); | |
1084 | |
1085 gfx::GpuMemoryBufferHandle handle; | 1086 gfx::GpuMemoryBufferHandle handle; |
1086 bool success; | 1087 bool success; |
1087 IPC::Message* message = | 1088 IPC::Message* message = |
1088 new ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer(size, &handle); | 1089 new ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer(width, |
| 1090 height, |
| 1091 internalformat, |
| 1092 &handle); |
1089 | 1093 |
1090 // Allow calling this from the compositor thread. | 1094 // Allow calling this from the compositor thread. |
1091 if (base::MessageLoop::current() == message_loop()) | 1095 if (base::MessageLoop::current() == message_loop()) |
1092 success = ChildThread::Send(message); | 1096 success = ChildThread::Send(message); |
1093 else | 1097 else |
1094 success = sync_message_filter()->Send(message); | 1098 success = sync_message_filter()->Send(message); |
1095 | 1099 |
1096 if (!success) | 1100 if (!success) |
1097 return scoped_ptr<gfx::GpuMemoryBuffer>(); | 1101 return scoped_ptr<gfx::GpuMemoryBuffer>(); |
1098 | 1102 |
1099 // Currently, shared memory is the only supported buffer type. | 1103 return GpuMemoryBufferImpl::Create( |
1100 if (handle.type != gfx::SHARED_MEMORY_BUFFER) | 1104 handle, |
1101 return scoped_ptr<gfx::GpuMemoryBuffer>(); | 1105 gfx::Size(width, height), |
1102 | 1106 internalformat).PassAs<gfx::GpuMemoryBuffer>(); |
1103 if (!base::SharedMemory::IsHandleValid(handle.handle)) | |
1104 return scoped_ptr<gfx::GpuMemoryBuffer>(); | |
1105 | |
1106 return make_scoped_ptr<gfx::GpuMemoryBuffer>( | |
1107 new GpuMemoryBufferImpl( | |
1108 make_scoped_ptr(new base::SharedMemory(handle.handle, false)), | |
1109 width, | |
1110 height, | |
1111 internalformat)); | |
1112 } | 1107 } |
1113 | 1108 |
1114 void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { | 1109 void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { |
1115 suspend_webkit_shared_timer_ = false; | 1110 suspend_webkit_shared_timer_ = false; |
1116 } | 1111 } |
1117 | 1112 |
1118 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { | 1113 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { |
1119 notify_webkit_of_modal_loop_ = false; | 1114 notify_webkit_of_modal_loop_ = false; |
1120 } | 1115 } |
1121 | 1116 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 if (!gamepad_shared_memory_reader_) | 1369 if (!gamepad_shared_memory_reader_) |
1375 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); | 1370 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); |
1376 gamepad_shared_memory_reader_->SampleGamepads(*data); | 1371 gamepad_shared_memory_reader_->SampleGamepads(*data); |
1377 } | 1372 } |
1378 | 1373 |
1379 base::ProcessId RenderThreadImpl::renderer_process_id() const { | 1374 base::ProcessId RenderThreadImpl::renderer_process_id() const { |
1380 return renderer_process_id_; | 1375 return renderer_process_id_; |
1381 } | 1376 } |
1382 | 1377 |
1383 } // namespace content | 1378 } // namespace content |
OLD | NEW |