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 // canDrawInCGLContext for other value meanings. | |
erikchen
2015/05/14 01:43:53
This comment is out of date.
ccameron
2015/05/14 01:55:12
Oops. Changed to LayerCanDraw.
| |
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 if (has_pending_draw_) { | |
443 // If there is a draw pending then increase the signal from 2 to 3, to | |
444 // indicate that there is a swap pending, and CoreAnimation has asked to | |
445 // draw it. | |
446 TRACE_COUNTER_ID1("gpu", "CALayerPendingSwap", this, 3); | |
erikchen
2015/05/14 01:43:53
Why is this not an instantaneous blip? When I look
ccameron
2015/05/14 01:55:12
I didn't feel that having a blip was helpful. It w
| |
447 } else { | |
448 // If there is not a draw pending, then give an instantaneous blip up from | |
449 // 0 to 1, indicating that CoreAnimation was ready to draw a frame, but we | |
450 // were not (or didn't have new content to draw). | |
451 TRACE_COUNTER_ID1("gpu", "CALayerPendingSwap", this, 1); | |
452 TRACE_COUNTER_ID1("gpu", "CALayerPendingSwap", this, 0); | |
453 } | |
454 | |
433 if (has_pending_draw_) { | 455 if (has_pending_draw_) { |
434 can_draw_returned_false_count_ = 0; | 456 can_draw_returned_false_count_ = 0; |
435 return true; | 457 return true; |
436 } else { | 458 } else { |
437 if ([layer_ isAsynchronous]) { | 459 if ([layer_ isAsynchronous]) { |
438 DCHECK(!gpu_vsync_disabled_); | 460 DCHECK(!gpu_vsync_disabled_); |
439 // If we are in asynchronous mode, we will be getting callbacks at every | 461 // 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 | 462 // 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 | 463 // in a row, ask that we stop getting these callback for now, so that we |
442 // don't waste CPU cycles. | 464 // don't waste CPU cycles. |
443 if (can_draw_returned_false_count_ >= kCanDrawFalsesBeforeSwitchFromAsync) | 465 if (can_draw_returned_false_count_ >= kCanDrawFalsesBeforeSwitchFromAsync) |
444 [layer_ setAsynchronous:NO]; | 466 [layer_ setAsynchronous:NO]; |
445 else | 467 else |
446 can_draw_returned_false_count_ += 1; | 468 can_draw_returned_false_count_ += 1; |
447 } | 469 } |
448 return false; | 470 return false; |
449 } | 471 } |
450 } | 472 } |
451 | 473 |
452 void CALayerStorageProvider::LayerDoDraw() { | 474 void CALayerStorageProvider::LayerDoDraw() { |
475 TRACE_EVENT0("gpu", "CALayerStorageProvider::LayerDoDraw"); | |
453 if (gfx::GetGLImplementation() == | 476 if (gfx::GetGLImplementation() == |
454 gfx::kGLImplementationDesktopGLCoreProfile) { | 477 gfx::kGLImplementationDesktopGLCoreProfile) { |
455 glClearColor(1, 0, 1, 1); | 478 glClearColor(1, 0, 1, 1); |
456 glClear(GL_COLOR_BUFFER_BIT); | 479 glClear(GL_COLOR_BUFFER_BIT); |
457 glDisable(GL_BLEND); | 480 glDisable(GL_BLEND); |
458 glDisable(GL_CULL_FACE); | 481 glDisable(GL_CULL_FACE); |
459 glDisable(GL_DEPTH_TEST); | 482 glDisable(GL_DEPTH_TEST); |
460 glDisable(GL_STENCIL_TEST); | 483 glDisable(GL_STENCIL_TEST); |
461 glDisable(GL_SCISSOR_TEST); | 484 glDisable(GL_SCISSOR_TEST); |
462 | 485 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 | 566 |
544 void CALayerStorageProvider::UnblockBrowserIfNeeded() { | 567 void CALayerStorageProvider::UnblockBrowserIfNeeded() { |
545 if (!has_pending_draw_) | 568 if (!has_pending_draw_) |
546 return; | 569 return; |
547 pending_draw_weak_factory_.InvalidateWeakPtrs(); | 570 pending_draw_weak_factory_.InvalidateWeakPtrs(); |
548 has_pending_draw_ = false; | 571 has_pending_draw_ = false; |
549 transport_surface_->SendSwapBuffers( | 572 transport_surface_->SendSwapBuffers( |
550 ui::SurfaceHandleFromCAContextID([context_ contextId]), | 573 ui::SurfaceHandleFromCAContextID([context_ contextId]), |
551 fbo_pixel_size_, | 574 fbo_pixel_size_, |
552 fbo_scale_factor_); | 575 fbo_scale_factor_); |
576 | |
577 // A trace value of 0 indicates that there is no longer a pending swap ack. | |
578 TRACE_COUNTER_ID1("gpu", "CALayerPendingSwap", this, 0); | |
553 } | 579 } |
554 | 580 |
555 } // namespace content | 581 } // namespace content |
OLD | NEW |