OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_egl.h" | 5 #include "ui/gl/gl_surface_egl.h" |
6 | 6 |
7 #if defined(OS_ANDROID) | 7 #if defined(OS_ANDROID) |
8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 } else if (vsync_override_) { | 670 } else if (vsync_override_) { |
671 // Only one window swapping, so let the normal vsync setting take over | 671 // Only one window swapping, so let the normal vsync setting take over |
672 eglSwapInterval(GetDisplay(), swap_interval_); | 672 eglSwapInterval(GetDisplay(), swap_interval_); |
673 vsync_override_ = false; | 673 vsync_override_ = false; |
674 } | 674 } |
675 | 675 |
676 swaps_this_generation_++; | 676 swaps_this_generation_++; |
677 } | 677 } |
678 #endif | 678 #endif |
679 | 679 |
680 if (!CommitAndClearPendingOverlays()) { | |
681 DVLOG(1) << "Failed to commit pending overlay planes."; | |
682 return gfx::SwapResult::SWAP_FAILED; | |
683 } | |
684 | |
680 if (!eglSwapBuffers(GetDisplay(), surface_)) { | 685 if (!eglSwapBuffers(GetDisplay(), surface_)) { |
681 DVLOG(1) << "eglSwapBuffers failed with error " | 686 DVLOG(1) << "eglSwapBuffers failed with error " |
682 << GetLastEGLErrorString(); | 687 << GetLastEGLErrorString(); |
683 return gfx::SwapResult::SWAP_FAILED; | 688 return gfx::SwapResult::SWAP_FAILED; |
684 } | 689 } |
685 | 690 |
686 return gfx::SwapResult::SWAP_ACK; | 691 return gfx::SwapResult::SWAP_ACK; |
687 } | 692 } |
688 | 693 |
689 gfx::Size NativeViewGLSurfaceEGL::GetSize() { | 694 gfx::Size NativeViewGLSurfaceEGL::GetSize() { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 | 745 |
741 bool NativeViewGLSurfaceEGL::SupportsPostSubBuffer() { | 746 bool NativeViewGLSurfaceEGL::SupportsPostSubBuffer() { |
742 return supports_post_sub_buffer_; | 747 return supports_post_sub_buffer_; |
743 } | 748 } |
744 | 749 |
745 gfx::SwapResult NativeViewGLSurfaceEGL::PostSubBuffer(int x, | 750 gfx::SwapResult NativeViewGLSurfaceEGL::PostSubBuffer(int x, |
746 int y, | 751 int y, |
747 int width, | 752 int width, |
748 int height) { | 753 int height) { |
749 DCHECK(supports_post_sub_buffer_); | 754 DCHECK(supports_post_sub_buffer_); |
755 if (!CommitAndClearPendingOverlays()) { | |
756 DVLOG(1) << "Failed to commit pending overlay planes."; | |
757 return gfx::SwapResult::SWAP_FAILED; | |
758 } | |
750 if (!eglPostSubBufferNV(GetDisplay(), surface_, x, y, width, height)) { | 759 if (!eglPostSubBufferNV(GetDisplay(), surface_, x, y, width, height)) { |
751 DVLOG(1) << "eglPostSubBufferNV failed with error " | 760 DVLOG(1) << "eglPostSubBufferNV failed with error " |
752 << GetLastEGLErrorString(); | 761 << GetLastEGLErrorString(); |
753 return gfx::SwapResult::SWAP_FAILED; | 762 return gfx::SwapResult::SWAP_FAILED; |
754 } | 763 } |
755 return gfx::SwapResult::SWAP_ACK; | 764 return gfx::SwapResult::SWAP_ACK; |
756 } | 765 } |
757 | 766 |
767 bool NativeViewGLSurfaceEGL::SupportsCommitOverlayPlanes() { | |
768 #if defined(OS_ANDROID) | |
769 return true; | |
770 #else | |
771 return false; | |
772 #endif | |
773 } | |
774 | |
775 gfx::SwapResult NativeViewGLSurfaceEGL::CommitOverlayPlanes() { | |
776 DCHECK(SupportsCommitOverlayPlanes()); | |
777 return CommitAndClearPendingOverlays() | |
778 ? gfx::SwapResult::SWAP_ACK | |
779 : gfx::SwapResult::SWAP_FAILED; | |
780 } | |
781 | |
758 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { | 782 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { |
759 return vsync_provider_.get(); | 783 return vsync_provider_.get(); |
760 } | 784 } |
761 | 785 |
762 bool NativeViewGLSurfaceEGL::ScheduleOverlayPlane(int z_order, | 786 bool NativeViewGLSurfaceEGL::ScheduleOverlayPlane(int z_order, |
763 OverlayTransform transform, | 787 OverlayTransform transform, |
764 gl::GLImage* image, | 788 gl::GLImage* image, |
765 const Rect& bounds_rect, | 789 const Rect& bounds_rect, |
766 const RectF& crop_rect) { | 790 const RectF& crop_rect) { |
767 #if defined(OS_ANDROID) | 791 #if !defined(OS_ANDROID) |
768 // Overlay planes are used on Android for fullscreen video. The image is | |
769 // expected to update the plane as soon as possible to display the video frame | |
770 // chosen for this vsync interval. | |
771 return image->ScheduleOverlayPlane(window_, z_order, transform, bounds_rect, | |
772 crop_rect); | |
773 #else | |
774 NOTIMPLEMENTED(); | 792 NOTIMPLEMENTED(); |
775 return false; | 793 return false; |
794 #else | |
795 pending_overlays_.push_back( | |
796 GLSurfaceOverlay(z_order, transform, image, bounds_rect, crop_rect)); | |
797 return true; | |
776 #endif | 798 #endif |
777 } | 799 } |
778 | 800 |
779 void NativeViewGLSurfaceEGL::OnSetSwapInterval(int interval) { | 801 void NativeViewGLSurfaceEGL::OnSetSwapInterval(int interval) { |
780 swap_interval_ = interval; | 802 swap_interval_ = interval; |
781 } | 803 } |
782 | 804 |
783 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { | 805 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { |
784 Destroy(); | 806 Destroy(); |
785 #if defined(OS_ANDROID) | 807 #if defined(OS_ANDROID) |
786 if (window_) | 808 if (window_) |
787 ANativeWindow_release(window_); | 809 ANativeWindow_release(window_); |
788 #endif | 810 #endif |
789 } | 811 } |
790 | 812 |
813 bool NativeViewGLSurfaceEGL::CommitAndClearPendingOverlays() { | |
814 if (pending_overlays_.empty()) | |
815 return true; | |
816 | |
817 bool success = true; | |
818 for (const auto& overlay : pending_overlays_) { | |
819 // In general |GLSurfaceOverlay::ScheduleOverlayPlane| only schedules the | |
820 // overlay to be shown at swap time, but here we assume that the overlays | |
821 // scheduled on this surface will display themselves to the screen right | |
822 // away. | |
watk
2015/12/01 01:55:55
How do you feel about this? It's not obvious how t
piman
2015/12/01 02:03:02
I'd move this comment to the CommitOverlayPlanes i
| |
823 success &= overlay.ScheduleOverlayPlane(window_); | |
824 } | |
825 pending_overlays_.clear(); | |
826 return success; | |
827 } | |
828 | |
791 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size) | 829 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size) |
792 : size_(size), | 830 : size_(size), |
793 surface_(NULL) { | 831 surface_(NULL) { |
794 // Some implementations of Pbuffer do not support having a 0 size. For such | 832 // Some implementations of Pbuffer do not support having a 0 size. For such |
795 // cases use a (1, 1) surface. | 833 // cases use a (1, 1) surface. |
796 if (size_.GetArea() == 0) | 834 if (size_.GetArea() == 0) |
797 size_.SetSize(1, 1); | 835 size_.SetSize(1, 1); |
798 } | 836 } |
799 | 837 |
800 bool PbufferGLSurfaceEGL::Initialize() { | 838 bool PbufferGLSurfaceEGL::Initialize() { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
955 } | 993 } |
956 | 994 |
957 void* SurfacelessEGL::GetShareHandle() { | 995 void* SurfacelessEGL::GetShareHandle() { |
958 return NULL; | 996 return NULL; |
959 } | 997 } |
960 | 998 |
961 SurfacelessEGL::~SurfacelessEGL() { | 999 SurfacelessEGL::~SurfacelessEGL() { |
962 } | 1000 } |
963 | 1001 |
964 } // namespace gfx | 1002 } // namespace gfx |
OLD | NEW |