diff options
author | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-26 01:32:26 +0000 |
---|---|---|
committer | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-26 01:32:26 +0000 |
commit | c06f3007c6f5f565501d33343de89c229f356e7a (patch) | |
tree | 039f559ceb9514f7e877e4edfcedff7bc9864485 /o3d | |
parent | 96318aa64aee83e9090105000aef785c25df3045 (diff) | |
download | chromium_src-c06f3007c6f5f565501d33343de89c229f356e7a.zip chromium_src-c06f3007c6f5f565501d33343de89c229f356e7a.tar.gz chromium_src-c06f3007c6f5f565501d33343de89c229f356e7a.tar.bz2 |
Refactored drawing and event model selection to generalize to more
browsers.
Tested in the following browsers / operating systems:
Mac OS X 10.5:
- Safari (QuickDraw drawing model)
- Firefox 3.6 (QuickDraw drawing model)
- Firefox 2.0.0.20 (QuickDraw drawing model)
- Modified Chromium TOT (Core Graphics drawing model)
Mac OS X 10.6:
- Safari (Core Animation drawing model)
- Firefox 3.6.3 (QuickDraw drawing model)
- Modified Chromium TOT (Core Animation drawing model)
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2169002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48236 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/plugin/mac/config_mac.mm | 1 | ||||
-rw-r--r-- | o3d/plugin/mac/main_mac.mm | 169 | ||||
-rw-r--r-- | o3d/plugin/mac/plugin_mac.h | 1 | ||||
-rw-r--r-- | o3d/plugin/mac/plugin_mac.mm | 2 |
4 files changed, 72 insertions, 101 deletions
diff --git a/o3d/plugin/mac/config_mac.mm b/o3d/plugin/mac/config_mac.mm index c137df6..c85f8c8 100644 --- a/o3d/plugin/mac/config_mac.mm +++ b/o3d/plugin/mac/config_mac.mm @@ -330,7 +330,6 @@ bool GetUserAgentMetrics(NPP npp) { // The Chrome user_agent string also contains Safari. Search for Chrome first. if (std::string::npos != user_agent.find("Chrome")) { o3d::metric_browser_type = o3d::BROWSER_NAME_CHROME; - gIsChrome = true; // The OmniWeb user_agent also contains Safari. Search for OminWeb first. } else if (std::string::npos != user_agent.find("OmniWeb")) { o3d::metric_browser_type = o3d::BROWSER_NAME_OMNIWEB; diff --git a/o3d/plugin/mac/main_mac.mm b/o3d/plugin/mac/main_mac.mm index 3f38d65..328c84b 100644 --- a/o3d/plugin/mac/main_mac.mm +++ b/o3d/plugin/mac/main_mac.mm @@ -502,28 +502,35 @@ NPError InitializePlugin() { return NPERR_NO_ERROR; } -// When to prefer Core Animation, currently that's only on Safari and 10.6+ -// but that will change as we use this model in more browsers. +// When to prefer Core Animation. Safari's support in 10.5 was too +// buggy to attempt to use. static bool PreferCoreAnimation() { bool isSafari = o3d::metric_browser_type.value() == o3d::BROWSER_NAME_SAFARI; - return (o3d::IsMacOSTenSixOrHigher() && isSafari); + return (!isSafari || o3d::IsMacOSTenSixOrHigher()); } -// Negotiates the best plugin event model, sets the browser to use that, -// and updates the PluginObject so we can remember which one we chose. -// We favor the newer Cocoa-based model, but can cope with browsers that -// only support the original event model, or indeed can't even understand -// what we are asking for. -// However, right at the minute, we shun the Cocoa event model because its -// NPP_SetWindow messages don't contain a WindowRef or NSWindow so we would -// not get enough info to create our AGL context. We'll go back to -// preferring Cocoa once we have worked out how to deal with that. -// Cannot actually fail - -void Mac_SetBestEventModel(NPP instance, PluginObject* obj) { +// Negotiates the best plugin drawing and event model, sets the +// browser to use that, and updates the PluginObject so we can +// remember which one we chose. We prefer these combinations in the +// given order: +// - Core Animation drawing model, Cocoa event model +// - QuickDraw drawing model, Carbon event model +// - Core Graphics drawing model, Cocoa event model +// If the browser doesn't even understand the question, we use the +// QuickDraw drawing model and Carbon event model for best backward +// compatibility. +// +// This ordering provides the best forward-looking behavior while +// still providing compatibility with older browsers. +// +// Returns NPERR_NO_ERROR (0) if successful, otherwise an NPError code. +NPError Mac_SetBestEventAndDrawingModel(NPP instance, PluginObject* obj) { NPError err = NPERR_NO_ERROR; - NPEventModel model_to_use = NPEventModelCarbon; NPBool supportsCocoaEventModel = FALSE; NPBool supportsCarbonEventModel = FALSE; + NPBool supportsCoreGraphics = FALSE; + NPBool supportsQuickDraw = FALSE; + NPBool supportsCoreAnimation = FALSE; // See if browser supports Cocoa event model. err = NPN_GetValue(instance, @@ -543,105 +550,77 @@ void Mac_SetBestEventModel(NPP instance, PluginObject* obj) { err = NPERR_NO_ERROR; } - // Now we've collected our data, the decision phase begins. - - // If we didn't successfully get TRUE for either question, the browser - // just does not know about the new switchable event models, so must only - // support the old Carbon event model. - if (!(supportsCocoaEventModel || supportsCarbonEventModel)) { - supportsCarbonEventModel = TRUE; - obj->event_model_ = NPEventModelCarbon; - } - - - if (PreferCoreAnimation()) { - // If we're building for Core Animation then we prefer the Cocoa event - // model. - model_to_use = - (supportsCocoaEventModel) ? NPEventModelCocoa : NPEventModelCarbon; - NPN_SetValue(instance, NPPVpluginEventModel, - reinterpret_cast<void*>(model_to_use)); - } else { - // Default to Carbon event model, because the new version of the - // Cocoa event model spec does not supply sufficient window - // information in its Cocoa NPP_SetWindow calls for us to bind an - // AGL context to the browser window. - model_to_use = - (supportsCarbonEventModel) ? NPEventModelCarbon : NPEventModelCocoa; - if (o3d::gIsChrome) { - if (supportsCocoaEventModel) { - model_to_use = NPEventModelCocoa; - } - } - } - NPN_SetValue(instance, NPPVpluginEventModel, - reinterpret_cast<void*>(model_to_use)); - - - obj->event_model_ = model_to_use; -} - - -// Negotiates the best plugin drawing model, sets the browser to use that, -// and updates the PluginObject so we can remember which one we chose. -// Returns NPERR_NO_ERROR (0) if successful, otherwise an NPError code. -NPError Mac_SetBestDrawingModel(NPP instance, PluginObject* obj) { - NPError err = NPERR_NO_ERROR; - NPBool supportsCoreGraphics = FALSE; - NPBool supportsQuickDraw = FALSE; - NPBool supportsCoreAnimation = FALSE; - NPDrawingModel drawing_model = NPDrawingModelQuickDraw; - - // test for QuickDraw support + // Test for QuickDraw support. err = NPN_GetValue(instance, NPNVsupportsQuickDrawBool, &supportsQuickDraw); if (err != NPERR_NO_ERROR) supportsQuickDraw = FALSE; - // Test for Core Graphics support + // Test for Core Graphics support. err = NPN_GetValue(instance, NPNVsupportsCoreGraphicsBool, &supportsCoreGraphics); if (err != NPERR_NO_ERROR) supportsCoreGraphics = FALSE; + // Test for Core Animation support. err = NPN_GetValue(instance, NPNVsupportsCoreAnimationBool, &supportsCoreAnimation); if (err != NPERR_NO_ERROR) supportsCoreAnimation = FALSE; - // In order of preference. Preference is now determined by compatibility, - // not by modernity, and so is the opposite of the order I first used. - if (supportsQuickDraw && !(obj->event_model_ == NPEventModelCocoa)) { - drawing_model = NPDrawingModelQuickDraw; - } else if (supportsCoreAnimation && PreferCoreAnimation()) { + // Fix up values for older browsers which don't even understand + // these questions. + if (!supportsCarbonEventModel && !supportsCocoaEventModel) { + supportsCarbonEventModel = TRUE; + } + + if (!supportsQuickDraw && !supportsCoreGraphics && !supportsCoreAnimation) { + // Must be a very old browser such as FF2. Avoid calling + // NPN_SetValue for the event or drawing models at all. + obj->drawing_model_ = NPDrawingModelQuickDraw; + obj->event_model_ = NPEventModelCarbon; + return NPERR_NO_ERROR; + } + + // Now that we have our information, decide on the appropriate combination. + NPDrawingModel drawing_model = NPDrawingModelQuickDraw; + NPEventModel event_model = NPEventModelCarbon; + + if (supportsCoreAnimation && supportsCocoaEventModel && + PreferCoreAnimation()) { drawing_model = NPDrawingModelCoreAnimation; - // In the Chrome browser we currently want to prefer the CoreGraphics - // drawing model, read back the frame buffer into system memory and draw - // the results to the screen using CG. - // - } else if (o3d::gIsChrome && supportsCoreGraphics) { + event_model = NPEventModelCocoa; + DLOG(INFO) << "Core Animation drawing model"; + } else if (supportsQuickDraw && supportsCarbonEventModel) { + drawing_model = NPDrawingModelQuickDraw; + event_model = NPEventModelCarbon; + DLOG(INFO) << "QuickDraw drawing model"; + } else if (supportsCoreGraphics && supportsCocoaEventModel) { drawing_model = NPDrawingModelCoreGraphics; + event_model = NPEventModelCocoa; + DLOG(INFO) << "Core Graphics drawing model"; } else { - if (supportsCoreGraphics) { - drawing_model = NPDrawingModelCoreGraphics; - } else { - // This case is for browsers that didn't even understand the question - // eg FF2, so drawing models are not supported, just assume QuickDraw. - obj->drawing_model_ = NPDrawingModelQuickDraw; - return NPERR_NO_ERROR; - } - } + // If all of the above tests failed, we are running on a browser + // which we don't know how to handle. + return NPERR_GENERIC_ERROR; + } + // Earlier versions of this code did not check the return value of + // the call to set the event model. + NPN_SetValue(instance, NPPVpluginEventModel, + reinterpret_cast<void*>(event_model)); err = NPN_SetValue(instance, NPPVpluginDrawingModel, reinterpret_cast<void*>(drawing_model)); - if (err != NPERR_NO_ERROR) + + if (err != NPERR_NO_ERROR) { return err; + } obj->drawing_model_ = drawing_model; - + obj->event_model_ = event_model; return NPERR_NO_ERROR; } } // end anonymous namespace @@ -960,11 +939,9 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, glue::_o3d::InitializeGlue(instance); pluginObject->Init(argc, argn, argv); - Mac_SetBestEventModel(instance, - static_cast<PluginObject*>(instance->pdata)); - - err = Mac_SetBestDrawingModel( - instance, static_cast<PluginObject*>(instance->pdata)); + err = Mac_SetBestEventAndDrawingModel(instance, + static_cast<PluginObject*>( + instance->pdata)); if (err != NPERR_NO_ERROR) return err; #ifdef CFTIMER @@ -1067,12 +1044,10 @@ NPError NPP_SetWindow(NPP instance, NPWindow* window) { CGLSetCurrentContext(obj->mac_cgl_context_); } } else if (obj->drawing_model_ == NPDrawingModelCoreGraphics && - o3d::gIsChrome && obj->mac_cgl_pbuffer_ == NULL) { - // This code path is only taken for Chrome. We initialize things with a - // CGL context rendering to a 1x1 pbuffer. Later we use the O3D - // RenderSurface APIs to set up the framebuffer object which is used - // for rendering. + // We initialize things with a CGL context rendering to a 1x1 + // pbuffer. Later we use the O3D RenderSurface APIs to set up the + // framebuffer object which is used for rendering. CGLContextObj share_context = obj->GetFullscreenShareContext(); CGLPixelFormatObj pixel_format = obj->GetFullscreenCGLPixelFormatObj(); DCHECK(share_context); diff --git a/o3d/plugin/mac/plugin_mac.h b/o3d/plugin/mac/plugin_mac.h index 8d003ee..2e349cf 100644 --- a/o3d/plugin/mac/plugin_mac.h +++ b/o3d/plugin/mac/plugin_mac.h @@ -70,7 +70,6 @@ class RenderTimer { }; extern RenderTimer gRenderTimer; -extern bool gIsChrome; void InitializeBreakpad(); void ShutdownBreakpad(); diff --git a/o3d/plugin/mac/plugin_mac.mm b/o3d/plugin/mac/plugin_mac.mm index d65ccec..071890b 100644 --- a/o3d/plugin/mac/plugin_mac.mm +++ b/o3d/plugin/mac/plugin_mac.mm @@ -57,8 +57,6 @@ using o3d::DisplayWindowMac; namespace o3d { -bool gIsChrome = false; - // Returns the version number of the running Mac browser, as parsed from // the short version string in the plist of the app's bundle. bool GetBrowserVersionInfo(int *returned_major, |