| 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 "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 5 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 // Create a GLInProcessContext that renders to an offscreen frame buffer. If | 92 // Create a GLInProcessContext that renders to an offscreen frame buffer. If |
| 93 // parent is not NULL, that GLInProcessContext can access a copy of the | 93 // parent is not NULL, that GLInProcessContext can access a copy of the |
| 94 // created GLInProcessContext's frame buffer that is updated every time | 94 // created GLInProcessContext's frame buffer that is updated every time |
| 95 // SwapBuffers is called. It is not as general as shared GLInProcessContexts | 95 // SwapBuffers is called. It is not as general as shared GLInProcessContexts |
| 96 // in other implementations of OpenGL. If parent is not NULL, it must be used | 96 // in other implementations of OpenGL. If parent is not NULL, it must be used |
| 97 // on the same thread as the parent. A child GLInProcessContext may not | 97 // on the same thread as the parent. A child GLInProcessContext may not |
| 98 // outlive its parent. attrib_list must be NULL or a NONE-terminated list of | 98 // outlive its parent. attrib_list must be NULL or a NONE-terminated list of |
| 99 // attribute/value pairs. | 99 // attribute/value pairs. |
| 100 static GLInProcessContext* CreateOffscreenContext( | 100 static GLInProcessContext* CreateOffscreenContext( |
| 101 GLInProcessContext* parent, |
| 101 const gfx::Size& size, | 102 const gfx::Size& size, |
| 102 GLInProcessContext* context_group, | 103 GLInProcessContext* context_group, |
| 103 const char* allowed_extensions, | 104 const char* allowed_extensions, |
| 104 const int32* attrib_list, | 105 const int32* attrib_list, |
| 105 gfx::GpuPreference gpu_preference); | 106 gfx::GpuPreference gpu_preference); |
| 106 | 107 |
| 107 // For an offscreen frame buffer GLInProcessContext, return the texture ID | 108 // For an offscreen frame buffer GLInProcessContext, return the texture ID |
| 108 // with respect to the parent GLInProcessContext. Returns zero if | 109 // with respect to the parent GLInProcessContext. Returns zero if |
| 109 // GLInProcessContext does not have a parent. | 110 // GLInProcessContext does not have a parent. |
| 110 uint32 GetParentTextureId(); | 111 uint32 GetParentTextureId(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 137 // Return the current error. | 138 // Return the current error. |
| 138 Error GetError(); | 139 Error GetError(); |
| 139 | 140 |
| 140 // Return true if GPU process reported GLInProcessContext lost or there was a | 141 // Return true if GPU process reported GLInProcessContext lost or there was a |
| 141 // problem communicating with the GPU process. | 142 // problem communicating with the GPU process. |
| 142 bool IsCommandBufferContextLost(); | 143 bool IsCommandBufferContextLost(); |
| 143 | 144 |
| 144 CommandBufferService* GetCommandBufferService(); | 145 CommandBufferService* GetCommandBufferService(); |
| 145 | 146 |
| 146 private: | 147 private: |
| 147 GLInProcessContext(); | 148 explicit GLInProcessContext(GLInProcessContext* parent); |
| 148 | 149 |
| 149 bool Initialize(const gfx::Size& size, | 150 bool Initialize(const gfx::Size& size, |
| 150 GLInProcessContext* context_group, | 151 GLInProcessContext* context_group, |
| 151 const char* allowed_extensions, | 152 const char* allowed_extensions, |
| 152 const int32* attrib_list, | 153 const int32* attrib_list, |
| 153 gfx::GpuPreference gpu_preference); | 154 gfx::GpuPreference gpu_preference); |
| 154 void Destroy(); | 155 void Destroy(); |
| 155 | 156 |
| 156 void OnContextLost(); | 157 void OnContextLost(); |
| 157 | 158 |
| 159 base::WeakPtr<GLInProcessContext> parent_; |
| 158 base::Closure context_lost_callback_; | 160 base::Closure context_lost_callback_; |
| 161 uint32 parent_texture_id_; |
| 159 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 162 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 160 scoped_ptr<CommandBufferService> command_buffer_; | 163 scoped_ptr<CommandBufferService> command_buffer_; |
| 161 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; | 164 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; |
| 162 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; | 165 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; |
| 163 scoped_refptr<gfx::GLContext> context_; | 166 scoped_refptr<gfx::GLContext> context_; |
| 164 scoped_refptr<gfx::GLSurface> surface_; | 167 scoped_refptr<gfx::GLSurface> surface_; |
| 165 scoped_ptr<GLES2CmdHelper> gles2_helper_; | 168 scoped_ptr<GLES2CmdHelper> gles2_helper_; |
| 166 scoped_ptr<TransferBuffer> transfer_buffer_; | 169 scoped_ptr<TransferBuffer> transfer_buffer_; |
| 167 scoped_ptr<GLES2Implementation> gles2_implementation_; | 170 scoped_ptr<GLES2Implementation> gles2_implementation_; |
| 168 Error last_error_; | 171 Error last_error_; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 static base::LazyInstance<GLES2Initializer> g_gles2_initializer = | 209 static base::LazyInstance<GLES2Initializer> g_gles2_initializer = |
| 207 LAZY_INSTANCE_INITIALIZER; | 210 LAZY_INSTANCE_INITIALIZER; |
| 208 | 211 |
| 209 } // namespace anonymous | 212 } // namespace anonymous |
| 210 | 213 |
| 211 GLInProcessContext::~GLInProcessContext() { | 214 GLInProcessContext::~GLInProcessContext() { |
| 212 Destroy(); | 215 Destroy(); |
| 213 } | 216 } |
| 214 | 217 |
| 215 GLInProcessContext* GLInProcessContext::CreateOffscreenContext( | 218 GLInProcessContext* GLInProcessContext::CreateOffscreenContext( |
| 219 GLInProcessContext* parent, |
| 216 const gfx::Size& size, | 220 const gfx::Size& size, |
| 217 GLInProcessContext* context_group, | 221 GLInProcessContext* context_group, |
| 218 const char* allowed_extensions, | 222 const char* allowed_extensions, |
| 219 const int32* attrib_list, | 223 const int32* attrib_list, |
| 220 gfx::GpuPreference gpu_preference) { | 224 gfx::GpuPreference gpu_preference) { |
| 221 scoped_ptr<GLInProcessContext> context(new GLInProcessContext); | 225 scoped_ptr<GLInProcessContext> context(new GLInProcessContext(parent)); |
| 222 if (!context->Initialize( | 226 if (!context->Initialize( |
| 223 size, | 227 size, |
| 224 context_group, | 228 context_group, |
| 225 allowed_extensions, | 229 allowed_extensions, |
| 226 attrib_list, | 230 attrib_list, |
| 227 gpu_preference)) | 231 gpu_preference)) |
| 228 return NULL; | 232 return NULL; |
| 229 | 233 |
| 230 return context.release(); | 234 return context.release(); |
| 231 } | 235 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 248 context_lost_ = true; | 252 context_lost_ = true; |
| 249 } | 253 } |
| 250 } | 254 } |
| 251 } | 255 } |
| 252 | 256 |
| 253 bool GLInProcessContext::GetBufferChanged(int32 transfer_buffer_id) { | 257 bool GLInProcessContext::GetBufferChanged(int32 transfer_buffer_id) { |
| 254 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); | 258 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); |
| 255 } | 259 } |
| 256 | 260 |
| 257 uint32 GLInProcessContext::GetParentTextureId() { | 261 uint32 GLInProcessContext::GetParentTextureId() { |
| 258 return 0; | 262 return parent_texture_id_; |
| 259 } | 263 } |
| 260 | 264 |
| 261 uint32 GLInProcessContext::CreateParentTexture(const gfx::Size& size) { | 265 uint32 GLInProcessContext::CreateParentTexture(const gfx::Size& size) { |
| 262 uint32 texture = 0; | 266 uint32 texture = 0; |
| 263 gles2_implementation_->GenTextures(1, &texture); | 267 gles2_implementation_->GenTextures(1, &texture); |
| 264 gles2_implementation_->Flush(); | 268 gles2_implementation_->Flush(); |
| 265 return texture; | 269 return texture; |
| 266 } | 270 } |
| 267 | 271 |
| 268 void GLInProcessContext::DeleteParentTexture(uint32 texture) { | 272 void GLInProcessContext::DeleteParentTexture(uint32 texture) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 334 |
| 331 // TODO(gman): Remove This | 335 // TODO(gman): Remove This |
| 332 void GLInProcessContext::DisableShaderTranslation() { | 336 void GLInProcessContext::DisableShaderTranslation() { |
| 333 NOTREACHED(); | 337 NOTREACHED(); |
| 334 } | 338 } |
| 335 | 339 |
| 336 GLES2Implementation* GLInProcessContext::GetImplementation() { | 340 GLES2Implementation* GLInProcessContext::GetImplementation() { |
| 337 return gles2_implementation_.get(); | 341 return gles2_implementation_.get(); |
| 338 } | 342 } |
| 339 | 343 |
| 340 GLInProcessContext::GLInProcessContext() | 344 GLInProcessContext::GLInProcessContext(GLInProcessContext* parent) |
| 341 : last_error_(SUCCESS), | 345 : parent_(parent ? |
| 346 parent->AsWeakPtr() : base::WeakPtr<GLInProcessContext>()), |
| 347 parent_texture_id_(0), |
| 348 last_error_(SUCCESS), |
| 342 context_lost_(false) { | 349 context_lost_(false) { |
| 343 } | 350 } |
| 344 | 351 |
| 345 bool GLInProcessContext::Initialize(const gfx::Size& size, | 352 bool GLInProcessContext::Initialize(const gfx::Size& size, |
| 346 GLInProcessContext* context_group, | 353 GLInProcessContext* context_group, |
| 347 const char* allowed_extensions, | 354 const char* allowed_extensions, |
| 348 const int32* attrib_list, | 355 const int32* attrib_list, |
| 349 gfx::GpuPreference gpu_preference) { | 356 gfx::GpuPreference gpu_preference) { |
| 350 // Use one share group for all contexts. | 357 // Use one share group for all contexts. |
| 351 CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, | 358 CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, |
| 352 (new gfx::GLShareGroup)); | 359 (new gfx::GLShareGroup)); |
| 353 | 360 |
| 354 DCHECK(size.width() >= 0 && size.height() >= 0); | 361 DCHECK(size.width() >= 0 && size.height() >= 0); |
| 355 | 362 |
| 356 // Ensure the gles2 library is initialized first in a thread safe way. | 363 // Ensure the gles2 library is initialized first in a thread safe way. |
| 357 g_gles2_initializer.Get(); | 364 g_gles2_initializer.Get(); |
| 358 | 365 |
| 366 // Allocate a frame buffer ID with respect to the parent. |
| 367 if (parent_.get()) { |
| 368 // Flush any remaining commands in the parent context to make sure the |
| 369 // texture id accounting stays consistent. |
| 370 int32 token = parent_->gles2_helper_->InsertToken(); |
| 371 parent_->gles2_helper_->WaitForToken(token); |
| 372 parent_texture_id_ = parent_->gles2_implementation_->MakeTextureId(); |
| 373 } |
| 374 |
| 359 std::vector<int32> attribs; | 375 std::vector<int32> attribs; |
| 360 while (attrib_list) { | 376 while (attrib_list) { |
| 361 int32 attrib = *attrib_list++; | 377 int32 attrib = *attrib_list++; |
| 362 switch (attrib) { | 378 switch (attrib) { |
| 363 // Known attributes | 379 // Known attributes |
| 364 case ALPHA_SIZE: | 380 case ALPHA_SIZE: |
| 365 case BLUE_SIZE: | 381 case BLUE_SIZE: |
| 366 case GREEN_SIZE: | 382 case GREEN_SIZE: |
| 367 case RED_SIZE: | 383 case RED_SIZE: |
| 368 case DEPTH_SIZE: | 384 case DEPTH_SIZE: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 true, | 458 true, |
| 443 size, | 459 size, |
| 444 disallowed_features, | 460 disallowed_features, |
| 445 allowed_extensions, | 461 allowed_extensions, |
| 446 attribs)) { | 462 attribs)) { |
| 447 LOG(ERROR) << "Could not initialize decoder."; | 463 LOG(ERROR) << "Could not initialize decoder."; |
| 448 Destroy(); | 464 Destroy(); |
| 449 return false; | 465 return false; |
| 450 } | 466 } |
| 451 | 467 |
| 468 if (!decoder_->SetParent( |
| 469 parent_.get() ? parent_->decoder_.get() : NULL, |
| 470 parent_texture_id_)) { |
| 471 LOG(ERROR) << "Could not set parent."; |
| 472 Destroy(); |
| 473 return false; |
| 474 } |
| 475 |
| 452 command_buffer_->SetPutOffsetChangeCallback( | 476 command_buffer_->SetPutOffsetChangeCallback( |
| 453 base::Bind(&GLInProcessContext::PumpCommands, base::Unretained(this))); | 477 base::Bind(&GLInProcessContext::PumpCommands, base::Unretained(this))); |
| 454 command_buffer_->SetGetBufferChangeCallback( | 478 command_buffer_->SetGetBufferChangeCallback( |
| 455 base::Bind( | 479 base::Bind( |
| 456 &GLInProcessContext::GetBufferChanged, base::Unretained(this))); | 480 &GLInProcessContext::GetBufferChanged, base::Unretained(this))); |
| 457 command_buffer_->SetParseErrorCallback( | 481 command_buffer_->SetParseErrorCallback( |
| 458 base::Bind(&GLInProcessContext::OnContextLost, base::Unretained(this))); | 482 base::Bind(&GLInProcessContext::OnContextLost, base::Unretained(this))); |
| 459 | 483 |
| 460 // Create the GLES2 helper, which writes the command buffer protocol. | 484 // Create the GLES2 helper, which writes the command buffer protocol. |
| 461 gles2_helper_.reset(new GLES2CmdHelper(command_buffer_.get())); | 485 gles2_helper_.reset(new GLES2CmdHelper(command_buffer_.get())); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 481 kMaxTransferBufferSize)) { | 505 kMaxTransferBufferSize)) { |
| 482 return false; | 506 return false; |
| 483 } | 507 } |
| 484 | 508 |
| 485 return true; | 509 return true; |
| 486 } | 510 } |
| 487 | 511 |
| 488 void GLInProcessContext::Destroy() { | 512 void GLInProcessContext::Destroy() { |
| 489 bool context_lost = IsCommandBufferContextLost(); | 513 bool context_lost = IsCommandBufferContextLost(); |
| 490 | 514 |
| 515 if (parent_.get() && parent_texture_id_ != 0) { |
| 516 parent_->gles2_implementation_->FreeTextureId(parent_texture_id_); |
| 517 parent_texture_id_ = 0; |
| 518 } |
| 519 |
| 491 if (gles2_implementation_.get()) { | 520 if (gles2_implementation_.get()) { |
| 492 // First flush the context to ensure that any pending frees of resources | 521 // First flush the context to ensure that any pending frees of resources |
| 493 // are completed. Otherwise, if this context is part of a share group, | 522 // are completed. Otherwise, if this context is part of a share group, |
| 494 // those resources might leak. Also, any remaining side effects of commands | 523 // those resources might leak. Also, any remaining side effects of commands |
| 495 // issued on this context might not be visible to other contexts in the | 524 // issued on this context might not be visible to other contexts in the |
| 496 // share group. | 525 // share group. |
| 497 gles2_implementation_->Flush(); | 526 gles2_implementation_->Flush(); |
| 498 | 527 |
| 499 gles2_implementation_.reset(); | 528 gles2_implementation_.reset(); |
| 500 } | 529 } |
| 501 | 530 |
| 502 transfer_buffer_.reset(); | 531 transfer_buffer_.reset(); |
| 503 gles2_helper_.reset(); | 532 gles2_helper_.reset(); |
| 504 command_buffer_.reset(); | 533 command_buffer_.reset(); |
| 505 | 534 |
| 506 if (decoder_.get()) { | 535 if (decoder_.get()) { |
| 507 decoder_->Destroy(!context_lost); | 536 decoder_->Destroy(!context_lost); |
| 508 } | 537 } |
| 509 } | 538 } |
| 510 | 539 |
| 511 void GLInProcessContext::OnContextLost() { | 540 void GLInProcessContext::OnContextLost() { |
| 512 if (!context_lost_callback_.is_null()) | 541 if (!context_lost_callback_.is_null()) |
| 513 context_lost_callback_.Run(); | 542 context_lost_callback_.Run(); |
| 514 } | 543 } |
| 515 | 544 |
| 516 WebGraphicsContext3DInProcessCommandBufferImpl:: | 545 WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 517 WebGraphicsContext3DInProcessCommandBufferImpl( | 546 WebGraphicsContext3DInProcessCommandBufferImpl() |
| 518 const WebKit::WebGraphicsContext3D::Attributes& attributes) | 547 : context_(NULL), |
| 519 : initialized_(false), | |
| 520 initialize_failed_(false), | |
| 521 context_(NULL), | |
| 522 gl_(NULL), | 548 gl_(NULL), |
| 523 context_lost_callback_(NULL), | 549 context_lost_callback_(NULL), |
| 524 context_lost_reason_(GL_NO_ERROR), | 550 context_lost_reason_(GL_NO_ERROR), |
| 525 attributes_(attributes), | |
| 526 cached_width_(0), | 551 cached_width_(0), |
| 527 cached_height_(0), | 552 cached_height_(0), |
| 528 bound_fbo_(0) { | 553 bound_fbo_(0) { |
| 529 } | 554 } |
| 530 | 555 |
| 531 WebGraphicsContext3DInProcessCommandBufferImpl:: | 556 WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 532 ~WebGraphicsContext3DInProcessCommandBufferImpl() { | 557 ~WebGraphicsContext3DInProcessCommandBufferImpl() { |
| 533 base::AutoLock a(g_all_shared_contexts_lock.Get()); | 558 base::AutoLock a(g_all_shared_contexts_lock.Get()); |
| 534 g_all_shared_contexts.Pointer()->erase(this); | 559 g_all_shared_contexts.Pointer()->erase(this); |
| 535 } | 560 } |
| 536 | 561 |
| 537 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { | 562 bool WebGraphicsContext3DInProcessCommandBufferImpl::Initialize( |
| 538 if (initialized_) | 563 WebGraphicsContext3D::Attributes attributes, |
| 539 return true; | 564 WebKit::WebGraphicsContext3D* view_context) { |
| 540 | |
| 541 if (initialize_failed_) | |
| 542 return false; | |
| 543 | |
| 544 // Convert WebGL context creation attributes into GLInProcessContext / EGL | 565 // Convert WebGL context creation attributes into GLInProcessContext / EGL |
| 545 // size requests. | 566 // size requests. |
| 546 const int alpha_size = attributes_.alpha ? 8 : 0; | 567 const int alpha_size = attributes.alpha ? 8 : 0; |
| 547 const int depth_size = attributes_.depth ? 24 : 0; | 568 const int depth_size = attributes.depth ? 24 : 0; |
| 548 const int stencil_size = attributes_.stencil ? 8 : 0; | 569 const int stencil_size = attributes.stencil ? 8 : 0; |
| 549 const int samples = attributes_.antialias ? 4 : 0; | 570 const int samples = attributes.antialias ? 4 : 0; |
| 550 const int sample_buffers = attributes_.antialias ? 1 : 0; | 571 const int sample_buffers = attributes.antialias ? 1 : 0; |
| 551 const int32 attribs[] = { | 572 const int32 attribs[] = { |
| 552 GLInProcessContext::ALPHA_SIZE, alpha_size, | 573 GLInProcessContext::ALPHA_SIZE, alpha_size, |
| 553 GLInProcessContext::DEPTH_SIZE, depth_size, | 574 GLInProcessContext::DEPTH_SIZE, depth_size, |
| 554 GLInProcessContext::STENCIL_SIZE, stencil_size, | 575 GLInProcessContext::STENCIL_SIZE, stencil_size, |
| 555 GLInProcessContext::SAMPLES, samples, | 576 GLInProcessContext::SAMPLES, samples, |
| 556 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers, | 577 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers, |
| 557 GLInProcessContext::NONE, | 578 GLInProcessContext::NONE, |
| 558 }; | 579 }; |
| 559 | 580 |
| 560 const char* preferred_extensions = "*"; | 581 const char* preferred_extensions = "*"; |
| 561 | 582 |
| 562 // TODO(kbr): More work will be needed in this implementation to | 583 // TODO(kbr): More work will be needed in this implementation to |
| 563 // properly support GPU switching. Like in the out-of-process | 584 // properly support GPU switching. Like in the out-of-process |
| 564 // command buffer implementation, all previously created contexts | 585 // command buffer implementation, all previously created contexts |
| 565 // will need to be lost either when the first context requesting the | 586 // will need to be lost either when the first context requesting the |
| 566 // discrete GPU is created, or the last one is destroyed. | 587 // discrete GPU is created, or the last one is destroyed. |
| 567 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 588 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| 568 | 589 |
| 590 GLInProcessContext* parent_context = NULL; |
| 591 if (view_context) { |
| 592 WebGraphicsContext3DInProcessCommandBufferImpl* context_impl = |
| 593 static_cast<WebGraphicsContext3DInProcessCommandBufferImpl*>( |
| 594 view_context); |
| 595 parent_context = context_impl->context_; |
| 596 } |
| 597 |
| 569 WebGraphicsContext3DInProcessCommandBufferImpl* context_group = NULL; | 598 WebGraphicsContext3DInProcessCommandBufferImpl* context_group = NULL; |
| 570 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 599 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 571 if (attributes_.shareResources) | 600 if (attributes.shareResources) |
| 572 context_group = g_all_shared_contexts.Pointer()->empty() ? | 601 context_group = g_all_shared_contexts.Pointer()->empty() ? |
| 573 NULL : *g_all_shared_contexts.Pointer()->begin(); | 602 NULL : *g_all_shared_contexts.Pointer()->begin(); |
| 574 | 603 |
| 575 context_ = GLInProcessContext::CreateOffscreenContext( | 604 context_ = GLInProcessContext::CreateOffscreenContext( |
| 605 parent_context, |
| 576 gfx::Size(1, 1), | 606 gfx::Size(1, 1), |
| 577 context_group ? context_group->context_ : NULL, | 607 context_group ? context_group->context_ : NULL, |
| 578 preferred_extensions, | 608 preferred_extensions, |
| 579 attribs, | 609 attribs, |
| 580 gpu_preference); | 610 gpu_preference); |
| 581 | 611 |
| 582 if (!context_) { | 612 if (!context_) |
| 583 initialize_failed_ = true; | |
| 584 return false; | 613 return false; |
| 585 } | |
| 586 | 614 |
| 587 gl_ = context_->GetImplementation(); | 615 gl_ = context_->GetImplementation(); |
| 588 | 616 |
| 589 if (gl_ && attributes_.noExtensions) | 617 if (gl_ && attributes.noExtensions) |
| 590 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); | 618 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); |
| 591 | 619 |
| 592 context_->SetContextLostCallback( | 620 context_->SetContextLostCallback( |
| 593 base::Bind( | 621 base::Bind( |
| 594 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, | 622 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, |
| 595 base::Unretained(this))); | 623 base::Unretained(this))); |
| 596 | 624 |
| 597 // Set attributes_ from created offscreen context. | 625 // Set attributes_ from created offscreen context. |
| 598 { | 626 { |
| 627 attributes_ = attributes; |
| 599 GLint alpha_bits = 0; | 628 GLint alpha_bits = 0; |
| 600 getIntegerv(GL_ALPHA_BITS, &alpha_bits); | 629 getIntegerv(GL_ALPHA_BITS, &alpha_bits); |
| 601 attributes_.alpha = alpha_bits > 0; | 630 attributes_.alpha = alpha_bits > 0; |
| 602 GLint depth_bits = 0; | 631 GLint depth_bits = 0; |
| 603 getIntegerv(GL_DEPTH_BITS, &depth_bits); | 632 getIntegerv(GL_DEPTH_BITS, &depth_bits); |
| 604 attributes_.depth = depth_bits > 0; | 633 attributes_.depth = depth_bits > 0; |
| 605 GLint stencil_bits = 0; | 634 GLint stencil_bits = 0; |
| 606 getIntegerv(GL_STENCIL_BITS, &stencil_bits); | 635 getIntegerv(GL_STENCIL_BITS, &stencil_bits); |
| 607 attributes_.stencil = stencil_bits > 0; | 636 attributes_.stencil = stencil_bits > 0; |
| 608 GLint sample_buffers = 0; | 637 GLint sample_buffers = 0; |
| 609 getIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers); | 638 getIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers); |
| 610 attributes_.antialias = sample_buffers > 0; | 639 attributes_.antialias = sample_buffers > 0; |
| 611 } | 640 } |
| 641 makeContextCurrent(); |
| 612 | 642 |
| 613 if (attributes_.shareResources) | 643 if (attributes.shareResources) |
| 614 g_all_shared_contexts.Pointer()->insert(this); | 644 g_all_shared_contexts.Pointer()->insert(this); |
| 615 | 645 |
| 616 initialized_ = true; | |
| 617 return true; | 646 return true; |
| 618 } | 647 } |
| 619 | 648 |
| 620 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { | 649 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { |
| 621 if (!MaybeInitializeGL()) | |
| 622 return false; | |
| 623 | |
| 624 return GLInProcessContext::MakeCurrent(context_); | 650 return GLInProcessContext::MakeCurrent(context_); |
| 625 } | 651 } |
| 626 | 652 |
| 627 void WebGraphicsContext3DInProcessCommandBufferImpl::ClearContext() { | 653 void WebGraphicsContext3DInProcessCommandBufferImpl::ClearContext() { |
| 628 // NOTE: Comment in the line below to check for code that is not calling | 654 // NOTE: Comment in the line below to check for code that is not calling |
| 629 // eglMakeCurrent where appropriate. The issue is code using | 655 // eglMakeCurrent where appropriate. The issue is code using |
| 630 // WebGraphicsContext3D does not need to call makeContextCurrent. Code using | 656 // WebGraphicsContext3D does not need to call makeContextCurrent. Code using |
| 631 // direct OpenGL bindings needs to call the appropriate form of | 657 // direct OpenGL bindings needs to call the appropriate form of |
| 632 // eglMakeCurrent. If it doesn't it will be issuing commands on the wrong | 658 // eglMakeCurrent. If it doesn't it will be issuing commands on the wrong |
| 633 // context. Uncommenting the line below clears the current context so that | 659 // context. Uncommenting the line below clears the current context so that |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) | 1684 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) |
| 1659 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, | 1685 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, |
| 1660 WGC3Denum, const WGC3Dbyte*) | 1686 WGC3Denum, const WGC3Dbyte*) |
| 1661 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, | 1687 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, |
| 1662 WGC3Denum, const WGC3Dbyte*) | 1688 WGC3Denum, const WGC3Dbyte*) |
| 1663 | 1689 |
| 1664 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, | 1690 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, |
| 1665 WGC3Dsizei, const WGC3Denum*) | 1691 WGC3Dsizei, const WGC3Denum*) |
| 1666 } // namespace gpu | 1692 } // namespace gpu |
| 1667 } // namespace webkit | 1693 } // namespace webkit |
| OLD | NEW |