2011-01-19 Anders Carlsson <andersca@apple.com>
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jan 2011 21:56:58 +0000 (21:56 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jan 2011 21:56:58 +0000 (21:56 +0000)
        Reviewed by Sam Weinig.

        Suspend/resume painting as the WKView visibility changes
        https://bugs.webkit.org/show_bug.cgi?id=52738

        * UIProcess/DrawingAreaProxy.h:
        (WebKit::DrawingAreaProxy::visibilityDidChange):
        Add new member function. It should really be pure virtual once setPageIsVisible
        is removed.

        * UIProcess/DrawingAreaProxyImpl.cpp:
        (WebKit::DrawingAreaProxyImpl::visibilityDidChange):
        Send SuspendPainting/ResumePainting messages based on whether the view is visible or not.

        (WebKit::DrawingAreaProxyImpl::setPageIsVisible):
        Make this a stub; it should really be removed.

        * UIProcess/WebPageProxy.cpp:
        (WebKit::WebPageProxy::viewStateDidChange):
        Call visibilityDidChange.

        * UIProcess/WebPageProxy.h:
        (WebKit::WebPageProxy::isViewVisible):
        Add new getter.

        * WebProcess/WebPage/DrawingArea.messages.in:
        Add SuspendPainting and ResumePainting messages.

        * WebProcess/WebPage/DrawingAreaImpl.cpp:
        (WebKit::DrawingAreaImpl::DrawingAreaImpl):
        Initialize m_isPaintingSuspended.

        (WebKit::DrawingAreaImpl::suspendPainting):
        Set m_isPaintingSuspended to true and stop the display timer.

        (WebKit::DrawingAreaImpl::resumePainting):
        Set m_isPaintingSuspended to false.

        (WebKit::DrawingAreaImpl::scheduleDisplay):
        (WebKit::DrawingAreaImpl::display):
        Bail if m_isPaintingSuspended is true.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/DrawingAreaProxy.h
Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp
Source/WebKit2/UIProcess/DrawingAreaProxyImpl.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/DrawingArea.h
Source/WebKit2/WebProcess/WebPage/DrawingArea.messages.in
Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp
Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h

index a19808a99e59da75a2f2201065abe102b3b2bcf5..54c63a369406bb162c7ba93611cb2a344a9d7ed0 100644 (file)
@@ -1,3 +1,47 @@
+2011-01-19  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Suspend/resume painting as the WKView visibility changes
+        https://bugs.webkit.org/show_bug.cgi?id=52738
+
+        * UIProcess/DrawingAreaProxy.h:
+        (WebKit::DrawingAreaProxy::visibilityDidChange):
+        Add new member function. It should really be pure virtual once setPageIsVisible
+        is removed.
+
+        * UIProcess/DrawingAreaProxyImpl.cpp:
+        (WebKit::DrawingAreaProxyImpl::visibilityDidChange):
+        Send SuspendPainting/ResumePainting messages based on whether the view is visible or not.
+
+        (WebKit::DrawingAreaProxyImpl::setPageIsVisible):
+        Make this a stub; it should really be removed.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::viewStateDidChange):
+        Call visibilityDidChange.
+
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::isViewVisible):
+        Add new getter.
+
+        * WebProcess/WebPage/DrawingArea.messages.in:
+        Add SuspendPainting and ResumePainting messages.
+
+        * WebProcess/WebPage/DrawingAreaImpl.cpp:
+        (WebKit::DrawingAreaImpl::DrawingAreaImpl):
+        Initialize m_isPaintingSuspended.
+
+        (WebKit::DrawingAreaImpl::suspendPainting):
+        Set m_isPaintingSuspended to true and stop the display timer.
+
+        (WebKit::DrawingAreaImpl::resumePainting):
+        Set m_isPaintingSuspended to false.
+
+        (WebKit::DrawingAreaImpl::scheduleDisplay):
+        (WebKit::DrawingAreaImpl::display):
+        Bail if m_isPaintingSuspended is true.
+
 2011-01-19  Andreas Kling  <kling@webkit.org>
 
         Reviewed by Simon Hausmann.
 2011-01-19  Andreas Kling  <kling@webkit.org>
 
         Reviewed by Simon Hausmann.
index 6bebe12444b82768a73d7382835b5439cf5dcc11..3eb24da463296fcb6e8af8c981c163b9706b34a5 100644 (file)
@@ -65,6 +65,10 @@ public:
     virtual bool paint(const WebCore::IntRect&, PlatformDrawingContext) = 0;
 
     virtual void sizeDidChange() = 0;
     virtual bool paint(const WebCore::IntRect&, PlatformDrawingContext) = 0;
 
     virtual void sizeDidChange() = 0;
