Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc

Issue 12908004: Lazy initialize WGC3DInProcessCommandBufferImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 } 537 }
538 } 538 }
539 539
540 void GLInProcessContext::OnContextLost() { 540 void GLInProcessContext::OnContextLost() {
541 if (!context_lost_callback_.is_null()) 541 if (!context_lost_callback_.is_null())
542 context_lost_callback_.Run(); 542 context_lost_callback_.Run();
543 } 543 }
544 544
545 WebGraphicsContext3DInProcessCommandBufferImpl:: 545 WebGraphicsContext3DInProcessCommandBufferImpl::
546 WebGraphicsContext3DInProcessCommandBufferImpl() 546 WebGraphicsContext3DInProcessCommandBufferImpl()
547 : context_(NULL), 547 : pending_lazy_initialize_(false),
548 context_(NULL),
548 gl_(NULL), 549 gl_(NULL),
549 context_lost_callback_(NULL), 550 context_lost_callback_(NULL),
550 context_lost_reason_(GL_NO_ERROR), 551 context_lost_reason_(GL_NO_ERROR),
551 cached_width_(0), 552 cached_width_(0),
552 cached_height_(0), 553 cached_height_(0),
553 bound_fbo_(0) { 554 bound_fbo_(0) {
554 } 555 }
555 556
556 WebGraphicsContext3DInProcessCommandBufferImpl:: 557 WebGraphicsContext3DInProcessCommandBufferImpl::
557 ~WebGraphicsContext3DInProcessCommandBufferImpl() { 558 ~WebGraphicsContext3DInProcessCommandBufferImpl() {
558 base::AutoLock a(g_all_shared_contexts_lock.Get()); 559 base::AutoLock a(g_all_shared_contexts_lock.Get());
559 g_all_shared_contexts.Pointer()->erase(this); 560 g_all_shared_contexts.Pointer()->erase(this);
560 } 561 }
561 562
562 bool WebGraphicsContext3DInProcessCommandBufferImpl::Initialize( 563 bool WebGraphicsContext3DInProcessCommandBufferImpl::Initialize(
563 WebGraphicsContext3D::Attributes attributes, 564 const WebGraphicsContext3D::Attributes& attributes) {
564 WebKit::WebGraphicsContext3D* view_context) { 565 attributes_ = attributes;
566 pending_lazy_initialize_ = true;
567 return true;
piman 2013/03/21 22:29:11 If Initialize doesn't do anything any more and can
boliu 2013/03/21 22:53:23 Done.
568 }
569
570 bool WebGraphicsContext3DInProcessCommandBufferImpl::DoInitialize() {
571 DCHECK(pending_lazy_initialize_);
572
565 // Convert WebGL context creation attributes into GLInProcessContext / EGL 573 // Convert WebGL context creation attributes into GLInProcessContext / EGL
566 // size requests. 574 // size requests.
567 const int alpha_size = attributes.alpha ? 8 : 0; 575 const int alpha_size = attributes_.alpha ? 8 : 0;
568 const int depth_size = attributes.depth ? 24 : 0; 576 const int depth_size = attributes_.depth ? 24 : 0;
569 const int stencil_size = attributes.stencil ? 8 : 0; 577 const int stencil_size = attributes_.stencil ? 8 : 0;
570 const int samples = attributes.antialias ? 4 : 0; 578 const int samples = attributes_.antialias ? 4 : 0;
571 const int sample_buffers = attributes.antialias ? 1 : 0; 579 const int sample_buffers = attributes_.antialias ? 1 : 0;
572 const int32 attribs[] = { 580 const int32 attribs[] = {
573 GLInProcessContext::ALPHA_SIZE, alpha_size, 581 GLInProcessContext::ALPHA_SIZE, alpha_size,
574 GLInProcessContext::DEPTH_SIZE, depth_size, 582 GLInProcessContext::DEPTH_SIZE, depth_size,
575 GLInProcessContext::STENCIL_SIZE, stencil_size, 583 GLInProcessContext::STENCIL_SIZE, stencil_size,
576 GLInProcessContext::SAMPLES, samples, 584 GLInProcessContext::SAMPLES, samples,
577 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers, 585 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers,
578 GLInProcessContext::NONE, 586 GLInProcessContext::NONE,
579 }; 587 };
580 588
581 const char* preferred_extensions = "*"; 589 const char* preferred_extensions = "*";
582 590
583 // TODO(kbr): More work will be needed in this implementation to 591 // TODO(kbr): More work will be needed in this implementation to
584 // properly support GPU switching. Like in the out-of-process 592 // properly support GPU switching. Like in the out-of-process
585 // command buffer implementation, all previously created contexts 593 // command buffer implementation, all previously created contexts
586 // will need to be lost either when the first context requesting the 594 // will need to be lost either when the first context requesting the
587 // discrete GPU is created, or the last one is destroyed. 595 // discrete GPU is created, or the last one is destroyed.
588 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; 596 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
589 597
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
598 WebGraphicsContext3DInProcessCommandBufferImpl* context_group = NULL; 598 WebGraphicsContext3DInProcessCommandBufferImpl* context_group = NULL;
599 base::AutoLock lock(g_all_shared_contexts_lock.Get()); 599 base::AutoLock lock(g_all_shared_contexts_lock.Get());
600 if (attributes.shareResources) 600 if (attributes_.shareResources)
601 context_group = g_all_shared_contexts.Pointer()->empty() ? 601 context_group = g_all_shared_contexts.Pointer()->empty() ?
602 NULL : *g_all_shared_contexts.Pointer()->begin(); 602 NULL : *g_all_shared_contexts.Pointer()->begin();
603 603
604 context_ = GLInProcessContext::CreateOffscreenContext( 604 context_ = GLInProcessContext::CreateOffscreenContext(
605 parent_context, 605 NULL,
piman 2013/03/21 22:29:11 note: if we don't use parenting here any more, the
boliu 2013/03/21 22:53:23 Done.
606 gfx::Size(1, 1), 606 gfx::Size(1, 1),
607 context_group ? context_group->context_ : NULL, 607 context_group ? context_group->context_ : NULL,
608 preferred_extensions, 608 preferred_extensions,
609 attribs, 609 attribs,
610 gpu_preference); 610 gpu_preference);
611 611
612 if (!context_) 612 if (!context_)
613 return false; 613 return false;
614 614
615 gl_ = context_->GetImplementation(); 615 gl_ = context_->GetImplementation();
616 616
617 if (gl_ && attributes.noExtensions) 617 if (gl_ && attributes_.noExtensions)
618 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); 618 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
619 619
620 context_->SetContextLostCallback( 620 context_->SetContextLostCallback(
621 base::Bind( 621 base::Bind(
622 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, 622 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost,
623 base::Unretained(this))); 623 base::Unretained(this)));
624 624
625 // Set attributes_ from created offscreen context. 625 // Set attributes_ from created offscreen context.
626 { 626 {
627 attributes_ = attributes;
628 GLint alpha_bits = 0; 627 GLint alpha_bits = 0;
629 getIntegerv(GL_ALPHA_BITS, &alpha_bits); 628 getIntegerv(GL_ALPHA_BITS, &alpha_bits);
630 attributes_.alpha = alpha_bits > 0; 629 attributes_.alpha = alpha_bits > 0;
631 GLint depth_bits = 0; 630 GLint depth_bits = 0;
632 getIntegerv(GL_DEPTH_BITS, &depth_bits); 631 getIntegerv(GL_DEPTH_BITS, &depth_bits);
633 attributes_.depth = depth_bits > 0; 632 attributes_.depth = depth_bits > 0;
634 GLint stencil_bits = 0; 633 GLint stencil_bits = 0;
635 getIntegerv(GL_STENCIL_BITS, &stencil_bits); 634 getIntegerv(GL_STENCIL_BITS, &stencil_bits);
636 attributes_.stencil = stencil_bits > 0; 635 attributes_.stencil = stencil_bits > 0;
637 GLint sample_buffers = 0; 636 GLint sample_buffers = 0;
638 getIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers); 637 getIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers);
639 attributes_.antialias = sample_buffers > 0; 638 attributes_.antialias = sample_buffers > 0;
640 } 639 }
641 makeContextCurrent();
642 640
643 if (attributes.shareResources) 641 if (attributes_.shareResources)
644 g_all_shared_contexts.Pointer()->insert(this); 642 g_all_shared_contexts.Pointer()->insert(this);
645 643
644 pending_lazy_initialize_ = false;
646 return true; 645 return true;
647 } 646 }
648 647
649 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { 648 bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() {
649 if (pending_lazy_initialize_ && !DoInitialize())
650 return false;
651
650 return GLInProcessContext::MakeCurrent(context_); 652 return GLInProcessContext::MakeCurrent(context_);
651 } 653 }
652 654
653 void WebGraphicsContext3DInProcessCommandBufferImpl::ClearContext() { 655 void WebGraphicsContext3DInProcessCommandBufferImpl::ClearContext() {
654 // NOTE: Comment in the line below to check for code that is not calling 656 // NOTE: Comment in the line below to check for code that is not calling
655 // eglMakeCurrent where appropriate. The issue is code using 657 // eglMakeCurrent where appropriate. The issue is code using
656 // WebGraphicsContext3D does not need to call makeContextCurrent. Code using 658 // WebGraphicsContext3D does not need to call makeContextCurrent. Code using
657 // direct OpenGL bindings needs to call the appropriate form of 659 // direct OpenGL bindings needs to call the appropriate form of
658 // eglMakeCurrent. If it doesn't it will be issuing commands on the wrong 660 // eglMakeCurrent. If it doesn't it will be issuing commands on the wrong
659 // context. Uncommenting the line below clears the current context so that 661 // context. Uncommenting the line below clears the current context so that
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) 1686 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
1685 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, 1687 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
1686 WGC3Denum, const WGC3Dbyte*) 1688 WGC3Denum, const WGC3Dbyte*)
1687 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, 1689 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
1688 WGC3Denum, const WGC3Dbyte*) 1690 WGC3Denum, const WGC3Dbyte*)
1689 1691
1690 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, 1692 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT,
1691 WGC3Dsizei, const WGC3Denum*) 1693 WGC3Dsizei, const WGC3Denum*)
1692 } // namespace gpu 1694 } // namespace gpu
1693 } // namespace webkit 1695 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h ('k') | webkit/support/test_webkit_platform_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698