2010-07-08 Simon Fraser <simon.fraser@apple.com>
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Jul 2010 22:35:15 +0000 (22:35 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Jul 2010 22:35:15 +0000 (22:35 +0000)
        Reviewed by Anders Carlsson.

        Allow the TestPlugin to use Core Animation rendering for testing
        https://bugs.webkit.org/show_bug.cgi?id=41872

        Add the ability for the TestPlugin to use the CoreAnimation rendering model
        when available, based on the "drawingmodel" attribute of the embed tag:
            drawingmodel="coreanimation"

        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj: Add PluginObjectMac.mm
        * DumpRenderTree/TestNetscapePlugIn/PluginObject.h: Add some macros so we can detect
        when building on Tiger. Add a void* coreAnimationLayer member.

        * DumpRenderTree/TestNetscapePlugIn/PluginObjectMac.mm: Added.
        (createCoreAnimationLayer): Obj-C method to create the CALayer.

        * DumpRenderTree/TestNetscapePlugIn/main.cpp:
        (NPP_New): Look for the drawingmodel attribute to decide which drawing
        model to use.
        (NPP_Destroy): Release the CALayer if we have one.
        (NPP_GetValue): Return the retained CALayer.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@62857 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/compositing/plugins/composited-plugin.html [new file with mode: 0644]
LayoutTests/platform/mac/compositing/plugins/composited-plugin-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/compositing/plugins/composited-plugin-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/compositing/plugins/composited-plugin-expected.txt [new file with mode: 0644]
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj
WebKitTools/DumpRenderTree/TestNetscapePlugIn/PluginObject.h
WebKitTools/DumpRenderTree/TestNetscapePlugIn/PluginObjectMac.mm [new file with mode: 0644]
WebKitTools/DumpRenderTree/TestNetscapePlugIn/main.cpp

index 327595e..c40b189 100644 (file)
@@ -1,3 +1,17 @@
+2010-07-08  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        Allow the TestPlugin to use Core Animation rendering for testing
+        https://bugs.webkit.org/show_bug.cgi?id=41872
+        
+        Simple pixel test with a Core Animation plugin.
+
+        * compositing/plugins/composited-plugin.html: Added.
+        * platform/mac/compositing/plugins/composited-plugin-expected.checksum: Added.
+        * platform/mac/compositing/plugins/composited-plugin-expected.png: Added.
+        * platform/mac/compositing/plugins/composited-plugin-expected.txt: Added.
+
 2010-07-08  Albert J. Wong  <ajwong@chromium.org>
 
         Unreviewed, chromium build fix.
diff --git a/LayoutTests/compositing/plugins/composited-plugin.html b/LayoutTests/compositing/plugins/composited-plugin.html
new file mode 100644 (file)
index 0000000..e9099ee
--- /dev/null
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+<body>
+  <embed type="application/x-webkit-test-netscape" drawingmodel="coreanimation">
+</body>
+</html>
diff --git a/LayoutTests/platform/mac/compositing/plugins/composited-plugin-expected.checksum b/LayoutTests/platform/mac/compositing/plugins/composited-plugin-expected.checksum
new file mode 100644 (file)
index 0000000..2cd3d68
--- /dev/null
@@ -0,0 +1 @@
+cbf1f1593fd3c9cf704bb0e0ca3b1390
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/compositing/plugins/composited-plugin-expected.png b/LayoutTests/platform/mac/compositing/plugins/composited-plugin-expected.png
new file mode 100644 (file)
index 0000000..dfb134f
Binary files /dev/null and b/LayoutTests/platform/mac/compositing/plugins/composited-plugin-expected.png differ
diff --git a/LayoutTests/platform/mac/compositing/plugins/composited-plugin-expected.txt b/LayoutTests/platform/mac/compositing/plugins/composited-plugin-expected.txt
new file mode 100644 (file)
index 0000000..511b2a7
--- /dev/null
@@ -0,0 +1,10 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x170
+  RenderBlock {HTML} at (0,0) size 800x170
+    RenderBody {BODY} at (8,8) size 784x154
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
+layer at (8,8) size 300x150
+  RenderEmbeddedObject {EMBED} at (0,0) size 300x150
index 1e18a0c..d144caf 100644 (file)
@@ -1,3 +1,27 @@
+2010-07-08  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        Allow the TestPlugin to use Core Animation rendering for testing
+        https://bugs.webkit.org/show_bug.cgi?id=41872
+        
+        Add the ability for the TestPlugin to use the CoreAnimation rendering model
+        when available, based on the "drawingmodel" attribute of the embed tag:
+            drawingmodel="coreanimation"
+
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj: Add PluginObjectMac.mm
+        * DumpRenderTree/TestNetscapePlugIn/PluginObject.h: Add some macros so we can detect
+        when building on Tiger. Add a void* coreAnimationLayer member.
+        
+        * DumpRenderTree/TestNetscapePlugIn/PluginObjectMac.mm: Added.
+        (createCoreAnimationLayer): Obj-C method to create the CALayer.
+        
+        * DumpRenderTree/TestNetscapePlugIn/main.cpp:
+        (NPP_New): Look for the drawingmodel attribute to decide which drawing
+        model to use.
+        (NPP_Destroy): Release the CALayer if we have one.
+        (NPP_GetValue): Return the retained CALayer.
+
 2010-07-08  Martin Robinson  <mrobinson@igalia.com>
 
         Reviewed by Xan Lopez.
index f994648..2ed5daa 100644 (file)
@@ -24,6 +24,8 @@
 /* End PBXAggregateTarget section */
 
 /* Begin PBXBuildFile section */
+               0F37A4A711E6628700275F54 /* PluginObjectMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F37A4A611E6628700275F54 /* PluginObjectMac.mm */; };
+               0F37A4AA11E6629100275F54 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5A752A108AF5D1F00138E45 /* QuartzCore.framework */; };
                141BF435096A455900E0753C /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9335435F03D75502008635CE /* WebKit.framework */; };
                141BF436096A455900E0753C /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A84F608908B136DA00E9745F /* Cocoa.framework */; };
                141BF438096A455900E0753C /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A817090308B164D300CCB9FB /* JavaScriptCore.framework */; };
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
+               0F37A4A611E6628700275F54 /* PluginObjectMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PluginObjectMac.mm; sourceTree = "<group>"; };
                141BF233096A44CF00E0753C /* TestNetscapePlugIn.plugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestNetscapePlugIn.plugin; sourceTree = BUILT_PRODUCTS_DIR; };
                141BF447096A45C800E0753C /* PluginObject.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PluginObject.h; sourceTree = "<group>"; };
                141BF448096A45C800E0753C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.plist.xml; name = Info.plist; path = mac/Info.plist; sourceTree = "<group>"; };
                                141BF436096A455900E0753C /* Cocoa.framework in Frameworks */,
                                141BF438096A455900E0753C /* JavaScriptCore.framework in Frameworks */,
                                141BF435096A455900E0753C /* WebKit.framework in Frameworks */,
