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, | |
|
nduca
2012/02/01 00:01:17
Awkward indent.
| |
| 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), | 57 surface_state_(), |
|
nduca
2012/02/01 00:01:17
not needed since its an scoped_ptr.
| |
| 58 affected_surface_ids_(), | |
|
nduca
2012/02/01 00:01:17
not needed.
| |
| 47 parent_stub_for_initialization_(), | 59 parent_stub_for_initialization_(), |
| 48 parent_texture_for_initialization_(0), | 60 parent_texture_for_initialization_(0), |
| 49 watchdog_(watchdog) { | 61 watchdog_(watchdog) { |
| 50 if (share_group) { | 62 if (share_group) { |
| 51 context_group_ = share_group->context_group_; | 63 context_group_ = share_group->context_group_; |
| 52 } else { | 64 } else { |
| 53 // TODO(gman): this needs to be false for everything but Pepper. | 65 // TODO(gman): this needs to be false for everything but Pepper. |
| 54 bool bind_generates_resource = true; | 66 bool bind_generates_resource = true; |
| 55 context_group_ = new gpu::gles2::ContextGroup(bind_generates_resource); | 67 context_group_ = new gpu::gles2::ContextGroup(bind_generates_resource); |
| 56 } | 68 } |
| 69 if (surface_id != 0) | |
| 70 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState( | |
| 71 surface_id, true, base::TimeTicks::Now())); | |
| 57 } | 72 } |
| 58 | 73 |
| 59 GpuCommandBufferStub::~GpuCommandBufferStub() { | 74 GpuCommandBufferStub::~GpuCommandBufferStub() { |
| 60 Destroy(); | 75 Destroy(); |
| 61 | 76 |
| 62 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 77 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
| 63 gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer(surface_id_)); | 78 gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer(surface_id())); |
| 64 } | 79 } |
| 65 | 80 |
| 66 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { | 81 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { |
| 67 // Ensure the appropriate GL context is current before handling any IPC | 82 // Ensure the appropriate GL context is current before handling any IPC |
| 68 // messages directed at the command buffer. This ensures that the message | 83 // messages directed at the command buffer. This ensures that the message |
| 69 // handler can assume that the context is current. | 84 // handler can assume that the context is current. |
| 70 if (decoder_.get()) { | 85 if (decoder_.get()) { |
| 71 if (!decoder_->MakeCurrent()) { | 86 if (!decoder_->MakeCurrent()) { |
| 72 DLOG(ERROR) << "Context lost because MakeCurrent failed."; | 87 DLOG(ERROR) << "Context lost because MakeCurrent failed."; |
| 73 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); | 88 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 | 161 |
| 147 if (decoder_.get()) { | 162 if (decoder_.get()) { |
| 148 decoder_->Destroy(); | 163 decoder_->Destroy(); |
| 149 decoder_.reset(); | 164 decoder_.reset(); |
| 150 } | 165 } |
| 151 | 166 |
| 152 command_buffer_.reset(); | 167 command_buffer_.reset(); |
| 153 | 168 |
| 154 context_ = NULL; | 169 context_ = NULL; |
| 155 surface_ = NULL; | 170 surface_ = NULL; |
| 171 | |
| 172 channel_->gpu_channel_manager()->gpu_memory_manager()->ScheduleManage(); | |
| 156 } | 173 } |
| 157 | 174 |
| 158 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { | 175 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { |
| 159 Destroy(); | 176 Destroy(); |
| 160 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); | 177 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); |
| 161 Send(reply_message); | 178 Send(reply_message); |
| 162 } | 179 } |
| 163 | 180 |
| 164 void GpuCommandBufferStub::OnInitialize( | 181 void GpuCommandBufferStub::OnInitialize( |
| 165 IPC::Message* reply_message) { | 182 IPC::Message* reply_message) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 | 284 |
| 268 if (parent_stub_for_initialization_) { | 285 if (parent_stub_for_initialization_) { |
| 269 decoder_->SetParent(parent_stub_for_initialization_->decoder_.get(), | 286 decoder_->SetParent(parent_stub_for_initialization_->decoder_.get(), |
| 270 parent_texture_for_initialization_); | 287 parent_texture_for_initialization_); |
| 271 parent_stub_for_initialization_.reset(); | 288 parent_stub_for_initialization_.reset(); |
| 272 parent_texture_for_initialization_ = 0; | 289 parent_texture_for_initialization_ = 0; |
| 273 } | 290 } |
| 274 | 291 |
| 275 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); | 292 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); |
| 276 Send(reply_message); | 293 Send(reply_message); |
| 294 | |
| 295 channel_->gpu_channel_manager()->gpu_memory_manager()->ScheduleManage(); | |
| 277 } | 296 } |
| 278 | 297 |
| 279 void GpuCommandBufferStub::OnSetGetBuffer( | 298 void GpuCommandBufferStub::OnSetGetBuffer( |
| 280 int32 shm_id, IPC::Message* reply_message) { | 299 int32 shm_id, IPC::Message* reply_message) { |
| 281 if (command_buffer_.get()) { | 300 if (command_buffer_.get()) { |
| 282 command_buffer_->SetGetBuffer(shm_id); | 301 command_buffer_->SetGetBuffer(shm_id); |
| 283 } else { | 302 } else { |
| 284 DLOG(ERROR) << "no command_buffer."; | 303 DLOG(ERROR) << "no command_buffer."; |
| 285 reply_message->set_reply_error(); | 304 reply_message->set_reply_error(); |
| 286 } | 305 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 channel_->renderer_process()); | 508 channel_->renderer_process()); |
| 490 } | 509 } |
| 491 | 510 |
| 492 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { | 511 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { |
| 493 channel_->RemoveRoute(decoder_route_id); | 512 channel_->RemoveRoute(decoder_route_id); |
| 494 video_decoders_.Remove(decoder_route_id); | 513 video_decoders_.Remove(decoder_route_id); |
| 495 } | 514 } |
| 496 | 515 |
| 497 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { | 516 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { |
| 498 surface_->SetVisible(visible); | 517 surface_->SetVisible(visible); |
| 518 DCHECK(surface_state_.get()); | |
| 519 surface_state_->visible = visible; | |
| 520 surface_state_->last_used_time = base::TimeTicks::Now(); | |
| 521 channel_->gpu_channel_manager()->gpu_memory_manager()->ScheduleManage(); | |
| 499 } | 522 } |
| 500 | 523 |
| 501 void GpuCommandBufferStub::SendConsoleMessage( | 524 void GpuCommandBufferStub::SendConsoleMessage( |
| 502 int32 id, | 525 int32 id, |
| 503 const std::string& message) { | 526 const std::string& message) { |
| 504 GPUCommandBufferConsoleMessage console_message; | 527 GPUCommandBufferConsoleMessage console_message; |
| 505 console_message.id = id; | 528 console_message.id = id; |
| 506 console_message.message = message; | 529 console_message.message = message; |
| 507 IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( | 530 IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( |
| 508 route_id_, console_message); | 531 route_id_, console_message); |
| 509 msg->set_unblock(true); | 532 msg->set_unblock(true); |
| 510 Send(msg); | 533 Send(msg); |
| 511 } | 534 } |
| 512 | 535 |
| 536 GpuCommandBufferStubBase::SurfaceState* GpuCommandBufferStub::surface_state() { | |
| 537 return surface_state_.get(); | |
| 538 } | |
| 539 | |
| 540 const std::vector<int32>& GpuCommandBufferStub::affected_surface_ids() { | |
| 541 return affected_surface_ids_; | |
| 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 |