| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 [io_surface_layer_ beginPumpingFrames]; | 124 [io_surface_layer_ beginPumpingFrames]; |
| 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 const gfx::Size& pixel_size, |
| 135 float scale_factor, |
| 136 const gfx::Rect& pixel_damage_rect, |
| 135 const base::Closure& drawn_callback) { | 137 const base::Closure& drawn_callback) { |
| 136 static bool use_ns_gl_surfaces = | 138 static bool use_ns_gl_surfaces = |
| 137 base::CommandLine::ForCurrentProcess()->HasSwitch( | 139 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 138 switches::kEnableNSGLSurfaces); | 140 switches::kEnableNSGLSurfaces); |
| 139 | 141 |
| 140 // Record the surface and latency info to use when acknowledging this frame. | 142 // Record the surface and latency info to use when acknowledging this frame. |
| 141 DCHECK(accelerated_frame_drawn_callback_.is_null()); | 143 DCHECK(accelerated_frame_drawn_callback_.is_null()); |
| 142 accelerated_frame_drawn_callback_ = drawn_callback; | 144 accelerated_frame_drawn_callback_ = drawn_callback; |
| 143 accelerated_latency_info_.insert(accelerated_latency_info_.end(), | 145 accelerated_latency_info_.insert(accelerated_latency_info_.end(), |
| 144 latency_info.begin(), latency_info.end()); | 146 latency_info.begin(), latency_info.end()); |
| 145 | 147 |
| 146 // If there is no view and therefore no superview to draw into, early-out. | 148 // If there is no view and therefore no superview to draw into, early-out. |
| 147 if (!view_) { | 149 if (!view_) { |
| 148 AcknowledgeAcceleratedFrame(); | 150 AcknowledgeAcceleratedFrame(); |
| 149 return; | 151 return; |
| 150 } | 152 } |
| 151 | 153 |
| 152 // Disable the fade-in or fade-out effect if we create or remove layers. | 154 // Disable the fade-in or fade-out effect if we create or remove layers. |
| 153 ScopedCAActionDisabler disabler; | 155 ScopedCAActionDisabler disabler; |
| 154 | 156 |
| 155 last_swap_size_dip_ = gfx::ConvertSizeToDIP(scale_factor, pixel_size); | 157 last_swap_size_dip_ = gfx::ConvertSizeToDIP(scale_factor, pixel_size); |
| 156 switch (GetSurfaceHandleType(surface_handle)) { | 158 switch (GetSurfaceHandleType(surface_handle)) { |
| 157 case kSurfaceHandleTypeIOSurface: { | 159 case kSurfaceHandleTypeIOSurface: { |
| 158 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(surface_handle); | 160 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(surface_handle); |
| 159 if (use_ns_gl_surfaces) { | 161 if (use_ns_gl_surfaces) { |
| 160 GotAcceleratedIOSurfaceFrameNSGL( | 162 GotAcceleratedIOSurfaceFrameNSGL( |
| 161 io_surface_id, pixel_size, scale_factor); | 163 io_surface_id, pixel_size, scale_factor, pixel_damage_rect); |
| 162 } else { | 164 } else { |
| 163 GotAcceleratedIOSurfaceFrame(io_surface_id, pixel_size, scale_factor); | 165 GotAcceleratedIOSurfaceFrame(io_surface_id, pixel_size, scale_factor); |
| 164 } | 166 } |
| 165 break; | 167 break; |
| 166 } | 168 } |
| 167 case kSurfaceHandleTypeCAContext: { | 169 case kSurfaceHandleTypeCAContext: { |
| 168 CAContextID ca_context_id = CAContextIDFromSurfaceHandle(surface_handle); | 170 CAContextID ca_context_id = CAContextIDFromSurfaceHandle(surface_handle); |
| 169 GotAcceleratedCAContextFrame(ca_context_id, pixel_size, scale_factor); | 171 GotAcceleratedCAContextFrame(ca_context_id, pixel_size, scale_factor); |
| 170 break; | 172 break; |
| 171 } | 173 } |
| 172 default: | 174 default: |
| 173 LOG(ERROR) << "Unrecognized accelerated frame type."; | 175 LOG(ERROR) << "Unrecognized accelerated frame type."; |
| 174 return; | 176 return; |
| 175 } | 177 } |
| 176 } | 178 } |
| 177 | 179 |
| 178 void AcceleratedWidgetMac::GotAcceleratedCAContextFrame( | 180 void AcceleratedWidgetMac::GotAcceleratedCAContextFrame( |
| 179 CAContextID ca_context_id, | 181 CAContextID ca_context_id, |
| 180 gfx::Size pixel_size, | 182 const gfx::Size& pixel_size, |
| 181 float scale_factor) { | 183 float scale_factor) { |
| 182 // In the layer is replaced, keep the old one around until after the new one | 184 // In the layer is replaced, keep the old one around until after the new one |
| 183 // is installed to avoid flashes. | 185 // is installed to avoid flashes. |
| 184 base::scoped_nsobject<CALayerHost> old_ca_context_layer = | 186 base::scoped_nsobject<CALayerHost> old_ca_context_layer = |
| 185 ca_context_layer_; | 187 ca_context_layer_; |
| 186 | 188 |
| 187 // Create the layer to host the layer exported by the GPU process with this | 189 // Create the layer to host the layer exported by the GPU process with this |
| 188 // particular CAContext ID. | 190 // particular CAContext ID. |
| 189 if ([ca_context_layer_ contextId] != ca_context_id) { | 191 if ([ca_context_layer_ contextId] != ca_context_id) { |
| 190 ca_context_layer_.reset([[CALayerHost alloc] init]); | 192 ca_context_layer_.reset([[CALayerHost alloc] init]); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 202 // in the hierarchy. | 204 // in the hierarchy. |
| 203 if (old_ca_context_layer != ca_context_layer_) | 205 if (old_ca_context_layer != ca_context_layer_) |
| 204 DestroyCAContextLayer(old_ca_context_layer); | 206 DestroyCAContextLayer(old_ca_context_layer); |
| 205 | 207 |
| 206 // Remove any different-type layers that this is replacing. | 208 // Remove any different-type layers that this is replacing. |
| 207 DestroyIOSurfaceLayer(io_surface_layer_); | 209 DestroyIOSurfaceLayer(io_surface_layer_); |
| 208 DestroySoftwareLayer(); | 210 DestroySoftwareLayer(); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrameNSGL( | 213 void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrameNSGL( |
| 212 IOSurfaceID io_surface_id, gfx::Size pixel_size, float scale_factor) { | 214 IOSurfaceID io_surface_id, |
| 215 const gfx::Size& pixel_size, |
| 216 float scale_factor, |
| 217 const gfx::Rect& pixel_damage_rect) { |
| 213 if (!io_surface_ns_gl_surface_) { | 218 if (!io_surface_ns_gl_surface_) { |
| 214 io_surface_ns_gl_surface_.reset( | 219 io_surface_ns_gl_surface_.reset( |
| 215 IOSurfaceNSGLSurface::Create(view_->AcceleratedWidgetGetNSView())); | 220 IOSurfaceNSGLSurface::Create(view_->AcceleratedWidgetGetNSView())); |
| 216 } | 221 } |
| 217 | 222 |
| 218 if (!io_surface_ns_gl_surface_) { | 223 if (!io_surface_ns_gl_surface_) { |
| 219 LOG(ERROR) << "Failed to create IOSurfaceNSGLSurface"; | 224 LOG(ERROR) << "Failed to create IOSurfaceNSGLSurface"; |
| 220 AcknowledgeAcceleratedFrame(); | 225 AcknowledgeAcceleratedFrame(); |
| 221 return; | 226 return; |
| 222 } | 227 } |
| 223 | 228 |
| 224 io_surface_ns_gl_surface_->GotFrame(io_surface_id, pixel_size, scale_factor); | 229 io_surface_ns_gl_surface_->GotFrame( |
| 230 io_surface_id, pixel_size, scale_factor, pixel_damage_rect); |
| 225 AcknowledgeAcceleratedFrame(); | 231 AcknowledgeAcceleratedFrame(); |
| 226 } | 232 } |
| 227 | 233 |
| 228 void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrame( | 234 void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrame( |
| 229 IOSurfaceID io_surface_id, | 235 IOSurfaceID io_surface_id, |
| 230 gfx::Size pixel_size, | 236 const gfx::Size& pixel_size, |
| 231 float scale_factor) { | 237 float scale_factor) { |
| 232 // In the layer is replaced, keep the old one around until after the new one | 238 // In the layer is replaced, keep the old one around until after the new one |
| 233 // is installed to avoid flashes. | 239 // is installed to avoid flashes. |
| 234 base::scoped_nsobject<IOSurfaceLayer> old_io_surface_layer = | 240 base::scoped_nsobject<IOSurfaceLayer> old_io_surface_layer = |
| 235 io_surface_layer_; | 241 io_surface_layer_; |
| 236 | 242 |
| 237 // Create or re-create an IOSurface layer if needed. If there already exists | 243 // Create or re-create an IOSurface layer if needed. If there already exists |
| 238 // a layer but it has the wrong scale factor or it was poisoned, re-create the | 244 // a layer but it has the wrong scale factor or it was poisoned, re-create the |
| 239 // layer. | 245 // layer. |
| 240 bool needs_new_layer = | 246 bool needs_new_layer = |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // Poison the context being used and request a mulligan. | 388 // Poison the context being used and request a mulligan. |
| 383 [io_surface_layer_ poisonContextAndSharegroup]; | 389 [io_surface_layer_ poisonContextAndSharegroup]; |
| 384 | 390 |
| 385 if (view_) | 391 if (view_) |
| 386 view_->AcceleratedWidgetHitError(); | 392 view_->AcceleratedWidgetHitError(); |
| 387 } | 393 } |
| 388 | 394 |
| 389 void AcceleratedWidgetMacGotAcceleratedFrame( | 395 void AcceleratedWidgetMacGotAcceleratedFrame( |
| 390 gfx::AcceleratedWidget widget, uint64 surface_handle, | 396 gfx::AcceleratedWidget widget, uint64 surface_handle, |
| 391 const std::vector<ui::LatencyInfo>& latency_info, | 397 const std::vector<ui::LatencyInfo>& latency_info, |
| 392 gfx::Size pixel_size, float scale_factor, | 398 const gfx::Size& pixel_size, |
| 399 float scale_factor, |
| 400 const gfx::Rect& pixel_damage_rect, |
| 393 const base::Closure& drawn_callback, | 401 const base::Closure& drawn_callback, |
| 394 bool* disable_throttling, int* renderer_id) { | 402 bool* disable_throttling, int* renderer_id) { |
| 395 AcceleratedWidgetMac* accelerated_widget_mac = | 403 AcceleratedWidgetMac* accelerated_widget_mac = |
| 396 GetHelperFromAcceleratedWidget(widget); | 404 GetHelperFromAcceleratedWidget(widget); |
| 397 if (accelerated_widget_mac) { | 405 if (accelerated_widget_mac) { |
| 398 accelerated_widget_mac->GotAcceleratedFrame( | 406 accelerated_widget_mac->GotAcceleratedFrame( |
| 399 surface_handle, latency_info, pixel_size, scale_factor, drawn_callback); | 407 surface_handle, latency_info, pixel_size, scale_factor, |
| 408 pixel_damage_rect, drawn_callback); |
| 400 *disable_throttling = | 409 *disable_throttling = |
| 401 accelerated_widget_mac->IsRendererThrottlingDisabled(); | 410 accelerated_widget_mac->IsRendererThrottlingDisabled(); |
| 402 *renderer_id = accelerated_widget_mac->GetRendererID(); | 411 *renderer_id = accelerated_widget_mac->GetRendererID(); |
| 403 } else { | 412 } else { |
| 404 *disable_throttling = false; | 413 *disable_throttling = false; |
| 405 *renderer_id = 0; | 414 *renderer_id = 0; |
| 406 } | 415 } |
| 407 } | 416 } |
| 408 | 417 |
| 409 void AcceleratedWidgetMacGotSoftwareFrame( | 418 void AcceleratedWidgetMacGotSoftwareFrame( |
| 410 gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas) { | 419 gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas) { |
| 411 AcceleratedWidgetMac* accelerated_widget_mac = | 420 AcceleratedWidgetMac* accelerated_widget_mac = |
| 412 GetHelperFromAcceleratedWidget(widget); | 421 GetHelperFromAcceleratedWidget(widget); |
| 413 if (accelerated_widget_mac) | 422 if (accelerated_widget_mac) |
| 414 accelerated_widget_mac->GotSoftwareFrame(scale_factor, canvas); | 423 accelerated_widget_mac->GotSoftwareFrame(scale_factor, canvas); |
| 415 } | 424 } |
| 416 | 425 |
| 417 } // namespace ui | 426 } // namespace ui |
| OLD | NEW |