1/*
2 * Copyright (C) 2009 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. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef GraphicsLayerClient_h
27#define GraphicsLayerClient_h
28
29namespace WebCore {
30
31class FloatPoint;
32class FloatRect;
33class GraphicsContext;
34class GraphicsLayer;
35class IntPoint;
36class IntRect;
37class TransformationMatrix;
38
39enum GraphicsLayerPaintingPhaseFlags {
40    GraphicsLayerPaintBackground = (1 << 0),
41    GraphicsLayerPaintForeground = (1 << 1),
42    GraphicsLayerPaintMask = (1 << 2),
43    GraphicsLayerPaintOverflowContents = (1 << 3),
44    GraphicsLayerPaintCompositedScroll = (1 << 4),
45    GraphicsLayerPaintAllWithOverflowClip = (GraphicsLayerPaintBackground | GraphicsLayerPaintForeground | GraphicsLayerPaintMask)
46};
47typedef unsigned GraphicsLayerPaintingPhase;
48
49enum AnimatedPropertyID {
50    AnimatedPropertyInvalid,
51    AnimatedPropertyWebkitTransform,
52    AnimatedPropertyOpacity,
53    AnimatedPropertyBackgroundColor,
54    AnimatedPropertyWebkitFilter
55};
56
57class GraphicsLayerClient {
58public:
59    virtual ~GraphicsLayerClient() {}
60
61    virtual bool shouldUseTiledBacking(const GraphicsLayer*) const { return false; }
62    virtual void tiledBackingUsageChanged(const GraphicsLayer*, bool /*usingTiledBacking*/) { }
63
64    // Callback for when hardware-accelerated animation started.
65    virtual void notifyAnimationStarted(const GraphicsLayer*, double time) = 0;
66
67    // Notification that a layer property changed that requires a subsequent call to flushCompositingState()
68    // to appear on the screen.
69    virtual void notifyFlushRequired(const GraphicsLayer*) = 0;
70
71    // Notification that this layer requires a flush before the next display refresh.
72    virtual void notifyFlushBeforeDisplayRefresh(const GraphicsLayer*) { }
73
74    virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const FloatRect& inClip) = 0;
75    virtual void didCommitChangesForLayer(const GraphicsLayer*) const { }
76
77    // Provides current transform (taking transform-origin and animations into account). Input matrix has been
78    // initialized to identity already. Returns false if the layer has no transform.
79    virtual bool getCurrentTransform(const GraphicsLayer*, TransformationMatrix&) const { return false; }
80
81    // Allows the client to modify a layer position used during the visibleRect calculation, for example to ignore
82    // scroll overhang.
83    virtual void customPositionForVisibleRectComputation(const GraphicsLayer*, FloatPoint&) const { }
84
85    // Multiplier for backing store size, related to high DPI.
86    virtual float deviceScaleFactor() const { return 1; }
87    // Page scale factor.
88    virtual float pageScaleFactor() const { return 1; }
89    virtual float zoomedOutPageScaleFactor() const { return 0; }
90
91    virtual float contentsScaleMultiplierForNewTiles(const GraphicsLayer*) const { return 1; }
92    virtual bool paintsOpaquelyAtNonIntegralScales(const GraphicsLayer*) const { return false; }
93
94    virtual bool isTrackingRepaints() const { return false; }
95
96    virtual bool shouldSkipLayerInDump(const GraphicsLayer*) const { return false; }
97    virtual bool shouldDumpPropertyForLayer(const GraphicsLayer*, const char*) const { return true; }
98
99    virtual bool shouldAggressivelyRetainTiles(const GraphicsLayer*) const { return false; }
100    virtual bool shouldTemporarilyRetainTileCohorts(const GraphicsLayer*) const { return true; }
101
102    virtual bool needsPixelAligment() const { return false; }
103
104#ifndef NDEBUG
105    // RenderLayerBacking overrides this to verify that it is not
106    // currently painting contents. An ASSERT fails, if it is.
107    // This is executed in GraphicsLayer construction and destruction
108    // to verify that we don't create or destroy GraphicsLayers
109    // while painting.
110    virtual void verifyNotPainting() { }
111#endif
112};
113
114} // namespace WebCore
115
116#endif // GraphicsLayerClient_h
117