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

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 634083002: gpu: Compositor management of GpuMemoryBuffer instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cc-pre-chromium-image-refactor
Patch Set: address review feedback Created 6 years, 2 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
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 #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
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
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
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 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 init_params, 1238 init_params,
1250 route_id, 1239 route_id,
1251 &result); 1240 &result);
1252 1241
1253 // Allow calling this from the compositor thread. 1242 // Allow calling this from the compositor thread.
1254 thread_safe_sender()->Send(message); 1243 thread_safe_sender()->Send(message);
1255 1244
1256 return result; 1245 return result;
1257 } 1246 }
1258 1247
1259 scoped_ptr<gfx::GpuMemoryBuffer> RenderThreadImpl::AllocateGpuMemoryBuffer(
1260 size_t width,
1261 size_t height,
1262 unsigned internalformat,
1263 unsigned usage) {
1264 TRACE_EVENT0("renderer", "RenderThreadImpl::AllocateGpuMemoryBuffer");
1265
1266 DCHECK(allocate_gpu_memory_buffer_thread_checker_.CalledOnValidThread());
1267
1268 if (!GpuMemoryBufferImpl::IsFormatValid(internalformat))
1269 return scoped_ptr<gfx::GpuMemoryBuffer>();
1270
1271 gfx::GpuMemoryBufferHandle handle;
1272 bool success;
1273 IPC::Message* message = new ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer(
1274 width, height, internalformat, usage, &handle);
1275
1276 // Allow calling this from the compositor thread.
1277 if (base::MessageLoop::current() == message_loop())
1278 success = ChildThread::Send(message);
1279 else
1280 success = sync_message_filter()->Send(message);
1281
1282 if (!success)
1283 return scoped_ptr<gfx::GpuMemoryBuffer>();
1284
1285 scoped_ptr<GpuMemoryBufferImpl> buffer(GpuMemoryBufferImpl::CreateFromHandle(
1286 handle,
1287 gfx::Size(width, height),
1288 internalformat,
1289 base::Bind(&DeletedGpuMemoryBuffer,
1290 make_scoped_refptr(thread_safe_sender()),
1291 handle.type,
1292 handle.global_id)));
1293 if (!buffer) {
1294 thread_safe_sender()->Send(new ChildProcessHostMsg_DeletedGpuMemoryBuffer(
1295 handle.type, handle.global_id));
1296 return scoped_ptr<gfx::GpuMemoryBuffer>();
1297 }
1298
1299 return buffer.PassAs<gfx::GpuMemoryBuffer>();
1300 }
1301
1302 void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { 1248 void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() {
1303 suspend_webkit_shared_timer_ = false; 1249 suspend_webkit_shared_timer_ = false;
1304 } 1250 }
1305 1251
1306 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { 1252 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() {
1307 notify_webkit_of_modal_loop_ = false; 1253 notify_webkit_of_modal_loop_ = false;
1308 } 1254 }
1309 1255
1310 bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { 1256 bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
1311 ObserverListBase<RenderProcessObserver>::Iterator it(observers_); 1257 ObserverListBase<RenderProcessObserver>::Iterator it(observers_);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 // Otherwise cancel the connection. 1364 // Otherwise cancel the connection.
1419 return NULL; 1365 return NULL;
1420 } 1366 }
1421 1367
1422 GetContentClient()->SetGpuInfo(gpu_info); 1368 GetContentClient()->SetGpuInfo(gpu_info);
1423 1369
1424 // Cache some variables that are needed on the compositor thread for our 1370 // Cache some variables that are needed on the compositor thread for our
1425 // implementation of GpuChannelHostFactory. 1371 // implementation of GpuChannelHostFactory.
1426 io_message_loop_proxy_ = ChildProcess::current()->io_message_loop_proxy(); 1372 io_message_loop_proxy_ = ChildProcess::current()->io_message_loop_proxy();
1427 1373
1428 gpu_channel_ = GpuChannelHost::Create( 1374 gpu_channel_ =
1429 this, gpu_info, channel_handle, 1375 GpuChannelHost::Create(this,
1430 ChildProcess::current()->GetShutDownEvent()); 1376 gpu_info,
1377 channel_handle,
1378 ChildProcess::current()->GetShutDownEvent(),
1379 gpu_memory_buffer_manager());
1431 return gpu_channel_.get(); 1380 return gpu_channel_.get();
1432 } 1381 }
1433 1382
1434 blink::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter( 1383 blink::WebMediaStreamCenter* RenderThreadImpl::CreateMediaStreamCenter(
1435 blink::WebMediaStreamCenterClient* client) { 1384 blink::WebMediaStreamCenterClient* client) {
1436 #if defined(OS_ANDROID) 1385 #if defined(OS_ANDROID)
1437 if (CommandLine::ForCurrentProcess()->HasSwitch( 1386 if (CommandLine::ForCurrentProcess()->HasSwitch(
1438 switches::kDisableWebRTC)) 1387 switches::kDisableWebRTC))
1439 return NULL; 1388 return NULL;
1440 #endif 1389 #endif
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 hidden_widget_count_--; 1581 hidden_widget_count_--;
1633 1582
1634 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { 1583 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
1635 return; 1584 return;
1636 } 1585 }
1637 1586
1638 ScheduleIdleHandler(kLongIdleHandlerDelayMs); 1587 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
1639 } 1588 }
1640 1589
1641 } // namespace content 1590 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698