| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/common/gpu/image_transport_surface_overlay_mac.h" | 5 #include "content/common/gpu/image_transport_surface_overlay_mac.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <IOSurface/IOSurface.h> | 8 #include <IOSurface/IOSurface.h> |
| 9 #include <OpenGL/CGLRenderers.h> | 9 #include <OpenGL/CGLRenderers.h> |
| 10 #include <OpenGL/CGLTypes.h> | 10 #include <OpenGL/CGLTypes.h> |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 public: | 90 public: |
| 91 OverlayPlane(int z_order, | 91 OverlayPlane(int z_order, |
| 92 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 92 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 93 const gfx::RectF& dip_frame_rect, | 93 const gfx::RectF& dip_frame_rect, |
| 94 const gfx::RectF& contents_rect) | 94 const gfx::RectF& contents_rect) |
| 95 : z_order(z_order), | 95 : z_order(z_order), |
| 96 io_surface(io_surface), | 96 io_surface(io_surface), |
| 97 dip_frame_rect(dip_frame_rect), | 97 dip_frame_rect(dip_frame_rect), |
| 98 contents_rect(contents_rect), | 98 contents_rect(contents_rect), |
| 99 layer_needs_update(true) {} | 99 layer_needs_update(true) {} |
| 100 |
| 101 OverlayPlane(int z_order, |
| 102 const gfx::RectF& dip_frame_rect, |
| 103 float red, float green, float blue, float alpha) |
| 104 : z_order(z_order), |
| 105 solid_color(CGColorCreateGenericRGB(red, green, blue, alpha)), |
| 106 dip_frame_rect(dip_frame_rect), |
| 107 layer_needs_update(true) {} |
| 108 |
| 100 ~OverlayPlane() { DCHECK(!ca_layer); } | 109 ~OverlayPlane() { DCHECK(!ca_layer); } |
| 101 | 110 |
| 102 const int z_order; | 111 const int z_order; |
| 103 base::scoped_nsobject<CALayer> ca_layer; | 112 base::scoped_nsobject<CALayer> ca_layer; |
| 104 | 113 |
| 105 // The IOSurface to set the CALayer's contents to. | 114 // The IOSurface to set the CALayer's contents to. |
| 106 const base::ScopedCFTypeRef<IOSurfaceRef> io_surface; | 115 const base::ScopedCFTypeRef<IOSurfaceRef> io_surface; |
| 116 base::ScopedCFTypeRef<CGColorRef> solid_color; |
| 107 const gfx::RectF dip_frame_rect; | 117 const gfx::RectF dip_frame_rect; |
| 108 const gfx::RectF contents_rect; | 118 const gfx::RectF contents_rect; |
| 109 | 119 |
| 110 bool layer_needs_update; | 120 bool layer_needs_update; |
| 111 | 121 |
| 112 static bool Compare(const linked_ptr<OverlayPlane>& a, | 122 static bool Compare(const linked_ptr<OverlayPlane>& a, |
| 113 const linked_ptr<OverlayPlane>& b) { | 123 const linked_ptr<OverlayPlane>& b) { |
| 114 return (a->z_order < b->z_order); | 124 return (a->z_order < b->z_order); |
| 115 } | 125 } |
| 116 | 126 |
| 117 void TakeCALayerFrom(OverlayPlane* other_plane) { | 127 void TakeCALayerFrom(OverlayPlane* other_plane) { |
| 118 ca_layer.swap(other_plane->ca_layer); | 128 ca_layer.swap(other_plane->ca_layer); |
| 119 } | 129 } |
| 120 | 130 |
| 121 void UpdateProperties() { | 131 void UpdateProperties() { |
| 122 if (layer_needs_update) { | 132 if (layer_needs_update) { |
| 123 [ca_layer setOpaque:YES]; | 133 [ca_layer setOpaque:YES]; |
| 124 [ca_layer setFrame:dip_frame_rect.ToCGRect()]; | 134 [ca_layer setFrame:dip_frame_rect.ToCGRect()]; |
| 125 [ca_layer setContentsRect:contents_rect.ToCGRect()]; | 135 [ca_layer setContentsRect:contents_rect.ToCGRect()]; |
| 126 id new_contents = static_cast<id>(io_surface.get()); | 136 if (io_surface.get()) { |
| 127 if ([ca_layer contents] == new_contents && z_order == 0) { | 137 id new_contents = static_cast<id>(io_surface.get()); |
| 128 [ca_layer setContentsChanged]; | 138 if ([ca_layer contents] == new_contents && z_order == 0) { |
| 129 } else { | 139 [ca_layer setContentsChanged]; |
| 130 [ca_layer setContents:new_contents]; | 140 } else { |
| 141 [ca_layer setContents:new_contents]; |
| 142 } |
| 143 } |
| 144 if (solid_color.get()) { |
| 145 [ca_layer setBackgroundColor:solid_color]; |
| 131 } | 146 } |
| 132 } | 147 } |
| 133 static bool show_borders = | 148 static bool show_borders = |
| 134 base::CommandLine::ForCurrentProcess()->HasSwitch( | 149 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 135 switches::kShowMacOverlayBorders); | 150 switches::kShowMacOverlayBorders); |
| 136 if (show_borders) { | 151 if (show_borders) { |
| 137 base::ScopedCFTypeRef<CGColorRef> color; | 152 base::ScopedCFTypeRef<CGColorRef> color; |
| 138 if (!layer_needs_update) { | 153 if (!layer_needs_update) { |
| 139 // Green represents contents that are unchanged across frames. | 154 // Green represents contents that are unchanged across frames. |
| 140 color.reset(CGColorCreateGenericRGB(0, 1, 0, 1)); | 155 color.reset(CGColorCreateGenericRGB(0, 1, 0, 1)); |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 ConvertRectToDIPF(scale_factor_, bounds_rect), | 653 ConvertRectToDIPF(scale_factor_, bounds_rect), |
| 639 crop_rect)); | 654 crop_rect)); |
| 640 if (z_order == 0) | 655 if (z_order == 0) |
| 641 pending_root_plane_ = plane; | 656 pending_root_plane_ = plane; |
| 642 else | 657 else |
| 643 pending_overlay_planes_.push_back(plane); | 658 pending_overlay_planes_.push_back(plane); |
| 644 | 659 |
| 645 return true; | 660 return true; |
| 646 } | 661 } |
| 647 | 662 |
| 663 bool ImageTransportSurfaceOverlayMac::ScheduleSolidColorOverlayPlane( |
| 664 int z_order, |
| 665 const gfx::Rect& bounds_rect, |
| 666 float red, |
| 667 float green, |
| 668 float blue, |
| 669 float alpha) { |
| 670 linked_ptr<OverlayPlane> plane( |
| 671 new OverlayPlane(z_order, |
| 672 ConvertRectToDIPF(scale_factor_, bounds_rect), |
| 673 red, green, blue, alpha)); |
| 674 pending_overlay_planes_.push_back(plane); |
| 675 return true; |
| 676 } |
| 677 |
| 648 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const { | 678 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const { |
| 649 return true; | 679 return true; |
| 650 } | 680 } |
| 651 | 681 |
| 652 void ImageTransportSurfaceOverlayMac::OnBufferPresented( | 682 void ImageTransportSurfaceOverlayMac::OnBufferPresented( |
| 653 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { | 683 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { |
| 654 vsync_timebase_ = params.vsync_timebase; | 684 vsync_timebase_ = params.vsync_timebase; |
| 655 vsync_interval_ = params.vsync_interval; | 685 vsync_interval_ = params.vsync_interval; |
| 656 vsync_parameters_valid_ = (vsync_interval_ != base::TimeDelta()); | 686 vsync_parameters_valid_ = (vsync_interval_ != base::TimeDelta()); |
| 657 | 687 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 // Compute the previous vsync time. | 737 // Compute the previous vsync time. |
| 708 base::TimeTicks previous_vsync = | 738 base::TimeTicks previous_vsync = |
| 709 vsync_interval_ * ((from - vsync_timebase_) / vsync_interval_) + | 739 vsync_interval_ * ((from - vsync_timebase_) / vsync_interval_) + |
| 710 vsync_timebase_; | 740 vsync_timebase_; |
| 711 | 741 |
| 712 // Return |interval_fraction| through the next vsync. | 742 // Return |interval_fraction| through the next vsync. |
| 713 return previous_vsync + (1 + interval_fraction) * vsync_interval_; | 743 return previous_vsync + (1 + interval_fraction) * vsync_interval_; |
| 714 } | 744 } |
| 715 | 745 |
| 716 } // namespace content | 746 } // namespace content |
| OLD | NEW |