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#include "config.h"
27#include "DrawingArea.h"
28#include <WebCore/DisplayRefreshMonitor.h>
29#include <WebCore/TransformationMatrix.h>
30#include <wtf/Functional.h>
31
32// Subclasses
33#if PLATFORM(COCOA)
34#include "RemoteLayerTreeDrawingArea.h"
35#include "TiledCoreAnimationDrawingArea.h"
36#else
37#if USE(COORDINATED_GRAPHICS)
38#include "CoordinatedDrawingArea.h"
39#else
40#include "DrawingAreaImpl.h"
41#endif
42#endif
43
44#include "WebPageCreationParameters.h"
45
46using namespace WebCore;
47
48namespace WebKit {
49
50std::unique_ptr<DrawingArea> DrawingArea::create(WebPage& webPage, const WebPageCreationParameters& parameters)
51{
52    switch (parameters.drawingAreaType) {
53#if PLATFORM(COCOA)
54#if !PLATFORM(IOS)
55    case DrawingAreaTypeTiledCoreAnimation:
56        return std::make_unique<TiledCoreAnimationDrawingArea>(webPage, parameters);
57#endif
58    case DrawingAreaTypeRemoteLayerTree:
59        return std::make_unique<RemoteLayerTreeDrawingArea>(webPage, parameters);
60#else
61#if USE(COORDINATED_GRAPHICS)
62    case DrawingAreaTypeCoordinated:
63        return std::make_unique<CoordinatedDrawingArea>(webPage, parameters);
64#else
65    case DrawingAreaTypeImpl:
66        return std::make_unique<DrawingAreaImpl>(webPage, parameters);
67#endif
68#endif
69    }
70
71    return nullptr;
72}
73
74DrawingArea::DrawingArea(DrawingAreaType type, WebPage& webPage)
75    : m_type(type)
76    , m_webPage(webPage)
77{
78}
79
80DrawingArea::~DrawingArea()
81{
82}
83
84void DrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()> function)
85{
86    // Scroll position updates are synchronous by default so we can just call the function right away here.
87    function();
88}
89
90#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
91PassRefPtr<WebCore::DisplayRefreshMonitor> DrawingArea::createDisplayRefreshMonitor(PlatformDisplayID)
92{
93    return nullptr;
94}
95#endif
96
97} // namespace WebKit
98