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

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

Powered by Google App Engine
This is Rietveld 408576698