| 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 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" |
| 18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 19 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/sys_info.h" | 22 #include "base/sys_info.h" |
| 22 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
| 23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 24 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
| 25 #include "ui/gl/angle_platform_impl.h" | 26 #include "ui/gl/angle_platform_impl.h" |
| 26 #include "ui/gl/egl_util.h" | 27 #include "ui/gl/egl_util.h" |
| 27 #include "ui/gl/gl_context.h" | 28 #include "ui/gl/gl_context.h" |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 UMA_HISTOGRAM_ENUMERATION("GPU.EGLDisplayType", display_type, | 702 UMA_HISTOGRAM_ENUMERATION("GPU.EGLDisplayType", display_type, |
| 702 DISPLAY_TYPE_MAX); | 703 DISPLAY_TYPE_MAX); |
| 703 g_display = display; | 704 g_display = display; |
| 704 break; | 705 break; |
| 705 } | 706 } |
| 706 } | 707 } |
| 707 | 708 |
| 708 return g_display; | 709 return g_display; |
| 709 } | 710 } |
| 710 | 711 |
| 711 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) | 712 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL( |
| 713 EGLNativeWindowType window, |
| 714 std::unique_ptr<gfx::VSyncProvider> vsync_provider) |
| 712 : window_(window), | 715 : window_(window), |
| 713 size_(1, 1), | 716 size_(1, 1), |
| 714 enable_fixed_size_angle_(false), | 717 enable_fixed_size_angle_(false), |
| 715 surface_(NULL), | 718 surface_(NULL), |
| 716 supports_post_sub_buffer_(false), | 719 supports_post_sub_buffer_(false), |
| 717 supports_swap_buffer_with_damage_(false), | 720 supports_swap_buffer_with_damage_(false), |
| 718 flips_vertically_(false), | 721 flips_vertically_(false), |
| 722 vsync_provider_external_(std::move(vsync_provider)), |
| 719 swap_interval_(1) { | 723 swap_interval_(1) { |
| 720 #if defined(OS_ANDROID) | 724 #if defined(OS_ANDROID) |
| 721 if (window) | 725 if (window) |
| 722 ANativeWindow_acquire(window); | 726 ANativeWindow_acquire(window); |
| 723 #endif | 727 #endif |
| 724 | 728 |
| 725 #if defined(OS_WIN) | 729 #if defined(OS_WIN) |
| 726 vsync_override_ = false; | 730 vsync_override_ = false; |
| 727 swap_generation_ = 0; | 731 swap_generation_ = 0; |
| 728 RECT windowRect; | 732 RECT windowRect; |
| 729 if (GetClientRect(window_, &windowRect)) | 733 if (GetClientRect(window_, &windowRect)) |
| 730 size_ = gfx::Rect(windowRect).size(); | 734 size_ = gfx::Rect(windowRect).size(); |
| 731 #endif | 735 #endif |
| 732 } | 736 } |
| 733 | 737 |
| 734 bool NativeViewGLSurfaceEGL::Initialize(GLSurfaceFormat format) { | 738 bool NativeViewGLSurfaceEGL::Initialize(GLSurfaceFormat format) { |
| 739 DCHECK(!surface_); |
| 735 format_ = format; | 740 format_ = format; |
| 736 return Initialize(nullptr); | |
| 737 } | |
| 738 | |
| 739 bool NativeViewGLSurfaceEGL::Initialize( | |
| 740 std::unique_ptr<gfx::VSyncProvider> sync_provider) { | |
| 741 DCHECK(!surface_); | |
| 742 | 741 |
| 743 if (!GetDisplay()) { | 742 if (!GetDisplay()) { |
| 744 LOG(ERROR) << "Trying to create surface with invalid display."; | 743 LOG(ERROR) << "Trying to create surface with invalid display."; |
| 745 return false; | 744 return false; |
| 746 } | 745 } |
| 747 | 746 |
| 748 // We need to make sure that window_ is correctly initialized with all | 747 // We need to make sure that window_ is correctly initialized with all |
| 749 // the platform-dependant quirks, if any, before creating the surface. | 748 // the platform-dependant quirks, if any, before creating the surface. |
| 750 if (!InitializeNativeWindow()) { | 749 if (!InitializeNativeWindow()) { |
| 751 LOG(ERROR) << "Error trying to initialize the native window."; | 750 LOG(ERROR) << "Error trying to initialize the native window."; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 if (g_driver_egl.ext.b_EGL_NV_post_sub_buffer) { | 802 if (g_driver_egl.ext.b_EGL_NV_post_sub_buffer) { |
| 804 EGLint surfaceVal; | 803 EGLint surfaceVal; |
| 805 EGLBoolean retVal = eglQuerySurface( | 804 EGLBoolean retVal = eglQuerySurface( |
| 806 GetDisplay(), surface_, EGL_POST_SUB_BUFFER_SUPPORTED_NV, &surfaceVal); | 805 GetDisplay(), surface_, EGL_POST_SUB_BUFFER_SUPPORTED_NV, &surfaceVal); |
| 807 supports_post_sub_buffer_ = (surfaceVal && retVal) == EGL_TRUE; | 806 supports_post_sub_buffer_ = (surfaceVal && retVal) == EGL_TRUE; |
| 808 } | 807 } |
| 809 | 808 |
| 810 supports_swap_buffer_with_damage_ = | 809 supports_swap_buffer_with_damage_ = |
| 811 g_driver_egl.ext.b_EGL_KHR_swap_buffers_with_damage; | 810 g_driver_egl.ext.b_EGL_KHR_swap_buffers_with_damage; |
| 812 | 811 |
| 813 if (sync_provider) | 812 if (!vsync_provider_external_ && EGLSyncControlVSyncProvider::IsSupported()) { |
| 814 vsync_provider_ = std::move(sync_provider); | 813 vsync_provider_internal_ = |
| 815 else if (EGLSyncControlVSyncProvider::IsSupported()) | 814 base::MakeUnique<EGLSyncControlVSyncProvider>(surface_); |
| 816 vsync_provider_.reset(new EGLSyncControlVSyncProvider(surface_)); | 815 } |
| 817 return true; | 816 return true; |
| 818 } | 817 } |
| 819 | 818 |
| 820 bool NativeViewGLSurfaceEGL::InitializeNativeWindow() { | 819 bool NativeViewGLSurfaceEGL::InitializeNativeWindow() { |
| 821 return true; | 820 return true; |
| 822 } | 821 } |
| 823 | 822 |
| 824 void NativeViewGLSurfaceEGL::Destroy() { | 823 void NativeViewGLSurfaceEGL::Destroy() { |
| 824 vsync_provider_internal_ = nullptr; |
| 825 |
| 825 if (surface_) { | 826 if (surface_) { |
| 826 if (!eglDestroySurface(GetDisplay(), surface_)) { | 827 if (!eglDestroySurface(GetDisplay(), surface_)) { |
| 827 LOG(ERROR) << "eglDestroySurface failed with error " | 828 LOG(ERROR) << "eglDestroySurface failed with error " |
| 828 << GetLastEGLErrorString(); | 829 << GetLastEGLErrorString(); |
| 829 } | 830 } |
| 830 surface_ = NULL; | 831 surface_ = NULL; |
| 831 } | 832 } |
| 832 } | 833 } |
| 833 | 834 |
| 834 bool NativeViewGLSurfaceEGL::IsOffscreen() { | 835 bool NativeViewGLSurfaceEGL::IsOffscreen() { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 gfx::SwapResult NativeViewGLSurfaceEGL::CommitOverlayPlanes() { | 1016 gfx::SwapResult NativeViewGLSurfaceEGL::CommitOverlayPlanes() { |
| 1016 DCHECK(SupportsCommitOverlayPlanes()); | 1017 DCHECK(SupportsCommitOverlayPlanes()); |
| 1017 // Here we assume that the overlays scheduled on this surface will display | 1018 // Here we assume that the overlays scheduled on this surface will display |
| 1018 // themselves to the screen right away in |CommitAndClearPendingOverlays|, | 1019 // themselves to the screen right away in |CommitAndClearPendingOverlays|, |
| 1019 // rather than being queued and waiting for a "swap" signal. | 1020 // rather than being queued and waiting for a "swap" signal. |
| 1020 return CommitAndClearPendingOverlays() ? gfx::SwapResult::SWAP_ACK | 1021 return CommitAndClearPendingOverlays() ? gfx::SwapResult::SWAP_ACK |
| 1021 : gfx::SwapResult::SWAP_FAILED; | 1022 : gfx::SwapResult::SWAP_FAILED; |
| 1022 } | 1023 } |
| 1023 | 1024 |
| 1024 gfx::VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { | 1025 gfx::VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { |
| 1025 return vsync_provider_.get(); | 1026 return vsync_provider_external_ ? vsync_provider_external_.get() |
| 1027 : vsync_provider_internal_.get(); |
| 1026 } | 1028 } |
| 1027 | 1029 |
| 1028 bool NativeViewGLSurfaceEGL::ScheduleOverlayPlane( | 1030 bool NativeViewGLSurfaceEGL::ScheduleOverlayPlane( |
| 1029 int z_order, | 1031 int z_order, |
| 1030 gfx::OverlayTransform transform, | 1032 gfx::OverlayTransform transform, |
| 1031 GLImage* image, | 1033 GLImage* image, |
| 1032 const gfx::Rect& bounds_rect, | 1034 const gfx::Rect& bounds_rect, |
| 1033 const gfx::RectF& crop_rect) { | 1035 const gfx::RectF& crop_rect) { |
| 1034 #if !defined(OS_ANDROID) | 1036 #if !defined(OS_ANDROID) |
| 1035 NOTIMPLEMENTED(); | 1037 NOTIMPLEMENTED(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 } | 1246 } |
| 1245 | 1247 |
| 1246 void* SurfacelessEGL::GetShareHandle() { | 1248 void* SurfacelessEGL::GetShareHandle() { |
| 1247 return NULL; | 1249 return NULL; |
| 1248 } | 1250 } |
| 1249 | 1251 |
| 1250 SurfacelessEGL::~SurfacelessEGL() { | 1252 SurfacelessEGL::~SurfacelessEGL() { |
| 1251 } | 1253 } |
| 1252 | 1254 |
| 1253 } // namespace gl | 1255 } // namespace gl |
| OLD | NEW |