| 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 17 matching lines...) Expand all Loading... |
| 28 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/threading/thread_local.h" | 29 #include "base/threading/thread_local.h" |
| 30 #include "base/threading/thread_restrictions.h" | 30 #include "base/threading/thread_restrictions.h" |
| 31 #include "base/values.h" | 31 #include "base/values.h" |
| 32 #include "cc/base/switches.h" | 32 #include "cc/base/switches.h" |
| 33 #include "cc/blink/web_external_bitmap_impl.h" | 33 #include "cc/blink/web_external_bitmap_impl.h" |
| 34 #include "cc/blink/web_layer_impl.h" | 34 #include "cc/blink/web_layer_impl.h" |
| 35 #include "cc/resources/raster_worker_pool.h" | 35 #include "cc/resources/raster_worker_pool.h" |
| 36 #include "content/child/appcache/appcache_dispatcher.h" | 36 #include "content/child/appcache/appcache_dispatcher.h" |
| 37 #include "content/child/appcache/appcache_frontend_impl.h" | 37 #include "content/child/appcache/appcache_frontend_impl.h" |
| 38 #include "content/child/child_gpu_memory_buffer_manager.h" |
| 38 #include "content/child/child_histogram_message_filter.h" | 39 #include "content/child/child_histogram_message_filter.h" |
| 39 #include "content/child/content_child_helpers.h" | 40 #include "content/child/content_child_helpers.h" |
| 40 #include "content/child/db_message_filter.h" | 41 #include "content/child/db_message_filter.h" |
| 41 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 42 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 42 #include "content/child/indexed_db/indexed_db_message_filter.h" | 43 #include "content/child/indexed_db/indexed_db_message_filter.h" |
| 43 #include "content/child/npapi/npobject_util.h" | 44 #include "content/child/npapi/npobject_util.h" |
| 44 #include "content/child/plugin_messages.h" | 45 #include "content/child/plugin_messages.h" |
| 45 #include "content/child/resource_dispatcher.h" | 46 #include "content/child/resource_dispatcher.h" |
| 46 #include "content/child/runtime_features.h" | 47 #include "content/child/runtime_features.h" |
| 47 #include "content/child/thread_safe_sender.h" | 48 #include "content/child/thread_safe_sender.h" |
| 48 #include "content/child/web_database_observer_impl.h" | 49 #include "content/child/web_database_observer_impl.h" |
| 49 #include "content/child/worker_task_runner.h" | 50 #include "content/child/worker_task_runner.h" |
| 50 #include "content/common/child_process_messages.h" | 51 #include "content/common/child_process_messages.h" |
| 51 #include "content/common/content_constants_internal.h" | 52 #include "content/common/content_constants_internal.h" |
| 52 #include "content/common/database_messages.h" | 53 #include "content/common/database_messages.h" |
| 53 #include "content/common/dom_storage/dom_storage_messages.h" | 54 #include "content/common/dom_storage/dom_storage_messages.h" |
| 54 #include "content/common/frame_messages.h" | 55 #include "content/common/frame_messages.h" |
| 55 #include "content/common/gpu/client/context_provider_command_buffer.h" | 56 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 56 #include "content/common/gpu/client/gpu_channel_host.h" | 57 #include "content/common/gpu/client/gpu_channel_host.h" |
| 57 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | |
| 58 #include "content/common/gpu/gpu_messages.h" | 58 #include "content/common/gpu/gpu_messages.h" |
| 59 #include "content/common/gpu/gpu_process_launch_causes.h" | 59 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 60 #include "content/common/render_frame_setup.mojom.h" | 60 #include "content/common/render_frame_setup.mojom.h" |
| 61 #include "content/common/resource_messages.h" | 61 #include "content/common/resource_messages.h" |
| 62 #include "content/common/view_messages.h" | 62 #include "content/common/view_messages.h" |
| 63 #include "content/common/worker_messages.h" | 63 #include "content/common/worker_messages.h" |
| 64 #include "content/public/common/content_constants.h" | 64 #include "content/public/common/content_constants.h" |
| 65 #include "content/public/common/content_paths.h" | 65 #include "content/public/common/content_paths.h" |
| 66 #include "content/public/common/content_switches.h" | 66 #include "content/public/common/content_switches.h" |
| 67 #include "content/public/common/renderer_preferences.h" | 67 #include "content/public/common/renderer_preferences.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 blink::WebGraphicsContext3D::Attributes GetOffscreenAttribs() { | 321 blink::WebGraphicsContext3D::Attributes GetOffscreenAttribs() { |
| 322 blink::WebGraphicsContext3D::Attributes attributes; | 322 blink::WebGraphicsContext3D::Attributes attributes; |
| 323 attributes.shareResources = true; | 323 attributes.shareResources = true; |
| 324 attributes.depth = false; | 324 attributes.depth = false; |
| 325 attributes.stencil = false; | 325 attributes.stencil = false; |
| 326 attributes.antialias = false; | 326 attributes.antialias = false; |
| 327 attributes.noAutomaticFlushes = true; | 327 attributes.noAutomaticFlushes = true; |
| 328 return attributes; | 328 return attributes; |
| 329 } | 329 } |
| 330 | 330 |
| 331 void DeletedGpuMemoryBuffer(ThreadSafeSender* sender, | |
| 332 gfx::GpuMemoryBufferType type, | |
| 333 const gfx::GpuMemoryBufferId& id) { | |
| 334 TRACE_EVENT0("renderer", "RenderThreadImpl::DeletedGpuMemoryBuffer"); | |
| 335 sender->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer(type, id)); | |
| 336 } | |
| 337 | |
| 338 } // namespace | 331 } // namespace |
| 339 | 332 |
| 340 // For measuring memory usage after each task. Behind a command line flag. | 333 // For measuring memory usage after each task. Behind a command line flag. |
| 341 class MemoryObserver : public base::MessageLoop::TaskObserver { | 334 class MemoryObserver : public base::MessageLoop::TaskObserver { |
| 342 public: | 335 public: |
| 343 MemoryObserver() {} | 336 MemoryObserver() {} |
| 344 virtual ~MemoryObserver() {} | 337 virtual ~MemoryObserver() {} |
| 345 | 338 |
| 346 virtual void WillProcessTask(const base::PendingTask& pending_task) override { | 339 virtual void WillProcessTask(const base::PendingTask& pending_task) override { |
| 347 } | 340 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 supported_types.end(), | 550 supported_types.end(), |
| 558 requested_type) != supported_types.end()) { | 551 requested_type) != supported_types.end()) { |
| 559 type = requested_type; | 552 type = requested_type; |
| 560 } else { | 553 } else { |
| 561 LOG(ERROR) << "Requested discardable memory type is not supported."; | 554 LOG(ERROR) << "Requested discardable memory type is not supported."; |
| 562 } | 555 } |
| 563 } | 556 } |
| 564 | 557 |
| 565 base::DiscardableMemory::SetPreferredType(type); | 558 base::DiscardableMemory::SetPreferredType(type); |
| 566 | 559 |
| 567 // AllocateGpuMemoryBuffer must be used exclusively on one thread but | |
| 568 // it doesn't have to be the same thread RenderThreadImpl is created on. | |
| 569 allocate_gpu_memory_buffer_thread_checker_.DetachFromThread(); | |
| 570 | |
| 571 if (is_impl_side_painting_enabled_) { | 560 if (is_impl_side_painting_enabled_) { |
| 572 int num_raster_threads = 0; | 561 int num_raster_threads = 0; |
| 573 std::string string_value = | 562 std::string string_value = |
| 574 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | 563 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
| 575 bool parsed_num_raster_threads = | 564 bool parsed_num_raster_threads = |
| 576 base::StringToInt(string_value, &num_raster_threads); | 565 base::StringToInt(string_value, &num_raster_threads); |
| 577 DCHECK(parsed_num_raster_threads) << string_value; | 566 DCHECK(parsed_num_raster_threads) << string_value; |
| 578 DCHECK_GT(num_raster_threads, 0); | 567 DCHECK_GT(num_raster_threads, 0); |
| 579 cc::RasterWorkerPool::SetNumRasterThreads(num_raster_threads); | 568 cc::RasterWorkerPool::SetNumRasterThreads(num_raster_threads); |
| 580 } | 569 } |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 init_params, | 1245 init_params, |
| 1257 route_id, | 1246 route_id, |
| 1258 &result); | 1247 &result); |
| 1259 | 1248 |
| 1260 // Allow calling this from the compositor thread. | 1249 // Allow calling this from the compositor thread. |
| 1261 thread_safe_sender()->Send(message); | 1250 thread_safe_sender()->Send(message); |
| 1262 | 1251 |
| 1263 return result; | 1252 return result; |
| 1264 } | 1253 } |
| 1265 | 1254 |
| 1266 scoped_ptr<gfx::GpuMemoryBuffer> RenderThreadImpl::AllocateGpuMemoryBuffer( | |
| 1267 size_t width, | |
| 1268 size_t height, | |
| 1269 unsigned internalformat, | |
| 1270 unsigned usage) { | |
| 1271 TRACE_EVENT0("renderer", "RenderThreadImpl::AllocateGpuMemoryBuffer"); | |
| 1272 | |
| 1273 DCHECK(allocate_gpu_memory_buffer_thread_checker_.CalledOnValidThread()); | |
| 1274 | |
| 1275 if (!GpuMemoryBufferImpl::IsFormatValid(internalformat)) | |
| 1276 return scoped_ptr<gfx::GpuMemoryBuffer>(); | |
| 1277 | |
| 1278 gfx::GpuMemoryBufferHandle handle; | |
| 1279 bool success; | |
| 1280 IPC::Message* message = new ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer( | |
| 1281 width, height, internalformat, usage, &handle); | |
| 1282 | |
| 1283 // Allow calling this from the compositor thread. | |
| 1284 if (base::MessageLoop::current() == message_loop()) | |
| 1285 success = ChildThread::Send(message); | |
| 1286 else | |
| 1287 success = sync_message_filter()->Send(message); | |
| 1288 | |
| 1289 if (!success) | |
| 1290 return scoped_ptr<gfx::GpuMemoryBuffer>(); | |
| 1291 | |
| 1292 scoped_ptr<GpuMemoryBufferImpl> buffer(GpuMemoryBufferImpl::CreateFromHandle( | |
| 1293 handle, | |
| 1294 gfx::Size(width, height), | |
| 1295 internalformat, | |
| 1296 base::Bind(&DeletedGpuMemoryBuffer, | |
| 1297 make_scoped_refptr(thread_safe_sender()), | |
| 1298 handle.type, | |
| 1299 handle.global_id))); | |
| 1300 if (!buffer) { | |
| 1301 thread_safe_sender()->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer( | |
| 1302 handle.type, handle.global_id)); | |
| 1303 return scoped_ptr<gfx::GpuMemoryBuffer>(); | |
| 1304 } | |
| 1305 | |
| 1306 return buffer.PassAs<gfx::GpuMemoryBuffer>(); | |
| 1307 } | |
| 1308 | |
| 1309 void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { | 1255 void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { |
| 1310 suspend_webkit_shared_timer_ = false; | 1256 suspend_webkit_shared_timer_ = false; |
| 1311 } | 1257 } |
| 1312 | 1258 |
| 1313 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { | 1259 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { |
| 1314 notify_webkit_of_modal_loop_ = false; | 1260 notify_webkit_of_modal_loop_ = false; |
| 1315 } | 1261 } |
| 1316 | 1262 |
| 1317 bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { | 1263 bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
| 1318 ObserverListBase<RenderProcessObserver>::Iterator it(observers_); | 1264 ObserverListBase<RenderProcessObserver>::Iterator it(observers_); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 // Otherwise cancel the connection. | 1371 // Otherwise cancel the connection. |
| 1426 return NULL; | 1372 return NULL; |
| 1427 } | 1373 } |
| 1428 | 1374 |
| 1429 GetContentClient()->SetGpuInfo(gpu_info); | 1375 GetContentClient()->SetGpuInfo(gpu_info); |
| 1430 | 1376 |
| 1431 // Cache some variables that are needed on the compositor thread for our | 1377 // Cache some variables that are needed on the compositor thread for our |
| 1432 // implementation of GpuChannelHostFactory. | 1378 // implementation of GpuChannelHostFactory. |
| 1433 io_message_loop_proxy_ = ChildProcess::current()->io_message_loop_proxy(); | 1379 io_message_loop_proxy_ = ChildProcess::current()->io_message_loop_proxy(); |
| 1434 | 1380 |
| 1435 gpu_channel_ = GpuChannelHost::Create( | 1381 gpu_channel_ = |
| 1436 this, gpu_info, channel_handle, | 1382 GpuChannelHost::Create(this, |
| 1437 ChildProcess::current()->GetShutDownEvent()); | 1383 gpu_info, |
| 1384 channel_handle, |
| 1385 ChildProcess::current()->GetShutDownEvent(), |
| 1386 gpu_memory_buffer_manager()); |
| 1438 return gpu_channel_.get(); | 1387 return gpu_channel_.get(); |
| 1439 } | 1388 } |
| 1440 | 1389 |
| 1441 blink::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter( | 1390 blink::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter( |
| 1442 blink::WebMediaStreamCenterClient* client) { | 1391 blink::WebMediaStreamCenterClient* client) { |
| 1443 #if defined(OS_ANDROID) | 1392 #if defined(OS_ANDROID) |
| 1444 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1393 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1445 switches::kDisableWebRTC)) | 1394 switches::kDisableWebRTC)) |
| 1446 return NULL; | 1395 return NULL; |
| 1447 #endif | 1396 #endif |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 hidden_widget_count_--; | 1587 hidden_widget_count_--; |
| 1639 | 1588 |
| 1640 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { | 1589 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
| 1641 return; | 1590 return; |
| 1642 } | 1591 } |
| 1643 | 1592 |
| 1644 ScheduleIdleHandler(kLongIdleHandlerDelayMs); | 1593 ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
| 1645 } | 1594 } |
| 1646 | 1595 |
| 1647 } // namespace content | 1596 } // namespace content |
| OLD | NEW |