| 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/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 | 1039 |
| 1040 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( | 1040 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( |
| 1041 const string16& text, int plugin_id) { | 1041 const string16& text, int plugin_id) { |
| 1042 if (render_widget_host_) { | 1042 if (render_widget_host_) { |
| 1043 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( | 1043 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( |
| 1044 render_widget_host_->GetRoutingID(), text, plugin_id)); | 1044 render_widget_host_->GetRoutingID(), text, plugin_id)); |
| 1045 } | 1045 } |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 bool RenderWidgetHostViewMac::CompositorSwapBuffers(uint64 surface_handle, | 1048 bool RenderWidgetHostViewMac::CompositorSwapBuffers(uint64 surface_handle, |
| 1049 const gfx::Size& size) { | 1049 const gfx::Size& size, |
| 1050 float scale_factor) { |
| 1050 if (is_hidden_) | 1051 if (is_hidden_) |
| 1051 return true; | 1052 return true; |
| 1052 | 1053 |
| 1053 NSWindow* window = [cocoa_view_ window]; | 1054 NSWindow* window = [cocoa_view_ window]; |
| 1054 if (window_number() <= 0) { | 1055 if (window_number() <= 0) { |
| 1055 // There is no window to present so capturing during present won't work. | 1056 // There is no window to present so capturing during present won't work. |
| 1056 // We check if frame subscriber wants this frame and capture manually. | 1057 // We check if frame subscriber wants this frame and capture manually. |
| 1057 if (compositing_iosurface_.get() && frame_subscriber_) { | 1058 if (compositing_iosurface_.get() && frame_subscriber_) { |
| 1058 const base::Time present_time = base::Time::Now(); | 1059 const base::Time present_time = base::Time::Now(); |
| 1059 scoped_refptr<media::VideoFrame> frame; | 1060 scoped_refptr<media::VideoFrame> frame; |
| 1060 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; | 1061 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; |
| 1061 if (frame_subscriber_->ShouldCaptureFrame(present_time, | 1062 if (frame_subscriber_->ShouldCaptureFrame(present_time, |
| 1062 &frame, &callback)) { | 1063 &frame, &callback)) { |
| 1063 compositing_iosurface_->SetIOSurface(surface_handle, size); | 1064 compositing_iosurface_->SetIOSurface( |
| 1065 surface_handle, size, scale_factor); |
| 1064 compositing_iosurface_->CopyToVideoFrame( | 1066 compositing_iosurface_->CopyToVideoFrame( |
| 1065 gfx::Rect(size), ScaleFactor(cocoa_view_), frame, | 1067 gfx::Rect(size), ScaleFactor(cocoa_view_), frame, |
| 1066 base::Bind(callback, present_time)); | 1068 base::Bind(callback, present_time)); |
| 1067 return true; | 1069 return true; |
| 1068 } | 1070 } |
| 1069 } | 1071 } |
| 1070 | 1072 |
| 1071 // TODO(shess) If the view does not have a window, or the window | 1073 // TODO(shess) If the view does not have a window, or the window |
| 1072 // does not have backing, the IOSurface will log "invalid drawable" | 1074 // does not have backing, the IOSurface will log "invalid drawable" |
| 1073 // in -setView:. It is not clear how this code is reached with such | 1075 // in -setView:. It is not clear how this code is reached with such |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1095 CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW : | 1097 CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW : |
| 1096 CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW; | 1098 CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW; |
| 1097 compositing_iosurface_.reset( | 1099 compositing_iosurface_.reset( |
| 1098 CompositingIOSurfaceMac::Create(window_number(), order)); | 1100 CompositingIOSurfaceMac::Create(window_number(), order)); |
| 1099 should_post_notification = true; | 1101 should_post_notification = true; |
| 1100 } | 1102 } |
| 1101 | 1103 |
| 1102 if (!compositing_iosurface_) | 1104 if (!compositing_iosurface_) |
| 1103 return true; | 1105 return true; |
| 1104 | 1106 |
| 1105 compositing_iosurface_->SetIOSurface(surface_handle, size); | 1107 compositing_iosurface_->SetIOSurface(surface_handle, size, scale_factor); |
| 1106 | 1108 |
| 1107 GotAcceleratedFrame(); | 1109 GotAcceleratedFrame(); |
| 1108 | 1110 |
| 1109 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size)); | 1111 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size)); |
| 1110 if (window_size.IsEmpty()) { | 1112 if (window_size.IsEmpty()) { |
| 1111 // setNeedsDisplay will never display and we'll never ack if the window is | 1113 // setNeedsDisplay will never display and we'll never ack if the window is |
| 1112 // empty, so ack now and don't bother calling setNeedsDisplay below. | 1114 // empty, so ack now and don't bother calling setNeedsDisplay below. |
| 1113 return true; | 1115 return true; |
| 1114 } | 1116 } |
| 1115 | 1117 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 void RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped( | 1307 void RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped( |
| 1306 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, | 1308 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, |
| 1307 int gpu_host_id) { | 1309 int gpu_host_id) { |
| 1308 TRACE_EVENT0("browser", | 1310 TRACE_EVENT0("browser", |
| 1309 "RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped"); | 1311 "RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped"); |
| 1310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1311 | 1313 |
| 1312 pending_swap_buffers_acks_.push_back(std::make_pair(params.route_id, | 1314 pending_swap_buffers_acks_.push_back(std::make_pair(params.route_id, |
| 1313 gpu_host_id)); | 1315 gpu_host_id)); |
| 1314 | 1316 |
| 1315 if (CompositorSwapBuffers(params.surface_handle, params.size)) | 1317 if (CompositorSwapBuffers(params.surface_handle, |
| 1318 params.size, |
| 1319 params.scale_factor)) |
| 1316 AckPendingSwapBuffers(); | 1320 AckPendingSwapBuffers(); |
| 1317 } | 1321 } |
| 1318 | 1322 |
| 1319 void RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer( | 1323 void RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer( |
| 1320 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, | 1324 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, |
| 1321 int gpu_host_id) { | 1325 int gpu_host_id) { |
| 1322 TRACE_EVENT0("browser", | 1326 TRACE_EVENT0("browser", |
| 1323 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer"); | 1327 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer"); |
| 1324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1325 | 1329 |
| 1326 pending_swap_buffers_acks_.push_back(std::make_pair(params.route_id, | 1330 pending_swap_buffers_acks_.push_back(std::make_pair(params.route_id, |
| 1327 gpu_host_id)); | 1331 gpu_host_id)); |
| 1328 | 1332 |
| 1329 if (CompositorSwapBuffers(params.surface_handle, params.surface_size)) | 1333 if (CompositorSwapBuffers(params.surface_handle, |
| 1334 params.surface_size, |
| 1335 params.surface_scale_factor)) |
| 1330 AckPendingSwapBuffers(); | 1336 AckPendingSwapBuffers(); |
| 1331 } | 1337 } |
| 1332 | 1338 |
| 1333 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { | 1339 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { |
| 1334 if (compositing_iosurface_) | 1340 if (compositing_iosurface_) |
| 1335 compositing_iosurface_->UnrefIOSurface(); | 1341 compositing_iosurface_->UnrefIOSurface(); |
| 1336 } | 1342 } |
| 1337 | 1343 |
| 1338 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() { | 1344 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() { |
| 1339 compositing_iosurface_.reset(); | 1345 compositing_iosurface_.reset(); |
| 1340 } | 1346 } |
| 1341 | 1347 |
| 1342 bool RenderWidgetHostViewMac::HasAcceleratedSurface( | 1348 bool RenderWidgetHostViewMac::HasAcceleratedSurface( |
| 1343 const gfx::Size& desired_size) { | 1349 const gfx::Size& desired_size) { |
| 1344 // Update device scale factor for the IOSurface before checking if there | |
| 1345 // is a match. When initially created, the IOSurface is unaware of its | |
| 1346 // scale factor, which can result in compatible IOSurfaces not being used | |
| 1347 // http://crbug.com/237293 | |
| 1348 if (compositing_iosurface_.get() && | |
| 1349 compositing_iosurface_->HasIOSurface()) { | |
| 1350 compositing_iosurface_->SetDeviceScaleFactor(ScaleFactor(cocoa_view_)); | |
| 1351 } | |
| 1352 | |
| 1353 return last_frame_was_accelerated_ && | 1350 return last_frame_was_accelerated_ && |
| 1354 compositing_iosurface_.get() && | 1351 compositing_iosurface_.get() && |
| 1355 compositing_iosurface_->HasIOSurface() && | 1352 compositing_iosurface_->HasIOSurface() && |
| 1356 (desired_size.IsEmpty() || | 1353 (desired_size.IsEmpty() || |
| 1357 compositing_iosurface_->io_surface_size() == desired_size); | 1354 compositing_iosurface_->io_surface_size() == desired_size); |
| 1358 } | 1355 } |
| 1359 | 1356 |
| 1360 void RenderWidgetHostViewMac::AboutToWaitForBackingStoreMsg() { | 1357 void RenderWidgetHostViewMac::AboutToWaitForBackingStoreMsg() { |
| 1361 AckPendingSwapBuffers(); | 1358 AckPendingSwapBuffers(); |
| 1362 } | 1359 } |
| (...skipping 2037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3400 if (!string) return NO; | 3397 if (!string) return NO; |
| 3401 | 3398 |
| 3402 // If the user is currently using an IME, confirm the IME input, | 3399 // If the user is currently using an IME, confirm the IME input, |
| 3403 // and then insert the text from the service, the same as TextEdit and Safari. | 3400 // and then insert the text from the service, the same as TextEdit and Safari. |
| 3404 [self confirmComposition]; | 3401 [self confirmComposition]; |
| 3405 [self insertText:string]; | 3402 [self insertText:string]; |
| 3406 return YES; | 3403 return YES; |
| 3407 } | 3404 } |
| 3408 | 3405 |
| 3409 @end | 3406 @end |
| OLD | NEW |