ca_layer_tree_coordinator.mm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2016 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 "ui/accelerated_widget_mac/ca_layer_tree_coordinator.h"
  5. #import <AVFoundation/AVFoundation.h>
  6. #include "base/logging.h"
  7. #include "base/mac/mac_util.h"
  8. #include "base/trace_event/trace_event.h"
  9. #include "ui/base/cocoa/animation_utils.h"
  10. namespace ui {
  11. CALayerTreeCoordinator::CALayerTreeCoordinator(
  12. bool allow_remote_layers,
  13. bool allow_av_sample_buffer_display_layer)
  14. : allow_remote_layers_(allow_remote_layers),
  15. allow_av_sample_buffer_display_layer_(
  16. allow_av_sample_buffer_display_layer) {
  17. if (allow_remote_layers_) {
  18. root_ca_layer_.reset([[CALayer alloc] init]);
  19. [root_ca_layer_ setGeometryFlipped:YES];
  20. [root_ca_layer_ setOpaque:YES];
  21. }
  22. }
  23. CALayerTreeCoordinator::~CALayerTreeCoordinator() {}
  24. void CALayerTreeCoordinator::Resize(const gfx::Size& pixel_size,
  25. float scale_factor) {
  26. pixel_size_ = pixel_size;
  27. scale_factor_ = scale_factor;
  28. }
  29. CARendererLayerTree* CALayerTreeCoordinator::GetPendingCARendererLayerTree() {
  30. if (!pending_ca_renderer_layer_tree_)
  31. pending_ca_renderer_layer_tree_ = std::make_unique<CARendererLayerTree>(
  32. allow_av_sample_buffer_display_layer_, false);
  33. return pending_ca_renderer_layer_tree_.get();
  34. }
  35. void CALayerTreeCoordinator::CommitPendingTreesToCA() {
  36. // Update the CALayer hierarchy.
  37. ScopedCAActionDisabler disabler;
  38. if (pending_ca_renderer_layer_tree_) {
  39. pending_ca_renderer_layer_tree_->CommitScheduledCALayers(
  40. root_ca_layer_.get(), std::move(current_ca_renderer_layer_tree_),
  41. pixel_size_, scale_factor_);
  42. current_ca_renderer_layer_tree_.swap(pending_ca_renderer_layer_tree_);
  43. } else {
  44. TRACE_EVENT0("gpu", "Blank frame: No overlays or CALayers");
  45. DLOG(WARNING) << "Blank frame: No overlays or CALayers";
  46. [root_ca_layer_ setSublayers:nil];
  47. current_ca_renderer_layer_tree_.reset();
  48. }
  49. // Reset all state for the next frame.
  50. pending_ca_renderer_layer_tree_.reset();
  51. }
  52. CALayer* CALayerTreeCoordinator::GetCALayerForDisplay() const {
  53. DCHECK(allow_remote_layers_);
  54. return root_ca_layer_.get();
  55. }
  56. IOSurfaceRef CALayerTreeCoordinator::GetIOSurfaceForDisplay() {
  57. DCHECK(!allow_remote_layers_);
  58. if (!current_ca_renderer_layer_tree_)
  59. return nullptr;
  60. return current_ca_renderer_layer_tree_->GetContentIOSurface();
  61. }
  62. } // namespace ui