Enabled Mac Async plugin by default + Fixes. b=663259 r=josh

This commit is contained in:
Benoit Girard 2011-06-25 15:12:59 -04:00
parent 7e7b4b1d5c
commit 6455de56ad
13 changed files with 150 additions and 51 deletions

View File

@ -88,7 +88,7 @@ nsNPAPIPluginInstance::nsNPAPIPluginInstance(nsNPAPIPlugin* plugin)
mMIMEType(nsnull),
mOwner(nsnull),
mCurrentPluginEvent(nsnull),
#if defined(MOZ_X11) || defined(XP_WIN)
#if defined(MOZ_X11) || defined(XP_WIN) || defined(XP_MACOSX)
mUsePluginLayersPref(PR_TRUE)
#else
mUsePluginLayersPref(PR_FALSE)
@ -104,7 +104,7 @@ nsNPAPIPluginInstance::nsNPAPIPluginInstance(nsNPAPIPlugin* plugin)
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefs) {
PRBool useLayersPref;
nsresult rv = prefs->GetBoolPref("mozilla.plugins.use_layers", &useLayersPref);
nsresult rv = prefs->GetBoolPref("plugins.use_layers", &useLayersPref);
if (NS_SUCCEEDED(rv))
mUsePluginLayersPref = useLayersPref;
}

View File

@ -263,8 +263,8 @@ nsPluginInstanceOwner::UseAsyncRendering()
NS_SUCCEEDED(mInstance->UseAsyncPainting(&useAsyncRendering)) &&
useAsyncRendering &&
#ifdef XP_MACOSX
mObjectFrame && mObjectFrame->GetImageContainer().get() &&
mObjectFrame->GetImageContainer().get()->GetBackendType() ==
container &&
container->GetBackendType() ==
LayerManager::LAYERS_OPENGL
#else
(!mPluginWindow ||

View File

@ -2336,17 +2336,12 @@ 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;
@ -2696,6 +2691,8 @@ PluginInstanceChild::UpdateWindowAttributes(bool aForceSetWindow)
return;
}
#ifndef XP_MACOSX
// Adjusting the window isn't needed for OSX
#ifndef XP_WIN
// On Windows, we translate the device context, in order for the window
// origin to be correct.
@ -2716,6 +2713,7 @@ PluginInstanceChild::UpdateWindowAttributes(bool aForceSetWindow)
mWindow.clipRect.right = clipRect.XMost();
mWindow.clipRect.bottom = clipRect.YMost();
}
#endif // XP_MACOSX
#ifdef XP_WIN
// Windowless plugins on Windows need a WM_WINDOWPOSCHANGED event to update
@ -3016,6 +3014,22 @@ PluginInstanceChild::ShowPluginFrame()
AutoRestore<bool> pending(mPendingPluginCall);
mPendingPluginCall = true;
bool temporarilyMakeVisible = !IsVisible() && !mHasPainted;
if (temporarilyMakeVisible && mWindow.width && mWindow.height) {
mWindow.clipRect.right = mWindow.width;
mWindow.clipRect.bottom = mWindow.height;
} else if (!IsVisible()) {
// If we're not visible, don't bother painting a <0,0,0,0>
// rect. If we're eventually made visible, the visibility
// change will invalidate our window.
ClearCurrentSurface();
return true;
}
if (!EnsureCurrentBuffer()) {
return false;
}
#ifdef XP_MACOSX
// We can't use the thebes code with CoreAnimation so we will
// take a different code path.
@ -3023,8 +3037,8 @@ PluginInstanceChild::ShowPluginFrame()
mDrawingModel == NPDrawingModelInvalidatingCoreAnimation ||
mDrawingModel == NPDrawingModelCoreGraphics) {
if (!EnsureCurrentBuffer()) {
return false;
if (!IsVisible()) {
return true;
}
// Clear accRect here to be able to pass
@ -3053,6 +3067,8 @@ PluginInstanceChild::ShowPluginFrame()
SurfaceDescriptor currSurf;
currSurf = IOSurfaceDescriptor(mCurrentIOSurface->GetIOSurfaceID());
mHasPainted = true;
// Unused
SurfaceDescriptor returnSurf;
@ -3067,22 +3083,6 @@ PluginInstanceChild::ShowPluginFrame()
}
#endif
bool temporarilyMakeVisible = !IsVisible() && !mHasPainted;
if (temporarilyMakeVisible && mWindow.width && mWindow.height) {
mWindow.clipRect.right = mWindow.width;
mWindow.clipRect.bottom = mWindow.height;
} else if (!IsVisible()) {
// If we're not visible, don't bother painting a <0,0,0,0>
// rect. If we're eventually made visible, the visibility
// change will invalidate our window.
ClearCurrentSurface();
return true;
}
if (!EnsureCurrentBuffer()) {
return false;
}
NS_ASSERTION(mWindow.width == (mWindow.clipRect.right - mWindow.clipRect.left) &&
mWindow.height == (mWindow.clipRect.bottom - mWindow.clipRect.top),
"Clip rect should be same size as window when using layers");
@ -3566,7 +3566,11 @@ PluginInstanceChild::ClearAllSurfaces()
SurfaceDescriptor temp = null_t();
NPRect r = { 0, 0, 1, 1 };
SendShow(r, temp, &temp);
}
if (mCGLayer) {
mozilla::plugins::PluginUtilsOSX::ReleaseCGLayer(mCGLayer);
mCGLayer = nsnull;
}
mCurrentIOSurface = nsnull;

