<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>90630</bug_id>
          
          <creation_ts>2012-07-05 13:36:08 -0700</creation_ts>
          <short_desc>Drawing to accelerated 2D canvas causes compositor to recompute layer tree</short_desc>
          <delta_ts>2012-07-06 10:47:56 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Justin Novosad">junov</reporter>
          <assigned_to name="Justin Novosad">junov</assigned_to>
          <cc>eric</cc>
    
    <cc>jamesr</cc>
    
    <cc>kbr</cc>
    
    <cc>senorblanco</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>vangelis</cc>
    
    <cc>webkit.review.bot</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>663707</commentid>
    <comment_count>0</comment_count>
    <who name="Justin Novosad">junov</who>
    <bug_when>2012-07-05 13:36:08 -0700</bug_when>
    <thetext>Drawing to accelerated 2D canvas causes compositor to recompute layer tree</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>663714</commentid>
    <comment_count>1</comment_count>
      <attachid>150979</attachid>
    <who name="Justin Novosad">junov</who>
    <bug_when>2012-07-05 13:52:07 -0700</bug_when>
    <thetext>Created attachment 150979
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>663717</commentid>
    <comment_count>2</comment_count>
    <who name="Justin Novosad">junov</who>
    <bug_when>2012-07-05 13:57:31 -0700</bug_when>
    <thetext>A key piece of code that is relevant to this patch is method RenderLayer::contentChanged (not modified by this patch). This is the method that was triggering the rebuild of the compositor tree when a 2D canvas is drawn to.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>663723</commentid>
    <comment_count>3</comment_count>
    <who name="Justin Novosad">junov</who>
    <bug_when>2012-07-05 14:06:57 -0700</bug_when>
    <thetext>kbr expressed concern that we must make sure that accelerated canvas layers will still trigger the compositor in all situations with this change.  I have verified that this is the case: RenderLayer::addChild will trigger the compositor (via RenderLayer::dirtyZOrderLists) when a new canvas is added.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>663724</commentid>
    <comment_count>4</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2012-07-05 14:09:02 -0700</bug_when>
    <thetext>What is the code path that causes the full layer rebuild? Is it via RenderLayer::contentChanged()?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>663731</commentid>
    <comment_count>5</comment_count>
    <who name="Justin Novosad">junov</who>
    <bug_when>2012-07-05 14:37:44 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; What is the code path that causes the full layer rebuild? Is it via RenderLayer::contentChanged()?

Yes.

