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/common/gpu/gpu_command_buffer_stub.h" | 5 #include "content/common/gpu/gpu_command_buffer_stub.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/hash.h" | 12 #include "base/hash.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "content/common/gpu/gpu_channel.h" | 19 #include "content/common/gpu/gpu_channel.h" |
20 #include "content/common/gpu/gpu_channel_manager.h" | 20 #include "content/common/gpu/gpu_channel_manager.h" |
21 #include "content/common/gpu/gpu_channel_manager_delegate.h" | |
21 #include "content/common/gpu/gpu_memory_manager.h" | 22 #include "content/common/gpu/gpu_memory_manager.h" |
22 #include "content/common/gpu/gpu_memory_tracking.h" | 23 #include "content/common/gpu/gpu_memory_tracking.h" |
23 #include "content/common/gpu/gpu_messages.h" | 24 #include "content/common/gpu/gpu_messages.h" |
24 #include "content/common/gpu/gpu_watchdog.h" | 25 #include "content/common/gpu/gpu_watchdog.h" |
25 #include "content/common/gpu/image_transport_surface.h" | 26 #include "content/common/gpu/image_transport_surface.h" |
26 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" | 27 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
27 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" | 28 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" |
28 #include "content/public/common/content_client.h" | 29 #include "content/public/common/content_client.h" |
Fady Samuel
2016/02/19 18:38:36
You can remove this include now, right?
Mark Dittmer
2016/02/20 00:55:20
Done.
| |
29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
30 #include "gpu/command_buffer/common/constants.h" | 31 #include "gpu/command_buffer/common/constants.h" |
31 #include "gpu/command_buffer/common/mailbox.h" | 32 #include "gpu/command_buffer/common/mailbox.h" |
32 #include "gpu/command_buffer/common/sync_token.h" | 33 #include "gpu/command_buffer/common/sync_token.h" |
33 #include "gpu/command_buffer/service/gl_context_virtual.h" | 34 #include "gpu/command_buffer/service/gl_context_virtual.h" |
34 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" | 35 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" |
35 #include "gpu/command_buffer/service/image_factory.h" | 36 #include "gpu/command_buffer/service/image_factory.h" |
36 #include "gpu/command_buffer/service/image_manager.h" | 37 #include "gpu/command_buffer/service/image_manager.h" |
37 #include "gpu/command_buffer/service/logger.h" | 38 #include "gpu/command_buffer/service/logger.h" |
38 #include "gpu/command_buffer/service/mailbox_manager.h" | 39 #include "gpu/command_buffer/service/mailbox_manager.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 private: | 99 private: |
99 ~GpuCommandBufferMemoryTracker() override {} | 100 ~GpuCommandBufferMemoryTracker() override {} |
100 scoped_ptr<GpuMemoryTrackingGroup> tracking_group_; | 101 scoped_ptr<GpuMemoryTrackingGroup> tracking_group_; |
101 const uint64_t client_tracing_id_; | 102 const uint64_t client_tracing_id_; |
102 const int client_id_; | 103 const int client_id_; |
103 const uint64_t share_group_tracing_guid_; | 104 const uint64_t share_group_tracing_guid_; |
104 | 105 |
105 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker); | 106 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker); |
106 }; | 107 }; |
107 | 108 |
108 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the | |
109 // url_hash matches. | |
110 void FastSetActiveURL(const GURL& url, size_t url_hash) { | |
111 // Leave the previously set URL in the empty case -- empty URLs are given by | |
112 // BlinkPlatformImpl::createOffscreenGraphicsContext3D. Hopefully the | |
113 // onscreen context URL was set previously and will show up even when a crash | |
114 // occurs during offscreen command processing. | |
115 if (url.is_empty()) | |
116 return; | |
117 static size_t g_last_url_hash = 0; | |
118 if (url_hash != g_last_url_hash) { | |
119 g_last_url_hash = url_hash; | |
120 GetContentClient()->SetActiveURL(url); | |
121 } | |
122 } | |
123 | |
124 // The first time polling a fence, delay some extra time to allow other | 109 // The first time polling a fence, delay some extra time to allow other |
125 // stubs to process some work, or else the timing of the fences could | 110 // stubs to process some work, or else the timing of the fences could |
126 // allow a pattern of alternating fast and slow frames to occur. | 111 // allow a pattern of alternating fast and slow frames to occur. |
127 const int64_t kHandleMoreWorkPeriodMs = 2; | 112 const int64_t kHandleMoreWorkPeriodMs = 2; |
128 const int64_t kHandleMoreWorkPeriodBusyMs = 1; | 113 const int64_t kHandleMoreWorkPeriodBusyMs = 1; |
129 | 114 |
130 // Prevents idle work from being starved. | 115 // Prevents idle work from being starved. |
131 const int64_t kMaxTimeSinceIdleMs = 10; | 116 const int64_t kMaxTimeSinceIdleMs = 10; |
132 | 117 |
133 class DevToolsChannelData : public base::trace_event::ConvertableToTraceFormat { | 118 class DevToolsChannelData : public base::trace_event::ConvertableToTraceFormat { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 gpu::gles2::SubscriptionRefSet* subscription_ref_set, | 172 gpu::gles2::SubscriptionRefSet* subscription_ref_set, |
188 gpu::ValueStateMap* pending_valuebuffer_state, | 173 gpu::ValueStateMap* pending_valuebuffer_state, |
189 const gfx::Size& size, | 174 const gfx::Size& size, |
190 const gpu::gles2::DisallowedFeatures& disallowed_features, | 175 const gpu::gles2::DisallowedFeatures& disallowed_features, |
191 const std::vector<int32_t>& attribs, | 176 const std::vector<int32_t>& attribs, |
192 gfx::GpuPreference gpu_preference, | 177 gfx::GpuPreference gpu_preference, |
193 int32_t stream_id, | 178 int32_t stream_id, |
194 int32_t route_id, | 179 int32_t route_id, |
195 bool offscreen, | 180 bool offscreen, |
196 GpuWatchdog* watchdog, | 181 GpuWatchdog* watchdog, |
197 const GURL& active_url) | 182 const std::string& active_url) |
198 : channel_(channel), | 183 : channel_(channel), |
199 sync_point_manager_(sync_point_manager), | 184 sync_point_manager_(sync_point_manager), |
200 task_runner_(task_runner), | 185 task_runner_(task_runner), |
201 initialized_(false), | 186 initialized_(false), |
202 handle_(handle), | 187 handle_(handle), |
203 initial_size_(size), | 188 initial_size_(size), |
204 disallowed_features_(disallowed_features), | 189 disallowed_features_(disallowed_features), |
205 requested_attribs_(attribs), | 190 requested_attribs_(attribs), |
206 gpu_preference_(gpu_preference), | 191 gpu_preference_(gpu_preference), |
207 use_virtualized_gl_context_(false), | 192 use_virtualized_gl_context_(false), |
208 command_buffer_id_(GetCommandBufferID(channel->client_id(), route_id)), | 193 command_buffer_id_(GetCommandBufferID(channel->client_id(), route_id)), |
209 stream_id_(stream_id), | 194 stream_id_(stream_id), |
210 route_id_(route_id), | 195 route_id_(route_id), |
211 offscreen_(offscreen), | 196 offscreen_(offscreen), |
212 last_flush_count_(0), | 197 last_flush_count_(0), |
213 surface_format_(gfx::GLSurface::SURFACE_DEFAULT), | 198 surface_format_(gfx::GLSurface::SURFACE_DEFAULT), |
214 watchdog_(watchdog), | 199 watchdog_(watchdog), |
215 waiting_for_sync_point_(false), | 200 waiting_for_sync_point_(false), |
216 previous_processed_num_(0), | 201 previous_processed_num_(0), |
217 preemption_flag_(preempt_by_flag), | 202 preemption_flag_(preempt_by_flag), |
218 active_url_(active_url) { | 203 active_url_(active_url) { |
219 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); | 204 active_url_hash_ = base::Hash(active_url); |
220 FastSetActiveURL(active_url_, active_url_hash_); | 205 FastSetActiveURL(active_url_, active_url_hash_); |
221 | 206 |
222 gpu::gles2::ContextCreationAttribHelper attrib_parser; | 207 gpu::gles2::ContextCreationAttribHelper attrib_parser; |
223 attrib_parser.Parse(requested_attribs_); | 208 attrib_parser.Parse(requested_attribs_); |
224 | 209 |
225 if (share_group) { | 210 if (share_group) { |
226 context_group_ = share_group->context_group_; | 211 context_group_ = share_group->context_group_; |
227 DCHECK(context_group_->bind_generates_resource() == | 212 DCHECK(context_group_->bind_generates_resource() == |
228 attrib_parser.bind_generates_resource); | 213 attrib_parser.bind_generates_resource); |
229 } else { | 214 } else { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 Send(wait_for_token_->reply.release()); | 449 Send(wait_for_token_->reply.release()); |
465 wait_for_token_.reset(); | 450 wait_for_token_.reset(); |
466 } | 451 } |
467 if (wait_for_get_offset_) { | 452 if (wait_for_get_offset_) { |
468 Send(wait_for_get_offset_->reply.release()); | 453 Send(wait_for_get_offset_->reply.release()); |
469 wait_for_get_offset_.reset(); | 454 wait_for_get_offset_.reset(); |
470 } | 455 } |
471 | 456 |
472 if (initialized_) { | 457 if (initialized_) { |
473 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 458 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
474 if (handle_.is_null() && !active_url_.is_empty()) { | 459 if (handle_.is_null() && !active_url_.empty()) { |
475 gpu_channel_manager->Send( | 460 gpu_channel_manager->Send( |
476 new GpuHostMsg_DidDestroyOffscreenContext(active_url_)); | 461 new GpuHostMsg_DidDestroyOffscreenContext(active_url_)); |
477 } | 462 } |
478 } | 463 } |
479 | 464 |
480 if (decoder_) | 465 if (decoder_) |
481 decoder_->set_engine(NULL); | 466 decoder_->set_engine(NULL); |
482 | 467 |
483 // The scheduler has raw references to the decoder and the command buffer so | 468 // The scheduler has raw references to the decoder and the command buffer so |
484 // destroy it before those. | 469 // destroy it before those. |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 } | 652 } |
668 command_buffer_->SetSharedStateBuffer(gpu::MakeBackingFromSharedMemory( | 653 command_buffer_->SetSharedStateBuffer(gpu::MakeBackingFromSharedMemory( |
669 std::move(shared_state_shm), kSharedStateSize)); | 654 std::move(shared_state_shm), kSharedStateSize)); |
670 | 655 |
671 gpu::Capabilities capabilities = decoder_->GetCapabilities(); | 656 gpu::Capabilities capabilities = decoder_->GetCapabilities(); |
672 | 657 |
673 GpuCommandBufferMsg_Initialize::WriteReplyParams( | 658 GpuCommandBufferMsg_Initialize::WriteReplyParams( |
674 reply_message, true, capabilities); | 659 reply_message, true, capabilities); |
675 Send(reply_message); | 660 Send(reply_message); |
676 | 661 |
677 if (handle_.is_null() && !active_url_.is_empty()) { | 662 if (handle_.is_null() && !active_url_.empty()) { |
678 manager->Send(new GpuHostMsg_DidCreateOffscreenContext( | 663 manager->Send(new GpuHostMsg_DidCreateOffscreenContext( |
679 active_url_)); | 664 active_url_)); |
680 } | 665 } |
681 | 666 |
682 initialized_ = true; | 667 initialized_ = true; |
683 } | 668 } |
684 | 669 |
685 void GpuCommandBufferStub::OnCreateStreamTexture(uint32_t texture_id, | 670 void GpuCommandBufferStub::OnCreateStreamTexture(uint32_t texture_id, |
686 int32_t stream_id, | 671 int32_t stream_id, |
687 bool* succeeded) { | 672 bool* succeeded) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 | 853 |
869 if (command_buffer_) | 854 if (command_buffer_) |
870 command_buffer_->DestroyTransferBuffer(id); | 855 command_buffer_->DestroyTransferBuffer(id); |
871 } | 856 } |
872 | 857 |
873 void GpuCommandBufferStub::OnCommandProcessed() { | 858 void GpuCommandBufferStub::OnCommandProcessed() { |
874 if (watchdog_) | 859 if (watchdog_) |
875 watchdog_->CheckArmed(); | 860 watchdog_->CheckArmed(); |
876 } | 861 } |
877 | 862 |
863 void GpuCommandBufferStub::FastSetActiveURL(const std::string& url, | |
864 size_t url_hash) { | |
865 // Leave the previously set URL in the empty case -- empty URLs are given by | |
866 // BlinkPlatformImpl::createOffscreenGraphicsContext3D. Hopefully the | |
867 // onscreen context URL was set previously and will show up even when a crash | |
868 // occurs during offscreen command processing. | |
869 if (url.empty()) | |
870 return; | |
871 static size_t g_last_url_hash = 0; | |
872 if (url_hash != g_last_url_hash) { | |
873 g_last_url_hash = url_hash; | |
874 // Plumb request through to a component that knows about the current active | |
875 // URLs. | |
876 channel_->gpu_channel_manager()->delegate()->SetActiveURL(url); | |
877 } | |
878 } | |
879 | |
878 void GpuCommandBufferStub::ReportState() { command_buffer_->UpdateState(); } | 880 void GpuCommandBufferStub::ReportState() { command_buffer_->UpdateState(); } |
879 | 881 |
880 void GpuCommandBufferStub::PutChanged() { | 882 void GpuCommandBufferStub::PutChanged() { |
881 FastSetActiveURL(active_url_, active_url_hash_); | 883 FastSetActiveURL(active_url_, active_url_hash_); |
882 scheduler_->PutChanged(); | 884 scheduler_->PutChanged(); |
883 } | 885 } |
884 | 886 |
885 void GpuCommandBufferStub::OnCreateVideoDecoder( | 887 void GpuCommandBufferStub::OnCreateVideoDecoder( |
886 const media::VideoDecodeAccelerator::Config& config, | 888 const media::VideoDecodeAccelerator::Config& config, |
887 int32_t decoder_route_id, | 889 int32_t decoder_route_id, |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1179 result)); | 1181 result)); |
1180 } | 1182 } |
1181 | 1183 |
1182 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, | 1184 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, |
1183 base::TimeDelta interval) { | 1185 base::TimeDelta interval) { |
1184 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, | 1186 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, |
1185 interval)); | 1187 interval)); |
1186 } | 1188 } |
1187 | 1189 |
1188 } // namespace content | 1190 } // namespace content |
OLD | NEW |