<?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>92300</bug_id>
          
          <creation_ts>2012-07-25 14:24:36 -0700</creation_ts>
          <short_desc>[BlackBerry] Rephrase suspend/resume condition to guard against crashes</short_desc>
          <delta_ts>2012-07-26 07:47:41 -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>WebKit BlackBerry</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="Jakob Petsovits">jpetsovits</reporter>
          <assigned_to name="Jakob Petsovits">jpetsovits</assigned_to>
          <cc>anilsson</cc>
    
    <cc>manyoso</cc>
    
    <cc>mifenton</cc>
    
    <cc>staikos</cc>
    
    <cc>tonikitoo</cc>
    
    <cc>webkit.review.bot</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>678467</commentid>
    <comment_count>0</comment_count>
    <who name="Jakob Petsovits">jpetsovits</who>
    <bug_when>2012-07-25 14:24:36 -0700</bug_when>
    <thetext>In short, we&apos;re getting a crash when the WebPageCompositor is set to 0 and its context is 0 too. Fixing the crash is easy, I hope this patch accomplishes it in the most correct way possible. Patch below.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>678472</commentid>
    <comment_count>1</comment_count>
      <attachid>154445</attachid>
    <who name="Jakob Petsovits">jpetsovits</who>
    <bug_when>2012-07-25 14:27:58 -0700</bug_when>
    <thetext>Created attachment 154445
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>678577</commentid>
    <comment_count>2</comment_count>
      <attachid>154445</attachid>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-07-25 16:15:20 -0700</bug_when>
    <thetext>Comment on attachment 154445
Patch

Clearing flags on attachment: 154445

Committed r123673: &lt;http://trac.webkit.org/changeset/123673&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>678578</commentid>
    <comment_count>3</comment_count>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-07-25 16:15:24 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>678879</commentid>
    <comment_count>4</comment_count>
    <who name="Arvid Nilsson">anilsson</who>
    <bug_when>2012-07-25 22:58:55 -0700</bug_when>
    <thetext>I would have used &quot;if (m_compositor-&gt;context() || m_client-&gt;window())&quot; (going from memory, not sure if this is right?).

My thinking is that it&apos;s actually the platform::gles2context that provides the buffer. There might be an internal m_compositor due to AC layers. And we might do unbalanced suspend.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>679004</commentid>
    <comment_count>5</comment_count>
    <who name="Arvid Nilsson">anilsson</who>
    <bug_when>2012-07-26 01:16:27 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; I would have used &quot;if (m_compositor-&gt;context() || m_client-&gt;window())&quot; (going from memory, not sure if this is right?).
&gt; 
&gt; My thinking is that it&apos;s actually the platform::gles2context that provides the buffer. There might be an internal m_compositor due to AC layers. And we might do unbalanced suspend.

Jakob correctly pointed out to me that the reason we&apos;re here in the first place is that m_compositor-&gt;context() can disappear without notice. So that would be a bad idea.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>679016</commentid>
    <comment_count>6</comment_count>
    <who name="Arvid Nilsson">anilsson</who>
    <bug_when>2012-07-26 01:25:36 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; (In reply to comment #4)
&gt; &gt; I would have used &quot;if (m_compositor-&gt;context() || m_client-&gt;window())&quot; (going from memory, not sure if this is right?).
&gt; &gt; 
&gt; &gt; My thinking is that it&apos;s actually the platform::gles2context that provides the buffer. There might be an internal m_compositor due to AC layers. And we might do unbalanced suspend.
&gt; 
&gt; Jakob correctly pointed out to me that the reason we&apos;re here in the first place is that m_compositor-&gt;context() can disappear without notice. So that would be a bad idea.

The reason I brought this up is I thought somebody had landed the patch to suspend the backingstore if there&apos;s no window at the time the WebPage is created, but nobody seems to be doing that yet...

I was thinking of a scenario where there&apos;s no window, we&apos;re suspended, and we set the external compositor, and it should resume.

But it seems we&apos;re not initially suspended after all, window or no window.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>679143</commentid>
    <comment_count>7</comment_count>
    <who name="Arvid Nilsson">anilsson</who>
    <bug_when>2012-07-26 04:24:06 -0700</bug_when>
    <thetext>Alright, Jakob showed me the initial suspend is in BackingStore::createSurfaces(). This was introduced in fix for bug #91686.

From the commit message:

&quot;   So, in effect, with this patch applied, the sequence
    of events will look like this:
    
    1) WebPage &amp; BackingStore are initialize, neither window
       nor compositor exists, therefore buffer() returns 0.
       createSurface() therefore suspends screen and
       backingstore.
    2) loadURL() or loadData() is called, web page is
       fully loaded, however we don&apos;t try to render because
       we&apos;re still suspended, still have no target buffer.
    3) A WebPageCompositor is being set from outside.
       At the beginning of WebPage::setCompositor() we still
       don&apos;t have a buffer() so there&apos;s nothing to suspend,
       however, after the sync call to setCompositorHelper()
       the compositor is set so buffer() will return a
       nonzero value, causing us to resume at this point.&quot;

