2010-01-11 Simon Fraser <simon.fraser@apple.com>
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Jan 2010 00:15:06 +0000 (00:15 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Jan 2010 00:15:06 +0000 (00:15 +0000)
        Reviewed by Kevin Decker.

        https://bugs.webkit.org/show_bug.cgi?id=33455
        Allows plugins to participate in accelerated compositing

        For plugins using the CoreAnimation rendering mode, host their CALayers in the
        accelerated compositing layer tree.

        This requires making normal flow RenderLayers for RenderEmbeddedObjects when they represent
        a plugin using this mode.

        * WebCore.base.exp: Export Node::setNeedsStyleRecalc() for use by WebKit.
        * WebCore.xcodeproj/project.pbxproj: Re-order files for sorting.

        * rendering/RenderEmbeddedObject.h:
        * rendering/RenderEmbeddedObject.cpp:
        (WebCore::RenderEmbeddedObject::requiresLayer): Make a layer if the plugin is using
        accelerated compositing mode.
        (WebCore::RenderEmbeddedObject::allowsAcceleratedCompositing): Asks whether the plugin has
        a layer, via PluginWidget.

        * rendering/RenderLayer.cpp:
        (WebCore::RenderLayer::shouldBeNormalFlowOnly):
        (WebCore::RenderLayer::isSelfPaintingLayer):
        RenderEmbeddedObjects should be normal flow layers, and self-painting layers.

        * rendering/RenderLayerBacking.cpp:
        (WebCore::RenderLayerBacking::updateGraphicsLayerConfiguration):
        Parent the plugin's layer in the GraphicsLayer when updating the layer configuration.

        * rendering/RenderLayerCompositor.h:
        * rendering/RenderLayerCompositor.cpp:
        (WebCore::RenderLayerCompositor::requiresCompositingLayer):
        (WebCore::RenderLayerCompositor::requiresCompositingForPlugin):
        RenderEmbeddedObjects that allow accelerated compositing trip accelerated compositing mode
        for the page.

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

17 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac/plugins/embed-attributes-style-expected.checksum
LayoutTests/platform/mac/plugins/embed-attributes-style-expected.png
LayoutTests/platform/mac/plugins/embed-attributes-style-expected.txt
LayoutTests/plugins/embed-attributes-style.html
WebCore/ChangeLog
WebCore/WebCore.base.exp
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/rendering/RenderEmbeddedObject.cpp
WebCore/rendering/RenderEmbeddedObject.h
WebCore/rendering/RenderLayer.cpp
WebCore/rendering/RenderLayerBacking.cpp
WebCore/rendering/RenderLayerCompositor.cpp
WebCore/rendering/RenderLayerCompositor.h
WebKit/mac/ChangeLog
WebKit/mac/Plugins/Hosted/WebHostedNetscapePluginView.mm
WebKit/mac/Plugins/WebNetscapePluginView.mm

index 7e07490..305f466 100644 (file)
@@ -1,3 +1,19 @@
+2010-01-11  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Kevin Decker.
+
+        https://bugs.webkit.org/show_bug.cgi?id=33455
+        Allows plugins to participate in accelerated compositing
+        
+        Change the testcase to make the embeds position: relative so that the behavior
+        of the test is not affected by whether WebCore decides to put plugins into
+        RenderLayers.
+
+        * platform/mac/plugins/embed-attributes-style-expected.checksum:
+        * platform/mac/plugins/embed-attributes-style-expected.png:
+        * platform/mac/plugins/embed-attributes-style-expected.txt:
+        * plugins/embed-attributes-style.html:
+
 2010-01-11  Dirk Schulze  <krit@webkit.org>
 
         Reviewed by Nikolas Zimmermann.
index 7d29555..1382e3b 100644 (file)
Binary files a/LayoutTests/platform/mac/plugins/embed-attributes-style-expected.png and b/LayoutTests/platform/mac/plugins/embed-attributes-style-expected.png differ
index 2a52682..f7ebd53 100644 (file)
@@ -12,17 +12,20 @@ layer at (0,0) size 800x600
       RenderBlock {HR} at (0,52) size 784x2 [border: (1px inset #000000)]
       RenderBlock {DIV} at (0,62) size 784x0
       RenderBlock {DIV} at (0,62) size 784x104
-        RenderEmbeddedObject {EMBED} at (0,0) size 50x100
         RenderText {#text} at (50,86) size 122x18
           text run at (50,86) width 4: " "
           text run at (54,86) width 118: "valign top attribute"
       RenderBlock {DIV} at (0,166) size 784x104
-        RenderEmbeddedObject {EMBED} at (0,0) size 50x100
         RenderText {#text} at (50,86) size 128x18
           text run at (50,86) width 4: " "
           text run at (54,86) width 124: "border 5px attribute"
       RenderBlock {DIV} at (0,270) size 784x106
-        RenderEmbeddedObject {EMBED} at (0,0) size 52x102 [border: (1px dashed #000000)]
         RenderText {#text} at (52,88) size 102x18
           text run at (52,88) width 4: " "
           text run at (56,88) width 98: "hidden attribute"
+layer at (8,70) size 50x100
+  RenderEmbeddedObject {EMBED} at (0,0) size 50x100
+layer at (8,174) size 50x100
+  RenderEmbeddedObject {EMBED} at (0,0) size 50x100
+layer at (8,278) size 52x102
+  RenderEmbeddedObject {EMBED} at (0,0) size 52x102 [border: (1px dashed #000000)]
index 6ca40ce..eb4266a 100644 (file)
@@ -2,6 +2,7 @@
 <head>
 <style>
 embed {
+    position: relative;
     width: 50px; 
     height: 100px;
 }
index f01a53a..13c95b2 100644 (file)
@@ -1,3 +1,42 @@
+2010-01-11  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Kevin Decker.
+
+        https://bugs.webkit.org/show_bug.cgi?id=33455
+        Allows plugins to participate in accelerated compositing
+
+        For plugins using the CoreAnimation rendering mode, host their CALayers in the
+        accelerated compositing layer tree.
+        
+        This requires making normal flow RenderLayers for RenderEmbeddedObjects when they represent
+        a plugin using this mode.
+        
+        * WebCore.base.exp: Export Node::setNeedsStyleRecalc() for use by WebKit.
+        * WebCore.xcodeproj/project.pbxproj: Re-order files for sorting.
+
+        * rendering/RenderEmbeddedObject.h:
+        * rendering/RenderEmbeddedObject.cpp:
+        (WebCore::RenderEmbeddedObject::requiresLayer): Make a layer if the plugin is using
+        accelerated compositing mode.
+        (WebCore::RenderEmbeddedObject::allowsAcceleratedCompositing): Asks whether the plugin has
+        a layer, via PluginWidget.
+
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::shouldBeNormalFlowOnly):
+        (WebCore::RenderLayer::isSelfPaintingLayer):
+        RenderEmbeddedObjects should be normal flow layers, and self-painting layers.
+        
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::updateGraphicsLayerConfiguration):
+        Parent the plugin's layer in the GraphicsLayer when updating the layer configuration.
+        
+        * rendering/RenderLayerCompositor.h:
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::requiresCompositingLayer):
+        (WebCore::RenderLayerCompositor::requiresCompositingForPlugin):
+        RenderEmbeddedObjects that allow accelerated compositing trip accelerated compositing mode
+        for the page.
+
 2010-01-11  Andreas Kling  <andreas.kling@nokia.com>
 
         Reviewed by Darin Adler.
index 3399a4e..798a3c7 100644 (file)
@@ -883,6 +883,7 @@ __ZNK7WebCore4KURLcvP5NSURLEv
 __ZNK7WebCore4Node14isDescendantOfEPKS0_
 __ZNK7WebCore4Node18getSubresourceURLsERN3WTF11ListHashSetINS_4KURLENS_8KURLHashEEE
 __ZNK7WebCore4Node9nodeIndexEv
+__ZN7WebCore4Node19setNeedsStyleRecalcENS_15StyleChangeTypeE
 __ZNK7WebCore4Page10pluginDataEv
 __ZNK7WebCore4Page34inLowQualityImageInterpolationModeEv
 __ZNK7WebCore4Page9groupNameEv
index ca971b1..312b75b 100644 (file)
                                9392F1410AD185F400691BD4 /* RenderCounter.h */,
                                BC77CEC70FF01CBE0070887B /* RenderDataGrid.cpp */,
                                BC77CEB20FF017F20070887B /* RenderDataGrid.h */,
+                               0F5B7A5210F65D7A00376302 /* RenderEmbeddedObject.cpp */,
+                               0F5B7A5310F65D7A00376302 /* RenderEmbeddedObject.h */,
                                A8EA73AF0A1900E300A8EF5F /* RenderFieldset.cpp */,
                                A8EA73B00A1900E300A8EF5F /* RenderFieldset.h */,
                                066C772E0AB603FD00238CC4 /* RenderFileUploadControl.cpp */,
                                A871DECD0A1530C700B12A68 /* RenderPartObject.h */,
                                853CA9EE0AEEC657002372DC /* RenderPath.cpp */,
                                853CA9EF0AEEC657002372DC /* RenderPath.h */,
-                               0F5B7A5210F65D7A00376302 /* RenderEmbeddedObject.cpp */,
-                               0F5B7A5310F65D7A00376302 /* RenderEmbeddedObject.h */,
                                A871DFDE0A15376B00B12A68 /* RenderReplaced.cpp */,
                                A871DFDF0A15376B00B12A68 /* RenderReplaced.h */,
                                BCA846D40DC67A350026C309 /* RenderReplica.cpp */,
index ad42b04..db32808 100644 (file)
@@ -33,6 +33,7 @@
 #include "HTMLParamElement.h"
 #include "MIMETypeRegistry.h"
 #include "Page.h"
+#include "PluginWidget.h"
 #include "RenderView.h"
 #include "RenderWidgetProtector.h"
 #include "Text.h"
 #include "HTMLVideoElement.h"
 #endif
 
+#if USE(ACCELERATED_COMPOSITING)
+#include "PluginWidget.h"
+#endif
+
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -57,6 +62,21 @@ RenderEmbeddedObject::~RenderEmbeddedObject()
         frameView()->removeWidgetToUpdate(this);
 }
 
+#if USE(ACCELERATED_COMPOSITING)
+bool RenderEmbeddedObject::requiresLayer() const
+{
+    if (RenderPartObject::requiresLayer())
+        return true;
+    
+    return allowsAcceleratedCompositing();
+}
+
+bool RenderEmbeddedObject::allowsAcceleratedCompositing() const
+{
+    return widget() && widget()->isPluginWidget() && static_cast<PluginWidget*>(widget())->platformLayer();
+}
+#endif
+
 static bool isURLAllowed(Document* doc, const String& url)
 {
     if (doc->frame()->page()->frameCount() >= 200)
index ad1911e..bdaea92 100644 (file)
@@ -35,10 +35,18 @@ public:
 
     void updateWidget(bool onlyCreateNonNetscapePlugins);
 
+#if USE(ACCELERATED_COMPOSITING)
+    virtual bool allowsAcceleratedCompositing() const;
+#endif
+
 private:
     virtual const char* renderName() const { return "RenderEmbeddedObject"; }
     virtual bool isEmbeddedObject() const { return true; }
 
+#if USE(ACCELERATED_COMPOSITING)
+    virtual bool requiresLayer() const;
+#endif
+
     virtual void layout();
 };
 
index 6ea7659..0063ea3 100644 (file)
@@ -3302,7 +3302,7 @@ void RenderLayer::repaintIncludingNonCompositingDescendants(RenderBoxModelObject
 
 bool RenderLayer::shouldBeNormalFlowOnly() const
 {
-    return (renderer()->hasOverflowClip() || renderer()->hasReflection() || renderer()->hasMask() || renderer()->isVideo()) &&
+    return (renderer()->hasOverflowClip() || renderer()->hasReflection() || renderer()->hasMask() || renderer()->isVideo() || renderer()->isEmbeddedObject()) &&
            !renderer()->isPositioned() &&
            !renderer()->isRelPositioned() &&
            !renderer()->hasTransform() &&
@@ -3311,7 +3311,7 @@ bool RenderLayer::shouldBeNormalFlowOnly() const
 
 bool RenderLayer::isSelfPaintingLayer() const
 {
-    return !isNormalFlowOnly() || renderer()->hasReflection() || renderer()->hasMask() || renderer()->isTableRow() || renderer()->isVideo();
+    return !isNormalFlowOnly() || renderer()->hasReflection() || renderer()->hasMask() || renderer()->isTableRow() || renderer()->isVideo() || renderer()->isEmbeddedObject();
 }
 
 void RenderLayer::styleChanged(StyleDifference diff, const RenderStyle*)
index d38294b..c14e808 100644 (file)
 #include "HTMLNames.h"
 #include "InspectorTimelineAgent.h"
 #include "KeyframeList.h"
+#include "PluginWidget.h"
 #include "RenderBox.h"
 #include "RenderImage.h"
 #include "RenderLayerCompositor.h"
+#include "RenderEmbeddedObject.h"
 #include "RenderVideo.h"
 #include "RenderView.h"
 #include "Settings.h"
@@ -197,6 +199,11 @@ bool RenderLayerBacking::updateGraphicsLayerConfiguration()
     if (isDirectlyCompositedImage())
         updateImageContents();
 
+    if (renderer()->isEmbeddedObject() && toRenderEmbeddedObject(renderer())->allowsAcceleratedCompositing()) {
+        PluginWidget* pluginWidget = static_cast<PluginWidget*>(toRenderEmbeddedObject(renderer())->widget());
+        m_graphicsLayer->setContentsToMedia(pluginWidget->platformLayer());
+    }
+
 #if ENABLE(3D_CANVAS)    
     if (is3DCanvas(renderer())) {
         HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(renderer()->node());
index f2ffb57..cbc1849 100644 (file)
@@ -39,6 +39,7 @@
 #include "HTMLCanvasElement.h"
 #include "Page.h"
 #include "RenderLayerBacking.h"
+#include "RenderEmbeddedObject.h"
 #include "RenderVideo.h"
 #include "RenderView.h"
 #include "Settings.h"
@@ -59,6 +60,8 @@ bool WebCoreHas3DRendering = true;
 
 namespace WebCore {
 
+using namespace HTMLNames;
+
 struct CompositingState {
     CompositingState(RenderLayer* compAncestor)
         : m_compositingAncestor(compAncestor)
@@ -885,15 +888,17 @@ bool RenderLayerCompositor::needsToBeComposited(const RenderLayer* layer) const
 // Use needsToBeComposited() to determine if a RL actually needs a compositing layer.
 // static
 bool RenderLayerCompositor::requiresCompositingLayer(const RenderLayer* layer) const
-{    
+{
+    RenderObject* renderer = layer->renderer();
     // The root layer always has a compositing layer, but it may not have backing.
     return (inCompositingMode() && layer->isRootLayer()) ||
-             requiresCompositingForTransform(layer->renderer()) ||
-             requiresCompositingForVideo(layer->renderer()) ||
-             requiresCompositingForCanvas(layer->renderer()) ||
-             layer->renderer()->style()->backfaceVisibility() == BackfaceVisibilityHidden ||
+             requiresCompositingForTransform(renderer) ||
+             requiresCompositingForVideo(renderer) ||
+             requiresCompositingForCanvas(renderer) ||
+             requiresCompositingForPlugin(renderer) ||
+             renderer->style()->backfaceVisibility() == BackfaceVisibilityHidden ||
              clipsCompositingDescendants(layer) ||
-             requiresCompositingForAnimation(layer->renderer());
+             requiresCompositingForAnimation(renderer);
 }
 
 // Return true if the given layer has some ancestor in the RenderLayer hierarchy that clips,
@@ -975,6 +980,11 @@ bool RenderLayerCompositor::requiresCompositingForCanvas(RenderObject* renderer)
     return false;
 }
 
+bool RenderLayerCompositor::requiresCompositingForPlugin(RenderObject* renderer) const
+{
+    return renderer->isEmbeddedObject() && toRenderEmbeddedObject(renderer)->allowsAcceleratedCompositing();
+}
+
 bool RenderLayerCompositor::requiresCompositingForAnimation(RenderObject* renderer) const
 {
     if (AnimationController* animController = renderer->animation()) {
index 73683f3..a9c7ea0 100644 (file)
@@ -173,6 +173,7 @@ private:
     bool requiresCompositingForTransform(RenderObject*) const;
     bool requiresCompositingForVideo(RenderObject*) const;
     bool requiresCompositingForCanvas(RenderObject*) const;
+    bool requiresCompositingForPlugin(RenderObject*) const;
     bool requiresCompositingWhenDescendantsAreCompositing(RenderObject*) const;
 
 private:
index 8bb99d2..00d9021 100644 (file)
@@ -1,3 +1,19 @@
+2010-01-11  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Kevin Decker.
+
+        https://bugs.webkit.org/show_bug.cgi?id=33455
+        Allows plugins to participate in accelerated compositing
+
+        * Plugins/Hosted/WebHostedNetscapePluginView.mm:
+        (-[WebHostedNetscapePluginView createPlugin]):
+        * Plugins/WebNetscapePluginView.mm:
+        (-[WebNetscapePluginView createPlugin]): If accelerated compositing is
+        available, don't use a layer-backed NSView for plugins. Instead, tickle the
+        accelerated compositing code via setNeedsStyleRecalc(SyntheticStyleChange),
+        which will parent the plugin's layer in the accelerated compositing layer
+        tree.
+
 2010-01-09  Adam Barth  <abarth@webkit.org>
 
         Reviewed by Darin Adler.
index 1e10c10..1819d91 100644 (file)
@@ -116,7 +116,11 @@ extern "C" {
         _softwareRenderer = WKSoftwareCARendererCreate(_proxy->renderContextID());
     else {
         _pluginLayer = WKMakeRenderLayer(_proxy->renderContextID());
-        self.wantsLayer = YES;
+
+        if (accleratedCompositingEnabled)
+            [self element]->setNeedsStyleRecalc(SyntheticStyleChange);
+        else
+            self.wantsLayer = YES;
     }
     
     // Update the window frame.
index 00c7b42..7057da4 100644 (file)
@@ -1089,10 +1089,18 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
     if (drawingModel == NPDrawingModelCoreAnimation) {
         void *value = 0;
         if ([_pluginPackage.get() pluginFuncs]->getvalue(plugin, NPPVpluginCoreAnimationLayer, &value) == NPERR_NO_ERROR && value) {
-            
+
             // The plug-in gives us a retained layer.
             _pluginLayer.adoptNS((CALayer *)value);
-            [self setWantsLayer:YES];
+
+            BOOL accleratedCompositingEnabled = false;
+#if USE(ACCELERATED_COMPOSITING)
+            accleratedCompositingEnabled = [[[self webView] preferences] acceleratedCompositingEnabled];
+#endif
+            if (accleratedCompositingEnabled)
+                [self element]->setNeedsStyleRecalc(SyntheticStyleChange);
+            else
+                [self setWantsLayer:YES];
             LOG(Plugins, "%@ is using Core Animation drawing model with layer %@", _pluginPackage.get(), _pluginLayer.get());
         }