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 GLuint* rb_depth_; | |
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 21 matching lines...) Expand all Loading... | |
496 GLSurfaceOzoneSurfacelessSurfaceImpl::SurfaceImage::~SurfaceImage() { | 498 GLSurfaceOzoneSurfacelessSurfaceImpl::SurfaceImage::~SurfaceImage() { |
497 } | 499 } |
498 | 500 |
499 GLSurfaceOzoneSurfacelessSurfaceImpl::GLSurfaceOzoneSurfacelessSurfaceImpl( | 501 GLSurfaceOzoneSurfacelessSurfaceImpl::GLSurfaceOzoneSurfacelessSurfaceImpl( |
500 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 502 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
501 AcceleratedWidget widget, | 503 AcceleratedWidget widget, |
502 const gfx::SurfaceConfiguration& requested_configuration) | 504 const gfx::SurfaceConfiguration& requested_configuration) |
503 : GLSurfaceOzoneSurfaceless( | 505 : GLSurfaceOzoneSurfaceless( |
504 ozone_surface.Pass(), widget, requested_configuration), | 506 ozone_surface.Pass(), widget, requested_configuration), |
505 fbo_(0), | 507 fbo_(0), |
508 rb_depth_(nullptr), | |
506 current_surface_(0) { | 509 current_surface_(0) { |
507 for (auto& texture : textures_) | 510 for (auto& texture : textures_) |
508 texture = 0; | 511 texture = 0; |
509 } | 512 } |
510 | 513 |
511 unsigned int | 514 unsigned int |
512 GLSurfaceOzoneSurfacelessSurfaceImpl::GetBackingFrameBufferObject() { | 515 GLSurfaceOzoneSurfacelessSurfaceImpl::GetBackingFrameBufferObject() { |
513 return fbo_; | 516 return fbo_; |
514 } | 517 } |
515 | 518 |
516 bool GLSurfaceOzoneSurfacelessSurfaceImpl::OnMakeCurrent(GLContext* context) { | 519 bool GLSurfaceOzoneSurfacelessSurfaceImpl::OnMakeCurrent(GLContext* context) { |
517 if (!fbo_) { | 520 if (!fbo_) { |
518 glGenFramebuffersEXT(1, &fbo_); | 521 glGenFramebuffersEXT(1, &fbo_); |
519 if (!fbo_) | 522 if (!fbo_) |
520 return false; | 523 return false; |
521 glGenTextures(arraysize(textures_), textures_); | 524 glGenTextures(arraysize(textures_), textures_); |
525 if (get_surface_configuration().depth_bits <= 16) { | |
526 rb_depth_ = new GLuint[kBuffers]; | |
527 glGenRenderbuffersEXT(kBuffers, rb_depth_); | |
528 } | |
522 if (!CreatePixmaps()) | 529 if (!CreatePixmaps()) |
523 return false; | 530 return false; |
524 } | 531 } |
525 BindFramebuffer(); | 532 BindFramebuffer(); |
526 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_); | 533 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_); |
527 return SurfacelessEGL::OnMakeCurrent(context); | 534 return SurfacelessEGL::OnMakeCurrent(context); |
528 } | 535 } |
529 | 536 |
530 bool GLSurfaceOzoneSurfacelessSurfaceImpl::Resize(const gfx::Size& size) { | 537 bool GLSurfaceOzoneSurfacelessSurfaceImpl::Resize(const gfx::Size& size) { |
531 if (size == GetSize()) | 538 if (size == GetSize()) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 } | 571 } |
565 | 572 |
566 void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { | 573 void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { |
567 GLContext* current_context = GLContext::GetCurrent(); | 574 GLContext* current_context = GLContext::GetCurrent(); |
568 DCHECK(current_context && current_context->IsCurrent(this)); | 575 DCHECK(current_context && current_context->IsCurrent(this)); |
569 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); | 576 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
570 if (fbo_) { | 577 if (fbo_) { |
571 glDeleteTextures(arraysize(textures_), textures_); | 578 glDeleteTextures(arraysize(textures_), textures_); |
572 for (auto& texture : textures_) | 579 for (auto& texture : textures_) |
573 texture = 0; | 580 texture = 0; |
581 if (rb_depth_) { | |
582 glDeleteRenderbuffersEXT(kBuffers, rb_depth_); | |
583 delete rb_depth_; | |
jamesr
2015/09/10 00:38:21
you called operator new[] so you can't call operat
cdotstout
2015/09/10 18:19:47
Done.
| |
584 rb_depth_ = nullptr; | |
jamesr
2015/09/10 00:38:21
a real smart pointer will handle this for you too
cdotstout
2015/09/10 18:19:47
Done.
| |
585 } | |
574 glDeleteFramebuffersEXT(1, &fbo_); | 586 glDeleteFramebuffersEXT(1, &fbo_); |
575 fbo_ = 0; | 587 fbo_ = 0; |
576 } | 588 } |
577 for (auto image : images_) { | 589 for (auto image : images_) { |
578 if (image) | 590 if (image) |
579 image->Destroy(true); | 591 image->Destroy(true); |
580 } | 592 } |
581 } | 593 } |
582 | 594 |
583 GLSurfaceOzoneSurfacelessSurfaceImpl::~GLSurfaceOzoneSurfacelessSurfaceImpl() { | 595 GLSurfaceOzoneSurfacelessSurfaceImpl::~GLSurfaceOzoneSurfacelessSurfaceImpl() { |
584 DCHECK(!fbo_); | 596 DCHECK(!fbo_); |
585 for (size_t i = 0; i < arraysize(textures_); i++) | 597 for (size_t i = 0; i < arraysize(textures_); i++) |
586 DCHECK(!textures_[i]) << "texture " << i << " not released"; | 598 DCHECK(!textures_[i]) << "texture " << i << " not released"; |
599 DCHECK(!rb_depth_); | |
587 } | 600 } |
588 | 601 |
589 void GLSurfaceOzoneSurfacelessSurfaceImpl::BindFramebuffer() { | 602 void GLSurfaceOzoneSurfacelessSurfaceImpl::BindFramebuffer() { |
590 ScopedFrameBufferBinder fb(fbo_); | 603 ScopedFrameBufferBinder fb(fbo_); |
591 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 604 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
592 textures_[current_surface_], 0); | 605 textures_[current_surface_], 0); |
606 if (rb_depth_) { | |
607 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, | |
608 GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb_depth_[current_surface_]); | |
609 } | |
593 } | 610 } |
594 | 611 |
595 bool GLSurfaceOzoneSurfacelessSurfaceImpl::CreatePixmaps() { | 612 bool GLSurfaceOzoneSurfacelessSurfaceImpl::CreatePixmaps() { |
596 if (!fbo_) | 613 if (!fbo_) |
597 return true; | 614 return true; |
598 for (size_t i = 0; i < arraysize(textures_); i++) { | 615 for (size_t i = 0; i < arraysize(textures_); i++) { |
599 scoped_refptr<ui::NativePixmap> pixmap = | 616 scoped_refptr<ui::NativePixmap> pixmap = |
600 ui::OzonePlatform::GetInstance() | 617 ui::OzonePlatform::GetInstance() |
601 ->GetSurfaceFactoryOzone() | 618 ->GetSurfaceFactoryOzone() |
602 ->CreateNativePixmap(widget_, GetSize(), | 619 ->CreateNativePixmap(widget_, GetSize(), |
603 ui::SurfaceFactoryOzone::BGRA_8888, | 620 ui::SurfaceFactoryOzone::BGRA_8888, |
604 ui::SurfaceFactoryOzone::SCANOUT); | 621 ui::SurfaceFactoryOzone::SCANOUT); |
605 if (!pixmap) | 622 if (!pixmap) |
606 return false; | 623 return false; |
607 scoped_refptr<SurfaceImage> image = | 624 scoped_refptr<SurfaceImage> image = |
608 new SurfaceImage(GetSize(), GL_BGRA_EXT); | 625 new SurfaceImage(GetSize(), GL_BGRA_EXT); |
609 if (!image->Initialize(pixmap, gfx::GpuMemoryBuffer::Format::BGRA_8888)) | 626 if (!image->Initialize(pixmap, gfx::GpuMemoryBuffer::Format::BGRA_8888)) |
610 return false; | 627 return false; |
611 if (images_[i]) | 628 if (images_[i]) |
612 images_[i]->Destroy(true); | 629 images_[i]->Destroy(true); |
613 images_[i] = image; | 630 images_[i] = image; |
614 // Bind image to texture. | 631 // Bind image to texture. |
615 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); | 632 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); |
616 | 633 |
617 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) | 634 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) |
618 return false; | 635 return false; |
619 } | 636 } |
637 if (rb_depth_) { | |
638 for (size_t i = 0; i < kBuffers; i++) { | |
639 glBindRenderbufferEXT(GL_RENDERBUFFER, rb_depth_[i]); | |
640 glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, | |
641 GetSize().width(), GetSize().height()); | |
642 } | |
643 } | |
620 return true; | 644 return true; |
621 } | 645 } |
622 | 646 |
623 } // namespace | 647 } // namespace |
624 | 648 |
625 // static | 649 // static |
626 bool GLSurface::InitializeOneOffInternal() { | 650 bool GLSurface::InitializeOneOffInternal() { |
627 switch (GetGLImplementation()) { | 651 switch (GetGLImplementation()) { |
628 case kGLImplementationEGLGLES2: | 652 case kGLImplementationEGLGLES2: |
629 if (!GLSurfaceEGL::InitializeOneOff()) { | 653 if (!GLSurfaceEGL::InitializeOneOff()) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 } | 773 } |
750 } | 774 } |
751 | 775 |
752 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 776 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
753 return ui::OzonePlatform::GetInstance() | 777 return ui::OzonePlatform::GetInstance() |
754 ->GetSurfaceFactoryOzone() | 778 ->GetSurfaceFactoryOzone() |
755 ->GetNativeDisplay(); | 779 ->GetNativeDisplay(); |
756 } | 780 } |
757 | 781 |
758 } // namespace gfx | 782 } // namespace gfx |
OLD | NEW |