Chromium Code Reviews| 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 "content/common/gpu/image_transport_surface_calayer_mac.h" | 5 #include "content/common/gpu/image_transport_surface_calayer_mac.h" |
| 6 | 6 |
| 7 #include <OpenGL/CGLRenderers.h> | 7 #include <OpenGL/CGLRenderers.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/mac/sdk_forward_declarations.h" | 10 #include "base/mac/sdk_forward_declarations.h" |
| 11 #include "base/trace_event/trace_event.h" | |
| 11 #include "ui/accelerated_widget_mac/surface_handle_types.h" | 12 #include "ui/accelerated_widget_mac/surface_handle_types.h" |
| 12 #include "ui/base/cocoa/animation_utils.h" | 13 #include "ui/base/cocoa/animation_utils.h" |
| 13 #include "ui/gfx/geometry/size_conversions.h" | 14 #include "ui/gfx/geometry/size_conversions.h" |
| 14 #include "ui/gl/gl_gl_api_implementation.h" | 15 #include "ui/gl/gl_gl_api_implementation.h" |
| 15 #include "ui/gl/gl_switches.h" | 16 #include "ui/gl/gl_switches.h" |
| 16 #include "ui/gl/gpu_switching_manager.h" | 17 #include "ui/gl/gpu_switching_manager.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 const size_t kFramesToKeepCAContextAfterDiscard = 2; | 20 const size_t kFramesToKeepCAContextAfterDiscard = 2; |
| 20 const size_t kCanDrawFalsesBeforeSwitchFromAsync = 4; | 21 const size_t kCanDrawFalsesBeforeSwitchFromAsync = 4; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 can_draw_returned_false_count_ = 0; | 291 can_draw_returned_false_count_ = 0; |
| 291 } | 292 } |
| 292 | 293 |
| 293 void CALayerStorageProvider::FrameSizeChanged(const gfx::Size& pixel_size, | 294 void CALayerStorageProvider::FrameSizeChanged(const gfx::Size& pixel_size, |
| 294 float scale_factor) { | 295 float scale_factor) { |
| 295 DCHECK_EQ(fbo_pixel_size_.ToString(), pixel_size.ToString()); | 296 DCHECK_EQ(fbo_pixel_size_.ToString(), pixel_size.ToString()); |
| 296 DCHECK_EQ(fbo_scale_factor_, scale_factor); | 297 DCHECK_EQ(fbo_scale_factor_, scale_factor); |
| 297 } | 298 } |
| 298 | 299 |
| 299 void CALayerStorageProvider::SwapBuffers() { | 300 void CALayerStorageProvider::SwapBuffers() { |
| 301 TRACE_EVENT0("gpu", "CALayerStorageProvider::SwapBuffers"); | |
| 300 DCHECK(!has_pending_draw_); | 302 DCHECK(!has_pending_draw_); |
| 301 | 303 |
| 304 // A trace value of 2 indicates that there is a pending swap ack. See | |
| 305 // LayerCanDraw for other value meanings. | |
| 306 TRACE_COUNTER_ID1("gpu", "CALayerPendingSwap", this, 2); | |
| 307 | |
| 302 // Recreate the CALayer on the new GPU if a GPU switch has occurred. Note | 308 // Recreate the CALayer on the new GPU if a GPU switch has occurred. Note |
| 303 // that the CAContext will retain a reference to the old CALayer until the | 309 // that the CAContext will retain a reference to the old CALayer until the |
| 304 // call to -[CAContext setLayer:] replaces the old CALayer with the new one. | 310 // call to -[CAContext setLayer:] replaces the old CALayer with the new one. |
| 305 if (recreate_layer_after_gpu_switch_) { | 311 if (recreate_layer_after_gpu_switch_) { |
| 306 [layer_ resetStorageProvider]; | 312 [layer_ resetStorageProvider]; |
| 307 layer_.reset(); | 313 layer_.reset(); |
| 308 recreate_layer_after_gpu_switch_ = false; | 314 recreate_layer_after_gpu_switch_ = false; |
| 309 } | 315 } |
| 310 | 316 |
| 311 // Set the pending draw flag only after destroying the old layer (otherwise | 317 // Set the pending draw flag only after destroying the old layer (otherwise |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 previously_discarded_contexts_.push_back( | 415 previously_discarded_contexts_.push_back( |
| 410 base::scoped_nsobject<CAContext>()); | 416 base::scoped_nsobject<CAContext>()); |
| 411 } | 417 } |
| 412 previously_discarded_contexts_.push_back(context_); | 418 previously_discarded_contexts_.push_back(context_); |
| 413 | 419 |
| 414 context_.reset(); | 420 context_.reset(); |
| 415 } | 421 } |
| 416 | 422 |
| 417 void CALayerStorageProvider::SwapBuffersAckedByBrowser( | 423 void CALayerStorageProvider::SwapBuffersAckedByBrowser( |
| 418 bool disable_throttling) { | 424 bool disable_throttling) { |
| 425 TRACE_EVENT0("gpu", "CALayerStorageProvider::SwapBuffersAckedByBrowser"); | |
| 419 throttling_disabled_ = disable_throttling; | 426 throttling_disabled_ = disable_throttling; |
| 420 if (!previously_discarded_contexts_.empty()) | 427 if (!previously_discarded_contexts_.empty()) |
| 421 previously_discarded_contexts_.pop_front(); | 428 previously_discarded_contexts_.pop_front(); |
| 422 } | 429 } |
| 423 | 430 |
| 424 CGLContextObj CALayerStorageProvider::LayerShareGroupContext() { | 431 CGLContextObj CALayerStorageProvider::LayerShareGroupContext() { |
| 425 return share_group_context_; | 432 return share_group_context_; |
| 426 } | 433 } |
| 427 | 434 |
| 428 base::Closure CALayerStorageProvider::LayerShareGroupContextDirtiedCallback() { | 435 base::Closure CALayerStorageProvider::LayerShareGroupContextDirtiedCallback() { |
| 429 return share_group_context_dirtied_callback_; | 436 return share_group_context_dirtied_callback_; |
| 430 } | 437 } |
| 431 | 438 |
| 432 bool CALayerStorageProvider::LayerCanDraw() { | 439 bool CALayerStorageProvider::LayerCanDraw() { |
| 440 TRACE_EVENT0("gpu", "CALayerStorageProvider::LayerCanDraw"); | |
| 441 | |
| 442 // This would tracing would be more natural to do with a pseudo-thread | |
|
erikchen
2015/05/14 16:04:08
grammar
ccameron
2015/05/14 17:20:14
Done.
| |
| 443 // for each layer, rather than a counter. | |
| 444 // http://crbug.com/366300 | |
| 445 if (has_pending_draw_) { | |
| 446 // If there is a draw pending then increase the signal from 2 to 3, to | |
| 447 // indicate that there is a swap pending, and CoreAnimation has asked to | |
| 448 // draw it. | |
| 449 TRACE_COUNTER_ID1("gpu", "CALayerPendingSwap", this, 3); | |
| 450 } else { | |
| 451 // If there is not a draw pending, then give an instantaneous blip up from | |
| 452 // 0 to 1, indicating that CoreAnimation was ready to draw a frame but we | |
| 453 // were not (or didn't have new content to draw). | |
| 454 TRACE_COUNTER_ID1("gpu", "CALayerPendingSwap", this, 1); | |
| 455 TRACE_COUNTER_ID1("gpu", "CALayerPendingSwap", this, 0); | |
| 456 } | |
| 457 | |
| 433 if (has_pending_draw_) { | 458 if (has_pending_draw_) { |
| 434 can_draw_returned_false_count_ = 0; | 459 can_draw_returned_false_count_ = 0; |
| 435 return true; | 460 return true; |
| 436 } else { | 461 } else { |
| 437 if ([layer_ isAsynchronous]) { | 462 if ([layer_ isAsynchronous]) { |
| 438 DCHECK(!gpu_vsync_disabled_); | 463 DCHECK(!gpu_vsync_disabled_); |
| 439 // If we are in asynchronous mode, we will be getting callbacks at every | 464 // If we are in asynchronous mode, we will be getting callbacks at every |
| 440 // vsync, asking us if we have anything to draw. If we get many of these | 465 // vsync, asking us if we have anything to draw. If we get many of these |
| 441 // in a row, ask that we stop getting these callback for now, so that we | 466 // in a row, ask that we stop getting these callback for now, so that we |
| 442 // don't waste CPU cycles. | 467 // don't waste CPU cycles. |
| 443 if (can_draw_returned_false_count_ >= kCanDrawFalsesBeforeSwitchFromAsync) | 468 if (can_draw_returned_false_count_ >= kCanDrawFalsesBeforeSwitchFromAsync) |
| 444 [layer_ setAsynchronous:NO]; | 469 [layer_ setAsynchronous:NO]; |
| 445 else | 470 else |
| 446 can_draw_returned_false_count_ += 1; | 471 can_draw_returned_false_count_ += 1; |
| 447 } | 472 } |
| 448 return false; | 473 return false; |
| 449 } | 474 } |
| 450 } | 475 } |
| 451 | 476 |
| 452 void CALayerStorageProvider::LayerDoDraw() { | 477 void CALayerStorageProvider::LayerDoDraw() { |
| 478 TRACE_EVENT0("gpu", "CALayerStorageProvider::LayerDoDraw"); | |
| 453 if (gfx::GetGLImplementation() == | 479 if (gfx::GetGLImplementation() == |
| 454 gfx::kGLImplementationDesktopGLCoreProfile) { | 480 gfx::kGLImplementationDesktopGLCoreProfile) { |
| 455 glClearColor(1, 0, 1, 1); | 481 glClearColor(1, 0, 1, 1); |
| 456 glClear(GL_COLOR_BUFFER_BIT); | 482 glClear(GL_COLOR_BUFFER_BIT); |
| 457 glDisable(GL_BLEND); | 483 glDisable(GL_BLEND); |
| 458 glDisable(GL_CULL_FACE); | 484 glDisable(GL_CULL_FACE); |
| 459 glDisable(GL_DEPTH_TEST); | 485 glDisable(GL_DEPTH_TEST); |
| 460 glDisable(GL_STENCIL_TEST); | 486 glDisable(GL_STENCIL_TEST); |
| 461 glDisable(GL_SCISSOR_TEST); | 487 glDisable(GL_SCISSOR_TEST); |
| 462 | 488 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 | 569 |
| 544 void CALayerStorageProvider::UnblockBrowserIfNeeded() { | 570 void CALayerStorageProvider::UnblockBrowserIfNeeded() { |
| 545 if (!has_pending_draw_) | 571 if (!has_pending_draw_) |
| 546 return; | 572 return; |
| 547 pending_draw_weak_factory_.InvalidateWeakPtrs(); | 573 pending_draw_weak_factory_.InvalidateWeakPtrs(); |
| 548 has_pending_draw_ = false; | 574 has_pending_draw_ = false; |
| 549 transport_surface_->SendSwapBuffers( | 575 transport_surface_->SendSwapBuffers( |
| 550 ui::SurfaceHandleFromCAContextID([context_ contextId]), | 576 ui::SurfaceHandleFromCAContextID([context_ contextId]), |
| 551 fbo_pixel_size_, | 577 fbo_pixel_size_, |
| 552 fbo_scale_factor_); | 578 fbo_scale_factor_); |
| 579 | |
| 580 // A trace value of 0 indicates that there is no longer a pending swap ack. | |
| 581 TRACE_COUNTER_ID1("gpu", "CALayerPendingSwap", this, 0); | |
| 553 } | 582 } |
| 554 | 583 |
| 555 } // namespace content | 584 } // namespace content |
| OLD | NEW |