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 #include <QuartzCore/QuartzCore.h> | 7 #include <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
13 #include "base/mac/closure_blocks_leopard_compat.h" | 13 #include "base/mac/closure_blocks_leopard_compat.h" |
14 #include "base/mac/scoped_cftyperef.h" | 14 #include "base/mac/scoped_cftyperef.h" |
15 #import "base/mac/scoped_nsautorelease_pool.h" | 15 #import "base/mac/scoped_nsautorelease_pool.h" |
16 #import "base/memory/scoped_nsobject.h" | 16 #import "base/memory/scoped_nsobject.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
20 #include "base/sys_string_conversions.h" | 20 #include "base/sys_string_conversions.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 22 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
23 #include "content/browser/accessibility/browser_accessibility_manager.h" | 23 #include "content/browser/accessibility/browser_accessibility_manager.h" |
24 #include "content/browser/plugin_process_host.h" | 24 #include "content/browser/plugin_process_host.h" |
25 #import "content/browser/renderer_host/accelerated_plugin_view_mac.h" | 25 #import "content/browser/renderer_host/accelerated_plugin_view_mac.h" |
26 #include "content/browser/renderer_host/backing_store_mac.h" | 26 #include "content/browser/renderer_host/backing_store_mac.h" |
| 27 #include "content/browser/renderer_host/backing_store_manager.h" |
27 #include "content/browser/renderer_host/compositing_iosurface_mac.h" | 28 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
28 #include "content/browser/renderer_host/render_process_host_impl.h" | 29 #include "content/browser/renderer_host/render_process_host_impl.h" |
29 #include "content/browser/renderer_host/render_view_host_impl.h" | 30 #include "content/browser/renderer_host/render_view_host_impl.h" |
30 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h
elper.h" | 31 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h
elper.h" |
31 #import "content/browser/renderer_host/text_input_client_mac.h" | 32 #import "content/browser/renderer_host/text_input_client_mac.h" |
32 #include "content/common/accessibility_messages.h" | 33 #include "content/common/accessibility_messages.h" |
33 #include "content/common/edit_command.h" | 34 #include "content/common/edit_command.h" |
34 #include "content/common/gpu/gpu_messages.h" | 35 #include "content/common/gpu/gpu_messages.h" |
35 #include "content/common/plugin_messages.h" | 36 #include "content/common/plugin_messages.h" |
36 #include "content/common/view_messages.h" | 37 #include "content/common/view_messages.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 257 |
257 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) | 258 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) |
258 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 259 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
259 about_to_validate_and_paint_(false), | 260 about_to_validate_and_paint_(false), |
260 call_set_needs_display_in_rect_pending_(false), | 261 call_set_needs_display_in_rect_pending_(false), |
261 last_frame_was_accelerated_(false), | 262 last_frame_was_accelerated_(false), |
262 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 263 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
263 can_compose_inline_(true), | 264 can_compose_inline_(true), |
264 is_loading_(false), | 265 is_loading_(false), |
265 is_hidden_(false), | 266 is_hidden_(false), |
266 weak_factory_(this), | 267 weak_factory_(this) { |
267 compositing_surface_(gfx::kNullPluginWindow) { | |
268 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 268 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
269 // goes away. Since we autorelease it, our caller must put | 269 // goes away. Since we autorelease it, our caller must put |
270 // |GetNativeView()| into the view hierarchy right after calling us. | 270 // |GetNativeView()| into the view hierarchy right after calling us. |
271 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 271 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
272 initWithRenderWidgetHostViewMac:this] autorelease]; | 272 initWithRenderWidgetHostViewMac:this] autorelease]; |
273 render_widget_host_->SetView(this); | 273 render_widget_host_->SetView(this); |
274 } | 274 } |
275 | 275 |
276 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 276 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
277 UnlockMouse(); | 277 UnlockMouse(); |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 int32 route_id, | 954 int32 route_id, |
955 int32 gpu_host_id) { | 955 int32 gpu_host_id) { |
956 pending_swap_buffers_acks_.push_back(std::make_pair(route_id, gpu_host_id)); | 956 pending_swap_buffers_acks_.push_back(std::make_pair(route_id, gpu_host_id)); |
957 if (!compositing_iosurface_.get() && !is_hidden_) { | 957 if (!compositing_iosurface_.get() && !is_hidden_) { |
958 compositing_iosurface_.reset(CompositingIOSurfaceMac::Create()); | 958 compositing_iosurface_.reset(CompositingIOSurfaceMac::Create()); |
959 } | 959 } |
960 | 960 |
961 if (compositing_iosurface_.get() && !is_hidden_) { | 961 if (compositing_iosurface_.get() && !is_hidden_) { |
962 last_frame_was_accelerated_ = true; | 962 last_frame_was_accelerated_ = true; |
963 compositing_iosurface_->SetIOSurface(surface_handle); | 963 compositing_iosurface_->SetIOSurface(surface_handle); |
964 [cocoa_view_ setNeedsDisplay:YES]; | 964 // No need for presenting if we're already in a drawRect (it will be done |
| 965 // later). |
| 966 if (!about_to_validate_and_paint_) { |
| 967 compositing_iosurface_->DrawIOSurface(cocoa_view_); |
| 968 AckPendingCompositorSwapBuffers(); |
| 969 } |
965 } else { | 970 } else { |
966 AckPendingCompositorSwapBuffers(); | 971 AckPendingCompositorSwapBuffers(); |
967 } | 972 } |
968 } | 973 } |
969 | 974 |
970 void RenderWidgetHostViewMac::AckPendingCompositorSwapBuffers() { | 975 void RenderWidgetHostViewMac::AckPendingCompositorSwapBuffers() { |
971 TRACE_EVENT0("browser", | 976 TRACE_EVENT0("browser", |
972 "RenderWidgetHostViewMac::AckPendingCompositorSwapBuffers"); | 977 "RenderWidgetHostViewMac::AckPendingCompositorSwapBuffers"); |
973 while (!pending_swap_buffers_acks_.empty()) { | 978 while (!pending_swap_buffers_acks_.empty()) { |
974 if (pending_swap_buffers_acks_.front().first != 0) { | 979 if (pending_swap_buffers_acks_.front().first != 0) { |
975 RenderWidgetHostImpl::AcknowledgeSwapBuffers( | 980 RenderWidgetHostImpl::AcknowledgeSwapBuffers( |
976 pending_swap_buffers_acks_.front().first, | 981 pending_swap_buffers_acks_.front().first, |
977 pending_swap_buffers_acks_.front().second); | 982 pending_swap_buffers_acks_.front().second); |
978 } | 983 } |
979 pending_swap_buffers_acks_.erase(pending_swap_buffers_acks_.begin()); | 984 pending_swap_buffers_acks_.erase(pending_swap_buffers_acks_.begin()); |
980 } | 985 } |
981 } | 986 } |
982 | 987 |
983 void RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped( | 988 void RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped( |
984 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, | 989 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, |
985 int gpu_host_id) { | 990 int gpu_host_id) { |
986 TRACE_EVENT0("browser", | 991 TRACE_EVENT0("browser", |
987 "RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped"); | 992 "RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped"); |
988 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 993 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
989 | 994 |
990 if (params.window == compositing_surface_) { | 995 // Compositor window is always gfx::kNullPluginWindow. |
| 996 // TODO(jbates) This will be removed when there are no plugin windows. |
| 997 if (params.window == gfx::kNullPluginWindow) { |
991 CompositorSwapBuffers(params.surface_handle, params.route_id, gpu_host_id); | 998 CompositorSwapBuffers(params.surface_handle, params.route_id, gpu_host_id); |
992 } else { | 999 } else { |
993 // Deprecated accelerated plugin code path. | 1000 // Deprecated accelerated plugin code path. |
994 AcceleratedPluginView* view = ViewForPluginWindowHandle(params.window); | 1001 AcceleratedPluginView* view = ViewForPluginWindowHandle(params.window); |
995 DCHECK(view); | 1002 DCHECK(view); |
996 if (view) { | 1003 if (view) { |
997 plugin_container_manager_.SetSurfaceWasPaintedTo(params.window, | 1004 plugin_container_manager_.SetSurfaceWasPaintedTo(params.window, |
998 params.surface_handle); | 1005 params.surface_handle); |
999 | 1006 |
1000 // The surface is hidden until its first paint, to not show garbage. | 1007 // The surface is hidden until its first paint, to not show garbage. |
1001 if (plugin_container_manager_.SurfaceShouldBeVisible(params.window)) | 1008 if (plugin_container_manager_.SurfaceShouldBeVisible(params.window)) |
1002 [view setHidden:NO]; | 1009 [view setHidden:NO]; |
1003 [view drawView]; | 1010 [view drawView]; |
1004 } | 1011 } |
1005 | 1012 |
1006 if (params.route_id != 0) { | 1013 if (params.route_id != 0) { |
1007 RenderWidgetHostImpl::AcknowledgeSwapBuffers(params.route_id, | 1014 RenderWidgetHostImpl::AcknowledgeSwapBuffers(params.route_id, |
1008 gpu_host_id); | 1015 gpu_host_id); |
1009 } | 1016 } |
1010 } | 1017 } |
1011 } | 1018 } |
1012 | 1019 |
1013 void RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer( | 1020 void RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer( |
1014 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, | 1021 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, |
1015 int gpu_host_id) { | 1022 int gpu_host_id) { |
1016 TRACE_EVENT0("browser", | 1023 TRACE_EVENT0("browser", |
1017 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer"); | 1024 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer"); |
1018 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1025 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1019 | 1026 |
1020 if (params.window == compositing_surface_) { | 1027 // Compositor window is always gfx::kNullPluginWindow. |
| 1028 // TODO(jbates) This will be removed when there are no plugin windows. |
| 1029 if (params.window == gfx::kNullPluginWindow) { |
1021 CompositorSwapBuffers(params.surface_handle, params.route_id, gpu_host_id); | 1030 CompositorSwapBuffers(params.surface_handle, params.route_id, gpu_host_id); |
1022 } else { | 1031 } else { |
1023 // Deprecated accelerated plugin code path. | 1032 // Deprecated accelerated plugin code path. |
1024 AcceleratedPluginView* view = ViewForPluginWindowHandle(params.window); | 1033 AcceleratedPluginView* view = ViewForPluginWindowHandle(params.window); |
1025 DCHECK(view); | 1034 DCHECK(view); |
1026 if (view) { | 1035 if (view) { |
1027 plugin_container_manager_.SetSurfaceWasPaintedTo( | 1036 plugin_container_manager_.SetSurfaceWasPaintedTo( |
1028 params.window, | 1037 params.window, |
1029 params.surface_handle, | 1038 params.surface_handle, |
1030 gfx::Rect(params.x, params.y, params.width, params.height)); | 1039 gfx::Rect(params.x, params.y, params.width, params.height)); |
1031 | 1040 |
1032 // The surface is hidden until its first paint, to not show garbage. | 1041 // The surface is hidden until its first paint, to not show garbage. |
1033 if (plugin_container_manager_.SurfaceShouldBeVisible(params.window)) | 1042 if (plugin_container_manager_.SurfaceShouldBeVisible(params.window)) |
1034 [view setHidden:NO]; | 1043 [view setHidden:NO]; |
1035 [view drawView]; | 1044 [view drawView]; |
1036 } | 1045 } |
1037 | 1046 |
1038 if (params.route_id != 0) { | 1047 if (params.route_id != 0) { |
1039 RenderWidgetHostImpl::AcknowledgePostSubBuffer( | 1048 RenderWidgetHostImpl::AcknowledgePostSubBuffer( |
1040 params.route_id, gpu_host_id); | 1049 params.route_id, gpu_host_id); |
1041 } | 1050 } |
1042 } | 1051 } |
1043 } | 1052 } |
1044 | 1053 |
1045 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { | 1054 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { |
| 1055 if (compositing_iosurface_.get()) |
| 1056 compositing_iosurface_->UnrefIOSurface(); |
| 1057 } |
| 1058 |
| 1059 bool RenderWidgetHostViewMac::HasAcceleratedSurface( |
| 1060 const gfx::Size& desired_size) { |
| 1061 return last_frame_was_accelerated_ && |
| 1062 compositing_iosurface_.get() && |
| 1063 compositing_iosurface_->HasIOSurface() && |
| 1064 (desired_size.IsEmpty() || |
| 1065 compositing_iosurface_->io_surface_size() == desired_size); |
| 1066 } |
| 1067 |
| 1068 void RenderWidgetHostViewMac::AboutToWaitForUpdateMsg() { |
| 1069 // We want to get a fresh frame from the renderer, so ack any pending swaps to |
| 1070 // allow the renderer to produce new frames. |
| 1071 AckPendingCompositorSwapBuffers(); |
1046 } | 1072 } |
1047 | 1073 |
1048 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { | 1074 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { |
1049 } | 1075 } |
1050 | 1076 |
1051 void RenderWidgetHostViewMac::GetScreenInfo(WebKit::WebScreenInfo* results) { | 1077 void RenderWidgetHostViewMac::GetScreenInfo(WebKit::WebScreenInfo* results) { |
1052 *results = WebKit::WebScreenInfoFactory::screenInfo(GetNativeView()); | 1078 *results = WebKit::WebScreenInfoFactory::screenInfo(GetNativeView()); |
1053 } | 1079 } |
1054 | 1080 |
1055 gfx::Rect RenderWidgetHostViewMac::GetRootWindowBounds() { | 1081 gfx::Rect RenderWidgetHostViewMac::GetRootWindowBounds() { |
1056 // TODO(shess): In case of !window, the view has been removed from | 1082 // TODO(shess): In case of !window, the view has been removed from |
1057 // the view hierarchy because the tab isn't main. Could retrieve | 1083 // the view hierarchy because the tab isn't main. Could retrieve |
1058 // the information from the main tab for our window. | 1084 // the information from the main tab for our window. |
1059 NSWindow* enclosing_window = ApparentWindowForView(cocoa_view_); | 1085 NSWindow* enclosing_window = ApparentWindowForView(cocoa_view_); |
1060 if (!enclosing_window) | 1086 if (!enclosing_window) |
1061 return gfx::Rect(); | 1087 return gfx::Rect(); |
1062 | 1088 |
1063 NSRect bounds = [enclosing_window frame]; | 1089 NSRect bounds = [enclosing_window frame]; |
1064 return FlipNSRectToRectScreen(bounds); | 1090 return FlipNSRectToRectScreen(bounds); |
1065 } | 1091 } |
1066 | 1092 |
1067 gfx::GLSurfaceHandle RenderWidgetHostViewMac::GetCompositingSurface() { | 1093 gfx::GLSurfaceHandle RenderWidgetHostViewMac::GetCompositingSurface() { |
1068 // compositing_surface_ is always gfx::kNullPluginWindow. | 1094 // Compositor window is always gfx::kNullPluginWindow. |
1069 return gfx::GLSurfaceHandle(compositing_surface_, true); | 1095 // TODO(jbates) This will be removed when there are no plugin windows. |
| 1096 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, true); |
1070 } | 1097 } |
1071 | 1098 |
1072 void RenderWidgetHostViewMac::DrawAcceleratedSurfaceInstance( | 1099 void RenderWidgetHostViewMac::DrawAcceleratedSurfaceInstance( |
1073 CGLContextObj context, | 1100 CGLContextObj context, |
1074 gfx::PluginWindowHandle plugin_handle, | 1101 gfx::PluginWindowHandle plugin_handle, |
1075 NSSize size) { | 1102 NSSize size) { |
1076 TRACE_EVENT0("browser", | 1103 TRACE_EVENT0("browser", |
1077 "RenderWidgetHostViewMac::DrawAcceleratedSurfaceInstance"); | 1104 "RenderWidgetHostViewMac::DrawAcceleratedSurfaceInstance"); |
1078 // Called on the display link thread. | 1105 // Called on the display link thread. |
1079 CGLSetCurrentContext(context); | 1106 CGLSetCurrentContext(context); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 [view performSelector:nonWebContentViewSelector]) { | 1377 [view performSelector:nonWebContentViewSelector]) { |
1351 // The cursor is over a nonWebContentView - ignore this mouse event. | 1378 // The cursor is over a nonWebContentView - ignore this mouse event. |
1352 return YES; | 1379 return YES; |
1353 } | 1380 } |
1354 view = [view superview]; | 1381 view = [view superview]; |
1355 } | 1382 } |
1356 return NO; | 1383 return NO; |
1357 } | 1384 } |
1358 | 1385 |
1359 - (void)mouseEvent:(NSEvent*)theEvent { | 1386 - (void)mouseEvent:(NSEvent*)theEvent { |
| 1387 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::mouseEvent"); |
1360 if (delegate_ && [delegate_ respondsToSelector:@selector(handleEvent:)]) { | 1388 if (delegate_ && [delegate_ respondsToSelector:@selector(handleEvent:)]) { |
1361 BOOL handled = [delegate_ handleEvent:theEvent]; | 1389 BOOL handled = [delegate_ handleEvent:theEvent]; |
1362 if (handled) | 1390 if (handled) |
1363 return; | 1391 return; |
1364 } | 1392 } |
1365 | 1393 |
1366 if ([self shouldIgnoreMouseEvent:theEvent]) { | 1394 if ([self shouldIgnoreMouseEvent:theEvent]) { |
1367 // If this is the first such event, send a mouse exit to the host view. | 1395 // If this is the first such event, send a mouse exit to the host view. |
1368 if (!mouseEventWasIgnored_ && renderWidgetHostView_->render_widget_host_) { | 1396 if (!mouseEventWasIgnored_ && renderWidgetHostView_->render_widget_host_) { |
1369 WebMouseEvent exitEvent = | 1397 WebMouseEvent exitEvent = |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 if (delegate_ && [delegate_ respondsToSelector:@selector(handleEvent:)]) { | 1539 if (delegate_ && [delegate_ respondsToSelector:@selector(handleEvent:)]) { |
1512 BOOL handled = [delegate_ handleEvent:theEvent]; | 1540 BOOL handled = [delegate_ handleEvent:theEvent]; |
1513 if (handled) | 1541 if (handled) |
1514 return; | 1542 return; |
1515 } | 1543 } |
1516 | 1544 |
1517 [self keyEvent:theEvent wasKeyEquivalent:NO]; | 1545 [self keyEvent:theEvent wasKeyEquivalent:NO]; |
1518 } | 1546 } |
1519 | 1547 |
1520 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv { | 1548 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv { |
| 1549 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::keyEvent"); |
1521 DCHECK([theEvent type] != NSKeyDown || | 1550 DCHECK([theEvent type] != NSKeyDown || |
1522 !equiv == !([theEvent modifierFlags] & NSCommandKeyMask)); | 1551 !equiv == !([theEvent modifierFlags] & NSCommandKeyMask)); |
1523 | 1552 |
1524 if ([theEvent type] == NSFlagsChanged) { | 1553 if ([theEvent type] == NSFlagsChanged) { |
1525 // Ignore NSFlagsChanged events from the NumLock and Fn keys as | 1554 // Ignore NSFlagsChanged events from the NumLock and Fn keys as |
1526 // Safari does in -[WebHTMLView flagsChanged:] (of "WebHTMLView.mm"). | 1555 // Safari does in -[WebHTMLView flagsChanged:] (of "WebHTMLView.mm"). |
1527 int keyCode = [theEvent keyCode]; | 1556 int keyCode = [theEvent keyCode]; |
1528 if (!keyCode || keyCode == 10 || keyCode == 63) | 1557 if (!keyCode || keyCode == 10 || keyCode == 63) |
1529 return; | 1558 return; |
1530 } | 1559 } |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1836 height = -height; | 1865 height = -height; |
1837 } | 1866 } |
1838 | 1867 |
1839 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; | 1868 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; |
1840 [[NSColor whiteColor] set]; | 1869 [[NSColor whiteColor] set]; |
1841 NSRectFill(r); | 1870 NSRectFill(r); |
1842 } | 1871 } |
1843 } | 1872 } |
1844 | 1873 |
1845 - (void)drawRect:(NSRect)dirtyRect { | 1874 - (void)drawRect:(NSRect)dirtyRect { |
| 1875 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); |
1846 if (!renderWidgetHostView_->render_widget_host_) { | 1876 if (!renderWidgetHostView_->render_widget_host_) { |
1847 // TODO(shess): Consider using something more noticable? | 1877 // TODO(shess): Consider using something more noticable? |
1848 [[NSColor whiteColor] set]; | 1878 [[NSColor whiteColor] set]; |
1849 NSRectFill(dirtyRect); | 1879 NSRectFill(dirtyRect); |
1850 return; | 1880 return; |
1851 } | 1881 } |
1852 | 1882 |
| 1883 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); |
| 1884 |
| 1885 // GetBackingStore works for both software and accelerated frames. If a |
| 1886 // SwapBuffers occurs while GetBackingStore is blocking, we will continue to |
| 1887 // blit the IOSurface below. |
| 1888 renderWidgetHostView_->about_to_validate_and_paint_ = true; |
| 1889 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( |
| 1890 renderWidgetHostView_->render_widget_host_->GetBackingStore(true)); |
| 1891 renderWidgetHostView_->about_to_validate_and_paint_ = false; |
| 1892 |
1853 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]); | 1893 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]); |
1854 | 1894 |
1855 if (renderWidgetHostView_->last_frame_was_accelerated_) { | 1895 if (renderWidgetHostView_->last_frame_was_accelerated_) { |
1856 // Draw transparency to expose the GL underlay: | 1896 // Delete software backingstore. |
1857 // TODO(jbates) avoid doing this every frame. | 1897 // TODO(jbates) Only do this on first GPU frame after software frame. |
1858 [[NSColor clearColor] set]; | 1898 BackingStoreManager::RemoveBackingStore( |
1859 NSRectFill(dirtyRect); | 1899 renderWidgetHostView_->render_widget_host_); |
| 1900 |
| 1901 { |
| 1902 TRACE_EVENT0("browser", "NSRectFill"); |
| 1903 // Draw transparency to expose the GL underlay: |
| 1904 // TODO(jbates) avoid doing this every frame. |
| 1905 [[NSColor clearColor] set]; |
| 1906 NSRectFill(dirtyRect); |
| 1907 } |
1860 | 1908 |
1861 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(self); | 1909 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(self); |
1862 renderWidgetHostView_->AckPendingCompositorSwapBuffers(); | 1910 renderWidgetHostView_->AckPendingCompositorSwapBuffers(); |
1863 return; | 1911 return; |
1864 } | 1912 } |
1865 | 1913 |
| 1914 // Forget IOSurface since we are drawing a software frame now. |
| 1915 if (renderWidgetHostView_->compositing_iosurface_.get() && |
| 1916 renderWidgetHostView_->compositing_iosurface_->HasIOSurface()) |
| 1917 renderWidgetHostView_->compositing_iosurface_->UnrefIOSurface(); |
| 1918 |
1866 // In case the last frame was accelerated, ack any pending swaps to unblock | 1919 // In case the last frame was accelerated, ack any pending swaps to unblock |
1867 // the GPU process. | 1920 // the GPU process. |
1868 renderWidgetHostView_->AckPendingCompositorSwapBuffers(); | 1921 renderWidgetHostView_->AckPendingCompositorSwapBuffers(); |
1869 | 1922 |
1870 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); | |
1871 | |
1872 renderWidgetHostView_->about_to_validate_and_paint_ = true; | |
1873 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( | |
1874 renderWidgetHostView_->render_widget_host_->GetBackingStore(true)); | |
1875 renderWidgetHostView_->about_to_validate_and_paint_ = false; | |
1876 | |
1877 if (backingStore) { | 1923 if (backingStore) { |
1878 gfx::Rect bitmapRect(0, 0, | 1924 gfx::Rect bitmapRect(0, 0, |
1879 backingStore->size().width(), | 1925 backingStore->size().width(), |
1880 backingStore->size().height()); | 1926 backingStore->size().height()); |
1881 | 1927 |
1882 // Specify the proper y offset to ensure that the view is rooted to the | 1928 // Specify the proper y offset to ensure that the view is rooted to the |
1883 // upper left corner. This can be negative, if the window was resized | 1929 // upper left corner. This can be negative, if the window was resized |
1884 // smaller and the renderer hasn't yet repainted. | 1930 // smaller and the renderer hasn't yet repainted. |
1885 int yOffset = NSHeight([self bounds]) - backingStore->size().height(); | 1931 int yOffset = NSHeight([self bounds]) - backingStore->size().height(); |
1886 | 1932 |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2856 if (!string) return NO; | 2902 if (!string) return NO; |
2857 | 2903 |
2858 // If the user is currently using an IME, confirm the IME input, | 2904 // If the user is currently using an IME, confirm the IME input, |
2859 // and then insert the text from the service, the same as TextEdit and Safari. | 2905 // and then insert the text from the service, the same as TextEdit and Safari. |
2860 [self confirmComposition]; | 2906 [self confirmComposition]; |
2861 [self insertText:string]; | 2907 [self insertText:string]; |
2862 return YES; | 2908 return YES; |
2863 } | 2909 } |
2864 | 2910 |
2865 @end | 2911 @end |
OLD | NEW |