initial import
[vuplus_webkit] / Source / WebKit2 / UIProcess / DrawingAreaProxyImpl.h
1 /*
2  * Copyright (C) 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef DrawingAreaProxyImpl_h
27 #define DrawingAreaProxyImpl_h
28
29 #include "BackingStore.h"
30 #include "DrawingAreaProxy.h"
31 #include "LayerTreeContext.h"
32 #include "RunLoop.h"
33 #include <wtf/OwnPtr.h>
34 #include <wtf/PassOwnPtr.h>
35
36 namespace WebCore {
37 class Region;
38 }
39
40 namespace WebKit {
41
42 class DrawingAreaProxyImpl : public DrawingAreaProxy {
43 public:
44     static PassOwnPtr<DrawingAreaProxyImpl> create(WebPageProxy*);
45     virtual ~DrawingAreaProxyImpl();
46
47     void paint(BackingStore::PlatformGraphicsContext, const WebCore::IntRect&, WebCore::Region& unpaintedRegion);
48
49 private:
50     explicit DrawingAreaProxyImpl(WebPageProxy*);
51
52     // DrawingAreaProxy
53     virtual bool paint(const WebCore::IntRect&, PlatformDrawingContext);
54     virtual void sizeDidChange();
55     virtual void deviceScaleFactorDidChange();
56     virtual void visibilityDidChange();
57     virtual void setPageIsVisible(bool);
58     virtual void setBackingStoreIsDiscardable(bool);
59     virtual void waitForBackingStoreUpdateOnNextPaint();
60
61     // CoreIPC message handlers
62     virtual void update(uint64_t backingStoreStateID, const UpdateInfo&);
63     virtual void didUpdateBackingStoreState(uint64_t backingStoreStateID, const UpdateInfo&, const LayerTreeContext&);
64     virtual void enterAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&);
65     virtual void exitAcceleratedCompositingMode(uint64_t backingStoreStateID, const UpdateInfo&);
66
67     void incorporateUpdate(const UpdateInfo&);
68
69     enum RespondImmediatelyOrNot { DoNotRespondImmediately, RespondImmediately };
70     void backingStoreStateDidChange(RespondImmediatelyOrNot);
71     void sendUpdateBackingStoreState(RespondImmediatelyOrNot);
72     void waitForAndDispatchDidUpdateBackingStoreState();
73
74 #if USE(ACCELERATED_COMPOSITING)
75     void enterAcceleratedCompositingMode(const LayerTreeContext&);
76     void exitAcceleratedCompositingMode();
77
78     bool isInAcceleratedCompositingMode() const { return !m_layerTreeContext.isEmpty(); }
79 #else
80     bool isInAcceleratedCompositingMode() const { return false; }
81 #endif
82
83     void discardBackingStoreSoon();
84     void discardBackingStore();
85
86     // The state ID corresponding to our current backing store. Updated whenever we allocate
87     // a new backing store. Any messages received that correspond to an earlier state are ignored,
88     // as they don't apply to our current backing store.
89     uint64_t m_currentBackingStoreStateID;
90
91     // The next backing store state ID we will request the web process update to. Incremented
92     // whenever our state changes in a way that will require a new backing store to be allocated.
93     uint64_t m_nextBackingStoreStateID;
94
95 #if USE(ACCELERATED_COMPOSITING)
96     // The current layer tree context.
97     LayerTreeContext m_layerTreeContext;
98 #endif
99
100     // Whether we've sent a UpdateBackingStoreState message and are now waiting for a DidUpdateBackingStoreState message.
101     // Used to throttle UpdateBackingStoreState messages so we don't send them faster than the Web process can handle.
102     bool m_isWaitingForDidUpdateBackingStoreState;
103     
104     // For a new Drawing Area don't draw anything until the WebProcess has sent over the first content.
105     bool m_hasReceivedFirstUpdate;
106
107     bool m_isBackingStoreDiscardable;
108     OwnPtr<BackingStore> m_backingStore;
109
110     RunLoop::Timer<DrawingAreaProxyImpl> m_discardBackingStoreTimer;
111 };
112
113 } // namespace WebKit
114
115 #endif // DrawingAreaProxyImpl_h