+
+    // FIXME: visibilityDidChange() should be pure virtual.
+    virtual void visibilityDidChange() { }
+
     virtual void setPageIsVisible(bool isVisible) = 0;
     
 #if USE(ACCELERATED_COMPOSITING)
     virtual void setPageIsVisible(bool isVisible) = 0;
     
 #if USE(ACCELERATED_COMPOSITING)
index c5f912fcd3e146342ef6f86cd514dea9f2a569a1..155743298b6bcaacfc5a68c3a6e5bbedd10d34a2 100644 (file)
@@ -82,9 +82,20 @@ void DrawingAreaProxyImpl::sizeDidChange()
     sendSetSize();
 }
 
     sendSetSize();
 }
 
-void DrawingAreaProxyImpl::setPageIsVisible(bool pageIsVisible)
+void DrawingAreaProxyImpl::visibilityDidChange()
+{
+    if (!m_webPageProxy->isViewVisible()) {
+        // Suspend painting.
+        m_webPageProxy->process()->send(Messages::DrawingArea::SuspendPainting(), m_webPageProxy->pageID());
+        return;
+    }
+
+    // Resume painting.
+    m_webPageProxy->process()->send(Messages::DrawingArea::ResumePainting(), m_webPageProxy->pageID());
+}
+
+void DrawingAreaProxyImpl::setPageIsVisible(bool)
 {
 {
-    // FIXME: Implement.
 }
 
 void DrawingAreaProxyImpl::attachCompositingContext(uint32_t contextID)
 }
 
 void DrawingAreaProxyImpl::attachCompositingContext(uint32_t contextID)
index fd0e4c3d60e996c64d58bb644bea5950aab77afb..d4c6841a55fc2cbc6640b681944a361b655d7af8 100644 (file)
@@ -46,6 +46,7 @@ private:
     virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
     virtual bool paint(const WebCore::IntRect&, PlatformDrawingContext);
     virtual void sizeDidChange();
     virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
     virtual bool paint(const WebCore::IntRect&, PlatformDrawingContext);
     virtual void sizeDidChange();
+    virtual void visibilityDidChange();
     virtual void setPageIsVisible(bool);
     virtual void attachCompositingContext(uint32_t contextID);
     virtual void detachCompositingContext();
     virtual void setPageIsVisible(bool);
     virtual void attachCompositingContext(uint32_t contextID);
     virtual void detachCompositingContext();
index 2693f9a21294eea03a3397f0fd92e119ddf3af7f..b51581a97d9f822d6dbe77e2cdb412762206433b 100644 (file)
@@ -497,6 +497,7 @@ void WebPageProxy::viewStateDidChange(ViewStateFlags flags)
         bool isVisible = m_pageClient->isViewVisible();
         if (isVisible != m_isVisible) {
             m_isVisible = isVisible;
         bool isVisible = m_pageClient->isViewVisible();
         if (isVisible != m_isVisible) {
             m_isVisible = isVisible;
+            m_drawingArea->visibilityDidChange();
             m_drawingArea->setPageIsVisible(isVisible);
         }
     }
             m_drawingArea->setPageIsVisible(isVisible);
         }
     }
index 2435d7e62f081c8851b8de0bad14cc393ef2e18f..374c9f601124e6376c01b671bc48d6abb6cec423 100644 (file)
@@ -185,6 +185,7 @@ public:
     void viewStateDidChange(ViewStateFlags flags);
 
     WebCore::IntSize viewSize() const;
     void viewStateDidChange(ViewStateFlags flags);
 
     WebCore::IntSize viewSize() const;
+    bool isViewVisible() const { return m_isVisible; }
 
     void executeEditCommand(const String& commandName);
     void validateMenuItem(const String& commandName);
 
     void executeEditCommand(const String& commandName);
     void validateMenuItem(const String& commandName);
index fb39bff46eb227a4abae908c22408edcf17a1141..713994db06ce12ccc5e992a686dd6029f207f904 100644 (file)
@@ -82,6 +82,8 @@ private:
     // FIXME: These should be pure virtual.
     virtual void setSize(const WebCore::IntSize&) { }
     virtual void didUpdate() { }
     // FIXME: These should be pure virtual.
     virtual void setSize(const WebCore::IntSize&) { }
     virtual void didUpdate() { }
+    virtual void suspendPainting() { }
+    virtual void resumePainting() { }
 };
 
 } // namespace WebKit
 };
 
 } // namespace WebKit
