| 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_ozone.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> |
| 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/callback.h" | 12 #include "base/callback.h" |
| 11 #include "base/location.h" | 13 #include "base/location.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/worker_pool.h" | 18 #include "base/threading/worker_pool.h" |
| 18 #include "ui/gfx/native_widget_types.h" | |
| 19 #include "ui/gl/egl_util.h" | 19 #include "ui/gl/egl_util.h" |
| 20 #include "ui/gl/gl_context.h" | 20 #include "ui/gl/gl_context.h" |
| 21 #include "ui/gl/gl_image.h" | 21 #include "ui/gl/gl_image.h" |
| 22 #include "ui/gl/gl_image_ozone_native_pixmap.h" | 22 #include "ui/gl/gl_image_ozone_native_pixmap.h" |
| 23 #include "ui/gl/gl_implementation.h" | 23 #include "ui/gl/gl_implementation.h" |
| 24 #include "ui/gl/gl_surface_egl.h" | 24 #include "ui/gl/gl_surface_egl.h" |
| 25 #include "ui/gl/gl_surface_osmesa.h" | 25 #include "ui/gl/gl_surface_osmesa.h" |
| 26 #include "ui/gl/gl_surface_overlay.h" | 26 #include "ui/gl/gl_surface_overlay.h" |
| 27 #include "ui/gl/gl_surface_stub.h" | 27 #include "ui/gl/gl_surface_stub.h" |
| 28 #include "ui/gl/scoped_binders.h" | 28 #include "ui/gl/scoped_binders.h" |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 images_[i]->Destroy(true); | 645 images_[i]->Destroy(true); |
| 646 images_[i] = image; | 646 images_[i] = image; |
| 647 // Bind image to texture. | 647 // Bind image to texture. |
| 648 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); | 648 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); |
| 649 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) | 649 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) |
| 650 return false; | 650 return false; |
| 651 } | 651 } |
| 652 return true; | 652 return true; |
| 653 } | 653 } |
| 654 | 654 |
| 655 } // namespace |
| 656 |
| 655 scoped_refptr<GLSurface> CreateViewGLSurfaceOzone( | 657 scoped_refptr<GLSurface> CreateViewGLSurfaceOzone( |
| 656 gfx::AcceleratedWidget window) { | 658 gfx::AcceleratedWidget window) { |
| 657 std::unique_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 659 std::unique_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 658 ui::OzonePlatform::GetInstance() | 660 ui::OzonePlatform::GetInstance() |
| 659 ->GetSurfaceFactoryOzone() | 661 ->GetSurfaceFactoryOzone() |
| 660 ->CreateEGLSurfaceForWidget(window); | 662 ->CreateEGLSurfaceForWidget(window); |
| 661 if (!surface_ozone) | 663 if (!surface_ozone) |
| 662 return nullptr; | 664 return nullptr; |
| 663 scoped_refptr<GLSurface> surface = | 665 return InitializeGLSurface( |
| 664 new GLSurfaceOzoneEGL(std::move(surface_ozone), window); | 666 new GLSurfaceOzoneEGL(std::move(surface_ozone), window)); |
| 665 if (!surface->Initialize()) | |
| 666 return nullptr; | |
| 667 return surface; | |
| 668 } | 667 } |
| 669 | 668 |
| 670 scoped_refptr<GLSurface> CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl( | 669 scoped_refptr<GLSurface> CreateViewGLSurfaceOzoneSurfaceless( |
| 671 gfx::AcceleratedWidget window) { | 670 gfx::AcceleratedWidget window) { |
| 672 std::unique_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 671 std::unique_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 673 ui::OzonePlatform::GetInstance() | 672 ui::OzonePlatform::GetInstance() |
| 674 ->GetSurfaceFactoryOzone() | 673 ->GetSurfaceFactoryOzone() |
| 675 ->CreateSurfacelessEGLSurfaceForWidget(window); | 674 ->CreateSurfacelessEGLSurfaceForWidget(window); |
| 676 if (!surface_ozone) | 675 if (!surface_ozone) |
| 677 return nullptr; | 676 return nullptr; |
| 678 scoped_refptr<GLSurface> surface = new GLSurfaceOzoneSurfacelessSurfaceImpl( | 677 return InitializeGLSurface( |
| 679 std::move(surface_ozone), window); | 678 new GLSurfaceOzoneSurfaceless(std::move(surface_ozone), window)); |
| 680 if (!surface->Initialize()) | |
| 681 return nullptr; | |
| 682 return surface; | |
| 683 } | 679 } |
| 684 | 680 |
| 685 } // namespace | 681 scoped_refptr<GLSurface> CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl( |
| 686 | |
| 687 // static | |
| 688 scoped_refptr<GLSurface> GLSurface::CreateSurfacelessViewGLSurface( | |
| 689 gfx::AcceleratedWidget window) { | 682 gfx::AcceleratedWidget window) { |
| 690 if (GetGLImplementation() == kGLImplementationEGLGLES2 && | 683 std::unique_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 691 window != gfx::kNullAcceleratedWidget && | 684 ui::OzonePlatform::GetInstance() |
| 692 GLSurfaceEGL::IsEGLSurfacelessContextSupported()) { | 685 ->GetSurfaceFactoryOzone() |
| 693 std::unique_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 686 ->CreateSurfacelessEGLSurfaceForWidget(window); |
| 694 ui::OzonePlatform::GetInstance() | 687 if (!surface_ozone) |
| 695 ->GetSurfaceFactoryOzone() | 688 return nullptr; |
| 696 ->CreateSurfacelessEGLSurfaceForWidget(window); | 689 return InitializeGLSurface(new GLSurfaceOzoneSurfacelessSurfaceImpl( |
| 697 if (!surface_ozone) | 690 std::move(surface_ozone), window)); |
| 698 return nullptr; | |
| 699 scoped_refptr<GLSurface> surface; | |
| 700 surface = new GLSurfaceOzoneSurfaceless(std::move(surface_ozone), window); | |
| 701 if (surface->Initialize()) | |
| 702 return surface; | |
| 703 } | |
| 704 | |
| 705 return nullptr; | |
| 706 } | |
| 707 | |
| 708 // static | |
| 709 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | |
| 710 gfx::AcceleratedWidget window) { | |
| 711 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | |
| 712 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | |
| 713 if (!surface->Initialize()) | |
| 714 return nullptr; | |
| 715 return surface; | |
| 716 } | |
| 717 if ((window != gfx::kNullAcceleratedWidget) && | |
| 718 (GetGLImplementation() == kGLImplementationEGLGLES2)) { | |
| 719 scoped_refptr<GLSurface> surface; | |
| 720 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported()) | |
| 721 surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window); | |
| 722 if (!surface) | |
| 723 surface = CreateViewGLSurfaceOzone(window); | |
| 724 return surface; | |
| 725 } else { | |
| 726 DCHECK_EQ(GetGLImplementation(), kGLImplementationMockGL); | |
| 727 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); | |
| 728 if (surface->Initialize()) | |
| 729 return surface; | |
| 730 } | |
| 731 return nullptr; | |
| 732 } | |
| 733 | |
| 734 // static | |
| 735 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( | |
| 736 const gfx::Size& size) { | |
| 737 switch (GetGLImplementation()) { | |
| 738 case kGLImplementationOSMesaGL: { | |
| 739 scoped_refptr<GLSurface> surface( | |
| 740 new GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, size)); | |
| 741 if (!surface->Initialize()) | |
| 742 return nullptr; | |
| 743 | |
| 744 return surface; | |
| 745 } | |
| 746 case kGLImplementationEGLGLES2: { | |
| 747 scoped_refptr<GLSurface> surface; | |
| 748 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && | |
| 749 (size.width() == 0 && size.height() == 0)) { | |
| 750 surface = new SurfacelessEGL(size); | |
| 751 } else { | |
| 752 surface = new PbufferGLSurfaceEGL(size); | |
| 753 } | |
| 754 | |
| 755 if (!surface->Initialize()) | |
| 756 return nullptr; | |
| 757 return surface; | |
| 758 } | |
| 759 case kGLImplementationMockGL: | |
| 760 return new GLSurfaceStub; | |
| 761 default: | |
| 762 NOTREACHED(); | |
| 763 return nullptr; | |
| 764 } | |
| 765 } | 691 } |
| 766 | 692 |
| 767 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 693 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 768 return ui::OzonePlatform::GetInstance() | 694 return ui::OzonePlatform::GetInstance() |
| 769 ->GetSurfaceFactoryOzone() | 695 ->GetSurfaceFactoryOzone() |
| 770 ->GetNativeDisplay(); | 696 ->GetNativeDisplay(); |
| 771 } | 697 } |
| 772 | 698 |
| 773 } // namespace gl | 699 } // namespace gl |
| OLD | NEW |