Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 347653005: Make cross-process CALayers work on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@image_transport_1
Patch Set: Remove stray test line Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 25 matching lines...) Expand all
36 #include "content/browser/renderer_host/compositing_iosurface_mac.h" 36 #include "content/browser/renderer_host/compositing_iosurface_mac.h"
37 #include "content/browser/renderer_host/render_widget_helper.h" 37 #include "content/browser/renderer_host/render_widget_helper.h"
38 #include "content/browser/renderer_host/render_view_host_impl.h" 38 #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" 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_editcommand_h elper.h" 40 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h"
41 #import "content/browser/renderer_host/software_layer_mac.h" 41 #import "content/browser/renderer_host/software_layer_mac.h"
42 #import "content/browser/renderer_host/text_input_client_mac.h" 42 #import "content/browser/renderer_host/text_input_client_mac.h"
43 #include "content/common/accessibility_messages.h" 43 #include "content/common/accessibility_messages.h"
44 #include "content/common/edit_command.h" 44 #include "content/common/edit_command.h"
45 #include "content/common/gpu/gpu_messages.h" 45 #include "content/common/gpu/gpu_messages.h"
46 #include "content/common/gpu/surface_handle_types_mac.h"
46 #include "content/common/input_messages.h" 47 #include "content/common/input_messages.h"
47 #include "content/common/view_messages.h" 48 #include "content/common/view_messages.h"
48 #include "content/common/webplugin_geometry.h" 49 #include "content/common/webplugin_geometry.h"
49 #include "content/public/browser/browser_thread.h" 50 #include "content/public/browser/browser_thread.h"
50 #include "content/public/browser/native_web_keyboard_event.h" 51 #include "content/public/browser/native_web_keyboard_event.h"
51 #include "content/public/browser/notification_service.h" 52 #include "content/public/browser/notification_service.h"
52 #include "content/public/browser/notification_types.h" 53 #include "content/public/browser/notification_types.h"
53 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 54 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
54 #import "content/public/browser/render_widget_host_view_mac_delegate.h" 55 #import "content/public/browser/render_widget_host_view_mac_delegate.h"
55 #include "content/public/browser/user_metrics.h" 56 #include "content/public/browser/user_metrics.h"
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 software_frame_weak_ptr_factory_.GetWeakPtr())); 463 software_frame_weak_ptr_factory_.GetWeakPtr()));
463 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| 464 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_|
464 // goes away. Since we autorelease it, our caller must put 465 // goes away. Since we autorelease it, our caller must put
465 // |GetNativeView()| into the view hierarchy right after calling us. 466 // |GetNativeView()| into the view hierarchy right after calling us.
466 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] 467 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc]
467 initWithRenderWidgetHostViewMac:this] autorelease]; 468 initWithRenderWidgetHostViewMac:this] autorelease];
468 469
469 background_layer_.reset([[CALayer alloc] init]); 470 background_layer_.reset([[CALayer alloc] init]);
470 [background_layer_ 471 [background_layer_
471 setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; 472 setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
473 [background_layer_
474 setAutoresizingMask:kCALayerWidthSizable|kCALayerHeightSizable];
475 [background_layer_ setGeometryFlipped:YES];
476 [background_layer_ setContentsGravity:kCAGravityTopLeft];
472 [cocoa_view_ setLayer:background_layer_]; 477 [cocoa_view_ setLayer:background_layer_];
473 [cocoa_view_ setWantsLayer:YES]; 478 [cocoa_view_ setWantsLayer:YES];
474 479
475 render_widget_host_->SetView(this); 480 render_widget_host_->SetView(this);
476 } 481 }
477 482
478 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { 483 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() {
479 // This is being called from |cocoa_view_|'s destructor, so invalidate the 484 // This is being called from |cocoa_view_|'s destructor, so invalidate the
480 // pointer. 485 // pointer.
481 cocoa_view_ = nil; 486 cocoa_view_ = nil;
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 return true; 1659 return true;
1655 } 1660 }
1656 1661
1657 void RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped( 1662 void RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped(
1658 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, 1663 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
1659 int gpu_host_id) { 1664 int gpu_host_id) {
1660 TRACE_EVENT0("browser", 1665 TRACE_EVENT0("browser",
1661 "RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped"); 1666 "RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped");
1662 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1667 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1663 1668
1664 IOSurfaceID io_surface_handle =
1665 static_cast<IOSurfaceID>(params.surface_handle);
1666 AddPendingSwapAck(params.route_id, 1669 AddPendingSwapAck(params.route_id,
1667 gpu_host_id, 1670 gpu_host_id,
1668 compositing_iosurface_ ? 1671 compositing_iosurface_ ?
1669 compositing_iosurface_->GetRendererID() : 0); 1672 compositing_iosurface_->GetRendererID() : 0);
1670 CompositorSwapBuffers(io_surface_handle, 1673
1671 params.size, 1674 switch (GetSurfaceHandleType(params.surface_handle)) {
1672 params.scale_factor, 1675 case kSurfaceHandleTypeIOSurface: {
1673 params.latency_info); 1676 IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(
1677 params.surface_handle);
1678
1679 CompositorSwapBuffers(io_surface_id,
1680 params.size,
1681 params.scale_factor,
1682 params.latency_info);
1683 } break;
1684 case kSurfaceHandleTypeCAContext: {
1685 // Disable the fade-out animation as the layer is added.
1686 ScopedCAActionDisabler disabler;
1687
1688 CAContextID context_id = CAContextIDFromSurfaceHandle(
1689 params.surface_handle);
1690
1691 // If if the layer has changed put the new layer in the hierarchy and
1692 // take the old one out.
1693 if ([remote_layer_host_ contextId] != context_id) {
1694 [remote_layer_host_ removeFromSuperlayer];
1695
1696 remote_layer_host_.reset([[CALayerHost alloc] init]);
1697 [remote_layer_host_ setContextId:context_id];
1698 [remote_layer_host_
1699 setAutoresizingMask:kCALayerMaxXMargin|kCALayerMaxYMargin];
1700 [background_layer_ addSublayer:remote_layer_host_];
1701 }
1702
1703 // Ack the frame immediately. Any GPU back pressure will be applied by
1704 // the remote layer from within the GPU process.
1705 SendPendingSwapAck();
1706 } break;
1707 default:
1708 LOG(ERROR) << "Invalid surface handle type.";
1709 break;
1710 }
1674 } 1711 }
1675 1712
1676 void RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer( 1713 void RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer(
1677 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 1714 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
1678 int gpu_host_id) { 1715 int gpu_host_id) {
1679 TRACE_EVENT0("browser", 1716 TRACE_EVENT0("browser",
1680 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer"); 1717 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer");
1681 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1718 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1682 1719
1683 IOSurfaceID io_surface_handle =
1684 static_cast<IOSurfaceID>(params.surface_handle);
1685 AddPendingSwapAck(params.route_id, 1720 AddPendingSwapAck(params.route_id,
1686 gpu_host_id, 1721 gpu_host_id,
1687 compositing_iosurface_ ? 1722 compositing_iosurface_ ?
1688 compositing_iosurface_->GetRendererID() : 0); 1723 compositing_iosurface_->GetRendererID() : 0);
1689 CompositorSwapBuffers(io_surface_handle, 1724 CompositorSwapBuffers(IOSurfaceIDFromSurfaceHandle(params.surface_handle),
1690 params.surface_size, 1725 params.surface_size,
1691 params.surface_scale_factor, 1726 params.surface_scale_factor,
1692 params.latency_info); 1727 params.latency_info);
1693 } 1728 }
1694 1729
1695 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { 1730 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() {
1696 if (compositing_iosurface_) 1731 if (compositing_iosurface_)
1697 compositing_iosurface_->UnrefIOSurface(); 1732 compositing_iosurface_->UnrefIOSurface();
1698 } 1733 }
1699 1734
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
2196 } 2231 }
2197 } 2232 }
2198 if (compositing_iosurface_ && 2233 if (compositing_iosurface_ &&
2199 compositing_iosurface_->HasIOSurface() && 2234 compositing_iosurface_->HasIOSurface() &&
2200 compositing_iosurface_layer_) { 2235 compositing_iosurface_layer_) {
2201 CGRect layer_bounds = CGRectMake( 2236 CGRect layer_bounds = CGRectMake(
2202 0, 2237 0,
2203 0, 2238 0,
2204 compositing_iosurface_->dip_io_surface_size().width(), 2239 compositing_iosurface_->dip_io_surface_size().width(),
2205 compositing_iosurface_->dip_io_surface_size().height()); 2240 compositing_iosurface_->dip_io_surface_size().height());
2206 CGPoint layer_position = CGPointMake(
2207 0,
2208 CGRectGetHeight(new_background_frame) - CGRectGetHeight(layer_bounds));
2209 bool bounds_changed = !CGRectEqualToRect( 2241 bool bounds_changed = !CGRectEqualToRect(
2210 layer_bounds, [compositing_iosurface_layer_ bounds]); 2242 layer_bounds, [compositing_iosurface_layer_ bounds]);
2211 [compositing_iosurface_layer_ setPosition:layer_position];
2212 [compositing_iosurface_layer_ setBounds:layer_bounds]; 2243 [compositing_iosurface_layer_ setBounds:layer_bounds];
2213 2244
2214 // If the bounds changed, then draw the frame immediately, to ensure that 2245 // If the bounds changed, then draw the frame immediately, to ensure that
2215 // content displayed is in sync with the window size. 2246 // content displayed is in sync with the window size.
2216 if (bounds_changed) { 2247 if (bounds_changed) {
2217 // Also, sometimes, especially when infobars are being removed, the 2248 // Also, sometimes, especially when infobars are being removed, the
2218 // setNeedsDisplay calls are dropped on the floor, and stale content is 2249 // setNeedsDisplay calls are dropped on the floor, and stale content is
2219 // displayed. Calling displayIfNeeded will ensure that the right size 2250 // displayed. Calling displayIfNeeded will ensure that the right size
2220 // frame is drawn to the screen. 2251 // frame is drawn to the screen.
2221 // http://crbug.com/350817 2252 // http://crbug.com/350817
(...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after
3928 3959
3929 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3960 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3930 // regions that are not draggable. (See ControlRegionView in 3961 // regions that are not draggable. (See ControlRegionView in
3931 // native_app_window_cocoa.mm). This requires the render host view to be 3962 // native_app_window_cocoa.mm). This requires the render host view to be
3932 // draggable by default. 3963 // draggable by default.
3933 - (BOOL)mouseDownCanMoveWindow { 3964 - (BOOL)mouseDownCanMoveWindow {
3934 return YES; 3965 return YES;
3935 } 3966 }
3936 3967
3937 @end 3968 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698