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 THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_COMPOSITING_COMPOSITING_LAYER_ASSIGNER_H_ 28 #define THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_COMPOSITING_COMPOSITING_LAYER_ASSIGNER_H_ 29 30 #include "third_party/blink/renderer/core/paint/compositing/paint_layer_compositor.h" 31 #include "third_party/blink/renderer/platform/geometry/int_rect.h" 32 #include "third_party/blink/renderer/platform/geometry/layout_point.h" 33 #include "third_party/blink/renderer/platform/graphics/squashing_disallowed_reasons.h" 34 #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" 35 36 namespace blink { 37 38 class CompositedLayerMapping; 39 class PaintLayer; 40 41 class CompositingLayerAssigner { 42 STACK_ALLOCATED(); 43 44 public: 45 explicit CompositingLayerAssigner(PaintLayerCompositor*); 46 47 void Assign(PaintLayer* update_root, 48 Vector<PaintLayer*>& layers_needing_paint_invalidation); 49 LayersChanged()50 bool LayersChanged() const { return layers_changed_; } 51 52 // FIXME: This function should be private. We should remove the one caller 53 // once we've fixed the compositing chicken/egg issues. 54 CompositingStateTransitionType ComputeCompositedLayerUpdate(PaintLayer*); 55 56 private: 57 struct SquashingState { 58 void UpdateSquashingStateForNewMapping( 59 CompositedLayerMapping*, 60 Vector<PaintLayer*>& layers_needing_paint_invalidation); 61 62 // The most recent composited backing that the layer should squash onto if 63 // needed. 64 CompositedLayerMapping* most_recent_mapping = nullptr; 65 66 // Whether all Layers in the stacking subtree rooted at the most recent 67 // mapping's owning layer have had CompositedLayerMappings assigned. Layers 68 // cannot squash into a CompositedLayerMapping owned by a stacking ancestor, 69 // since this changes paint order. 70 bool have_assigned_backings_to_entire_squashing_layer_subtree = false; 71 72 // This is set to true when most_recent_mapping supports composited 73 // scrolling, and reset to false whenever any layer is not squashed into 74 // scrolling contents, to ensure all layers squashed into scrolling contents 75 // are continuous with the scroller in stacking order, without any other 76 // layer interlacing among them. 77 bool next_layer_may_squash_into_scrolling_contents = false; 78 79 // Counter that tracks what index the next Layer would be if it gets 80 // squashed to the current non scrolling squashing layer. 81 wtf_size_t next_non_scrolling_squashed_layer_index = 0; 82 // Same as above but for layers squashed into scrolling contents layer. 83 wtf_size_t next_squashed_layer_in_scrolling_contents_index = 0; 84 85 // The absolute bounding rect of all the squashed layers (not including 86 // those squashed into scrolling contents). 87 IntRect bounding_rect; 88 89 // This is simply the sum of the areas of the squashed rects. This can be 90 // very skewed if the rects overlap, but should be close enough to drive a 91 // heuristic (not including those squashed into scrolling contents). 92 uint64_t total_area_of_squashed_rects = 0; 93 }; 94 95 void AssignLayersToBackingsInternal( 96 PaintLayer* layer, 97 PaintLayer* paint_invalidation_container, 98 SquashingState&, 99 Vector<PaintLayer*>& layers_needing_paint_invalidation); 100 SquashingDisallowedReasons GetReasonsPreventingSquashing( 101 const PaintLayer*, 102 const SquashingState&); 103 bool SquashingWouldExceedSparsityTolerance(const PaintLayer* candidate, 104 const SquashingState&); 105 void UpdateSquashingAssignment( 106 PaintLayer*, 107 SquashingState&, 108 CompositingStateTransitionType, 109 Vector<PaintLayer*>& layers_needing_paint_invalidation); 110 bool NeedsOwnBacking(const PaintLayer*) const; 111 112 PaintLayerCompositor* compositor_; 113 bool layers_changed_; 114 }; 115 116 } // namespace blink 117 118 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_COMPOSITING_COMPOSITING_LAYER_ASSIGNER_H_ 119