Bug 651192 - Part 4: Allow setting different drawing models across all platforms. r=roc

This commit is contained in:
Bas Schouten 2012-02-16 04:24:38 +01:00
parent d0ff82a582
commit 252cced9e6
13 changed files with 79 additions and 28 deletions

View File

@ -2528,7 +2528,8 @@ _setvalue(NPP npp, NPPVariable variable, void *result)
return inst->SetUsesDOMForCursor(useDOMForCursor); return inst->SetUsesDOMForCursor(useDOMForCursor);
} }
#ifdef XP_MACOSX #ifndef MOZ_WIDGET_ANDROID
// On android, their 'drawing model' uses the same constant!
case NPPVpluginDrawingModel: { case NPPVpluginDrawingModel: {
if (inst) { if (inst) {
inst->SetDrawingModel((NPDrawingModel)NS_PTR_TO_INT32(result)); inst->SetDrawingModel((NPDrawingModel)NS_PTR_TO_INT32(result));
@ -2538,7 +2539,9 @@ _setvalue(NPP npp, NPPVariable variable, void *result)
return NPERR_GENERIC_ERROR; return NPERR_GENERIC_ERROR;
} }
} }
#endif
#ifdef XP_MACOSX
case NPPVpluginEventModel: { case NPPVpluginEventModel: {
if (inst) { if (inst) {
inst->SetEventModel((NPEventModel)NS_PTR_TO_INT32(result)); inst->SetEventModel((NPEventModel)NS_PTR_TO_INT32(result));

View File

@ -80,13 +80,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS0(nsNPAPIPluginInstance)
nsNPAPIPluginInstance::nsNPAPIPluginInstance(nsNPAPIPlugin* plugin) nsNPAPIPluginInstance::nsNPAPIPluginInstance(nsNPAPIPlugin* plugin)
: :
#ifdef XP_MACOSX mDrawingModel(kDefaultDrawingModel),
#ifdef NP_NO_QUICKDRAW
mDrawingModel(NPDrawingModelCoreGraphics),
#else
mDrawingModel(NPDrawingModelQuickDraw),
#endif
#endif
#ifdef MOZ_WIDGET_ANDROID #ifdef MOZ_WIDGET_ANDROID
mSurface(nsnull), mSurface(nsnull),
mANPDrawingModel(0), mANPDrawingModel(0),
@ -704,12 +698,12 @@ nsNPAPIPluginInstance::UsesDOMForCursor()
return mUsesDOMForCursor; return mUsesDOMForCursor;
} }
#if defined(XP_MACOSX)
void nsNPAPIPluginInstance::SetDrawingModel(NPDrawingModel aModel) void nsNPAPIPluginInstance::SetDrawingModel(NPDrawingModel aModel)
{ {
mDrawingModel = aModel; mDrawingModel = aModel;
} }
#if defined(XP_MACOSX)
void nsNPAPIPluginInstance::SetEventModel(NPEventModel aModel) void nsNPAPIPluginInstance::SetEventModel(NPEventModel aModel)
{ {
// the event model needs to be set for the object frame immediately // the event model needs to be set for the object frame immediately

View File

@ -64,6 +64,18 @@ class nsIPluginInstanceOwner;
class nsIPluginStreamListener; class nsIPluginStreamListener;
class nsIOutputStream; class nsIOutputStream;
#if defined(OS_WIN)
const NPDrawingModel kDefaultDrawingModel = NPDrawingModelSyncWin;
#elif defined(MOZ_X11)
const NPDrawingModel kDefaultDrawingModel = NPDrawingModelSyncX;
#else
#ifndef NP_NO_QUICKDRAW
const NPDrawingModel kDefaultDrawingModel = NPDrawingModelQuickDraw;
#else
const NPDrawingModel kDefaultDrawingModel = NPDrawingModelCoreGraphics;
#endif
#endif
class nsNPAPITimer class nsNPAPITimer
{ {
public: public:
@ -141,8 +153,8 @@ public:
NPError SetUsesDOMForCursor(bool aUsesDOMForCursor); NPError SetUsesDOMForCursor(bool aUsesDOMForCursor);
bool UsesDOMForCursor(); bool UsesDOMForCursor();
#ifdef XP_MACOSX
void SetDrawingModel(NPDrawingModel aModel); void SetDrawingModel(NPDrawingModel aModel);
#ifdef XP_MACOSX
void SetEventModel(NPEventModel aModel); void SetEventModel(NPEventModel aModel);
#endif #endif
@ -237,9 +249,7 @@ protected:
// the browser. // the browser.
NPP_t mNPP; NPP_t mNPP;
#ifdef XP_MACOSX
NPDrawingModel mDrawingModel; NPDrawingModel mDrawingModel;
#endif
#ifdef MOZ_WIDGET_ANDROID #ifdef MOZ_WIDGET_ANDROID
PRUint32 mANPDrawingModel; PRUint32 mANPDrawingModel;

View File

@ -87,7 +87,7 @@ child:
rpc NP_GetEntryPoints() rpc NP_GetEntryPoints()
returns (NPError rv); returns (NPError rv);
rpc NP_Initialize() rpc NP_Initialize(uint32_t aFlags)
returns (NPError rv); returns (NPError rv);
rpc PPluginInstance(nsCString aMimeType, rpc PPluginInstance(nsCString aMimeType,

View File

@ -54,6 +54,7 @@
#include "PluginProcessChild.h" #include "PluginProcessChild.h"
#include "gfxASurface.h" #include "gfxASurface.h"
#include "gfxContext.h" #include "gfxContext.h"
#include "nsNPAPIPluginInstance.h"
#ifdef MOZ_X11 #ifdef MOZ_X11
#include "gfxXlibSurface.h" #include "gfxXlibSurface.h"
#endif #endif
@ -131,6 +132,7 @@ struct RunnableMethodTraits<PluginInstanceChild>
PluginInstanceChild::PluginInstanceChild(const NPPluginFuncs* aPluginIface) PluginInstanceChild::PluginInstanceChild(const NPPluginFuncs* aPluginIface)
: mPluginIface(aPluginIface) : mPluginIface(aPluginIface)
, mDrawingModel(kDefaultDrawingModel)
, mCachedWindowActor(nsnull) , mCachedWindowActor(nsnull)
, mCachedElementActor(nsnull) , mCachedElementActor(nsnull)
#if defined(OS_WIN) #if defined(OS_WIN)
@ -149,7 +151,6 @@ PluginInstanceChild::PluginInstanceChild(const NPPluginFuncs* aPluginIface)
#endif #endif
, mShColorSpace(nsnull) , mShColorSpace(nsnull)
, mShContext(nsnull) , mShContext(nsnull)
, mDrawingModel(NPDrawingModelCoreGraphics)
, mCGLayer(nsnull) , mCGLayer(nsnull)
, mCurrentEvent(nsnull) , mCurrentEvent(nsnull)
#endif #endif
@ -414,6 +415,16 @@ PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
#endif #endif
} }
case NPNVsupportsAsyncBitmapSurfaceBool: {
#ifdef XP_WIN
*((NPBool*)aValue) = PluginModuleChild::current()->AsyncDrawingAllowed();
#else
// We do not support non-windows yet.
*((NPBool*)aValue) = false;
#endif
return NPERR_NO_ERROR;
}
#ifdef XP_MACOSX #ifdef XP_MACOSX
case NPNVsupportsCoreGraphicsBool: { case NPNVsupportsCoreGraphicsBool: {
*((NPBool*)aValue) = true; *((NPBool*)aValue) = true;
@ -519,18 +530,27 @@ PluginInstanceChild::NPN_SetValue(NPPVariable aVar, void* aValue)
return rv; return rv;
} }
#ifdef XP_MACOSX
case NPPVpluginDrawingModel: { case NPPVpluginDrawingModel: {
NPError rv; NPError rv;
int drawingModel = (int16) (intptr_t) aValue; int drawingModel = (int16) (intptr_t) aValue;
if (!PluginModuleChild::current()->AsyncDrawingAllowed()) {
if (drawingModel == NPDrawingModelAsyncBitmapSurface ||
drawingModel == NPDrawingModelAsyncWindowsDXGISurface ||
drawingModel == NPDrawingModelAsyncWindowsDX9ExSurface) {
return NPERR_GENERIC_ERROR;
}
}
if (!CallNPN_SetValue_NPPVpluginDrawingModel(drawingModel, &rv)) if (!CallNPN_SetValue_NPPVpluginDrawingModel(drawingModel, &rv))
return NPERR_GENERIC_ERROR; return NPERR_GENERIC_ERROR;
mDrawingModel = drawingModel; mDrawingModel = drawingModel;
#ifdef XP_MACOSX
if (drawingModel == NPDrawingModelCoreAnimation) { if (drawingModel == NPDrawingModelCoreAnimation) {
mCARefreshTimer = ScheduleTimer(DEFAULT_REFRESH_MS, true, CAUpdate); mCARefreshTimer = ScheduleTimer(DEFAULT_REFRESH_MS, true, CAUpdate);
} }
#endif
PLUGIN_LOG_DEBUG((" Plugin requested drawing model id #%i\n", PLUGIN_LOG_DEBUG((" Plugin requested drawing model id #%i\n",
mDrawingModel)); mDrawingModel));
@ -538,6 +558,7 @@ PluginInstanceChild::NPN_SetValue(NPPVariable aVar, void* aValue)
return rv; return rv;
} }
#ifdef XP_MACOSX
case NPPVpluginEventModel: { case NPPVpluginEventModel: {
NPError rv; NPError rv;
int eventModel = (int16) (intptr_t) aValue; int eventModel = (int16) (intptr_t) aValue;

View File

@ -364,6 +364,7 @@ private:
const NPPluginFuncs* mPluginIface; const NPPluginFuncs* mPluginIface;
NPP_t mData; NPP_t mData;
NPWindow mWindow; NPWindow mWindow;
int16_t mDrawingModel;
// Cached scriptable actors to avoid IPC churn // Cached scriptable actors to avoid IPC churn
PluginScriptableObjectChild* mCachedWindowActor; PluginScriptableObjectChild* mCachedWindowActor;
@ -426,7 +427,6 @@ private:
#endif #endif
CGColorSpaceRef mShColorSpace; CGColorSpaceRef mShColorSpace;
CGContextRef mShContext; CGContextRef mShContext;
int16_t mDrawingModel;
nsCARenderer mCARenderer; nsCARenderer mCARenderer;
void *mCGLayer; void *mCGLayer;

View File

@ -50,6 +50,7 @@
#include "gfxContext.h" #include "gfxContext.h"
#include "gfxPlatform.h" #include "gfxPlatform.h"
#include "gfxSharedImageSurface.h" #include "gfxSharedImageSurface.h"
#include "nsNPAPIPluginInstance.h"
#ifdef MOZ_X11 #ifdef MOZ_X11
#include "gfxXlibSurface.h" #include "gfxXlibSurface.h"
#endif #endif
@ -91,6 +92,7 @@ PluginInstanceParent::PluginInstanceParent(PluginModuleParent* parent,
, mNPP(npp) , mNPP(npp)
, mNPNIface(npniface) , mNPNIface(npniface)
, mWindowType(NPWindowTypeWindow) , mWindowType(NPWindowTypeWindow)
, mDrawingModel(kDefaultDrawingModel)
#if defined(OS_WIN) #if defined(OS_WIN)
, mPluginHWND(NULL) , mPluginHWND(NULL)
, mPluginWndProc(NULL) , mPluginWndProc(NULL)
@ -100,7 +102,6 @@ PluginInstanceParent::PluginInstanceParent(PluginModuleParent* parent,
, mShWidth(0) , mShWidth(0)
, mShHeight(0) , mShHeight(0)
, mShColorSpace(nsnull) , mShColorSpace(nsnull)
, mDrawingModel(NPDrawingModelCoreGraphics)
#endif #endif
{ {
} }
@ -362,16 +363,18 @@ PluginInstanceParent::AnswerNPN_SetValue_NPPVpluginDrawingModel(
mDrawingModel = drawingModel; mDrawingModel = drawingModel;
*result = mNPNIface->setvalue(mNPP, NPPVpluginDrawingModel, *result = mNPNIface->setvalue(mNPP, NPPVpluginDrawingModel,
(void*)NPDrawingModelCoreGraphics); (void*)NPDrawingModelCoreGraphics);
} else { } else
#endif
{
if (!GetImageContainer()) {
return false;
}
mDrawingModel = drawingModel; mDrawingModel = drawingModel;
*result = mNPNIface->setvalue(mNPP, NPPVpluginDrawingModel, *result = mNPNIface->setvalue(mNPP, NPPVpluginDrawingModel,
(void*)drawingModel); (void*)drawingModel);
} }
return true; return true;
#else
*result = NPERR_GENERIC_ERROR;
return true;
#endif
} }
bool bool

View File

@ -321,6 +321,7 @@ private:
NPP mNPP; NPP mNPP;
const NPNetscapeFuncs* mNPNIface; const NPNetscapeFuncs* mNPNIface;
NPWindowType mWindowType; NPWindowType mWindowType;
int16_t mDrawingModel;
nsDataHashtable<nsVoidPtrHashKey, PluginScriptableObjectParent*> mScriptableObjects; nsDataHashtable<nsVoidPtrHashKey, PluginScriptableObjectParent*> mScriptableObjects;
@ -351,7 +352,6 @@ private:
uint16_t mShWidth; uint16_t mShWidth;
uint16_t mShHeight; uint16_t mShHeight;
CGColorSpaceRef mShColorSpace; CGColorSpaceRef mShColorSpace;
int16_t mDrawingModel;
nsRefPtr<nsIOSurface> mIOSurface; nsRefPtr<nsIOSurface> mIOSurface;
nsRefPtr<nsIOSurface> mFrontIOSurface; nsRefPtr<nsIOSurface> mFrontIOSurface;
#endif // definied(MOZ_WIDGET_COCOA) #endif // definied(MOZ_WIDGET_COCOA)

View File

@ -86,6 +86,8 @@ UnmungePluginDsoPath(const std::string& munged);
extern PRLogModuleInfo* gPluginLog; extern PRLogModuleInfo* gPluginLog;
const uint32_t kAllowAsyncDrawing = 0x1;
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define FULLFUNCTION __FUNCSIG__ #define FULLFUNCTION __FUNCSIG__
#elif (__GNUC__ >= 4) #elif (__GNUC__ >= 4)

View File

@ -1832,11 +1832,13 @@ PluginModuleChild::AnswerNP_GetEntryPoints(NPError* _retval)
} }
bool bool
PluginModuleChild::AnswerNP_Initialize(NPError* _retval) PluginModuleChild::AnswerNP_Initialize(const uint32_t& aFlags, NPError* _retval)
{ {
PLUGIN_LOG_DEBUG_METHOD; PLUGIN_LOG_DEBUG_METHOD;
AssertPluginThread(); AssertPluginThread();
mAsyncDrawingAllowed = aFlags & kAllowAsyncDrawing;
#ifdef OS_WIN #ifdef OS_WIN
SetEventHooks(); SetEventHooks();
#endif #endif

View File

@ -123,7 +123,7 @@ protected:
// Implement the PPluginModuleChild interface // Implement the PPluginModuleChild interface
virtual bool AnswerNP_GetEntryPoints(NPError* rv); virtual bool AnswerNP_GetEntryPoints(NPError* rv);
virtual bool AnswerNP_Initialize(NPError* rv); virtual bool AnswerNP_Initialize(const uint32_t& aFlags, NPError* rv);
virtual PPluginIdentifierChild* virtual PPluginIdentifierChild*
AllocPPluginIdentifier(const nsCString& aString, AllocPPluginIdentifier(const nsCString& aString,
@ -228,6 +228,8 @@ public:
bool NPObjectIsRegistered(NPObject* aObject); bool NPObjectIsRegistered(NPObject* aObject);
#endif #endif
bool AsyncDrawingAllowed() { return mAsyncDrawingAllowed; }
/** /**
* The child implementation of NPN_CreateObject. * The child implementation of NPN_CreateObject.
*/ */
@ -357,6 +359,7 @@ private:
nsCString mPluginFilename; // UTF8 nsCString mPluginFilename; // UTF8
nsCString mUserAgent; nsCString mUserAgent;
int mQuirks; int mQuirks;
bool mAsyncDrawingAllowed;
// we get this from the plugin // we get this from the plugin
NP_PLUGINSHUTDOWN mShutdownFunc; NP_PLUGINSHUTDOWN mShutdownFunc;

View File

@ -749,7 +749,12 @@ PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
if (!CallNP_Initialize(error)) { uint32_t flags = 0;
if (mozilla::Preferences::GetBool("plugin.allow.asyncdrawing", false)) {
flags |= kAllowAsyncDrawing;
}
if (!CallNP_Initialize(flags, error)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
else if (*error != NPERR_NO_ERROR) { else if (*error != NPERR_NO_ERROR) {
@ -773,7 +778,12 @@ PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
if (!CallNP_Initialize(error)) uint32_t flags = 0;
if (mozilla::Preferences::GetBool("plugin.allow.asyncdrawing", false)) {
flags |= kAllowAsyncDrawing;
}
if (!CallNP_Initialize(flags, error))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
#if defined XP_WIN #if defined XP_WIN

View File

@ -2020,6 +2020,9 @@ pref("plugin.scan.WindowsMediaPlayer", "7.0");
// Which is currently HKLM\Software\MozillaPlugins\xxxPLIDxxx\Path // Which is currently HKLM\Software\MozillaPlugins\xxxPLIDxxx\Path
pref("plugin.scan.plid.all", true); pref("plugin.scan.plid.all", true);
// Allow the new AsyncDrawing mode to be used for plugins.
pref("plugin.allow.asyncdrawing", false);
// Help Windows NT, 2000, and XP dialup a RAS connection // Help Windows NT, 2000, and XP dialup a RAS connection
// when a network address is unreachable. // when a network address is unreachable.
pref("network.autodial-helper.enabled", true); pref("network.autodial-helper.enabled", true);