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

Side by Side Diff: content/common/gpu/gpu_command_buffer_stub.cc

Issue 10695133: Improve GPU process URL crash reporting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update / merge Created 8 years, 5 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
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 #if defined(ENABLE_GPU) 5 #if defined(ENABLE_GPU)
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/shared_memory.h" 11 #include "base/shared_memory.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "content/common/gpu/gpu_channel.h" 14 #include "content/common/gpu/gpu_channel.h"
15 #include "content/common/gpu/gpu_channel_manager.h" 15 #include "content/common/gpu/gpu_channel_manager.h"
16 #include "content/common/gpu/gpu_command_buffer_stub.h" 16 #include "content/common/gpu/gpu_command_buffer_stub.h"
17 #include "content/common/gpu/gpu_memory_manager.h" 17 #include "content/common/gpu/gpu_memory_manager.h"
18 #include "content/common/gpu/gpu_messages.h" 18 #include "content/common/gpu/gpu_messages.h"
19 #include "content/common/gpu/gpu_watchdog.h" 19 #include "content/common/gpu/gpu_watchdog.h"
20 #include "content/common/gpu/image_transport_surface.h" 20 #include "content/common/gpu/image_transport_surface.h"
21 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" 21 #include "content/common/gpu/media/gpu_video_decode_accelerator.h"
22 #include "content/common/gpu/sync_point_manager.h" 22 #include "content/common/gpu/sync_point_manager.h"
23 #include "content/public/common/content_client.h"
23 #include "gpu/command_buffer/common/constants.h" 24 #include "gpu/command_buffer/common/constants.h"
24 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 25 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
25 #include "ui/gl/gl_bindings.h" 26 #include "ui/gl/gl_bindings.h"
26 #include "ui/gl/gl_switches.h" 27 #include "ui/gl/gl_switches.h"
27 28
28 #if defined(OS_WIN) 29 #if defined(OS_WIN)
29 #include "content/public/common/sandbox_init.h" 30 #include "content/public/common/sandbox_init.h"
30 #endif 31 #endif
31 32
32 namespace { 33 namespace {
34
35 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the
36 // url_hash matches.
37 void FastSetActiveURL(const GURL& url, size_t url_hash) {
38 // Leave the previously set URL in the empty case -- empty URLs are given by
39 // WebKitPlatformSupportImpl::createOffscreenGraphicsContext3D. Hopefully the
40 // onscreen context URL was set previously and will show up even when a crash
41 // occurs during offscreen command processing.
42 if (url.is_empty())
43 return;
44 static GURL g_last_url;
45 static size_t g_last_url_hash;
46 if (url_hash != g_last_url_hash) {
47 g_last_url = url;
48 g_last_url_hash = url_hash;
49 content::GetContentClient()->SetActiveURL(url);
50 }
51 }
52
33 // The first time polling a fence, delay some extra time to allow other 53 // The first time polling a fence, delay some extra time to allow other
34 // stubs to process some work, or else the timing of the fences could 54 // stubs to process some work, or else the timing of the fences could
35 // allow a pattern of alternating fast and slow frames to occur. 55 // allow a pattern of alternating fast and slow frames to occur.
36 const int64 kHandleMoreWorkPeriodMs = 2; 56 const int64 kHandleMoreWorkPeriodMs = 2;
37 const int64 kHandleMoreWorkPeriodBusyMs = 1; 57 const int64 kHandleMoreWorkPeriodBusyMs = 1;
38 } 58
59 } // namespace
39 60
40 GpuCommandBufferStub::SurfaceState::SurfaceState(int32 surface_id, 61 GpuCommandBufferStub::SurfaceState::SurfaceState(int32 surface_id,
41 bool visible, 62 bool visible,
42 base::TimeTicks last_used_time) 63 base::TimeTicks last_used_time)
43 : surface_id(surface_id), 64 : surface_id(surface_id),
44 visible(visible), 65 visible(visible),
45 last_used_time(last_used_time) { 66 last_used_time(last_used_time) {
46 } 67 }
47 68
48 GpuCommandBufferStub::GpuCommandBufferStub( 69 GpuCommandBufferStub::GpuCommandBufferStub(
49 GpuChannel* channel, 70 GpuChannel* channel,
50 GpuCommandBufferStub* share_group, 71 GpuCommandBufferStub* share_group,
51 const gfx::GLSurfaceHandle& handle, 72 const gfx::GLSurfaceHandle& handle,
52 gpu::gles2::MailboxManager* mailbox_manager, 73 gpu::gles2::MailboxManager* mailbox_manager,
53 const gfx::Size& size, 74 const gfx::Size& size,
54 const gpu::gles2::DisallowedFeatures& disallowed_features, 75 const gpu::gles2::DisallowedFeatures& disallowed_features,
55 const std::string& allowed_extensions, 76 const std::string& allowed_extensions,
56 const std::vector<int32>& attribs, 77 const std::vector<int32>& attribs,
57 gfx::GpuPreference gpu_preference, 78 gfx::GpuPreference gpu_preference,
58 int32 route_id, 79 int32 route_id,
59 int32 surface_id, 80 int32 surface_id,
60 GpuWatchdog* watchdog, 81 GpuWatchdog* watchdog,
61 bool software) 82 bool software,
83 const GURL& active_url)
62 : channel_(channel), 84 : channel_(channel),
63 handle_(handle), 85 handle_(handle),
64 initial_size_(size), 86 initial_size_(size),
65 disallowed_features_(disallowed_features), 87 disallowed_features_(disallowed_features),
66 allowed_extensions_(allowed_extensions), 88 allowed_extensions_(allowed_extensions),
67 requested_attribs_(attribs), 89 requested_attribs_(attribs),
68 gpu_preference_(gpu_preference), 90 gpu_preference_(gpu_preference),
69 route_id_(route_id), 91 route_id_(route_id),
70 software_(software), 92 software_(software),
71 client_has_memory_allocation_changed_callback_(false), 93 client_has_memory_allocation_changed_callback_(false),
72 last_flush_count_(0), 94 last_flush_count_(0),
73 parent_stub_for_initialization_(), 95 parent_stub_for_initialization_(),
74 parent_texture_for_initialization_(0), 96 parent_texture_for_initialization_(0),
75 watchdog_(watchdog), 97 watchdog_(watchdog),
76 sync_point_wait_count_(0), 98 sync_point_wait_count_(0),
77 delayed_work_scheduled_(false) { 99 delayed_work_scheduled_(false),
100 active_url_(active_url) {
101 active_url_hash_ =
102 base::hash<std::string>()(active_url.possibly_invalid_spec());
103 FastSetActiveURL(active_url_, active_url_hash_);
78 if (share_group) { 104 if (share_group) {
79 context_group_ = share_group->context_group_; 105 context_group_ = share_group->context_group_;
80 } else { 106 } else {
81 context_group_ = new gpu::gles2::ContextGroup(mailbox_manager, true); 107 context_group_ = new gpu::gles2::ContextGroup(mailbox_manager, true);
82 } 108 }
83 if (surface_id != 0) 109 if (surface_id != 0)
84 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState( 110 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState(
85 surface_id, true, base::TimeTicks::Now())); 111 surface_id, true, base::TimeTicks::Now()));
86 if (handle_.sync_point) 112 if (handle_.sync_point)
87 OnWaitSyncPoint(handle_.sync_point); 113 OnWaitSyncPoint(handle_.sync_point);
88 } 114 }
89 115
90 GpuCommandBufferStub::~GpuCommandBufferStub() { 116 GpuCommandBufferStub::~GpuCommandBufferStub() {
91 Destroy(); 117 Destroy();
92 118
93 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); 119 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager();
94 gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer(surface_id())); 120 gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer(surface_id()));
95 } 121 }
96 122
97 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { 123 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) {
124 FastSetActiveURL(active_url_, active_url_hash_);
125
98 // Ensure the appropriate GL context is current before handling any IPC 126 // Ensure the appropriate GL context is current before handling any IPC
99 // messages directed at the command buffer. This ensures that the message 127 // messages directed at the command buffer. This ensures that the message
100 // handler can assume that the context is current (not necessary for 128 // handler can assume that the context is current (not necessary for
101 // Echo, RetireSyncPoint, or WaitSyncPoint). 129 // Echo, RetireSyncPoint, or WaitSyncPoint).
102 if (decoder_.get() && 130 if (decoder_.get() &&
103 message.type() != GpuCommandBufferMsg_Echo::ID && 131 message.type() != GpuCommandBufferMsg_Echo::ID &&
104 message.type() != GpuCommandBufferMsg_RetireSyncPoint::ID && 132 message.type() != GpuCommandBufferMsg_RetireSyncPoint::ID &&
105 message.type() != GpuCommandBufferMsg_WaitSyncPoint::ID) { 133 message.type() != GpuCommandBufferMsg_WaitSyncPoint::ID) {
106 if (!MakeCurrent()) 134 if (!MakeCurrent())
107 return false; 135 return false;
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 if (CommandLine::ForCurrentProcess()->HasSwitch( 392 if (CommandLine::ForCurrentProcess()->HasSwitch(
365 switches::kEnableGPUServiceLogging)) { 393 switches::kEnableGPUServiceLogging)) {
366 decoder_->set_log_commands(true); 394 decoder_->set_log_commands(true);
367 } 395 }
368 396
369 decoder_->SetMsgCallback( 397 decoder_->SetMsgCallback(
370 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, 398 base::Bind(&GpuCommandBufferStub::SendConsoleMessage,
371 base::Unretained(this))); 399 base::Unretained(this)));
372 400
373 command_buffer_->SetPutOffsetChangeCallback( 401 command_buffer_->SetPutOffsetChangeCallback(
374 base::Bind(&gpu::GpuScheduler::PutChanged, 402 base::Bind(&GpuCommandBufferStub::PutChanged, base::Unretained(this)));
375 base::Unretained(scheduler_.get())));
376 command_buffer_->SetGetBufferChangeCallback( 403 command_buffer_->SetGetBufferChangeCallback(
377 base::Bind(&gpu::GpuScheduler::SetGetBuffer, 404 base::Bind(&gpu::GpuScheduler::SetGetBuffer,
378 base::Unretained(scheduler_.get()))); 405 base::Unretained(scheduler_.get())));
379 command_buffer_->SetParseErrorCallback( 406 command_buffer_->SetParseErrorCallback(
380 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); 407 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this)));
381 scheduler_->SetScheduledCallback( 408 scheduler_->SetScheduledCallback(
382 base::Bind(&GpuCommandBufferStub::OnReschedule, base::Unretained(this))); 409 base::Bind(&GpuCommandBufferStub::OnReschedule, base::Unretained(this)));
383 410
384 if (watchdog_) { 411 if (watchdog_) {
385 scheduler_->SetCommandProcessedCallback( 412 scheduler_->SetCommandProcessedCallback(
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 void GpuCommandBufferStub::ReportState() { 628 void GpuCommandBufferStub::ReportState() {
602 gpu::CommandBuffer::State state = command_buffer_->GetState(); 629 gpu::CommandBuffer::State state = command_buffer_->GetState();
603 if (state.error == gpu::error::kLostContext && 630 if (state.error == gpu::error::kLostContext &&
604 gfx::GLContext::LosesAllContextsOnContextLost()) { 631 gfx::GLContext::LosesAllContextsOnContextLost()) {
605 channel_->LoseAllContexts(); 632 channel_->LoseAllContexts();
606 } else { 633 } else {
607 command_buffer_->UpdateState(); 634 command_buffer_->UpdateState();
608 } 635 }
609 } 636 }
610 637
638 void GpuCommandBufferStub::PutChanged() {
639 FastSetActiveURL(active_url_, active_url_hash_);
640 scheduler_->PutChanged();
641 }
642
611 void GpuCommandBufferStub::OnCreateVideoDecoder( 643 void GpuCommandBufferStub::OnCreateVideoDecoder(
612 media::VideoCodecProfile profile, 644 media::VideoCodecProfile profile,
613 IPC::Message* reply_message) { 645 IPC::Message* reply_message) {
614 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateVideoDecoder"); 646 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateVideoDecoder");
615 int decoder_route_id = channel_->GenerateRouteID(); 647 int decoder_route_id = channel_->GenerateRouteID();
616 GpuVideoDecodeAccelerator* decoder = 648 GpuVideoDecodeAccelerator* decoder =
617 new GpuVideoDecodeAccelerator(this, decoder_route_id, this); 649 new GpuVideoDecodeAccelerator(this, decoder_route_id, this);
618 video_decoders_.AddWithID(decoder, decoder_route_id); 650 video_decoders_.AddWithID(decoder, decoder_route_id);
619 channel_->AddRoute(decoder_route_id, decoder); 651 channel_->AddRoute(decoder_route_id, decoder);
620 decoder->Initialize(profile, reply_message); 652 decoder->Initialize(profile, reply_message);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 const GpuMemoryAllocation& allocation) { 797 const GpuMemoryAllocation& allocation) {
766 Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation)); 798 Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation));
767 // This can be called outside of OnMessageReceived, so the context needs to be 799 // This can be called outside of OnMessageReceived, so the context needs to be
768 // made current before calling methods on the surface. 800 // made current before calling methods on the surface.
769 if (!surface_ || !MakeCurrent()) 801 if (!surface_ || !MakeCurrent())
770 return; 802 return;
771 surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer); 803 surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer);
772 } 804 }
773 805
774 #endif // defined(ENABLE_GPU) 806 #endif // defined(ENABLE_GPU)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698