OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/command_buffer/service/in_process_command_buffer.h" | 5 #include "gpu/command_buffer/service/in_process_command_buffer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <queue> | 10 #include <queue> |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 if (!MakeCurrent()) | 244 if (!MakeCurrent()) |
245 return; | 245 return; |
246 | 246 |
247 executor_->PutChanged(); | 247 executor_->PutChanged(); |
248 } | 248 } |
249 | 249 |
250 bool InProcessCommandBuffer::Initialize( | 250 bool InProcessCommandBuffer::Initialize( |
251 scoped_refptr<gl::GLSurface> surface, | 251 scoped_refptr<gl::GLSurface> surface, |
252 bool is_offscreen, | 252 bool is_offscreen, |
253 gfx::AcceleratedWidget window, | 253 gfx::AcceleratedWidget window, |
| 254 const gfx::Size& size, |
254 const gles2::ContextCreationAttribHelper& attribs, | 255 const gles2::ContextCreationAttribHelper& attribs, |
| 256 gl::GpuPreference gpu_preference, |
255 InProcessCommandBuffer* share_group, | 257 InProcessCommandBuffer* share_group, |
256 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 258 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
257 ImageFactory* image_factory) { | 259 ImageFactory* image_factory) { |
258 DCHECK(!share_group || service_.get() == share_group->service_.get()); | 260 DCHECK(!share_group || service_.get() == share_group->service_.get()); |
259 | 261 |
260 if (surface) { | 262 if (surface) { |
261 // GPU thread must be the same as client thread due to GLSurface not being | 263 // GPU thread must be the same as client thread due to GLSurface not being |
262 // thread safe. | 264 // thread safe. |
263 sequence_checker_.reset(new base::SequenceChecker); | 265 sequence_checker_.reset(new base::SequenceChecker); |
264 surface_ = surface; | 266 surface_ = surface; |
265 } else { | 267 } else { |
266 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 268 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
267 client_thread_weak_ptr_ = client_thread_weak_ptr_factory_.GetWeakPtr(); | 269 client_thread_weak_ptr_ = client_thread_weak_ptr_factory_.GetWeakPtr(); |
268 } | 270 } |
269 | 271 |
270 gpu::Capabilities capabilities; | 272 gpu::Capabilities capabilities; |
271 InitializeOnGpuThreadParams params(is_offscreen, window, attribs, | 273 InitializeOnGpuThreadParams params(is_offscreen, |
272 &capabilities, share_group, image_factory); | 274 window, |
| 275 size, |
| 276 attribs, |
| 277 gpu_preference, |
| 278 &capabilities, |
| 279 share_group, |
| 280 image_factory); |
273 | 281 |
274 base::Callback<bool(void)> init_task = | 282 base::Callback<bool(void)> init_task = |
275 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, | 283 base::Bind(&InProcessCommandBuffer::InitializeOnGpuThread, |
276 base::Unretained(this), params); | 284 base::Unretained(this), |
| 285 params); |
277 | 286 |
278 base::WaitableEvent completion( | 287 base::WaitableEvent completion( |
279 base::WaitableEvent::ResetPolicy::MANUAL, | 288 base::WaitableEvent::ResetPolicy::MANUAL, |
280 base::WaitableEvent::InitialState::NOT_SIGNALED); | 289 base::WaitableEvent::InitialState::NOT_SIGNALED); |
281 bool result = false; | 290 bool result = false; |
282 QueueTask( | 291 QueueTask( |
283 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); | 292 base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); |
284 completion.Wait(); | 293 completion.Wait(); |
285 | 294 |
286 gpu_memory_buffer_manager_ = gpu_memory_buffer_manager; | 295 gpu_memory_buffer_manager_ = gpu_memory_buffer_manager; |
287 | 296 |
288 if (result) { | 297 if (result) { |
289 capabilities_ = capabilities; | 298 capabilities_ = capabilities; |
290 capabilities_.image = capabilities_.image && gpu_memory_buffer_manager_; | 299 capabilities_.image = capabilities_.image && gpu_memory_buffer_manager_; |
291 } | 300 } |
292 | 301 |
293 return result; | 302 return result; |
294 } | 303 } |
295 | 304 |
296 bool InProcessCommandBuffer::InitializeOnGpuThread( | 305 bool InProcessCommandBuffer::InitializeOnGpuThread( |
297 const InitializeOnGpuThreadParams& params) { | 306 const InitializeOnGpuThreadParams& params) { |
298 CheckSequencedThread(); | 307 CheckSequencedThread(); |
299 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); | 308 gpu_thread_weak_ptr_ = gpu_thread_weak_ptr_factory_.GetWeakPtr(); |
300 | 309 |
| 310 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); |
| 311 |
301 TransferBufferManager* manager = new TransferBufferManager(nullptr); | 312 TransferBufferManager* manager = new TransferBufferManager(nullptr); |
302 transfer_buffer_manager_ = manager; | 313 transfer_buffer_manager_ = manager; |
303 manager->Initialize(); | 314 manager->Initialize(); |
304 | 315 |
305 std::unique_ptr<CommandBufferService> command_buffer( | 316 std::unique_ptr<CommandBufferService> command_buffer( |
306 new CommandBufferService(transfer_buffer_manager_.get())); | 317 new CommandBufferService(transfer_buffer_manager_.get())); |
307 command_buffer->SetPutOffsetChangeCallback(base::Bind( | 318 command_buffer->SetPutOffsetChangeCallback(base::Bind( |
308 &InProcessCommandBuffer::PumpCommandsOnGpuThread, gpu_thread_weak_ptr_)); | 319 &InProcessCommandBuffer::PumpCommandsOnGpuThread, gpu_thread_weak_ptr_)); |
309 command_buffer->SetParseErrorCallback(base::Bind( | 320 command_buffer->SetParseErrorCallback(base::Bind( |
310 &InProcessCommandBuffer::OnContextLostOnGpuThread, gpu_thread_weak_ptr_)); | 321 &InProcessCommandBuffer::OnContextLostOnGpuThread, gpu_thread_weak_ptr_)); |
(...skipping 17 matching lines...) Expand all Loading... |
328 executor_.reset(new CommandExecutor(command_buffer.get(), decoder_.get(), | 339 executor_.reset(new CommandExecutor(command_buffer.get(), decoder_.get(), |
329 decoder_.get())); | 340 decoder_.get())); |
330 command_buffer->SetGetBufferChangeCallback(base::Bind( | 341 command_buffer->SetGetBufferChangeCallback(base::Bind( |
331 &CommandExecutor::SetGetBuffer, base::Unretained(executor_.get()))); | 342 &CommandExecutor::SetGetBuffer, base::Unretained(executor_.get()))); |
332 command_buffer_ = std::move(command_buffer); | 343 command_buffer_ = std::move(command_buffer); |
333 | 344 |
334 decoder_->set_engine(executor_.get()); | 345 decoder_->set_engine(executor_.get()); |
335 | 346 |
336 if (!surface_.get()) { | 347 if (!surface_.get()) { |
337 if (params.is_offscreen) | 348 if (params.is_offscreen) |
338 surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size()); | 349 surface_ = gl::init::CreateOffscreenGLSurface(params.size); |
339 else | 350 else |
340 surface_ = gl::init::CreateViewGLSurface(params.window); | 351 surface_ = gl::init::CreateViewGLSurface(params.window); |
341 } | 352 } |
342 | 353 |
343 if (!surface_.get()) { | 354 if (!surface_.get()) { |
344 LOG(ERROR) << "Could not create GLSurface."; | 355 LOG(ERROR) << "Could not create GLSurface."; |
345 DestroyOnGpuThread(); | 356 DestroyOnGpuThread(); |
346 return false; | 357 return false; |
347 } | 358 } |
348 | 359 |
349 sync_point_order_data_ = SyncPointOrderData::Create(); | 360 sync_point_order_data_ = SyncPointOrderData::Create(); |
350 sync_point_client_ = service_->sync_point_manager()->CreateSyncPointClient( | 361 sync_point_client_ = service_->sync_point_manager()->CreateSyncPointClient( |
351 sync_point_order_data_, GetNamespaceID(), GetCommandBufferID()); | 362 sync_point_order_data_, GetNamespaceID(), GetCommandBufferID()); |
352 | 363 |
353 if (service_->UseVirtualizedGLContexts() || | 364 if (service_->UseVirtualizedGLContexts() || |
354 decoder_->GetContextGroup() | 365 decoder_->GetContextGroup() |
355 ->feature_info() | 366 ->feature_info() |
356 ->workarounds() | 367 ->workarounds() |
357 .use_virtualized_gl_contexts) { | 368 .use_virtualized_gl_contexts) { |
358 context_ = gl_share_group_->GetSharedContext(); | 369 context_ = gl_share_group_->GetSharedContext(); |
359 if (!context_.get()) { | 370 if (!context_.get()) { |
360 context_ = gl::init::CreateGLContext( | 371 context_ = gl::init::CreateGLContext( |
361 gl_share_group_.get(), surface_.get(), params.attribs.gpu_preference); | 372 gl_share_group_.get(), surface_.get(), params.gpu_preference); |
362 gl_share_group_->SetSharedContext(context_.get()); | 373 gl_share_group_->SetSharedContext(context_.get()); |
363 } | 374 } |
364 | 375 |
365 context_ = new GLContextVirtual( | 376 context_ = new GLContextVirtual( |
366 gl_share_group_.get(), context_.get(), decoder_->AsWeakPtr()); | 377 gl_share_group_.get(), context_.get(), decoder_->AsWeakPtr()); |
367 if (context_->Initialize(surface_.get(), params.attribs.gpu_preference)) { | 378 if (context_->Initialize(surface_.get(), params.gpu_preference)) { |
368 VLOG(1) << "Created virtual GL context."; | 379 VLOG(1) << "Created virtual GL context."; |
369 } else { | 380 } else { |
370 context_ = NULL; | 381 context_ = NULL; |
371 } | 382 } |
372 } else { | 383 } else { |
373 context_ = gl::init::CreateGLContext(gl_share_group_.get(), surface_.get(), | 384 context_ = gl::init::CreateGLContext(gl_share_group_.get(), surface_.get(), |
374 params.attribs.gpu_preference); | 385 params.gpu_preference); |
375 } | 386 } |
376 | 387 |
377 if (!context_.get()) { | 388 if (!context_.get()) { |
378 LOG(ERROR) << "Could not create GLContext."; | 389 LOG(ERROR) << "Could not create GLContext."; |
379 DestroyOnGpuThread(); | 390 DestroyOnGpuThread(); |
380 return false; | 391 return false; |
381 } | 392 } |
382 | 393 |
383 if (!context_->MakeCurrent(surface_.get())) { | 394 if (!context_->MakeCurrent(surface_.get())) { |
384 LOG(ERROR) << "Could not make context current."; | 395 LOG(ERROR) << "Could not make context current."; |
385 DestroyOnGpuThread(); | 396 DestroyOnGpuThread(); |
386 return false; | 397 return false; |
387 } | 398 } |
388 | 399 |
389 if (!decoder_->GetContextGroup()->has_program_cache() && | 400 if (!decoder_->GetContextGroup()->has_program_cache() && |
390 !decoder_->GetContextGroup() | 401 !decoder_->GetContextGroup() |
391 ->feature_info() | 402 ->feature_info() |
392 ->workarounds() | 403 ->workarounds() |
393 .disable_program_cache) { | 404 .disable_program_cache) { |
394 decoder_->GetContextGroup()->set_program_cache(service_->program_cache()); | 405 decoder_->GetContextGroup()->set_program_cache(service_->program_cache()); |
395 } | 406 } |
396 | 407 |
397 gles2::DisallowedFeatures disallowed_features; | 408 gles2::DisallowedFeatures disallowed_features; |
398 disallowed_features.gpu_memory_manager = true; | 409 disallowed_features.gpu_memory_manager = true; |
399 if (!decoder_->Initialize(surface_, | 410 if (!decoder_->Initialize(surface_, |
400 context_, | 411 context_, |
401 params.is_offscreen, | 412 params.is_offscreen, |
| 413 params.size, |
402 disallowed_features, | 414 disallowed_features, |
403 params.attribs)) { | 415 params.attribs)) { |
404 LOG(ERROR) << "Could not initialize decoder."; | 416 LOG(ERROR) << "Could not initialize decoder."; |
405 DestroyOnGpuThread(); | 417 DestroyOnGpuThread(); |
406 return false; | 418 return false; |
407 } | 419 } |
408 *params.capabilities = decoder_->GetCapabilities(); | 420 *params.capabilities = decoder_->GetCapabilities(); |
409 | 421 |
410 decoder_->SetFenceSyncReleaseCallback( | 422 decoder_->SetFenceSyncReleaseCallback( |
411 base::Bind(&InProcessCommandBuffer::FenceSyncReleaseOnGpuThread, | 423 base::Bind(&InProcessCommandBuffer::FenceSyncReleaseOnGpuThread, |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 framebuffer_completeness_cache_ = | 1081 framebuffer_completeness_cache_ = |
1070 new gpu::gles2::FramebufferCompletenessCache; | 1082 new gpu::gles2::FramebufferCompletenessCache; |
1071 return framebuffer_completeness_cache_; | 1083 return framebuffer_completeness_cache_; |
1072 } | 1084 } |
1073 | 1085 |
1074 SyncPointManager* GpuInProcessThread::sync_point_manager() { | 1086 SyncPointManager* GpuInProcessThread::sync_point_manager() { |
1075 return sync_point_manager_; | 1087 return sync_point_manager_; |
1076 } | 1088 } |
1077 | 1089 |
1078 } // namespace gpu | 1090 } // namespace gpu |
OLD | NEW |