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