| 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" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/worker_pool.h" | 14 #include "base/threading/worker_pool.h" |
| 15 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
| 16 #include "ui/gl/gl_context.h" | 16 #include "ui/gl/gl_context.h" |
| 17 #include "ui/gl/gl_image.h" | 17 #include "ui/gl/gl_image.h" |
| 18 #include "ui/gl/gl_image_linux_dma_buffer.h" | 18 #include "ui/gl/gl_image_linux_dma_buffer.h" |
| 19 #include "ui/gl/gl_implementation.h" | 19 #include "ui/gl/gl_implementation.h" |
| 20 #include "ui/gl/gl_surface_egl.h" | 20 #include "ui/gl/gl_surface_egl.h" |
| 21 #include "ui/gl/gl_surface_osmesa.h" | 21 #include "ui/gl/gl_surface_osmesa.h" |
| 22 #include "ui/gl/gl_surface_stub.h" | 22 #include "ui/gl/gl_surface_stub.h" |
| 23 #include "ui/gl/scoped_binders.h" | 23 #include "ui/gl/scoped_binders.h" |
| 24 #include "ui/gl/scoped_make_current.h" | 24 #include "ui/gl/scoped_make_current.h" |
| 25 #include "ui/ozone/public/native_pixmap.h" | 25 #include "ui/ozone/public/native_pixmap.h" |
| 26 #include "ui/ozone/public/ozone_platform.h" | |
| 27 #include "ui/ozone/public/surface_factory_ozone.h" | 26 #include "ui/ozone/public/surface_factory_ozone.h" |
| 28 #include "ui/ozone/public/surface_ozone_egl.h" | 27 #include "ui/ozone/public/surface_ozone_egl.h" |
| 29 | 28 |
| 30 namespace gfx { | 29 namespace gfx { |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 void WaitForFence(EGLDisplay display, EGLSyncKHR fence) { | 33 void WaitForFence(EGLDisplay display, EGLSyncKHR fence) { |
| 35 eglClientWaitSyncKHR(display, fence, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, | 34 eglClientWaitSyncKHR(display, fence, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, |
| 36 EGL_FOREVER_KHR); | 35 EGL_FOREVER_KHR); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 111 |
| 113 bool GLSurfaceOzoneEGL::ReinitializeNativeSurface() { | 112 bool GLSurfaceOzoneEGL::ReinitializeNativeSurface() { |
| 114 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; | 113 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
| 115 GLContext* current_context = GLContext::GetCurrent(); | 114 GLContext* current_context = GLContext::GetCurrent(); |
| 116 bool was_current = current_context && current_context->IsCurrent(this); | 115 bool was_current = current_context && current_context->IsCurrent(this); |
| 117 if (was_current) { | 116 if (was_current) { |
| 118 scoped_make_current.reset(new ui::ScopedMakeCurrent(current_context, this)); | 117 scoped_make_current.reset(new ui::ScopedMakeCurrent(current_context, this)); |
| 119 } | 118 } |
| 120 | 119 |
| 121 Destroy(); | 120 Destroy(); |
| 122 ozone_surface_ = ui::OzonePlatform::GetInstance() | 121 ozone_surface_ = ui::SurfaceFactoryOzone::GetInstance() |
| 123 ->GetSurfaceFactoryOzone() | |
| 124 ->CreateEGLSurfaceForWidget(widget_) | 122 ->CreateEGLSurfaceForWidget(widget_) |
| 125 .Pass(); | 123 .Pass(); |
| 126 if (!ozone_surface_) { | 124 if (!ozone_surface_) { |
| 127 LOG(ERROR) << "Failed to create native surface."; | 125 LOG(ERROR) << "Failed to create native surface."; |
| 128 return false; | 126 return false; |
| 129 } | 127 } |
| 130 | 128 |
| 131 window_ = ozone_surface_->GetNativeWindow(); | 129 window_ = ozone_surface_->GetNativeWindow(); |
| 132 if (!Initialize()) { | 130 if (!Initialize()) { |
| 133 LOG(ERROR) << "Failed to initialize."; | 131 LOG(ERROR) << "Failed to initialize."; |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 return false; | 471 return false; |
| 474 pixmap_ = pixmap; | 472 pixmap_ = pixmap; |
| 475 return true; | 473 return true; |
| 476 } | 474 } |
| 477 bool GLSurfaceOzoneSurfacelessSurfaceImpl::SurfaceImage::ScheduleOverlayPlane( | 475 bool GLSurfaceOzoneSurfacelessSurfaceImpl::SurfaceImage::ScheduleOverlayPlane( |
| 478 gfx::AcceleratedWidget widget, | 476 gfx::AcceleratedWidget widget, |
| 479 int z_order, | 477 int z_order, |
| 480 gfx::OverlayTransform transform, | 478 gfx::OverlayTransform transform, |
| 481 const gfx::Rect& bounds_rect, | 479 const gfx::Rect& bounds_rect, |
| 482 const gfx::RectF& crop_rect) { | 480 const gfx::RectF& crop_rect) { |
| 483 return ui::OzonePlatform::GetInstance() | 481 return ui::SurfaceFactoryOzone::GetInstance()->ScheduleOverlayPlane( |
| 484 ->GetSurfaceFactoryOzone() | 482 widget, z_order, transform, pixmap_, bounds_rect, crop_rect); |
| 485 ->ScheduleOverlayPlane(widget, z_order, transform, pixmap_, bounds_rect, | |
| 486 crop_rect); | |
| 487 } | 483 } |
| 488 | 484 |
| 489 GLSurfaceOzoneSurfacelessSurfaceImpl::SurfaceImage::~SurfaceImage() { | 485 GLSurfaceOzoneSurfacelessSurfaceImpl::SurfaceImage::~SurfaceImage() { |
| 490 } | 486 } |
| 491 | 487 |
| 492 GLSurfaceOzoneSurfacelessSurfaceImpl::GLSurfaceOzoneSurfacelessSurfaceImpl( | 488 GLSurfaceOzoneSurfacelessSurfaceImpl::GLSurfaceOzoneSurfacelessSurfaceImpl( |
| 493 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 489 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 494 AcceleratedWidget widget) | 490 AcceleratedWidget widget) |
| 495 : GLSurfaceOzoneSurfaceless(ozone_surface.Pass(), widget), | 491 : GLSurfaceOzoneSurfaceless(ozone_surface.Pass(), widget), |
| 496 fbo_(0), | 492 fbo_(0), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 ScopedFrameBufferBinder fb(fbo_); | 577 ScopedFrameBufferBinder fb(fbo_); |
| 582 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 578 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 583 textures_[current_surface_], 0); | 579 textures_[current_surface_], 0); |
| 584 } | 580 } |
| 585 | 581 |
| 586 bool GLSurfaceOzoneSurfacelessSurfaceImpl::CreatePixmaps() { | 582 bool GLSurfaceOzoneSurfacelessSurfaceImpl::CreatePixmaps() { |
| 587 if (!fbo_) | 583 if (!fbo_) |
| 588 return true; | 584 return true; |
| 589 for (size_t i = 0; i < arraysize(textures_); i++) { | 585 for (size_t i = 0; i < arraysize(textures_); i++) { |
| 590 scoped_refptr<ui::NativePixmap> pixmap = | 586 scoped_refptr<ui::NativePixmap> pixmap = |
| 591 ui::OzonePlatform::GetInstance() | 587 ui::SurfaceFactoryOzone::GetInstance()->CreateNativePixmap( |
| 592 ->GetSurfaceFactoryOzone() | 588 widget_, GetSize(), ui::SurfaceFactoryOzone::BGRA_8888, |
| 593 ->CreateNativePixmap(widget_, GetSize(), | 589 ui::SurfaceFactoryOzone::SCANOUT); |
| 594 ui::SurfaceFactoryOzone::BGRA_8888, | |
| 595 ui::SurfaceFactoryOzone::SCANOUT); | |
| 596 if (!pixmap) | 590 if (!pixmap) |
| 597 return false; | 591 return false; |
| 598 scoped_refptr<SurfaceImage> image = | 592 scoped_refptr<SurfaceImage> image = |
| 599 new SurfaceImage(GetSize(), GL_BGRA_EXT); | 593 new SurfaceImage(GetSize(), GL_BGRA_EXT); |
| 600 if (!image->Initialize(pixmap, gfx::GpuMemoryBuffer::Format::BGRA_8888)) | 594 if (!image->Initialize(pixmap, gfx::GpuMemoryBuffer::Format::BGRA_8888)) |
| 601 return false; | 595 return false; |
| 602 images_[i] = image; | 596 images_[i] = image; |
| 603 // Bind image to texture. | 597 // Bind image to texture. |
| 604 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); | 598 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); |
| 605 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) | 599 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 627 return false; | 621 return false; |
| 628 } | 622 } |
| 629 } | 623 } |
| 630 | 624 |
| 631 // static | 625 // static |
| 632 scoped_refptr<GLSurface> GLSurface::CreateSurfacelessViewGLSurface( | 626 scoped_refptr<GLSurface> GLSurface::CreateSurfacelessViewGLSurface( |
| 633 gfx::AcceleratedWidget window) { | 627 gfx::AcceleratedWidget window) { |
| 634 if (GetGLImplementation() == kGLImplementationEGLGLES2 && | 628 if (GetGLImplementation() == kGLImplementationEGLGLES2 && |
| 635 window != kNullAcceleratedWidget && | 629 window != kNullAcceleratedWidget && |
| 636 GLSurfaceEGL::IsEGLSurfacelessContextSupported() && | 630 GLSurfaceEGL::IsEGLSurfacelessContextSupported() && |
| 637 ui::OzonePlatform::GetInstance() | 631 ui::SurfaceFactoryOzone::GetInstance()->CanShowPrimaryPlaneAsOverlay()) { |
| 638 ->GetSurfaceFactoryOzone() | |
| 639 ->CanShowPrimaryPlaneAsOverlay()) { | |
| 640 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 632 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 641 ui::OzonePlatform::GetInstance() | 633 ui::SurfaceFactoryOzone::GetInstance() |
| 642 ->GetSurfaceFactoryOzone() | |
| 643 ->CreateSurfacelessEGLSurfaceForWidget(window); | 634 ->CreateSurfacelessEGLSurfaceForWidget(window); |
| 644 if (!surface_ozone) | 635 if (!surface_ozone) |
| 645 return nullptr; | 636 return nullptr; |
| 646 scoped_refptr<GLSurface> surface; | 637 scoped_refptr<GLSurface> surface; |
| 647 surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window); | 638 surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window); |
| 648 if (surface->Initialize()) | 639 if (surface->Initialize()) |
| 649 return surface; | 640 return surface; |
| 650 } | 641 } |
| 651 | 642 |
| 652 return nullptr; | 643 return nullptr; |
| 653 } | 644 } |
| 654 | 645 |
| 655 // static | 646 // static |
| 656 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 647 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 657 gfx::AcceleratedWidget window) { | 648 gfx::AcceleratedWidget window) { |
| 658 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | 649 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 659 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | 650 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 660 if (!surface->Initialize()) | 651 if (!surface->Initialize()) |
| 661 return NULL; | 652 return NULL; |
| 662 return surface; | 653 return surface; |
| 663 } | 654 } |
| 664 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 655 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| 665 if (window != kNullAcceleratedWidget) { | 656 if (window != kNullAcceleratedWidget) { |
| 666 scoped_refptr<GLSurface> surface; | 657 scoped_refptr<GLSurface> surface; |
| 667 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && | 658 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && |
| 668 ui::OzonePlatform::GetInstance() | 659 ui::SurfaceFactoryOzone::GetInstance() |
| 669 ->GetSurfaceFactoryOzone() | |
| 670 ->CanShowPrimaryPlaneAsOverlay()) { | 660 ->CanShowPrimaryPlaneAsOverlay()) { |
| 671 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 661 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 672 ui::OzonePlatform::GetInstance() | 662 ui::SurfaceFactoryOzone::GetInstance() |
| 673 ->GetSurfaceFactoryOzone() | |
| 674 ->CreateSurfacelessEGLSurfaceForWidget(window); | 663 ->CreateSurfacelessEGLSurfaceForWidget(window); |
| 675 if (!surface_ozone) | 664 if (!surface_ozone) |
| 676 return NULL; | 665 return NULL; |
| 677 surface = new GLSurfaceOzoneSurfacelessSurfaceImpl(surface_ozone.Pass(), | 666 surface = new GLSurfaceOzoneSurfacelessSurfaceImpl(surface_ozone.Pass(), |
| 678 window); | 667 window); |
| 679 } else { | 668 } else { |
| 680 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 669 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 681 ui::OzonePlatform::GetInstance() | 670 ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( |
| 682 ->GetSurfaceFactoryOzone() | 671 window); |
| 683 ->CreateEGLSurfaceForWidget(window); | |
| 684 if (!surface_ozone) | 672 if (!surface_ozone) |
| 685 return NULL; | 673 return NULL; |
| 686 | 674 |
| 687 surface = new GLSurfaceOzoneEGL(surface_ozone.Pass(), window); | 675 surface = new GLSurfaceOzoneEGL(surface_ozone.Pass(), window); |
| 688 } | 676 } |
| 689 if (!surface->Initialize()) | 677 if (!surface->Initialize()) |
| 690 return NULL; | 678 return NULL; |
| 691 return surface; | 679 return surface; |
| 692 } else { | 680 } else { |
| 693 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); | 681 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 723 } | 711 } |
| 724 case kGLImplementationMockGL: | 712 case kGLImplementationMockGL: |
| 725 return new GLSurfaceStub; | 713 return new GLSurfaceStub; |
| 726 default: | 714 default: |
| 727 NOTREACHED(); | 715 NOTREACHED(); |
| 728 return NULL; | 716 return NULL; |
| 729 } | 717 } |
| 730 } | 718 } |
| 731 | 719 |
| 732 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 720 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 733 return ui::OzonePlatform::GetInstance() | 721 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
| 734 ->GetSurfaceFactoryOzone() | |
| 735 ->GetNativeDisplay(); | |
| 736 } | 722 } |
| 737 | 723 |
| 738 } // namespace gfx | 724 } // namespace gfx |
| OLD | NEW |