<?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>172883</bug_id>
          
          <creation_ts>2017-06-02 17:05:02 -0700</creation_ts>
          <short_desc>REGRESSION(r216212): RenderReplaced::paint() should not save and restore the context unless it has to</short_desc>
          <delta_ts>2017-06-03 15:01:01 -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>Layout and Rendering</component>
          <version>WebKit 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>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Said Abou-Hallawa">sabouhallawa</reporter>
          <assigned_to name="Wenson Hsieh">wenson_hsieh</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>commit-queue</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>thorton</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wenson_hsieh</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1315297</commentid>
    <comment_count>0</comment_count>
    <who name="Said Abou-Hallawa">sabouhallawa</who>
    <bug_when>2017-06-02 17:05:02 -0700</bug_when>
    <thetext>The change r216212 made RenderReplaced::paint() saves and restores the context every time it is called. However the context should be saved and restored only if the renderer is dragged and it is painted in a low alpha. Restoring the context is an expensive operation and should be called only when we have to. Actually with the low alpha painting case, we may not need the context to be saved and restored. All we need:

At the beginning of the function:
float alpha = paintInfo.context().alpha();

And before it exits:
paintInfo.context().setAlpha(alpha);

This affects the MotionMark scores.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1315298</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2017-06-02 17:05:35 -0700</bug_when>
    <thetext>&lt;rdar://problem/32548614&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1315317</commentid>
    <comment_count>2</comment_count>
      <attachid>311893</attachid>
    <who name="Wenson Hsieh">wenson_hsieh</who>
    <bug_when>2017-06-02 18:02:23 -0700</bug_when>
    <thetext>Created attachment 311893
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1315337</commentid>
    <comment_count>3</comment_count>
      <attachid>311893</attachid>
    <who name="Wenson Hsieh">wenson_hsieh</who>
    <bug_when>2017-06-02 18:59:27 -0700</bug_when>
    <thetext>Comment on attachment 311893
Patch

Thanks Tim!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1315342</commentid>
    <comment_count>4</comment_count>
      <attachid>311893</attachid>
    <who name="Said Abou-Hallawa">sabouhallawa</who>
    <bug_when>2017-06-02 19:27:09 -0700</bug_when>
    <thetext>Comment on attachment 311893
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=311893&amp;action=review

&gt; Source/WebCore/ChangeLog:18
&gt; +        graphics context.

The whole context will be saved and restored because we just changed its alpha. This is still expensive. This might be okay because dragging the renderer is not the common case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1315343</commentid>
    <comment_count>5</comment_count>
      <attachid>311893</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2017-06-02 19:27:31 -0700</bug_when>
    <thetext>Comment on attachment 311893
Patch

Clearing flags on attachment: 311893

Committed r217748: &lt;http://trac.webkit.org/changeset/217748&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1315344</commentid>
    <comment_count>6</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2017-06-02 19:27:33 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1315464</commentid>
    <comment_count>7</comment_count>
      <attachid>311893</attachid>
    <who name="alan">zalan</who>
    <bug_when>2017-06-03 12:48:27 -0700</bug_when>
    <thetext>Comment on attachment 311893
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=311893&amp;action=review

&gt; Source/WebCore/rendering/RenderReplaced.cpp:166
&gt;      if (element() &amp;&amp; element()-&gt;parentOrShadowHostElement()) {
&gt;          auto* parentContainer = element()-&gt;parentOrShadowHostElement();
&gt; -        if (draggedContentContainsReplacedElement(document().markers().markersFor(parentContainer, DocumentMarker::DraggedContent), *element()))
&gt; +        if (draggedContentContainsReplacedElement(document().markers().markersFor(parentContainer, DocumentMarker::DraggedContent), *element())) {
&gt; +            savedGraphicsContext.save();

I&apos;d rather have this as a state somewhere like we have it with selection (since dragging has a start and an end). We make all these calls on every paint when &quot;paints with dragging/all paints --&gt; 0&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1315484</commentid>
    <comment_count>8</comment_count>
      <attachid>311893</attachid>
    <who name="Wenson Hsieh">wenson_hsieh</who>
    <bug_when>2017-06-03 15:01:01 -0700</bug_when>
    <thetext>Comment on attachment 311893
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=311893&amp;action=review

&gt;&gt; Source/WebCore/ChangeLog:18
&gt;&gt; +        graphics context.
&gt; 
&gt; The whole context will be saved and restored because we just changed its alpha. This is still expensive. This might be okay because dragging the renderer is not the common case.

The renderer being dragged is a very rare case -- we should be okay here.

&gt;&gt; Source/WebCore/rendering/RenderReplaced.cpp:166
&gt;&gt; +            savedGraphicsContext.save();
&gt; 
&gt; I&apos;d rather have this as a state somewhere like we have it with selection (since dragging has a start and an end). We make all these calls on every paint when &quot;paints with dragging/all paints --&gt; 0&quot;.

I see. I considered an approach like this, but didn&apos;t want to introduce new state to RenderObject or RenderText. What do you think about the following?
1. Make a new DraggedRange struct that has start/end offsets and make it an optional member of RenderObject.
2. When beginning a drag, use TextIterator to find text/images in the dragged range and set their renderers&apos; dragged ranges.
3. When painting a RenderText or RenderReplaced, inspect this dragged content range to determine whether we need to fade before painting.
4. When dragging concludes, iterate through all nodes in the dragged range and clear their renderers&apos; dragged ranges. Alternately, we could remember exactly which nodes we set dragged ranges for at the beginning of the drag, and unset those.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>311893</attachid>
            <date>2017-06-02 18:02:23 -0700</date>
            <delta_ts>2017-06-02 19:27:31 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-172883-20170602180222.patch</filename>
            <type>text/plain</type>
            <size>2919</size>
            <attacher name="Wenson Hsieh">wenson_hsieh</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjE3Njg4CmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggOGRjOGMzZTcyNjNlN2I4
MTQ1NWYzOTRlOTM3NWY0MTZkYTU0ZjQwYi4uNzAxM2MyMzY2NTMxOGQwY2NjY2ZmNjYyMzI5Mzli
OWE4MTM1ZTNiOCAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9XZWJDb3JlL0NoYW5nZUxvZwpAQCAtMSwzICsxLDI1IEBACisyMDE3LTA2LTAyICBXZW5z
b24gSHNpZWggIDx3ZW5zb25faHNpZWhAYXBwbGUuY29tPgorCisgICAgICAgIFJFR1JFU1NJT04o
cjIxNjIxMik6IFJlbmRlclJlcGxhY2VkOjpwYWludCgpIHNob3VsZCBub3Qgc2F2ZSBhbmQgcmVz
dG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ldEFscGhhKDAuMjUpOworICAgICAgICB9CiAgICAg
fQogCiAgICAgTGF5b3V0UG9pbnQgYWRqdXN0ZWRQYWludE9mZnNldCA9IHBhaW50T2Zmc2V0ICsg
bG9jYXRpb24oKTsK
</data>

          </attachment>
      

    </bug>

</bugzilla>