image_transport_surface_win.cc 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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
  3. // found in the LICENSE file.
  4. #include "gpu/ipc/service/image_transport_surface.h"
  5. #include <memory>
  6. #include "base/win/windows_version.h"
  7. #include "gpu/command_buffer/service/feature_info.h"
  8. #include "gpu/config/gpu_preferences.h"
  9. #include "gpu/ipc/service/pass_through_image_transport_surface.h"
  10. #include "ui/gfx/native_widget_types.h"
  11. #include "ui/gl/direct_composition_support.h"
  12. #include "ui/gl/direct_composition_surface_win.h"
  13. #include "ui/gl/gl_bindings.h"
  14. #include "ui/gl/gl_implementation.h"
  15. #include "ui/gl/gl_surface_egl.h"
  16. #include "ui/gl/gl_switches.h"
  17. #include "ui/gl/gl_utils.h"
  18. #include "ui/gl/init/gl_factory.h"
  19. #include "ui/gl/vsync_provider_win.h"
  20. namespace gpu {
  21. namespace {
  22. gl::DirectCompositionSurfaceWin::Settings
  23. CreateDirectCompositionSurfaceSettings(
  24. const GpuDriverBugWorkarounds& workarounds) {
  25. gl::DirectCompositionSurfaceWin::Settings settings;
  26. settings.no_downscaled_overlay_promotion =
  27. workarounds.no_downscaled_overlay_promotion;
  28. settings.disable_nv12_dynamic_textures =
  29. workarounds.disable_nv12_dynamic_textures;
  30. settings.disable_vp_scaling = workarounds.disable_vp_scaling;
  31. settings.disable_vp_super_resolution =
  32. workarounds.disable_vp_super_resolution;
  33. settings.use_angle_texture_offset = true;
  34. settings.force_root_surface_full_damage =
  35. gl::ShouldForceDirectCompositionRootSurfaceFullDamage();
  36. settings.force_root_surface_full_damage_always =
  37. workarounds.force_direct_composition_full_damage_always;
  38. return settings;
  39. }
  40. } // namespace
  41. // static
  42. scoped_refptr<gl::GLSurface> ImageTransportSurface::CreateNativeSurface(
  43. gl::GLDisplay* display,
  44. base::WeakPtr<ImageTransportSurfaceDelegate> delegate,
  45. SurfaceHandle surface_handle,
  46. gl::GLSurfaceFormat format) {
  47. DCHECK_NE(surface_handle, kNullSurfaceHandle);
  48. scoped_refptr<gl::GLSurface> surface;
  49. if (gl::GetGLImplementation() == gl::kGLImplementationEGLANGLE) {
  50. if (gl::DirectCompositionSupported()) {
  51. auto vsync_callback = delegate->GetGpuVSyncCallback();
  52. auto settings = CreateDirectCompositionSurfaceSettings(
  53. delegate->GetFeatureInfo()->workarounds());
  54. auto dc_surface = base::MakeRefCounted<gl::DirectCompositionSurfaceWin>(
  55. display->GetAs<gl::GLDisplayEGL>(), surface_handle,
  56. std::move(vsync_callback), settings);
  57. if (!dc_surface->Initialize(gl::GLSurfaceFormat()))
  58. return nullptr;
  59. delegate->DidCreateAcceleratedSurfaceChildWindow(surface_handle,
  60. dc_surface->window());
  61. surface = std::move(dc_surface);
  62. } else {
  63. surface = gl::InitializeGLSurface(
  64. base::MakeRefCounted<gl::NativeViewGLSurfaceEGL>(
  65. display->GetAs<gl::GLDisplayEGL>(), surface_handle,
  66. std::make_unique<gl::VSyncProviderWin>(surface_handle)));
  67. if (!surface)
  68. return nullptr;
  69. }
  70. } else {
  71. surface = gl::init::CreateViewGLSurface(display, surface_handle);
  72. if (!surface)
  73. return nullptr;
  74. }
  75. // |override_vsync_for_multi_window_swap| is needed because Present() blocks
  76. // when multiple windows use swap interval 1 all the time. With this flag the
  77. // surface forces swap interval 0 when multiple windows are presenting.
  78. return scoped_refptr<gl::GLSurface>(new PassThroughImageTransportSurface(
  79. delegate, surface.get(), /*override_vsync_for_multi_window_swap=*/true));
  80. }
  81. } // namespace gpu