mas_disable_remote_layer.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cheng Zhao <[email protected]>
  3. Date: Thu, 20 Sep 2018 17:48:49 -0700
  4. Subject: mas: disable remote layer APIs (CAContext and CALayerHost) for MAS
  5. build
  6. Accordin to ccameron:
  7. For apps that spend a lot of time watching video (especially fullscreen video),
  8. the power/battery usage will likely increase 1.5x to 2x. For something that is,
  9. e.g, scrolling, it'll be smaller, more like 1.15x or 1.25x.
  10. In terms of performance, the impact will likely be fairly small -- any app that
  11. could hit 60fps before will likely still be able to hit 60fps. There may even be
  12. cases where performance improves when disabling remote CoreAnimation (remote
  13. CoreAnimation is really only about battery usage).
  14. diff --git a/gpu/ipc/service/image_transport_surface_overlay_mac.h b/gpu/ipc/service/image_transport_surface_overlay_mac.h
  15. index ee83f9e5504eda6bd1ad80db7bd486934b7f3b6d..5db55a349f7eaf829d8458b279fd64f1f28a9a2c 100644
  16. --- a/gpu/ipc/service/image_transport_surface_overlay_mac.h
  17. +++ b/gpu/ipc/service/image_transport_surface_overlay_mac.h
  18. @@ -24,7 +24,9 @@
  19. #include "gpu/ipc/service/gpu_vsync_mac.h"
  20. #endif
  21. +#if !IS_MAS_BUILD()
  22. @class CAContext;
  23. +#endif
  24. @class CALayer;
  25. namespace ui {
  26. @@ -79,8 +81,10 @@ class ImageTransportSurfaceOverlayMacEGL : public gl::Presenter {
  27. base::WeakPtr<ImageTransportSurfaceDelegate> delegate_;
  28. +#if !IS_MAS_BUILD()
  29. const bool use_remote_layer_api_;
  30. CAContext* __strong ca_context_;
  31. +#endif
  32. std::unique_ptr<ui::CALayerTreeCoordinator> ca_layer_tree_coordinator_;
  33. gfx::Size pixel_size_;
  34. diff --git a/gpu/ipc/service/image_transport_surface_overlay_mac.mm b/gpu/ipc/service/image_transport_surface_overlay_mac.mm
  35. index bd2f1d8a8d82456390a5efb641545e9177727542..c368baeb3b8141a84f461eff5bd84129dc26f0fd 100644
  36. --- a/gpu/ipc/service/image_transport_surface_overlay_mac.mm
  37. +++ b/gpu/ipc/service/image_transport_surface_overlay_mac.mm
  38. @@ -53,7 +53,9 @@
  39. ImageTransportSurfaceOverlayMacEGL::ImageTransportSurfaceOverlayMacEGL(
  40. base::WeakPtr<ImageTransportSurfaceDelegate> delegate)
  41. : delegate_(delegate),
  42. +#if !IS_MAS_BUILD()
  43. use_remote_layer_api_(ui::RemoteLayerAPISupported()),
  44. +#endif
  45. scale_factor_(1),
  46. weak_ptr_factory_(this) {
  47. static bool av_disabled_at_command_line =
  48. @@ -65,6 +67,7 @@
  49. ->workarounds()
  50. .disable_av_sample_buffer_display_layer;
  51. +#if !IS_MAS_BUILD()
  52. ca_layer_tree_coordinator_ = std::make_unique<ui::CALayerTreeCoordinator>(
  53. use_remote_layer_api_, allow_av_sample_buffer_display_layer);
  54. @@ -85,6 +88,10 @@
  55. #endif
  56. ca_context_.layer = ca_layer_tree_coordinator_->GetCALayerForDisplay();
  57. }
  58. +#else
  59. + ca_layer_tree_coordinator_ = std::make_unique<ui::CALayerTreeCoordinator>(
  60. + /*allow_remote_layers=*/false, allow_av_sample_buffer_display_layer);
  61. +#endif
  62. #if BUILDFLAG(IS_MAC)
  63. if (features::UseGpuVsync()) {
  64. @@ -176,9 +183,13 @@
  65. TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD,
  66. "GLImpl", static_cast<int>(gl::GetGLImplementation()),
  67. "width", pixel_size_.width());
  68. +#if !IS_MAS_BUILD()
  69. if (use_remote_layer_api_) {
  70. params.ca_context_id = [ca_context_ contextId];
  71. } else {
  72. +#else
  73. + if (true) {
  74. +#endif
  75. IOSurfaceRef io_surface =
  76. ca_layer_tree_coordinator_->GetIOSurfaceForDisplay();
  77. if (io_surface) {
  78. diff --git a/ui/accelerated_widget_mac/display_ca_layer_tree.mm b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  79. index cdcb1da0c11b07cce895369aba56b78623a0bef5..3765fb5106c8f2fbc1438ad759a173610b5db2aa 100644
  80. --- a/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  81. +++ b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  82. @@ -120,6 +120,7 @@ - (void)setContentsChanged;
  83. }
  84. void DisplayCALayerTree::GotCALayerFrame(uint32_t ca_context_id) {
  85. +#if !IS_MAS_BUILD()
  86. // Early-out if the remote layer has not changed.
  87. if (remote_layer_.contextId == ca_context_id) {
  88. return;
  89. @@ -149,6 +150,9 @@ - (void)setContentsChanged;
  90. [io_surface_layer_ removeFromSuperlayer];
  91. io_surface_layer_ = nil;
  92. }
  93. +#else
  94. + NOTREACHED() << "Remote layer is being used in MAS build";
  95. +#endif
  96. }
  97. void DisplayCALayerTree::GotIOSurfaceFrame(
  98. diff --git a/ui/base/cocoa/remote_layer_api.h b/ui/base/cocoa/remote_layer_api.h
  99. index 59dc2f82214cfd883b6ebef3b0fb25af6387a9cd..d585ba14b34021a93c878d0d9f9d9ef70eed32ca 100644
  100. --- a/ui/base/cocoa/remote_layer_api.h
  101. +++ b/ui/base/cocoa/remote_layer_api.h
  102. @@ -17,6 +17,7 @@
  103. #if BUILDFLAG(IS_MAC)
  104. +#if !IS_MAS_BUILD()
  105. // The CGSConnectionID is used to create the CAContext in the process that is
  106. // going to share the CALayers that it is rendering to another process to
  107. // display.
  108. @@ -68,6 +69,8 @@ extern NSString* const kCAContextIgnoresHitTest;
  109. #endif // __OBJC__
  110. +#endif // MAS_BUILD
  111. +
  112. namespace ui {
  113. // This function will check if all of the interfaces listed above are supported
  114. diff --git a/ui/base/cocoa/remote_layer_api.mm b/ui/base/cocoa/remote_layer_api.mm
  115. index fc25ba79d2b0e1acdb7ba54b89e7d6e16f94771b..962df2d65d61ec0836cf465d847eb666033846f2 100644
  116. --- a/ui/base/cocoa/remote_layer_api.mm
  117. +++ b/ui/base/cocoa/remote_layer_api.mm
  118. @@ -10,6 +10,7 @@
  119. namespace ui {
  120. +#if !IS_MAS_BUILD()
  121. namespace {
  122. // Control use of cross-process CALayers to display content directly from the
  123. // GPU process on Mac.
  124. @@ -17,8 +18,10 @@
  125. "RemoteCoreAnimationAPI",
  126. base::FEATURE_ENABLED_BY_DEFAULT);
  127. } // namespace
  128. +#endif
  129. bool RemoteLayerAPISupported() {
  130. +#if !IS_MAS_BUILD()
  131. if (!base::FeatureList::IsEnabled(kRemoteCoreAnimationAPI))
  132. return false;
  133. @@ -55,6 +58,9 @@ bool RemoteLayerAPISupported() {
  134. // If everything is there, we should be able to use the API.
  135. return true;
  136. +#else
  137. + return false;
  138. +#endif // MAS_BUILD
  139. }
  140. } // namespace