<?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>60757</bug_id>
          
          <creation_ts>2011-05-13 04:55:24 -0700</creation_ts>
          <short_desc>[CAIRO] Don&apos;t copy the surface before drawing it into the context in ShareableBitmap::paint()</short_desc>
          <delta_ts>2011-05-27 09:14: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>WebKit2</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>Cairo, Gtk</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Carlos Garcia Campos">cgarcia</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>mrobinson</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>403478</commentid>
    <comment_count>0</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2011-05-13 04:55:24 -0700</bug_when>
    <thetext>cairo_image_surface_create_for_data() is already a shallow copy of the image, so we don&apos;t need to copy it again.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>403479</commentid>
    <comment_count>1</comment_count>
      <attachid>93434</attachid>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2011-05-13 04:58:47 -0700</bug_when>
    <thetext>Created attachment 93434
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>403569</commentid>
    <comment_count>2</comment_count>
    <who name="Martin Robinson">mrobinson</who>
    <bug_when>2011-05-13 08:38:22 -0700</bug_when>
    <thetext>(In reply to comment #0)
&gt; cairo_image_surface_create_for_data() is already a shallow copy of the image, so we don&apos;t need to copy it again.

Notice that in ShareableBitmapCG.cpp (the CG version of this file), the code does a copy of the image. Perhaps that this is just to support self copies though. If that&apos;s the case, it would be better to support self-copies by detecting when the target of the context is the same as the ShareableBitmap. Please contect the Apple team to see what the correct behavior is here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>403570</commentid>
    <comment_count>3</comment_count>
      <attachid>93434</attachid>
    <who name="Martin Robinson">mrobinson</who>
    <bug_when>2011-05-13 08:38:48 -0700</bug_when>
    <thetext>Comment on attachment 93434
Patch

Removing review flag until we get some input from the authors of the CG version of ShareableBitmap.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>403722</commentid>
    <comment_count>4</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2011-05-13 11:58:06 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; (In reply to comment #0)
&gt; &gt; cairo_image_surface_create_for_data() is already a shallow copy of the image, so we don&apos;t need to copy it again.
&gt; 
&gt; Notice that in ShareableBitmapCG.cpp (the CG version of this file), the code does a copy of the image. Perhaps that this is just to support self copies though. If that&apos;s the case, it would be better to support self-copies by detecting when the target of the context is the same as the ShareableBitmap. Please contect the Apple team to see what the correct behavior is here.

But we are creating a new surface and copying that new surface, CG copies the already existing image, I think, which is the same than simply create a new surface with the image data.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>403736</commentid>
    <comment_count>5</comment_count>
    <who name="Martin Robinson">mrobinson</who>
    <bug_when>2011-05-13 12:19:43 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; &gt; Notice that in ShareableBitmapCG.cpp (the CG version of this file), the code does a copy of the image. Perhaps that this is just to support self copies though. If that&apos;s the case, it would be better to support self-copies by detecting when the target of the context is the same as the ShareableBitmap. Please contect the Apple team to see what the correct behavior is here.
&gt; 
&gt; But we are creating a new surface and copying that new surface, CG copies the already existing image, I think, which is the same than simply create a new surface with the image data.

The documentation for CGBitmapContextCreateImage states: 

The CGImage object returned by this function is created by a copy operation. Subsequent changes to the bitmap graphics context do not affect the contents of the returned image. In some cases the copy operation actually follows copy-on-write semantics, so that the actual physical copy of the bits occur only if the underlying data in the bitmap graphics context is modified. As a consequence, you may want to use the resulting image and release it before you perform additional drawing into the bitmap graphics context. In this way, you can avoid the actual physical copy of the data.

In the case of Cairo, unless you explicitly create a copy of the original surface, all surfaces will be backed by the same block of data. Thus it seems the semantics of the blit could deviate if the ShareableBitmap is painting onto itself.

In my opinion, we should check with the authors of the CG version. If the bitmap will never do a self-paint we can make your optimization, otherwise we can optimize only when the backing surface of the GraphicsContext does not contain the same bytes as the ShareableBitmap.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>411478</commentid>
    <comment_count>6</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2011-05-27 09:14:56 -0700</bug_when>
    <thetext>Committed r87517: &lt;http://trac.webkit.org/changeset/87517&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>93434</attachid>
            <date>2011-05-13 04:58:47 -0700</date>
            <delta_ts>2011-05-27 08:35:32 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>wk2-shareable-bitmap-cairo.diff</filename>
            <type>text/plain</type>
            <size>1923</size>
            <attacher name="Carlos Garcia Campos">cgarcia</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJLaXQyL0NoYW5nZUxvZyBiL1NvdXJjZS9XZWJLaXQyL0No
YW5nZUxvZwppbmRleCBkMDljYjNjLi5hNmZkOWVjIDEwMDY0NAotLS0gYS9Tb3VyY2UvV2ViS2l0
Mi9DaGFuZ2VMb2cKKysrIGIvU291cmNlL1dlYktpd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8vU2hhcmVhYmxlQml0bWFwQ2Fpcm8uY3BwCisrKyBiL1NvdXJj
ZS9XZWJLaXQyL1NoYXJlZC9jYWlyby9TaGFyZWFibGVCaXRtYXBDYWlyby5jcHAKQEAgLTUwLDEx
ICs1MCw4IEBAIHZvaWQgU2hhcmVhYmxlQml0bWFwOjpwYWludChHcmFwaGljc0NvbnRleHQmIGNv
bnRleHQsIGNvbnN0IEludFBvaW50JiBkc3RQb2ludCwKICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgQ0FJUk9fRk9STUFUX0FSR0IzMiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbV9zaXpl
LndpZHRoKCksIG1fc2l6ZS5oZWlnaHQoKSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbV9z
aXplLndpZHRoKCkgKiA0KSk7Ci0KLSAgICAvLyBUaGlzIGNvcHkgaXMgbm90IGNvcHktb24td3Jp
dGUsIHNvIHRoaXMgaXMgcHJvYmFibHkgc3ViLW9wdGltYWwuCi0gICAgUmVmUHRyPGNhaXJvX3N1
cmZhY2VfdD4gc3VyZmFjZUNvcHkgPSBjb3B5Q2Fpcm9JbWFnZVN1cmZhY2Uoc3VyZmFjZS5nZXQo
KSk7CiAgICAgRmxvYXRSZWN0IGRlc3RSZWN0KGRzdFBvaW50LCBzcmNSZWN0LnNpemUoKSk7Ci0g
ICAgY29udGV4dC5wbGF0Zm9ybUNvbnRleHQoKS0+ZHJhd1N1cmZhY2VUb0NvbnRleHQoc3VyZmFj
ZUNvcHkuZ2V0KCksIGRlc3RSZWN0LCBzcmNSZWN0LCAmY29udGV4dCk7CisgICAgY29udGV4dC5w
bGF0Zm9ybUNvbnRleHQoKS0+ZHJhd1N1cmZhY2VUb0NvbnRleHQoc3VyZmFjZS5nZXQoKSwgZGVz
dFJlY3QsIHNyY1JlY3QsICZjb250ZXh0KTsKIH0KIAogUGFzc1JlZlB0cjxjYWlyb19zdXJmYWNl
X3Q+IFNoYXJlYWJsZUJpdG1hcDo6Y3JlYXRlQ2Fpcm9TdXJmYWNlKCkK
</data>
<flag name="review"
          id="88618"
          type_id="1"
          status="+"
          setter="mrobinson"
    />
          </attachment>
      

    </bug>

</bugzilla>