2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef WebLayerTreeView_h
27 #define WebLayerTreeView_h
30 #include "WebCommon.h"
31 #include "WebFloatPoint.h"
32 #include "WebNonCopyable.h"
33 #include "WebPrivateOwnPtr.h"
37 class WebGraphicsContext3D;
39 class WebLayerTreeViewClient;
42 struct WebRenderingStats;
44 class WebLayerTreeView {
48 : acceleratePainting(false)
49 , showDebugBorders(false)
50 , showFPSCounter(false)
51 , showPlatformLayerTree(false)
52 , showPaintRects(false)
53 , renderVSyncEnabled(true)
54 , renderVSyncNotificationEnabled(false)
55 , perTilePaintingEnabled(false)
56 , partialSwapEnabled(false)
57 , acceleratedAnimationEnabled(true)
58 , pageScalePinchZoomEnabled(false)
59 , recordRenderingStats(false)
61 , defaultTileSize(WebSize(256, 256))
62 , maxUntiledLayerSize(WebSize(512, 512))
66 bool acceleratePainting;
67 bool showDebugBorders;
69 bool showPlatformLayerTree;
71 bool renderVSyncEnabled;
72 bool renderVSyncNotificationEnabled;
73 bool perTilePaintingEnabled;
74 bool partialSwapEnabled;
75 bool acceleratedAnimationEnabled;
76 bool pageScalePinchZoomEnabled;
77 bool recordRenderingStats;
79 WebSize defaultTileSize;
80 WebSize maxUntiledLayerSize;
83 virtual ~WebLayerTreeView() { }
85 // Initialization and lifecycle --------------------------------------
87 // Indicates that the compositing surface used by this WebLayerTreeView is ready to use.
88 // A WebLayerTreeView may request a context from its client before the surface is ready,
89 // but it won't attempt to use it.
90 virtual void setSurfaceReady() = 0;
92 // Sets the root of the tree. The root is set by way of the constructor.
93 virtual void setRootLayer(const WebLayer&) = 0;
94 virtual void clearRootLayer() = 0;
97 // View properties ---------------------------------------------------
99 virtual void setViewportSize(const WebSize& layoutViewportSize, const WebSize& deviceViewportSize) = 0;
100 // Gives the viewport size in layer space.
101 virtual WebSize layoutViewportSize() const = 0;
102 // Gives the viewport size in physical device pixels (may be different
103 // from the above if there exists page scale, device scale or fixed layout
105 virtual WebSize deviceViewportSize() const = 0;
107 // FIXME: remove this after WebKit roll
108 virtual WebFloatPoint adjustEventPointForPinchZoom(const WebFloatPoint& p) const { return p; }
110 virtual void setDeviceScaleFactor(float) = 0;
111 virtual float deviceScaleFactor() const = 0;
113 // Sets the background color for the viewport.
114 virtual void setBackgroundColor(WebColor) = 0;
116 // Sets the background transparency for the viewport. The default is 'false'.
117 virtual void setHasTransparentBackground(bool) = 0;
119 // Sets whether this view is visible. In threaded mode, a view that is not visible will not
120 // composite or trigger updateAnimations() or layout() calls until it becomes visible.
121 virtual void setVisible(bool) = 0;
123 // Sets the current page scale factor and minimum / maximum limits. Both limits are initially 1 (no page scale allowed).
124 virtual void setPageScaleFactorAndLimits(float pageScaleFactor, float minimum, float maximum) = 0;
126 // Starts an animation of the page scale to a target scale factor and scroll offset.
127 // If useAnchor is true, destination is a point on the screen that will remain fixed for the duration of the animation.
128 // If useAnchor is false, destination is the final top-left scroll position.
129 virtual void startPageScaleAnimation(const WebPoint& destination, bool useAnchor, float newPageScale, double durationSec) = 0;
132 // Flow control and scheduling ---------------------------------------
134 // Requests an updateAnimations() call.
135 virtual void setNeedsAnimate() = 0;
137 // Indicates that the view needs to be redrawn. This is typically used when the frontbuffer is damaged.
138 virtual void setNeedsRedraw() = 0;
140 // Indicates whether a commit is pending.
141 virtual bool commitRequested() const = 0;
143 // Triggers a compositing pass. If the compositor thread was not
144 // enabled via WebCompositorSupport::initialize, the compositing pass happens
145 // immediately. If it is enabled, the compositing pass will happen at a
146 // later time. Before the compositing pass happens (i.e. before composite()
147 // returns when the compositor thread is disabled), WebContentLayers will be
148 // asked to paint their dirty region, through
149 // WebContentLayerClient::paintContents.
150 virtual void composite() = 0;
152 // Immediately update animations. This should only be used when frame scheduling is handled by
153 // the WebLayerTreeView user and not internally by the compositor, meaning only in single-threaded
155 virtual void updateAnimations(double frameBeginTime) = 0;
157 // Relays the end of a fling animation.
158 virtual void didStopFlinging() { }
160 // Composites and attempts to read back the result into the provided
161 // buffer. If it wasn't possible, e.g. due to context lost, will return
162 // false. Pixel format is 32bit (RGBA), and the provided buffer must be
163 // large enough contain viewportSize().width() * viewportSize().height()
164 // pixels. The WebLayerTreeView does not assume ownership of the buffer.
165 // The buffer is not modified if the false is returned.
166 virtual bool compositeAndReadback(void *pixels, const WebRect&) = 0;
168 // Blocks until the most recently composited frame has finished rendering on the GPU.
169 // This can have a significant performance impact and should be used with care.
170 virtual void finishAllRendering() = 0;
172 // Prevents updates to layer tree from becoming visible.
173 virtual void setDeferCommits(bool deferCommits) { }
175 // Take responsiblity for this layer's animations, even if this layer hasn't yet
176 // been added to the tree.
177 virtual void registerForAnimations(WebLayer* layer) { }
179 // Debugging / dangerous ---------------------------------------------
181 // Fills in a WebRenderingStats struct containing information about the state of the compositor.
182 // This call is relatively expensive in threaded mode as it blocks on the compositor thread.
183 virtual void renderingStats(WebRenderingStats&) const = 0;
185 // Toggles the FPS counter in the HUD layer
186 virtual void setShowFPSCounter(bool) { }
188 // Toggles the paint rects in the HUD layer
189 virtual void setShowPaintRects(bool) { }
191 // Toggles the debug borders on layers
192 virtual void setShowDebugBorders(bool) { }
194 // Toggles continuous painting
195 virtual void setContinuousPaintingEnabled(bool) { }
197 // FIXME: Remove this.
198 virtual void loseCompositorContext(int numTimes) { }
201 } // namespace WebKit
203 #endif // WebLayerTreeView_h