Home | History | Annotate | Download | only in compositing
      1 /*
      2  * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
      3  * Copyright (C) 2014 Google Inc. All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      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 INC. ``AS IS'' AND ANY
     15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #ifndef CompositingLayerAssigner_h
     28 #define CompositingLayerAssigner_h
     29 
     30 #include "core/rendering/compositing/RenderLayerCompositor.h"
     31 #include "platform/geometry/IntRect.h"
     32 #include "platform/geometry/LayoutPoint.h"
     33 
     34 namespace WebCore {
     35 
     36 class RenderLayer;
     37 
     38 class CompositingLayerAssigner {
     39 public:
     40     explicit CompositingLayerAssigner(RenderLayerCompositor*);
     41     ~CompositingLayerAssigner();
     42 
     43     void assign(RenderLayer* updateRoot, bool& layersChanged, Vector<RenderLayer*>& layersNeedingRepaint);
     44 
     45     // FIXME: This function should be private. We should remove the one caller
     46     // once we've fixed the compositing chicken/egg issues.
     47     CompositingStateTransitionType computeCompositedLayerUpdate(RenderLayer*);
     48 
     49 private:
     50     struct SquashingState {
     51         SquashingState()
     52             : mostRecentMapping(0)
     53             , hasMostRecentMapping(false)
     54             , haveAssignedBackingsToEntireSquashingLayerSubtree(false)
     55             , nextSquashedLayerIndex(0)
     56             , totalAreaOfSquashedRects(0) { }
     57 
     58         void updateSquashingStateForNewMapping(CompositedLayerMappingPtr, bool hasNewCompositedLayerMapping);
     59 
     60         // The most recent composited backing that the layer should squash onto if needed.
     61         CompositedLayerMappingPtr mostRecentMapping;
     62         bool hasMostRecentMapping;
     63 
     64         // Whether all RenderLayers in the stacking subtree rooted at the most recent mapping's
     65         // owning layer have had CompositedLayerMappings assigned. Layers cannot squash into a
     66         // CompositedLayerMapping owned by a stacking ancestor, since this changes paint order.
     67         bool haveAssignedBackingsToEntireSquashingLayerSubtree;
     68 
     69         // Counter that tracks what index the next RenderLayer would be if it gets squashed to the current squashing layer.
     70         size_t nextSquashedLayerIndex;
     71 
     72         // The absolute bounding rect of all the squashed layers.
     73         IntRect boundingRect;
     74 
     75         // This is simply the sum of the areas of the squashed rects. This can be very skewed if the rects overlap,
     76         // but should be close enough to drive a heuristic.
     77         uint64_t totalAreaOfSquashedRects;
     78     };
     79 
     80     void assignLayersToBackingsInternal(RenderLayer*, SquashingState&, bool& layersChanged, Vector<RenderLayer*>& layersNeedingRepaint);
     81     void assignLayersToBackingsForReflectionLayer(RenderLayer* reflectionLayer, bool& layersChanged, Vector<RenderLayer*>& layersNeedingRepaint);
     82     CompositingReasons getReasonsPreventingSquashing(const RenderLayer*, const SquashingState&);
     83     bool squashingWouldExceedSparsityTolerance(const RenderLayer* candidate, const SquashingState&);
     84     bool updateSquashingAssignment(RenderLayer*, SquashingState&, CompositingStateTransitionType, Vector<RenderLayer*>& layersNeedingRepaint);
     85     bool needsOwnBacking(const RenderLayer*) const;
     86 
     87     RenderLayerCompositor* m_compositor;
     88     bool m_layerSquashingEnabled;
     89 };
     90 
     91 } // namespace WebCore
     92 
     93 #endif // CompositingLayerAssigner_h
     94