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 "gpu/ipc/service/gpu_command_buffer_stub.h" | 5 #include "gpu/ipc/service/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" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 base::Bind(&GpuCommandBufferMemoryTracker::LogMemoryStatsPressure, | 110 base::Bind(&GpuCommandBufferMemoryTracker::LogMemoryStatsPressure, |
111 base::Unretained(this)))) { | 111 base::Unretained(this)))) { |
112 // Set up |memory_stats_timer_| to call LogMemoryPeriodic periodically | 112 // Set up |memory_stats_timer_| to call LogMemoryPeriodic periodically |
113 // via the provided |task_runner|. | 113 // via the provided |task_runner|. |
114 memory_stats_timer_.SetTaskRunner(std::move(task_runner)); | 114 memory_stats_timer_.SetTaskRunner(std::move(task_runner)); |
115 memory_stats_timer_.Start( | 115 memory_stats_timer_.Start( |
116 FROM_HERE, base::TimeDelta::FromSeconds(30), this, | 116 FROM_HERE, base::TimeDelta::FromSeconds(30), this, |
117 &GpuCommandBufferMemoryTracker::LogMemoryStatsPeriodic); | 117 &GpuCommandBufferMemoryTracker::LogMemoryStatsPeriodic); |
118 } | 118 } |
119 | 119 |
120 void TrackMemoryAllocatedChange( | 120 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size) override { |
121 size_t old_size, size_t new_size) override { | 121 tracking_group_->TrackMemoryAllocatedChange(old_size, new_size); |
122 tracking_group_->TrackMemoryAllocatedChange( | |
123 old_size, new_size); | |
124 } | 122 } |
125 | 123 |
126 bool EnsureGPUMemoryAvailable(size_t size_needed) override { | 124 bool EnsureGPUMemoryAvailable(size_t size_needed) override { |
127 return tracking_group_->EnsureGPUMemoryAvailable(size_needed); | 125 return tracking_group_->EnsureGPUMemoryAvailable(size_needed); |
128 } | 126 } |
129 | 127 |
130 uint64_t ClientTracingId() const override { return client_tracing_id_; } | 128 uint64_t ClientTracingId() const override { return client_tracing_id_; } |
131 int ClientId() const override { return client_id_; } | 129 int ClientId() const override { return client_id_; } |
132 uint64_t ShareGroupTracingGUID() const override { | 130 uint64_t ShareGroupTracingGUID() const override { |
133 return share_group_tracing_guid_; | 131 return share_group_tracing_guid_; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 }; | 204 }; |
207 | 205 |
208 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 206 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
209 DevToolsChannelData::CreateForChannel(GpuChannel* channel) { | 207 DevToolsChannelData::CreateForChannel(GpuChannel* channel) { |
210 std::unique_ptr<base::DictionaryValue> res(new base::DictionaryValue); | 208 std::unique_ptr<base::DictionaryValue> res(new base::DictionaryValue); |
211 res->SetInteger("renderer_pid", channel->GetClientPID()); | 209 res->SetInteger("renderer_pid", channel->GetClientPID()); |
212 res->SetDouble("used_bytes", channel->GetMemoryUsage()); | 210 res->SetDouble("used_bytes", channel->GetMemoryUsage()); |
213 return base::WrapUnique(new DevToolsChannelData(res.release())); | 211 return base::WrapUnique(new DevToolsChannelData(res.release())); |
214 } | 212 } |
215 | 213 |
216 CommandBufferId GetCommandBufferID(int channel_id, int32_t route_id) { | |
217 return CommandBufferId::FromUnsafeValue( | |
218 (static_cast<uint64_t>(channel_id) << 32) | route_id); | |
219 } | |
220 | |
221 } // namespace | 214 } // namespace |
222 | 215 |
223 std::unique_ptr<GpuCommandBufferStub> GpuCommandBufferStub::Create( | 216 std::unique_ptr<GpuCommandBufferStub> GpuCommandBufferStub::Create( |
224 GpuChannel* channel, | 217 GpuChannel* channel, |
225 GpuCommandBufferStub* share_command_buffer_stub, | 218 GpuCommandBufferStub* share_command_buffer_stub, |
226 const GPUCreateCommandBufferConfig& init_params, | 219 const GPUCreateCommandBufferConfig& init_params, |
| 220 CommandBufferId command_buffer_id, |
| 221 SequenceId sequence_id, |
227 int32_t route_id, | 222 int32_t route_id, |
228 std::unique_ptr<base::SharedMemory> shared_state_shm) { | 223 std::unique_ptr<base::SharedMemory> shared_state_shm) { |
229 std::unique_ptr<GpuCommandBufferStub> stub( | 224 std::unique_ptr<GpuCommandBufferStub> stub(new GpuCommandBufferStub( |
230 new GpuCommandBufferStub(channel, init_params, route_id)); | 225 channel, init_params, command_buffer_id, sequence_id, route_id)); |
231 if (!stub->Initialize(share_command_buffer_stub, init_params, | 226 if (!stub->Initialize(share_command_buffer_stub, init_params, |
232 std::move(shared_state_shm))) | 227 std::move(shared_state_shm))) |
233 return nullptr; | 228 return nullptr; |
234 return stub; | 229 return stub; |
235 } | 230 } |
236 | 231 |
237 GpuCommandBufferStub::GpuCommandBufferStub( | 232 GpuCommandBufferStub::GpuCommandBufferStub( |
238 GpuChannel* channel, | 233 GpuChannel* channel, |
239 const GPUCreateCommandBufferConfig& init_params, | 234 const GPUCreateCommandBufferConfig& init_params, |
| 235 CommandBufferId command_buffer_id, |
| 236 SequenceId sequence_id, |
240 int32_t route_id) | 237 int32_t route_id) |
241 : channel_(channel), | 238 : channel_(channel), |
242 initialized_(false), | 239 initialized_(false), |
243 surface_handle_(init_params.surface_handle), | 240 surface_handle_(init_params.surface_handle), |
244 use_virtualized_gl_context_(false), | 241 use_virtualized_gl_context_(false), |
245 command_buffer_id_(GetCommandBufferID(channel->client_id(), route_id)), | 242 command_buffer_id_(command_buffer_id), |
246 stream_id_(init_params.stream_id), | 243 sequence_id_(sequence_id), |
247 route_id_(route_id), | 244 route_id_(route_id), |
248 last_flush_count_(0), | 245 last_flush_count_(0), |
249 waiting_for_sync_point_(false), | 246 waiting_for_sync_point_(false), |
250 previous_processed_num_(0), | 247 previous_processed_num_(0), |
251 active_url_(init_params.active_url), | 248 active_url_(init_params.active_url), |
252 active_url_hash_(base::Hash(active_url_.possibly_invalid_spec())) {} | 249 active_url_hash_(base::Hash(active_url_.possibly_invalid_spec())) {} |
253 | 250 |
254 GpuCommandBufferStub::~GpuCommandBufferStub() { | 251 GpuCommandBufferStub::~GpuCommandBufferStub() { |
255 Destroy(); | 252 Destroy(); |
256 } | 253 } |
257 | 254 |
258 GpuMemoryManager* GpuCommandBufferStub::GetMemoryManager() const { | 255 GpuMemoryManager* GpuCommandBufferStub::GetMemoryManager() const { |
259 return channel()->gpu_channel_manager()->gpu_memory_manager(); | 256 return channel()->gpu_channel_manager()->gpu_memory_manager(); |
260 } | 257 } |
261 | 258 |
262 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { | 259 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { |
263 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), | 260 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "GPUTask", |
264 "GPUTask", | 261 "data", DevToolsChannelData::CreateForChannel(channel())); |
265 "data", | |
266 DevToolsChannelData::CreateForChannel(channel())); | |
267 FastSetActiveURL(active_url_, active_url_hash_, channel_); | 262 FastSetActiveURL(active_url_, active_url_hash_, channel_); |
268 | 263 |
269 bool have_context = false; | 264 bool have_context = false; |
270 // Ensure the appropriate GL context is current before handling any IPC | 265 // Ensure the appropriate GL context is current before handling any IPC |
271 // messages directed at the command buffer. This ensures that the message | 266 // messages directed at the command buffer. This ensures that the message |
272 // handler can assume that the context is current (not necessary for | 267 // handler can assume that the context is current (not necessary for |
273 // RetireSyncPoint or WaitSyncPoint). | 268 // RetireSyncPoint or WaitSyncPoint). |
274 if (decoder_.get() && | 269 if (decoder_.get() && |
275 message.type() != GpuCommandBufferMsg_SetGetBuffer::ID && | 270 message.type() != GpuCommandBufferMsg_SetGetBuffer::ID && |
276 message.type() != GpuCommandBufferMsg_WaitForTokenInRange::ID && | 271 message.type() != GpuCommandBufferMsg_WaitForTokenInRange::ID && |
(...skipping 19 matching lines...) Expand all Loading... |
296 OnReturnFrontBuffer); | 291 OnReturnFrontBuffer); |
297 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_WaitForTokenInRange, | 292 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_WaitForTokenInRange, |
298 OnWaitForTokenInRange); | 293 OnWaitForTokenInRange); |
299 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_WaitForGetOffsetInRange, | 294 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_WaitForGetOffsetInRange, |
300 OnWaitForGetOffsetInRange); | 295 OnWaitForGetOffsetInRange); |
301 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); | 296 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); |
302 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RegisterTransferBuffer, | 297 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RegisterTransferBuffer, |
303 OnRegisterTransferBuffer); | 298 OnRegisterTransferBuffer); |
304 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer, | 299 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer, |
305 OnDestroyTransferBuffer); | 300 OnDestroyTransferBuffer); |
306 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_WaitSyncToken, | 301 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_WaitSyncToken, OnWaitSyncToken) |
307 OnWaitSyncToken) | 302 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncToken, OnSignalSyncToken) |
308 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncToken, | 303 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalQuery, OnSignalQuery) |
309 OnSignalSyncToken) | |
310 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalQuery, | |
311 OnSignalQuery) | |
312 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateImage, OnCreateImage); | 304 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateImage, OnCreateImage); |
313 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyImage, OnDestroyImage); | 305 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyImage, OnDestroyImage); |
314 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateStreamTexture, | 306 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateStreamTexture, |
315 OnCreateStreamTexture) | 307 OnCreateStreamTexture) |
316 IPC_MESSAGE_UNHANDLED(handled = false) | 308 IPC_MESSAGE_UNHANDLED(handled = false) |
317 IPC_END_MESSAGE_MAP() | 309 IPC_END_MESSAGE_MAP() |
318 | 310 |
319 CheckCompleteWaits(); | 311 CheckCompleteWaits(); |
320 | 312 |
321 // Ensure that any delayed work that was created will be handled. | 313 // Ensure that any delayed work that was created will be handled. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 399 |
408 void GpuCommandBufferStub::PerformWork() { | 400 void GpuCommandBufferStub::PerformWork() { |
409 TRACE_EVENT0("gpu", "GpuCommandBufferStub::PerformWork"); | 401 TRACE_EVENT0("gpu", "GpuCommandBufferStub::PerformWork"); |
410 | 402 |
411 FastSetActiveURL(active_url_, active_url_hash_, channel_); | 403 FastSetActiveURL(active_url_, active_url_hash_, channel_); |
412 if (decoder_.get() && !MakeCurrent()) | 404 if (decoder_.get() && !MakeCurrent()) |
413 return; | 405 return; |
414 | 406 |
415 if (executor_) { | 407 if (executor_) { |
416 uint32_t current_unprocessed_num = | 408 uint32_t current_unprocessed_num = |
417 channel()->gpu_channel_manager()->GetUnprocessedOrderNum(); | 409 channel()->sync_point_manager()->GetUnprocessedOrderNum(); |
418 // We're idle when no messages were processed or scheduled. | 410 // We're idle when no messages were processed or scheduled. |
419 bool is_idle = (previous_processed_num_ == current_unprocessed_num); | 411 bool is_idle = (previous_processed_num_ == current_unprocessed_num); |
420 if (!is_idle && !last_idle_time_.is_null()) { | 412 if (!is_idle && !last_idle_time_.is_null()) { |
421 base::TimeDelta time_since_idle = | 413 base::TimeDelta time_since_idle = |
422 base::TimeTicks::Now() - last_idle_time_; | 414 base::TimeTicks::Now() - last_idle_time_; |
423 base::TimeDelta max_time_since_idle = | 415 base::TimeDelta max_time_since_idle = |
424 base::TimeDelta::FromMilliseconds(kMaxTimeSinceIdleMs); | 416 base::TimeDelta::FromMilliseconds(kMaxTimeSinceIdleMs); |
425 | 417 |
426 // Force idle when it's been too long since last time we were idle. | 418 // Force idle when it's been too long since last time we were idle. |
427 if (time_since_idle > max_time_since_idle) | 419 if (time_since_idle > max_time_since_idle) |
(...skipping 10 matching lines...) Expand all Loading... |
438 } | 430 } |
439 | 431 |
440 ScheduleDelayedWork( | 432 ScheduleDelayedWork( |
441 base::TimeDelta::FromMilliseconds(kHandleMoreWorkPeriodBusyMs)); | 433 base::TimeDelta::FromMilliseconds(kHandleMoreWorkPeriodBusyMs)); |
442 } | 434 } |
443 | 435 |
444 bool GpuCommandBufferStub::HasUnprocessedCommands() { | 436 bool GpuCommandBufferStub::HasUnprocessedCommands() { |
445 if (command_buffer_) { | 437 if (command_buffer_) { |
446 CommandBuffer::State state = command_buffer_->GetLastState(); | 438 CommandBuffer::State state = command_buffer_->GetLastState(); |
447 return command_buffer_->GetPutOffset() != state.get_offset && | 439 return command_buffer_->GetPutOffset() != state.get_offset && |
448 !error::IsError(state.error); | 440 !error::IsError(state.error); |
449 } | 441 } |
450 return false; | 442 return false; |
451 } | 443 } |
452 | 444 |
453 void GpuCommandBufferStub::ScheduleDelayedWork(base::TimeDelta delay) { | 445 void GpuCommandBufferStub::ScheduleDelayedWork(base::TimeDelta delay) { |
454 bool has_more_work = executor_.get() && (executor_->HasPendingQueries() || | 446 bool has_more_work = executor_.get() && (executor_->HasPendingQueries() || |
455 executor_->HasMoreIdleWork() || | 447 executor_->HasMoreIdleWork() || |
456 executor_->HasPollingWork()); | 448 executor_->HasPollingWork()); |
457 if (!has_more_work) { | 449 if (!has_more_work) { |
458 last_idle_time_ = base::TimeTicks(); | 450 last_idle_time_ = base::TimeTicks(); |
459 return; | 451 return; |
460 } | 452 } |
461 | 453 |
462 base::TimeTicks current_time = base::TimeTicks::Now(); | 454 base::TimeTicks current_time = base::TimeTicks::Now(); |
463 // |process_delayed_work_time_| is set if processing of delayed work is | 455 // |process_delayed_work_time_| is set if processing of delayed work is |
464 // already scheduled. Just update the time if already scheduled. | 456 // already scheduled. Just update the time if already scheduled. |
465 if (!process_delayed_work_time_.is_null()) { | 457 if (!process_delayed_work_time_.is_null()) { |
466 process_delayed_work_time_ = current_time + delay; | 458 process_delayed_work_time_ = current_time + delay; |
467 return; | 459 return; |
468 } | 460 } |
469 | 461 |
470 // Idle when no messages are processed between now and when | 462 // Idle when no messages are processed between now and when |
471 // PollWork is called. | 463 // PollWork is called. |
472 previous_processed_num_ = | 464 previous_processed_num_ = |
473 channel()->gpu_channel_manager()->GetProcessedOrderNum(); | 465 channel()->sync_point_manager()->GetProcessedOrderNum(); |
474 if (last_idle_time_.is_null()) | 466 if (last_idle_time_.is_null()) |
475 last_idle_time_ = current_time; | 467 last_idle_time_ = current_time; |
476 | 468 |
477 // IsScheduled() returns true after passing all unschedule fences | 469 // IsScheduled() returns true after passing all unschedule fences |
478 // and this is when we can start performing idle work. Idle work | 470 // and this is when we can start performing idle work. Idle work |
479 // is done synchronously so we can set delay to 0 and instead poll | 471 // is done synchronously so we can set delay to 0 and instead poll |
480 // for more work at the rate idle work is performed. This also ensures | 472 // for more work at the rate idle work is performed. This also ensures |
481 // that idle work is done as efficiently as possible without any | 473 // that idle work is done as efficiently as possible without any |
482 // unnecessary delays. | 474 // unnecessary delays. |
483 if (executor_.get() && executor_->scheduled() && | 475 if (executor_.get() && executor_->scheduled() && |
(...skipping 26 matching lines...) Expand all Loading... |
510 Send(wait_for_get_offset_->reply.release()); | 502 Send(wait_for_get_offset_->reply.release()); |
511 wait_for_get_offset_.reset(); | 503 wait_for_get_offset_.reset(); |
512 } | 504 } |
513 | 505 |
514 if (initialized_) { | 506 if (initialized_) { |
515 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 507 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
516 // If we are currently shutting down the GPU process to help with recovery | 508 // If we are currently shutting down the GPU process to help with recovery |
517 // (exit_on_context_lost workaround), then don't tell the browser about | 509 // (exit_on_context_lost workaround), then don't tell the browser about |
518 // offscreen context destruction here since it's not client-invoked, and | 510 // offscreen context destruction here since it's not client-invoked, and |
519 // might bypass the 3D API blocking logic. | 511 // might bypass the 3D API blocking logic. |
520 if ((surface_handle_ == gpu::kNullSurfaceHandle) && !active_url_.is_empty() | 512 if ((surface_handle_ == gpu::kNullSurfaceHandle) && |
521 && !gpu_channel_manager->is_exiting_for_lost_context()) { | 513 !active_url_.is_empty() && |
| 514 !gpu_channel_manager->is_exiting_for_lost_context()) { |
522 gpu_channel_manager->delegate()->DidDestroyOffscreenContext(active_url_); | 515 gpu_channel_manager->delegate()->DidDestroyOffscreenContext(active_url_); |
523 } | 516 } |
524 } | 517 } |
525 | 518 |
526 if (decoder_) | 519 if (decoder_) |
527 decoder_->set_engine(NULL); | 520 decoder_->set_engine(NULL); |
528 | 521 |
529 // The scheduler has raw references to the decoder and the command buffer so | 522 // The scheduler has raw references to the decoder and the command buffer so |
530 // destroy it before those. | 523 // destroy it before those. |
531 executor_.reset(); | 524 executor_.reset(); |
532 | 525 |
533 sync_point_client_.reset(); | 526 if (sync_point_client_state_) { |
| 527 sync_point_client_state_->Destroy(); |
| 528 sync_point_client_state_ = nullptr; |
| 529 } |
534 | 530 |
535 bool have_context = false; | 531 bool have_context = false; |
536 if (decoder_ && decoder_->GetGLContext()) { | 532 if (decoder_ && decoder_->GetGLContext()) { |
537 // Try to make the context current regardless of whether it was lost, so we | 533 // Try to make the context current regardless of whether it was lost, so we |
538 // don't leak resources. | 534 // don't leak resources. |
539 have_context = decoder_->GetGLContext()->MakeCurrent(surface_.get()); | 535 have_context = decoder_->GetGLContext()->MakeCurrent(surface_.get()); |
540 } | 536 } |
541 for (auto& observer : destruction_observers_) | 537 for (auto& observer : destruction_observers_) |
542 observer.OnWillDestroyStub(); | 538 observer.OnWillDestroyStub(); |
543 | 539 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 } | 628 } |
633 | 629 |
634 // We can only use virtualized contexts for onscreen command buffers if their | 630 // We can only use virtualized contexts for onscreen command buffers if their |
635 // config is compatible with the offscreen ones - otherwise MakeCurrent fails. | 631 // config is compatible with the offscreen ones - otherwise MakeCurrent fails. |
636 // Example use case is a client requesting an onscreen RGBA8888 buffer for | 632 // Example use case is a client requesting an onscreen RGBA8888 buffer for |
637 // fullscreen video on a low-spec device with RGB565 default format. | 633 // fullscreen video on a low-spec device with RGB565 default format. |
638 if (!surface_format.IsCompatible(default_surface->GetFormat()) && !offscreen) | 634 if (!surface_format.IsCompatible(default_surface->GetFormat()) && !offscreen) |
639 use_virtualized_gl_context_ = false; | 635 use_virtualized_gl_context_ = false; |
640 #endif | 636 #endif |
641 | 637 |
642 command_buffer_.reset(new CommandBufferService( | 638 command_buffer_.reset( |
643 context_group_->transfer_buffer_manager())); | 639 new CommandBufferService(context_group_->transfer_buffer_manager())); |
644 | 640 |
645 decoder_.reset(gles2::GLES2Decoder::Create(context_group_.get())); | 641 decoder_.reset(gles2::GLES2Decoder::Create(context_group_.get())); |
646 executor_.reset(new CommandExecutor(command_buffer_.get(), decoder_.get(), | 642 executor_.reset(new CommandExecutor(command_buffer_.get(), decoder_.get(), |
647 decoder_.get())); | 643 decoder_.get())); |
648 sync_point_client_ = base::MakeUnique<SyncPointClient>( | 644 |
649 channel_->sync_point_manager(), | 645 sync_point_client_state_ = |
650 channel_->GetSyncPointOrderData(stream_id_), | 646 channel_->sync_point_manager()->CreateSyncPointClientState( |
651 CommandBufferNamespace::GPU_IO, command_buffer_id_); | 647 CommandBufferNamespace::GPU_IO, command_buffer_id_, sequence_id_); |
652 | 648 |
653 executor_->SetPreemptByFlag(channel_->preempted_flag()); | 649 executor_->SetPreemptByFlag(channel_->preempted_flag()); |
654 | 650 |
655 decoder_->set_engine(executor_.get()); | 651 decoder_->set_engine(executor_.get()); |
656 | 652 |
657 if (offscreen) { | 653 if (offscreen) { |
658 if (init_params.attribs.depth_size > 0) { | 654 if (init_params.attribs.depth_size > 0) { |
659 surface_format.SetDepthBits(init_params.attribs.depth_size); | 655 surface_format.SetDepthBits(init_params.attribs.depth_size); |
660 } | 656 } |
661 if (init_params.attribs.samples > 0) { | 657 if (init_params.attribs.samples > 0) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 DLOG(ERROR) << "Failed to create context."; | 747 DLOG(ERROR) << "Failed to create context."; |
752 return false; | 748 return false; |
753 } | 749 } |
754 | 750 |
755 if (!context->MakeCurrent(surface_.get())) { | 751 if (!context->MakeCurrent(surface_.get())) { |
756 LOG(ERROR) << "Failed to make context current."; | 752 LOG(ERROR) << "Failed to make context current."; |
757 return false; | 753 return false; |
758 } | 754 } |
759 | 755 |
760 if (!context->GetGLStateRestorer()) { | 756 if (!context->GetGLStateRestorer()) { |
761 context->SetGLStateRestorer( | 757 context->SetGLStateRestorer(new GLStateRestorerImpl(decoder_->AsWeakPtr())); |
762 new GLStateRestorerImpl(decoder_->AsWeakPtr())); | |
763 } | 758 } |
764 | 759 |
765 if (!context_group_->has_program_cache() && | 760 if (!context_group_->has_program_cache() && |
766 !context_group_->feature_info()->workarounds().disable_program_cache) { | 761 !context_group_->feature_info()->workarounds().disable_program_cache) { |
767 context_group_->set_program_cache(manager->program_cache()); | 762 context_group_->set_program_cache(manager->program_cache()); |
768 } | 763 } |
769 | 764 |
770 // Initialize the decoder with either the view or pbuffer GLContext. | 765 // Initialize the decoder with either the view or pbuffer GLContext. |
771 if (!decoder_->Initialize(surface_, context, offscreen, | 766 if (!decoder_->Initialize(surface_, context, offscreen, |
772 gpu::gles2::DisallowedFeatures(), | 767 gpu::gles2::DisallowedFeatures(), |
773 init_params.attribs)) { | 768 init_params.attribs)) { |
774 DLOG(ERROR) << "Failed to initialize decoder."; | 769 DLOG(ERROR) << "Failed to initialize decoder."; |
775 return false; | 770 return false; |
776 } | 771 } |
777 | 772 |
778 if (manager->gpu_preferences().enable_gpu_service_logging) { | 773 if (manager->gpu_preferences().enable_gpu_service_logging) { |
779 decoder_->set_log_commands(true); | 774 decoder_->set_log_commands(true); |
780 } | 775 } |
781 | 776 |
782 decoder_->GetLogger()->SetMsgCallback( | 777 decoder_->GetLogger()->SetMsgCallback(base::Bind( |
783 base::Bind(&GpuCommandBufferStub::SendConsoleMessage, | 778 &GpuCommandBufferStub::SendConsoleMessage, base::Unretained(this))); |
784 base::Unretained(this))); | 779 decoder_->SetShaderCacheCallback(base::Bind( |
785 decoder_->SetShaderCacheCallback( | 780 &GpuCommandBufferStub::SendCachedShader, base::Unretained(this))); |
786 base::Bind(&GpuCommandBufferStub::SendCachedShader, | |
787 base::Unretained(this))); | |
788 decoder_->SetFenceSyncReleaseCallback(base::Bind( | 781 decoder_->SetFenceSyncReleaseCallback(base::Bind( |
789 &GpuCommandBufferStub::OnFenceSyncRelease, base::Unretained(this))); | 782 &GpuCommandBufferStub::OnFenceSyncRelease, base::Unretained(this))); |
790 decoder_->SetWaitSyncTokenCallback(base::Bind( | 783 decoder_->SetWaitSyncTokenCallback(base::Bind( |
791 &GpuCommandBufferStub::OnWaitSyncToken, base::Unretained(this))); | 784 &GpuCommandBufferStub::OnWaitSyncToken, base::Unretained(this))); |
792 decoder_->SetDescheduleUntilFinishedCallback( | 785 decoder_->SetDescheduleUntilFinishedCallback( |
793 base::Bind(&GpuCommandBufferStub::OnDescheduleUntilFinished, | 786 base::Bind(&GpuCommandBufferStub::OnDescheduleUntilFinished, |
794 base::Unretained(this))); | 787 base::Unretained(this))); |
795 decoder_->SetRescheduleAfterFinishedCallback( | 788 decoder_->SetRescheduleAfterFinishedCallback( |
796 base::Bind(&GpuCommandBufferStub::OnRescheduleAfterFinished, | 789 base::Bind(&GpuCommandBufferStub::OnRescheduleAfterFinished, |
797 base::Unretained(this))); | 790 base::Unretained(this))); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 } | 895 } |
903 wait_for_get_offset_ = | 896 wait_for_get_offset_ = |
904 base::MakeUnique<WaitForCommandState>(start, end, reply_message); | 897 base::MakeUnique<WaitForCommandState>(start, end, reply_message); |
905 CheckCompleteWaits(); | 898 CheckCompleteWaits(); |
906 } | 899 } |
907 | 900 |
908 void GpuCommandBufferStub::CheckCompleteWaits() { | 901 void GpuCommandBufferStub::CheckCompleteWaits() { |
909 if (wait_for_token_ || wait_for_get_offset_) { | 902 if (wait_for_token_ || wait_for_get_offset_) { |
910 CommandBuffer::State state = command_buffer_->GetLastState(); | 903 CommandBuffer::State state = command_buffer_->GetLastState(); |
911 if (wait_for_token_ && | 904 if (wait_for_token_ && |
912 (CommandBuffer::InRange( | 905 (CommandBuffer::InRange(wait_for_token_->start, wait_for_token_->end, |
913 wait_for_token_->start, wait_for_token_->end, state.token) || | 906 state.token) || |
914 state.error != error::kNoError)) { | 907 state.error != error::kNoError)) { |
915 ReportState(); | 908 ReportState(); |
916 GpuCommandBufferMsg_WaitForTokenInRange::WriteReplyParams( | 909 GpuCommandBufferMsg_WaitForTokenInRange::WriteReplyParams( |
917 wait_for_token_->reply.get(), state); | 910 wait_for_token_->reply.get(), state); |
918 Send(wait_for_token_->reply.release()); | 911 Send(wait_for_token_->reply.release()); |
919 wait_for_token_.reset(); | 912 wait_for_token_.reset(); |
920 } | 913 } |
921 if (wait_for_get_offset_ && | 914 if (wait_for_get_offset_ && |
922 (CommandBuffer::InRange(wait_for_get_offset_->start, | 915 (CommandBuffer::InRange(wait_for_get_offset_->start, |
923 wait_for_get_offset_->end, | 916 wait_for_get_offset_->end, state.get_offset) || |
924 state.get_offset) || | |
925 state.error != error::kNoError)) { | 917 state.error != error::kNoError)) { |
926 ReportState(); | 918 ReportState(); |
927 GpuCommandBufferMsg_WaitForGetOffsetInRange::WriteReplyParams( | 919 GpuCommandBufferMsg_WaitForGetOffsetInRange::WriteReplyParams( |
928 wait_for_get_offset_->reply.get(), state); | 920 wait_for_get_offset_->reply.get(), state); |
929 Send(wait_for_get_offset_->reply.release()); | 921 Send(wait_for_get_offset_->reply.release()); |
930 wait_for_get_offset_.reset(); | 922 wait_for_get_offset_.reset(); |
931 } | 923 } |
932 } | 924 } |
933 } | 925 } |
934 | 926 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 | 985 |
994 if (command_buffer_) | 986 if (command_buffer_) |
995 command_buffer_->DestroyTransferBuffer(id); | 987 command_buffer_->DestroyTransferBuffer(id); |
996 } | 988 } |
997 | 989 |
998 void GpuCommandBufferStub::OnCommandProcessed() { | 990 void GpuCommandBufferStub::OnCommandProcessed() { |
999 DCHECK(channel_->watchdog()); | 991 DCHECK(channel_->watchdog()); |
1000 channel_->watchdog()->CheckArmed(); | 992 channel_->watchdog()->CheckArmed(); |
1001 } | 993 } |
1002 | 994 |
1003 void GpuCommandBufferStub::ReportState() { command_buffer_->UpdateState(); } | 995 void GpuCommandBufferStub::ReportState() { |
| 996 command_buffer_->UpdateState(); |
| 997 } |
1004 | 998 |
1005 void GpuCommandBufferStub::PutChanged() { | 999 void GpuCommandBufferStub::PutChanged() { |
1006 FastSetActiveURL(active_url_, active_url_hash_, channel_); | 1000 FastSetActiveURL(active_url_, active_url_hash_, channel_); |
1007 executor_->PutChanged(); | 1001 executor_->PutChanged(); |
1008 } | 1002 } |
1009 | 1003 |
1010 void GpuCommandBufferStub::OnSignalSyncToken(const SyncToken& sync_token, | 1004 void GpuCommandBufferStub::OnSignalSyncToken(const SyncToken& sync_token, |
1011 uint32_t id) { | 1005 uint32_t id) { |
1012 if (!sync_point_client_->WaitNonThreadSafe( | 1006 if (!sync_point_client_state_->WaitNonThreadSafe( |
1013 sync_token, channel_->task_runner(), | 1007 sync_token, channel_->task_runner(), |
1014 base::Bind(&GpuCommandBufferStub::OnSignalAck, this->AsWeakPtr(), | 1008 base::Bind(&GpuCommandBufferStub::OnSignalAck, this->AsWeakPtr(), |
1015 id))) { | 1009 id))) { |
1016 OnSignalAck(id); | 1010 OnSignalAck(id); |
1017 } | 1011 } |
1018 } | 1012 } |
1019 | 1013 |
1020 void GpuCommandBufferStub::OnSignalAck(uint32_t id) { | 1014 void GpuCommandBufferStub::OnSignalAck(uint32_t id) { |
1021 Send(new GpuCommandBufferMsg_SignalAck(route_id_, id)); | 1015 Send(new GpuCommandBufferMsg_SignalAck(route_id_, id)); |
1022 } | 1016 } |
1023 | 1017 |
1024 void GpuCommandBufferStub::OnSignalQuery(uint32_t query_id, uint32_t id) { | 1018 void GpuCommandBufferStub::OnSignalQuery(uint32_t query_id, uint32_t id) { |
1025 if (decoder_) { | 1019 if (decoder_) { |
1026 gles2::QueryManager* query_manager = decoder_->GetQueryManager(); | 1020 gles2::QueryManager* query_manager = decoder_->GetQueryManager(); |
1027 if (query_manager) { | 1021 if (query_manager) { |
1028 gles2::QueryManager::Query* query = | 1022 gles2::QueryManager::Query* query = query_manager->GetQuery(query_id); |
1029 query_manager->GetQuery(query_id); | |
1030 if (query) { | 1023 if (query) { |
1031 query->AddCallback( | 1024 query->AddCallback(base::Bind(&GpuCommandBufferStub::OnSignalAck, |
1032 base::Bind(&GpuCommandBufferStub::OnSignalAck, | 1025 this->AsWeakPtr(), id)); |
1033 this->AsWeakPtr(), | |
1034 id)); | |
1035 return; | 1026 return; |
1036 } | 1027 } |
1037 } | 1028 } |
1038 } | 1029 } |
1039 // Something went wrong, run callback immediately. | 1030 // Something went wrong, run callback immediately. |
1040 OnSignalAck(id); | 1031 OnSignalAck(id); |
1041 } | 1032 } |
1042 | 1033 |
1043 void GpuCommandBufferStub::OnFenceSyncRelease(uint64_t release) { | 1034 void GpuCommandBufferStub::OnFenceSyncRelease(uint64_t release) { |
1044 SyncToken sync_token(CommandBufferNamespace::GPU_IO, 0, command_buffer_id_, | 1035 SyncToken sync_token(CommandBufferNamespace::GPU_IO, 0, command_buffer_id_, |
1045 release); | 1036 release); |
1046 gles2::MailboxManager* mailbox_manager = context_group_->mailbox_manager(); | 1037 gles2::MailboxManager* mailbox_manager = context_group_->mailbox_manager(); |
1047 if (mailbox_manager->UsesSync() && MakeCurrent()) | 1038 if (mailbox_manager->UsesSync() && MakeCurrent()) |
1048 mailbox_manager->PushTextureUpdates(sync_token); | 1039 mailbox_manager->PushTextureUpdates(sync_token); |
1049 | 1040 |
1050 command_buffer_->SetReleaseCount(release); | 1041 command_buffer_->SetReleaseCount(release); |
1051 sync_point_client_->ReleaseFenceSync(release); | 1042 sync_point_client_state_->ReleaseFenceSync(release); |
1052 } | 1043 } |
1053 | 1044 |
1054 void GpuCommandBufferStub::OnDescheduleUntilFinished() { | 1045 void GpuCommandBufferStub::OnDescheduleUntilFinished() { |
1055 DCHECK(executor_->scheduled()); | 1046 DCHECK(executor_->scheduled()); |
1056 DCHECK(executor_->HasPollingWork()); | 1047 DCHECK(executor_->HasPollingWork()); |
1057 | 1048 |
1058 executor_->SetScheduled(false); | 1049 executor_->SetScheduled(false); |
1059 channel_->OnStreamRescheduled(stream_id_, false); | 1050 channel_->OnCommandBufferDescheduled(this); |
1060 } | 1051 } |
1061 | 1052 |
1062 void GpuCommandBufferStub::OnRescheduleAfterFinished() { | 1053 void GpuCommandBufferStub::OnRescheduleAfterFinished() { |
1063 DCHECK(!executor_->scheduled()); | 1054 DCHECK(!executor_->scheduled()); |
1064 | 1055 |
1065 executor_->SetScheduled(true); | 1056 executor_->SetScheduled(true); |
1066 channel_->OnStreamRescheduled(stream_id_, true); | 1057 channel_->OnCommandBufferScheduled(this); |
1067 } | 1058 } |
1068 | 1059 |
1069 bool GpuCommandBufferStub::OnWaitSyncToken(const SyncToken& sync_token) { | 1060 bool GpuCommandBufferStub::OnWaitSyncToken(const SyncToken& sync_token) { |
1070 DCHECK(!waiting_for_sync_point_); | 1061 DCHECK(!waiting_for_sync_point_); |
1071 DCHECK(executor_->scheduled()); | 1062 DCHECK(executor_->scheduled()); |
1072 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitSyncToken", this, "GpuCommandBufferStub", | 1063 TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitSyncToken", this, "GpuCommandBufferStub", |
1073 this); | 1064 this); |
1074 | 1065 |
1075 waiting_for_sync_point_ = sync_point_client_->WaitNonThreadSafe( | 1066 waiting_for_sync_point_ = sync_point_client_state_->WaitNonThreadSafe( |
1076 sync_token, channel_->task_runner(), | 1067 sync_token, channel_->task_runner(), |
1077 base::Bind(&GpuCommandBufferStub::OnWaitSyncTokenCompleted, AsWeakPtr(), | 1068 base::Bind(&GpuCommandBufferStub::OnWaitSyncTokenCompleted, AsWeakPtr(), |
1078 sync_token)); | 1069 sync_token)); |
1079 | 1070 |
1080 if (waiting_for_sync_point_) { | 1071 if (waiting_for_sync_point_) { |
1081 executor_->SetScheduled(false); | 1072 executor_->SetScheduled(false); |
1082 channel_->OnStreamRescheduled(stream_id_, false); | 1073 channel_->OnCommandBufferDescheduled(this); |
1083 return true; | 1074 return true; |
1084 } | 1075 } |
1085 | 1076 |
1086 gles2::MailboxManager* mailbox_manager = context_group_->mailbox_manager(); | 1077 gles2::MailboxManager* mailbox_manager = context_group_->mailbox_manager(); |
1087 if (mailbox_manager->UsesSync() && MakeCurrent()) | 1078 if (mailbox_manager->UsesSync() && MakeCurrent()) |
1088 mailbox_manager->PullTextureUpdates(sync_token); | 1079 mailbox_manager->PullTextureUpdates(sync_token); |
1089 return false; | 1080 return false; |
1090 } | 1081 } |
1091 | 1082 |
1092 void GpuCommandBufferStub::OnWaitSyncTokenCompleted( | 1083 void GpuCommandBufferStub::OnWaitSyncTokenCompleted( |
1093 const SyncToken& sync_token) { | 1084 const SyncToken& sync_token) { |
1094 DCHECK(waiting_for_sync_point_); | 1085 DCHECK(waiting_for_sync_point_); |
1095 TRACE_EVENT_ASYNC_END1("gpu", "WaitSyncTokenCompleted", this, | 1086 TRACE_EVENT_ASYNC_END1("gpu", "WaitSyncTokenCompleted", this, |
1096 "GpuCommandBufferStub", this); | 1087 "GpuCommandBufferStub", this); |
1097 // Don't call PullTextureUpdates here because we can't MakeCurrent if we're | 1088 // Don't call PullTextureUpdates here because we can't MakeCurrent if we're |
1098 // executing commands on another context. The WaitSyncToken command will run | 1089 // executing commands on another context. The WaitSyncToken command will run |
1099 // again and call PullTextureUpdates once this command buffer gets scheduled. | 1090 // again and call PullTextureUpdates once this command buffer gets scheduled. |
1100 waiting_for_sync_point_ = false; | 1091 waiting_for_sync_point_ = false; |
1101 executor_->SetScheduled(true); | 1092 executor_->SetScheduled(true); |
1102 channel_->OnStreamRescheduled(stream_id_, true); | 1093 channel_->OnCommandBufferScheduled(this); |
1103 } | 1094 } |
1104 | 1095 |
1105 void GpuCommandBufferStub::OnCreateImage( | 1096 void GpuCommandBufferStub::OnCreateImage( |
1106 const GpuCommandBufferMsg_CreateImage_Params& params) { | 1097 const GpuCommandBufferMsg_CreateImage_Params& params) { |
1107 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateImage"); | 1098 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateImage"); |
1108 const int32_t id = params.id; | 1099 const int32_t id = params.id; |
1109 const gfx::GpuMemoryBufferHandle& handle = params.gpu_memory_buffer; | 1100 const gfx::GpuMemoryBufferHandle& handle = params.gpu_memory_buffer; |
1110 const gfx::Size& size = params.size; | 1101 const gfx::Size& size = params.size; |
1111 const gfx::BufferFormat& format = params.format; | 1102 const gfx::BufferFormat& format = params.format; |
1112 const uint32_t internalformat = params.internal_format; | 1103 const uint32_t internalformat = params.internal_format; |
(...skipping 26 matching lines...) Expand all Loading... |
1139 return; | 1130 return; |
1140 } | 1131 } |
1141 | 1132 |
1142 scoped_refptr<gl::GLImage> image = channel()->CreateImageForGpuMemoryBuffer( | 1133 scoped_refptr<gl::GLImage> image = channel()->CreateImageForGpuMemoryBuffer( |
1143 handle, size, format, internalformat, surface_handle_); | 1134 handle, size, format, internalformat, surface_handle_); |
1144 if (!image.get()) | 1135 if (!image.get()) |
1145 return; | 1136 return; |
1146 | 1137 |
1147 image_manager->AddImage(image.get(), id); | 1138 image_manager->AddImage(image.get(), id); |
1148 if (image_release_count) | 1139 if (image_release_count) |
1149 sync_point_client_->ReleaseFenceSync(image_release_count); | 1140 sync_point_client_state_->ReleaseFenceSync(image_release_count); |
1150 } | 1141 } |
1151 | 1142 |
1152 void GpuCommandBufferStub::OnDestroyImage(int32_t id) { | 1143 void GpuCommandBufferStub::OnDestroyImage(int32_t id) { |
1153 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyImage"); | 1144 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyImage"); |
1154 | 1145 |
1155 if (!decoder_) | 1146 if (!decoder_) |
1156 return; | 1147 return; |
1157 | 1148 |
1158 gles2::ImageManager* image_manager = decoder_->GetImageManager(); | 1149 gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
1159 DCHECK(image_manager); | 1150 DCHECK(image_manager); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 command_buffer_->GetLastState().error == error::kLostContext) | 1219 command_buffer_->GetLastState().error == error::kLostContext) |
1229 return; | 1220 return; |
1230 | 1221 |
1231 command_buffer_->SetContextLostReason(error::kUnknown); | 1222 command_buffer_->SetContextLostReason(error::kUnknown); |
1232 if (decoder_) | 1223 if (decoder_) |
1233 decoder_->MarkContextLost(error::kUnknown); | 1224 decoder_->MarkContextLost(error::kUnknown); |
1234 command_buffer_->SetParseError(error::kLostContext); | 1225 command_buffer_->SetParseError(error::kLostContext); |
1235 } | 1226 } |
1236 | 1227 |
1237 } // namespace gpu | 1228 } // namespace gpu |
OLD | NEW |