1/*
2 * Copyright (C) 2010 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 DrawingArea_h
27#define DrawingArea_h
28
29#include "DrawingAreaInfo.h"
30#include "LayerTreeContext.h"
31#include <WebCore/FloatRect.h>
32#include <WebCore/IntRect.h>
33#include <WebCore/LayerFlushThrottleState.h>
34#include <WebCore/PlatformScreen.h>
35#include <WebCore/ViewState.h>
36#include <functional>
37#include <wtf/Forward.h>
38#include <wtf/Noncopyable.h>
39
40namespace IPC {
41class Connection;
42class MessageDecoder;
43}
44
45namespace WebCore {
46class DisplayRefreshMonitor;
47class FrameView;
48class GraphicsLayer;
49class GraphicsLayerFactory;
50}
51
52namespace WebKit {
53
54struct ColorSpaceData;
55class LayerTreeHost;
56class WebPage;
57struct WebPageCreationParameters;
58struct WebPreferencesStore;
59
60class DrawingArea {
61    WTF_MAKE_NONCOPYABLE(DrawingArea);
62
63public:
64    static std::unique_ptr<DrawingArea> create(WebPage&, const WebPageCreationParameters&);
65    virtual ~DrawingArea();
66
67    DrawingAreaType type() const { return m_type; }
68
69    void didReceiveDrawingAreaMessage(IPC::Connection*, IPC::MessageDecoder&);
70
71    virtual void setNeedsDisplay() = 0;
72    virtual void setNeedsDisplayInRect(const WebCore::IntRect&) = 0;
73    virtual void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) = 0;
74
75    // FIXME: These should be pure virtual.
76    virtual void pageBackgroundTransparencyChanged() { }
77    virtual void forceRepaint() { }
78    virtual bool forceRepaintAsync(uint64_t /*callbackID*/) { return false; }
79    virtual void setLayerTreeStateIsFrozen(bool) { }
80    virtual bool layerTreeStateIsFrozen() const { return false; }
81    virtual LayerTreeHost* layerTreeHost() const { return 0; }
82
83    virtual void setPaintingEnabled(bool) { }
84    virtual void updatePreferences(const WebPreferencesStore&) { }
85    virtual void mainFrameContentSizeChanged(const WebCore::IntSize&) { }
86
87#if PLATFORM(COCOA)
88    virtual void setExposedRect(const WebCore::FloatRect&) = 0;
89    virtual WebCore::FloatRect exposedRect() const = 0;
90    virtual void acceleratedAnimationDidStart(uint64_t /*layerID*/, const String& /*key*/, double /*startTime*/) { }
91#endif
92#if PLATFORM(IOS)
93    virtual void setExposedContentRect(const WebCore::FloatRect&) = 0;
94#endif
95    virtual void mainFrameScrollabilityChanged(bool) { }
96
97    virtual bool supportsAsyncScrolling() { return false; }
98
99    virtual bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) { return false; }
100
101    virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() { return nullptr; }
102    virtual void setRootCompositingLayer(WebCore::GraphicsLayer*) = 0;
103    virtual void scheduleCompositingLayerFlush() = 0;
104    virtual void scheduleCompositingLayerFlushImmediately() = 0;
105
106#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
107    virtual PassRefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID);
108#endif
109
110#if USE(COORDINATED_GRAPHICS)
111    virtual void didReceiveCoordinatedLayerTreeHostMessage(IPC::Connection*, IPC::MessageDecoder&) = 0;
112#endif
113
114    virtual void dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()>);
115
116    virtual void viewStateDidChange(WebCore::ViewState::Flags, bool /*wantsDidUpdateViewState*/) { }
117    virtual void setLayerHostingMode(LayerHostingMode) { }
118
119    virtual bool markLayersVolatileImmediatelyIfPossible() { return true; }
120
121    virtual bool adjustLayerFlushThrottling(WebCore::LayerFlushThrottleState::Flags) { return false; }
122
123protected:
124    DrawingArea(DrawingAreaType, WebPage&);
125
126    DrawingAreaType m_type;
127    WebPage& m_webPage;
128
129private:
130    // Message handlers.
131    // FIXME: These should be pure virtual.
132    virtual void updateBackingStoreState(uint64_t /*backingStoreStateID*/, bool /*respondImmediately*/, float /*deviceScaleFactor*/, const WebCore::IntSize& /*size*/,
133                                         const WebCore::IntSize& /*scrollOffset*/) { }
134    virtual void didUpdate() { }
135
136#if PLATFORM(COCOA)
137    // Used by TiledCoreAnimationDrawingArea.
138    virtual void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition) { }
139    virtual void setDeviceScaleFactor(float) { }
140    virtual void setColorSpace(const ColorSpaceData&) { }
141
142    virtual void adjustTransientZoom(double scale, WebCore::FloatPoint origin) { }
143    virtual void commitTransientZoom(double scale, WebCore::FloatPoint origin) { }
144
145    virtual void addTransactionCallbackID(uint64_t callbackID) { ASSERT_NOT_REACHED(); }
146#endif
147};
148
149#define DRAWING_AREA_TYPE_CASTS(ToValueTypeName, predicate) \
150    TYPE_CASTS_BASE(ToValueTypeName, DrawingArea, value, value->predicate, value.predicate)
151
152} // namespace WebKit
153
154#endif // DrawingArea_h
155