OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/gl/gl_surface.h" | 5 #include "ui/gl/gl_surface.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 ~SurfaceImage() override; | 453 ~SurfaceImage() override; |
454 | 454 |
455 scoped_refptr<ui::NativePixmap> pixmap_; | 455 scoped_refptr<ui::NativePixmap> pixmap_; |
456 }; | 456 }; |
457 | 457 |
458 ~GLSurfaceOzoneSurfacelessSurfaceImpl() override; | 458 ~GLSurfaceOzoneSurfacelessSurfaceImpl() override; |
459 | 459 |
460 void BindFramebuffer(); | 460 void BindFramebuffer(); |
461 bool CreatePixmaps(); | 461 bool CreatePixmaps(); |
462 | 462 |
463 static const int kBuffers = 2; | |
463 GLuint fbo_; | 464 GLuint fbo_; |
464 GLuint textures_[2]; | 465 GLuint textures_[kBuffers]; |
466 std::unique_ptr<GLuint[]> rb_depth_; | |
jamesr
2015/09/10 18:22:27
add #include <memory> for this
| |
465 scoped_refptr<GLImage> images_[2]; | 467 scoped_refptr<GLImage> images_[2]; |
466 int current_surface_; | 468 int current_surface_; |
467 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfacelessSurfaceImpl); | 469 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfacelessSurfaceImpl); |
468 }; | 470 }; |
469 | 471 |
470 GLSurfaceOzoneSurfacelessSurfaceImpl::SurfaceImage::SurfaceImage( | 472 GLSurfaceOzoneSurfacelessSurfaceImpl::SurfaceImage::SurfaceImage( |
471 const gfx::Size& size, | 473 const gfx::Size& size, |
472 unsigned internalformat) | 474 unsigned internalformat) |
473 : GLImageLinuxDMABuffer(size, internalformat) { | 475 : GLImageLinuxDMABuffer(size, internalformat) { |
474 } | 476 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 GLSurfaceOzoneSurfacelessSurfaceImpl::GetBackingFrameBufferObject() { | 514 GLSurfaceOzoneSurfacelessSurfaceImpl::GetBackingFrameBufferObject() { |
513 return fbo_; | 515 return fbo_; |
514 } | 516 } |
515 | 517 |
516 bool GLSurfaceOzoneSurfacelessSurfaceImpl::OnMakeCurrent(GLContext* context) { | 518 bool GLSurfaceOzoneSurfacelessSurfaceImpl::OnMakeCurrent(GLContext* context) { |
517 if (!fbo_) { | 519 if (!fbo_) { |
518 glGenFramebuffersEXT(1, &fbo_); | 520 glGenFramebuffersEXT(1, &fbo_); |
519 if (!fbo_) | 521 if (!fbo_) |
520 return false; | 522 return false; |
521 glGenTextures(arraysize(textures_), textures_); | 523 glGenTextures(arraysize(textures_), textures_); |
524 if (get_surface_configuration().depth_bits <= 16) { | |
525 rb_depth_.reset(new GLuint[kBuffers]); | |
526 glGenRenderbuffersEXT(kBuffers, rb_depth_.get()); | |
527 } | |
522 if (!CreatePixmaps()) | 528 if (!CreatePixmaps()) |
523 return false; | 529 return false; |
524 } | 530 } |
525 BindFramebuffer(); | 531 BindFramebuffer(); |
526 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_); | 532 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_); |
527 return SurfacelessEGL::OnMakeCurrent(context); | 533 return SurfacelessEGL::OnMakeCurrent(context); |
528 } | 534 } |
529 | 535 |
530 bool GLSurfaceOzoneSurfacelessSurfaceImpl::Resize(const gfx::Size& size) { | 536 bool GLSurfaceOzoneSurfacelessSurfaceImpl::Resize(const gfx::Size& size) { |
531 if (size == GetSize()) | 537 if (size == GetSize()) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 } | 570 } |
565 | 571 |
566 void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { | 572 void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { |
567 GLContext* current_context = GLContext::GetCurrent(); | 573 GLContext* current_context = GLContext::GetCurrent(); |
568 DCHECK(current_context && current_context->IsCurrent(this)); | 574 DCHECK(current_context && current_context->IsCurrent(this)); |
569 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); | 575 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
570 if (fbo_) { | 576 if (fbo_) { |
571 glDeleteTextures(arraysize(textures_), textures_); | 577 glDeleteTextures(arraysize(textures_), textures_); |
572 for (auto& texture : textures_) | 578 for (auto& texture : textures_) |
573 texture = 0; | 579 texture = 0; |
580 if (rb_depth_) { | |
581 glDeleteRenderbuffersEXT(kBuffers, rb_depth_.get()); | |
582 rb_depth_.reset(); | |
583 } | |
574 glDeleteFramebuffersEXT(1, &fbo_); | 584 glDeleteFramebuffersEXT(1, &fbo_); |
575 fbo_ = 0; | 585 fbo_ = 0; |
576 } | 586 } |
577 for (auto image : images_) { | 587 for (auto image : images_) { |
578 if (image) | 588 if (image) |
579 image->Destroy(true); | 589 image->Destroy(true); |
580 } | 590 } |
581 } | 591 } |
582 | 592 |
583 GLSurfaceOzoneSurfacelessSurfaceImpl::~GLSurfaceOzoneSurfacelessSurfaceImpl() { | 593 GLSurfaceOzoneSurfacelessSurfaceImpl::~GLSurfaceOzoneSurfacelessSurfaceImpl() { |
584 DCHECK(!fbo_); | 594 DCHECK(!fbo_); |
585 for (size_t i = 0; i < arraysize(textures_); i++) | 595 for (size_t i = 0; i < arraysize(textures_); i++) |
586 DCHECK(!textures_[i]) << "texture " << i << " not released"; | 596 DCHECK(!textures_[i]) << "texture " << i << " not released"; |
597 DCHECK(!rb_depth_); | |
587 } | 598 } |
588 | 599 |
589 void GLSurfaceOzoneSurfacelessSurfaceImpl::BindFramebuffer() { | 600 void GLSurfaceOzoneSurfacelessSurfaceImpl::BindFramebuffer() { |
590 ScopedFrameBufferBinder fb(fbo_); | 601 ScopedFrameBufferBinder fb(fbo_); |
591 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 602 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
592 textures_[current_surface_], 0); | 603 textures_[current_surface_], 0); |
604 if (rb_depth_) { | |
605 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, | |
606 GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb_depth_[current_surface_]); | |
607 } | |
593 } | 608 } |
594 | 609 |
595 bool GLSurfaceOzoneSurfacelessSurfaceImpl::CreatePixmaps() { | 610 bool GLSurfaceOzoneSurfacelessSurfaceImpl::CreatePixmaps() { |
596 if (!fbo_) | 611 if (!fbo_) |
597 return true; | 612 return true; |
598 for (size_t i = 0; i < arraysize(textures_); i++) { | 613 for (size_t i = 0; i < arraysize(textures_); i++) { |
599 scoped_refptr<ui::NativePixmap> pixmap = | 614 scoped_refptr<ui::NativePixmap> pixmap = |
600 ui::OzonePlatform::GetInstance() | 615 ui::OzonePlatform::GetInstance() |
601 ->GetSurfaceFactoryOzone() | 616 ->GetSurfaceFactoryOzone() |
602 ->CreateNativePixmap(widget_, GetSize(), | 617 ->CreateNativePixmap(widget_, GetSize(), |
603 ui::SurfaceFactoryOzone::BGRA_8888, | 618 ui::SurfaceFactoryOzone::BGRA_8888, |
604 ui::SurfaceFactoryOzone::SCANOUT); | 619 ui::SurfaceFactoryOzone::SCANOUT); |
605 if (!pixmap) | 620 if (!pixmap) |
606 return false; | 621 return false; |
607 scoped_refptr<SurfaceImage> image = | 622 scoped_refptr<SurfaceImage> image = |
608 new SurfaceImage(GetSize(), GL_BGRA_EXT); | 623 new SurfaceImage(GetSize(), GL_BGRA_EXT); |
609 if (!image->Initialize(pixmap, gfx::GpuMemoryBuffer::Format::BGRA_8888)) | 624 if (!image->Initialize(pixmap, gfx::GpuMemoryBuffer::Format::BGRA_8888)) |
610 return false; | 625 return false; |
611 if (images_[i]) | 626 if (images_[i]) |
612 images_[i]->Destroy(true); | 627 images_[i]->Destroy(true); |
613 images_[i] = image; | 628 images_[i] = image; |
614 // Bind image to texture. | 629 // Bind image to texture. |
615 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); | 630 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); |
616 | 631 |
617 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) | 632 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) |
618 return false; | 633 return false; |
619 } | 634 } |
635 if (rb_depth_) { | |
636 for (size_t i = 0; i < kBuffers; i++) { | |
637 glBindRenderbufferEXT(GL_RENDERBUFFER, rb_depth_[i]); | |
638 glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, | |
639 GetSize().width(), GetSize().height()); | |
640 } | |
641 } | |
620 return true; | 642 return true; |
621 } | 643 } |
622 | 644 |
623 } // namespace | 645 } // namespace |
624 | 646 |
625 // static | 647 // static |
626 bool GLSurface::InitializeOneOffInternal() { | 648 bool GLSurface::InitializeOneOffInternal() { |
627 switch (GetGLImplementation()) { | 649 switch (GetGLImplementation()) { |
628 case kGLImplementationEGLGLES2: | 650 case kGLImplementationEGLGLES2: |
629 if (!GLSurfaceEGL::InitializeOneOff()) { | 651 if (!GLSurfaceEGL::InitializeOneOff()) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 } | 771 } |
750 } | 772 } |
751 | 773 |
752 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 774 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
753 return ui::OzonePlatform::GetInstance() | 775 return ui::OzonePlatform::GetInstance() |
754 ->GetSurfaceFactoryOzone() | 776 ->GetSurfaceFactoryOzone() |
755 ->GetNativeDisplay(); | 777 ->GetNativeDisplay(); |
756 } | 778 } |
757 | 779 |
758 } // namespace gfx | 780 } // namespace gfx |
OLD | NEW |