| 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" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (view_) { | 111 if (view_) { |
| 112 view_->AcceleratedWidgetGetVSyncParameters(timebase, interval); | 112 view_->AcceleratedWidgetGetVSyncParameters(timebase, interval); |
| 113 } else { | 113 } else { |
| 114 *timebase = base::TimeTicks(); | 114 *timebase = base::TimeTicks(); |
| 115 *interval = base::TimeDelta(); | 115 *interval = base::TimeDelta(); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 void AcceleratedWidgetMac::GotFrame( | 119 void AcceleratedWidgetMac::GotFrame( |
| 120 CAContextID ca_context_id, | 120 CAContextID ca_context_id, |
| 121 bool fullscreen_low_power_ca_context_valid, |
| 122 CAContextID fullscreen_low_power_ca_context_id, |
| 121 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 123 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 122 const gfx::Size& pixel_size, | 124 const gfx::Size& pixel_size, |
| 123 float scale_factor) { | 125 float scale_factor) { |
| 124 TRACE_EVENT0("ui", "AcceleratedWidgetMac::GotFrame"); | 126 TRACE_EVENT0("ui", "AcceleratedWidgetMac::GotFrame"); |
| 125 | 127 |
| 126 // If there is no view and therefore no superview to draw into, early-out. | 128 // If there is no view and therefore no superview to draw into, early-out. |
| 127 if (!view_) { | 129 if (!view_) { |
| 128 TRACE_EVENT0("ui", "No associated NSView"); | 130 TRACE_EVENT0("ui", "No associated NSView"); |
| 129 return; | 131 return; |
| 130 } | 132 } |
| 131 | 133 |
| 132 // Disable the fade-in or fade-out effect if we create or remove layers. | 134 // Disable the fade-in or fade-out effect if we create or remove layers. |
| 133 ScopedCAActionDisabler disabler; | 135 ScopedCAActionDisabler disabler; |
| 134 | 136 |
| 135 last_swap_size_dip_ = gfx::ConvertSizeToDIP(scale_factor, pixel_size); | 137 last_swap_size_dip_ = gfx::ConvertSizeToDIP(scale_factor, pixel_size); |
| 136 | 138 |
| 137 if (ca_context_id) | 139 if (ca_context_id) { |
| 138 GotCAContextFrame(ca_context_id, pixel_size, scale_factor); | 140 GotCAContextFrame(ca_context_id, fullscreen_low_power_ca_context_valid, |
| 139 else | 141 fullscreen_low_power_ca_context_id, pixel_size, |
| 142 scale_factor); |
| 143 } else { |
| 140 GotIOSurfaceFrame(io_surface, pixel_size, scale_factor); | 144 GotIOSurfaceFrame(io_surface, pixel_size, scale_factor); |
| 145 } |
| 141 | 146 |
| 142 view_->AcceleratedWidgetSwapCompleted(); | 147 view_->AcceleratedWidgetSwapCompleted(); |
| 143 } | 148 } |
| 144 | 149 |
| 145 void AcceleratedWidgetMac::GotCAContextFrame(CAContextID ca_context_id, | 150 void AcceleratedWidgetMac::GotCAContextFrame( |
| 146 const gfx::Size& pixel_size, | 151 CAContextID ca_context_id, |
| 147 float scale_factor) { | 152 bool fullscreen_low_power_ca_context_valid, |
| 153 CAContextID fullscreen_low_power_ca_context_id, |
| 154 const gfx::Size& pixel_size, |
| 155 float scale_factor) { |
| 148 TRACE_EVENT0("ui", "AcceleratedWidgetMac::GotCAContextFrame"); | 156 TRACE_EVENT0("ui", "AcceleratedWidgetMac::GotCAContextFrame"); |
| 149 | 157 |
| 150 // In the layer is replaced, keep the old one around until after the new one | 158 // In the layer is replaced, keep the old one around until after the new one |
| 151 // is installed to avoid flashes. | 159 // is installed to avoid flashes. |
| 152 base::scoped_nsobject<CALayerHost> old_ca_context_layer = | 160 base::scoped_nsobject<CALayerHost> old_ca_context_layer = |
| 153 ca_context_layer_; | 161 ca_context_layer_; |
| 154 | 162 |
| 155 // Create the layer to host the layer exported by the GPU process with this | 163 // Create the layer to host the layer exported by the GPU process with this |
| 156 // particular CAContext ID. | 164 // particular CAContext ID. |
| 157 if ([ca_context_layer_ contextId] != ca_context_id) { | 165 if ([ca_context_layer_ contextId] != ca_context_id) { |
| 158 TRACE_EVENT0("ui", "Creating a new CALayerHost"); | 166 TRACE_EVENT0("ui", "Creating a new CALayerHost"); |
| 159 ca_context_layer_.reset([[CALayerHost alloc] init]); | 167 ca_context_layer_.reset([[CALayerHost alloc] init]); |
| 160 [ca_context_layer_ setContextId:ca_context_id]; | 168 [ca_context_layer_ setContextId:ca_context_id]; |
| 161 [ca_context_layer_ | 169 [ca_context_layer_ |
| 162 setAutoresizingMask:kCALayerMaxXMargin|kCALayerMaxYMargin]; | 170 setAutoresizingMask:kCALayerMaxXMargin|kCALayerMaxYMargin]; |
| 163 [flipped_layer_ addSublayer:ca_context_layer_]; | 171 [flipped_layer_ addSublayer:ca_context_layer_]; |
| 164 } | 172 } |
| 173 if ([fullscreen_low_power_layer_ contextId] != |
| 174 fullscreen_low_power_ca_context_id) { |
| 175 TRACE_EVENT0("ui", "Creating a new CALayerHost"); |
| 176 fullscreen_low_power_layer_.reset([[CALayerHost alloc] init]); |
| 177 [fullscreen_low_power_layer_ |
| 178 setContextId:fullscreen_low_power_ca_context_id]; |
| 179 } |
| 165 | 180 |
| 166 // If this replacing a same-type layer, remove it now that the new layer is | 181 // If this replacing a same-type layer, remove it now that the new layer is |
| 167 // in the hierarchy. | 182 // in the hierarchy. |
| 168 if (old_ca_context_layer != ca_context_layer_) | 183 if (old_ca_context_layer != ca_context_layer_) |
| 169 DestroyCAContextLayer(old_ca_context_layer); | 184 DestroyCAContextLayer(old_ca_context_layer); |
| 170 | 185 |
| 171 // Remove any different-type layers that this is replacing. | 186 // Remove any different-type layers that this is replacing. |
| 172 DestroyLocalLayer(); | 187 DestroyLocalLayer(); |
| 173 } | 188 } |
| 174 | 189 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 void AcceleratedWidgetMac::DestroyLocalLayer() { | 237 void AcceleratedWidgetMac::DestroyLocalLayer() { |
| 223 if (!local_layer_) | 238 if (!local_layer_) |
| 224 return; | 239 return; |
| 225 [local_layer_ removeFromSuperlayer]; | 240 [local_layer_ removeFromSuperlayer]; |
| 226 local_layer_.reset(); | 241 local_layer_.reset(); |
| 227 } | 242 } |
| 228 | 243 |
| 229 void AcceleratedWidgetMacGotFrame( | 244 void AcceleratedWidgetMacGotFrame( |
| 230 gfx::AcceleratedWidget widget, | 245 gfx::AcceleratedWidget widget, |
| 231 CAContextID ca_context_id, | 246 CAContextID ca_context_id, |
| 247 bool fullscreen_low_power_ca_context_valid, |
| 248 CAContextID fullscreen_low_power_ca_context_id, |
| 232 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 249 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 233 const gfx::Size& pixel_size, | 250 const gfx::Size& pixel_size, |
| 234 float scale_factor, | 251 float scale_factor, |
| 235 base::TimeTicks* vsync_timebase, | 252 base::TimeTicks* vsync_timebase, |
| 236 base::TimeDelta* vsync_interval) { | 253 base::TimeDelta* vsync_interval) { |
| 237 if (vsync_timebase) | 254 if (vsync_timebase) |
| 238 *vsync_timebase = base::TimeTicks(); | 255 *vsync_timebase = base::TimeTicks(); |
| 239 if (vsync_interval) | 256 if (vsync_interval) |
| 240 *vsync_interval = base::TimeDelta(); | 257 *vsync_interval = base::TimeDelta(); |
| 241 | 258 |
| 242 AcceleratedWidgetMac* accelerated_widget_mac = | 259 AcceleratedWidgetMac* accelerated_widget_mac = |
| 243 GetHelperFromAcceleratedWidget(widget); | 260 GetHelperFromAcceleratedWidget(widget); |
| 244 | 261 |
| 245 if (accelerated_widget_mac) { | 262 if (accelerated_widget_mac) { |
| 246 accelerated_widget_mac->GotFrame(ca_context_id, io_surface, pixel_size, | 263 accelerated_widget_mac->GotFrame(ca_context_id, |
| 247 scale_factor); | 264 fullscreen_low_power_ca_context_valid, |
| 265 fullscreen_low_power_ca_context_id, |
| 266 io_surface, pixel_size, scale_factor); |
| 248 if (vsync_timebase && vsync_interval) { | 267 if (vsync_timebase && vsync_interval) { |
| 249 accelerated_widget_mac->GetVSyncParameters(vsync_timebase, | 268 accelerated_widget_mac->GetVSyncParameters(vsync_timebase, |
| 250 vsync_interval); | 269 vsync_interval); |
| 251 } | 270 } |
| 252 } | 271 } |
| 253 } | 272 } |
| 254 | 273 |
| 255 } // namespace ui | 274 } // namespace ui |
| OLD | NEW |