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" |
| 16 #include "content/common/gpu/gpu_messages.h" | 17 #include "content/common/gpu/gpu_messages.h" |
| 18 #include "content/common/gpu/gpu_memory_manager.h" | |
| 17 #include "content/common/gpu/gpu_watchdog.h" | 19 #include "content/common/gpu/gpu_watchdog.h" |
| 18 #include "content/common/gpu/image_transport_surface.h" | 20 #include "content/common/gpu/image_transport_surface.h" |
| 19 #include "gpu/command_buffer/common/constants.h" | 21 #include "gpu/command_buffer/common/constants.h" |
| 20 #include "ui/gfx/gl/gl_bindings.h" | 22 #include "ui/gfx/gl/gl_bindings.h" |
| 21 #include "ui/gfx/gl/gl_switches.h" | 23 #include "ui/gfx/gl/gl_switches.h" |
| 22 | 24 |
| 23 GpuCommandBufferStub::GpuCommandBufferStub( | 25 GpuCommandBufferStub::GpuCommandBufferStub( |
| 24 GpuChannel* channel, | 26 GpuChannel* channel, |
| 25 GpuCommandBufferStub* share_group, | 27 GpuCommandBufferStub* share_group, |
| 26 gfx::PluginWindowHandle handle, | 28 gfx::PluginWindowHandle handle, |
| 27 const gfx::Size& size, | 29 const gfx::Size& size, |
| 28 const gpu::gles2::DisallowedFeatures& disallowed_features, | 30 const gpu::gles2::DisallowedFeatures& disallowed_features, |
| 29 const std::string& allowed_extensions, | 31 const std::string& allowed_extensions, |
| 30 const std::vector<int32>& attribs, | 32 const std::vector<int32>& attribs, |
| 31 gfx::GpuPreference gpu_preference, | 33 gfx::GpuPreference gpu_preference, |
| 32 int32 route_id, | 34 int32 route_id, |
| 33 int32 surface_id, | 35 int32 surface_id, |
| 34 GpuWatchdog* watchdog, | 36 GpuWatchdog* watchdog, |
| 35 bool software) | 37 bool software) |
| 36 : channel_(channel), | 38 : channel_(channel), |
| 37 handle_(handle), | 39 handle_(handle), |
| 38 initial_size_(size), | 40 initial_size_(size), |
| 39 disallowed_features_(disallowed_features), | 41 disallowed_features_(disallowed_features), |
| 40 allowed_extensions_(allowed_extensions), | 42 allowed_extensions_(allowed_extensions), |
| 41 requested_attribs_(attribs), | 43 requested_attribs_(attribs), |
| 42 gpu_preference_(gpu_preference), | 44 gpu_preference_(gpu_preference), |
| 43 route_id_(route_id), | 45 route_id_(route_id), |
| 44 software_(software), | 46 software_(software), |
| 45 last_flush_count_(0), | 47 last_flush_count_(0), |
| 48 visible_(true), | |
| 49 last_used_time_(kUnknownLastUsedTime), | |
| 46 surface_id_(surface_id), | 50 surface_id_(surface_id), |
| 47 parent_stub_for_initialization_(), | 51 parent_stub_for_initialization_(), |
| 48 parent_texture_for_initialization_(0), | 52 parent_texture_for_initialization_(0), |
| 49 watchdog_(watchdog) { | 53 watchdog_(watchdog) { |
| 50 if (share_group) { | 54 if (share_group) { |
| 51 context_group_ = share_group->context_group_; | 55 context_group_ = share_group->context_group_; |
| 52 } else { | 56 } else { |
| 53 // TODO(gman): this needs to be false for everything but Pepper. | 57 // TODO(gman): this needs to be false for everything but Pepper. |
| 54 bool bind_generates_resource = true; | 58 bool bind_generates_resource = true; |
| 55 context_group_ = new gpu::gles2::ContextGroup(bind_generates_resource); | 59 context_group_ = new gpu::gles2::ContextGroup(bind_generates_resource); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 | 150 |
| 147 if (decoder_.get()) { | 151 if (decoder_.get()) { |
| 148 decoder_->Destroy(); | 152 decoder_->Destroy(); |
| 149 decoder_.reset(); | 153 decoder_.reset(); |
| 150 } | 154 } |
| 151 | 155 |
| 152 command_buffer_.reset(); | 156 command_buffer_.reset(); |
| 153 | 157 |
| 154 context_ = NULL; | 158 context_ = NULL; |
| 155 surface_ = NULL; | 159 surface_ = NULL; |
| 160 | |
| 161 channel_->gpu_channel_manager()->GetGpuMemoryManager()->Manage(); | |
| 156 } | 162 } |
| 157 | 163 |
| 158 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { | 164 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { |
| 159 Destroy(); | 165 Destroy(); |
| 160 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); | 166 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); |
| 161 Send(reply_message); | 167 Send(reply_message); |
| 162 } | 168 } |
| 163 | 169 |
| 164 void GpuCommandBufferStub::OnInitialize( | 170 void GpuCommandBufferStub::OnInitialize( |
| 165 IPC::Message* reply_message) { | 171 IPC::Message* reply_message) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 | 273 |
| 268 if (parent_stub_for_initialization_) { | 274 if (parent_stub_for_initialization_) { |
| 269 decoder_->SetParent(parent_stub_for_initialization_->decoder_.get(), | 275 decoder_->SetParent(parent_stub_for_initialization_->decoder_.get(), |
| 270 parent_texture_for_initialization_); | 276 parent_texture_for_initialization_); |
| 271 parent_stub_for_initialization_.reset(); | 277 parent_stub_for_initialization_.reset(); |
| 272 parent_texture_for_initialization_ = 0; | 278 parent_texture_for_initialization_ = 0; |
| 273 } | 279 } |
| 274 | 280 |
| 275 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); | 281 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); |
| 276 Send(reply_message); | 282 Send(reply_message); |
| 283 | |
| 284 channel_->gpu_channel_manager()->GetGpuMemoryManager()->Manage(); | |
| 277 } | 285 } |
| 278 | 286 |
| 279 void GpuCommandBufferStub::OnSetGetBuffer( | 287 void GpuCommandBufferStub::OnSetGetBuffer( |
| 280 int32 shm_id, IPC::Message* reply_message) { | 288 int32 shm_id, IPC::Message* reply_message) { |
| 281 if (command_buffer_.get()) { | 289 if (command_buffer_.get()) { |
| 282 command_buffer_->SetGetBuffer(shm_id); | 290 command_buffer_->SetGetBuffer(shm_id); |
| 283 } else { | 291 } else { |
| 284 DLOG(ERROR) << "no command_buffer."; | 292 DLOG(ERROR) << "no command_buffer."; |
| 285 reply_message->set_reply_error(); | 293 reply_message->set_reply_error(); |
| 286 } | 294 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 if (flush_count - last_flush_count_ < 0x8000000U) { | 365 if (flush_count - last_flush_count_ < 0x8000000U) { |
| 358 last_flush_count_ = flush_count; | 366 last_flush_count_ = flush_count; |
| 359 command_buffer_->Flush(put_offset); | 367 command_buffer_->Flush(put_offset); |
| 360 } else { | 368 } else { |
| 361 // We received this message out-of-order. This should not happen but is here | 369 // We received this message out-of-order. This should not happen but is here |
| 362 // to catch regressions. Ignore the message. | 370 // to catch regressions. Ignore the message. |
| 363 NOTREACHED() << "Received a Flush message out-of-order"; | 371 NOTREACHED() << "Received a Flush message out-of-order"; |
| 364 } | 372 } |
| 365 | 373 |
| 366 ReportState(); | 374 ReportState(); |
| 375 // TODO(mmocny): Call GpuMemoryManager::Manage here? | |
| 367 } | 376 } |
| 368 | 377 |
| 369 void GpuCommandBufferStub::OnRescheduled() { | 378 void GpuCommandBufferStub::OnRescheduled() { |
| 370 gpu::CommandBuffer::State pre_state = command_buffer_->GetLastState(); | 379 gpu::CommandBuffer::State pre_state = command_buffer_->GetLastState(); |
| 371 command_buffer_->Flush(pre_state.put_offset); | 380 command_buffer_->Flush(pre_state.put_offset); |
| 372 gpu::CommandBuffer::State post_state = command_buffer_->GetLastState(); | 381 gpu::CommandBuffer::State post_state = command_buffer_->GetLastState(); |
| 373 | 382 |
| 374 if (pre_state.get_offset != post_state.get_offset) | 383 if (pre_state.get_offset != post_state.get_offset) |
| 375 ReportState(); | 384 ReportState(); |
| 376 } | 385 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 channel_->renderer_process()); | 498 channel_->renderer_process()); |
| 490 } | 499 } |
| 491 | 500 |
| 492 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { | 501 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { |
| 493 channel_->RemoveRoute(decoder_route_id); | 502 channel_->RemoveRoute(decoder_route_id); |
| 494 video_decoders_.Remove(decoder_route_id); | 503 video_decoders_.Remove(decoder_route_id); |
| 495 } | 504 } |
| 496 | 505 |
| 497 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { | 506 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { |
| 498 surface_->SetVisible(visible); | 507 surface_->SetVisible(visible); |
| 508 visible_ = visible; | |
| 509 base::Time now = base::Time::Now(); | |
| 510 last_used_time_ = now.ToInternalValue(); | |
| 511 | |
| 512 channel_->gpu_channel_manager()->GetGpuMemoryManager()->Manage(); | |
|
nduca
2012/01/27 10:10:13
Not liking this. I would rather you modify the upp
mmocny
2012/01/27 19:51:33
Added ScheduleManage.
On 2012/01/27 10:10:13, nduc
| |
| 499 } | 513 } |
| 500 | 514 |
| 501 void GpuCommandBufferStub::SendConsoleMessage( | 515 void GpuCommandBufferStub::SendConsoleMessage( |
| 502 int32 id, | 516 int32 id, |
| 503 const std::string& message) { | 517 const std::string& message) { |
| 504 GPUCommandBufferConsoleMessage console_message; | 518 GPUCommandBufferConsoleMessage console_message; |
| 505 console_message.id = id; | 519 console_message.id = id; |
| 506 console_message.message = message; | 520 console_message.message = message; |
| 507 IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( | 521 IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( |
| 508 route_id_, console_message); | 522 route_id_, console_message); |
| 509 msg->set_unblock(true); | 523 msg->set_unblock(true); |
| 510 Send(msg); | 524 Send(msg); |
| 511 } | 525 } |
| 512 | 526 |
| 527 std::vector<int> GpuCommandBufferStub::render_widget_ids() const { | |
| 528 // TODO(mmocny): Hack alert, treat route_id as renderer_widget_id until | |
| 529 // we actually feed real render_widget_ids through | |
| 530 return std::vector<int>(1,int(route_id_)); | |
|
nduca
2012/01/27 10:10:13
woah, what? You can wire this up already if you th
mmocny
2012/01/27 19:51:33
I cannot find any reference to render_view during
| |
| 531 } | |
|
nduca
2012/01/27 10:10:13
Shouldn't you be using render_view_id, not route_i
| |
| 532 | |
| 533 void GpuCommandBufferStub::SetMemoryAllocation( | |
| 534 GpuMemoryAllocation const& allocation) { | |
| 535 // TODO(mmocny): 1. Send callback once gl extensions are added | |
| 536 // 2. Move drop backbuffer hook from SetSurfaceVisibile to here | |
|
nduca
2012/01/27 10:10:13
Woah, this will have side effects other than just
mmocny
2012/01/27 19:51:33
You are correct on all points, this was leftover d
| |
| 537 // 3. Implement drop frontbuffer with hook here | |
| 538 // 4. Implement browser notification on drop frontbuffer | |
| 539 #if 0 | |
| 540 printf(" [%p] Allocation: %i, front: %s, back: %s\n", this, | |
| 541 allocation.gpuResourceSizeInBytes, | |
| 542 allocation.hasFrontbuffer ? "true" : "false", | |
| 543 allocation.hasBackbuffer ? "true" : "false"); | |
| 544 #endif | |
| 545 } | |
| 546 | |
| 513 #endif // defined(ENABLE_GPU) | 547 #endif // defined(ENABLE_GPU) |
| OLD | NEW |