| 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/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "ui/accelerated_widget_mac/surface_handle_types.h" | |
| 16 #include "ui/base/cocoa/animation_utils.h" | 15 #include "ui/base/cocoa/animation_utils.h" |
| 17 #include "ui/gfx/geometry/dip_util.h" | 16 #include "ui/gfx/geometry/dip_util.h" |
| 18 #include "ui/gl/scoped_cgl.h" | 17 #include "ui/gl/scoped_cgl.h" |
| 19 | 18 |
| 20 @interface CALayer (PrivateAPI) | 19 @interface CALayer (PrivateAPI) |
| 21 - (void)setContentsChanged; | 20 - (void)setContentsChanged; |
| 22 @end | 21 @end |
| 23 | 22 |
| 24 namespace ui { | 23 namespace ui { |
| 25 namespace { | 24 namespace { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return false; | 127 return false; |
| 129 } | 128 } |
| 130 | 129 |
| 131 void AcceleratedWidgetMac::BeginPumpingFrames() { | 130 void AcceleratedWidgetMac::BeginPumpingFrames() { |
| 132 } | 131 } |
| 133 | 132 |
| 134 void AcceleratedWidgetMac::EndPumpingFrames() { | 133 void AcceleratedWidgetMac::EndPumpingFrames() { |
| 135 } | 134 } |
| 136 | 135 |
| 137 void AcceleratedWidgetMac::GotAcceleratedFrame( | 136 void AcceleratedWidgetMac::GotAcceleratedFrame( |
| 138 uint64 surface_handle, | 137 CAContextID ca_context_id, |
| 138 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 139 const std::vector<ui::LatencyInfo>& latency_info, | 139 const std::vector<ui::LatencyInfo>& latency_info, |
| 140 const gfx::Size& pixel_size, | 140 const gfx::Size& pixel_size, |
| 141 float scale_factor, | 141 float scale_factor, |
| 142 const gfx::Rect& pixel_damage_rect, | 142 const gfx::Rect& pixel_damage_rect, |
| 143 const base::Closure& drawn_callback) { | 143 const base::Closure& drawn_callback) { |
| 144 // Record the surface and latency info to use when acknowledging this frame. | 144 // Record the surface and latency info to use when acknowledging this frame. |
| 145 DCHECK(accelerated_frame_drawn_callback_.is_null()); | 145 DCHECK(accelerated_frame_drawn_callback_.is_null()); |
| 146 accelerated_frame_drawn_callback_ = drawn_callback; | 146 accelerated_frame_drawn_callback_ = drawn_callback; |
| 147 accelerated_latency_info_.insert(accelerated_latency_info_.end(), | 147 accelerated_latency_info_.insert(accelerated_latency_info_.end(), |
| 148 latency_info.begin(), latency_info.end()); | 148 latency_info.begin(), latency_info.end()); |
| 149 | 149 |
| 150 // If there is no view and therefore no superview to draw into, early-out. | 150 // If there is no view and therefore no superview to draw into, early-out. |
| 151 if (!view_) { | 151 if (!view_) { |
| 152 AcknowledgeAcceleratedFrame(); | 152 AcknowledgeAcceleratedFrame(); |
| 153 return; | 153 return; |
| 154 } | 154 } |
| 155 | 155 |
| 156 // Disable the fade-in or fade-out effect if we create or remove layers. | 156 // Disable the fade-in or fade-out effect if we create or remove layers. |
| 157 ScopedCAActionDisabler disabler; | 157 ScopedCAActionDisabler disabler; |
| 158 | 158 |
| 159 switch (GetSurfaceHandleType(surface_handle)) { | 159 if (ca_context_id) |
| 160 case kSurfaceHandleTypeIOSurface: { | 160 GotAcceleratedCAContextFrame(ca_context_id, pixel_size, scale_factor); |
| 161 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(surface_handle); | 161 else |
| 162 GotAcceleratedIOSurfaceFrame(io_surface_id, pixel_size, scale_factor); | 162 GotAcceleratedIOSurfaceFrame(io_surface, pixel_size, scale_factor); |
| 163 break; | |
| 164 } | |
| 165 case kSurfaceHandleTypeCAContext: { | |
| 166 CAContextID ca_context_id = CAContextIDFromSurfaceHandle(surface_handle); | |
| 167 GotAcceleratedCAContextFrame(ca_context_id, pixel_size, scale_factor); | |
| 168 break; | |
| 169 } | |
| 170 default: | |
| 171 DLOG(ERROR) << "Unrecognized accelerated frame type."; | |
| 172 return; | |
| 173 } | |
| 174 | 163 |
| 175 AcknowledgeAcceleratedFrame(); | 164 AcknowledgeAcceleratedFrame(); |
| 176 } | 165 } |
| 177 | 166 |
| 178 void AcceleratedWidgetMac::GotAcceleratedCAContextFrame( | 167 void AcceleratedWidgetMac::GotAcceleratedCAContextFrame( |
| 179 CAContextID ca_context_id, | 168 CAContextID ca_context_id, |
| 180 const gfx::Size& pixel_size, | 169 const gfx::Size& pixel_size, |
| 181 float scale_factor) { | 170 float scale_factor) { |
| 182 last_swap_size_dip_ = gfx::ConvertSizeToDIP(scale_factor, pixel_size); | 171 last_swap_size_dip_ = gfx::ConvertSizeToDIP(scale_factor, pixel_size); |
| 183 | 172 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 199 // If this replacing a same-type layer, remove it now that the new layer is | 188 // If this replacing a same-type layer, remove it now that the new layer is |
| 200 // in the hierarchy. | 189 // in the hierarchy. |
| 201 if (old_ca_context_layer != ca_context_layer_) | 190 if (old_ca_context_layer != ca_context_layer_) |
| 202 DestroyCAContextLayer(old_ca_context_layer); | 191 DestroyCAContextLayer(old_ca_context_layer); |
| 203 | 192 |
| 204 // Remove any different-type layers that this is replacing. | 193 // Remove any different-type layers that this is replacing. |
| 205 DestroyLocalLayer(); | 194 DestroyLocalLayer(); |
| 206 } | 195 } |
| 207 | 196 |
| 208 void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrame( | 197 void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrame( |
| 209 IOSurfaceID io_surface_id, | 198 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 210 const gfx::Size& pixel_size, | 199 const gfx::Size& pixel_size, |
| 211 float scale_factor) { | 200 float scale_factor) { |
| 212 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | 201 GotIOSurfaceFrame(io_surface, pixel_size, scale_factor, false); |
| 213 IOSurfaceLookup(io_surface_id)); | |
| 214 GotIOSurfaceFrame(io_surface, pixel_size, scale_factor, true); | |
| 215 } | 202 } |
| 216 | 203 |
| 217 void AcceleratedWidgetMac::EnsureLocalLayer() { | 204 void AcceleratedWidgetMac::EnsureLocalLayer() { |
| 218 if (!local_layer_) { | 205 if (!local_layer_) { |
| 219 local_layer_.reset([[CALayer alloc] init]); | 206 local_layer_.reset([[CALayer alloc] init]); |
| 220 // Setting contents gravity is necessary to prevent the layer from being | 207 // Setting contents gravity is necessary to prevent the layer from being |
| 221 // scaled during dyanmic resizes (especially with devtools open). | 208 // scaled during dyanmic resizes (especially with devtools open). |
| 222 [local_layer_ setContentsGravity:kCAGravityTopLeft]; | 209 [local_layer_ setContentsGravity:kCAGravityTopLeft]; |
| 223 [flipped_layer_ addSublayer:local_layer_]; | 210 [flipped_layer_ addSublayer:local_layer_]; |
| 224 } | 211 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 if (accelerated_frame_drawn_callback_.is_null()) | 274 if (accelerated_frame_drawn_callback_.is_null()) |
| 288 return; | 275 return; |
| 289 accelerated_frame_drawn_callback_.Run(); | 276 accelerated_frame_drawn_callback_.Run(); |
| 290 accelerated_frame_drawn_callback_.Reset(); | 277 accelerated_frame_drawn_callback_.Reset(); |
| 291 if (view_) | 278 if (view_) |
| 292 view_->AcceleratedWidgetSwapCompleted(accelerated_latency_info_); | 279 view_->AcceleratedWidgetSwapCompleted(accelerated_latency_info_); |
| 293 accelerated_latency_info_.clear(); | 280 accelerated_latency_info_.clear(); |
| 294 } | 281 } |
| 295 | 282 |
| 296 void AcceleratedWidgetMacGotAcceleratedFrame( | 283 void AcceleratedWidgetMacGotAcceleratedFrame( |
| 297 gfx::AcceleratedWidget widget, uint64 surface_handle, | 284 gfx::AcceleratedWidget widget, |
| 285 CAContextID ca_context_id, |
| 286 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 298 const std::vector<ui::LatencyInfo>& latency_info, | 287 const std::vector<ui::LatencyInfo>& latency_info, |
| 299 const gfx::Size& pixel_size, | 288 const gfx::Size& pixel_size, |
| 300 float scale_factor, | 289 float scale_factor, |
| 301 const gfx::Rect& pixel_damage_rect, | 290 const gfx::Rect& pixel_damage_rect, |
| 302 const base::Closure& drawn_callback, | 291 const base::Closure& drawn_callback, |
| 303 bool* disable_throttling, int* renderer_id, | 292 bool* disable_throttling, |
| 304 base::TimeTicks* vsync_timebase, base::TimeDelta* vsync_interval) { | 293 int* renderer_id, |
| 294 base::TimeTicks* vsync_timebase, |
| 295 base::TimeDelta* vsync_interval) { |
| 305 AcceleratedWidgetMac* accelerated_widget_mac = | 296 AcceleratedWidgetMac* accelerated_widget_mac = |
| 306 GetHelperFromAcceleratedWidget(widget); | 297 GetHelperFromAcceleratedWidget(widget); |
| 307 if (accelerated_widget_mac) { | 298 if (accelerated_widget_mac) { |
| 308 accelerated_widget_mac->GotAcceleratedFrame( | 299 accelerated_widget_mac->GotAcceleratedFrame( |
| 309 surface_handle, latency_info, pixel_size, scale_factor, | 300 ca_context_id, io_surface, latency_info, pixel_size, scale_factor, |
| 310 pixel_damage_rect, drawn_callback); | 301 pixel_damage_rect, drawn_callback); |
| 311 *disable_throttling = | 302 *disable_throttling = |
| 312 accelerated_widget_mac->IsRendererThrottlingDisabled(); | 303 accelerated_widget_mac->IsRendererThrottlingDisabled(); |
| 313 *renderer_id = accelerated_widget_mac->GetRendererID(); | 304 *renderer_id = accelerated_widget_mac->GetRendererID(); |
| 314 accelerated_widget_mac->GetVSyncParameters(vsync_timebase, vsync_interval); | 305 accelerated_widget_mac->GetVSyncParameters(vsync_timebase, vsync_interval); |
| 315 } else { | 306 } else { |
| 316 *disable_throttling = false; | 307 *disable_throttling = false; |
| 317 *renderer_id = 0; | 308 *renderer_id = 0; |
| 318 *vsync_timebase = base::TimeTicks(); | 309 *vsync_timebase = base::TimeTicks(); |
| 319 *vsync_interval = base::TimeDelta(); | 310 *vsync_interval = base::TimeDelta(); |
| 320 } | 311 } |
| 321 } | 312 } |
| 322 | 313 |
| 323 void AcceleratedWidgetMacGotIOSurfaceFrame( | 314 void AcceleratedWidgetMacGotIOSurfaceFrame( |
| 324 gfx::AcceleratedWidget widget, | 315 gfx::AcceleratedWidget widget, |
| 325 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 316 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 326 const gfx::Size& pixel_size, | 317 const gfx::Size& pixel_size, |
| 327 float scale_factor, | 318 float scale_factor, |
| 328 bool flip_y) { | 319 bool flip_y) { |
| 329 AcceleratedWidgetMac* accelerated_widget_mac = | 320 AcceleratedWidgetMac* accelerated_widget_mac = |
| 330 GetHelperFromAcceleratedWidget(widget); | 321 GetHelperFromAcceleratedWidget(widget); |
| 331 if (accelerated_widget_mac) { | 322 if (accelerated_widget_mac) { |
| 332 accelerated_widget_mac->GotIOSurfaceFrame(io_surface, pixel_size, | 323 accelerated_widget_mac->GotIOSurfaceFrame(io_surface, pixel_size, |
| 333 scale_factor, flip_y); | 324 scale_factor, flip_y); |
| 334 } | 325 } |
| 335 } | 326 } |
| 336 | 327 |
| 337 } // namespace ui | 328 } // namespace ui |
| OLD | NEW |