Home | History | Annotate | Download | only in platform
      1 /*
      2  * Copyright (C) 2011 Google 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  *
      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.
     13  *
     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.
     24  */
     25 
     26 #ifndef WebLayerTreeView_h
     27 #define WebLayerTreeView_h
     28 
     29 #include "WebColor.h"
     30 #include "WebCommon.h"
     31 #include "WebFloatPoint.h"
     32 #include "WebNonCopyable.h"
     33 #include "WebPrivateOwnPtr.h"
     34 #include "WebSize.h"
     35 
     36 namespace WebKit {
     37 class WebGraphicsContext3D;
     38 class WebLayer;
     39 struct WebPoint;
     40 struct WebRect;
     41 struct WebRenderingStats;
     42 
     43 class WebLayerTreeView {
     44 public:
     45     virtual ~WebLayerTreeView() { }
     46 
     47     // Initialization and lifecycle --------------------------------------
     48 
     49     // Indicates that the compositing surface used by this WebLayerTreeView is ready to use.
     50     // A WebLayerTreeView may request a context from its client before the surface is ready,
     51     // but it won't attempt to use it.
     52     virtual void setSurfaceReady() = 0;
     53 
     54     // Sets the root of the tree. The root is set by way of the constructor.
     55     virtual void setRootLayer(const WebLayer&) = 0;
     56     virtual void clearRootLayer() = 0;
     57 
     58 
     59     // View properties ---------------------------------------------------
     60 
     61     virtual void setViewportSize(const WebSize& layoutViewportSize, const WebSize& deviceViewportSize) = 0;
     62     // Gives the viewport size in layer space.
     63     virtual WebSize layoutViewportSize() const = 0;
     64     // Gives the viewport size in physical device pixels (may be different
     65     // from the above if there exists page scale, device scale or fixed layout
     66     // mode).
     67     virtual WebSize deviceViewportSize() const = 0;
     68 
     69     virtual void setDeviceScaleFactor(float) = 0;
     70     virtual float deviceScaleFactor() const = 0;
     71 
     72     // Sets the background color for the viewport.
     73     virtual void setBackgroundColor(WebColor) = 0;
     74 
     75     // Sets the background transparency for the viewport. The default is 'false'.
     76     virtual void setHasTransparentBackground(bool) = 0;
     77 
     78     // Sets whether this view is visible. In threaded mode, a view that is not visible will not
     79     // composite or trigger updateAnimations() or layout() calls until it becomes visible.
     80     virtual void setVisible(bool) = 0;
     81 
     82     // Sets the current page scale factor and minimum / maximum limits. Both limits are initially 1 (no page scale allowed).
     83     virtual void setPageScaleFactorAndLimits(float pageScaleFactor, float minimum, float maximum) = 0;
     84 
     85     // Starts an animation of the page scale to a target scale factor and scroll offset.
     86     // If useAnchor is true, destination is a point on the screen that will remain fixed for the duration of the animation.
     87     // If useAnchor is false, destination is the final top-left scroll position.
     88     virtual void startPageScaleAnimation(const WebPoint& destination, bool useAnchor, float newPageScale, double durationSec) = 0;
     89 
     90 
     91     // Flow control and scheduling ---------------------------------------
     92 
     93     // Indicates that an animation needs to be updated.
     94     virtual void setNeedsAnimate() = 0;
     95 
     96     // Indicates that the view needs to be redrawn. This is typically used when the frontbuffer is damaged.
     97     virtual void setNeedsRedraw() = 0;
     98 
     99     // Indicates whether a commit is pending.
    100     virtual bool commitRequested() const = 0;
    101 
    102     // Relays the end of a fling animation.
    103     virtual void didStopFlinging() { }
    104 
    105     // Composites and attempts to read back the result into the provided
    106     // buffer. If it wasn't possible, e.g. due to context lost, will return
    107     // false. Pixel format is 32bit (RGBA), and the provided buffer must be
    108     // large enough contain viewportSize().width() * viewportSize().height()
    109     // pixels. The WebLayerTreeView does not assume ownership of the buffer.
    110     // The buffer is not modified if the false is returned.
    111     virtual bool compositeAndReadback(void *pixels, const WebRect&) = 0;
    112 
    113     // Blocks until the most recently composited frame has finished rendering on the GPU.
    114     // This can have a significant performance impact and should be used with care.
    115     virtual void finishAllRendering() = 0;
    116 
    117     // Prevents updates to layer tree from becoming visible.
    118     virtual void setDeferCommits(bool deferCommits) { }
    119 
    120     // Take responsiblity for this layer's animations, even if this layer hasn't yet
    121     // been added to the tree.
    122     virtual void registerForAnimations(WebLayer* layer) { }
    123 
    124     // Identify key layers to the compositor when using the pinch virtual viewport.
    125     virtual void registerPinchViewportLayers(
    126         const WebLayer* innerViewportContainerLayer,
    127         const WebLayer* pageScaleLayerLayer,
    128         const WebLayer* innerViewportScrollLayer,
    129         const WebLayer* outerViewportScrollLayer,
    130         const WebLayer* innerViewportHorizontalScrollbarLayer,
    131         const WebLayer* innerViewportVerticalScrollbarLayer) { }
    132     virtual void clearPinchViewportLayers() { }
    133 
    134     // Debugging / dangerous ---------------------------------------------
    135 
    136     // Toggles the FPS counter in the HUD layer
    137     virtual void setShowFPSCounter(bool) { }
    138 
    139     // Toggles the paint rects in the HUD layer
    140     virtual void setShowPaintRects(bool) { }
    141 
    142     // Toggles the debug borders on layers
    143     virtual void setShowDebugBorders(bool) { }
    144 
    145     // Toggles continuous painting
    146     virtual void setContinuousPaintingEnabled(bool) { }
    147 
    148     // Toggles scroll bottleneck rects on the HUD layer
    149     virtual void setShowScrollBottleneckRects(bool) { }
    150 };
    151 
    152 } // namespace WebKit
    153 
    154 #endif // WebLayerTreeView_h
    155