The problem introduced by this patch is that the WebPage::m_compositor is initialized to an internal compositor in WebPagePrivate::initialize:

#if USE(ACCELERATED_COMPOSITING)
    // The compositor will be needed for overlay rendering, so create it
    // unconditionally. It will allocate OpenGL objects lazily, so this incurs
    // no overhead in the unlikely case where the compositor is not needed.
    Platform::userInterfaceThreadMessageClient()-&gt;dispatchSyncMessage(
            createMethodCallMessage(&amp;WebPagePrivate::createCompositor, this));
#endif

so m_compositor is non-0 at this point:

    if (m_compositor || m_client-&gt;window())
        m_backingStore-&gt;d-&gt;suspendScreenAndBackingStoreUpdates();

so it will suspend again, and

    if (m_compositor || m_client-&gt;window()) // the new compositor, if one was set
        m_backingStore-&gt;d-&gt;resumeScreenAndBackingStoreUpdates(BackingStore::RenderAndBlit);

will not balance the suspend count...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>679144</commentid>
    <comment_count>8</comment_count>
    <who name="Arvid Nilsson">anilsson</who>
    <bug_when>2012-07-26 04:27:15 -0700</bug_when>
    <thetext>A possible fix could be

#if USE(ACCELERATED_COMPOSITING)
    // If there&apos;s no window, the client will provide a compositor
    if (m_client-&gt;window()) {
        // The compositor will be needed for overlay rendering, so create it
        // unconditionally. It will allocate OpenGL objects lazily, so this incurs
        // no overhead in the unlikely case where the compositor is not needed.
        Platform::userInterfaceThreadMessageClient()-&gt;dispatchSyncMessage(
                createMethodCallMessage(&amp;WebPagePrivate::createCompositor, this));
    }
#endif

Then the checks in this patch will be valid:

so m_compositor is actually 0 at this point:

    if (m_compositor || m_client-&gt;window())
        m_backingStore-&gt;d-&gt;suspendScreenAndBackingStoreUpdates();</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>679201</commentid>
    <comment_count>9</comment_count>
    <who name="Arvid Nilsson">anilsson</who>
    <bug_when>2012-07-26 05:33:30 -0700</bug_when>
    <thetext>D&apos;oh:

bool WebPagePrivate::createCompositor()
{
    // If there&apos;s no window, the compositor will be supplied by the API client
    if (!m_client-&gt;window())
        return false;

It already contains that line, but when the message is received, not when it&apos;s sent =)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>679276</commentid>
    <comment_count>10</comment_count>
    <who name="Antonio Gomes">tonikitoo</who>
    <bug_when>2012-07-26 06:49:02 -0700</bug_when>
    <thetext>(In reply to comment #7)
&gt; Alright, Jakob showed me the initial suspend is in BackingStore::createSurfaces(). This was introduced in fix for bug #91686.
&gt; 
&gt; From the commit message:
...
&gt; 
&gt; The problem introduced by this patch is that the WebPage::m_compositor is initialized to an internal compositor in WebPagePrivate::initialize:

that was exactly my concern, and Jakob and I had a almost long conversation on IRC.

IMO, we seem to be piling up hacks. Suspending from one place, and relying on conditions to resume it elsewhere by making use of a count-based mechanism is *fragile*.

in a count-based suspend/resume mechanism, each suspend has to match exactly a call to resume without relying on any variable or state, in my mind. Otherwise it can/will fail in a given point, and it is going to be hard to find out where...

:(</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>679325</commentid>
    <comment_count>11</comment_count>
    <who name="Jakob Petsovits">jpetsovits</who>
    <bug_when>2012-07-26 07:47:41 -0700</bug_when>
    <thetext>Oh wow, big discussion here. Sorry for being late to the party. Antonio&apos;s and Arvid&apos;s latest verdicts are correct, it&apos;s unnecessarily fragile but right now there&apos;s no easy way around this unless we make the suspend/resume mechanism into more of a state machine. However for a state machine we need to be able to intercept changing states, which right now is difficult since several objects are provided by outside containers but we don&apos;t get to know about when they change. We should try to work more towards setter methods in WebPage or BackingStore, rather than using getters from &quot;client&quot;-type objects.

So what Arvid and Antonio are saying is right, I just wasn&apos;t in a position to spend more time for a large-scale solution to this issue.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>154445</attachid>
            <date>2012-07-25 14:27:58 -0700</date>
            <delta_ts>2012-07-25 16:15:20 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-92300-20120725172655.patch</filename>
            <type>text/plain</type>
            <size>4028</size>
            <attacher name="Jakob Petsovits">jpetsovits</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTIzNjEwCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViS2l0L2Js
YWNrYmVycnkvQ2hhbmdlTG9nIGIvU291cmNlL1dlYktpdC9ibGFja2JlcnJ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