simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 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 COMPUTER, 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 RenderLayerCompositor_h |
| 27 | #define RenderLayerCompositor_h |
| 28 | |
| 29 | #include "RenderLayer.h" |
simon.fraser@apple.com | 994de4f | 2009-06-30 19:53:41 +0000 | [diff] [blame] | 30 | #include "RenderLayerBacking.h" |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | #define PROFILE_LAYER_REBUILD 0 |
| 35 | |
| 36 | class GraphicsLayer; |
simon.fraser@apple.com | 98df11b | 2009-06-18 18:52:09 +0000 | [diff] [blame] | 37 | #if ENABLE(VIDEO) |
| 38 | class RenderVideo; |
| 39 | #endif |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 40 | |
simon.fraser@apple.com | 762661b | 2010-01-28 18:07:14 +0000 | [diff] [blame] | 41 | enum CompositingUpdateType { |
| 42 | CompositingUpdateAfterLayoutOrStyleChange, |
| 43 | CompositingUpdateOnPaitingOrHitTest, |
| 44 | CompositingUpdateOnScroll |
| 45 | }; |
| 46 | |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 47 | // RenderLayerCompositor manages the hierarchy of |
| 48 | // composited RenderLayers. It determines which RenderLayers |
| 49 | // become compositing, and creates and maintains a hierarchy of |
| 50 | // GraphicsLayers based on the RenderLayer painting order. |
| 51 | // |
| 52 | // There is one RenderLayerCompositor per RenderView. |
| 53 | |
| 54 | class RenderLayerCompositor { |
| 55 | public: |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 56 | RenderLayerCompositor(RenderView*); |
| 57 | ~RenderLayerCompositor(); |
| 58 | |
| 59 | // Return true if this RenderView is in "compositing mode" (i.e. has one or more |
| 60 | // composited RenderLayers) |
| 61 | bool inCompositingMode() const { return m_compositing; } |
| 62 | // This will make a compositing layer at the root automatically, and hook up to |
| 63 | // the native view/window system. |
| 64 | void enableCompositingMode(bool enable = true); |
cmarrin@apple.com | 89072a0 | 2009-06-25 22:03:59 +0000 | [diff] [blame] | 65 | |
| 66 | // Returns true if the accelerated compositing is enabled |
cmarrin@apple.com | d285182 | 2009-06-25 22:35:21 +0000 | [diff] [blame] | 67 | bool hasAcceleratedCompositing() const { return m_hasAcceleratedCompositing; } |
cmarrin@apple.com | 89072a0 | 2009-06-25 22:03:59 +0000 | [diff] [blame] | 68 | |
cmarrin@apple.com | f2dff33 | 2009-11-18 19:23:44 +0000 | [diff] [blame] | 69 | bool showDebugBorders() const { return m_showDebugBorders; } |
| 70 | bool showRepaintCounter() const { return m_showRepaintCounter; } |
| 71 | |
| 72 | // Copy the accelerated compositing related flags from Settings |
| 73 | void cacheAcceleratedCompositingFlags(); |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 74 | |
simon.fraser@apple.com | 8717fee | 2009-07-31 23:03:25 +0000 | [diff] [blame] | 75 | // Called when the layer hierarchy needs to be updated (compositing layers have been |
simon.fraser@apple.com | 02f4049 | 2009-07-07 17:15:16 +0000 | [diff] [blame] | 76 | // created, destroyed or re-parented). |
| 77 | void setCompositingLayersNeedRebuild(bool needRebuild = true); |
| 78 | bool compositingLayersNeedRebuild() const { return m_compositingLayersNeedRebuild; } |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 79 | |
simon.fraser@apple.com | 02f4049 | 2009-07-07 17:15:16 +0000 | [diff] [blame] | 80 | // Controls whether or not to consult geometry when deciding which layers need |
| 81 | // to be composited. Defaults to true. |
| 82 | void setCompositingConsultsOverlap(bool b) { m_compositingConsultsOverlap = b; } |
| 83 | bool compositingConsultsOverlap() const { return m_compositingConsultsOverlap; } |
| 84 | |
simon.fraser@apple.com | 8717fee | 2009-07-31 23:03:25 +0000 | [diff] [blame] | 85 | void scheduleSync(); |
cmarrin@apple.com | 20dc489 | 2009-04-03 19:29:22 +0000 | [diff] [blame] | 86 | |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 87 | // Rebuild the tree of compositing layers |
simon.fraser@apple.com | 762661b | 2010-01-28 18:07:14 +0000 | [diff] [blame] | 88 | void updateCompositingLayers(CompositingUpdateType = CompositingUpdateAfterLayoutOrStyleChange, RenderLayer* updateRoot = 0); |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 89 | |
simon.fraser@apple.com | 3bc08f1 | 2009-04-07 22:06:19 +0000 | [diff] [blame] | 90 | // Update the compositing state of the given layer. Returns true if that state changed. |
| 91 | enum CompositingChangeRepaint { CompositingChangeRepaintNow, CompositingChangeWillRepaintLater }; |
| 92 | bool updateLayerCompositingState(RenderLayer*, CompositingChangeRepaint = CompositingChangeRepaintNow); |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 93 | |
simon.fraser@apple.com | b2fc99c | 2009-06-22 22:45:24 +0000 | [diff] [blame] | 94 | // Update the geometry for compositing children of compositingAncestor. |
simon.fraser@apple.com | 994de4f | 2009-06-30 19:53:41 +0000 | [diff] [blame] | 95 | void updateCompositingDescendantGeometry(RenderLayer* compositingAncestor, RenderLayer* layer, RenderLayerBacking::UpdateDepth); |
simon.fraser@apple.com | b2fc99c | 2009-06-22 22:45:24 +0000 | [diff] [blame] | 96 | |
simon.fraser@apple.com | 699dc0b | 2009-04-07 17:45:00 +0000 | [diff] [blame] | 97 | // Whether layer's backing needs a graphics layer to do clipping by an ancestor (non-stacking-context parent with overflow). |
| 98 | bool clippedByAncestor(RenderLayer*) const; |
| 99 | // Whether layer's backing needs a graphics layer to clip z-order children of the given layer. |
| 100 | bool clipsCompositingDescendants(const RenderLayer*) const; |
| 101 | |
| 102 | // Whether the given layer needs an extra 'contents' layer. |
| 103 | bool needsContentsCompositingLayer(const RenderLayer*) const; |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 104 | // Return the bounding box required for compositing layer and its childern, relative to ancestorLayer. |
| 105 | // If layerBoundingBox is not 0, on return it contains the bounding box of this layer only. |
simon.fraser@apple.com | b2fc99c | 2009-06-22 22:45:24 +0000 | [diff] [blame] | 106 | IntRect calculateCompositedBounds(const RenderLayer* layer, const RenderLayer* ancestorLayer); |
simon.fraser@apple.com | 3bc08f1 | 2009-04-07 22:06:19 +0000 | [diff] [blame] | 107 | |
| 108 | // Repaint the appropriate layers when the given RenderLayer starts or stops being composited. |
| 109 | void repaintOnCompositingChange(RenderLayer*); |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 110 | |
| 111 | // Notify us that a layer has been added or removed |
| 112 | void layerWasAdded(RenderLayer* parent, RenderLayer* child); |
| 113 | void layerWillBeRemoved(RenderLayer* parent, RenderLayer* child); |
| 114 | |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 115 | // Get the nearest ancestor layer that has overflow or clip, but is not a stacking context |
| 116 | RenderLayer* enclosingNonStackingClippingLayer(const RenderLayer* layer) const; |
| 117 | |
| 118 | // Repaint parts of all composited layers that intersect the given absolute rectangle. |
| 119 | void repaintCompositedLayersAbsoluteRect(const IntRect&); |
| 120 | |
| 121 | RenderLayer* rootRenderLayer() const; |
| 122 | GraphicsLayer* rootPlatformLayer() const; |
| 123 | |
simon.fraser@apple.com | c152ae6 | 2009-02-03 20:14:37 +0000 | [diff] [blame] | 124 | void didMoveOnscreen(); |
| 125 | void willMoveOffscreen(); |
| 126 | |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 127 | void updateRootLayerPosition(); |
simon.fraser@apple.com | 98df11b | 2009-06-18 18:52:09 +0000 | [diff] [blame] | 128 | |
simon.fraser@apple.com | 02f4049 | 2009-07-07 17:15:16 +0000 | [diff] [blame] | 129 | void didStartAcceleratedAnimation(); |
| 130 | |
simon.fraser@apple.com | 98df11b | 2009-06-18 18:52:09 +0000 | [diff] [blame] | 131 | #if ENABLE(VIDEO) |
| 132 | // Use by RenderVideo to ask if it should try to use accelerated compositing. |
| 133 | bool canAccelerateVideoRendering(RenderVideo*) const; |
| 134 | #endif |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 135 | |
simon.fraser@apple.com | 61cf5eb | 2009-02-13 05:10:12 +0000 | [diff] [blame] | 136 | // Walk the tree looking for layers with 3d transforms. Useful in case you need |
| 137 | // to know if there is non-affine content, e.g. for drawing into an image. |
| 138 | bool has3DContent() const; |
| 139 | |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 140 | private: |
| 141 | // Whether the given RL needs a compositing layer. |
| 142 | bool needsToBeComposited(const RenderLayer*) const; |
| 143 | // Whether the layer has an intrinsic need for compositing layer. |
| 144 | bool requiresCompositingLayer(const RenderLayer*) const; |
| 145 | |
simon.fraser@apple.com | b2fc99c | 2009-06-22 22:45:24 +0000 | [diff] [blame] | 146 | // Make or destroy the backing for this layer; returns true if backing changed. |
| 147 | bool updateBacking(RenderLayer*, CompositingChangeRepaint shouldRepaint); |
| 148 | |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 149 | // Repaint the given rect (which is layer's coords), and regions of child layers that intersect that rect. |
| 150 | void recursiveRepaintLayerRect(RenderLayer* layer, const IntRect& rect); |
| 151 | |
simon.fraser@apple.com | 02f4049 | 2009-07-07 17:15:16 +0000 | [diff] [blame] | 152 | typedef HashMap<RenderLayer*, IntRect> OverlapMap; |
| 153 | static void addToOverlapMap(OverlapMap&, RenderLayer*, IntRect& layerBounds, bool& boundsComputed); |
| 154 | static bool overlapsCompositedLayers(OverlapMap&, const IntRect& layerBounds); |
| 155 | |
| 156 | // Returns true if any layer's compositing changed |
| 157 | void computeCompositingRequirements(RenderLayer*, OverlapMap*, struct CompositingState&, bool& layersChanged); |
simon.fraser@apple.com | 90c94a1 | 2009-11-30 03:21:55 +0000 | [diff] [blame] | 158 | |
| 159 | // Recurses down the tree, parenting descendant compositing layers and collecting an array of child layers for the current compositing layer. |
| 160 | void rebuildCompositingLayerTree(RenderLayer* layer, const struct CompositingState&, Vector<GraphicsLayer*>& childGraphicsLayersOfEnclosingLayer); |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 161 | |
simon.fraser@apple.com | 90c94a1 | 2009-11-30 03:21:55 +0000 | [diff] [blame] | 162 | // Recurses down the tree, updating layer geometry only. |
| 163 | void updateLayerTreeGeometry(RenderLayer*); |
| 164 | |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 165 | // Hook compositing layers together |
| 166 | void setCompositingParent(RenderLayer* childLayer, RenderLayer* parentLayer); |
| 167 | void removeCompositedChildren(RenderLayer*); |
| 168 | |
| 169 | void parentInRootLayer(RenderLayer*); |
| 170 | |
simon.fraser@apple.com | 61cf5eb | 2009-02-13 05:10:12 +0000 | [diff] [blame] | 171 | bool layerHas3DContent(const RenderLayer*) const; |
| 172 | |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 173 | void ensureRootPlatformLayer(); |
cmarrin@apple.com | 89072a0 | 2009-06-25 22:03:59 +0000 | [diff] [blame] | 174 | void destroyRootPlatformLayer(); |
| 175 | |
simon.fraser@apple.com | 6b59a90 | 2009-03-17 20:01:31 +0000 | [diff] [blame] | 176 | // Whether a running transition or animation enforces the need for a compositing layer. |
simon.fraser@apple.com | 0ac1f06 | 2009-06-27 06:22:30 +0000 | [diff] [blame] | 177 | bool requiresCompositingForAnimation(RenderObject*) const; |
| 178 | bool requiresCompositingForTransform(RenderObject*) const; |
simon.fraser@apple.com | 98df11b | 2009-06-18 18:52:09 +0000 | [diff] [blame] | 179 | bool requiresCompositingForVideo(RenderObject*) const; |
cmarrin@apple.com | 4e7728f | 2009-08-27 23:55:44 +0000 | [diff] [blame] | 180 | bool requiresCompositingForCanvas(RenderObject*) const; |
simon.fraser@apple.com | d6aff5e | 2010-01-12 00:15:06 +0000 | [diff] [blame] | 181 | bool requiresCompositingForPlugin(RenderObject*) const; |
simon.fraser@apple.com | 9d9e298 | 2009-08-18 03:57:08 +0000 | [diff] [blame] | 182 | bool requiresCompositingWhenDescendantsAreCompositing(RenderObject*) const; |
simon.fraser@apple.com | 6b59a90 | 2009-03-17 20:01:31 +0000 | [diff] [blame] | 183 | |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 184 | private: |
| 185 | RenderView* m_renderView; |
simon.fraser@apple.com | a90a99d | 2009-08-17 18:29:36 +0000 | [diff] [blame] | 186 | OwnPtr<GraphicsLayer> m_rootPlatformLayer; |
simon.fraser@apple.com | 02f4049 | 2009-07-07 17:15:16 +0000 | [diff] [blame] | 187 | bool m_hasAcceleratedCompositing; |
cmarrin@apple.com | f2dff33 | 2009-11-18 19:23:44 +0000 | [diff] [blame] | 188 | bool m_showDebugBorders; |
| 189 | bool m_showRepaintCounter; |
simon.fraser@apple.com | 02f4049 | 2009-07-07 17:15:16 +0000 | [diff] [blame] | 190 | bool m_compositingConsultsOverlap; |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 191 | bool m_compositing; |
| 192 | bool m_rootLayerAttached; |
simon.fraser@apple.com | 02f4049 | 2009-07-07 17:15:16 +0000 | [diff] [blame] | 193 | bool m_compositingLayersNeedRebuild; |
cmarrin@apple.com | 89072a0 | 2009-06-25 22:03:59 +0000 | [diff] [blame] | 194 | |
simon.fraser@apple.com | 6d640a0 | 2009-01-31 01:47:49 +0000 | [diff] [blame] | 195 | #if PROFILE_LAYER_REBUILD |
| 196 | int m_rootLayerUpdateCount; |
| 197 | #endif |
| 198 | }; |
| 199 | |
| 200 | |
| 201 | } // namespace WebCore |
| 202 | |
| 203 | #endif // RenderLayerCompositor_h |