diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 23:45:31 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 23:45:31 +0000 |
commit | 5c6ac767a5a53fda75cb680e657073de8a89e839 (patch) | |
tree | 0f042936a89310b0d0c153899de5726836ea1f9a | |
parent | 43e2256528de1ddc42e0d60587c1f09ffedc9d45 (diff) | |
download | chromium_src-5c6ac767a5a53fda75cb680e657073de8a89e839.zip chromium_src-5c6ac767a5a53fda75cb680e657073de8a89e839.tar.gz chromium_src-5c6ac767a5a53fda75cb680e657073de8a89e839.tar.bz2 |
Switch to using the dummy window for QD plugin drawing
This simplifies things a bit over the old way, and should be a step closer to supporting more QD-based plugins.
Also makes the HandleInputEvent logic a bit clearer.
BUG=none
TEST=QuickTime movies should still play on the Mac. Leaving a page with QuickTime content should not cause a crash.
Review URL: http://codereview.chromium.org/491027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34305 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/plugins/coregraphics_private_symbols_mac.h | 27 | ||||
-rw-r--r-- | webkit/glue/plugins/fake_plugin_window_tracker_mac.cc | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl_mac.mm | 123 | ||||
-rw-r--r-- | webkit/webkit.gyp | 1 |
4 files changed, 72 insertions, 81 deletions
diff --git a/webkit/glue/plugins/coregraphics_private_symbols_mac.h b/webkit/glue/plugins/coregraphics_private_symbols_mac.h new file mode 100644 index 0000000..0342d6f --- /dev/null +++ b/webkit/glue/plugins/coregraphics_private_symbols_mac.h @@ -0,0 +1,27 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_GLUE_PLUGINS_COREGRAPHICS_PRIVATE_SYMBOLS_MAC_H_ +#define WEBKIT_GLUE_PLUGINS_COREGRAPHICS_PRIVATE_SYMBOLS_MAC_H_ + +// These are CoreGraphics SPI, verified to exist in both 10.5 and 10.6. + +#ifdef __cplusplus +extern "C" { +#endif + +// Copies the contents of the window with id |wid| into the given rect in the +// given context +OSStatus CGContextCopyWindowCaptureContentsToRect( + CGContextRef, CGRect, int cid, int wid, int unknown); + +// Returns the connection ID we need for the third argument to +// CGContextCopyWindowCaptureContentsToRect +int _CGSDefaultConnection(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBKIT_GLUE_PLUGINS_COREGRAPHICS_PRIVATE_SYMBOLS_MAC_H_ diff --git a/webkit/glue/plugins/fake_plugin_window_tracker_mac.cc b/webkit/glue/plugins/fake_plugin_window_tracker_mac.cc index 9f809a5..6f7f7ef 100644 --- a/webkit/glue/plugins/fake_plugin_window_tracker_mac.cc +++ b/webkit/glue/plugins/fake_plugin_window_tracker_mac.cc @@ -26,7 +26,7 @@ WindowRef FakePluginWindowTracker::GenerateFakeWindowForDelegate( Rect window_bounds = { 0, 0, 100, 100 }; WindowRef new_ref = NULL; if (CreateNewWindow(kDocumentWindowClass, - kWindowStandardDocumentAttributes, + kWindowNoTitleBarAttribute, &window_bounds, &new_ref) == noErr) { CFDictionaryAddValue(window_to_delegate_map_, new_ref, delegate); diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm index e20b915..fedf29d 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm +++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm @@ -20,6 +20,7 @@ #include "webkit/default_plugin/plugin_impl.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/webplugin.h" +#include "webkit/glue/plugins/coregraphics_private_symbols_mac.h" #include "webkit/glue/plugins/fake_plugin_window_tracker_mac.h" #include "webkit/glue/plugins/plugin_constants_win.h" #include "webkit/glue/plugins/plugin_instance.h" @@ -76,7 +77,6 @@ WebPluginDelegateImpl::WebPluginDelegateImpl( plugin_(NULL), instance_(instance), parent_(containing_view), - qd_world_(0), quirks_(0), null_event_factory_(this), waiting_to_die_(false), @@ -109,21 +109,14 @@ WebPluginDelegateImpl::WebPluginDelegateImpl( WebPluginDelegateImpl::~WebPluginDelegateImpl() { std::set<WebPluginDelegateImpl*>* delegates = g_active_delegates.Pointer(); delegates->erase(this); -#ifndef NP_NO_QUICKDRAW - if (qd_port_.port) { - DisposeGWorld(qd_port_.port); - DisposeGWorld(qd_world_); - } -#endif -} - -void WebPluginDelegateImpl::PluginDestroyed() { FakePluginWindowTracker::SharedInstance()->RemoveFakeWindowForDelegate( this, reinterpret_cast<WindowRef>(cg_context_.window)); +} +void WebPluginDelegateImpl::PluginDestroyed() { if (instance_->event_model() == NPEventModelCarbon) { if (PluginDrawingModel() == NPDrawingModelQuickDraw) { - // Tell the plugin it should stop drawing into the GWorld (which will go + // Tell the plugin it should stop drawing into the window (which will go // away when the next idle event arrives). window_.x = 0; window_.y = 0; @@ -164,6 +157,8 @@ void WebPluginDelegateImpl::PlatformInitialize() { Rect window_bounds = { 0, 0, window_rect_.height(), window_rect_.width() }; SetWindowBounds(reinterpret_cast<WindowRef>(cg_context_.window), kWindowContentRgn, &window_bounds); + qd_port_.port = + GetWindowPort(reinterpret_cast<WindowRef>(cg_context_.window)); switch (PluginDrawingModel()) { #ifndef NP_NO_QUICKDRAW @@ -195,38 +190,12 @@ void WebPluginDelegateImpl::PlatformDestroyInstance() { } void WebPluginDelegateImpl::UpdateContext(CGContextRef context) { - // Flash on the Mac apparently caches the context from the struct it recieves - // in NPP_SetWindow, and continue to use it even when the contents of the + // Flash on the Mac apparently caches the context from the struct it receives + // in NPP_SetWindow, and continues to use it even when the contents of the // struct have changed, so we need to call NPP_SetWindow again if the context // changes. if (context != cg_context_.context) { cg_context_.context = context; -#ifndef NP_NO_QUICKDRAW - if (PluginDrawingModel() == NPDrawingModelQuickDraw) { - if (qd_port_.port) { - DisposeGWorld(qd_port_.port); - DisposeGWorld(qd_world_); - qd_port_.port = NULL; - qd_world_ = NULL; - } - Rect window_bounds = { - 0, 0, window_rect_.height(), window_rect_.width() - }; - // Create a GWorld pointing at the same bits as our CGContextRef - NewGWorldFromPtr(&qd_world_, k32BGRAPixelFormat, &window_bounds, - NULL, NULL, 0, - static_cast<Ptr>(CGBitmapContextGetData(context)), - static_cast<SInt32>(CGBitmapContextGetBytesPerRow(context))); - // Create a GWorld for the plugin to paint into whenever it wants - NewGWorld(&qd_port_.port, k32ARGBPixelFormat, &window_bounds, - NULL, NULL, kNativeEndianPixMap); - SetGWorld(qd_port_.port, NULL); - // Fill with black - ForeColor(blackColor); - BackColor(whiteColor); - PaintRect(&window_bounds); - } -#endif WindowlessSetWindow(true); } } @@ -300,28 +269,19 @@ void WebPluginDelegateImpl::WindowlessPaint(gfx::NativeDrawingContext context, // Plugins using the QuickDraw drawing model do not restrict their // drawing to update events the way that CoreGraphics-based plugins // do. When we are asked to paint, we therefore just copy from the - // plugin's persistent offscreen GWorld into our shared memory bitmap - // context. - Rect window_bounds = { - 0, 0, window_rect_.height(), window_rect_.width() - }; - PixMapHandle plugin_pixmap = GetGWorldPixMap(qd_port_.port); - if (LockPixels(plugin_pixmap)) { - PixMapHandle shared_pixmap = GetGWorldPixMap(qd_world_); - if (LockPixels(shared_pixmap)) { - SetGWorld(qd_world_, NULL); - // Set foreground and background colors to avoid "colorizing" the - // image. - ForeColor(blackColor); - BackColor(whiteColor); - CopyBits(reinterpret_cast<BitMap*>(*plugin_pixmap), - reinterpret_cast<BitMap*>(*shared_pixmap), - &window_bounds, &window_bounds, srcCopy, NULL); - UnlockPixels(shared_pixmap); - } - UnlockPixels(plugin_pixmap); - } - break; + // plugin's hidden window into our shared memory bitmap context. + CGRect window_bounds = CGRectMake(0, 0, + window_rect_.width(), + window_rect_.height()); + CGWindowID window_id = HIWindowGetCGWindowID( + reinterpret_cast<WindowRef>(cg_context_.window)); + CGContextSaveGState(context); + CGContextTranslateCTM(context, 0, window_rect_.height()); + CGContextScaleCTM(context, 1.0, -1.0); + CGContextCopyWindowCaptureContentsToRect(context, window_bounds, + _CGSDefaultConnection(), + window_id, 0); + CGContextRestoreGState(context); } #endif case NPDrawingModelCoreGraphics: { @@ -746,33 +706,36 @@ bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, switch (PluginDrawingModel()) { #ifndef NP_NO_QUICKDRAW case NPDrawingModelQuickDraw: - SetGWorld(qd_port_.port, NULL); - ret = instance()->NPP_HandleEvent(&np_event) != 0; + SetPort(qd_port_.port); break; #endif case NPDrawingModelCoreGraphics: CGContextSaveGState(cg_context_.context); - switch (instance()->event_model()) { + break; + } + + switch (instance()->event_model()) { #ifndef NP_NO_CARBON - case NPEventModelCarbon: - // Send the event to the plugin. - ret = instance()->NPP_HandleEvent(&np_event) != 0; - break; + case NPEventModelCarbon: + // Send the event to the plugin. + ret = instance()->NPP_HandleEvent(&np_event) != 0; + break; #endif - case NPEventModelCocoa: { - NPCocoaEvent np_cocoa_event; - if (!NPCocoaEventFromWebInputEvent(event, &np_cocoa_event)) { - LOG(WARNING) << "NPCocoaEventFromWebInputEvent failed"; - return false; - } - ret = instance()->NPP_HandleEvent( - reinterpret_cast<NPEvent*>(&np_cocoa_event)) != 0; - break; - } + case NPEventModelCocoa: { + NPCocoaEvent np_cocoa_event; + if (!NPCocoaEventFromWebInputEvent(event, &np_cocoa_event)) { + LOG(WARNING) << "NPCocoaEventFromWebInputEvent failed"; + return false; } - CGContextRestoreGState(cg_context_.context); + ret = instance()->NPP_HandleEvent( + reinterpret_cast<NPEvent*>(&np_cocoa_event)) != 0; break; + } } + + if (PluginDrawingModel() == NPDrawingModelCoreGraphics) + CGContextRestoreGState(cg_context_.context); + return ret; } @@ -823,7 +786,7 @@ void WebPluginDelegateImpl::OnNullEvent() { #ifndef NP_NO_QUICKDRAW // Quickdraw-based plugins can draw at any time, so tell the renderer to // repaint. - // TODO: only do this if the contents of the offscreen GWorld has changed, + // TODO: only do this if the contents of the offscreen window has changed, // so as not to spam the renderer with an unchanging image. if (PluginDrawingModel() == NPDrawingModelQuickDraw) instance()->webplugin()->Invalidate(); diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 041aabc..c2bb0b6 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -258,6 +258,7 @@ 'glue/media/simple_data_source.h', 'glue/media/video_renderer_impl.cc', 'glue/media/video_renderer_impl.h', + 'glue/plugins/coregraphics_private_symbols_mac.h', 'glue/plugins/nphostapi.h', 'glue/plugins/fake_plugin_window_tracker_mac.h', 'glue/plugins/fake_plugin_window_tracker_mac.cc', |