Chromium Code Reviews| 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 "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "content/common/gpu/gpu_channel.h" | 14 #include "content/common/gpu/gpu_channel.h" |
| 14 #include "content/common/gpu/gpu_channel_manager.h" | 15 #include "content/common/gpu/gpu_channel_manager.h" |
| 15 #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_allocation.h" | |
| 18 #include "content/common/gpu/gpu_memory_manager.h" | |
| 16 #include "content/common/gpu/gpu_messages.h" | 19 #include "content/common/gpu/gpu_messages.h" |
| 17 #include "content/common/gpu/gpu_watchdog.h" | 20 #include "content/common/gpu/gpu_watchdog.h" |
| 18 #include "content/common/gpu/image_transport_surface.h" | 21 #include "content/common/gpu/image_transport_surface.h" |
| 19 #include "gpu/command_buffer/common/constants.h" | 22 #include "gpu/command_buffer/common/constants.h" |
| 20 #include "ui/gfx/gl/gl_bindings.h" | 23 #include "ui/gfx/gl/gl_bindings.h" |
| 21 #include "ui/gfx/gl/gl_switches.h" | 24 #include "ui/gfx/gl/gl_switches.h" |
| 22 | 25 |
| 26 GpuCommandBufferStub::SurfaceState::SurfaceState(int32 surface_id, | |
| 27 bool visible, | |
| 28 base::TimeTicks last_used_time) | |
| 29 : surface_id(surface_id), | |
| 30 visible(visible), | |
| 31 last_used_time(last_used_time) { | |
| 32 } | |
| 33 | |
| 23 GpuCommandBufferStub::GpuCommandBufferStub( | 34 GpuCommandBufferStub::GpuCommandBufferStub( |
| 24 GpuChannel* channel, | 35 GpuChannel* channel, |
| 25 GpuCommandBufferStub* share_group, | 36 GpuCommandBufferStub* share_group, |
| 26 gfx::PluginWindowHandle handle, | 37 gfx::PluginWindowHandle handle, |
| 27 const gfx::Size& size, | 38 const gfx::Size& size, |
| 28 const gpu::gles2::DisallowedFeatures& disallowed_features, | 39 const gpu::gles2::DisallowedFeatures& disallowed_features, |
| 29 const std::string& allowed_extensions, | 40 const std::string& allowed_extensions, |
| 30 const std::vector<int32>& attribs, | 41 const std::vector<int32>& attribs, |
| 31 gfx::GpuPreference gpu_preference, | 42 gfx::GpuPreference gpu_preference, |
| 32 int32 route_id, | 43 int32 route_id, |
| 33 int32 surface_id, | 44 int32 surface_id, |
| 34 GpuWatchdog* watchdog, | 45 GpuWatchdog* watchdog, |
| 35 bool software) | 46 bool software) |
| 36 : channel_(channel), | 47 : channel_(channel), |
| 37 handle_(handle), | 48 handle_(handle), |
| 38 initial_size_(size), | 49 initial_size_(size), |
| 39 disallowed_features_(disallowed_features), | 50 disallowed_features_(disallowed_features), |
| 40 allowed_extensions_(allowed_extensions), | 51 allowed_extensions_(allowed_extensions), |
| 41 requested_attribs_(attribs), | 52 requested_attribs_(attribs), |
| 42 gpu_preference_(gpu_preference), | 53 gpu_preference_(gpu_preference), |
| 43 route_id_(route_id), | 54 route_id_(route_id), |
| 44 software_(software), | 55 software_(software), |
| 45 last_flush_count_(0), | 56 last_flush_count_(0), |
| 46 surface_id_(surface_id), | |
| 47 parent_stub_for_initialization_(), | 57 parent_stub_for_initialization_(), |
| 48 parent_texture_for_initialization_(0), | 58 parent_texture_for_initialization_(0), |
| 49 watchdog_(watchdog) { | 59 watchdog_(watchdog) { |
| 50 if (share_group) { | 60 if (share_group) { |
| 51 context_group_ = share_group->context_group_; | 61 context_group_ = share_group->context_group_; |
| 52 } else { | 62 } else { |
| 53 // TODO(gman): this needs to be false for everything but Pepper. | 63 // TODO(gman): this needs to be false for everything but Pepper. |
| 54 bool bind_generates_resource = true; | 64 bool bind_generates_resource = true; |
| 55 context_group_ = new gpu::gles2::ContextGroup(bind_generates_resource); | 65 context_group_ = new gpu::gles2::ContextGroup(bind_generates_resource); |
| 56 } | 66 } |
| 67 if (surface_id != 0) | |
| 68 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState( | |
| 69 surface_id, true, base::TimeTicks::Now())); | |
| 57 } | 70 } |
| 58 | 71 |
| 59 GpuCommandBufferStub::~GpuCommandBufferStub() { | 72 GpuCommandBufferStub::~GpuCommandBufferStub() { |
| 60 Destroy(); | 73 Destroy(); |
| 61 | 74 |
| 62 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 75 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
| 63 gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer(surface_id_)); | 76 gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer(surface_id())); |
| 64 } | 77 } |
| 65 | 78 |
| 66 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { | 79 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { |
| 67 // Ensure the appropriate GL context is current before handling any IPC | 80 // Ensure the appropriate GL context is current before handling any IPC |
| 68 // messages directed at the command buffer. This ensures that the message | 81 // messages directed at the command buffer. This ensures that the message |
| 69 // handler can assume that the context is current. | 82 // handler can assume that the context is current. |
| 70 if (decoder_.get()) { | 83 if (decoder_.get()) { |
| 71 if (!decoder_->MakeCurrent()) { | 84 if (!decoder_->MakeCurrent()) { |
| 72 DLOG(ERROR) << "Context lost because MakeCurrent failed."; | 85 DLOG(ERROR) << "Context lost because MakeCurrent failed."; |
| 73 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); | 86 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 | 159 |
| 147 if (decoder_.get()) { | 160 if (decoder_.get()) { |
| 148 decoder_->Destroy(); | 161 decoder_->Destroy(); |
| 149 decoder_.reset(); | 162 decoder_.reset(); |
| 150 } | 163 } |
| 151 | 164 |
| 152 command_buffer_.reset(); | 165 command_buffer_.reset(); |
| 153 | 166 |
| 154 context_ = NULL; | 167 context_ = NULL; |
| 155 surface_ = NULL; | 168 surface_ = NULL; |
| 169 | |
| 170 channel_->gpu_channel_manager()->gpu_memory_manager()->ScheduleManage(); | |
| 156 } | 171 } |
| 157 | 172 |
| 158 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { | 173 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { |
| 159 Destroy(); | 174 Destroy(); |
| 160 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); | 175 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); |
| 161 Send(reply_message); | 176 Send(reply_message); |
| 162 } | 177 } |
| 163 | 178 |
| 164 void GpuCommandBufferStub::OnInitialize( | 179 void GpuCommandBufferStub::OnInitialize( |
| 165 IPC::Message* reply_message) { | 180 IPC::Message* reply_message) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 | 282 |
| 268 if (parent_stub_for_initialization_) { | 283 if (parent_stub_for_initialization_) { |
| 269 decoder_->SetParent(parent_stub_for_initialization_->decoder_.get(), | 284 decoder_->SetParent(parent_stub_for_initialization_->decoder_.get(), |
| 270 parent_texture_for_initialization_); | 285 parent_texture_for_initialization_); |
| 271 parent_stub_for_initialization_.reset(); | 286 parent_stub_for_initialization_.reset(); |
| 272 parent_texture_for_initialization_ = 0; | 287 parent_texture_for_initialization_ = 0; |
| 273 } | 288 } |
| 274 | 289 |
| 275 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); | 290 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); |
| 276 Send(reply_message); | 291 Send(reply_message); |
| 292 | |
| 293 channel_->gpu_channel_manager()->gpu_memory_manager()->ScheduleManage(); | |
| 277 } | 294 } |
| 278 | 295 |
| 279 void GpuCommandBufferStub::OnSetGetBuffer( | 296 void GpuCommandBufferStub::OnSetGetBuffer( |
| 280 int32 shm_id, IPC::Message* reply_message) { | 297 int32 shm_id, IPC::Message* reply_message) { |
| 281 if (command_buffer_.get()) { | 298 if (command_buffer_.get()) { |
| 282 command_buffer_->SetGetBuffer(shm_id); | 299 command_buffer_->SetGetBuffer(shm_id); |
| 283 } else { | 300 } else { |
| 284 DLOG(ERROR) << "no command_buffer."; | 301 DLOG(ERROR) << "no command_buffer."; |
| 285 reply_message->set_reply_error(); | 302 reply_message->set_reply_error(); |
| 286 } | 303 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 channel_->renderer_process()); | 506 channel_->renderer_process()); |
| 490 } | 507 } |
| 491 | 508 |
| 492 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { | 509 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { |
| 493 channel_->RemoveRoute(decoder_route_id); | 510 channel_->RemoveRoute(decoder_route_id); |
| 494 video_decoders_.Remove(decoder_route_id); | 511 video_decoders_.Remove(decoder_route_id); |
| 495 } | 512 } |
| 496 | 513 |
| 497 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { | 514 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { |
| 498 surface_->SetVisible(visible); | 515 surface_->SetVisible(visible); |
| 516 DCHECK(surface_state_.get()); | |
| 517 surface_state_->visible = visible; | |
| 518 surface_state_->last_used_time = base::TimeTicks::Now(); | |
| 519 channel_->gpu_channel_manager()->gpu_memory_manager()->ScheduleManage(); | |
| 499 } | 520 } |
| 500 | 521 |
| 501 void GpuCommandBufferStub::SendConsoleMessage( | 522 void GpuCommandBufferStub::SendConsoleMessage( |
| 502 int32 id, | 523 int32 id, |
| 503 const std::string& message) { | 524 const std::string& message) { |
| 504 GPUCommandBufferConsoleMessage console_message; | 525 GPUCommandBufferConsoleMessage console_message; |
| 505 console_message.id = id; | 526 console_message.id = id; |
| 506 console_message.message = message; | 527 console_message.message = message; |
| 507 IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( | 528 IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( |
| 508 route_id_, console_message); | 529 route_id_, console_message); |
| 509 msg->set_unblock(true); | 530 msg->set_unblock(true); |
| 510 Send(msg); | 531 Send(msg); |
| 511 } | 532 } |
| 512 | 533 |
| 534 bool GpuCommandBufferStub::has_surface_state() { | |
| 535 return !!surface_state_.get(); | |
|
jonathan.backer
2012/02/02 14:03:53
Correct me if I'm wrong, I think that !! is redund
mmocny
2012/02/02 14:58:10
Its not redundant, but its needlessly clever. I'l
mmocny
2012/02/02 14:58:10
Done.
mmocny
2012/02/02 15:22:29
Update: These functions are virtual and should not
| |
| 536 } | |
| 537 | |
| 538 const GpuCommandBufferStubBase::SurfaceState& | |
| 539 GpuCommandBufferStub::surface_state() { | |
| 540 DCHECK(has_surface_state()); | |
| 541 return *surface_state_.get(); | |
|
jonathan.backer
2012/02/02 14:03:53
Header?
mmocny
2012/02/02 14:58:10
Done.
| |
| 542 } | |
| 543 | |
| 544 void GpuCommandBufferStub::SendMemoryAllocationToProxy( | |
| 545 const GpuMemoryAllocation& allocation) { | |
| 546 // TODO(mmocny): Send callback once gl extensions are added. | |
| 547 } | |
| 548 | |
| 513 #endif // defined(ENABLE_GPU) | 549 #endif // defined(ENABLE_GPU) |
| OLD | NEW |