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 <WebCore/Region.h>
32#include <WebCore/RunLoop.h>
33
34namespace WebCore {
35    class GraphicsContext;
36}
37
38namespace WebKit {
39
40class ShareableBitmap;
41class UpdateInfo;
42
43class DrawingAreaImpl : public DrawingArea {
44public:
45    static PassOwnPtr<DrawingAreaImpl> create(WebPage*, const WebPageCreationParameters&);
46    virtual ~DrawingAreaImpl();
47
48    void layerHostDidFlushLayers();
49
50private:
51    DrawingAreaImpl(WebPage*, const WebPageCreationParameters&);
52
53    // DrawingArea
54    virtual void setNeedsDisplay() OVERRIDE;
55    virtual void setNeedsDisplayInRect(const WebCore::IntRect&) OVERRIDE;
56    virtual void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta);
57    virtual void pageBackgroundTransparencyChanged() OVERRIDE;
58    virtual void setLayerTreeStateIsFrozen(bool);
59    virtual bool layerTreeStateIsFrozen() const { return m_layerTreeStateIsFrozen; }
60    virtual LayerTreeHost* layerTreeHost() const { return m_layerTreeHost.get(); }
61    virtual void forceRepaint();
62    virtual bool forceRepaintAsync(uint64_t callbackID);
63
64    virtual void didInstallPageOverlay(PageOverlay*);
65    virtual void didUninstallPageOverlay(PageOverlay*);
66    virtual void setPageOverlayNeedsDisplay(PageOverlay*, const WebCore::IntRect&);
67    virtual void setPageOverlayOpacity(PageOverlay*, float);
68    virtual bool pageOverlayShouldApplyFadeWhenPainting() const;
69
70    virtual void setPaintingEnabled(bool);
71    virtual void updatePreferences(const WebPreferencesStore&) OVERRIDE;
72
73#if USE(ACCELERATED_COMPOSITING)
74    virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() OVERRIDE;
75    virtual void setRootCompositingLayer(WebCore::GraphicsLayer*) OVERRIDE;
76    virtual void scheduleCompositingLayerFlush() OVERRIDE;
77#endif
78
79#if PLATFORM(MAC)
80    virtual void setLayerHostingMode(uint32_t) OVERRIDE;
81#endif
82
83#if USE(COORDINATED_GRAPHICS)
84    virtual void didReceiveCoordinatedLayerTreeHostMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
85#endif
86
87    // CoreIPC message handlers.
88    virtual void updateBackingStoreState(uint64_t backingStoreStateID, bool respondImmediately, float deviceScaleFactor, const WebCore::IntSize&, const WebCore::IntSize& scrollOffset);
89    virtual void didUpdate();
90    virtual void suspendPainting();
91    virtual void resumePainting();
92
93    virtual void pageCustomRepresentationChanged();
94
95    void sendDidUpdateBackingStoreState();
96
97    void enterAcceleratedCompositingMode(WebCore::GraphicsLayer*);
98    void exitAcceleratedCompositingModeSoon();
99    bool exitAcceleratedCompositingModePending() const { return m_exitCompositingTimer.isActive(); }
100    void exitAcceleratedCompositingMode();
101
102    void scheduleDisplay();
103    void displayTimerFired();
104    void display();
105    void display(UpdateInfo&);
106
107    uint64_t m_backingStoreStateID;
108
109    WebCore::Region m_dirtyRegion;
110    WebCore::IntRect m_scrollRect;
111    WebCore::IntSize m_scrollOffset;
112
113    // Whether painting is enabled. If painting is disabled, any calls to setNeedsDisplay and scroll are ignored.
114    bool m_isPaintingEnabled;
115
116    // Whether we're currently processing an UpdateBackingStoreState message.
117    bool m_inUpdateBackingStoreState;
118
119    // When true, we should send an UpdateBackingStoreState message instead of any other messages
120    // we normally send to the UI process.
121    bool m_shouldSendDidUpdateBackingStoreState;
122
123    // Whether we're waiting for a DidUpdate message. Used for throttling paints so that the
124    // web process won't paint more frequent than the UI process can handle.
125    bool m_isWaitingForDidUpdate;
126
127    // True between sending the 'enter compositing' messages, and the 'exit compositing' message.
128    bool m_compositingAccordingToProxyMessages;
129
130    // When true, we maintain the layer tree in its current state by not leaving accelerated compositing mode
131    // and not scheduling layer flushes.
132    bool m_layerTreeStateIsFrozen;
133
134    // True when we were asked to exit accelerated compositing mode but couldn't because layer tree
135    // state was frozen.
136    bool m_wantsToExitAcceleratedCompositingMode;
137
138    // Whether painting is suspended. We'll still keep track of the dirty region but we
139    // won't paint until painting has resumed again.
140    bool m_isPaintingSuspended;
141    bool m_alwaysUseCompositing;
142
143    WebCore::RunLoop::Timer<DrawingAreaImpl> m_displayTimer;
144    WebCore::RunLoop::Timer<DrawingAreaImpl> m_exitCompositingTimer;
145
146    // The layer tree host that handles accelerated compositing.
147    RefPtr<LayerTreeHost> m_layerTreeHost;
148};
149
150} // namespace WebKit
151
152#endif // DrawingAreaImpl_h
153