Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/accelerated_widget_mac/accelerated_widget_mac.h" | 5 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| 11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
| 12 #include "base/mac/sdk_forward_declarations.h" | 12 #include "base/mac/sdk_forward_declarations.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
| 16 #include "ui/accelerated_widget_mac/fullscreen_low_power_coordinator.h" | |
| 16 #include "ui/base/cocoa/animation_utils.h" | 17 #include "ui/base/cocoa/animation_utils.h" |
| 17 #include "ui/gfx/geometry/dip_util.h" | 18 #include "ui/gfx/geometry/dip_util.h" |
| 18 #include "ui/gl/scoped_cgl.h" | 19 #include "ui/gl/scoped_cgl.h" |
| 19 | 20 |
| 20 @interface CALayer (PrivateAPI) | 21 @interface CALayer (PrivateAPI) |
| 21 - (void)setContentsChanged; | 22 - (void)setContentsChanged; |
| 22 @end | 23 @end |
| 23 | 24 |
| 24 namespace ui { | 25 namespace ui { |
| 25 namespace { | 26 namespace { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 71 |
| 71 AcceleratedWidgetMac::~AcceleratedWidgetMac() { | 72 AcceleratedWidgetMac::~AcceleratedWidgetMac() { |
| 72 DCHECK(!view_); | 73 DCHECK(!view_); |
| 73 g_widget_to_helper_map.Pointer()->erase(native_widget_); | 74 g_widget_to_helper_map.Pointer()->erase(native_widget_); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void AcceleratedWidgetMac::SetNSView(AcceleratedWidgetMacNSView* view) { | 77 void AcceleratedWidgetMac::SetNSView(AcceleratedWidgetMacNSView* view) { |
| 77 // Disable the fade-in animation as the view is added. | 78 // Disable the fade-in animation as the view is added. |
| 78 ScopedCAActionDisabler disabler; | 79 ScopedCAActionDisabler disabler; |
| 79 | 80 |
| 81 DCHECK(!fslp_coordinator_); | |
| 80 DCHECK(view && !view_); | 82 DCHECK(view && !view_); |
| 81 view_ = view; | 83 view_ = view; |
| 82 | 84 |
| 83 CALayer* background_layer = [view_->AcceleratedWidgetGetNSView() layer]; | 85 CALayer* background_layer = [view_->AcceleratedWidgetGetNSView() layer]; |
| 84 DCHECK(background_layer); | 86 DCHECK(background_layer); |
| 85 [flipped_layer_ setBounds:[background_layer bounds]]; | 87 [flipped_layer_ setBounds:[background_layer bounds]]; |
| 86 [background_layer addSublayer:flipped_layer_]; | 88 [background_layer addSublayer:flipped_layer_]; |
| 87 } | 89 } |
| 88 | 90 |
| 89 void AcceleratedWidgetMac::ResetNSView() { | 91 void AcceleratedWidgetMac::ResetNSView() { |
| 90 if (!view_) | 92 if (!view_) |
| 91 return; | 93 return; |
| 92 | 94 |
| 95 if (fslp_coordinator_) { | |
| 96 fslp_coordinator_->WillLoseAcceleratedWidget(); | |
| 97 DCHECK(!fslp_coordinator_); | |
| 98 } | |
|
erikchen
2016/05/05 17:47:38
should we be reseting the FSLPlayer?
ccameron
2016/05/05 19:27:18
There's no upside to resetting it -- we can reuse
| |
| 99 | |
| 93 // Disable the fade-out animation as the view is removed. | 100 // Disable the fade-out animation as the view is removed. |
| 94 ScopedCAActionDisabler disabler; | 101 ScopedCAActionDisabler disabler; |
| 95 | 102 |
| 96 [flipped_layer_ removeFromSuperlayer]; | 103 [flipped_layer_ removeFromSuperlayer]; |
| 97 DestroyCAContextLayer(ca_context_layer_); | 104 DestroyCAContextLayer(ca_context_layer_); |
| 98 DestroyLocalLayer(); | 105 DestroyLocalLayer(); |
| 99 | 106 |
| 100 last_swap_size_dip_ = gfx::Size(); | 107 last_swap_size_dip_ = gfx::Size(); |
| 101 view_ = NULL; | 108 view_ = NULL; |
| 102 } | 109 } |
| 103 | 110 |
| 111 void AcceleratedWidgetMac::SetFullscreenLowPowerCoordinator( | |
| 112 FullscreenLowPowerCoordinator* coordinator) { | |
| 113 DCHECK(coordinator); | |
| 114 DCHECK(!fslp_coordinator_); | |
| 115 fslp_coordinator_ = coordinator; | |
| 116 } | |
| 117 | |
| 118 void AcceleratedWidgetMac::ResetFullscreenLowPowerCoordinator() { | |
| 119 DCHECK(fslp_coordinator_); | |
| 120 fslp_coordinator_ = nullptr; | |
| 121 } | |
| 122 | |
| 123 CALayer* AcceleratedWidgetMac::GetFullscreenLowPowerLayer() const { | |
| 124 return fullscreen_low_power_layer_; | |
| 125 } | |
| 126 | |
| 104 bool AcceleratedWidgetMac::HasFrameOfSize( | 127 bool AcceleratedWidgetMac::HasFrameOfSize( |
| 105 const gfx::Size& dip_size) const { | 128 const gfx::Size& dip_size) const { |
| 106 return last_swap_size_dip_ == dip_size; | 129 return last_swap_size_dip_ == dip_size; |
| 107 } | 130 } |
| 108 | 131 |
| 109 void AcceleratedWidgetMac::GetVSyncParameters( | 132 void AcceleratedWidgetMac::GetVSyncParameters( |
| 110 base::TimeTicks* timebase, base::TimeDelta* interval) const { | 133 base::TimeTicks* timebase, base::TimeDelta* interval) const { |
| 111 if (view_) { | 134 if (view_) { |
| 112 view_->AcceleratedWidgetGetVSyncParameters(timebase, interval); | 135 view_->AcceleratedWidgetGetVSyncParameters(timebase, interval); |
| 113 } else { | 136 } else { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 TRACE_EVENT0("ui", "Creating a new CALayerHost"); | 189 TRACE_EVENT0("ui", "Creating a new CALayerHost"); |
| 167 ca_context_layer_.reset([[CALayerHost alloc] init]); | 190 ca_context_layer_.reset([[CALayerHost alloc] init]); |
| 168 [ca_context_layer_ setContextId:ca_context_id]; | 191 [ca_context_layer_ setContextId:ca_context_id]; |
| 169 [ca_context_layer_ | 192 [ca_context_layer_ |
| 170 setAutoresizingMask:kCALayerMaxXMargin|kCALayerMaxYMargin]; | 193 setAutoresizingMask:kCALayerMaxXMargin|kCALayerMaxYMargin]; |
| 171 [flipped_layer_ addSublayer:ca_context_layer_]; | 194 [flipped_layer_ addSublayer:ca_context_layer_]; |
| 172 } | 195 } |
| 173 if ([fullscreen_low_power_layer_ contextId] != | 196 if ([fullscreen_low_power_layer_ contextId] != |
| 174 fullscreen_low_power_ca_context_id) { | 197 fullscreen_low_power_ca_context_id) { |
| 175 TRACE_EVENT0("ui", "Creating a new CALayerHost"); | 198 TRACE_EVENT0("ui", "Creating a new CALayerHost"); |
| 199 if (fslp_coordinator_) { | |
| 200 fslp_coordinator_->WillLoseAcceleratedWidget(); | |
| 201 DCHECK(!fslp_coordinator_); | |
| 202 } | |
| 176 fullscreen_low_power_layer_.reset([[CALayerHost alloc] init]); | 203 fullscreen_low_power_layer_.reset([[CALayerHost alloc] init]); |
| 177 [fullscreen_low_power_layer_ | 204 [fullscreen_low_power_layer_ |
| 178 setContextId:fullscreen_low_power_ca_context_id]; | 205 setContextId:fullscreen_low_power_ca_context_id]; |
| 179 } | 206 } |
| 180 | 207 |
| 208 if (fslp_coordinator_) { | |
| 209 fslp_coordinator_->SetLowPowerLayerValid( | |
| 210 fullscreen_low_power_ca_context_valid); | |
| 211 } | |
| 212 | |
| 181 // If this replacing a same-type layer, remove it now that the new layer is | 213 // If this replacing a same-type layer, remove it now that the new layer is |
| 182 // in the hierarchy. | 214 // in the hierarchy. |
| 183 if (old_ca_context_layer != ca_context_layer_) | 215 if (old_ca_context_layer != ca_context_layer_) |
| 184 DestroyCAContextLayer(old_ca_context_layer); | 216 DestroyCAContextLayer(old_ca_context_layer); |
| 185 | 217 |
| 186 // Remove any different-type layers that this is replacing. | 218 // Remove any different-type layers that this is replacing. |
| 187 DestroyLocalLayer(); | 219 DestroyLocalLayer(); |
| 188 } | 220 } |
| 189 | 221 |
| 190 void AcceleratedWidgetMac::EnsureLocalLayer() { | 222 void AcceleratedWidgetMac::EnsureLocalLayer() { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 fullscreen_low_power_ca_context_id, | 297 fullscreen_low_power_ca_context_id, |
| 266 io_surface, pixel_size, scale_factor); | 298 io_surface, pixel_size, scale_factor); |
| 267 if (vsync_timebase && vsync_interval) { | 299 if (vsync_timebase && vsync_interval) { |
| 268 accelerated_widget_mac->GetVSyncParameters(vsync_timebase, | 300 accelerated_widget_mac->GetVSyncParameters(vsync_timebase, |
| 269 vsync_interval); | 301 vsync_interval); |
| 270 } | 302 } |
| 271 } | 303 } |
| 272 } | 304 } |
| 273 | 305 |
| 274 } // namespace ui | 306 } // namespace ui |
| OLD | NEW |