| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #include <QuartzCore/QuartzCore.h> | 8 #include <QuartzCore/QuartzCore.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug/crash_logging.h" | 14 #include "base/debug/crash_logging.h" |
| 15 #include "base/debug/trace_event.h" | 15 #include "base/debug/trace_event.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/mac/mac_util.h" | 17 #include "base/mac/mac_util.h" |
| 18 #include "base/mac/scoped_cftyperef.h" | 18 #include "base/mac/scoped_cftyperef.h" |
| 19 #import "base/mac/scoped_nsobject.h" | 19 #import "base/mac/scoped_nsobject.h" |
| 20 #include "base/mac/sdk_forward_declarations.h" | 20 #include "base/mac/sdk_forward_declarations.h" |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/sys_string_conversions.h" | 25 #include "base/strings/sys_string_conversions.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/sys_info.h" | 27 #include "base/sys_info.h" |
| 28 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 28 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
| 29 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" | 29 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" |
| 30 #include "content/browser/compositor/browser_compositor_view_mac.h" |
| 30 #include "content/browser/compositor/resize_lock.h" | 31 #include "content/browser/compositor/resize_lock.h" |
| 31 #include "content/browser/frame_host/frame_tree.h" | 32 #include "content/browser/frame_host/frame_tree.h" |
| 32 #include "content/browser/frame_host/frame_tree_node.h" | 33 #include "content/browser/frame_host/frame_tree_node.h" |
| 33 #include "content/browser/frame_host/render_frame_host_impl.h" | 34 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 34 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" | 35 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" |
| 35 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" | 36 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" |
| 36 #include "content/browser/renderer_host/compositing_iosurface_mac.h" | 37 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
| 37 #include "content/browser/renderer_host/render_widget_helper.h" | 38 #include "content/browser/renderer_host/render_widget_helper.h" |
| 38 #include "content/browser/renderer_host/render_view_host_impl.h" | 39 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 39 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he
lper.h" | 40 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he
lper.h" |
| 40 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h
elper.h" | 41 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h
elper.h" |
| 42 #import "content/browser/renderer_host/software_layer_mac.h" |
| 41 #import "content/browser/renderer_host/text_input_client_mac.h" | 43 #import "content/browser/renderer_host/text_input_client_mac.h" |
| 42 #include "content/common/accessibility_messages.h" | 44 #include "content/common/accessibility_messages.h" |
| 43 #include "content/common/edit_command.h" | 45 #include "content/common/edit_command.h" |
| 44 #include "content/common/gpu/gpu_messages.h" | 46 #include "content/common/gpu/gpu_messages.h" |
| 45 #include "content/common/input_messages.h" | 47 #include "content/common/input_messages.h" |
| 46 #include "content/common/view_messages.h" | 48 #include "content/common/view_messages.h" |
| 47 #include "content/common/webplugin_geometry.h" | 49 #include "content/common/webplugin_geometry.h" |
| 48 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
| 49 #include "content/public/browser/native_web_keyboard_event.h" | 51 #include "content/public/browser/native_web_keyboard_event.h" |
| 50 #include "content/public/browser/notification_service.h" | 52 #include "content/public/browser/notification_service.h" |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 } | 405 } |
| 404 | 406 |
| 405 } // namespace | 407 } // namespace |
| 406 | 408 |
| 407 namespace content { | 409 namespace content { |
| 408 | 410 |
| 409 //////////////////////////////////////////////////////////////////////////////// | 411 //////////////////////////////////////////////////////////////////////////////// |
| 410 // DelegatedFrameHost, public: | 412 // DelegatedFrameHost, public: |
| 411 | 413 |
| 412 ui::Compositor* RenderWidgetHostViewMac::GetCompositor() const { | 414 ui::Compositor* RenderWidgetHostViewMac::GetCompositor() const { |
| 413 return compositor_.get(); | 415 return [browser_compositor_view_ compositor]; |
| 414 } | 416 } |
| 415 | 417 |
| 416 ui::Layer* RenderWidgetHostViewMac::GetLayer() { | 418 ui::Layer* RenderWidgetHostViewMac::GetLayer() { |
| 417 return root_layer_.get(); | 419 return root_layer_.get(); |
| 418 } | 420 } |
| 419 | 421 |
| 420 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() { | 422 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() { |
| 421 return render_widget_host_; | 423 return render_widget_host_; |
| 422 } | 424 } |
| 423 | 425 |
| 424 void RenderWidgetHostViewMac::SchedulePaintInRect( | 426 void RenderWidgetHostViewMac::SchedulePaintInRect( |
| 425 const gfx::Rect& damage_rect_in_dip) { | 427 const gfx::Rect& damage_rect_in_dip) { |
| 426 compositor_->ScheduleFullRedraw(); | 428 [browser_compositor_view_ compositor]->ScheduleFullRedraw(); |
| 427 } | 429 } |
| 428 | 430 |
| 429 bool RenderWidgetHostViewMac::IsVisible() { | 431 bool RenderWidgetHostViewMac::IsVisible() { |
| 430 return !render_widget_host_->is_hidden(); | 432 return !render_widget_host_->is_hidden(); |
| 431 } | 433 } |
| 432 | 434 |
| 433 gfx::Size RenderWidgetHostViewMac::DesiredFrameSize() { | 435 gfx::Size RenderWidgetHostViewMac::DesiredFrameSize() { |
| 434 return GetViewBounds().size(); | 436 return GetViewBounds().size(); |
| 435 } | 437 } |
| 436 | 438 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 465 } | 467 } |
| 466 | 468 |
| 467 /////////////////////////////////////////////////////////////////////////////// | 469 /////////////////////////////////////////////////////////////////////////////// |
| 468 // RenderWidgetHostViewMac, public: | 470 // RenderWidgetHostViewMac, public: |
| 469 | 471 |
| 470 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) | 472 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) |
| 471 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 473 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
| 472 last_frame_was_accelerated_(false), | 474 last_frame_was_accelerated_(false), |
| 473 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 475 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 474 can_compose_inline_(true), | 476 can_compose_inline_(true), |
| 475 compositing_iosurface_layer_async_timer_( | |
| 476 FROM_HERE, base::TimeDelta::FromMilliseconds(250), | |
| 477 this, &RenderWidgetHostViewMac::TimerSinceGotAcceleratedFrameFired), | |
| 478 allow_overlapping_views_(false), | 477 allow_overlapping_views_(false), |
| 479 use_core_animation_(false), | 478 use_core_animation_(false), |
| 480 pending_latency_info_delay_(0), | 479 pending_latency_info_delay_(0), |
| 481 pending_latency_info_delay_weak_ptr_factory_(this), | 480 pending_latency_info_delay_weak_ptr_factory_(this), |
| 482 backing_store_scale_factor_(1), | 481 backing_store_scale_factor_(1), |
| 483 is_loading_(false), | 482 is_loading_(false), |
| 484 weak_factory_(this), | 483 weak_factory_(this), |
| 485 fullscreen_parent_host_view_(NULL), | 484 fullscreen_parent_host_view_(NULL), |
| 486 underlay_view_has_drawn_(false), | 485 underlay_view_has_drawn_(false), |
| 487 overlay_view_weak_factory_(this), | 486 overlay_view_weak_factory_(this), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 506 render_widget_host_->SetView(this); | 505 render_widget_host_->SetView(this); |
| 507 } | 506 } |
| 508 | 507 |
| 509 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 508 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
| 510 // This is being called from |cocoa_view_|'s destructor, so invalidate the | 509 // This is being called from |cocoa_view_|'s destructor, so invalidate the |
| 511 // pointer. | 510 // pointer. |
| 512 cocoa_view_ = nil; | 511 cocoa_view_ = nil; |
| 513 | 512 |
| 514 // Delete the delegated frame state. | 513 // Delete the delegated frame state. |
| 515 delegated_frame_host_.reset(); | 514 delegated_frame_host_.reset(); |
| 516 compositor_.reset(); | |
| 517 root_layer_.reset(); | 515 root_layer_.reset(); |
| 518 | 516 |
| 519 UnlockMouse(); | 517 UnlockMouse(); |
| 520 | 518 |
| 521 // Make sure that the layer doesn't reach into the now-invalid object. | 519 // Make sure that the layer doesn't reach into the now-invalid object. |
| 522 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); | 520 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); |
| 523 DestroySoftwareLayer(); | 521 DestroySoftwareLayer(); |
| 524 | 522 |
| 525 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the | 523 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the |
| 526 // RenderWidgetHost does we need to tell it not to hold a stale pointer to | 524 // RenderWidgetHost does we need to tell it not to hold a stale pointer to |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 ClearBoundContextDrawable(); | 583 ClearBoundContextDrawable(); |
| 586 if (!new_context) { | 584 if (!new_context) { |
| 587 LOG(ERROR) << "Failed to create CompositingIOSurfaceContext"; | 585 LOG(ERROR) << "Failed to create CompositingIOSurfaceContext"; |
| 588 return false; | 586 return false; |
| 589 } | 587 } |
| 590 compositing_iosurface_context_ = new_context; | 588 compositing_iosurface_context_ = new_context; |
| 591 } | 589 } |
| 592 | 590 |
| 593 // Create the IOSurface texture. | 591 // Create the IOSurface texture. |
| 594 if (new_surface_needed) { | 592 if (new_surface_needed) { |
| 595 compositing_iosurface_.reset(CompositingIOSurfaceMac::Create()); | 593 compositing_iosurface_ = CompositingIOSurfaceMac::Create(); |
| 596 if (!compositing_iosurface_) { | 594 if (!compositing_iosurface_) { |
| 597 LOG(ERROR) << "Failed to create CompositingIOSurface"; | 595 LOG(ERROR) << "Failed to create CompositingIOSurface"; |
| 598 return false; | 596 return false; |
| 599 } | 597 } |
| 600 } | 598 } |
| 601 | 599 |
| 602 return true; | 600 return true; |
| 603 } | 601 } |
| 604 | 602 |
| 605 void RenderWidgetHostViewMac::EnsureSoftwareLayer() { | 603 void RenderWidgetHostViewMac::EnsureSoftwareLayer() { |
| 606 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::EnsureSoftwareLayer"); | 604 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::EnsureSoftwareLayer"); |
| 607 if (software_layer_ || !use_core_animation_) | 605 if (software_layer_ || !use_core_animation_) |
| 608 return; | 606 return; |
| 609 | 607 |
| 610 software_layer_.reset([[SoftwareLayer alloc] init]); | 608 software_layer_.reset([[SoftwareLayer alloc] init]); |
| 611 DCHECK(software_layer_); | 609 DCHECK(software_layer_); |
| 612 | 610 |
| 613 // Disable the fade-in animation as the layer is added. | 611 // Disable the fade-in animation as the layer is added. |
| 614 ScopedCAActionDisabler disabler; | 612 ScopedCAActionDisabler disabler; |
| 615 [background_layer_ addSublayer:software_layer_]; | 613 [background_layer_ addSublayer:software_layer_]; |
| 616 } | 614 } |
| 617 | 615 |
| 618 void RenderWidgetHostViewMac::DestroySoftwareLayer() { | 616 void RenderWidgetHostViewMac::DestroySoftwareLayer() { |
| 619 if (!software_layer_) | 617 if (!software_layer_) |
| 620 return; | 618 return; |
| 621 | 619 |
| 622 // Disable the fade-out animation as the layer is removed. | 620 // Disable the fade-out animation as the layer is removed. |
| 623 ScopedCAActionDisabler disabler; | 621 ScopedCAActionDisabler disabler; |
| 624 [software_layer_ removeFromSuperlayer]; | 622 [software_layer_ removeFromSuperlayer]; |
| 625 [software_layer_ disableRendering]; | |
| 626 software_layer_.reset(); | 623 software_layer_.reset(); |
| 627 } | 624 } |
| 628 | 625 |
| 629 void RenderWidgetHostViewMac::EnsureCompositedIOSurfaceLayer() { | 626 void RenderWidgetHostViewMac::EnsureCompositedIOSurfaceLayer() { |
| 630 TRACE_EVENT0("browser", | 627 TRACE_EVENT0("browser", |
| 631 "RenderWidgetHostViewMac::EnsureCompositedIOSurfaceLayer"); | 628 "RenderWidgetHostViewMac::EnsureCompositedIOSurfaceLayer"); |
| 632 DCHECK(compositing_iosurface_context_); | 629 DCHECK(compositing_iosurface_context_); |
| 633 if (compositing_iosurface_layer_ || !use_core_animation_) | 630 if (compositing_iosurface_layer_ || !use_core_animation_) |
| 634 return; | 631 return; |
| 635 | 632 |
| 636 compositing_iosurface_layer_.reset([[CompositingIOSurfaceLayer alloc] | 633 compositing_iosurface_layer_.reset([[CompositingIOSurfaceLayer alloc] |
| 637 initWithRenderWidgetHostViewMac:this]); | 634 initWithIOSurface:compositing_iosurface_ |
| 635 withClient:this]); |
| 638 DCHECK(compositing_iosurface_layer_); | 636 DCHECK(compositing_iosurface_layer_); |
| 639 | 637 |
| 640 // Disable the fade-in animation as the layer is added. | 638 // Disable the fade-in animation as the layer is added. |
| 641 ScopedCAActionDisabler disabler; | 639 ScopedCAActionDisabler disabler; |
| 642 [background_layer_ addSublayer:compositing_iosurface_layer_]; | 640 [background_layer_ addSublayer:compositing_iosurface_layer_]; |
| 643 } | 641 } |
| 644 | 642 |
| 645 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceLayer( | 643 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceLayer( |
| 646 DestroyCompositedIOSurfaceLayerBehavior destroy_layer_behavior) { | 644 DestroyCompositedIOSurfaceLayerBehavior destroy_layer_behavior) { |
| 647 if (!compositing_iosurface_layer_) | 645 if (!compositing_iosurface_layer_) |
| 648 return; | 646 return; |
| 649 | 647 |
| 650 if (destroy_layer_behavior == kRemoveLayerFromHierarchy) { | 648 if (destroy_layer_behavior == kRemoveLayerFromHierarchy) { |
| 651 // Disable the fade-out animation as the layer is removed. | 649 // Disable the fade-out animation as the layer is removed. |
| 652 ScopedCAActionDisabler disabler; | 650 ScopedCAActionDisabler disabler; |
| 653 [compositing_iosurface_layer_ removeFromSuperlayer]; | 651 [compositing_iosurface_layer_ removeFromSuperlayer]; |
| 654 } | 652 } |
| 655 [compositing_iosurface_layer_ disableCompositing]; | 653 [compositing_iosurface_layer_ resetClient]; |
| 656 compositing_iosurface_layer_.reset(); | 654 compositing_iosurface_layer_.reset(); |
| 657 } | 655 } |
| 658 | 656 |
| 659 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceAndLayer( | 657 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceAndLayer( |
| 660 DestroyContextBehavior destroy_context_behavior) { | 658 DestroyContextBehavior destroy_context_behavior) { |
| 661 // Any pending frames will not be displayed, so ack them now. | 659 // Any pending frames will not be displayed, so ack them now. |
| 662 SendPendingSwapAck(); | 660 SendPendingSwapAck(); |
| 663 | 661 |
| 664 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); | 662 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); |
| 665 compositing_iosurface_.reset(); | 663 compositing_iosurface_ = NULL; |
| 666 | 664 |
| 667 switch (destroy_context_behavior) { | 665 switch (destroy_context_behavior) { |
| 668 case kLeaveContextBoundToView: | 666 case kLeaveContextBoundToView: |
| 669 break; | 667 break; |
| 670 case kDestroyContext: | 668 case kDestroyContext: |
| 671 ClearBoundContextDrawable(); | 669 ClearBoundContextDrawable(); |
| 672 compositing_iosurface_context_ = NULL; | 670 compositing_iosurface_context_ = NULL; |
| 673 break; | 671 break; |
| 674 default: | 672 default: |
| 675 NOTREACHED(); | 673 NOTREACHED(); |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 // captured. | 1542 // captured. |
| 1545 if (window_is_occluded && frame_subscriber_) | 1543 if (window_is_occluded && frame_subscriber_) |
| 1546 scoped_ack.Reset(); | 1544 scoped_ack.Reset(); |
| 1547 } | 1545 } |
| 1548 | 1546 |
| 1549 // If we reach here, then the frame will be displayed by a future draw | 1547 // If we reach here, then the frame will be displayed by a future draw |
| 1550 // call, so don't make the callback. | 1548 // call, so don't make the callback. |
| 1551 ignore_result(scoped_ack.Release()); | 1549 ignore_result(scoped_ack.Release()); |
| 1552 if (use_core_animation_) { | 1550 if (use_core_animation_) { |
| 1553 DCHECK(compositing_iosurface_layer_); | 1551 DCHECK(compositing_iosurface_layer_); |
| 1554 compositing_iosurface_layer_async_timer_.Reset(); | |
| 1555 [compositing_iosurface_layer_ gotNewFrame]; | 1552 [compositing_iosurface_layer_ gotNewFrame]; |
| 1556 } else { | 1553 } else { |
| 1557 gfx::ScopedCGLSetCurrentContext scoped_set_current_context( | 1554 gfx::ScopedCGLSetCurrentContext scoped_set_current_context( |
| 1558 compositing_iosurface_context_->cgl_context()); | 1555 compositing_iosurface_context_->cgl_context()); |
| 1559 DrawIOSurfaceWithoutCoreAnimation(); | 1556 DrawIOSurfaceWithoutCoreAnimation(); |
| 1560 } | 1557 } |
| 1561 | 1558 |
| 1562 // Try to finish previous copy requests after draw to get better pipelining. | 1559 // Try to finish previous copy requests after draw to get better pipelining. |
| 1563 if (compositing_iosurface_) | 1560 if (compositing_iosurface_) |
| 1564 compositing_iosurface_->CheckIfAllCopiesAreFinished(false); | 1561 compositing_iosurface_->CheckIfAllCopiesAreFinished(false); |
| 1565 | 1562 |
| 1566 // The IOSurface's size may have changed, so re-layout the layers to take | 1563 // The IOSurface's size may have changed, so re-layout the layers to take |
| 1567 // this into account. This may force an immediate draw. | 1564 // this into account. This may force an immediate draw. |
| 1568 LayoutLayers(); | 1565 LayoutLayers(); |
| 1569 } | 1566 } |
| 1570 | 1567 |
| 1571 void RenderWidgetHostViewMac::GotBrowserCompositorSoftwareFrame( | |
| 1572 cc::SoftwareFrameData* frame_data, | |
| 1573 float scale_factor, | |
| 1574 SkCanvas* canvas) { | |
| 1575 if (!frame_data || !canvas) | |
| 1576 return; | |
| 1577 | |
| 1578 SkImageInfo info; | |
| 1579 size_t row_bytes; | |
| 1580 const void* pixels = canvas->peekPixels(&info, &row_bytes); | |
| 1581 | |
| 1582 EnsureSoftwareLayer(); | |
| 1583 [software_layer_ setContentsToData:pixels | |
| 1584 withRowBytes:row_bytes | |
| 1585 withPixelSize:gfx::Size(info.fWidth, info.fHeight) | |
| 1586 withScaleFactor:scale_factor]; | |
| 1587 | |
| 1588 LayoutLayers(); | |
| 1589 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); | |
| 1590 } | |
| 1591 | |
| 1592 void RenderWidgetHostViewMac::DrawIOSurfaceWithoutCoreAnimation() { | 1568 void RenderWidgetHostViewMac::DrawIOSurfaceWithoutCoreAnimation() { |
| 1593 CHECK(!use_core_animation_); | 1569 CHECK(!use_core_animation_); |
| 1594 CHECK(compositing_iosurface_); | 1570 CHECK(compositing_iosurface_); |
| 1595 | 1571 |
| 1596 // If there is a pending frame, it should be acked by the end of this | 1572 // If there is a pending frame, it should be acked by the end of this |
| 1597 // function. Note that the ack should happen only after all drawing is | 1573 // function. Note that the ack should happen only after all drawing is |
| 1598 // complete, so that the ack happens after any blocking due to vsync. | 1574 // complete, so that the ack happens after any blocking due to vsync. |
| 1599 base::ScopedClosureRunner scoped_ack( | 1575 base::ScopedClosureRunner scoped_ack( |
| 1600 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck, | 1576 base::Bind(&RenderWidgetHostViewMac::SendPendingSwapAck, |
| 1601 weak_factory_.GetWeakPtr())); | 1577 weak_factory_.GetWeakPtr())); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1908 desired_size)); | 1884 desired_size)); |
| 1909 } | 1885 } |
| 1910 return false; | 1886 return false; |
| 1911 } | 1887 } |
| 1912 | 1888 |
| 1913 void RenderWidgetHostViewMac::OnSwapCompositorFrame( | 1889 void RenderWidgetHostViewMac::OnSwapCompositorFrame( |
| 1914 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { | 1890 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { |
| 1915 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); | 1891 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); |
| 1916 | 1892 |
| 1917 if (frame->delegated_frame_data) { | 1893 if (frame->delegated_frame_data) { |
| 1918 if (!compositor_) { | 1894 if (!browser_compositor_view_) { |
| 1919 compositor_.reset(new ui::Compositor(cocoa_view_)); | 1895 browser_compositor_view_.reset( |
| 1896 [[BrowserCompositorViewMac alloc] initWithSuperview:cocoa_view_]); |
| 1920 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); | 1897 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); |
| 1921 delegated_frame_host_.reset(new DelegatedFrameHost(this)); | 1898 delegated_frame_host_.reset(new DelegatedFrameHost(this)); |
| 1922 } | 1899 } |
| 1923 | 1900 |
| 1924 // TODO(ccameron): Having the root layer set while swapping the frame will | 1901 // TODO(ccameron): Having the root layer set while swapping the frame will |
| 1925 // result in frames not appearing. Fix this. | 1902 // result in frames not appearing. Fix this. |
| 1926 compositor_->SetRootLayer(NULL); | 1903 [browser_compositor_view_ compositor]->SetRootLayer(NULL); |
| 1927 delegated_frame_host_->SwapDelegatedFrame( | 1904 delegated_frame_host_->SwapDelegatedFrame( |
| 1928 output_surface_id, | 1905 output_surface_id, |
| 1929 frame->delegated_frame_data.Pass(), | 1906 frame->delegated_frame_data.Pass(), |
| 1930 frame->metadata.device_scale_factor, | 1907 frame->metadata.device_scale_factor, |
| 1931 frame->metadata.latency_info); | 1908 frame->metadata.latency_info); |
| 1932 compositor_->SetRootLayer(root_layer_.get()); | 1909 [browser_compositor_view_ compositor]->SetRootLayer(root_layer_.get()); |
| 1933 | 1910 |
| 1934 // Update the compositor and root layer size and scale factor to match | 1911 // Update the compositor and root layer size and scale factor to match |
| 1935 // the frame just received. | 1912 // the frame just received. |
| 1936 float scale_factor = frame->metadata.device_scale_factor; | 1913 float scale_factor = frame->metadata.device_scale_factor; |
| 1937 gfx::Size dip_size = ToCeiledSize(frame->metadata.viewport_size); | 1914 gfx::Size dip_size = ToCeiledSize(frame->metadata.viewport_size); |
| 1938 gfx::Size pixel_size = ConvertSizeToPixel( | 1915 gfx::Size pixel_size = ConvertSizeToPixel( |
| 1939 scale_factor, dip_size); | 1916 scale_factor, dip_size); |
| 1940 compositor_->SetScaleAndSize(scale_factor, pixel_size); | 1917 [browser_compositor_view_ compositor]->SetScaleAndSize( |
| 1918 scale_factor, pixel_size); |
| 1941 root_layer_->SetBounds(gfx::Rect(dip_size)); | 1919 root_layer_->SetBounds(gfx::Rect(dip_size)); |
| 1942 } else if (frame->software_frame_data) { | 1920 } else if (frame->software_frame_data) { |
| 1943 if (!software_frame_manager_->SwapToNewFrame( | 1921 if (!software_frame_manager_->SwapToNewFrame( |
| 1944 output_surface_id, | 1922 output_surface_id, |
| 1945 frame->software_frame_data.get(), | 1923 frame->software_frame_data.get(), |
| 1946 frame->metadata.device_scale_factor, | 1924 frame->metadata.device_scale_factor, |
| 1947 render_widget_host_->GetProcess()->GetHandle())) { | 1925 render_widget_host_->GetProcess()->GetHandle())) { |
| 1948 render_widget_host_->GetProcess()->ReceivedBadMessage(); | 1926 render_widget_host_->GetProcess()->ReceivedBadMessage(); |
| 1949 return; | 1927 return; |
| 1950 } | 1928 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2146 // http://crbug.com/279472 | 2124 // http://crbug.com/279472 |
| 2147 if (!use_core_animation_) | 2125 if (!use_core_animation_) |
| 2148 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; | 2126 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; |
| 2149 if (allow_overlapping_views_) | 2127 if (allow_overlapping_views_) |
| 2150 DestroyCompositedIOSurfaceAndLayer(kLeaveContextBoundToView); | 2128 DestroyCompositedIOSurfaceAndLayer(kLeaveContextBoundToView); |
| 2151 else | 2129 else |
| 2152 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); | 2130 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); |
| 2153 } | 2131 } |
| 2154 } | 2132 } |
| 2155 | 2133 |
| 2156 void RenderWidgetHostViewMac::TimerSinceGotAcceleratedFrameFired() { | |
| 2157 [compositing_iosurface_layer_ timerSinceGotNewFrameFired]; | |
| 2158 } | |
| 2159 | |
| 2160 void RenderWidgetHostViewMac::SetActive(bool active) { | 2134 void RenderWidgetHostViewMac::SetActive(bool active) { |
| 2161 if (render_widget_host_) { | 2135 if (render_widget_host_) { |
| 2162 render_widget_host_->SetActive(active); | 2136 render_widget_host_->SetActive(active); |
| 2163 if (active) { | 2137 if (active) { |
| 2164 if (HasFocus()) | 2138 if (HasFocus()) |
| 2165 render_widget_host_->Focus(); | 2139 render_widget_host_->Focus(); |
| 2166 } else { | 2140 } else { |
| 2167 render_widget_host_->Blur(); | 2141 render_widget_host_->Blur(); |
| 2168 } | 2142 } |
| 2169 } | 2143 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2381 | 2355 |
| 2382 void RenderWidgetHostViewMac::AddPendingSwapAck( | 2356 void RenderWidgetHostViewMac::AddPendingSwapAck( |
| 2383 int32 route_id, int gpu_host_id, int32 renderer_id) { | 2357 int32 route_id, int gpu_host_id, int32 renderer_id) { |
| 2384 // Note that multiple un-acked swaps can come in the event of a GPU process | 2358 // Note that multiple un-acked swaps can come in the event of a GPU process |
| 2385 // loss. Drop the old acks. | 2359 // loss. Drop the old acks. |
| 2386 pending_swap_ack_.reset(new PendingSwapAck( | 2360 pending_swap_ack_.reset(new PendingSwapAck( |
| 2387 route_id, gpu_host_id, renderer_id)); | 2361 route_id, gpu_host_id, renderer_id)); |
| 2388 | 2362 |
| 2389 // A trace value of 2 indicates that there is a pending swap ack. See | 2363 // A trace value of 2 indicates that there is a pending swap ack. See |
| 2390 // CompositingIOSurfaceLayer's canDrawInCGLContext for other value meanings. | 2364 // CompositingIOSurfaceLayer's canDrawInCGLContext for other value meanings. |
| 2391 TRACE_COUNTER_ID1("browser", "PendingSwapAck", this, 2); | 2365 TRACE_COUNTER_ID1("browser", "PendingSwapAck", |
| 2366 compositing_iosurface_layer_.get(), 2); |
| 2392 } | 2367 } |
| 2393 | 2368 |
| 2394 void RenderWidgetHostViewMac::SendPendingSwapAck() { | 2369 void RenderWidgetHostViewMac::SendPendingSwapAck() { |
| 2395 if (!pending_swap_ack_) | 2370 if (!pending_swap_ack_) |
| 2396 return; | 2371 return; |
| 2397 | 2372 |
| 2398 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 2373 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
| 2399 ack_params.sync_point = 0; | 2374 ack_params.sync_point = 0; |
| 2400 ack_params.renderer_id = pending_swap_ack_->renderer_id; | 2375 ack_params.renderer_id = pending_swap_ack_->renderer_id; |
| 2401 RenderWidgetHostImpl::AcknowledgeBufferPresent(pending_swap_ack_->route_id, | 2376 RenderWidgetHostImpl::AcknowledgeBufferPresent(pending_swap_ack_->route_id, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2427 // to keep the window and the window's contents in sync. | 2402 // to keep the window and the window's contents in sync. |
| 2428 [cocoa_view_ displayIfNeeded]; | 2403 [cocoa_view_ displayIfNeeded]; |
| 2429 [software_layer_ displayIfNeeded]; | 2404 [software_layer_ displayIfNeeded]; |
| 2430 [compositing_iosurface_layer_ displayIfNeeded]; | 2405 [compositing_iosurface_layer_ displayIfNeeded]; |
| 2431 } | 2406 } |
| 2432 | 2407 |
| 2433 void RenderWidgetHostViewMac::LayoutLayers() { | 2408 void RenderWidgetHostViewMac::LayoutLayers() { |
| 2434 if (!use_core_animation_) | 2409 if (!use_core_animation_) |
| 2435 return; | 2410 return; |
| 2436 | 2411 |
| 2412 if (browser_compositor_view_) { |
| 2413 [browser_compositor_view_ layoutLayers]; |
| 2414 return; |
| 2415 } |
| 2416 |
| 2437 // Disable animation of the layer's resizing or change in contents scale. | 2417 // Disable animation of the layer's resizing or change in contents scale. |
| 2438 ScopedCAActionDisabler disabler; | 2418 ScopedCAActionDisabler disabler; |
| 2439 | 2419 |
| 2440 CGRect new_background_frame = NSRectToCGRect([cocoa_view() bounds]); | 2420 CGRect new_background_frame = NSRectToCGRect([cocoa_view() bounds]); |
| 2441 | 2421 |
| 2442 // Dynamically calling setContentsScale on a CAOpenGLLayer for which | 2422 // Dynamically calling setContentsScale on a CAOpenGLLayer for which |
| 2443 // setAsynchronous is dynamically toggled can result in flashes of corrupt | 2423 // setAsynchronous is dynamically toggled can result in flashes of corrupt |
| 2444 // content. Work around this by replacing the entire layer when the scale | 2424 // content. Work around this by replacing the entire layer when the scale |
| 2445 // factor changes. | 2425 // factor changes. |
| 2446 if (compositing_iosurface_ && | 2426 if (compositing_iosurface_ && |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2490 if (frame_changed) { | 2470 if (frame_changed) { |
| 2491 [software_layer_ setFrame:new_background_frame]; | 2471 [software_layer_ setFrame:new_background_frame]; |
| 2492 } | 2472 } |
| 2493 } | 2473 } |
| 2494 } | 2474 } |
| 2495 | 2475 |
| 2496 SkBitmap::Config RenderWidgetHostViewMac::PreferredReadbackFormat() { | 2476 SkBitmap::Config RenderWidgetHostViewMac::PreferredReadbackFormat() { |
| 2497 return SkBitmap::kARGB_8888_Config; | 2477 return SkBitmap::kARGB_8888_Config; |
| 2498 } | 2478 } |
| 2499 | 2479 |
| 2480 //////////////////////////////////////////////////////////////////////////////// |
| 2481 // CompositingIOSurfaceLayerClient, public: |
| 2482 |
| 2483 void RenderWidgetHostViewMac::AcceleratedLayerDidDrawFrame(bool succeeded) { |
| 2484 SendPendingLatencyInfoToHost(); |
| 2485 SendPendingSwapAck(); |
| 2486 if (!succeeded) |
| 2487 GotAcceleratedCompositingError(); |
| 2488 } |
| 2489 |
| 2490 bool RenderWidgetHostViewMac::AcceleratedLayerHasNotAckedPendingFrame() const { |
| 2491 return pending_swap_ack_; |
| 2492 } |
| 2493 |
| 2500 } // namespace content | 2494 } // namespace content |
| 2501 | 2495 |
| 2502 // RenderWidgetHostViewCocoa --------------------------------------------------- | 2496 // RenderWidgetHostViewCocoa --------------------------------------------------- |
| 2503 | 2497 |
| 2504 @implementation RenderWidgetHostViewCocoa | 2498 @implementation RenderWidgetHostViewCocoa |
| 2505 @synthesize selectedRange = selectedRange_; | 2499 @synthesize selectedRange = selectedRange_; |
| 2506 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; | 2500 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; |
| 2507 @synthesize markedRange = markedRange_; | 2501 @synthesize markedRange = markedRange_; |
| 2508 | 2502 |
| 2509 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { | 2503 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3324 height = -height; | 3318 height = -height; |
| 3325 } | 3319 } |
| 3326 | 3320 |
| 3327 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; | 3321 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; |
| 3328 CGContextSetFillColorWithColor(context, | 3322 CGContextSetFillColorWithColor(context, |
| 3329 CGColorGetConstantColor(kCGColorWhite)); | 3323 CGColorGetConstantColor(kCGColorWhite)); |
| 3330 CGContextFillRect(context, NSRectToCGRect(r)); | 3324 CGContextFillRect(context, NSRectToCGRect(r)); |
| 3331 } | 3325 } |
| 3332 } | 3326 } |
| 3333 | 3327 |
| 3334 - (void)onNativeSurfaceBuffersSwappedWithParams: | |
| 3335 (GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params { | |
| 3336 | |
| 3337 renderWidgetHostView_->CompositorSwapBuffers( | |
| 3338 params.surface_handle, | |
| 3339 params.size, | |
| 3340 params.scale_factor, | |
| 3341 params.latency_info); | |
| 3342 } | |
| 3343 | |
| 3344 - (void)gotSoftwareFrame:(cc::SoftwareFrameData*)frame_data | |
| 3345 withScaleFactor:(float)scale_factor | |
| 3346 withCanvas:(SkCanvas*)canvas { | |
| 3347 renderWidgetHostView_->GotBrowserCompositorSoftwareFrame( | |
| 3348 frame_data, scale_factor, canvas); | |
| 3349 } | |
| 3350 | |
| 3351 - (void)drawRect:(NSRect)dirtyRect { | 3328 - (void)drawRect:(NSRect)dirtyRect { |
| 3352 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); | 3329 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); |
| 3353 DCHECK(!renderWidgetHostView_->use_core_animation_); | 3330 DCHECK(!renderWidgetHostView_->use_core_animation_); |
| 3354 | 3331 |
| 3355 if (!renderWidgetHostView_->render_widget_host_) { | 3332 if (!renderWidgetHostView_->render_widget_host_) { |
| 3356 // When using CoreAnimation, this path is used to paint the contents area | 3333 // When using CoreAnimation, this path is used to paint the contents area |
| 3357 // white before any frames come in. When layers to draw frames exist, this | 3334 // white before any frames come in. When layers to draw frames exist, this |
| 3358 // is not hit. | 3335 // is not hit. |
| 3359 [[NSColor whiteColor] set]; | 3336 [[NSColor whiteColor] set]; |
| 3360 NSRectFill(dirtyRect); | 3337 NSRectFill(dirtyRect); |
| (...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4408 | 4385 |
| 4409 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 4386 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 4410 // regions that are not draggable. (See ControlRegionView in | 4387 // regions that are not draggable. (See ControlRegionView in |
| 4411 // native_app_window_cocoa.mm). This requires the render host view to be | 4388 // native_app_window_cocoa.mm). This requires the render host view to be |
| 4412 // draggable by default. | 4389 // draggable by default. |
| 4413 - (BOOL)mouseDownCanMoveWindow { | 4390 - (BOOL)mouseDownCanMoveWindow { |
| 4414 return YES; | 4391 return YES; |
| 4415 } | 4392 } |
| 4416 | 4393 |
| 4417 @end | 4394 @end |
| 4418 | |
| 4419 @implementation SoftwareLayer | |
| 4420 | |
| 4421 - (id)init { | |
| 4422 if (self = [super init]) { | |
| 4423 [self setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | |
| 4424 [self setAnchorPoint:CGPointMake(0, 0)]; | |
| 4425 // Setting contents gravity is necessary to prevent the layer from being | |
| 4426 // scaled during dyanmic resizes (especially with devtools open). | |
| 4427 [self setContentsGravity:kCAGravityTopLeft]; | |
| 4428 } | |
| 4429 return self; | |
| 4430 } | |
| 4431 | |
| 4432 - (void)setContentsToData:(const void *)data | |
| 4433 withRowBytes:(size_t)rowBytes | |
| 4434 withPixelSize:(gfx::Size)pixelSize | |
| 4435 withScaleFactor:(float)scaleFactor { | |
| 4436 TRACE_EVENT0("browser", "-[SoftwareLayer setContentsToData]"); | |
| 4437 | |
| 4438 // Disable animating the contents change or the scale factor change. | |
| 4439 ScopedCAActionDisabler disabler; | |
| 4440 | |
| 4441 // Set the contents of the software CALayer to be a CGImage with the provided | |
| 4442 // pixel data. Make a copy of the data before backing the image with them, | |
| 4443 // because the same buffer will be reused for the next frame. | |
| 4444 base::ScopedCFTypeRef<CFDataRef> dataCopy( | |
| 4445 CFDataCreate(NULL, | |
| 4446 static_cast<const UInt8 *>(data), | |
| 4447 rowBytes * pixelSize.height())); | |
| 4448 base::ScopedCFTypeRef<CGDataProviderRef> dataProvider( | |
| 4449 CGDataProviderCreateWithCFData(dataCopy)); | |
| 4450 base::ScopedCFTypeRef<CGImageRef> image( | |
| 4451 CGImageCreate(pixelSize.width(), | |
| 4452 pixelSize.height(), | |
| 4453 8, | |
| 4454 32, | |
| 4455 rowBytes, | |
| 4456 base::mac::GetSystemColorSpace(), | |
| 4457 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, | |
| 4458 dataProvider, | |
| 4459 NULL, | |
| 4460 false, | |
| 4461 kCGRenderingIntentDefault)); | |
| 4462 [self setContents:(id)image.get()]; | |
| 4463 | |
| 4464 // Set the contents scale of the software CALayer. | |
| 4465 if ([self respondsToSelector:(@selector(contentsScale))] && | |
| 4466 [self respondsToSelector:(@selector(setContentsScale:))] && | |
| 4467 [self contentsScale] != scaleFactor) { | |
| 4468 [self setContentsScale:scaleFactor]; | |
| 4469 } | |
| 4470 } | |
| 4471 | |
| 4472 - (void)disableRendering { | |
| 4473 // Disable the fade-out animation as the layer is removed. | |
| 4474 ScopedCAActionDisabler disabler; | |
| 4475 [self removeFromSuperlayer]; | |
| 4476 } | |
| 4477 | |
| 4478 @end // implementation SoftwareLayer | |
| OLD | NEW |