| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #import <QuartzCore/QuartzCore.h> | 6 #import <QuartzCore/QuartzCore.h> |
| 7 | 7 |
| 8 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" | 8 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // all Mac plugins are "windowless" in the Windows/X11 sense | 260 // all Mac plugins are "windowless" in the Windows/X11 sense |
| 261 windowless_(true), | 261 windowless_(true), |
| 262 plugin_(NULL), | 262 plugin_(NULL), |
| 263 instance_(instance), | 263 instance_(instance), |
| 264 parent_(containing_view), | 264 parent_(containing_view), |
| 265 quirks_(0), | 265 quirks_(0), |
| 266 use_buffer_context_(true), | 266 use_buffer_context_(true), |
| 267 buffer_context_(NULL), | 267 buffer_context_(NULL), |
| 268 layer_(nil), | 268 layer_(nil), |
| 269 surface_(NULL), | 269 surface_(NULL), |
| 270 composited_(false), |
| 270 renderer_(nil), | 271 renderer_(nil), |
| 271 containing_window_has_focus_(false), | 272 containing_window_has_focus_(false), |
| 272 initial_window_focus_(false), | 273 initial_window_focus_(false), |
| 273 container_is_visible_(false), | 274 container_is_visible_(false), |
| 274 have_called_set_window_(false), | 275 have_called_set_window_(false), |
| 275 ime_enabled_(false), | 276 ime_enabled_(false), |
| 276 keyup_ignore_count_(0), | 277 keyup_ignore_count_(0), |
| 277 external_drag_tracker_(new ExternalDragTracker()), | 278 external_drag_tracker_(new ExternalDragTracker()), |
| 278 handle_event_depth_(0), | 279 handle_event_depth_(0), |
| 279 first_set_window_call_(true), | 280 first_set_window_call_(true), |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 const WebPluginInfo& plugin_info = | 396 const WebPluginInfo& plugin_info = |
| 396 instance_->plugin_lib()->plugin_info(); | 397 instance_->plugin_lib()->plugin_info(); |
| 397 if (plugin_info.name.find(ASCIIToUTF16("Flash")) != string16::npos) | 398 if (plugin_info.name.find(ASCIIToUTF16("Flash")) != string16::npos) |
| 398 gpu_preference = gfx::PreferIntegratedGpu; | 399 gpu_preference = gfx::PreferIntegratedGpu; |
| 399 surface_ = plugin_->GetAcceleratedSurface(gpu_preference); | 400 surface_ = plugin_->GetAcceleratedSurface(gpu_preference); |
| 400 | 401 |
| 401 // If surface initialization fails for some reason, just continue | 402 // If surface initialization fails for some reason, just continue |
| 402 // without any drawing; returning false would be a more confusing user | 403 // without any drawing; returning false would be a more confusing user |
| 403 // experience (since it triggers a missing plugin placeholder). | 404 // experience (since it triggers a missing plugin placeholder). |
| 404 if (surface_ && surface_->context()) { | 405 if (surface_ && surface_->context()) { |
| 406 composited_ = surface_->IsComposited(); |
| 405 renderer_ = [[CARenderer rendererWithCGLContext:surface_->context() | 407 renderer_ = [[CARenderer rendererWithCGLContext:surface_->context() |
| 406 options:NULL] retain]; | 408 options:NULL] retain]; |
| 407 [renderer_ setLayer:layer_]; | 409 [renderer_ setLayer:layer_]; |
| 408 } | 410 } |
| 409 plugin_->BindFakePluginWindowHandle(false); | 411 if (composited_) { |
| 412 plugin_->AcceleratedPluginEnabledRendering(); |
| 413 } else { |
| 414 plugin_->BindFakePluginWindowHandle(false); |
| 415 } |
| 410 } | 416 } |
| 411 break; | 417 break; |
| 412 } | 418 } |
| 413 default: | 419 default: |
| 414 NOTREACHED(); | 420 NOTREACHED(); |
| 415 break; | 421 break; |
| 416 } | 422 } |
| 417 | 423 |
| 418 // Let the WebPlugin know that we are windowless (unless this is a | 424 // Let the WebPlugin know that we are windowless, unless this is a Core |
| 419 // Core Animation plugin, in which case BindFakePluginWindowHandle will take | 425 // Animation plugin, in which case AcceleratedPluginEnabledRendering |
| 420 // care of setting up the appropriate window handle). | 426 // calls SetWindow. Rendering breaks if SetWindow is called before |
| 427 // accelerated rendering is enabled. |
| 421 if (!layer_) | 428 if (!layer_) |
| 422 plugin_->SetWindow(NULL); | 429 plugin_->SetWindow(NULL); |
| 423 | 430 |
| 424 #ifndef NP_NO_CARBON | 431 #ifndef NP_NO_CARBON |
| 425 // If the plugin wants Carbon events, hook up to the source of idle events. | 432 // If the plugin wants Carbon events, hook up to the source of idle events. |
| 426 if (instance()->event_model() == NPEventModelCarbon) | 433 if (instance()->event_model() == NPEventModelCarbon) |
| 427 UpdateIdleEventRate(); | 434 UpdateIdleEventRate(); |
| 428 #endif | 435 #endif |
| 429 | 436 |
| 430 // QuickTime (in QD mode only) can crash if it gets other calls (e.g., | 437 // QuickTime (in QD mode only) can crash if it gets other calls (e.g., |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 #endif | 1035 #endif |
| 1029 } | 1036 } |
| 1030 | 1037 |
| 1031 void WebPluginDelegateImpl::PluginVisibilityChanged() { | 1038 void WebPluginDelegateImpl::PluginVisibilityChanged() { |
| 1032 #ifndef NP_NO_CARBON | 1039 #ifndef NP_NO_CARBON |
| 1033 if (instance()->event_model() == NPEventModelCarbon) | 1040 if (instance()->event_model() == NPEventModelCarbon) |
| 1034 UpdateIdleEventRate(); | 1041 UpdateIdleEventRate(); |
| 1035 #endif | 1042 #endif |
| 1036 if (instance()->drawing_model() == NPDrawingModelCoreAnimation) { | 1043 if (instance()->drawing_model() == NPDrawingModelCoreAnimation) { |
| 1037 bool plugin_visible = container_is_visible_ && !clip_rect_.IsEmpty(); | 1044 bool plugin_visible = container_is_visible_ && !clip_rect_.IsEmpty(); |
| 1038 if (plugin_visible && !redraw_timer_->IsRunning() && windowed_handle()) { | 1045 if (plugin_visible && !redraw_timer_->IsRunning() && |
| 1046 (composited_ || windowed_handle())) { |
| 1039 redraw_timer_->Start(FROM_HERE, | 1047 redraw_timer_->Start(FROM_HERE, |
| 1040 base::TimeDelta::FromMilliseconds(kCoreAnimationRedrawPeriodMs), | 1048 base::TimeDelta::FromMilliseconds(kCoreAnimationRedrawPeriodMs), |
| 1041 this, &WebPluginDelegateImpl::DrawLayerInSurface); | 1049 this, &WebPluginDelegateImpl::DrawLayerInSurface); |
| 1042 } else if (!plugin_visible) { | 1050 } else if (!plugin_visible) { |
| 1043 redraw_timer_->Stop(); | 1051 redraw_timer_->Stop(); |
| 1044 } | 1052 } |
| 1045 } | 1053 } |
| 1046 } | 1054 } |
| 1047 | 1055 |
| 1048 void WebPluginDelegateImpl::StartIme() { | 1056 void WebPluginDelegateImpl::StartIme() { |
| 1049 // Currently the plugin IME implementation only works on 10.6. | 1057 // Currently the plugin IME implementation only works on 10.6. |
| 1050 if (instance()->event_model() != NPEventModelCocoa || | 1058 if (instance()->event_model() != NPEventModelCocoa || |
| 1051 base::mac::IsOSLeopardOrEarlier()) { | 1059 base::mac::IsOSLeopardOrEarlier()) { |
| 1052 return; | 1060 return; |
| 1053 } | 1061 } |
| 1054 if (ime_enabled_) | 1062 if (ime_enabled_) |
| 1055 return; | 1063 return; |
| 1056 ime_enabled_ = true; | 1064 ime_enabled_ = true; |
| 1057 plugin_->StartIme(); | 1065 plugin_->StartIme(); |
| 1058 } | 1066 } |
| 1059 | 1067 |
| 1060 #pragma mark - | 1068 #pragma mark - |
| 1061 #pragma mark Core Animation Support | 1069 #pragma mark Core Animation Support |
| 1062 | 1070 |
| 1063 void WebPluginDelegateImpl::DrawLayerInSurface() { | 1071 void WebPluginDelegateImpl::DrawLayerInSurface() { |
| 1064 // If we haven't plumbed up the surface yet, don't try to draw. | 1072 // If we haven't plumbed up the surface yet, don't try to draw. |
| 1065 if (!windowed_handle() || !renderer_) | 1073 if (!renderer_) |
| 1074 return; |
| 1075 |
| 1076 if (!composited_ && !windowed_handle()) |
| 1066 return; | 1077 return; |
| 1067 | 1078 |
| 1068 [renderer_ beginFrameAtTime:CACurrentMediaTime() timeStamp:NULL]; | 1079 [renderer_ beginFrameAtTime:CACurrentMediaTime() timeStamp:NULL]; |
| 1069 if (CGRectIsEmpty([renderer_ updateBounds])) { | 1080 if (CGRectIsEmpty([renderer_ updateBounds])) { |
| 1070 // If nothing has changed, we are done. | 1081 // If nothing has changed, we are done. |
| 1071 [renderer_ endFrame]; | 1082 [renderer_ endFrame]; |
| 1072 return; | 1083 return; |
| 1073 } | 1084 } |
| 1074 | 1085 |
| 1075 surface_->StartDrawing(); | 1086 surface_->StartDrawing(); |
| 1076 | 1087 |
| 1077 CGRect layerRect = [layer_ bounds]; | 1088 CGRect layerRect = [layer_ bounds]; |
| 1078 [renderer_ addUpdateRect:layerRect]; | 1089 [renderer_ addUpdateRect:layerRect]; |
| 1079 [renderer_ render]; | 1090 [renderer_ render]; |
| 1080 [renderer_ endFrame]; | 1091 [renderer_ endFrame]; |
| 1081 | 1092 |
| 1082 surface_->EndDrawing(); | 1093 surface_->EndDrawing(); |
| 1083 } | 1094 } |
| 1084 | 1095 |
| 1085 // Update the size of the surface to match the current size of the plug-in. | 1096 // Update the size of the surface to match the current size of the plug-in. |
| 1086 void WebPluginDelegateImpl::UpdateAcceleratedSurface() { | 1097 void WebPluginDelegateImpl::UpdateAcceleratedSurface() { |
| 1087 // Will only have a window handle when using a Core Animation drawing model. | 1098 if (!surface_ || !layer_) |
| 1088 if (!windowed_handle() || !layer_) | 1099 return; |
| 1100 |
| 1101 if (!composited_ && !windowed_handle()) |
| 1089 return; | 1102 return; |
| 1090 | 1103 |
| 1091 [CATransaction begin]; | 1104 [CATransaction begin]; |
| 1092 [CATransaction setValue:[NSNumber numberWithInt:0] | 1105 [CATransaction setValue:[NSNumber numberWithInt:0] |
| 1093 forKey:kCATransactionAnimationDuration]; | 1106 forKey:kCATransactionAnimationDuration]; |
| 1094 [layer_ setFrame:CGRectMake(0, 0, | 1107 [layer_ setFrame:CGRectMake(0, 0, |
| 1095 window_rect_.width(), window_rect_.height())]; | 1108 window_rect_.width(), window_rect_.height())]; |
| 1096 [CATransaction commit]; | 1109 [CATransaction commit]; |
| 1097 | 1110 |
| 1098 [renderer_ setBounds:[layer_ bounds]]; | 1111 [renderer_ setBounds:[layer_ bounds]]; |
| 1099 surface_->SetSize(window_rect_.size()); | 1112 surface_->SetSize(window_rect_.size()); |
| 1113 if (composited_) { |
| 1114 // Kick off the drawing timer, if necessary. |
| 1115 PluginVisibilityChanged(); |
| 1116 } |
| 1100 } | 1117 } |
| 1101 | 1118 |
| 1102 void WebPluginDelegateImpl::set_windowed_handle( | 1119 void WebPluginDelegateImpl::set_windowed_handle( |
| 1103 gfx::PluginWindowHandle handle) { | 1120 gfx::PluginWindowHandle handle) { |
| 1121 DCHECK(!composited_); |
| 1104 windowed_handle_ = handle; | 1122 windowed_handle_ = handle; |
| 1105 surface_->SetWindowHandle(handle); | 1123 surface_->SetWindowHandle(handle); |
| 1106 UpdateAcceleratedSurface(); | 1124 UpdateAcceleratedSurface(); |
| 1107 // Kick off the drawing timer, if necessary. | 1125 // Kick off the drawing timer, if necessary. |
| 1108 PluginVisibilityChanged(); | 1126 PluginVisibilityChanged(); |
| 1109 } | 1127 } |
| 1110 | 1128 |
| 1111 #pragma mark - | 1129 #pragma mark - |
| 1112 #pragma mark Carbon Event support | 1130 #pragma mark Carbon Event support |
| 1113 | 1131 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 qd_manager_->SetFastPathEnabled(enabled); | 1239 qd_manager_->SetFastPathEnabled(enabled); |
| 1222 qd_port_.port = qd_manager_->port(); | 1240 qd_port_.port = qd_manager_->port(); |
| 1223 WindowlessSetWindow(); | 1241 WindowlessSetWindow(); |
| 1224 // Send a paint event so that the new buffer gets updated immediately. | 1242 // Send a paint event so that the new buffer gets updated immediately. |
| 1225 WindowlessPaint(buffer_context_, clip_rect_); | 1243 WindowlessPaint(buffer_context_, clip_rect_); |
| 1226 } | 1244 } |
| 1227 #endif // !NP_NO_QUICKDRAW | 1245 #endif // !NP_NO_QUICKDRAW |
| 1228 | 1246 |
| 1229 } // namespace npapi | 1247 } // namespace npapi |
| 1230 } // namespace webkit | 1248 } // namespace webkit |
| OLD | NEW |