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 #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 |
33 namespace { | |
34 | |
35 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the | |
36 // url_hash matches. | |
Ken Russell (switch to Gerrit)
2012/07/10 23:38:01
Any indication of what kind of speedup this yields
jbates
2012/07/11 00:07:18
From a quick printf run, the majority of FastSetAc
| |
37 void FastSetActiveURL(const GURL& url, size_t url_hash) { | |
38 static GURL g_last_url; | |
39 static size_t g_last_url_hash; | |
40 if (url_hash != g_last_url_hash) { | |
41 g_last_url = url; | |
42 g_last_url_hash = url_hash; | |
43 content::GetContentClient()->SetActiveURL(url); | |
44 } | |
45 } | |
46 | |
47 } | |
48 | |
32 GpuCommandBufferStub::SurfaceState::SurfaceState(int32 surface_id, | 49 GpuCommandBufferStub::SurfaceState::SurfaceState(int32 surface_id, |
33 bool visible, | 50 bool visible, |
34 base::TimeTicks last_used_time) | 51 base::TimeTicks last_used_time) |
35 : surface_id(surface_id), | 52 : surface_id(surface_id), |
36 visible(visible), | 53 visible(visible), |
37 last_used_time(last_used_time) { | 54 last_used_time(last_used_time) { |
38 } | 55 } |
39 | 56 |
40 GpuCommandBufferStub::GpuCommandBufferStub( | 57 GpuCommandBufferStub::GpuCommandBufferStub( |
41 GpuChannel* channel, | 58 GpuChannel* channel, |
42 GpuCommandBufferStub* share_group, | 59 GpuCommandBufferStub* share_group, |
43 const gfx::GLSurfaceHandle& handle, | 60 const gfx::GLSurfaceHandle& handle, |
44 gpu::gles2::MailboxManager* mailbox_manager, | 61 gpu::gles2::MailboxManager* mailbox_manager, |
45 const gfx::Size& size, | 62 const gfx::Size& size, |
46 const gpu::gles2::DisallowedFeatures& disallowed_features, | 63 const gpu::gles2::DisallowedFeatures& disallowed_features, |
47 const std::string& allowed_extensions, | 64 const std::string& allowed_extensions, |
48 const std::vector<int32>& attribs, | 65 const std::vector<int32>& attribs, |
49 gfx::GpuPreference gpu_preference, | 66 gfx::GpuPreference gpu_preference, |
50 int32 route_id, | 67 int32 route_id, |
51 int32 surface_id, | 68 int32 surface_id, |
52 GpuWatchdog* watchdog, | 69 GpuWatchdog* watchdog, |
53 bool software) | 70 bool software, |
71 const GURL& active_url) | |
54 : channel_(channel), | 72 : channel_(channel), |
55 handle_(handle), | 73 handle_(handle), |
56 initial_size_(size), | 74 initial_size_(size), |
57 disallowed_features_(disallowed_features), | 75 disallowed_features_(disallowed_features), |
58 allowed_extensions_(allowed_extensions), | 76 allowed_extensions_(allowed_extensions), |
59 requested_attribs_(attribs), | 77 requested_attribs_(attribs), |
60 gpu_preference_(gpu_preference), | 78 gpu_preference_(gpu_preference), |
61 route_id_(route_id), | 79 route_id_(route_id), |
62 software_(software), | 80 software_(software), |
63 client_has_memory_allocation_changed_callback_(false), | 81 client_has_memory_allocation_changed_callback_(false), |
64 last_flush_count_(0), | 82 last_flush_count_(0), |
65 parent_stub_for_initialization_(), | 83 parent_stub_for_initialization_(), |
66 parent_texture_for_initialization_(0), | 84 parent_texture_for_initialization_(0), |
67 watchdog_(watchdog), | 85 watchdog_(watchdog), |
68 sync_point_wait_count_(0) { | 86 sync_point_wait_count_(0), |
87 active_url_(active_url) { | |
88 active_url_hash_ = | |
89 base::hash<std::string>()(active_url.possibly_invalid_spec()); | |
69 if (share_group) { | 90 if (share_group) { |
70 context_group_ = share_group->context_group_; | 91 context_group_ = share_group->context_group_; |
71 } else { | 92 } else { |
72 context_group_ = new gpu::gles2::ContextGroup(mailbox_manager, true); | 93 context_group_ = new gpu::gles2::ContextGroup(mailbox_manager, true); |
73 } | 94 } |
74 if (surface_id != 0) | 95 if (surface_id != 0) |
75 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState( | 96 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState( |
76 surface_id, true, base::TimeTicks::Now())); | 97 surface_id, true, base::TimeTicks::Now())); |
77 if (handle_.sync_point) | 98 if (handle_.sync_point) |
78 OnWaitSyncPoint(handle_.sync_point); | 99 OnWaitSyncPoint(handle_.sync_point); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 if (CommandLine::ForCurrentProcess()->HasSwitch( | 359 if (CommandLine::ForCurrentProcess()->HasSwitch( |
339 switches::kEnableGPUServiceLogging)) { | 360 switches::kEnableGPUServiceLogging)) { |
340 decoder_->set_log_commands(true); | 361 decoder_->set_log_commands(true); |
341 } | 362 } |
342 | 363 |
343 decoder_->SetMsgCallback( | 364 decoder_->SetMsgCallback( |
344 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, | 365 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, |
345 base::Unretained(this))); | 366 base::Unretained(this))); |
346 | 367 |
347 command_buffer_->SetPutOffsetChangeCallback( | 368 command_buffer_->SetPutOffsetChangeCallback( |
348 base::Bind(&gpu::GpuScheduler::PutChanged, | 369 base::Bind(&GpuCommandBufferStub::PutChanged, base::Unretained(this))); |
349 base::Unretained(scheduler_.get()))); | |
350 command_buffer_->SetGetBufferChangeCallback( | 370 command_buffer_->SetGetBufferChangeCallback( |
351 base::Bind(&gpu::GpuScheduler::SetGetBuffer, | 371 base::Bind(&gpu::GpuScheduler::SetGetBuffer, |
352 base::Unretained(scheduler_.get()))); | 372 base::Unretained(scheduler_.get()))); |
353 command_buffer_->SetParseErrorCallback( | 373 command_buffer_->SetParseErrorCallback( |
354 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); | 374 base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); |
355 scheduler_->SetScheduledCallback( | 375 scheduler_->SetScheduledCallback( |
356 base::Bind(&GpuCommandBufferStub::OnReschedule, base::Unretained(this))); | 376 base::Bind(&GpuCommandBufferStub::OnReschedule, base::Unretained(this))); |
357 | 377 |
358 if (watchdog_) { | 378 if (watchdog_) { |
359 scheduler_->SetCommandProcessedCallback( | 379 scheduler_->SetCommandProcessedCallback( |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 void GpuCommandBufferStub::ReportState() { | 595 void GpuCommandBufferStub::ReportState() { |
576 gpu::CommandBuffer::State state = command_buffer_->GetState(); | 596 gpu::CommandBuffer::State state = command_buffer_->GetState(); |
577 if (state.error == gpu::error::kLostContext && | 597 if (state.error == gpu::error::kLostContext && |
578 gfx::GLContext::LosesAllContextsOnContextLost()) { | 598 gfx::GLContext::LosesAllContextsOnContextLost()) { |
579 channel_->LoseAllContexts(); | 599 channel_->LoseAllContexts(); |
580 } else { | 600 } else { |
581 command_buffer_->UpdateState(); | 601 command_buffer_->UpdateState(); |
582 } | 602 } |
583 } | 603 } |
584 | 604 |
605 void GpuCommandBufferStub::PutChanged() { | |
606 FastSetActiveURL(active_url_, active_url_hash_); | |
607 scheduler_->PutChanged(); | |
608 } | |
609 | |
585 void GpuCommandBufferStub::OnCreateVideoDecoder( | 610 void GpuCommandBufferStub::OnCreateVideoDecoder( |
586 media::VideoCodecProfile profile, | 611 media::VideoCodecProfile profile, |
587 IPC::Message* reply_message) { | 612 IPC::Message* reply_message) { |
588 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateVideoDecoder"); | 613 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateVideoDecoder"); |
589 int decoder_route_id = channel_->GenerateRouteID(); | 614 int decoder_route_id = channel_->GenerateRouteID(); |
590 GpuVideoDecodeAccelerator* decoder = | 615 GpuVideoDecodeAccelerator* decoder = |
591 new GpuVideoDecodeAccelerator(this, decoder_route_id, this); | 616 new GpuVideoDecodeAccelerator(this, decoder_route_id, this); |
592 video_decoders_.AddWithID(decoder, decoder_route_id); | 617 video_decoders_.AddWithID(decoder, decoder_route_id); |
593 channel_->AddRoute(decoder_route_id, decoder); | 618 channel_->AddRoute(decoder_route_id, decoder); |
594 decoder->Initialize(profile, reply_message); | 619 decoder->Initialize(profile, reply_message); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 const GpuMemoryAllocation& allocation) { | 764 const GpuMemoryAllocation& allocation) { |
740 Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation)); | 765 Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation)); |
741 // This can be called outside of OnMessageReceived, so the context needs to be | 766 // This can be called outside of OnMessageReceived, so the context needs to be |
742 // made current before calling methods on the surface. | 767 // made current before calling methods on the surface. |
743 if (!surface_ || !MakeCurrent()) | 768 if (!surface_ || !MakeCurrent()) |
744 return; | 769 return; |
745 surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer); | 770 surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer); |
746 } | 771 } |
747 | 772 |
748 #endif // defined(ENABLE_GPU) | 773 #endif // defined(ENABLE_GPU) |
OLD | NEW |