193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)/*
293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Copyright (C) 2011 Google Inc. All rights reserved.
393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * modification, are permitted provided that the following conditions
693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * are met:
793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 1.  Redistributions of source code must retain the above copyright
993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *     notice, this list of conditions and the following disclaimer.
1093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 2.  Redistributions in binary form must reproduce the above copyright
1193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *     notice, this list of conditions and the following disclaimer in the
1293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *     documentation and/or other materials provided with the distribution.
1393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
1493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
1593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
1893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) */
2593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
2693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#ifndef WebLayerTreeView_h
2793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define WebLayerTreeView_h
2893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
2993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebColor.h"
3093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebCommon.h"
3193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebFloatPoint.h"
3293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebNonCopyable.h"
3393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebPrivateOwnPtr.h"
3493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebSize.h"
3593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)namespace WebKit {
3793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class WebGraphicsContext3D;
3893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class WebLayer;
3993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct WebPoint;
4093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct WebRect;
4193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct WebRenderingStats;
4293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
4393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class WebLayerTreeView {
4493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)public:
4593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual ~WebLayerTreeView() { }
4693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
4793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Initialization and lifecycle --------------------------------------
4893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
4993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Indicates that the compositing surface used by this WebLayerTreeView is ready to use.
5093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // A WebLayerTreeView may request a context from its client before the surface is ready,
5193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // but it won't attempt to use it.
5293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setSurfaceReady() = 0;
5393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
5493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Sets the root of the tree. The root is set by way of the constructor.
5593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setRootLayer(const WebLayer&) = 0;
5693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void clearRootLayer() = 0;
5793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
5893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
5993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // View properties ---------------------------------------------------
6093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
6193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setViewportSize(const WebSize& layoutViewportSize, const WebSize& deviceViewportSize) = 0;
6293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Gives the viewport size in layer space.
6393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual WebSize layoutViewportSize() const = 0;
6493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Gives the viewport size in physical device pixels (may be different
6593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // from the above if there exists page scale, device scale or fixed layout
6693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // mode).
6793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual WebSize deviceViewportSize() const = 0;
6893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
6993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setDeviceScaleFactor(float) = 0;
7093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual float deviceScaleFactor() const = 0;
7193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Sets the background color for the viewport.
7393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setBackgroundColor(WebColor) = 0;
7493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Sets the background transparency for the viewport. The default is 'false'.
7693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setHasTransparentBackground(bool) = 0;
7793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Sets whether this view is visible. In threaded mode, a view that is not visible will not
7993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // composite or trigger updateAnimations() or layout() calls until it becomes visible.
8093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setVisible(bool) = 0;
8193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
8293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Sets the current page scale factor and minimum / maximum limits. Both limits are initially 1 (no page scale allowed).
8393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setPageScaleFactorAndLimits(float pageScaleFactor, float minimum, float maximum) = 0;
8493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
8593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Starts an animation of the page scale to a target scale factor and scroll offset.
8693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // If useAnchor is true, destination is a point on the screen that will remain fixed for the duration of the animation.
8793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // If useAnchor is false, destination is the final top-left scroll position.
8893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void startPageScaleAnimation(const WebPoint& destination, bool useAnchor, float newPageScale, double durationSec) = 0;
8993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Flow control and scheduling ---------------------------------------
9293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Indicates that an animation needs to be updated.
9493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setNeedsAnimate() = 0;
9593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Indicates that the view needs to be redrawn. This is typically used when the frontbuffer is damaged.
9793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setNeedsRedraw() = 0;
9893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Indicates whether a commit is pending.
10093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual bool commitRequested() const = 0;
10193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
10293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Relays the end of a fling animation.
10393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void didStopFlinging() { }
10493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
10593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Composites and attempts to read back the result into the provided
10693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // buffer. If it wasn't possible, e.g. due to context lost, will return
10793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // false. Pixel format is 32bit (RGBA), and the provided buffer must be
10893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // large enough contain viewportSize().width() * viewportSize().height()
10993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // pixels. The WebLayerTreeView does not assume ownership of the buffer.
11093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // The buffer is not modified if the false is returned.
11193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual bool compositeAndReadback(void *pixels, const WebRect&) = 0;
11293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
11393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Blocks until the most recently composited frame has finished rendering on the GPU.
11493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // This can have a significant performance impact and should be used with care.
11593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void finishAllRendering() = 0;
11693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
11793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Prevents updates to layer tree from becoming visible.
11893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setDeferCommits(bool deferCommits) { }
11993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
12093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Take responsiblity for this layer's animations, even if this layer hasn't yet
12193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // been added to the tree.
12293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void registerForAnimations(WebLayer* layer) { }
12393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
124591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    // Identify key layers to the compositor when using the pinch virtual viewport.
125591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    virtual void registerPinchViewportLayers(
126e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        const WebLayer* innerViewportContainerLayer,
127591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        const WebLayer* pageScaleLayerLayer,
128591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        const WebLayer* innerViewportScrollLayer,
129591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        const WebLayer* outerViewportScrollLayer,
130591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        const WebLayer* innerViewportHorizontalScrollbarLayer,
131591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        const WebLayer* innerViewportVerticalScrollbarLayer) { }
132591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    virtual void clearPinchViewportLayers() { }
13393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
13493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Debugging / dangerous ---------------------------------------------
13593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
13693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Toggles the FPS counter in the HUD layer
13793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setShowFPSCounter(bool) { }
13893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
13993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Toggles the paint rects in the HUD layer
14093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setShowPaintRects(bool) { }
14193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
14293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Toggles the debug borders on layers
14393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setShowDebugBorders(bool) { }
14493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
14593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Toggles continuous painting
14693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    virtual void setContinuousPaintingEnabled(bool) { }
147591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
148591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    // Toggles scroll bottleneck rects on the HUD layer
149591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    virtual void setShowScrollBottleneckRects(bool) { }
15093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)};
15193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
15293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} // namespace WebKit
15393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
15493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif // WebLayerTreeView_h
155