| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/hash.h" | 8 #include "base/hash.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace | 174 } // namespace |
| 175 | 175 |
| 176 GpuCommandBufferStub::GpuCommandBufferStub( | 176 GpuCommandBufferStub::GpuCommandBufferStub( |
| 177 GpuChannel* channel, | 177 GpuChannel* channel, |
| 178 base::SingleThreadTaskRunner* task_runner, | 178 base::SingleThreadTaskRunner* task_runner, |
| 179 GpuCommandBufferStub* share_group, | 179 GpuCommandBufferStub* share_group, |
| 180 const gfx::GLSurfaceHandle& handle, | 180 const gfx::GLSurfaceHandle& handle, |
| 181 gpu::gles2::MailboxManager* mailbox_manager, | 181 gpu::gles2::MailboxManager* mailbox_manager, |
| 182 gpu::PreemptionFlag* preempt_by_flag, |
| 182 gpu::gles2::SubscriptionRefSet* subscription_ref_set, | 183 gpu::gles2::SubscriptionRefSet* subscription_ref_set, |
| 183 gpu::ValueStateMap* pending_valuebuffer_state, | 184 gpu::ValueStateMap* pending_valuebuffer_state, |
| 184 const gfx::Size& size, | 185 const gfx::Size& size, |
| 185 const gpu::gles2::DisallowedFeatures& disallowed_features, | 186 const gpu::gles2::DisallowedFeatures& disallowed_features, |
| 186 const std::vector<int32>& attribs, | 187 const std::vector<int32>& attribs, |
| 187 gfx::GpuPreference gpu_preference, | 188 gfx::GpuPreference gpu_preference, |
| 188 int32 stream_id, | 189 int32 stream_id, |
| 189 int32 route_id, | 190 int32 route_id, |
| 190 int32 surface_id, | 191 bool offscreen, |
| 191 GpuWatchdog* watchdog, | 192 GpuWatchdog* watchdog, |
| 192 bool software, | |
| 193 const GURL& active_url) | 193 const GURL& active_url) |
| 194 : channel_(channel), | 194 : channel_(channel), |
| 195 task_runner_(task_runner), | 195 task_runner_(task_runner), |
| 196 initialized_(false), | 196 initialized_(false), |
| 197 handle_(handle), | 197 handle_(handle), |
| 198 initial_size_(size), | 198 initial_size_(size), |
| 199 disallowed_features_(disallowed_features), | 199 disallowed_features_(disallowed_features), |
| 200 requested_attribs_(attribs), | 200 requested_attribs_(attribs), |
| 201 gpu_preference_(gpu_preference), | 201 gpu_preference_(gpu_preference), |
| 202 use_virtualized_gl_context_(false), | 202 use_virtualized_gl_context_(false), |
| 203 command_buffer_id_(GetCommandBufferID(channel->client_id(), route_id)), | 203 command_buffer_id_(GetCommandBufferID(channel->client_id(), route_id)), |
| 204 stream_id_(stream_id), | 204 stream_id_(stream_id), |
| 205 route_id_(route_id), | 205 route_id_(route_id), |
| 206 surface_id_(surface_id), | 206 offscreen_(offscreen), |
| 207 software_(software), | |
| 208 last_flush_count_(0), | 207 last_flush_count_(0), |
| 209 last_memory_allocation_valid_(false), | 208 last_memory_allocation_valid_(false), |
| 210 watchdog_(watchdog), | 209 watchdog_(watchdog), |
| 211 waiting_for_sync_point_(false), | 210 waiting_for_sync_point_(false), |
| 212 previous_processed_num_(0), | 211 previous_processed_num_(0), |
| 212 preemption_flag_(preempt_by_flag), |
| 213 active_url_(active_url), | 213 active_url_(active_url), |
| 214 total_gpu_memory_(0) { | 214 total_gpu_memory_(0) { |
| 215 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); | 215 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); |
| 216 FastSetActiveURL(active_url_, active_url_hash_); | 216 FastSetActiveURL(active_url_, active_url_hash_); |
| 217 | 217 |
| 218 gpu::gles2::ContextCreationAttribHelper attrib_parser; | 218 gpu::gles2::ContextCreationAttribHelper attrib_parser; |
| 219 attrib_parser.Parse(requested_attribs_); | 219 attrib_parser.Parse(requested_attribs_); |
| 220 | 220 |
| 221 if (share_group) { | 221 if (share_group) { |
| 222 context_group_ = share_group->context_group_; | 222 context_group_ = share_group->context_group_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 236 // performance regressions when enabling FCM. | 236 // performance regressions when enabling FCM. |
| 237 // http://crbug.com/180463 | 237 // http://crbug.com/180463 |
| 238 #if defined(OS_MACOSX) | 238 #if defined(OS_MACOSX) |
| 239 if (gpu_preference_ == gfx::PreferIntegratedGpu) | 239 if (gpu_preference_ == gfx::PreferIntegratedGpu) |
| 240 use_virtualized_gl_context_ = true; | 240 use_virtualized_gl_context_ = true; |
| 241 #endif | 241 #endif |
| 242 | 242 |
| 243 use_virtualized_gl_context_ |= | 243 use_virtualized_gl_context_ |= |
| 244 context_group_->feature_info()->UseVirtualizedGLContexts(); | 244 context_group_->feature_info()->UseVirtualizedGLContexts(); |
| 245 | 245 |
| 246 bool is_offscreen = surface_id_ == 0; | 246 if (offscreen && initial_size_.IsEmpty()) { |
| 247 if (is_offscreen && initial_size_.IsEmpty()) { | |
| 248 // If we're an offscreen surface with zero width and/or height, set to a | 247 // If we're an offscreen surface with zero width and/or height, set to a |
| 249 // non-zero size so that we have a complete framebuffer for operations like | 248 // non-zero size so that we have a complete framebuffer for operations like |
| 250 // glClear. | 249 // glClear. |
| 251 initial_size_ = gfx::Size(1, 1); | 250 initial_size_ = gfx::Size(1, 1); |
| 252 } | 251 } |
| 253 } | 252 } |
| 254 | 253 |
| 255 GpuCommandBufferStub::~GpuCommandBufferStub() { | 254 GpuCommandBufferStub::~GpuCommandBufferStub() { |
| 256 Destroy(); | 255 Destroy(); |
| 257 } | 256 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 Send(wait_for_get_offset_->reply.release()); | 468 Send(wait_for_get_offset_->reply.release()); |
| 470 wait_for_get_offset_.reset(); | 469 wait_for_get_offset_.reset(); |
| 471 } | 470 } |
| 472 | 471 |
| 473 if (initialized_) { | 472 if (initialized_) { |
| 474 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 473 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
| 475 if (handle_.is_null() && !active_url_.is_empty()) { | 474 if (handle_.is_null() && !active_url_.is_empty()) { |
| 476 gpu_channel_manager->Send( | 475 gpu_channel_manager->Send( |
| 477 new GpuHostMsg_DidDestroyOffscreenContext(active_url_)); | 476 new GpuHostMsg_DidDestroyOffscreenContext(active_url_)); |
| 478 } | 477 } |
| 479 gpu_channel_manager->Send( | |
| 480 new GpuHostMsg_DestroyCommandBuffer(surface_id())); | |
| 481 } | 478 } |
| 482 | 479 |
| 483 memory_manager_client_state_.reset(); | 480 memory_manager_client_state_.reset(); |
| 484 | 481 |
| 485 while (!sync_points_.empty()) | 482 while (!sync_points_.empty()) |
| 486 OnRetireSyncPoint(sync_points_.front()); | 483 OnRetireSyncPoint(sync_points_.front()); |
| 487 | 484 |
| 488 if (decoder_) | 485 if (decoder_) |
| 489 decoder_->set_engine(NULL); | 486 decoder_->set_engine(NULL); |
| 490 | 487 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 channel_->GetSyncPointClientState(), | 549 channel_->GetSyncPointClientState(), |
| 553 gpu::CommandBufferNamespace::GPU_IO, | 550 gpu::CommandBufferNamespace::GPU_IO, |
| 554 command_buffer_id_); | 551 command_buffer_id_); |
| 555 | 552 |
| 556 if (preemption_flag_.get()) | 553 if (preemption_flag_.get()) |
| 557 scheduler_->SetPreemptByFlag(preemption_flag_); | 554 scheduler_->SetPreemptByFlag(preemption_flag_); |
| 558 | 555 |
| 559 decoder_->set_engine(scheduler_.get()); | 556 decoder_->set_engine(scheduler_.get()); |
| 560 | 557 |
| 561 if (!handle_.is_null()) { | 558 if (!handle_.is_null()) { |
| 562 #if defined(OS_MACOSX) || defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | |
| 563 if (software_) { | |
| 564 LOG(ERROR) << "No software support."; | |
| 565 OnInitializeFailed(reply_message); | |
| 566 return; | |
| 567 } | |
| 568 #endif | |
| 569 | |
| 570 surface_ = ImageTransportSurface::CreateSurface( | 559 surface_ = ImageTransportSurface::CreateSurface( |
| 571 channel_->gpu_channel_manager(), | 560 channel_->gpu_channel_manager(), |
| 572 this, | 561 this, |
| 573 handle_); | 562 handle_); |
| 574 } else { | 563 } else { |
| 575 surface_ = manager->GetDefaultOffscreenSurface(); | 564 surface_ = manager->GetDefaultOffscreenSurface(); |
| 576 } | 565 } |
| 577 | 566 |
| 578 if (!surface_.get()) { | 567 if (!surface_.get()) { |
| 579 DLOG(ERROR) << "Failed to create surface."; | 568 DLOG(ERROR) << "Failed to create surface."; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 if (!context->GetTotalGpuMemory(&total_gpu_memory_)) | 625 if (!context->GetTotalGpuMemory(&total_gpu_memory_)) |
| 637 total_gpu_memory_ = 0; | 626 total_gpu_memory_ = 0; |
| 638 | 627 |
| 639 if (!context_group_->has_program_cache() && | 628 if (!context_group_->has_program_cache() && |
| 640 !context_group_->feature_info()->workarounds().disable_program_cache) { | 629 !context_group_->feature_info()->workarounds().disable_program_cache) { |
| 641 context_group_->set_program_cache( | 630 context_group_->set_program_cache( |
| 642 channel_->gpu_channel_manager()->program_cache()); | 631 channel_->gpu_channel_manager()->program_cache()); |
| 643 } | 632 } |
| 644 | 633 |
| 645 // Initialize the decoder with either the view or pbuffer GLContext. | 634 // Initialize the decoder with either the view or pbuffer GLContext. |
| 646 if (!decoder_->Initialize(surface_, | 635 if (!decoder_->Initialize(surface_, context, offscreen_, initial_size_, |
| 647 context, | 636 disallowed_features_, requested_attribs_)) { |
| 648 !surface_id(), | |
| 649 initial_size_, | |
| 650 disallowed_features_, | |
| 651 requested_attribs_)) { | |
| 652 DLOG(ERROR) << "Failed to initialize decoder."; | 637 DLOG(ERROR) << "Failed to initialize decoder."; |
| 653 OnInitializeFailed(reply_message); | 638 OnInitializeFailed(reply_message); |
| 654 return; | 639 return; |
| 655 } | 640 } |
| 656 | 641 |
| 657 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 642 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 658 switches::kEnableGPUServiceLogging)) { | 643 switches::kEnableGPUServiceLogging)) { |
| 659 decoder_->set_log_commands(true); | 644 decoder_->set_log_commands(true); |
| 660 } | 645 } |
| 661 | 646 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 } | 1023 } |
| 1039 | 1024 |
| 1040 | 1025 |
| 1041 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( | 1026 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( |
| 1042 bool has_callback) { | 1027 bool has_callback) { |
| 1043 TRACE_EVENT0( | 1028 TRACE_EVENT0( |
| 1044 "gpu", | 1029 "gpu", |
| 1045 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); | 1030 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); |
| 1046 if (has_callback) { | 1031 if (has_callback) { |
| 1047 if (!memory_manager_client_state_) { | 1032 if (!memory_manager_client_state_) { |
| 1048 memory_manager_client_state_.reset(GetMemoryManager()->CreateClientState( | 1033 memory_manager_client_state_.reset( |
| 1049 this, surface_id_ != 0, true)); | 1034 GetMemoryManager()->CreateClientState(this, !offscreen_, true)); |
| 1050 } | 1035 } |
| 1051 } else { | 1036 } else { |
| 1052 memory_manager_client_state_.reset(); | 1037 memory_manager_client_state_.reset(); |
| 1053 } | 1038 } |
| 1054 } | 1039 } |
| 1055 | 1040 |
| 1056 void GpuCommandBufferStub::OnCreateImage(int32 id, | 1041 void GpuCommandBufferStub::OnCreateImage(int32 id, |
| 1057 gfx::GpuMemoryBufferHandle handle, | 1042 gfx::GpuMemoryBufferHandle handle, |
| 1058 gfx::Size size, | 1043 gfx::Size size, |
| 1059 gfx::BufferFormat format, | 1044 gfx::BufferFormat format, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 void GpuCommandBufferStub::AddDestructionObserver( | 1117 void GpuCommandBufferStub::AddDestructionObserver( |
| 1133 DestructionObserver* observer) { | 1118 DestructionObserver* observer) { |
| 1134 destruction_observers_.AddObserver(observer); | 1119 destruction_observers_.AddObserver(observer); |
| 1135 } | 1120 } |
| 1136 | 1121 |
| 1137 void GpuCommandBufferStub::RemoveDestructionObserver( | 1122 void GpuCommandBufferStub::RemoveDestructionObserver( |
| 1138 DestructionObserver* observer) { | 1123 DestructionObserver* observer) { |
| 1139 destruction_observers_.RemoveObserver(observer); | 1124 destruction_observers_.RemoveObserver(observer); |
| 1140 } | 1125 } |
| 1141 | 1126 |
| 1142 void GpuCommandBufferStub::SetPreemptByFlag( | |
| 1143 scoped_refptr<gpu::PreemptionFlag> flag) { | |
| 1144 preemption_flag_ = flag; | |
| 1145 if (scheduler_) | |
| 1146 scheduler_->SetPreemptByFlag(preemption_flag_); | |
| 1147 } | |
| 1148 | |
| 1149 bool GpuCommandBufferStub::GetTotalGpuMemory(uint64* bytes) { | 1127 bool GpuCommandBufferStub::GetTotalGpuMemory(uint64* bytes) { |
| 1150 *bytes = total_gpu_memory_; | 1128 *bytes = total_gpu_memory_; |
| 1151 return !!total_gpu_memory_; | 1129 return !!total_gpu_memory_; |
| 1152 } | 1130 } |
| 1153 | 1131 |
| 1154 gfx::Size GpuCommandBufferStub::GetSurfaceSize() const { | 1132 gfx::Size GpuCommandBufferStub::GetSurfaceSize() const { |
| 1155 if (!surface_.get()) | 1133 if (!surface_.get()) |
| 1156 return gfx::Size(); | 1134 return gfx::Size(); |
| 1157 return surface_->GetSize(); | 1135 return surface_->GetSize(); |
| 1158 } | 1136 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 result)); | 1218 result)); |
| 1241 } | 1219 } |
| 1242 | 1220 |
| 1243 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, | 1221 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, |
| 1244 base::TimeDelta interval) { | 1222 base::TimeDelta interval) { |
| 1245 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, | 1223 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, |
| 1246 interval)); | 1224 interval)); |
| 1247 } | 1225 } |
| 1248 | 1226 |
| 1249 } // namespace content | 1227 } // namespace content |
| OLD | NEW |