From 468e5acf13d59df8072d30ab50c0642b78fea785 Mon Sep 17 00:00:00 2001 From: Benoit Girard Date: Thu, 19 May 2011 17:08:14 -0400 Subject: [PATCH 01/18] Asynchronous layer-based plugin painting on Mac b=598425 r=roc,josh --- dom/plugins/base/PluginPRLibrary.cpp | 11 -- dom/plugins/base/PluginPRLibrary.h | 3 - dom/plugins/base/nsNPAPIPluginInstance.cpp | 16 -- dom/plugins/base/nsPluginInstanceOwner.cpp | 72 +++++---- dom/plugins/base/nsPluginInstanceOwner.h | 16 +- dom/plugins/ipc/PPluginInstance.ipdl | 5 + dom/plugins/ipc/PluginInstanceChild.cpp | 171 ++++++++++++++++++++- dom/plugins/ipc/PluginInstanceChild.h | 9 ++ dom/plugins/ipc/PluginInstanceParent.cpp | 36 +++-- dom/plugins/ipc/PluginInstanceParent.h | 15 +- dom/plugins/ipc/PluginInterposeOSX.h | 2 + dom/plugins/ipc/PluginLibrary.h | 3 - dom/plugins/ipc/PluginModuleParent.cpp | 14 +- dom/plugins/ipc/PluginModuleParent.h | 4 - dom/plugins/ipc/PluginUtilsOSX.h | 11 +- dom/plugins/ipc/PluginUtilsOSX.mm | 56 +++++++ layout/generic/nsObjectFrame.cpp | 8 +- 17 files changed, 336 insertions(+), 116 deletions(-) diff --git a/dom/plugins/base/PluginPRLibrary.cpp b/dom/plugins/base/PluginPRLibrary.cpp index 8f5e2f73821..2ae125e02da 100644 --- a/dom/plugins/base/PluginPRLibrary.cpp +++ b/dom/plugins/base/PluginPRLibrary.cpp @@ -258,17 +258,6 @@ PluginPRLibrary::GetImageSize(NPP instance, nsIntSize* aSize) return NS_ERROR_NOT_IMPLEMENTED; } -#if defined(XP_MACOSX) -nsresult -PluginPRLibrary::IsRemoteDrawingCoreAnimation(NPP instance, PRBool *aDrawing) -{ - nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata; - NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER); - *aDrawing = PR_FALSE; - return NS_OK; -} -#endif - nsresult PluginPRLibrary::SetBackgroundUnknown(NPP instance) { diff --git a/dom/plugins/base/PluginPRLibrary.h b/dom/plugins/base/PluginPRLibrary.h index f796921d28e..8169887a86a 100644 --- a/dom/plugins/base/PluginPRLibrary.h +++ b/dom/plugins/base/PluginPRLibrary.h @@ -143,9 +143,6 @@ public: virtual nsresult GetImage(NPP instance, ImageContainer* aContainer, Image** aImage); virtual nsresult GetImageSize(NPP instance, nsIntSize* aSize); NS_OVERRIDE virtual bool UseAsyncPainting() { return false; } -#if defined(XP_MACOSX) - virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, PRBool *aDrawing); -#endif NS_OVERRIDE virtual nsresult SetBackgroundUnknown(NPP instance); NS_OVERRIDE diff --git a/dom/plugins/base/nsNPAPIPluginInstance.cpp b/dom/plugins/base/nsNPAPIPluginInstance.cpp index d9965e6a62a..5797b01a935 100644 --- a/dom/plugins/base/nsNPAPIPluginInstance.cpp +++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp @@ -729,22 +729,6 @@ nsresult nsNPAPIPluginInstance::GetDrawingModel(PRInt32* aModel) #endif } -nsresult nsNPAPIPluginInstance::IsRemoteDrawingCoreAnimation(PRBool* aDrawing) -{ -#ifdef XP_MACOSX - if (!mPlugin) - return NS_ERROR_FAILURE; - - PluginLibrary* library = mPlugin->GetLibrary(); - if (!library) - return NS_ERROR_FAILURE; - - return library->IsRemoteDrawingCoreAnimation(&mNPP, aDrawing); -#else - return NS_ERROR_FAILURE; -#endif -} - nsresult nsNPAPIPluginInstance::GetJSObject(JSContext *cx, JSObject** outObject) { diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index 60f4f0772fc..a733d31f084 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -251,6 +251,28 @@ nsPluginInstanceOwner::EndUpdateBackground(gfxContext* aContext, } } +PRBool +nsPluginInstanceOwner::UseAsyncRendering() +{ +#ifdef XP_MACOSX + nsRefPtr container = mObjectFrame->GetImageContainer(); +#endif + + PRBool useAsyncRendering; + return (mInstance && + NS_SUCCEEDED(mInstance->UseAsyncPainting(&useAsyncRendering)) && + useAsyncRendering && +#ifdef XP_MACOSX + mObjectFrame && mObjectFrame->GetImageContainer().get() && + mObjectFrame->GetImageContainer().get()->GetBackendType() == + LayerManager::LAYERS_OPENGL +#else + (!mPluginWindow || + mPluginWindow->type == NPWindowTypeDrawable) +#endif + ); +} + nsIntSize nsPluginInstanceOwner::GetCurrentImageSize() { @@ -1338,18 +1360,6 @@ NPDrawingModel nsPluginInstanceOwner::GetDrawingModel() return drawingModel; } -PRBool nsPluginInstanceOwner::IsRemoteDrawingCoreAnimation() -{ - if (!mInstance) - return PR_FALSE; - - PRBool coreAnimation; - if (!NS_SUCCEEDED(mInstance->IsRemoteDrawingCoreAnimation(&coreAnimation))) - return PR_FALSE; - - return coreAnimation; -} - NPEventModel nsPluginInstanceOwner::GetEventModel() { return mEventModel; @@ -3217,7 +3227,7 @@ void* nsPluginInstanceOwner::FixUpPluginWindow(PRInt32 inPaintState) mPluginWindow->clipRect.right != oldClipRect.right || mPluginWindow->clipRect.bottom != oldClipRect.bottom) { - mInstance->SetWindow(mPluginWindow); + CallSetWindow(); mPluginPortChanged = PR_FALSE; #ifdef MAC_CARBON_PLUGINS // if the clipRect is of size 0, make the null timer fire less often @@ -3231,7 +3241,7 @@ void* nsPluginInstanceOwner::FixUpPluginWindow(PRInt32 inPaintState) } #endif } else if (mPluginPortChanged) { - mInstance->SetWindow(mPluginWindow); + CallSetWindow(); mPluginPortChanged = PR_FALSE; } @@ -3273,7 +3283,11 @@ nsPluginInstanceOwner::HidePluginWindow() mPluginWindow->clipRect.bottom = mPluginWindow->clipRect.top; mPluginWindow->clipRect.right = mPluginWindow->clipRect.left; mWidgetVisible = PR_FALSE; - mInstance->SetWindow(mPluginWindow); + if (mAsyncHidePluginWindow) { + mInstance->AsyncSetWindow(mPluginWindow); + } else { + mInstance->SetWindow(mPluginWindow); + } } #else // XP_MACOSX @@ -3321,19 +3335,6 @@ void nsPluginInstanceOwner::UpdateWindowPositionAndClipRect(PRBool aSetWindow) } } -void -nsPluginInstanceOwner::CallSetWindow() -{ - if (!mInstance) - return; - - if (UseAsyncRendering()) { - mInstance->AsyncSetWindow(mPluginWindow); - } else { - mInstance->SetWindow(mPluginWindow); - } -} - void nsPluginInstanceOwner::UpdateWindowVisibility(PRBool aVisible) { @@ -3343,6 +3344,21 @@ nsPluginInstanceOwner::UpdateWindowVisibility(PRBool aVisible) #endif // XP_MACOSX +void +nsPluginInstanceOwner::CallSetWindow() +{ + if (!mInstance) + return; + + if (UseAsyncRendering()) { + mAsyncHidePluginWindow = true; + mInstance->AsyncSetWindow(mPluginWindow); + } else { + mAsyncHidePluginWindow = false; + mInstance->SetWindow(mPluginWindow); + } +} + // Little helper function to resolve relative URL in // |value| for certain inputs of |name| void nsPluginInstanceOwner::FixUpURLS(const nsString &name, nsAString &value) diff --git a/dom/plugins/base/nsPluginInstanceOwner.h b/dom/plugins/base/nsPluginInstanceOwner.h index e1e8f7b794d..ed9566122a1 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.h +++ b/dom/plugins/base/nsPluginInstanceOwner.h @@ -179,7 +179,6 @@ public: enum { ePluginPaintEnable, ePluginPaintDisable }; NPDrawingModel GetDrawingModel(); - PRBool IsRemoteDrawingCoreAnimation(); NPEventModel GetEventModel(); static void CARefresh(nsITimer *aTimer, void *aClosure); static void AddToCARefreshTimer(nsPluginInstanceOwner *aPluginInstance); @@ -207,9 +206,9 @@ public: void EndCGPaint(); #else // XP_MACOSX void UpdateWindowPositionAndClipRect(PRBool aSetWindow); - void CallSetWindow(); void UpdateWindowVisibility(PRBool aVisible); #endif // XP_MACOSX + void CallSetWindow(); void SetOwner(nsObjectFrame *aOwner) { @@ -295,15 +294,7 @@ public: already_AddRefed BeginUpdateBackground(const nsIntRect& aRect); void EndUpdateBackground(gfxContext* aContext, const nsIntRect& aRect); - PRBool UseAsyncRendering() - { - PRBool useAsyncRendering; - return (mInstance && - NS_SUCCEEDED(mInstance->UseAsyncPainting(&useAsyncRendering)) && - useAsyncRendering && - (!mPluginWindow || - mPluginWindow->type == NPWindowTypeDrawable)); - } + PRBool UseAsyncRendering(); private: @@ -339,6 +330,9 @@ private: static nsTArray *sCARefreshListeners; PRBool mSentInitialTopLevelWindowEvent; #endif + // We need to know if async hide window is required since we + // can not check UseAsyncRendering when executing StopPlugin + PRBool mAsyncHidePluginWindow; // Initially, the event loop nesting level we were created on, it's updated // if we detect the appshell is on a lower level as long as we're not stopped. diff --git a/dom/plugins/ipc/PPluginInstance.ipdl b/dom/plugins/ipc/PPluginInstance.ipdl index 4dfce814e4d..7ac8afc96dd 100644 --- a/dom/plugins/ipc/PPluginInstance.ipdl +++ b/dom/plugins/ipc/PPluginInstance.ipdl @@ -69,10 +69,15 @@ struct SurfaceDescriptorX11 { gfxIntSize size; }; +struct IOSurfaceDescriptor { + uint32_t surfaceId; +}; + union SurfaceDescriptor { Shmem; SurfaceDescriptorX11; PPluginSurface; // used on Windows + IOSurfaceDescriptor; // used on OSX 10.5+ // Descriptor can be null here in case // 1) of first Show call (prevSurface is null) // 2) when child is going to destroy diff --git a/dom/plugins/ipc/PluginInstanceChild.cpp b/dom/plugins/ipc/PluginInstanceChild.cpp index 6167a2b4c9f..8b9bfcff8e9 100644 --- a/dom/plugins/ipc/PluginInstanceChild.cpp +++ b/dom/plugins/ipc/PluginInstanceChild.cpp @@ -105,6 +105,7 @@ static const TCHAR kPluginIgnoreSubclassProperty[] = TEXT("PluginIgnoreSubclassP #elif defined(XP_MACOSX) #include +#include "PluginUtilsOSX.h" #endif // defined(XP_MACOSX) template<> @@ -135,6 +136,7 @@ PluginInstanceChild::PluginInstanceChild(const NPPluginFuncs* aPluginIface) , mShColorSpace(nsnull) , mShContext(nsnull) , mDrawingModel(NPDrawingModelCoreGraphics) + , mCGLayer(nsnull) , mCurrentEvent(nsnull) #endif , mLayersRendering(false) @@ -183,6 +185,9 @@ PluginInstanceChild::~PluginInstanceChild() if (mShContext) { ::CGContextRelease(mShContext); } + if (mCGLayer) { + mozilla::plugins::PluginUtilsOSX::ReleaseCGLayer(mCGLayer); + } #endif } @@ -477,6 +482,9 @@ PluginInstanceChild::NPN_SetValue(NPPVariable aVar, void* aValue) return NPERR_GENERIC_ERROR; mDrawingModel = drawingModel; + PLUGIN_LOG_DEBUG((" Plugin requested drawing model id #%i\n", + mDrawingModel)); + return rv; } @@ -490,6 +498,9 @@ PluginInstanceChild::NPN_SetValue(NPPVariable aVar, void* aValue) mEventModel = static_cast(eventModel); #endif + PLUGIN_LOG_DEBUG((" Plugin requested event model id # %i\n", + eventModel)); + return rv; } #endif @@ -778,6 +789,32 @@ PluginInstanceChild::AnswerNPP_HandleEvent_Shmem(const NPRemoteEvent& event, #endif #ifdef XP_MACOSX + +void CallCGDraw(CGContextRef ref, void* aPluginInstance, nsIntRect aUpdateRect) { + PluginInstanceChild* pluginInstance = (PluginInstanceChild*)aPluginInstance; + + pluginInstance->CGDraw(ref, aUpdateRect); +} + +bool +PluginInstanceChild::CGDraw(CGContextRef ref, nsIntRect aUpdateRect) { + + NPCocoaEvent drawEvent; + drawEvent.type = NPCocoaEventDrawRect; + drawEvent.version = 0; + drawEvent.data.draw.x = aUpdateRect.x; + drawEvent.data.draw.y = aUpdateRect.y; + drawEvent.data.draw.width = aUpdateRect.width; + drawEvent.data.draw.height = aUpdateRect.height; + drawEvent.data.draw.context = ref; + + NPRemoteEvent remoteDrawEvent = {drawEvent}; + + int16_t handled; + AnswerNPP_HandleEvent(remoteDrawEvent, &handled); + return handled == true; +} + bool PluginInstanceChild::AnswerNPP_HandleEvent_IOSurface(const NPRemoteEvent& event, const uint32_t &surfaceid, @@ -803,13 +840,16 @@ PluginInstanceChild::AnswerNPP_HandleEvent_IOSurface(const NPRemoteEvent& event, NPError result = mPluginIface->getvalue(GetNPP(), NPPVpluginCoreAnimationLayer, &caLayer); + if (result != NPERR_NO_ERROR || !caLayer) { PLUGIN_LOG_DEBUG(("Plugin requested CoreAnimation but did not " "provide CALayer.")); *handled = false; return false; } + mCARenderer.SetupRenderer(caLayer, mWindow.width, mWindow.height); + // Flash needs to have the window set again after this step if (mPluginIface->setwindow) (void) mPluginIface->setwindow(&mData, &mWindow); @@ -2278,12 +2318,17 @@ PluginInstanceChild::DoAsyncSetWindow(const gfxSurfaceType& aSurfaceType, } mWindow.window = NULL; +#ifdef XP_MACOSX + if (mWindow.width != aWindow.width || mWindow.height != aWindow.height) + mAccumulatedInvalidRect = nsIntRect(0, 0, aWindow.width, aWindow.height); +#else if (mWindow.width != aWindow.width || mWindow.height != aWindow.height || mWindow.clipRect.top != aWindow.clipRect.top || mWindow.clipRect.left != aWindow.clipRect.left || mWindow.clipRect.bottom != aWindow.clipRect.bottom || mWindow.clipRect.right != aWindow.clipRect.right) mAccumulatedInvalidRect = nsIntRect(0, 0, aWindow.width, aWindow.height); +#endif mWindow.x = aWindow.x; mWindow.y = aWindow.y; @@ -2472,6 +2517,7 @@ PluginInstanceChild::MaybeCreatePlatformHelperSurface(void) bool PluginInstanceChild::EnsureCurrentBuffer(void) { +#ifndef XP_MACOSX nsIntRect toInvalidate(0, 0, 0, 0); gfxIntSize winSize = gfxIntSize(mWindow.width, mWindow.height); @@ -2503,7 +2549,7 @@ PluginInstanceChild::EnsureCurrentBuffer(void) mAccumulatedInvalidRect.UnionRect(mAccumulatedInvalidRect, toInvalidate); if (mCurrentSurface) { - return true; + return true; } if (!CreateOptSurface()) { @@ -2517,6 +2563,65 @@ PluginInstanceChild::EnsureCurrentBuffer(void) } return true; +#else // XP_MACOSX + if (mCurrentIOSurface && + (mCurrentIOSurface->GetWidth() != mWindow.width || + mCurrentIOSurface->GetHeight() != mWindow.height) ) { + mCurrentIOSurface = nsnull; + } + + if (!mCARenderer.isInit() || !mCurrentIOSurface) { + if (!mCurrentIOSurface) { + mCurrentIOSurface = nsIOSurface::CreateIOSurface(mWindow.width, mWindow.height); + + nsIntRect toInvalidate(0, 0, mWindow.width, mWindow.height); + mAccumulatedInvalidRect.UnionRect(mAccumulatedInvalidRect, toInvalidate); + } + + if (!mCurrentIOSurface) { + NS_WARNING("Failed to allocate IOSurface"); + return false; + } + + nsIOSurface *rendererSurface = nsIOSurface::LookupSurface(mCurrentIOSurface->GetIOSurfaceID()); + if (!rendererSurface) { + NS_WARNING("Failed to lookup IOSurface"); + return false; + } + mCARenderer.AttachIOSurface(rendererSurface); + + void *caLayer = nsnull; + if (mDrawingModel == NPDrawingModelCoreGraphics) { + if (mCGLayer) { + mozilla::plugins::PluginUtilsOSX::ReleaseCGLayer(mCGLayer); + mCGLayer = nsnull; + } + + caLayer = mozilla::plugins::PluginUtilsOSX::GetCGLayer(CallCGDraw, this); + if (!caLayer) { + return false; + } + + mCGLayer = caLayer; + } else { + NPError result = mPluginIface->getvalue(GetNPP(), + NPPVpluginCoreAnimationLayer, + &caLayer); + if (result != NPERR_NO_ERROR || !caLayer) { + PLUGIN_LOG_DEBUG(("Plugin requested CoreAnimation but did not " + "provide CALayer.")); + return false; + } + } + + mCARenderer.SetupRenderer(caLayer, mWindow.width, mWindow.height); + // Flash needs to have the window set again after this step + if (mPluginIface->setwindow) + (void) mPluginIface->setwindow(&mData, &mWindow); + } + + return true; +#endif } void @@ -2893,6 +2998,57 @@ PluginInstanceChild::ShowPluginFrame() AutoRestore pending(mPendingPluginCall); mPendingPluginCall = true; +#ifdef XP_MACOSX + // We can't use the thebes code with CoreAnimation so we will + // take a different code path. + if (mDrawingModel == NPDrawingModelCoreAnimation || + mDrawingModel == NPDrawingModelInvalidatingCoreAnimation || + mDrawingModel == NPDrawingModelCoreGraphics) { + + if (!EnsureCurrentBuffer()) { + return false; + } + + // Clear accRect here to be able to pass + // test_invalidate_during_plugin_paint test + nsIntRect rect = mAccumulatedInvalidRect; + mAccumulatedInvalidRect.SetEmpty(); + + // Fix up old invalidations that might have been made when our + // surface was a different size + rect.IntersectRect(rect, + nsIntRect(0, 0, mCurrentIOSurface->GetWidth(), mCurrentIOSurface->GetHeight())); + + if (!mCARenderer.isInit()) { + NS_ERROR("CARenderer not initialized"); + return false; + } + + if (mDrawingModel == NPDrawingModelCoreGraphics) { + mozilla::plugins::PluginUtilsOSX::Repaint(mCGLayer, rect); + } + + mCARenderer.Render(mWindow.width, mWindow.height, nsnull); + + NPRect r = { (uint16_t)rect.y, (uint16_t)rect.x, + (uint16_t)rect.YMost(), (uint16_t)rect.XMost() }; + SurfaceDescriptor currSurf; + currSurf = IOSurfaceDescriptor(mCurrentIOSurface->GetIOSurfaceID()); + + // Unused + SurfaceDescriptor returnSurf; + + if (!SendShow(r, currSurf, &returnSurf)) { + return false; + } + + return true; + } else { + NS_ERROR("Unsupported drawing model for async layer rendering"); + return false; + } +#endif + bool temporarilyMakeVisible = !IsVisible() && !mHasPainted; if (temporarilyMakeVisible && mWindow.width && mWindow.height) { mWindow.clipRect.right = mWindow.width; @@ -3145,6 +3301,7 @@ PluginInstanceChild::InvalidateRect(NPRect* aInvalidRect) AsyncShowPluginFrame(); return; } + // If we were going to use layers rendering but it's not set up // yet, and the plugin happens to call this first, we'll forward // the invalidation to the browser. It's unclear whether @@ -3384,6 +3541,18 @@ PluginInstanceChild::ClearAllSurfaces() mBackSurfaceActor = NULL; } #endif + +#ifdef XP_MACOSX + if (mCurrentIOSurface) { + // Get last surface back, and drop it + SurfaceDescriptor temp = null_t(); + NPRect r = { 0, 0, 1, 1 }; + SendShow(r, temp, &temp); + + } + + mCurrentIOSurface = nsnull; +#endif } bool diff --git a/dom/plugins/ipc/PluginInstanceChild.h b/dom/plugins/ipc/PluginInstanceChild.h index 8dc9e39d6c4..3ab4133b1ac 100644 --- a/dom/plugins/ipc/PluginInstanceChild.h +++ b/dom/plugins/ipc/PluginInstanceChild.h @@ -414,11 +414,14 @@ private: CGContextRef mShContext; int16_t mDrawingModel; nsCARenderer mCARenderer; + void *mCGLayer; public: const NPCocoaEvent* getCurrentEvent() { return mCurrentEvent; } + + bool CGDraw(CGContextRef ref, nsIntRect aUpdateRect); #if defined(__i386__) NPEventModel EventModel() { return mEventModel; } @@ -511,6 +514,12 @@ private: // surface which is on ParentProcess side nsRefPtr mBackSurface; +#ifdef XP_MACOSX + // Current IOSurface available for rendering + // We can't use thebes gfxASurface like other platforms. + nsAutoPtr mCurrentIOSurface; +#endif + // (Not to be confused with mBackSurface). This is a recent copy // of the opaque pixels under our object frame, if // |mIsTransparent|. We ask the plugin render directly onto a diff --git a/dom/plugins/ipc/PluginInstanceParent.cpp b/dom/plugins/ipc/PluginInstanceParent.cpp index 6c464f99e17..5914f24367b 100644 --- a/dom/plugins/ipc/PluginInstanceParent.cpp +++ b/dom/plugins/ipc/PluginInstanceParent.cpp @@ -103,7 +103,6 @@ PluginInstanceParent::PluginInstanceParent(PluginModuleParent* parent, , mShHeight(0) , mShColorSpace(nsnull) , mDrawingModel(NPDrawingModelCoreGraphics) - , mIOSurface(nsnull) #endif { InitQuirksModes(aMimeType); @@ -137,7 +136,6 @@ PluginInstanceParent::~PluginInstanceParent() } if (mShColorSpace) ::CGColorSpaceRelease(mShColorSpace); - delete mIOSurface; if (mDrawingModel == NPDrawingModelCoreAnimation) { mParent->RemoveFromRefreshTimer(this); } @@ -517,6 +515,29 @@ PluginInstanceParent::RecvShow(const NPRect& updatedRect, } surface = gfxSharedImageSurface::Open(newSurface.get_Shmem()); } +#ifdef XP_MACOSX + else if (newSurface.type() == SurfaceDescriptor::TIOSurfaceDescriptor) { + IOSurfaceDescriptor iodesc = newSurface.get_IOSurfaceDescriptor(); + + nsIOSurface *newIOSurface = nsIOSurface::LookupSurface(iodesc.surfaceId()); + + if (!newIOSurface) { + NS_WARNING("Got bad IOSurfaceDescriptor in RecvShow"); + return false; + } + + mIOSurface = newIOSurface; + + RecvNPN_InvalidateRect(updatedRect); + + *prevSurface = null_t(); + + PLUGIN_LOG_DEBUG((" (RecvShow invalidated for surface %p)", + mFrontSurface.get())); + + return true; + } +#endif #ifdef MOZ_X11 else if (newSurface.type() == SurfaceDescriptor::TSurfaceDescriptorX11) { SurfaceDescriptorX11 xdesc = newSurface.get_SurfaceDescriptorX11(); @@ -659,16 +680,6 @@ PluginInstanceParent::GetImageSize(nsIntSize* aSize) return NS_ERROR_NOT_AVAILABLE; } -#ifdef XP_MACOSX -nsresult -PluginInstanceParent::IsRemoteDrawingCoreAnimation(PRBool *aDrawing) -{ - *aDrawing = (NPDrawingModelCoreAnimation == (NPDrawingModel)mDrawingModel || - NPDrawingModelInvalidatingCoreAnimation == (NPDrawingModel)mDrawingModel); - return NS_OK; -} -#endif - nsresult PluginInstanceParent::SetBackgroundUnknown() { @@ -869,7 +880,6 @@ PluginInstanceParent::NPP_SetWindow(const NPWindow* aWindow) if (mShWidth != window.width || mShHeight != window.height) { if (mDrawingModel == NPDrawingModelCoreAnimation || mDrawingModel == NPDrawingModelInvalidatingCoreAnimation) { - delete mIOSurface; mIOSurface = nsIOSurface::CreateIOSurface(window.width, window.height); } else if (mShWidth * mShHeight != window.width * window.height) { if (mShWidth != 0 && mShHeight != 0) { diff --git a/dom/plugins/ipc/PluginInstanceParent.h b/dom/plugins/ipc/PluginInstanceParent.h index 77c486876a0..033d0999f01 100644 --- a/dom/plugins/ipc/PluginInstanceParent.h +++ b/dom/plugins/ipc/PluginInstanceParent.h @@ -282,9 +282,6 @@ public: nsresult AsyncSetWindow(NPWindow* window); nsresult GetImage(mozilla::layers::ImageContainer* aContainer, mozilla::layers::Image** aImage); nsresult GetImageSize(nsIntSize* aSize); -#ifdef XP_MACOSX - nsresult IsRemoteDrawingCoreAnimation(PRBool *aDrawing); -#endif nsresult SetBackgroundUnknown(); nsresult BeginUpdateBackground(const nsIntRect& aRect, gfxContext** aCtx); @@ -352,12 +349,12 @@ private: #endif // defined(XP_WIN) #if defined(OS_MACOSX) private: - Shmem mShSurface; - size_t mShWidth; - size_t mShHeight; - CGColorSpaceRef mShColorSpace; - int16_t mDrawingModel; - nsIOSurface *mIOSurface; + Shmem mShSurface; + size_t mShWidth; + size_t mShHeight; + CGColorSpaceRef mShColorSpace; + int16_t mDrawingModel; + nsAutoPtr mIOSurface; #endif // definied(OS_MACOSX) // ObjectFrame layer wrapper diff --git a/dom/plugins/ipc/PluginInterposeOSX.h b/dom/plugins/ipc/PluginInterposeOSX.h index d639da05e02..6f1ec9c3781 100644 --- a/dom/plugins/ipc/PluginInterposeOSX.h +++ b/dom/plugins/ipc/PluginInterposeOSX.h @@ -32,6 +32,8 @@ #include "base/basictypes.h" #include "nsPoint.h" +#include "npapi.h" +#include "nsRect.h" // Make this includable from non-Objective-C code. #ifndef __OBJC__ diff --git a/dom/plugins/ipc/PluginLibrary.h b/dom/plugins/ipc/PluginLibrary.h index a1feb628f7e..9fa6f24f2c6 100644 --- a/dom/plugins/ipc/PluginLibrary.h +++ b/dom/plugins/ipc/PluginLibrary.h @@ -102,9 +102,6 @@ public: virtual nsresult GetImage(NPP instance, ImageContainer* aContainer, Image** aImage) = 0; virtual nsresult GetImageSize(NPP instance, nsIntSize* aSize) = 0; virtual bool UseAsyncPainting() = 0; -#if defined(XP_MACOSX) - virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, PRBool *aDrawing) = 0; -#endif /** * The next three methods are the third leg in the trip to * PluginInstanceParent. They approximately follow the ReadbackSink diff --git a/dom/plugins/ipc/PluginModuleParent.cpp b/dom/plugins/ipc/PluginModuleParent.cpp index e5f0033ba28..597757acf0b 100644 --- a/dom/plugins/ipc/PluginModuleParent.cpp +++ b/dom/plugins/ipc/PluginModuleParent.cpp @@ -39,8 +39,8 @@ #ifdef MOZ_WIDGET_GTK2 #include #elif XP_MACOSX -#include "PluginUtilsOSX.h" #include "PluginInterposeOSX.h" +#include "PluginUtilsOSX.h" #include "nsIPrefService.h" #include "nsIPrefBranch.h" #endif @@ -924,18 +924,6 @@ PluginModuleParent::NPP_GetSitesWithData(InfallibleTArray& result) return NS_OK; } -#if defined(XP_MACOSX) -nsresult -PluginModuleParent::IsRemoteDrawingCoreAnimation(NPP instance, PRBool *aDrawing) -{ - PluginInstanceParent* i = InstCast(instance); - if (!i) - return NS_ERROR_FAILURE; - - return i->IsRemoteDrawingCoreAnimation(aDrawing); -} -#endif - bool PluginModuleParent::AnswerNPN_GetValue_WithBoolReturn(const NPNVariable& aVariable, NPError* aError, diff --git a/dom/plugins/ipc/PluginModuleParent.h b/dom/plugins/ipc/PluginModuleParent.h index bea57196d26..5122ef40022 100644 --- a/dom/plugins/ipc/PluginModuleParent.h +++ b/dom/plugins/ipc/PluginModuleParent.h @@ -282,10 +282,6 @@ private: uint64_t maxAge); virtual nsresult NPP_GetSitesWithData(InfallibleTArray& result); -#if defined(XP_MACOSX) - virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, PRBool *aDrawing); -#endif - private: void WritePluginExtraDataForMinidump(const nsAString& id); void WriteExtraDataForHang(); diff --git a/dom/plugins/ipc/PluginUtilsOSX.h b/dom/plugins/ipc/PluginUtilsOSX.h index 492c806c722..a67d5c8d46d 100644 --- a/dom/plugins/ipc/PluginUtilsOSX.h +++ b/dom/plugins/ipc/PluginUtilsOSX.h @@ -38,18 +38,27 @@ * ***** END LICENSE BLOCK ***** */ #include "npapi.h" +#include "nsRect.h" namespace mozilla { namespace plugins { namespace PluginUtilsOSX { -// Need to call back into the browser's to process event. +// Need to call back into the browser's message loop to process event. typedef void (*RemoteProcessEvents) (void*); NPError ShowCocoaContextMenu(void* aMenu, int aX, int aY, void* pluginModule, RemoteProcessEvents remoteEvent); void InvokeNativeEventLoop(); +// Need to call back and send a cocoa draw event to the plugin. +typedef void (*DrawPluginFunc) (CGContextRef, void*, nsIntRect aUpdateRect); + +void* GetCGLayer(DrawPluginFunc aFunc, void* aPluginInstance); +void ReleaseCGLayer(void* cgLayer); +void Repaint(void* cgLayer, nsIntRect aRect); + + } // namespace PluginUtilsOSX } // namespace plugins } // namespace mozilla diff --git a/dom/plugins/ipc/PluginUtilsOSX.mm b/dom/plugins/ipc/PluginUtilsOSX.mm index 903552a5f54..881f627836d 100644 --- a/dom/plugins/ipc/PluginUtilsOSX.mm +++ b/dom/plugins/ipc/PluginUtilsOSX.mm @@ -38,6 +38,7 @@ * ***** END LICENSE BLOCK ***** */ #import +#import #include "PluginUtilsOSX.h" // Remove definitions for try/catch interfering with ObjCException macros. @@ -45,6 +46,61 @@ using namespace mozilla::plugins::PluginUtilsOSX; +@interface CGBridgeLayer : CALayer { + DrawPluginFunc mDrawFunc; + void* mPluginInstance; + nsIntRect mUpdateRect; +} +- (void) setDrawFunc: (DrawPluginFunc)aFunc pluginInstance:(void*) aPluginInstance; +- (void) updateRect: (nsIntRect)aRect; + +@end + +@implementation CGBridgeLayer +- (void) updateRect: (nsIntRect)aRect +{ + mUpdateRect.UnionRect(mUpdateRect, aRect); +} + +- (void) setDrawFunc: (DrawPluginFunc)aFunc pluginInstance:(void*) aPluginInstance +{ + mDrawFunc = aFunc; + mPluginInstance = aPluginInstance; +} + +- (void)drawInContext:(CGContextRef)aCGContext + +{ + ::CGContextSaveGState(aCGContext); + ::CGContextTranslateCTM(aCGContext, 0, self.bounds.size.height); + ::CGContextScaleCTM(aCGContext, (CGFloat) 1, (CGFloat) -1); + + mDrawFunc(aCGContext, mPluginInstance, mUpdateRect); + + ::CGContextRestoreGState(aCGContext); + + mUpdateRect.SetEmpty(); +} + +@end + +void* mozilla::plugins::PluginUtilsOSX::GetCGLayer(DrawPluginFunc aFunc, void* aPluginInstance) { + CGBridgeLayer *bridgeLayer = [[CGBridgeLayer alloc] init ]; + [bridgeLayer setDrawFunc:aFunc pluginInstance:aPluginInstance]; + return bridgeLayer; +} + +void mozilla::plugins::PluginUtilsOSX::ReleaseCGLayer(void *cgLayer) { + CGBridgeLayer *bridgeLayer = (CGBridgeLayer*)cgLayer; + [bridgeLayer release]; +} + +void mozilla::plugins::PluginUtilsOSX::Repaint(void *caLayer, nsIntRect aRect) { + CGBridgeLayer *bridgeLayer = (CGBridgeLayer*)caLayer; + [bridgeLayer updateRect:aRect]; + [bridgeLayer setNeedsDisplay]; +} + @interface EventProcessor : NSObject { RemoteProcessEvents aRemoteEvents; void *aPluginModule; diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index aee2394019f..48070c49fb0 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -1500,7 +1500,9 @@ nsObjectFrame::UpdateImageLayer(ImageContainer* aContainer, const gfxRect& aRect } #ifdef XP_MACOSX - mInstanceOwner->DoCocoaEventDrawRect(aRect, nsnull); + if (!mInstanceOwner->UseAsyncRendering()) { + mInstanceOwner->DoCocoaEventDrawRect(aRect, nsnull); + } #endif mInstanceOwner->SetCurrentImage(aContainer); @@ -1516,9 +1518,9 @@ nsObjectFrame::GetLayerState(nsDisplayListBuilder* aBuilder, #ifdef XP_MACOSX if (aManager && aManager->GetBackendType() == LayerManager::LAYERS_OPENGL && + mInstanceOwner->UseAsyncRendering() && mInstanceOwner->GetEventModel() == NPEventModelCocoa && - mInstanceOwner->GetDrawingModel() == NPDrawingModelCoreGraphics && - mInstanceOwner->IsRemoteDrawingCoreAnimation()) + mInstanceOwner->GetDrawingModel() == NPDrawingModelCoreGraphics) { return LAYER_ACTIVE; } From 0fc9bbc32cc10136faccc1cfc23f2cc202053a48 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 3 Jun 2011 17:45:38 +0200 Subject: [PATCH 02/18] Bug 660131 - Follow up fix. Include glib-object.h for disabling gconf. r=karlt --- toolkit/system/gnome/nsGnomeModule.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/toolkit/system/gnome/nsGnomeModule.cpp b/toolkit/system/gnome/nsGnomeModule.cpp index 13dbbb7bf1e..9dbd47e6d97 100644 --- a/toolkit/system/gnome/nsGnomeModule.cpp +++ b/toolkit/system/gnome/nsGnomeModule.cpp @@ -39,6 +39,8 @@ #include "nsToolkitCompsCID.h" #include "mozilla/ModuleUtils.h" +#include + #ifdef MOZ_ENABLE_GCONF #include "nsGConfService.h" NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGConfService, Init) From b24e41048e23f19d8a341f9ee19c59c49049deac Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 3 Jun 2011 15:04:52 -0400 Subject: [PATCH 03/18] Bug 495577 - Rename the "Permanent Private Browsing mode" checkbox in the Privacy prefpane to better match the surrounding options; r=dao ui-r=faaborg --- browser/components/preferences/privacy.xul | 4 ++-- browser/locales/en-US/chrome/browser/preferences/privacy.dtd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/browser/components/preferences/privacy.xul b/browser/components/preferences/privacy.xul index ea2f0cba57c..e52989b5a8e 100644 --- a/browser/components/preferences/privacy.xul +++ b/browser/components/preferences/privacy.xul @@ -187,8 +187,8 @@ diff --git a/browser/locales/en-US/chrome/browser/preferences/privacy.dtd b/browser/locales/en-US/chrome/browser/preferences/privacy.dtd index 01e0f856fb0..48baec34bae 100644 --- a/browser/locales/en-US/chrome/browser/preferences/privacy.dtd +++ b/browser/locales/en-US/chrome/browser/preferences/privacy.dtd @@ -61,8 +61,8 @@ - - + + From f9339f6813c6e56ba2e3959045cc9d0df8a353e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Fri, 3 Jun 2011 16:34:42 -0400 Subject: [PATCH 04/18] b=661145, r=bsmedberg Move the function declarations passed to AC_TRY_COMPILE out of the body of main. --- configure.in | 16 ++++++++-------- js/src/configure.in | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/configure.in b/configure.in index dcf1332e7f4..b3620162c52 100644 --- a/configure.in +++ b/configure.in @@ -4298,29 +4298,29 @@ dnl See if compiler supports some gcc-style attributes AC_CACHE_CHECK(for __attribute__((always_inline)), ac_cv_attribute_always_inline, - [AC_TRY_COMPILE([], - [inline void f(void) __attribute__((always_inline));], + [AC_TRY_COMPILE([inline void f(void) __attribute__((always_inline));], + [], ac_cv_attribute_always_inline=yes, ac_cv_attribute_always_inline=no)]) AC_CACHE_CHECK(for __attribute__((malloc)), ac_cv_attribute_malloc, - [AC_TRY_COMPILE([], - [void* f(int) __attribute__((malloc));], + [AC_TRY_COMPILE([void* f(int) __attribute__((malloc));], + [], ac_cv_attribute_malloc=yes, ac_cv_attribute_malloc=no)]) AC_CACHE_CHECK(for __attribute__((warn_unused_result)), ac_cv_attribute_warn_unused, - [AC_TRY_COMPILE([], - [int f(void) __attribute__((warn_unused_result));], + [AC_TRY_COMPILE([int f(void) __attribute__((warn_unused_result));], + [], ac_cv_attribute_warn_unused=yes, ac_cv_attribute_warn_unused=no)]) AC_CACHE_CHECK(for __attribute__((noreturn)), ac_cv_attribute_noreturn, - [AC_TRY_COMPILE([], - [void f(void) __attribute__((noreturn));], + [AC_TRY_COMPILE([void f(void) __attribute__((noreturn));], + [], ac_cv_attribute_noreturn=yes, ac_cv_attribute_noreturn=no)]) diff --git a/js/src/configure.in b/js/src/configure.in index eb52841dc98..3448d74f355 100644 --- a/js/src/configure.in +++ b/js/src/configure.in @@ -4221,29 +4221,29 @@ dnl See if compiler supports some gcc-style attributes AC_CACHE_CHECK(for __attribute__((always_inline)), ac_cv_attribute_always_inline, - [AC_TRY_COMPILE([], - [inline void f(void) __attribute__((always_inline));], + [AC_TRY_COMPILE([inline void f(void) __attribute__((always_inline));], + [], ac_cv_attribute_always_inline=yes, ac_cv_attribute_always_inline=no)]) AC_CACHE_CHECK(for __attribute__((malloc)), ac_cv_attribute_malloc, - [AC_TRY_COMPILE([], - [void* f(int) __attribute__((malloc));], + [AC_TRY_COMPILE([void* f(int) __attribute__((malloc));], + [], ac_cv_attribute_malloc=yes, ac_cv_attribute_malloc=no)]) AC_CACHE_CHECK(for __attribute__((warn_unused_result)), ac_cv_attribute_warn_unused, - [AC_TRY_COMPILE([], - [int f(void) __attribute__((warn_unused_result));], + [AC_TRY_COMPILE([int f(void) __attribute__((warn_unused_result));], + [], ac_cv_attribute_warn_unused=yes, ac_cv_attribute_warn_unused=no)]) AC_CACHE_CHECK(for __attribute__((noreturn)), ac_cv_attribute_noreturn, - [AC_TRY_COMPILE([], - [void f(void) __attribute__((noreturn));], + [AC_TRY_COMPILE([void f(void) __attribute__((noreturn));], + [], ac_cv_attribute_noreturn=yes, ac_cv_attribute_noreturn=no)]) From 8703cf51437549737ae616940b6beba56aa433f9 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 3 Jun 2011 16:48:31 -0400 Subject: [PATCH 05/18] Bug 612448 - Protect the progress listener object from being garbage collected too soon which could cause a test timeout; r=roc --- .../test/mochitest/xulbrowser_plugin_visibility.xul | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dom/plugins/test/mochitest/xulbrowser_plugin_visibility.xul b/dom/plugins/test/mochitest/xulbrowser_plugin_visibility.xul index 2e5a672e06f..0b4a3a35618 100644 --- a/dom/plugins/test/mochitest/xulbrowser_plugin_visibility.xul +++ b/dom/plugins/test/mochitest/xulbrowser_plugin_visibility.xul @@ -52,10 +52,14 @@ var browser1 = document.getElementById('browser1'); var browser2 = document.getElementById('browser2'); + var progressListener1, progressListener2; + function setup() { - browser1.addProgressListener(new ProgressListener(), nsIWebProgress.NOTIFY_STATE_WINDOW); + progressListener1 = new ProgressListener(); + browser1.addProgressListener(progressListener1, nsIWebProgress.NOTIFY_STATE_WINDOW); browser1.loadURI(kURI, null, null); - browser2.addProgressListener(new ProgressListener(), nsIWebProgress.NOTIFY_STATE_WINDOW); + progressListener2 = new ProgressListener(); + browser2.addProgressListener(progressListener2, nsIWebProgress.NOTIFY_STATE_WINDOW); browser2.loadURI(kURI, null, null); } From 7778dfb0d946f3233bc2a90485a75ee897d73b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A3o=20Gottwald?= Date: Sun, 5 Jun 2011 19:37:10 +0200 Subject: [PATCH 06/18] Bug 662155 - addTab should report the exception when loadURIWithFlags fails. r=gavin --- browser/base/content/tabbrowser.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml index 36678d08861..d192b764c6a 100644 --- a/browser/base/content/tabbrowser.xml +++ b/browser/base/content/tabbrowser.xml @@ -1334,9 +1334,9 @@ flags |= Ci.nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL; try { b.loadURIWithFlags(aURI, flags, aReferrerURI, aCharset, aPostData); - + } catch (ex) { + Cu.reportError(ex); } - catch (ex) { } } // We start our browsers out as inactive, and then maintain From 7c8feff73ed6f0417f4c8e49678a30eff2b4b4b5 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Sun, 5 Jun 2011 11:54:14 -0700 Subject: [PATCH 07/18] Bug 661876: Fix tests to avoid using obsolete nsIDOMFile properties/methods. --- content/base/test/Makefile.in | 1 - content/base/test/test_bug414796.html | 55 ---------------------- content/canvas/test/test_mozGetAsFile.html | 21 +++++++-- 3 files changed, 17 insertions(+), 60 deletions(-) delete mode 100644 content/base/test/test_bug414796.html diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in index c1eb022888f..9d25f30430b 100644 --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -158,7 +158,6 @@ _TEST_FILES1 = test_bug5141.html \ test_bug413974.html \ test_bug415860.html \ test_bug414190.html \ - test_bug414796.html \ test_bug527896.html \ test_bug416317-1.html \ test_bug416317-2.html \ diff --git a/content/base/test/test_bug414796.html b/content/base/test/test_bug414796.html deleted file mode 100644 index a488f2dc835..00000000000 --- a/content/base/test/test_bug414796.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - Test for Bug 414796 - - - - - - -Mozilla Bug 414796 -

- -

- - -
-
-
- diff --git a/content/canvas/test/test_mozGetAsFile.html b/content/canvas/test/test_mozGetAsFile.html index 294c36f0c5e..e4a32683e05 100644 --- a/content/canvas/test/test_mozGetAsFile.html +++ b/content/canvas/test/test_mozGetAsFile.html @@ -6,6 +6,21 @@

FAIL (fallback content)