+                               0F37A4AA11E6629100275F54 /* QuartzCore.framework in Frameworks */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                141BF448096A45C800E0753C /* Info.plist */,
                                1AC6C77F0D07589B00CD3161 /* main.cpp */,
                                1AC6C7800D07589B00CD3161 /* PluginObject.cpp */,
+                               0F37A4A611E6628700275F54 /* PluginObjectMac.mm */,
                                141BF447096A45C800E0753C /* PluginObject.h */,
                                1AC6C7810D07589B00CD3161 /* TestObject.cpp */,
                                1A8F024C0BB9B056008CFA34 /* TestObject.h */,
                                1AC6C8490D07638600CD3161 /* main.cpp in Sources */,
                                1AC6C84A0D07638600CD3161 /* PluginObject.cpp in Sources */,
                                1AC6C84B0D07638600CD3161 /* TestObject.cpp in Sources */,
+                               0F37A4A711E6628700275F54 /* PluginObjectMac.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index ceec40a..03befb0 100644 (file)
 
 #include <WebKit/npfunctions.h>
 
+#if XP_MACOSX
+#if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
+#define BUILDING_ON_TIGER 1
+#elif !defined(MAC_OS_X_VERSION_10_6) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
+#define BUILDING_ON_LEOPARD 1
+#elif !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
+#define BUILDING_ON_SNOW_LEOPARD 1
+#endif
+#endif // XP_MACOSX
+
 extern NPNetscapeFuncs *browser;
 
 typedef struct {
@@ -56,6 +66,9 @@ typedef struct {
 #ifdef XP_MACOSX
     NPEventModel eventModel;
 #endif
+#if XP_MACOSX && !defined(BUILDING_ON_TIGER)
+    void* coreAnimationLayer;
+#endif
     NPWindow lastWindow;
 } PluginObject;
 
@@ -66,3 +79,8 @@ extern void testNPRuntime(NPP npp);
 extern void pluginLog(NPP instance, const char* format, ...);
 extern bool testDocumentOpen(NPP npp);
 extern bool testWindowOpen(NPP npp);
+
+#if XP_MACOSX && !defined(BUILDING_ON_TIGER)
+extern void* createCoreAnimationLayer();
+#endif
+
diff --git a/WebKitTools/DumpRenderTree/TestNetscapePlugIn/PluginObjectMac.mm b/WebKitTools/DumpRenderTree/TestNetscapePlugIn/PluginObjectMac.mm
new file mode 100644 (file)
index 0000000..3aff46d
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "PluginObject.h"
+
+#if !defined(BUILDING_ON_TIGER)
+
+#include <QuartzCore/QuartzCore.h>
+
+@interface TestPluginLayer : CALayer
+@end
+
+@implementation TestPluginLayer
+
+- (void)drawInContext:(CGContextRef)context
+{
+    CGRect bounds = [self bounds];
+    const char* text = "Test Plug-in";
+    CGContextSelectFont(context, "Helvetica", 24, kCGEncodingMacRoman);
+    CGContextShowTextAtPoint(context, bounds.origin.x + 3.0f, bounds.origin.y + bounds.size.height - 30.0f, text, strlen(text));
+}
+
+@end
+
+void* createCoreAnimationLayer()
+{
+    CALayer *caLayer = [[TestPluginLayer alloc] init];
+
+    NSNull *nullValue = [NSNull null];
+    NSDictionary *actions = [NSDictionary dictionaryWithObjectsAndKeys:
+                             nullValue, @"anchorPoint",
+                             nullValue, @"bounds",
+                             nullValue, @"contents",
+                             nullValue, @"contentsRect",
+                             nullValue, @"opacity",
+                             nullValue, @"position",
+                             nullValue, @"shadowColor",
+                             nullValue, @"sublayerTransform",
+                             nullValue, @"sublayers",
+                             nullValue, @"transform",
+                             nullValue, @"zPosition",
+                             nil];
+    // Turn off default animations.
+    [caLayer setStyle:[NSDictionary dictionaryWithObject:actions forKey:@"actions"]];
+    [caLayer setNeedsDisplayOnBoundsChange:YES];
+
+    [caLayer setBounds:CGRectMake(0, 0, 200, 100)];
+    [caLayer setAnchorPoint:CGPointZero];
+    
+    CGColorRef color = CGColorCreateGenericRGB(0.5, 0.5, 1, 1);
+    [caLayer setBackgroundColor:color];
+    CGColorRelease(color);
+    
+    [caLayer setLayoutManager:[CAConstraintLayoutManager layoutManager]];
+
+    CALayer *sublayer = [CALayer layer];
+    // Turn off default animations.
+    [sublayer setStyle:[NSDictionary dictionaryWithObject:actions forKey:@"actions"]];
+
+    color = CGColorCreateGenericRGB(0, 0, 0, 0.75);
+    [sublayer setBackgroundColor:color];
+    CGColorRelease(color);
+    [sublayer setBounds:CGRectMake(0, 0, 180, 20)];
+
+    [sublayer addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMinY
+                                                     relativeTo:@"superlayer"
+                                                      attribute:kCAConstraintMinY]];
+    [sublayer addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMinX
+                                                     relativeTo:@"superlayer"
+                                                      attribute:kCAConstraintMinX]];
+    [sublayer addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMaxX
+                                                     relativeTo:@"superlayer"
+                                                      attribute:kCAConstraintMaxX]];
+
+    [caLayer addSublayer:sublayer];
+    return caLayer;
+}
+
+#endif // !defined(BUILDING_ON_TIGER)
+
index 11751aa..67336f8 100644 (file)
@@ -89,7 +89,11 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc
     if (!supportsCoreGraphics)
         return NPERR_INCOMPATIBLE_VERSION_ERROR;
 
-    browser->setvalue(instance, NPPVpluginDrawingModel, (void *)NPDrawingModelCoreGraphics);
+    NPDrawingModel drawingModelToUse = NPDrawingModelCoreGraphics;
+    
+    NPBool supportsCoreAnimation;
+    if (browser->getvalue(instance, NPNVsupportsCoreAnimationBool, &supportsCoreAnimation) != NPERR_NO_ERROR)
+        supportsCoreAnimation = false;
 
 #ifndef NP_NO_CARBON
     NPBool supportsCarbon = false;
@@ -123,6 +127,7 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc
 
 #if XP_MACOSX
     obj->eventModel = eventModel;
+    obj->coreAnimationLayer = 0;
 #endif // XP_MACOSX
 
     for (int i = 0; i < argc; i++) {
@@ -155,7 +160,21 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc
             obj->testDocumentOpenInDestroyStream = TRUE;
         else if (strcasecmp(argn[i], "testwindowopen") == 0)
             obj->testWindowOpen = TRUE;
-        else if (strcasecmp(argn[i], "testGetURLOnDestroy") == 0) {
+        else if (strcasecmp(argn[i], "drawingmodel") == 0) {
+            const char* value = argv[i];
+            if (strcasecmp(value, "coreanimation") == 0) {
+                if (supportsCoreAnimation)
+                    drawingModelToUse = NPDrawingModelCoreAnimation;
+                else
+                    return NPERR_INCOMPATIBLE_VERSION_ERROR;
+             } else if (strcasecmp(value, "coregraphics") == 0) {
+                if (supportsCoreGraphics)
+                    drawingModelToUse = NPDrawingModelCoreGraphics;
+                else
+                    return NPERR_INCOMPATIBLE_VERSION_ERROR;
+             } else
+                return NPERR_INCOMPATIBLE_VERSION_ERROR;
+        } else if (strcasecmp(argn[i], "testGetURLOnDestroy") == 0) {
 #if XP_WIN
             // FIXME: When https://bugs.webkit.org/show_bug.cgi?id=41831 is fixed, this #ifdef can be removed.
             obj->testGetURLOnDestroy = TRUE;
@@ -164,6 +183,12 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc
             obj->testKeyboardFocusForPlugins = TRUE;
     }
 
+#if XP_MACOSX && !defined(BUILDING_ON_TIGER)
+    browser->setvalue(instance, NPPVpluginDrawingModel, (void *)drawingModelToUse);
+    if (drawingModelToUse == NPDrawingModelCoreAnimation)
+        obj->coreAnimationLayer = createCoreAnimationLayer();
+#endif
+
     browser->getvalue(instance, NPNVprivateModeBool, (void *)&obj->cachedPrivateBrowsingMode);
         
     return NPERR_NO_ERROR;
@@ -196,6 +221,11 @@ NPError NPP_Destroy(NPP instance, NPSavedData **save)
         if (obj->logDestroy)
             pluginLog(instance, "NPP_Destroy");
 
+#if XP_MACOSX && !defined(BUILDING_ON_TIGER)
+        if (obj->coreAnimationLayer)
+            CFRelease(obj->coreAnimationLayer);
+#endif
+
         browser->releaseobject(&obj->header);
     }
     return NPERR_NO_ERROR;
@@ -496,6 +526,17 @@ NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
         return NPERR_NO_ERROR;
     }
     
+#if XP_MACOSX && !defined(BUILDING_ON_TIGER)
+    if (variable == NPPVpluginCoreAnimationLayer) {
+        if (!obj->coreAnimationLayer)
+            return NPERR_GENERIC_ERROR;
+        
+        void **v = (void **)value;
+        *v = (void*)CFRetain(obj->coreAnimationLayer);
+        return NPERR_NO_ERROR;
+    }
+#endif
+    
     return NPERR_GENERIC_ERROR;
 }