View File

@ -436,10 +436,15 @@ private:
bool CanPaintOnBackground();
bool IsVisible() {
#ifdef XP_MACOSX
return mWindow.clipRect.top != mWindow.clipRect.bottom &&
mWindow.clipRect.left != mWindow.clipRect.right;
#else
return mWindow.clipRect.top != 0 ||
mWindow.clipRect.left != 0 ||
mWindow.clipRect.bottom != 0 ||
mWindow.clipRect.right != 0;
#endif
}
// ShowPluginFrame - in general does four things:

View File

@ -526,7 +526,7 @@ PluginInstanceParent::RecvShow(const NPRect& updatedRect,
return false;
}
mIOSurface = newIOSurface;
mFrontIOSurface = newIOSurface;
RecvNPN_InvalidateRect(updatedRect);
@ -616,7 +616,7 @@ nsresult
PluginInstanceParent::GetImage(ImageContainer* aContainer, Image** aImage)
{
#ifdef XP_MACOSX
if (!mFrontSurface && !mIOSurface)
if (!mFrontSurface && !mFrontIOSurface)
#else
if (!mFrontSurface)
#endif
@ -624,7 +624,7 @@ PluginInstanceParent::GetImage(ImageContainer* aContainer, Image** aImage)
Image::Format format = Image::CAIRO_SURFACE;
#ifdef XP_MACOSX
if (mIOSurface) {
if (mFrontIOSurface) {
format = Image::MAC_IO_SURFACE;
if (!aContainer->Manager()) {
return NS_ERROR_FAILURE;
@ -639,11 +639,11 @@ PluginInstanceParent::GetImage(ImageContainer* aContainer, Image** aImage)
}
#ifdef XP_MACOSX
if (mIOSurface) {
if (mFrontIOSurface) {
NS_ASSERTION(image->GetFormat() == Image::MAC_IO_SURFACE, "Wrong format?");
MacIOSurfaceImage* ioImage = static_cast<MacIOSurfaceImage*>(image.get());
MacIOSurfaceImage::Data ioData;
ioData.mIOSurface = mIOSurface;
ioData.mIOSurface = mFrontIOSurface;
ioImage->SetData(ioData);
*aImage = image.forget().get();
return NS_OK;
@ -671,8 +671,8 @@ PluginInstanceParent::GetImageSize(nsIntSize* aSize)
}
#ifdef XP_MACOSX
if (mIOSurface) {
*aSize = nsIntSize(mIOSurface->GetWidth(), mIOSurface->GetHeight());
if (mFrontIOSurface) {
*aSize = nsIntSize(mFrontIOSurface->GetWidth(), mFrontIOSurface->GetHeight());
return NS_OK;
}
#endif
@ -1167,7 +1167,25 @@ PluginInstanceParent::NPP_HandleEvent(void* event)
npevent->data.draw.width,
npevent->data.draw.height);
}
return false;
return true;
} else if (mFrontIOSurface) {
CGContextRef cgContext = npevent->data.draw.context;
if (!mShColorSpace) {
mShColorSpace = CreateSystemColorSpace();
}
if (!mShColorSpace) {
PLUGIN_LOG_DEBUG(("Could not allocate ColorSpace."));
return false;
}
if (cgContext) {
nsCARenderer::DrawSurfaceToCGContext(cgContext, mFrontIOSurface,
mShColorSpace,
npevent->data.draw.x,
npevent->data.draw.y,
npevent->data.draw.width,
npevent->data.draw.height);
}
return true;
} else {
if (mShWidth == 0 && mShHeight == 0) {
PLUGIN_LOG_DEBUG(("NPCocoaEventDrawRect on window of size 0."));

View File

@ -355,6 +355,7 @@ private:
CGColorSpaceRef mShColorSpace;
int16_t mDrawingModel;
nsAutoPtr<nsIOSurface> mIOSurface;
nsAutoPtr<nsIOSurface> mFrontIOSurface;
#endif // definied(MOZ_WIDGET_COCOA)
// ObjectFrame layer wrapper

View File

@ -97,8 +97,11 @@ void mozilla::plugins::PluginUtilsOSX::ReleaseCGLayer(void *cgLayer) {
void mozilla::plugins::PluginUtilsOSX::Repaint(void *caLayer, nsIntRect aRect) {
CGBridgeLayer *bridgeLayer = (CGBridgeLayer*)caLayer;
[CATransaction begin];
[bridgeLayer updateRect:aRect];
[bridgeLayer setNeedsDisplay];
[bridgeLayer displayIfNeeded];
[CATransaction commit];
}
@interface EventProcessor : NSObject {

View File

@ -1,8 +1,7 @@
function paintCountIs(plugin, expected, msg) {
var count = plugin.getPaintCount();
var realExpected = expected;
var isAsync = SimpleTest.testPluginIsOOP() &&
navigator.platform.indexOf("Mac") < 0;
var isAsync = SimpleTest.testPluginIsOOP();
if (isAsync) {
++realExpected; // extra paint at startup for all async-rendering plugins
} else {

View File

@ -8,7 +8,9 @@ div {
#good {
left:0px; top:0px;
width:220px; height:220px;
background-color: rgba(0,255,0, 0.6);
/* Core Animation alpha blending rounding differs
from the Core Graphics blending, adjust with care */
background-color: rgba(0,255,0, 0.51);
z-index: 0;
}
@ -55,4 +57,5 @@ embed#plugin {
position: absolute;
left:1px; top:1px;
z-index: 1;
}
}

View File

@ -8,7 +8,7 @@ random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) fails-if(!haveTestPlugin) =
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) fails-if(!haveTestPlugin) == border-padding-2.html border-padding-2-ref.html # bug 629430
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) fails-if(!haveTestPlugin) skip-if(Android) == border-padding-3.html border-padding-3-ref.html # bug 629430
random-if(cocoaWidget||d2d) fails-if(!haveTestPlugin&&!Android) skip-if(!testPluginIsOOP()) == pluginproblemui-direction-1.html pluginproblemui-direction-1-ref.html
fails-if(!haveTestPlugin&&!Android) skip-if(!testPluginIsOOP()) == pluginproblemui-direction-2.html pluginproblemui-direction-2-ref.html
random-if(cocoaWidget) fails-if(!haveTestPlugin&&!Android) skip-if(!testPluginIsOOP()) == pluginproblemui-direction-2.html pluginproblemui-direction-2-ref.html
fails-if(!haveTestPlugin) == plugin-canvas-alpha-zindex.html div-alpha-zindex.html
fails-if(!haveTestPlugin) == plugin-transform-alpha-zindex.html div-alpha-zindex.html
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) fails-if(!haveTestPlugin) == plugin-busy-alpha-zindex.html div-alpha-zindex.html

View File

@ -75,6 +75,10 @@ public:
CGColorSpaceRef aColorSpace,
int aX, int aY,
size_t aWidth, size_t aHeight);
#ifdef DEBUG
static void SaveToDisk(nsIOSurface *surf);
#endif
private:
void Destroy();

View File

@ -316,10 +316,6 @@ nsIOSurface* nsIOSurface::LookupSurface(IOSurfaceID aIOSurfaceID) {
IOSurfacePtr surfaceRef = nsIOSurfaceLib::IOSurfaceLookup(aIOSurfaceID);
if (!surfaceRef)
return nsnull;
// IOSurfaceLookup does not retain the object for us,
// we want IOSurfacePtr to remain for the lifetime of
// nsIOSurface.
CFRetain(surfaceRef);
nsIOSurface* ioSurface = new nsIOSurface(surfaceRef);
if (!ioSurface) {
@ -502,10 +498,27 @@ nsresult nsCARenderer::SetupRenderer(void *aCALayer, int aWidth, int aHeight) {
Destroy();
return NS_ERROR_FAILURE;
}
// Create a transaction and disable animations
// to make the position update instant.
[CATransaction begin];
NSMutableDictionary *newActions = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"onOrderIn",
[NSNull null], @"onOrderOut",
[NSNull null], @"sublayers",
[NSNull null], @"contents",
[NSNull null], @"position",
[NSNull null], @"bounds",
nil];
layer.actions = newActions;
[newActions release];
[CATransaction setValue: [NSNumber numberWithFloat:0.0f] forKey: kCATransactionAnimationDuration];
[CATransaction setValue: (id) kCFBooleanTrue forKey: kCATransactionDisableActions];
[layer setBounds:CGRectMake(0, 0, aWidth, aHeight)];
[layer setPosition:CGPointMake(aWidth/2.0, aHeight/2.0)];
caRenderer.layer = layer;
caRenderer.bounds = CGRectMake(0, 0, aWidth, aHeight);
[CATransaction commit];
// We either target rendering to a CGImage or IOSurface.
if (!mIOSurface) {
@ -680,6 +693,7 @@ nsresult nsCARenderer::Render(int aWidth, int aHeight,
::glClearColor(0.0, 0.0, 0.0, 0.0);
::glClear(GL_COLOR_BUFFER_BIT);
[CATransaction commit];
double caTime = ::CACurrentMediaTime();
[caRenderer beginFrameAtTime:caTime timeStamp:NULL];
[caRenderer addUpdateRect:CGRectMake(0,0, aWidth, aHeight)];
@ -767,3 +781,55 @@ nsresult nsCARenderer::DrawSurfaceToCGContext(CGContextRef aContext,
return NS_OK;
}
#ifdef DEBUG
int sSaveToDiskSequence = 0;
void nsCARenderer::SaveToDisk(nsIOSurface *surf) {
surf->Lock();
size_t bytesPerRow = surf->GetBytesPerRow();
size_t ioWidth = surf->GetWidth();
size_t ioHeight = surf->GetHeight();
void* ioData = surf->GetBaseAddress();
CGDataProviderRef dataProvider = ::CGDataProviderCreateWithData(ioData,
ioData, ioHeight*(bytesPerRow)*4,
NULL); //No release callback
if (!dataProvider) {
surf->Unlock();
return;
}
CGImageRef cgImage = ::CGImageCreate(ioWidth, ioHeight, 8, 32, bytesPerRow,
CreateSystemColorSpace(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
dataProvider, NULL, true, kCGRenderingIntentDefault);
::CGDataProviderRelease(dataProvider);
if (!cgImage) {
surf->Unlock();
return;
}
char cstr[1000];
sprintf(cstr, "file:///Users/benoitgirard/debug/iosurface_%i.png", ++sSaveToDiskSequence);
CFStringRef cfStr = ::CFStringCreateWithCString(kCFAllocatorDefault, cstr, kCFStringEncodingMacRoman);
printf("Exporting: %s\n", cstr);
CFURLRef url = ::CFURLCreateWithString( NULL, cfStr, NULL);
CFStringRef type = kUTTypePNG;
size_t count = 1;
CFDictionaryRef options = NULL;
CGImageDestinationRef dest = ::CGImageDestinationCreateWithURL(url, type, count, options);
::CGImageDestinationAddImage(dest, cgImage, NULL);
::CGImageDestinationFinalize(dest);
::CFRelease(dest);
surf->Unlock();
return;
}
#endif

View File

@ -1559,13 +1559,9 @@ nsObjectFrame::GetLayerState(nsDisplayListBuilder* aBuilder,
return LAYER_NONE;
#ifdef XP_MACOSX
if (aManager &&
aManager->GetBackendType() == LayerManager::LAYERS_OPENGL &&
mInstanceOwner->UseAsyncRendering() &&
mInstanceOwner->GetEventModel() == NPEventModelCocoa &&
mInstanceOwner->GetDrawingModel() == NPDrawingModelCoreGraphics)
{
return LAYER_ACTIVE;
if (aManager && aManager->GetBackendType() !=
LayerManager::LAYERS_OPENGL) {
return LAYER_NONE;
}
#endif