| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/glue/plugins/webplugin_delegate_impl.h" | 8 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 if (instance()->event_model() != NPEventModelCocoa) | 365 if (instance()->event_model() != NPEventModelCocoa) |
| 366 return false; | 366 return false; |
| 367 window_.type = NPWindowTypeDrawable; | 367 window_.type = NPWindowTypeDrawable; |
| 368 // Ask the plug-in for the CALayer it created for rendering content. Have | 368 // Ask the plug-in for the CALayer it created for rendering content. Have |
| 369 // the renderer tell the browser to create a "windowed plugin" to host | 369 // the renderer tell the browser to create a "windowed plugin" to host |
| 370 // the IOSurface. | 370 // the IOSurface. |
| 371 CALayer* layer = nil; | 371 CALayer* layer = nil; |
| 372 NPError err = instance()->NPP_GetValue(NPPVpluginCoreAnimationLayer, | 372 NPError err = instance()->NPP_GetValue(NPPVpluginCoreAnimationLayer, |
| 373 reinterpret_cast<void*>(&layer)); | 373 reinterpret_cast<void*>(&layer)); |
| 374 if (!err) { | 374 if (!err) { |
| 375 // Create the timer; it will be started when we get a window handle. |
| 376 redraw_timer_.reset(new base::RepeatingTimer<WebPluginDelegateImpl>); |
| 375 layer_ = layer; | 377 layer_ = layer; |
| 376 plugin_->BindFakePluginWindowHandle(false); | |
| 377 surface_ = new AcceleratedSurface; | 378 surface_ = new AcceleratedSurface; |
| 378 surface_->Initialize(NULL, true); | 379 surface_->Initialize(NULL, true); |
| 379 renderer_ = [[CARenderer rendererWithCGLContext:surface_->context() | 380 renderer_ = [[CARenderer rendererWithCGLContext:surface_->context() |
| 380 options:NULL] retain]; | 381 options:NULL] retain]; |
| 381 [renderer_ setLayer:layer_]; | 382 [renderer_ setLayer:layer_]; |
| 382 UpdateAcceleratedSurface(); | 383 plugin_->BindFakePluginWindowHandle(false); |
| 383 redraw_timer_.reset(new base::RepeatingTimer<WebPluginDelegateImpl>); | |
| 384 // This will start the timer, but only if we are visible. | |
| 385 PluginVisibilityChanged(); | |
| 386 } | 384 } |
| 387 break; | 385 break; |
| 388 } | 386 } |
| 389 default: | 387 default: |
| 390 NOTREACHED(); | 388 NOTREACHED(); |
| 391 break; | 389 break; |
| 392 } | 390 } |
| 393 | 391 |
| 394 // TODO(stuartmorgan): We need real plugin container visibility information | 392 // TODO(stuartmorgan): We need real plugin container visibility information |
| 395 // when the plugin is initialized; for now, assume it's visible. | 393 // when the plugin is initialized; for now, assume it's visible. |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 #endif | 970 #endif |
| 973 } | 971 } |
| 974 | 972 |
| 975 void WebPluginDelegateImpl::PluginVisibilityChanged() { | 973 void WebPluginDelegateImpl::PluginVisibilityChanged() { |
| 976 #ifndef NP_NO_CARBON | 974 #ifndef NP_NO_CARBON |
| 977 if (instance()->event_model() == NPEventModelCarbon) | 975 if (instance()->event_model() == NPEventModelCarbon) |
| 978 UpdateIdleEventRate(); | 976 UpdateIdleEventRate(); |
| 979 #endif | 977 #endif |
| 980 if (instance()->drawing_model() == NPDrawingModelCoreAnimation) { | 978 if (instance()->drawing_model() == NPDrawingModelCoreAnimation) { |
| 981 bool plugin_visible = container_is_visible_ && !clip_rect_.IsEmpty(); | 979 bool plugin_visible = container_is_visible_ && !clip_rect_.IsEmpty(); |
| 982 if (plugin_visible && !redraw_timer_->IsRunning()) { | 980 if (plugin_visible && !redraw_timer_->IsRunning() && windowed_handle()) { |
| 983 redraw_timer_->Start( | 981 redraw_timer_->Start( |
| 984 base::TimeDelta::FromMilliseconds(kCoreAnimationRedrawPeriodMs), | 982 base::TimeDelta::FromMilliseconds(kCoreAnimationRedrawPeriodMs), |
| 985 this, &WebPluginDelegateImpl::DrawLayerInSurface); | 983 this, &WebPluginDelegateImpl::DrawLayerInSurface); |
| 986 } else if (!plugin_visible) { | 984 } else if (!plugin_visible) { |
| 987 redraw_timer_->Stop(); | 985 redraw_timer_->Stop(); |
| 988 } | 986 } |
| 989 } | 987 } |
| 990 } | 988 } |
| 991 | 989 |
| 992 #pragma mark - | 990 #pragma mark - |
| 993 #pragma mark Core Animation Support | 991 #pragma mark Core Animation Support |
| 994 | 992 |
| 995 void WebPluginDelegateImpl::DrawLayerInSurface() { | 993 void WebPluginDelegateImpl::DrawLayerInSurface() { |
| 994 // If we haven't plumbed up the surface yet, don't try to draw. |
| 995 if (!windowed_handle()) |
| 996 return; |
| 997 |
| 996 surface_->MakeCurrent(); | 998 surface_->MakeCurrent(); |
| 997 | 999 |
| 998 surface_->Clear(window_rect_); | 1000 surface_->Clear(window_rect_); |
| 999 | 1001 |
| 1000 [renderer_ beginFrameAtTime:CACurrentMediaTime() timeStamp:NULL]; | 1002 [renderer_ beginFrameAtTime:CACurrentMediaTime() timeStamp:NULL]; |
| 1001 CGRect layerRect = [layer_ bounds]; | 1003 CGRect layerRect = [layer_ bounds]; |
| 1002 [renderer_ addUpdateRect:layerRect]; | 1004 [renderer_ addUpdateRect:layerRect]; |
| 1003 [renderer_ render]; | 1005 [renderer_ render]; |
| 1004 [renderer_ endFrame]; | 1006 [renderer_ endFrame]; |
| 1005 | 1007 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1022 | 1024 |
| 1023 uint64 io_surface_id = surface_->SetSurfaceSize(window_rect_.size()); | 1025 uint64 io_surface_id = surface_->SetSurfaceSize(window_rect_.size()); |
| 1024 if (io_surface_id) { | 1026 if (io_surface_id) { |
| 1025 plugin_->SetAcceleratedSurface(windowed_handle(), | 1027 plugin_->SetAcceleratedSurface(windowed_handle(), |
| 1026 window_rect_.width(), | 1028 window_rect_.width(), |
| 1027 window_rect_.height(), | 1029 window_rect_.height(), |
| 1028 io_surface_id); | 1030 io_surface_id); |
| 1029 } | 1031 } |
| 1030 } | 1032 } |
| 1031 | 1033 |
| 1034 void WebPluginDelegateImpl::set_windowed_handle( |
| 1035 gfx::PluginWindowHandle handle) { |
| 1036 windowed_handle_ = handle; |
| 1037 UpdateAcceleratedSurface(); |
| 1038 // Kick off the drawing timer, if necessary. |
| 1039 PluginVisibilityChanged(); |
| 1040 } |
| 1041 |
| 1032 #pragma mark - | 1042 #pragma mark - |
| 1033 #pragma mark Carbon Event support | 1043 #pragma mark Carbon Event support |
| 1034 | 1044 |
| 1035 #ifndef NP_NO_CARBON | 1045 #ifndef NP_NO_CARBON |
| 1036 void WebPluginDelegateImpl::UpdateDummyWindowBounds( | 1046 void WebPluginDelegateImpl::UpdateDummyWindowBounds( |
| 1037 const gfx::Point& plugin_origin) { | 1047 const gfx::Point& plugin_origin) { |
| 1038 WindowRef window = reinterpret_cast<WindowRef>(np_cg_context_.window); | 1048 WindowRef window = reinterpret_cast<WindowRef>(np_cg_context_.window); |
| 1039 Rect current_bounds; | 1049 Rect current_bounds; |
| 1040 GetWindowBounds(window, kWindowContentRgn, ¤t_bounds); | 1050 GetWindowBounds(window, kWindowContentRgn, ¤t_bounds); |
| 1041 | 1051 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 return; | 1145 return; |
| 1136 } | 1146 } |
| 1137 | 1147 |
| 1138 qd_manager_->SetFastPathEnabled(enabled); | 1148 qd_manager_->SetFastPathEnabled(enabled); |
| 1139 qd_port_.port = qd_manager_->port(); | 1149 qd_port_.port = qd_manager_->port(); |
| 1140 WindowlessSetWindow(); | 1150 WindowlessSetWindow(); |
| 1141 // Send a paint event so that the new buffer gets updated immediately. | 1151 // Send a paint event so that the new buffer gets updated immediately. |
| 1142 WindowlessPaint(buffer_context_, clip_rect_); | 1152 WindowlessPaint(buffer_context_, clip_rect_); |
| 1143 } | 1153 } |
| 1144 #endif // !NP_NO_QUICKDRAW | 1154 #endif // !NP_NO_QUICKDRAW |
| OLD | NEW |