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 <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
9 #include <QuartzCore/QuartzCore.h> | 9 #include <QuartzCore/QuartzCore.h> |
10 | 10 |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 fullscreen_parent_host_view_(NULL), | 506 fullscreen_parent_host_view_(NULL), |
507 software_frame_weak_ptr_factory_(this) { | 507 software_frame_weak_ptr_factory_(this) { |
508 software_frame_manager_.reset(new SoftwareFrameManager( | 508 software_frame_manager_.reset(new SoftwareFrameManager( |
509 software_frame_weak_ptr_factory_.GetWeakPtr())); | 509 software_frame_weak_ptr_factory_.GetWeakPtr())); |
510 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 510 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
511 // goes away. Since we autorelease it, our caller must put | 511 // goes away. Since we autorelease it, our caller must put |
512 // |GetNativeView()| into the view hierarchy right after calling us. | 512 // |GetNativeView()| into the view hierarchy right after calling us. |
513 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 513 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
514 initWithRenderWidgetHostViewMac:this] autorelease]; | 514 initWithRenderWidgetHostViewMac:this] autorelease]; |
515 | 515 |
| 516 // Make this view host a solid white layer when there is no content ready to |
| 517 // draw. |
516 background_layer_.reset([[CALayer alloc] init]); | 518 background_layer_.reset([[CALayer alloc] init]); |
517 [background_layer_ | 519 [background_layer_ |
518 setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | 520 setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; |
519 [background_layer_ setGeometryFlipped:YES]; | |
520 [background_layer_ setContentsGravity:kCAGravityTopLeft]; | |
521 [cocoa_view_ setLayer:background_layer_]; | 521 [cocoa_view_ setLayer:background_layer_]; |
522 [cocoa_view_ setWantsLayer:YES]; | 522 [cocoa_view_ setWantsLayer:YES]; |
523 | 523 |
| 524 if (!IsDelegatedRendererEnabled()) { |
| 525 // Add a flipped transparent layer as a child, so that we don't need to |
| 526 // fiddle with the position of sub-layers -- they will always be at the |
| 527 // origin. |
| 528 flipped_layer_.reset([[CALayer alloc] init]); |
| 529 [flipped_layer_ setGeometryFlipped:YES]; |
| 530 [flipped_layer_ |
| 531 setAutoresizingMask:kCALayerWidthSizable|kCALayerHeightSizable]; |
| 532 [background_layer_ addSublayer:flipped_layer_]; |
| 533 } |
| 534 |
524 if (IsDelegatedRendererEnabled()) { | 535 if (IsDelegatedRendererEnabled()) { |
525 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); | 536 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); |
526 delegated_frame_host_.reset(new DelegatedFrameHost(this)); | 537 delegated_frame_host_.reset(new DelegatedFrameHost(this)); |
527 } | 538 } |
528 | 539 |
529 render_widget_host_->SetView(this); | 540 render_widget_host_->SetView(this); |
530 } | 541 } |
531 | 542 |
532 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 543 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
533 // This is being called from |cocoa_view_|'s destructor, so invalidate the | 544 // This is being called from |cocoa_view_|'s destructor, so invalidate the |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 void RenderWidgetHostViewMac::EnsureSoftwareLayer() { | 657 void RenderWidgetHostViewMac::EnsureSoftwareLayer() { |
647 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::EnsureSoftwareLayer"); | 658 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::EnsureSoftwareLayer"); |
648 if (software_layer_) | 659 if (software_layer_) |
649 return; | 660 return; |
650 | 661 |
651 software_layer_.reset([[SoftwareLayer alloc] init]); | 662 software_layer_.reset([[SoftwareLayer alloc] init]); |
652 DCHECK(software_layer_); | 663 DCHECK(software_layer_); |
653 | 664 |
654 // Disable the fade-in animation as the layer is added. | 665 // Disable the fade-in animation as the layer is added. |
655 ScopedCAActionDisabler disabler; | 666 ScopedCAActionDisabler disabler; |
656 [background_layer_ addSublayer:software_layer_]; | 667 [flipped_layer_ addSublayer:software_layer_]; |
657 } | 668 } |
658 | 669 |
659 void RenderWidgetHostViewMac::DestroySoftwareLayer() { | 670 void RenderWidgetHostViewMac::DestroySoftwareLayer() { |
660 if (!software_layer_) | 671 if (!software_layer_) |
661 return; | 672 return; |
662 | 673 |
663 // Disable the fade-out animation as the layer is removed. | 674 // Disable the fade-out animation as the layer is removed. |
664 ScopedCAActionDisabler disabler; | 675 ScopedCAActionDisabler disabler; |
665 [software_layer_ removeFromSuperlayer]; | 676 [software_layer_ removeFromSuperlayer]; |
666 software_layer_.reset(); | 677 software_layer_.reset(); |
667 } | 678 } |
668 | 679 |
669 void RenderWidgetHostViewMac::EnsureCompositedIOSurfaceLayer() { | 680 void RenderWidgetHostViewMac::EnsureCompositedIOSurfaceLayer() { |
670 TRACE_EVENT0("browser", | 681 TRACE_EVENT0("browser", |
671 "RenderWidgetHostViewMac::EnsureCompositedIOSurfaceLayer"); | 682 "RenderWidgetHostViewMac::EnsureCompositedIOSurfaceLayer"); |
672 DCHECK(compositing_iosurface_context_); | 683 DCHECK(compositing_iosurface_context_); |
673 if (compositing_iosurface_layer_) | 684 if (compositing_iosurface_layer_) |
674 return; | 685 return; |
675 | 686 |
676 compositing_iosurface_layer_.reset([[CompositingIOSurfaceLayer alloc] | 687 compositing_iosurface_layer_.reset([[CompositingIOSurfaceLayer alloc] |
677 initWithIOSurface:compositing_iosurface_ | 688 initWithIOSurface:compositing_iosurface_ |
678 withScaleFactor:compositing_iosurface_->scale_factor() | 689 withScaleFactor:compositing_iosurface_->scale_factor() |
679 withClient:this]); | 690 withClient:this]); |
680 DCHECK(compositing_iosurface_layer_); | 691 DCHECK(compositing_iosurface_layer_); |
681 | 692 |
682 // Disable the fade-in animation as the layer is added. | 693 // Disable the fade-in animation as the layer is added. |
683 ScopedCAActionDisabler disabler; | 694 ScopedCAActionDisabler disabler; |
684 [background_layer_ addSublayer:compositing_iosurface_layer_]; | 695 [flipped_layer_ addSublayer:compositing_iosurface_layer_]; |
685 } | 696 } |
686 | 697 |
687 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceLayer( | 698 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceLayer( |
688 DestroyCompositedIOSurfaceLayerBehavior destroy_layer_behavior) { | 699 DestroyCompositedIOSurfaceLayerBehavior destroy_layer_behavior) { |
689 if (!compositing_iosurface_layer_) | 700 if (!compositing_iosurface_layer_) |
690 return; | 701 return; |
691 | 702 |
692 if (destroy_layer_behavior == kRemoveLayerFromHierarchy) { | 703 if (destroy_layer_behavior == kRemoveLayerFromHierarchy) { |
693 // Disable the fade-out animation as the layer is removed. | 704 // Disable the fade-out animation as the layer is removed. |
694 ScopedCAActionDisabler disabler; | 705 ScopedCAActionDisabler disabler; |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1747 | 1758 |
1748 // If if the layer has changed put the new layer in the hierarchy and | 1759 // If if the layer has changed put the new layer in the hierarchy and |
1749 // take the old one out. | 1760 // take the old one out. |
1750 if ([remote_layer_host_ contextId] != context_id) { | 1761 if ([remote_layer_host_ contextId] != context_id) { |
1751 [remote_layer_host_ removeFromSuperlayer]; | 1762 [remote_layer_host_ removeFromSuperlayer]; |
1752 | 1763 |
1753 remote_layer_host_.reset([[CALayerHost alloc] init]); | 1764 remote_layer_host_.reset([[CALayerHost alloc] init]); |
1754 [remote_layer_host_ setContextId:context_id]; | 1765 [remote_layer_host_ setContextId:context_id]; |
1755 [remote_layer_host_ | 1766 [remote_layer_host_ |
1756 setAutoresizingMask:kCALayerMaxXMargin|kCALayerMaxYMargin]; | 1767 setAutoresizingMask:kCALayerMaxXMargin|kCALayerMaxYMargin]; |
1757 [background_layer_ addSublayer:remote_layer_host_]; | 1768 [flipped_layer_ addSublayer:remote_layer_host_]; |
1758 } | 1769 } |
1759 | 1770 |
1760 // Ack the frame immediately. Any GPU back pressure will be applied by | 1771 // Ack the frame immediately. Any GPU back pressure will be applied by |
1761 // the remote layer from within the GPU process. | 1772 // the remote layer from within the GPU process. |
1762 SendPendingSwapAck(); | 1773 SendPendingSwapAck(); |
1763 } break; | 1774 } break; |
1764 default: | 1775 default: |
1765 LOG(ERROR) << "Invalid surface handle type."; | 1776 LOG(ERROR) << "Invalid surface handle type."; |
1766 break; | 1777 break; |
1767 } | 1778 } |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2185 ack_params); | 2196 ack_params); |
2186 pending_swap_ack_.reset(); | 2197 pending_swap_ack_.reset(); |
2187 } | 2198 } |
2188 | 2199 |
2189 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() { | 2200 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() { |
2190 if (!render_widget_host_ || render_widget_host_->is_hidden()) | 2201 if (!render_widget_host_ || render_widget_host_->is_hidden()) |
2191 return; | 2202 return; |
2192 | 2203 |
2193 // Synchronized resizing does not yet work with browser compositor. | 2204 // Synchronized resizing does not yet work with browser compositor. |
2194 // http://crbug.com/388005 | 2205 // http://crbug.com/388005 |
2195 if (delegated_frame_host_) | 2206 if (IsDelegatedRendererEnabled()) |
2196 return; | 2207 return; |
2197 | 2208 |
2198 // Pausing for one view prevents others from receiving frames. | 2209 // Pausing for one view prevents others from receiving frames. |
2199 // This may lead to large delays, causing overlaps. See crbug.com/352020. | 2210 // This may lead to large delays, causing overlaps. See crbug.com/352020. |
2200 if (!allow_pause_for_resize_or_repaint_) | 2211 if (!allow_pause_for_resize_or_repaint_) |
2201 return; | 2212 return; |
2202 | 2213 |
2203 // Ensure that all frames are acked before waiting for a frame to come in. | 2214 // Ensure that all frames are acked before waiting for a frame to come in. |
2204 // Note that we will draw a frame at the end of this function, so it is safe | 2215 // Note that we will draw a frame at the end of this function, so it is safe |
2205 // to ack a never-drawn frame here. | 2216 // to ack a never-drawn frame here. |
(...skipping 1765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3971 | 3982 |
3972 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3983 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3973 // regions that are not draggable. (See ControlRegionView in | 3984 // regions that are not draggable. (See ControlRegionView in |
3974 // native_app_window_cocoa.mm). This requires the render host view to be | 3985 // native_app_window_cocoa.mm). This requires the render host view to be |
3975 // draggable by default. | 3986 // draggable by default. |
3976 - (BOOL)mouseDownCanMoveWindow { | 3987 - (BOOL)mouseDownCanMoveWindow { |
3977 return YES; | 3988 return YES; |
3978 } | 3989 } |
3979 | 3990 |
3980 @end | 3991 @end |
OLD | NEW |