index 6c628fbc38170577387238698bbc970a43b400f8..682ef5af7c70655f84a054b20725550a9f17a93e 100644 (file)
@@ -22,5 +22,7 @@
 
 messages -> DrawingArea {
     SetSize(WebCore::IntSize size)
 
 messages -> DrawingArea {
     SetSize(WebCore::IntSize size)
-    DidUpdate()    
+    DidUpdate()
+    SuspendPainting()
+    ResumePainting()
 }
 }
index a5dbf9aa5cd463abd0fd63da1f304ff82639519f..72ed768b44220c1e6b651c3ea26c243c957096c1 100644 (file)
@@ -53,6 +53,7 @@ DrawingAreaImpl::~DrawingAreaImpl()
 DrawingAreaImpl::DrawingAreaImpl(WebPage* webPage, const WebPageCreationParameters& parameters)
     : DrawingArea(DrawingAreaInfo::Impl, parameters.drawingAreaInfo.identifier, webPage)
     , m_isWaitingForDidUpdate(false)
 DrawingAreaImpl::DrawingAreaImpl(WebPage* webPage, const WebPageCreationParameters& parameters)
     : DrawingArea(DrawingAreaInfo::Impl, parameters.drawingAreaInfo.identifier, webPage)
     , m_isWaitingForDidUpdate(false)
+    , m_isPaintingSuspended(!parameters.isVisible)
     , m_displayTimer(WebProcess::shared().runLoop(), this, &DrawingAreaImpl::display)
 {
 }
     , m_displayTimer(WebProcess::shared().runLoop(), this, &DrawingAreaImpl::display)
 {
 }
@@ -156,11 +157,31 @@ void DrawingAreaImpl::didUpdate()
     display();
 }
 
     display();
 }
 
+void DrawingAreaImpl::suspendPainting()
+{
+    ASSERT(!m_isPaintingSuspended);
+
+    m_isPaintingSuspended = true;
+    m_displayTimer.stop();
+}
+
+void DrawingAreaImpl::resumePainting()
+{
+    ASSERT(m_isPaintingSuspended);
+
+    m_isPaintingSuspended = false;
+
+    // FIXME: Repaint if needed.
+}
+
 void DrawingAreaImpl::scheduleDisplay()
 {
     if (m_isWaitingForDidUpdate)
         return;
 
 void DrawingAreaImpl::scheduleDisplay()
 {
     if (m_isWaitingForDidUpdate)
         return;
 
+    if (m_isPaintingSuspended)
+        return;
+
     if (m_dirtyRegion.isEmpty())
         return;
 
     if (m_dirtyRegion.isEmpty())
         return;
 
@@ -172,6 +193,11 @@ void DrawingAreaImpl::scheduleDisplay()
 
 void DrawingAreaImpl::display()
 {
 
 void DrawingAreaImpl::display()
 {
+    ASSERT(!m_isWaitingForDidUpdate);
+
+    if (m_isPaintingSuspended)
+        return;
+
     if (m_dirtyRegion.isEmpty())
         return;
 
     if (m_dirtyRegion.isEmpty())
         return;
 
index fc640ebe80a0b0acba6d74833b08463155d56002..e008adc01b29b022b498baaa36ee2a28e5f4519b 100644 (file)
@@ -55,6 +55,8 @@ private:
     // CoreIPC message handlers.
     virtual void setSize(const WebCore::IntSize&);
     virtual void didUpdate();
     // CoreIPC message handlers.
     virtual void setSize(const WebCore::IntSize&);
     virtual void didUpdate();
+    virtual void suspendPainting();
+    virtual void resumePainting();
 
     void scheduleDisplay();
     void display();
 
     void scheduleDisplay();
     void display();
@@ -67,7 +69,11 @@ private:
     // Whether we're waiting for a DidUpdate message. Used for throttling paints so that the 
     // web process won't paint more frequent than the UI process can handle.
     bool m_isWaitingForDidUpdate;
     // Whether we're waiting for a DidUpdate message. Used for throttling paints so that the 
     // web process won't paint more frequent than the UI process can handle.
     bool m_isWaitingForDidUpdate;
-    
+
+    // Whether painting is suspended. We'll still keep track of the dirty region but we 
+    // won't paint until painting has resumed again.
+    bool m_isPaintingSuspended;
+
     RunLoop::Timer<DrawingAreaImpl> m_displayTimer;
 };
 
     RunLoop::Timer<DrawingAreaImpl> m_displayTimer;
 };