1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
|
/*
* Copyright (C) 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef RenderLayerCompositor_h
#define RenderLayerCompositor_h
#if USE(ACCELERATED_COMPOSITING)
#include "ChromeClient.h"
#include "Frame.h"
#include "GraphicsLayerClient.h"
#include "GraphicsLayerUpdater.h"
#include "RenderLayer.h"
#include <wtf/HashMap.h>
namespace WebCore {
class FixedPositionViewportConstraints;
class GraphicsLayer;
class GraphicsLayerUpdater;
class RenderEmbeddedObject;
class RenderPart;
class ScrollingCoordinator;
class StickyPositionViewportConstraints;
#if ENABLE(VIDEO)
class RenderVideo;
#endif
class TiledBacking;
enum CompositingUpdateType {
CompositingUpdateAfterStyleChange,
CompositingUpdateAfterLayout,
CompositingUpdateOnHitTest,
CompositingUpdateOnScroll,
CompositingUpdateOnCompositedScroll
};
enum {
CompositingReasonNone = 0,
CompositingReason3DTransform = 1 << 0,
CompositingReasonVideo = 1 << 1,
CompositingReasonCanvas = 1 << 2,
CompositingReasonPlugin = 1 << 3,
CompositingReasonIFrame = 1 << 4,
CompositingReasonBackfaceVisibilityHidden = 1 << 5,
CompositingReasonClipsCompositingDescendants = 1 << 6,
CompositingReasonAnimation = 1 << 7,
CompositingReasonFilters = 1 << 8,
CompositingReasonPositionFixed = 1 << 9,
CompositingReasonPositionSticky = 1 << 10,
CompositingReasonOverflowScrollingTouch = 1 << 11,
CompositingReasonStacking = 1 << 12,
CompositingReasonOverlap = 1 << 13,
CompositingReasonNegativeZIndexChildren = 1 << 14,
CompositingReasonTransformWithCompositedDescendants = 1 << 15,
CompositingReasonOpacityWithCompositedDescendants = 1 << 16,
CompositingReasonMaskWithCompositedDescendants = 1 << 17,
CompositingReasonReflectionWithCompositedDescendants = 1 << 18,
CompositingReasonFilterWithCompositedDescendants = 1 << 19,
CompositingReasonBlendingWithCompositedDescendants = 1 << 20,
CompositingReasonPerspective = 1 << 21,
CompositingReasonPreserve3D = 1 << 22,
CompositingReasonRoot = 1 << 23
};
typedef unsigned CompositingReasons;
// RenderLayerCompositor manages the hierarchy of
// composited RenderLayers. It determines which RenderLayers
// become compositing, and creates and maintains a hierarchy of
// GraphicsLayers based on the RenderLayer painting order.
//
// There is one RenderLayerCompositor per RenderView.
class RenderLayerCompositor : public GraphicsLayerClient, public GraphicsLayerUpdaterClient {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit RenderLayerCompositor(RenderView*);
~RenderLayerCompositor();
// Return true if this RenderView is in "compositing mode" (i.e. has one or more
// composited RenderLayers)
bool inCompositingMode() const { return m_compositing; }
// This will make a compositing layer at the root automatically, and hook up to
// the native view/window system.
void enableCompositingMode(bool enable = true);
bool inForcedCompositingMode() const { return m_forceCompositingMode; }
// Returns true if the accelerated compositing is enabled
bool hasAcceleratedCompositing() const { return m_hasAcceleratedCompositing; }
bool canRender3DTransforms() const;
// Copy the accelerated compositing related flags from Settings
void cacheAcceleratedCompositingFlags();
// Called when the layer hierarchy needs to be updated (compositing layers have been
// created, destroyed or re-parented).
void setCompositingLayersNeedRebuild(bool needRebuild = true);
bool compositingLayersNeedRebuild() const { return m_compositingLayersNeedRebuild; }
// GraphicsLayers buffer state, which gets pushed to the underlying platform layers
// at specific times.
void scheduleLayerFlush(bool canThrottle);
void flushPendingLayerChanges(bool isFlushRoot = true);
// flushPendingLayerChanges() flushes the entire GraphicsLayer tree, which can cross frame boundaries.
// This call returns the rootmost compositor that is being flushed (including self).
RenderLayerCompositor* enclosingCompositorFlushingLayers() const;
// Called when the GraphicsLayer for the given RenderLayer has flushed changes inside of flushPendingLayerChanges().
void didFlushChangesForLayer(RenderLayer*, const GraphicsLayer*);
// Called when something outside WebKit affects the visible rect (e.g. delegated scrolling). Might schedule a layer flush.
void didChangeVisibleRect();
// Rebuild the tree of compositing layers
void updateCompositingLayers(CompositingUpdateType, RenderLayer* updateRoot = 0);
// This is only used when state changes and we do not exepect a style update or layout to happen soon (e.g. when
// we discover that an iframe is overlapped during painting).
void scheduleCompositingLayerUpdate();
// Update the compositing state of the given layer. Returns true if that state changed.
enum CompositingChangeRepaint { CompositingChangeRepaintNow, CompositingChangeWillRepaintLater };
bool updateLayerCompositingState(RenderLayer*, CompositingChangeRepaint = CompositingChangeRepaintNow);
// Update the geometry for compositing children of compositingAncestor.
void updateCompositingDescendantGeometry(RenderLayer* compositingAncestor, RenderLayer*, bool compositedChildrenOnly);
// Whether layer's backing needs a graphics layer to do clipping by an ancestor (non-stacking-context parent with overflow).
bool clippedByAncestor(RenderLayer*) const;
// Whether layer's backing needs a graphics layer to clip z-order children of the given layer.
bool clipsCompositingDescendants(const RenderLayer*) const;
// Whether the given layer needs an extra 'contents' layer.
bool needsContentsCompositingLayer(const RenderLayer*) const;
bool supportsFixedRootBackgroundCompositing() const;
bool needsFixedRootBackgroundLayer(const RenderLayer*) const;
GraphicsLayer* fixedRootBackgroundLayer() const;
// Return the bounding box required for compositing layer and its childern, relative to ancestorLayer.
// If layerBoundingBox is not 0, on return it contains the bounding box of this layer only.
LayoutRect calculateCompositedBounds(const RenderLayer*, const RenderLayer* ancestorLayer) const;
// Repaint the appropriate layers when the given RenderLayer starts or stops being composited.
void repaintOnCompositingChange(RenderLayer*);
void repaintInCompositedAncestor(RenderLayer*, const LayoutRect&);
// Notify us that a layer has been added or removed
void layerWasAdded(RenderLayer* parent, RenderLayer* child);
void layerWillBeRemoved(RenderLayer* parent, RenderLayer* child);
// Get the nearest ancestor layer that has overflow or clip, but is not a stacking context
RenderLayer* enclosingNonStackingClippingLayer(const RenderLayer* layer) const;
// Repaint parts of all composited layers that intersect the given absolute rectangle (or the entire layer if the pointer is null).
void repaintCompositedLayers(const IntRect* = 0);
// Returns true if the given layer needs it own backing store.
bool requiresOwnBackingStore(const RenderLayer*, const RenderLayer* compositingAncestorLayer, const IntRect& layerCompositedBoundsInAncestor, const IntRect& ancestorCompositedBounds) const;
RenderLayer* rootRenderLayer() const;
GraphicsLayer* rootGraphicsLayer() const;
GraphicsLayer* scrollLayer() const;
#if ENABLE(RUBBER_BANDING)
GraphicsLayer* headerLayer() const;
GraphicsLayer* footerLayer() const;
#endif
enum RootLayerAttachment {
RootLayerUnattached,
RootLayerAttachedViaChromeClient,
RootLayerAttachedViaEnclosingFrame
};
RootLayerAttachment rootLayerAttachment() const { return m_rootLayerAttachment; }
void updateRootLayerAttachment();
void updateRootLayerPosition();
void setIsInWindow(bool);
void clearBackingForAllLayers();
void layerBecameComposited(const RenderLayer*) { ++m_compositedLayerCount; }
void layerBecameNonComposited(const RenderLayer*);
#if ENABLE(VIDEO)
// Use by RenderVideo to ask if it should try to use accelerated compositing.
bool canAccelerateVideoRendering(RenderVideo*) const;
#endif
// Walk the tree looking for layers with 3d transforms. Useful in case you need
// to know if there is non-affine content, e.g. for drawing into an image.
bool has3DContent() const;
// Most platforms connect compositing layer trees between iframes and their parent document.
// Some (currently just Mac) allow iframes to do their own compositing.
static bool allowsIndependentlyCompositedFrames(const FrameView*);
bool shouldPropagateCompositingToEnclosingFrame() const;
static RenderLayerCompositor* frameContentsCompositor(RenderPart*);
// Return true if the layers changed.
static bool parentFrameContentLayers(RenderPart*);
// Update the geometry of the layers used for clipping and scrolling in frames.
void frameViewDidChangeLocation(const IntPoint& contentsOffset);
void frameViewDidChangeSize();
void frameViewDidScroll();
void frameViewDidLayout();
void rootFixedBackgroundsChanged();
void scrollingLayerDidChange(RenderLayer*);
void fixedRootBackgroundLayerChanged();
String layerTreeAsText(LayerTreeFlags);
virtual float deviceScaleFactor() const OVERRIDE;
virtual float pageScaleFactor() const OVERRIDE;
virtual void didCommitChangesForLayer(const GraphicsLayer*) const OVERRIDE;
virtual void notifyFlushBeforeDisplayRefresh(const GraphicsLayer*) OVERRIDE;
void layerTiledBackingUsageChanged(const GraphicsLayer*, bool /*usingTiledBacking*/);
bool keepLayersPixelAligned() const;
bool acceleratedDrawingEnabled() const { return m_acceleratedDrawingEnabled; }
void deviceOrPageScaleFactorChanged();
void windowScreenDidChange(PlatformDisplayID);
GraphicsLayer* layerForHorizontalScrollbar() const { return m_layerForHorizontalScrollbar.get(); }
GraphicsLayer* layerForVerticalScrollbar() const { return m_layerForVerticalScrollbar.get(); }
GraphicsLayer* layerForScrollCorner() const { return m_layerForScrollCorner.get(); }
#if ENABLE(RUBBER_BANDING)
GraphicsLayer* layerForOverhangAreas() const { return m_layerForOverhangAreas.get(); }
GraphicsLayer* updateLayerForTopOverhangArea(bool wantsLayer);
GraphicsLayer* updateLayerForBottomOverhangArea(bool wantsLayer);
GraphicsLayer* updateLayerForHeader(bool wantsLayer);
GraphicsLayer* updateLayerForFooter(bool wantsLayer);
#endif
void updateViewportConstraintStatus(RenderLayer*);
void removeViewportConstrainedLayer(RenderLayer*);
void resetTrackedRepaintRects();
void setTracksRepaints(bool);
void setShouldReevaluateCompositingAfterLayout() { m_reevaluateCompositingAfterLayout = true; }
bool viewHasTransparentBackground(Color* backgroundColor = 0) const;
bool hasNonMainLayersWithTiledBacking() const { return m_layersWithTiledBackingCount; }
CompositingReasons reasonsForCompositing(const RenderLayer*) const;
void setLayerFlushThrottlingEnabled(bool);
void disableLayerFlushThrottlingTemporarilyForInteraction();
void didPaintBacking(RenderLayerBacking*);
private:
class OverlapMap;
// GraphicsLayerClient implementation
virtual void notifyAnimationStarted(const GraphicsLayer*, double) OVERRIDE { }
virtual void notifyFlushRequired(const GraphicsLayer*) OVERRIDE;
virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect&) OVERRIDE;
virtual bool isTrackingRepaints() const OVERRIDE;
// GraphicsLayerUpdaterClient implementation
virtual void flushLayers(GraphicsLayerUpdater*) OVERRIDE;
virtual void customPositionForVisibleRectComputation(const GraphicsLayer*, FloatPoint&) const OVERRIDE;
// Whether the given RL needs a compositing layer.
bool needsToBeComposited(const RenderLayer*, RenderLayer::ViewportConstrainedNotCompositedReason* = 0) const;
// Whether the layer has an intrinsic need for compositing layer.
bool requiresCompositingLayer(const RenderLayer*, RenderLayer::ViewportConstrainedNotCompositedReason* = 0) const;
// Whether the layer could ever be composited.
bool canBeComposited(const RenderLayer*) const;
// Make or destroy the backing for this layer; returns true if backing changed.
bool updateBacking(RenderLayer*, CompositingChangeRepaint shouldRepaint);
void clearBackingForLayerIncludingDescendants(RenderLayer*);
// Repaint the given rect (which is layer's coords), and regions of child layers that intersect that rect.
void recursiveRepaintLayer(RenderLayer*, const IntRect* = 0);
void addToOverlapMap(OverlapMap&, RenderLayer*, IntRect& layerBounds, bool& boundsComputed);
void addToOverlapMapRecursive(OverlapMap&, RenderLayer*, RenderLayer* ancestorLayer = 0);
void updateCompositingLayersTimerFired(Timer<RenderLayerCompositor>*);
// Returns true if any layer's compositing changed
void computeCompositingRequirements(RenderLayer* ancestorLayer, RenderLayer*, OverlapMap*, struct CompositingState&, bool& layersChanged, bool& descendantHas3DTransform);
// Recurses down the tree, parenting descendant compositing layers and collecting an array of child layers for the current compositing layer.
void rebuildCompositingLayerTree(RenderLayer*, Vector<GraphicsLayer*>& childGraphicsLayersOfEnclosingLayer, int depth);
// Recurses down the tree, updating layer geometry only.
void updateLayerTreeGeometry(RenderLayer*, int depth);
// Hook compositing layers together
void setCompositingParent(RenderLayer* childLayer, RenderLayer* parentLayer);
void removeCompositedChildren(RenderLayer*);
bool layerHas3DContent(const RenderLayer*) const;
bool isRunningAcceleratedTransformAnimation(RenderObject*) const;
bool hasAnyAdditionalCompositedLayers(const RenderLayer* rootLayer) const;
void ensureRootLayer();
void destroyRootLayer();
void attachRootLayer(RootLayerAttachment);
void detachRootLayer();
void rootLayerAttachmentChanged();
void updateOverflowControlsLayers();
void notifyIFramesOfCompositingChange();
bool isFlushingLayers() const { return m_flushingLayers; }
Page* page() const;
TiledBacking* pageTiledBacking() const;
GraphicsLayerFactory* graphicsLayerFactory() const;
ScrollingCoordinator* scrollingCoordinator() const;
// Whether a running transition or animation enforces the need for a compositing layer.
bool requiresCompositingForAnimation(RenderObject*) const;
bool requiresCompositingForTransform(RenderObject*) const;
bool requiresCompositingForVideo(RenderObject*) const;
bool requiresCompositingForCanvas(RenderObject*) const;
bool requiresCompositingForPlugin(RenderObject*) const;
bool requiresCompositingForFrame(RenderObject*) const;
bool requiresCompositingForFilters(RenderObject*) const;
bool requiresCompositingForBlending(RenderObject* renderer) const;
bool requiresCompositingForScrollableFrame() const;
bool requiresCompositingForPosition(RenderObject*, const RenderLayer*, RenderLayer::ViewportConstrainedNotCompositedReason* = 0) const;
bool requiresCompositingForOverflowScrolling(const RenderLayer*) const;
bool requiresCompositingForIndirectReason(RenderObject*, bool hasCompositedDescendants, bool has3DTransformedDescendants, RenderLayer::IndirectCompositingReason&) const;
void addViewportConstrainedLayer(RenderLayer*);
void registerOrUpdateViewportConstrainedLayer(RenderLayer*);
void unregisterViewportConstrainedLayer(RenderLayer*);
FixedPositionViewportConstraints computeFixedViewportConstraints(RenderLayer*) const;
StickyPositionViewportConstraints computeStickyViewportConstraints(RenderLayer*) const;
bool requiresScrollLayer(RootLayerAttachment) const;
bool requiresHorizontalScrollbarLayer() const;
bool requiresVerticalScrollbarLayer() const;
bool requiresScrollCornerLayer() const;
#if ENABLE(RUBBER_BANDING)
bool requiresOverhangAreasLayer() const;
bool requiresContentShadowLayer() const;
#endif
bool hasCoordinatedScrolling() const;
bool shouldCompositeOverflowControls() const;
void scheduleLayerFlushNow();
bool isThrottlingLayerFlushes() const;
void startLayerFlushTimerIfNeeded();
void layerFlushTimerFired(Timer<RenderLayerCompositor>*);
void paintRelatedMilestonesTimerFired(Timer<RenderLayerCompositor>*);
#if !LOG_DISABLED
const char* logReasonsForCompositing(const RenderLayer*);
void logLayerInfo(const RenderLayer*, int depth);
#endif
private:
RenderView* m_renderView;
OwnPtr<GraphicsLayer> m_rootContentLayer;
Timer<RenderLayerCompositor> m_updateCompositingLayersTimer;
bool m_hasAcceleratedCompositing;
ChromeClient::CompositingTriggerFlags m_compositingTriggers;
int m_compositedLayerCount;
bool m_showDebugBorders;
bool m_showRepaintCounter;
bool m_acceleratedDrawingEnabled;
// When true, we have to wait until layout has happened before we can decide whether to enter compositing mode,
// because only then do we know the final size of plugins and iframes.
mutable bool m_reevaluateCompositingAfterLayout;
bool m_compositing;
bool m_compositingLayersNeedRebuild;
bool m_flushingLayers;
bool m_shouldFlushOnReattach;
bool m_forceCompositingMode;
bool m_inPostLayoutUpdate; // true when it's OK to trust layout information (e.g. layer sizes and positions)
bool m_isTrackingRepaints; // Used for testing.
unsigned m_layersWithTiledBackingCount;
RootLayerAttachment m_rootLayerAttachment;
// Enclosing clipping layer for iframe content
OwnPtr<GraphicsLayer> m_clipLayer;
OwnPtr<GraphicsLayer> m_scrollLayer;
HashSet<RenderLayer*> m_viewportConstrainedLayers;
HashSet<RenderLayer*> m_viewportConstrainedLayersNeedingUpdate;
// Enclosing layer for overflow controls and the clipping layer
OwnPtr<GraphicsLayer> m_overflowControlsHostLayer;
// Layers for overflow controls
OwnPtr<GraphicsLayer> m_layerForHorizontalScrollbar;
OwnPtr<GraphicsLayer> m_layerForVerticalScrollbar;
OwnPtr<GraphicsLayer> m_layerForScrollCorner;
#if ENABLE(RUBBER_BANDING)
OwnPtr<GraphicsLayer> m_layerForOverhangAreas;
OwnPtr<GraphicsLayer> m_contentShadowLayer;
OwnPtr<GraphicsLayer> m_layerForTopOverhangArea;
OwnPtr<GraphicsLayer> m_layerForBottomOverhangArea;
OwnPtr<GraphicsLayer> m_layerForHeader;
OwnPtr<GraphicsLayer> m_layerForFooter;
#endif
OwnPtr<GraphicsLayerUpdater> m_layerUpdater; // Updates tiled layer visible area periodically while animations are running.
Timer<RenderLayerCompositor> m_layerFlushTimer;
bool m_layerFlushThrottlingEnabled;
bool m_layerFlushThrottlingTemporarilyDisabledForInteraction;
bool m_hasPendingLayerFlush;
Timer<RenderLayerCompositor> m_paintRelatedMilestonesTimer;
#if !LOG_DISABLED
int m_rootLayerUpdateCount;
int m_obligateCompositedLayerCount; // count of layer that have to be composited.
int m_secondaryCompositedLayerCount; // count of layers that have to be composited because of stacking or overlap.
double m_obligatoryBackingStoreBytes;
double m_secondaryBackingStoreBytes;
#endif
};
} // namespace WebCore
#endif // USE(ACCELERATED_COMPOSITING)
#endif // RenderLayerCompositor_h
|