| 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 "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 5 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 6 | 6 |
| 7 #include "third_party/khronos/GLES2/gl2.h" | 7 #include "third_party/khronos/GLES2/gl2.h" |
| 8 #ifndef GL_GLEXT_PROTOTYPES | 8 #ifndef GL_GLEXT_PROTOTYPES |
| 9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_GLEXT_PROTOTYPES 1 |
| 10 #endif | 10 #endif |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 298 |
| 299 command_buffer_size_ = command_buffer_size; | 299 command_buffer_size_ = command_buffer_size; |
| 300 start_transfer_buffer_size_ = start_transfer_buffer_size; | 300 start_transfer_buffer_size_ = start_transfer_buffer_size; |
| 301 min_transfer_buffer_size_ = min_transfer_buffer_size; | 301 min_transfer_buffer_size_ = min_transfer_buffer_size; |
| 302 max_transfer_buffer_size_ = max_transfer_buffer_size; | 302 max_transfer_buffer_size_ = max_transfer_buffer_size; |
| 303 mapped_memory_limit_ = mapped_memory_limit; | 303 mapped_memory_limit_ = mapped_memory_limit; |
| 304 | 304 |
| 305 return true; | 305 return true; |
| 306 } | 306 } |
| 307 | 307 |
| 308 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL( | 308 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() { |
| 309 const char* allowed_extensions) { | |
| 310 if (initialized_) | 309 if (initialized_) |
| 311 return true; | 310 return true; |
| 312 | 311 |
| 313 if (initialize_failed_) | 312 if (initialize_failed_) |
| 314 return false; | 313 return false; |
| 315 | 314 |
| 316 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); | 315 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); |
| 317 | 316 |
| 318 const char* preferred_extensions = "*"; | 317 if (!CreateContext(surface_id_ != 0)) { |
| 319 | |
| 320 if (!CreateContext(surface_id_ != 0, | |
| 321 allowed_extensions ? | |
| 322 allowed_extensions : preferred_extensions)) { | |
| 323 Destroy(); | 318 Destroy(); |
| 324 initialize_failed_ = true; | 319 initialize_failed_ = true; |
| 325 return false; | 320 return false; |
| 326 } | 321 } |
| 327 | 322 |
| 328 // TODO(twiz): This code is too fragile in that it assumes that only WebGL | 323 // TODO(twiz): This code is too fragile in that it assumes that only WebGL |
| 329 // contexts will request noExtensions. | 324 // contexts will request noExtensions. |
| 330 if (gl_ && attributes_.noExtensions) | 325 if (gl_ && attributes_.noExtensions) |
| 331 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); | 326 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); |
| 332 | 327 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 attributes_.stencil = pvalues[2] > 0; | 360 attributes_.stencil = pvalues[2] > 0; |
| 366 attributes_.antialias = pvalues[3] > 0; | 361 attributes_.antialias = pvalues[3] > 0; |
| 367 } | 362 } |
| 368 | 363 |
| 369 visible_ = true; | 364 visible_ = true; |
| 370 initialized_ = true; | 365 initialized_ = true; |
| 371 return true; | 366 return true; |
| 372 } | 367 } |
| 373 | 368 |
| 374 bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer( | 369 bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer( |
| 375 bool onscreen, | 370 bool onscreen) { |
| 376 const char* allowed_extensions) { | |
| 377 if (!host_.get()) | 371 if (!host_.get()) |
| 378 return false; | 372 return false; |
| 379 // We need to lock g_all_shared_contexts to ensure that the context we picked | 373 // We need to lock g_all_shared_contexts to ensure that the context we picked |
| 380 // for our share group isn't deleted. | 374 // for our share group isn't deleted. |
| 381 // (There's also a lock in our destructor.) | 375 // (There's also a lock in our destructor.) |
| 382 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 376 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 383 CommandBufferProxyImpl* share_group = NULL; | 377 CommandBufferProxyImpl* share_group = NULL; |
| 384 if (attributes_.shareResources) { | 378 if (attributes_.shareResources) { |
| 385 WebGraphicsContext3DCommandBufferImpl* share_group_context = | 379 WebGraphicsContext3DCommandBufferImpl* share_group_context = |
| 386 g_all_shared_contexts.Pointer()->empty() ? | 380 g_all_shared_contexts.Pointer()->empty() ? |
| (...skipping 13 matching lines...) Expand all Loading... |
| 400 attribs.push_back(attributes_.antialias ? 4 : 0); | 394 attribs.push_back(attributes_.antialias ? 4 : 0); |
| 401 attribs.push_back(SAMPLE_BUFFERS); | 395 attribs.push_back(SAMPLE_BUFFERS); |
| 402 attribs.push_back(attributes_.antialias ? 1 : 0); | 396 attribs.push_back(attributes_.antialias ? 1 : 0); |
| 403 attribs.push_back(NONE); | 397 attribs.push_back(NONE); |
| 404 | 398 |
| 405 // Create a proxy to a command buffer in the GPU process. | 399 // Create a proxy to a command buffer in the GPU process. |
| 406 if (onscreen) { | 400 if (onscreen) { |
| 407 command_buffer_.reset(host_->CreateViewCommandBuffer( | 401 command_buffer_.reset(host_->CreateViewCommandBuffer( |
| 408 surface_id_, | 402 surface_id_, |
| 409 share_group, | 403 share_group, |
| 410 allowed_extensions, | |
| 411 attribs, | 404 attribs, |
| 412 active_url_, | 405 active_url_, |
| 413 gpu_preference_)); | 406 gpu_preference_)); |
| 414 } else { | 407 } else { |
| 415 command_buffer_.reset(host_->CreateOffscreenCommandBuffer( | 408 command_buffer_.reset(host_->CreateOffscreenCommandBuffer( |
| 416 gfx::Size(1, 1), | 409 gfx::Size(1, 1), |
| 417 share_group, | 410 share_group, |
| 418 allowed_extensions, | |
| 419 attribs, | 411 attribs, |
| 420 active_url_, | 412 active_url_, |
| 421 gpu_preference_)); | 413 gpu_preference_)); |
| 422 } | 414 } |
| 423 | 415 |
| 424 if (!command_buffer_) | 416 if (!command_buffer_) |
| 425 return false; | 417 return false; |
| 426 | 418 |
| 427 // Initialize the command buffer. | 419 // Initialize the command buffer. |
| 428 return command_buffer_->Initialize(); | 420 return command_buffer_->Initialize(); |
| 429 } | 421 } |
| 430 | 422 |
| 431 bool WebGraphicsContext3DCommandBufferImpl::CreateContext( | 423 bool WebGraphicsContext3DCommandBufferImpl::CreateContext( |
| 432 bool onscreen, | 424 bool onscreen) { |
| 433 const char* allowed_extensions) { | |
| 434 | |
| 435 // Ensure the gles2 library is initialized first in a thread safe way. | 425 // Ensure the gles2 library is initialized first in a thread safe way. |
| 436 g_gles2_initializer.Get(); | 426 g_gles2_initializer.Get(); |
| 437 | 427 |
| 438 if (!command_buffer_ && | 428 if (!command_buffer_ && |
| 439 !InitializeCommandBuffer(onscreen, | 429 !InitializeCommandBuffer(onscreen)) { |
| 440 allowed_extensions)) { | |
| 441 return false; | 430 return false; |
| 442 } | 431 } |
| 443 | 432 |
| 444 // Create the GLES2 helper, which writes the command buffer protocol. | 433 // Create the GLES2 helper, which writes the command buffer protocol. |
| 445 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); | 434 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); |
| 446 if (!gles2_helper_->Initialize(command_buffer_size_)) | 435 if (!gles2_helper_->Initialize(command_buffer_size_)) |
| 447 return false; | 436 return false; |
| 448 | 437 |
| 449 if (attributes_.noAutomaticFlushes) | 438 if (attributes_.noAutomaticFlushes) |
| 450 gles2_helper_->SetAutomaticFlushes(false); | 439 gles2_helper_->SetAutomaticFlushes(false); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if (CommandLine::ForCurrentProcess()->HasSwitch( | 481 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 493 switches::kEnableGpuClientTracing)) { | 482 switches::kEnableGpuClientTracing)) { |
| 494 trace_gl_.reset(new gpu::gles2::GLES2TraceImplementation(gl_)); | 483 trace_gl_.reset(new gpu::gles2::GLES2TraceImplementation(gl_)); |
| 495 gl_ = trace_gl_.get(); | 484 gl_ = trace_gl_.get(); |
| 496 } | 485 } |
| 497 | 486 |
| 498 return true; | 487 return true; |
| 499 } | 488 } |
| 500 | 489 |
| 501 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { | 490 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { |
| 502 if (!MaybeInitializeGL(NULL)) | 491 if (!MaybeInitializeGL()) |
| 503 return false; | 492 return false; |
| 504 gles2::SetGLContext(gl_); | 493 gles2::SetGLContext(gl_); |
| 505 if (command_buffer_->GetLastError() != gpu::error::kNoError) | 494 if (command_buffer_->GetLastError() != gpu::error::kNoError) |
| 506 return false; | 495 return false; |
| 507 | 496 |
| 508 return true; | 497 return true; |
| 509 } | 498 } |
| 510 | 499 |
| 511 int WebGraphicsContext3DCommandBufferImpl::width() { | 500 int WebGraphicsContext3DCommandBufferImpl::width() { |
| 512 return cached_width_; | 501 return cached_width_; |
| (...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 | 1580 |
| 1592 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( | 1581 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( |
| 1593 const std::string& message, int id) { | 1582 const std::string& message, int id) { |
| 1594 if (error_message_callback_) { | 1583 if (error_message_callback_) { |
| 1595 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); | 1584 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); |
| 1596 error_message_callback_->onErrorMessage(str, id); | 1585 error_message_callback_->onErrorMessage(str, id); |
| 1597 } | 1586 } |
| 1598 } | 1587 } |
| 1599 | 1588 |
| 1600 } // namespace content | 1589 } // namespace content |
| OLD | NEW |