| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 | 126 |
| 127 void AcceleratedWidgetMac::EndPumpingFrames() { | 127 void AcceleratedWidgetMac::EndPumpingFrames() { |
| 128 [io_surface_layer_ endPumpingFrames]; | 128 [io_surface_layer_ endPumpingFrames]; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void AcceleratedWidgetMac::GotAcceleratedFrame( | 131 void AcceleratedWidgetMac::GotAcceleratedFrame( |
| 132 uint64 surface_handle, | 132 uint64 surface_handle, |
| 133 const std::vector<ui::LatencyInfo>& latency_info, | 133 const std::vector<ui::LatencyInfo>& latency_info, |
| 134 gfx::Size pixel_size, float scale_factor, | 134 gfx::Size pixel_size, float scale_factor, |
| 135 gfx::Rect pixel_damage_rect, |
| 135 const base::Closure& drawn_callback) { | 136 const base::Closure& drawn_callback) { |
| 136 static bool use_ns_gl_surfaces = | 137 static bool use_ns_gl_surfaces = |
| 137 base::CommandLine::ForCurrentProcess()->HasSwitch( | 138 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 138 switches::kEnableNSGLSurfaces); | 139 switches::kEnableNSGLSurfaces); |
| 139 | 140 |
| 140 // Record the surface and latency info to use when acknowledging this frame. | 141 // Record the surface and latency info to use when acknowledging this frame. |
| 141 DCHECK(accelerated_frame_drawn_callback_.is_null()); | 142 DCHECK(accelerated_frame_drawn_callback_.is_null()); |
| 142 accelerated_frame_drawn_callback_ = drawn_callback; | 143 accelerated_frame_drawn_callback_ = drawn_callback; |
| 143 accelerated_latency_info_.insert(accelerated_latency_info_.end(), | 144 accelerated_latency_info_.insert(accelerated_latency_info_.end(), |
| 144 latency_info.begin(), latency_info.end()); | 145 latency_info.begin(), latency_info.end()); |
| 145 | 146 |
| 146 // If there is no view and therefore no superview to draw into, early-out. | 147 // If there is no view and therefore no superview to draw into, early-out. |
| 147 if (!view_) { | 148 if (!view_) { |
| 148 AcknowledgeAcceleratedFrame(); | 149 AcknowledgeAcceleratedFrame(); |
| 149 return; | 150 return; |
| 150 } | 151 } |
| 151 | 152 |
| 152 // Disable the fade-in or fade-out effect if we create or remove layers. | 153 // Disable the fade-in or fade-out effect if we create or remove layers. |
| 153 ScopedCAActionDisabler disabler; | 154 ScopedCAActionDisabler disabler; |
| 154 | 155 |
| 155 last_swap_size_dip_ = gfx::ConvertSizeToDIP(scale_factor, pixel_size); | 156 last_swap_size_dip_ = gfx::ConvertSizeToDIP(scale_factor, pixel_size); |
| 156 switch (GetSurfaceHandleType(surface_handle)) { | 157 switch (GetSurfaceHandleType(surface_handle)) { |
| 157 case kSurfaceHandleTypeIOSurface: { | 158 case kSurfaceHandleTypeIOSurface: { |
| 158 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(surface_handle); | 159 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(surface_handle); |
| 159 if (use_ns_gl_surfaces) { | 160 if (use_ns_gl_surfaces) { |
| 160 GotAcceleratedIOSurfaceFrameNSGL( | 161 GotAcceleratedIOSurfaceFrameNSGL( |
| 161 io_surface_id, pixel_size, scale_factor); | 162 io_surface_id, pixel_size, scale_factor, pixel_damage_rect); |
| 162 } else { | 163 } else { |
| 163 GotAcceleratedIOSurfaceFrame(io_surface_id, pixel_size, scale_factor); | 164 GotAcceleratedIOSurfaceFrame(io_surface_id, pixel_size, scale_factor); |
| 164 } | 165 } |
| 165 break; | 166 break; |
| 166 } | 167 } |
| 167 case kSurfaceHandleTypeCAContext: { | 168 case kSurfaceHandleTypeCAContext: { |
| 168 CAContextID ca_context_id = CAContextIDFromSurfaceHandle(surface_handle); | 169 CAContextID ca_context_id = CAContextIDFromSurfaceHandle(surface_handle); |
| 169 GotAcceleratedCAContextFrame(ca_context_id, pixel_size, scale_factor); | 170 GotAcceleratedCAContextFrame(ca_context_id, pixel_size, scale_factor); |
| 170 break; | 171 break; |
| 171 } | 172 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 202 // in the hierarchy. | 203 // in the hierarchy. |
| 203 if (old_ca_context_layer != ca_context_layer_) | 204 if (old_ca_context_layer != ca_context_layer_) |
| 204 DestroyCAContextLayer(old_ca_context_layer); | 205 DestroyCAContextLayer(old_ca_context_layer); |
| 205 | 206 |
| 206 // Remove any different-type layers that this is replacing. | 207 // Remove any different-type layers that this is replacing. |
| 207 DestroyIOSurfaceLayer(io_surface_layer_); | 208 DestroyIOSurfaceLayer(io_surface_layer_); |
| 208 DestroySoftwareLayer(); | 209 DestroySoftwareLayer(); |
| 209 } | 210 } |
| 210 | 211 |
| 211 void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrameNSGL( | 212 void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrameNSGL( |
| 212 IOSurfaceID io_surface_id, gfx::Size pixel_size, float scale_factor) { | 213 IOSurfaceID io_surface_id, gfx::Size pixel_size, float scale_factor, |
| 214 gfx::Rect pixel_damage_rect) { |
| 213 if (!io_surface_ns_gl_surface_) { | 215 if (!io_surface_ns_gl_surface_) { |
| 214 io_surface_ns_gl_surface_.reset( | 216 io_surface_ns_gl_surface_.reset( |
| 215 IOSurfaceNSGLSurface::Create(view_->AcceleratedWidgetGetNSView())); | 217 IOSurfaceNSGLSurface::Create(view_->AcceleratedWidgetGetNSView())); |
| 216 } | 218 } |
| 217 | 219 |
| 218 if (!io_surface_ns_gl_surface_) { | 220 if (!io_surface_ns_gl_surface_) { |
| 219 LOG(ERROR) << "Failed to create IOSurfaceNSGLSurface"; | 221 LOG(ERROR) << "Failed to create IOSurfaceNSGLSurface"; |
| 220 AcknowledgeAcceleratedFrame(); | 222 AcknowledgeAcceleratedFrame(); |
| 221 return; | 223 return; |
| 222 } | 224 } |
| 223 | 225 |
| 224 io_surface_ns_gl_surface_->GotFrame(io_surface_id, pixel_size, scale_factor); | 226 io_surface_ns_gl_surface_->GotFrame( |
| 227 io_surface_id, pixel_size, scale_factor, pixel_damage_rect); |
| 225 AcknowledgeAcceleratedFrame(); | 228 AcknowledgeAcceleratedFrame(); |
| 226 } | 229 } |
| 227 | 230 |
| 228 void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrame( | 231 void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrame( |
| 229 IOSurfaceID io_surface_id, | 232 IOSurfaceID io_surface_id, |
| 230 gfx::Size pixel_size, | 233 gfx::Size pixel_size, |
| 231 float scale_factor) { | 234 float scale_factor) { |
| 232 // In the layer is replaced, keep the old one around until after the new one | 235 // In the layer is replaced, keep the old one around until after the new one |
| 233 // is installed to avoid flashes. | 236 // is installed to avoid flashes. |
| 234 base::scoped_nsobject<IOSurfaceLayer> old_io_surface_layer = | 237 base::scoped_nsobject<IOSurfaceLayer> old_io_surface_layer = |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // Poison the context being used and request a mulligan. | 385 // Poison the context being used and request a mulligan. |
| 383 [io_surface_layer_ poisonContextAndSharegroup]; | 386 [io_surface_layer_ poisonContextAndSharegroup]; |
| 384 | 387 |
| 385 if (view_) | 388 if (view_) |
| 386 view_->AcceleratedWidgetHitError(); | 389 view_->AcceleratedWidgetHitError(); |
| 387 } | 390 } |
| 388 | 391 |
| 389 void AcceleratedWidgetMacGotAcceleratedFrame( | 392 void AcceleratedWidgetMacGotAcceleratedFrame( |
| 390 gfx::AcceleratedWidget widget, uint64 surface_handle, | 393 gfx::AcceleratedWidget widget, uint64 surface_handle, |
| 391 const std::vector<ui::LatencyInfo>& latency_info, | 394 const std::vector<ui::LatencyInfo>& latency_info, |
| 392 gfx::Size pixel_size, float scale_factor, | 395 gfx::Size pixel_size, float scale_factor, gfx::Rect pixel_damage_rect, |
| 393 const base::Closure& drawn_callback, | 396 const base::Closure& drawn_callback, |
| 394 bool* disable_throttling, int* renderer_id) { | 397 bool* disable_throttling, int* renderer_id) { |
| 395 AcceleratedWidgetMac* accelerated_widget_mac = | 398 AcceleratedWidgetMac* accelerated_widget_mac = |
| 396 GetHelperFromAcceleratedWidget(widget); | 399 GetHelperFromAcceleratedWidget(widget); |
| 397 if (accelerated_widget_mac) { | 400 if (accelerated_widget_mac) { |
| 398 accelerated_widget_mac->GotAcceleratedFrame( | 401 accelerated_widget_mac->GotAcceleratedFrame( |
| 399 surface_handle, latency_info, pixel_size, scale_factor, drawn_callback); | 402 surface_handle, latency_info, pixel_size, scale_factor, |
| 403 pixel_damage_rect, drawn_callback); |
| 400 *disable_throttling = | 404 *disable_throttling = |
| 401 accelerated_widget_mac->IsRendererThrottlingDisabled(); | 405 accelerated_widget_mac->IsRendererThrottlingDisabled(); |
| 402 *renderer_id = accelerated_widget_mac->GetRendererID(); | 406 *renderer_id = accelerated_widget_mac->GetRendererID(); |
| 403 } else { | 407 } else { |
| 404 *disable_throttling = false; | 408 *disable_throttling = false; |
| 405 *renderer_id = 0; | 409 *renderer_id = 0; |
| 406 } | 410 } |
| 407 } | 411 } |
| 408 | 412 |
| 409 void AcceleratedWidgetMacGotSoftwareFrame( | 413 void AcceleratedWidgetMacGotSoftwareFrame( |
| 410 gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas) { | 414 gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas) { |
| 411 AcceleratedWidgetMac* accelerated_widget_mac = | 415 AcceleratedWidgetMac* accelerated_widget_mac = |
| 412 GetHelperFromAcceleratedWidget(widget); | 416 GetHelperFromAcceleratedWidget(widget); |
| 413 if (accelerated_widget_mac) | 417 if (accelerated_widget_mac) |
| 414 accelerated_widget_mac->GotSoftwareFrame(scale_factor, canvas); | 418 accelerated_widget_mac->GotSoftwareFrame(scale_factor, canvas); |
| 415 } | 419 } |
| 416 | 420 |
| 417 } // namespace ui | 421 } // namespace ui |
| OLD | NEW |