initial import
[vuplus_webkit] / Source / WebKit2 / WebProcess / WebPage / DrawingAreaImpl.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 DrawingAreaImpl_h
27 #define DrawingAreaImpl_h
28
29 #include "DrawingArea.h"
30 #include "LayerTreeHost.h"
31 #include "RunLoop.h"
32 #include <WebCore/Region.h>
33
34 namespace WebCore {
35     class GraphicsContext;
36 }
37
38 namespace WebKit {
39
40 class ShareableBitmap;
41 class UpdateInfo;
42
43 class DrawingAreaImpl : public DrawingArea {
44 public:
45     static PassOwnPtr<DrawingAreaImpl> create(WebPage*, const WebPageCreationParameters&);
46     virtual ~DrawingAreaImpl();
47
48     void layerHostDidFlushLayers();
49
50 private:
51     DrawingAreaImpl(WebPage*, const WebPageCreationParameters&);
52
53     // DrawingArea
54     virtual void setNeedsDisplay(const WebCore::IntRect&);
55     virtual void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
56     virtual void setLayerTreeStateIsFrozen(bool);
57     virtual void forceRepaint();
58
59     virtual void enableDisplayThrottling();
60     virtual void disableDisplayThrottling();
61
62     virtual void didInstallPageOverlay();
63     virtual void didUninstallPageOverlay();
64     virtual void setPageOverlayNeedsDisplay(const WebCore::IntRect&);
65     
66     virtual void setRootCompositingLayer(WebCore::GraphicsLayer*);
67     virtual void scheduleCompositingLayerSync();
68     virtual void syncCompositingLayers();
69
70 #if PLATFORM(WIN)
71     virtual void scheduleChildWindowGeometryUpdate(const WindowGeometry&);
72 #endif
73
74     // CoreIPC message handlers.
75     virtual void updateBackingStoreState(uint64_t backingStoreStateID, bool respondImmediately, float deviceScaleFactor, const WebCore::IntSize&, const WebCore::IntSize& scrollOffset);
76     virtual void didUpdate();
77     virtual void suspendPainting();
78     virtual void resumePainting();
79
80     void sendDidUpdateBackingStoreState();
81
82     void enterAcceleratedCompositingMode(WebCore::GraphicsLayer*);
83     void exitAcceleratedCompositingModeSoon();
84     bool exitAcceleratedCompositingModePending() const { return m_exitCompositingTimer.isActive(); }
85     void exitAcceleratedCompositingMode();
86
87     void scheduleDisplay();
88     void displayTimerFired();
89     void display();
90     void display(UpdateInfo&);
91     PassOwnPtr<WebCore::GraphicsContext> createGraphicsContext(ShareableBitmap*);
92
93     uint64_t m_backingStoreStateID;
94
95     WebCore::Region m_dirtyRegion;
96     WebCore::IntRect m_scrollRect;
97     WebCore::IntSize m_scrollOffset;
98
99     // Whether we're currently processing an UpdateBackingStoreState message.
100     bool m_inUpdateBackingStoreState;
101
102     // When true, we should send an UpdateBackingStoreState message instead of any other messages
103     // we normally send to the UI process.
104     bool m_shouldSendDidUpdateBackingStoreState;
105
106     // Whether we're waiting for a DidUpdate message. Used for throttling paints so that the 
107     // web process won't paint more frequent than the UI process can handle.
108     bool m_isWaitingForDidUpdate;
109     
110     // True between sending the 'enter compositing' messages, and the 'exit compositing' message.
111     bool m_compositingAccordingToProxyMessages;
112
113     // When true, we maintain the layer tree in its current state by not leaving accelerated compositing mode
114     // and not scheduling layer flushes.
115     bool m_layerTreeStateIsFrozen;
116
117     // True when we were asked to exit accelerated compositing mode but couldn't because layer tree
118     // state was frozen.
119     bool m_wantsToExitAcceleratedCompositingMode;
120
121     // Whether painting is suspended. We'll still keep track of the dirty region but we 
122     // won't paint until painting has resumed again.
123     bool m_isPaintingSuspended;
124     bool m_alwaysUseCompositing;
125
126     // Whether we should throttle displays to a set update rate on the WebProcess side.
127     bool m_shouldThrottleDisplay;
128
129     double m_lastDisplayTime;
130
131     RunLoop::Timer<DrawingAreaImpl> m_displayTimer;
132     RunLoop::Timer<DrawingAreaImpl> m_exitCompositingTimer;
133
134     // The layer tree host that handles accelerated compositing.
135     RefPtr<LayerTreeHost> m_layerTreeHost;
136 };
137
138 } // namespace WebKit
139
140 #endif // DrawingAreaImpl_h