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

View File

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

View File

@ -64,6 +64,18 @@ class nsIPluginInstanceOwner;
class nsIPluginStreamListener;
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
{
public:
@ -141,8 +153,8 @@ public:
NPError SetUsesDOMForCursor(bool aUsesDOMForCursor);
bool UsesDOMForCursor();
#ifdef XP_MACOSX
void SetDrawingModel(NPDrawingModel aModel);
#ifdef XP_MACOSX
void SetEventModel(NPEventModel aModel);
#endif
@ -237,9 +249,7 @@ protected:
// the browser.
NPP_t mNPP;
#ifdef XP_MACOSX
NPDrawingModel mDrawingModel;
#endif
#ifdef MOZ_WIDGET_ANDROID
PRUint32 mANPDrawingModel;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -749,7 +749,12 @@ PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs
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;
}
else if (*error != NPERR_NO_ERROR) {
@ -773,7 +778,12 @@ PluginModuleParent::NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error)
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;
#if defined XP_WIN

View File

@ -2020,6 +2020,9 @@ pref("plugin.scan.WindowsMediaPlayer", "7.0");
// Which is currently HKLM\Software\MozillaPlugins\xxxPLIDxxx\Path
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
// when a network address is unreachable.
pref("network.autodial-helper.enabled", true);