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 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 !compositing_iosurface_->HasIOSurface()) | 936 !compositing_iosurface_->HasIOSurface()) |
937 return; | 937 return; |
938 | 938 |
939 float scale = ScaleFactor(cocoa_view_); | 939 float scale = ScaleFactor(cocoa_view_); |
940 gfx::Size dst_pixel_size = gfx::ToFlooredSize( | 940 gfx::Size dst_pixel_size = gfx::ToFlooredSize( |
941 gfx::ScaleSize(dst_size, scale)); | 941 gfx::ScaleSize(dst_size, scale)); |
942 | 942 |
943 scoped_callback_runner.Release(); | 943 scoped_callback_runner.Release(); |
944 | 944 |
945 compositing_iosurface_->CopyTo(GetScaledOpenGLPixelRect(src_subrect), | 945 compositing_iosurface_->CopyTo(GetScaledOpenGLPixelRect(src_subrect), |
946 ScaleFactor(cocoa_view_), | |
947 dst_pixel_size, | 946 dst_pixel_size, |
948 callback); | 947 callback); |
949 } | 948 } |
950 | 949 |
951 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( | 950 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( |
952 const gfx::Rect& src_subrect, | 951 const gfx::Rect& src_subrect, |
953 const scoped_refptr<media::VideoFrame>& target, | 952 const scoped_refptr<media::VideoFrame>& target, |
954 const base::Callback<void(bool)>& callback) { | 953 const base::Callback<void(bool)>& callback) { |
955 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); | 954 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); |
956 if (!render_widget_host_->is_accelerated_compositing_active() || | 955 if (!render_widget_host_->is_accelerated_compositing_active() || |
(...skipping 11 matching lines...) Expand all Loading... |
968 NOTREACHED(); | 967 NOTREACHED(); |
969 return; | 968 return; |
970 } | 969 } |
971 | 970 |
972 if (src_subrect.IsEmpty()) | 971 if (src_subrect.IsEmpty()) |
973 return; | 972 return; |
974 | 973 |
975 scoped_callback_runner.Release(); | 974 scoped_callback_runner.Release(); |
976 compositing_iosurface_->CopyToVideoFrame( | 975 compositing_iosurface_->CopyToVideoFrame( |
977 GetScaledOpenGLPixelRect(src_subrect), | 976 GetScaledOpenGLPixelRect(src_subrect), |
978 ScaleFactor(cocoa_view_), | |
979 target, | 977 target, |
980 callback); | 978 callback); |
981 } | 979 } |
982 | 980 |
983 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { | 981 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { |
984 return (!render_widget_host_->GetBackingStore(false) && | 982 return (!render_widget_host_->GetBackingStore(false) && |
985 render_widget_host_->is_accelerated_compositing_active() && | 983 render_widget_host_->is_accelerated_compositing_active() && |
986 compositing_iosurface_.get() && | 984 compositing_iosurface_.get() && |
987 compositing_iosurface_->HasIOSurface()); | 985 compositing_iosurface_->HasIOSurface()); |
988 } | 986 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 | 1037 |
1040 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( | 1038 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( |
1041 const string16& text, int plugin_id) { | 1039 const string16& text, int plugin_id) { |
1042 if (render_widget_host_) { | 1040 if (render_widget_host_) { |
1043 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( | 1041 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( |
1044 render_widget_host_->GetRoutingID(), text, plugin_id)); | 1042 render_widget_host_->GetRoutingID(), text, plugin_id)); |
1045 } | 1043 } |
1046 } | 1044 } |
1047 | 1045 |
1048 bool RenderWidgetHostViewMac::CompositorSwapBuffers(uint64 surface_handle, | 1046 bool RenderWidgetHostViewMac::CompositorSwapBuffers(uint64 surface_handle, |
1049 const gfx::Size& size) { | 1047 const gfx::Size& size, |
| 1048 float scale_factor) { |
1050 if (is_hidden_) | 1049 if (is_hidden_) |
1051 return true; | 1050 return true; |
1052 | 1051 |
1053 NSWindow* window = [cocoa_view_ window]; | 1052 NSWindow* window = [cocoa_view_ window]; |
1054 if (window_number() <= 0) { | 1053 if (window_number() <= 0) { |
1055 // There is no window to present so capturing during present won't work. | 1054 // 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. | 1055 // We check if frame subscriber wants this frame and capture manually. |
1057 if (compositing_iosurface_.get() && frame_subscriber_) { | 1056 if (compositing_iosurface_.get() && frame_subscriber_) { |
1058 const base::Time present_time = base::Time::Now(); | 1057 const base::Time present_time = base::Time::Now(); |
1059 scoped_refptr<media::VideoFrame> frame; | 1058 scoped_refptr<media::VideoFrame> frame; |
1060 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; | 1059 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; |
1061 if (frame_subscriber_->ShouldCaptureFrame(present_time, | 1060 if (frame_subscriber_->ShouldCaptureFrame(present_time, |
1062 &frame, &callback)) { | 1061 &frame, &callback)) { |
1063 compositing_iosurface_->SetIOSurface(surface_handle, size); | 1062 compositing_iosurface_->SetIOSurface( |
| 1063 surface_handle, size, scale_factor); |
1064 compositing_iosurface_->CopyToVideoFrame( | 1064 compositing_iosurface_->CopyToVideoFrame( |
1065 gfx::Rect(size), ScaleFactor(cocoa_view_), frame, | 1065 gfx::Rect(size), frame, |
1066 base::Bind(callback, present_time)); | 1066 base::Bind(callback, present_time)); |
1067 return true; | 1067 return true; |
1068 } | 1068 } |
1069 } | 1069 } |
1070 | 1070 |
1071 // TODO(shess) If the view does not have a window, or the window | 1071 // TODO(shess) If the view does not have a window, or the window |
1072 // does not have backing, the IOSurface will log "invalid drawable" | 1072 // does not have backing, the IOSurface will log "invalid drawable" |
1073 // in -setView:. It is not clear how this code is reached with such | 1073 // in -setView:. It is not clear how this code is reached with such |
1074 // a case, so record some info into breakpad (some subset of | 1074 // a case, so record some info into breakpad (some subset of |
1075 // browsers are likely to crash later for unrelated reasons). | 1075 // browsers are likely to crash later for unrelated reasons). |
(...skipping 19 matching lines...) Expand all Loading... |
1095 CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW : | 1095 CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW : |
1096 CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW; | 1096 CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW; |
1097 compositing_iosurface_.reset( | 1097 compositing_iosurface_.reset( |
1098 CompositingIOSurfaceMac::Create(window_number(), order)); | 1098 CompositingIOSurfaceMac::Create(window_number(), order)); |
1099 should_post_notification = true; | 1099 should_post_notification = true; |
1100 } | 1100 } |
1101 | 1101 |
1102 if (!compositing_iosurface_) | 1102 if (!compositing_iosurface_) |
1103 return true; | 1103 return true; |
1104 | 1104 |
1105 compositing_iosurface_->SetIOSurface(surface_handle, size); | 1105 compositing_iosurface_->SetIOSurface(surface_handle, size, scale_factor); |
1106 | 1106 |
1107 GotAcceleratedFrame(); | 1107 GotAcceleratedFrame(); |
1108 | 1108 |
1109 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size)); | 1109 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size)); |
1110 if (window_size.IsEmpty()) { | 1110 if (window_size.IsEmpty()) { |
1111 // setNeedsDisplay will never display and we'll never ack if the window is | 1111 // 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. | 1112 // empty, so ack now and don't bother calling setNeedsDisplay below. |
1113 return true; | 1113 return true; |
1114 } | 1114 } |
1115 | 1115 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 void RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped( | 1305 void RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped( |
1306 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, | 1306 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, |
1307 int gpu_host_id) { | 1307 int gpu_host_id) { |
1308 TRACE_EVENT0("browser", | 1308 TRACE_EVENT0("browser", |
1309 "RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped"); | 1309 "RenderWidgetHostViewMac::AcceleratedSurfaceBuffersSwapped"); |
1310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1311 | 1311 |
1312 pending_swap_buffers_acks_.push_back(std::make_pair(params.route_id, | 1312 pending_swap_buffers_acks_.push_back(std::make_pair(params.route_id, |
1313 gpu_host_id)); | 1313 gpu_host_id)); |
1314 | 1314 |
1315 if (CompositorSwapBuffers(params.surface_handle, params.size)) | 1315 if (CompositorSwapBuffers(params.surface_handle, |
| 1316 params.size, |
| 1317 params.scale_factor)) |
1316 AckPendingSwapBuffers(); | 1318 AckPendingSwapBuffers(); |
1317 } | 1319 } |
1318 | 1320 |
1319 void RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer( | 1321 void RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer( |
1320 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, | 1322 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, |
1321 int gpu_host_id) { | 1323 int gpu_host_id) { |
1322 TRACE_EVENT0("browser", | 1324 TRACE_EVENT0("browser", |
1323 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer"); | 1325 "RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer"); |
1324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1325 | 1327 |
1326 pending_swap_buffers_acks_.push_back(std::make_pair(params.route_id, | 1328 pending_swap_buffers_acks_.push_back(std::make_pair(params.route_id, |
1327 gpu_host_id)); | 1329 gpu_host_id)); |
1328 | 1330 |
1329 if (CompositorSwapBuffers(params.surface_handle, params.surface_size)) | 1331 if (CompositorSwapBuffers(params.surface_handle, |
| 1332 params.surface_size, |
| 1333 params.surface_scale_factor)) |
1330 AckPendingSwapBuffers(); | 1334 AckPendingSwapBuffers(); |
1331 } | 1335 } |
1332 | 1336 |
1333 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { | 1337 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { |
1334 if (compositing_iosurface_) | 1338 if (compositing_iosurface_) |
1335 compositing_iosurface_->UnrefIOSurface(); | 1339 compositing_iosurface_->UnrefIOSurface(); |
1336 } | 1340 } |
1337 | 1341 |
1338 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() { | 1342 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() { |
1339 compositing_iosurface_.reset(); | 1343 compositing_iosurface_.reset(); |
1340 } | 1344 } |
1341 | 1345 |
1342 bool RenderWidgetHostViewMac::HasAcceleratedSurface( | 1346 bool RenderWidgetHostViewMac::HasAcceleratedSurface( |
1343 const gfx::Size& desired_size) { | 1347 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_ && | 1348 return last_frame_was_accelerated_ && |
1354 compositing_iosurface_.get() && | 1349 compositing_iosurface_.get() && |
1355 compositing_iosurface_->HasIOSurface() && | 1350 compositing_iosurface_->HasIOSurface() && |
1356 (desired_size.IsEmpty() || | 1351 (desired_size.IsEmpty() || |
1357 compositing_iosurface_->io_surface_size() == desired_size); | 1352 compositing_iosurface_->dip_io_surface_size() == desired_size); |
1358 } | 1353 } |
1359 | 1354 |
1360 void RenderWidgetHostViewMac::AboutToWaitForBackingStoreMsg() { | 1355 void RenderWidgetHostViewMac::AboutToWaitForBackingStoreMsg() { |
1361 AckPendingSwapBuffers(); | 1356 AckPendingSwapBuffers(); |
1362 } | 1357 } |
1363 | 1358 |
1364 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { | 1359 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { |
1365 } | 1360 } |
1366 | 1361 |
1367 void RenderWidgetHostViewMac::GetScreenInfo(WebKit::WebScreenInfo* results) { | 1362 void RenderWidgetHostViewMac::GetScreenInfo(WebKit::WebScreenInfo* results) { |
(...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3400 if (!string) return NO; | 3395 if (!string) return NO; |
3401 | 3396 |
3402 // If the user is currently using an IME, confirm the IME input, | 3397 // 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. | 3398 // and then insert the text from the service, the same as TextEdit and Safari. |
3404 [self confirmComposition]; | 3399 [self confirmComposition]; |
3405 [self insertText:string]; | 3400 [self insertText:string]; |
3406 return YES; | 3401 return YES; |
3407 } | 3402 } |
3408 | 3403 |
3409 @end | 3404 @end |
OLD | NEW |