All the methods in CanvasRenderingContext2D that draw something to the canvas end up calling CanvasRenderingContext2D::didDraw, which calls RenderBoxModelObject::contentChanged(), which calls RenderLAyer::contentChanged()</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>663739</commentid>
    <comment_count>6</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2012-07-05 14:43:49 -0700</bug_when>
    <thetext>But that should only cause a layer rebuild if updateLayerCompositingState() returns true. Does it?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>664124</commentid>
    <comment_count>7</comment_count>
    <who name="Justin Novosad">junov</who>
    <bug_when>2012-07-06 08:28:22 -0700</bug_when>
    <thetext>(In reply to comment #6)
&gt; But that should only cause a layer rebuild if updateLayerCompositingState() returns true. Does it?

updateLayerCompositingState is returning true because RenderLayerBacking::updateGraphicsLayerConfiguration() is returning true because of this bit of code:

else if (isAcceleratedCanvas(renderer)) {
    HTMLCanvasElement* canvas = static_cast&lt;HTMLCanvasElement*&gt;(renderer-&gt;node());
    if (CanvasRenderingContext* context = canvas-&gt;renderingContext())
        m_graphicsLayer-&gt;setContentsToCanvas(context-&gt;platformLayer());
    layerConfigChanged = true;
}

BTW, an important benefit of this patch is that will bypass the call to
updateLayerCompositingState which was a hot spot that I identified in a profiling experiment. When rendering a whole bunch of small primitives in a tight loop, all the calls to updateLayerCompositingState (can be thousands per frame) are often a much heavier burden than the compositor tree rebuild. In some experiments, I&apos;ve seen up to 20% of CPU time being spent there.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>664129</commentid>
    <comment_count>8</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2012-07-06 08:52:49 -0700</bug_when>
    <thetext>(In reply to comment #7)
&gt; (In reply to comment #6)
&gt; &gt; But that should only cause a layer rebuild if updateLayerCompositingState() returns true. Does it?
&gt; 
&gt; updateLayerCompositingState is returning true because RenderLayerBacking::updateGraphicsLayerConfiguration() is returning true because of this bit of code:
&gt; 
&gt; else if (isAcceleratedCanvas(renderer)) {
&gt;     HTMLCanvasElement* canvas = static_cast&lt;HTMLCanvasElement*&gt;(renderer-&gt;node());
&gt;     if (CanvasRenderingContext* context = canvas-&gt;renderingContext())
&gt;         m_graphicsLayer-&gt;setContentsToCanvas(context-&gt;platformLayer());
&gt;     layerConfigChanged = true;
&gt; }

OK, for some reason Mac doesn&apos;t hit this code. I think your original patch is OK.

&gt; BTW, an important benefit of this patch is that will bypass the call to
&gt; updateLayerCompositingState which was a hot spot that I identified in a profiling experiment. When rendering a whole bunch of small primitives in a tight loop, all the calls to updateLayerCompositingState (can be thousands per frame) are often a much heavier burden than the compositor tree rebuild. In some experiments, I&apos;ve seen up to 20% of CPU time being spent there.

Please file a new bug on that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>664170</commentid>
    <comment_count>9</comment_count>
    <who name="Justin Novosad">junov</who>
    <bug_when>2012-07-06 10:16:50 -0700</bug_when>
    <thetext>
&gt; 
&gt; Please file a new bug on that.

Done.
https://bugs.webkit.org/show_bug.cgi?id=90695</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>664175</commentid>
    <comment_count>10</comment_count>
      <attachid>150979</attachid>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2012-07-06 10:23:15 -0700</bug_when>
    <thetext>Comment on attachment 150979
Patch

What is the code path that causes the full layer rebuild? Is it via RenderLayer::contentChanged()?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>664177</commentid>
    <comment_count>11</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2012-07-06 10:23:34 -0700</bug_when>
    <thetext>&gt; What is the code path that causes the full layer rebuild? Is it via RenderLayer::contentChanged()?
Ignore that comment.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>664196</commentid>
    <comment_count>12</comment_count>
      <attachid>150979</attachid>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-07-06 10:47:51 -0700</bug_when>
    <thetext>Comment on attachment 150979
Patch

Clearing flags on attachment: 150979

Committed r121987: &lt;http://trac.webkit.org/changeset/121987&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>664197</commentid>
    <comment_count>13</comment_count>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-07-06 10:47:56 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>150979</attachid>
            <date>2012-07-05 13:52:07 -0700</date>
            <delta_ts>2012-07-06 10:47:51 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-90630-20120705165205.patch</filename>
            <type>text/plain</type>
            <size>2979</size>
            <attacher name="Justin Novosad">junov</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2UvV2Vi
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDEyMTkyMykKKysrIFNvdXJjZS9XZWJDb3JlL0NoYW5n
ZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDIzIEBACisyMDEyLTA3LTA1ICBKdXN0aW4g
Tm92b3NhZCAgPGp1bm92QGNocm9taXVtLm9yZz4KKworICAgICAgICBEcmF3aW5nIHRvIGFjY2Vs
ZXJhdGVkIDJEIGNhbnZhcyBjYXVzZXMgY29tcG9zaXRvciB0byByZWNvbXB1dGUgbGF5ZXIgdHJl
ZQorICAgICAgICBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9OTA2MzAK
KworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAgICBObyBuZXcg
dGVzdHM6IGNvdmVyZWQgYnkgZXhpc3RpbmcgY2FudmFzL2NvbXBvc2l0aW5nIGxheW91dCB0ZXN0
cworCisgICAgICAgIEJlZm9yZSB0aGlzIGNoYW5nZSwgdGhlcmUgd2FzIG5vIGRpc3RpbmN0aW9u
IGJldHdlZW4gY2FudmFzIGNoYW5nZXMKKyAgICAgICAgdGhhdCByZXF1aXJlIHJlY29tcHV0aW5n
IHRoZSBjb21wb3NpdG9yIHRyZWUgYW5kIGNhbnZhcyBjaGFuZ2VzIHRoYXQKKyAgICAgICAgb25s
eSByZXF1aXJlIHJlLWRpc3BsYXkuIFRoZSBuZXcgQ2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mRlckxheWVyQmFja2luZy5jcHAKPT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQot
LS0gU291cmNlL1dlYkNvcmUvcmVuZGVyaW5nL1JlbmRlckxheWVyQmFja2luZy5jcHAJKHJldmlz
aW9uIDEyMTkyMikKKysrIFNvdXJjZS9XZWJDb3JlL3JlbmRlcmluZy9SZW5kZXJMYXllckJhY2tp
bmcuY3BwCSh3b3JraW5nIGNvcHkpCkBAIC0xMDMzLDcgKzEwMzMsNyBAQCB2b2lkIFJlbmRlckxh
eWVyQmFja2luZzo6Y29udGVudENoYW5nZWQoCiAgICAgfQogCiAjaWYgRU5BQkxFKFdFQkdMKSB8
fCBFTkFCTEUoQUNDRUxFUkFURURfMkRfQ0FOVkFTKQotICAgIGlmICgoY2hhbmdlVHlwZSA9PSBD
YW52YXNDaGFuZ2VkKSAmJiBpc0FjY2VsZXJhdGVkQ2FudmFzKHJlbmRlcmVyKCkpKSB7CisgICAg
aWYgKChjaGFuZ2VUeXBlID09IENhbnZhc0NoYW5nZWQgfHwgY2hhbmdlVHlwZSA9PSBDYW52YXNQ
aXhlbHNDaGFuZ2VkKSAmJiBpc0FjY2VsZXJhdGVkQ2FudmFzKHJlbmRlcmVyKCkpKSB7CiAgICAg
ICAgIG1fZ3JhcGhpY3NMYXllci0+c2V0Q29udGVudHNOZWVkc0Rpc3BsYXkoKTsKICAgICAgICAg
cmV0dXJuOwogICAgIH0K
</data>

          </attachment>
      

    </bug>

</bugzilla>