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