@@ -50,14 +50,13 @@ void* DisplayListBuilder::Push(size_t pod, int op_inc, Args&&... args) {
5050}
5151
5252sk_sp<DisplayList> DisplayListBuilder::Build () {
53-
5453 FML_DCHECK (build_count_ == 0 );
5554 build_count_++;
5655
5756 while (layer_stack_.size () > 1 ) {
5857 restore ();
5958 }
60-
59+
6160 size_t bytes = used_;
6261 int count = op_count_;
6362 size_t nested_bytes = nested_bytes_;
@@ -67,18 +66,17 @@ sk_sp<DisplayList> DisplayListBuilder::Build() {
6766 storage_.realloc (bytes);
6867 bool compatible = layer_stack_.back ().is_group_opacity_compatible ();
6968 FML_DCHECK (current_layer_ == &layer_stack_.back ());
70- FML_DCHECK (accumulator_ == layer_stack_.back ().layer_accumulator ());
71- // accumulator_ = layer_stack_.back().layer_accumulator();
7269 return sk_sp<DisplayList>(new DisplayList (storage_.release (), bytes, count,
7370 nested_bytes, nested_count,
74- bounds (), cull_rect_, compatible));
71+ bounds (), cull_rect_, compatible, rtree () ));
7572}
7673
7774DisplayListBuilder::DisplayListBuilder (const SkRect& cull_rect)
7875 : ClipBoundsDispatchHelper(&cull_rect), cull_rect_(cull_rect) {
79- layer_stack_.emplace_back (SkM44 (), cull_rect, nullptr );
76+ layer_stack_.emplace_back (SkM44 (), cull_rect);
8077 current_layer_ = &layer_stack_.back ();
81- accumulator_ = current_layer_->layer_accumulator ();
78+ combine_bounds_accumulator_.push_back (&rect_bounds_accumulator_);
79+ combine_bounds_accumulator_.push_back (&rtree_bounds_accumulator_);
8280}
8381
8482DisplayListBuilder::~DisplayListBuilder () {
@@ -436,72 +434,50 @@ void DisplayListBuilder::setAttributesFromPaint(
436434void DisplayListBuilder::save () {
437435 ClipBoundsDispatchHelper::save ();
438436 Push<SaveOp>(0 , 1 );
439- layer_stack_.emplace_back (current_layer_, accumulator_ );
437+ layer_stack_.emplace_back (current_layer_);
440438 current_layer_ = &layer_stack_.back ();
441- accumulator_ = current_layer_-> layer_accumulator ();
439+ accumulator ()-> save ();
442440}
443441void DisplayListBuilder::restore () {
444442 if (layer_stack_.size () > 1 ) {
445443 // Grab the current layer info before we push the restore
446444 // on the stack.
447- LayerInfo& layer_info = layer_stack_.back ();
445+ LayerInfo layer_info = layer_stack_.back ();
448446
449447 ClipBoundsDispatchHelper::restore ();
450-
451- // BoundsAccumulator* outer_accumulator = layer_info.restore_accumulator();
452448 bool is_unbounded = layer_info.is_unbounded ();
453449
454450 // Before we pop_back we will get the current layer bounds from the
455451 // current accumulator and adjust ot as required based on the filter.
456- SkRect layer_bounds = accumulator_->bounds ();
457452 std::shared_ptr<const DlImageFilter> filter = layer_info.filter ();
453+ const SkRect* clip = has_clip () ? &clip_bounds () : nullptr ;
458454 if (filter) {
459- SkIRect filter_bounds;
460- if (filter->map_device_bounds (layer_bounds.roundOut (), matrix (),
461- filter_bounds)) {
462- layer_bounds.set (filter_bounds);
463-
464- // We could leave the clipping to the code below that will
465- // finally accumulate the layer bounds, but the bounds do
466- // not normally need clipping unless they were modified by
467- // entering this filtering code path.
468- if (has_clip () && !layer_bounds.intersect (clip_bounds ())) {
469- layer_bounds.setEmpty ();
470- }
471- } else {
472- // If the filter cannot compute bounds then it might take an
473- // unbounded amount of space. This can sometimes happen if it
474- // modifies transparent black which means its affect will not
475- // be bounded by the transparent pixels outside of the layer
476- // drawable.
455+ if (!accumulator ()->restore (
456+ [filter = filter, matrix = matrix ()](const SkRect& input,
457+ SkRect& output) {
458+ SkIRect output_bounds;
459+ bool ret = filter->map_device_bounds (input.roundOut (), matrix,
460+ output_bounds);
461+ output.set (output_bounds);
462+ return ret;
463+ },
464+ clip)) {
477465 is_unbounded = true ;
478466 }
467+ } else {
468+ accumulator ()->restore (clip);
479469 }
480470
481-
482-
483- LayerInfo layer_info1 = layer_info;
484-
485471 layer_stack_.pop_back ();
486472 current_layer_ = &layer_stack_.back ();
487- // Restore the accumulator before popping the LayerInfo so that
488- // it nevers points to an out of scope instance.
489- accumulator_ = current_layer_->layer_accumulator ();
490473 Push<RestoreOp>(0 , 1 );
491474
492- // Finally accumulate the impact of the layer into the new scope.
493- // Note that the bounds were already accumulated in device pixels
494- // and clipped to any clips involved so we do not need to go
495- // through any transforms or clips to accuulate them into this
496- // layer.
497- accumulator_->accumulate (layer_bounds);
498-
499475 if (is_unbounded) {
500476 AccumulateUnbounded ();
501477 }
502478
503- if (layer_info1 .has_layer ) {
504- if (layer_info1 .is_group_opacity_compatible ()) {
479+ if (layer_info .has_layer ) {
480+ if (layer_info .is_group_opacity_compatible ()) {
505481 // We are now going to go back and modify the matching saveLayer
506482 // call to add the option indicating it can distribute an opacity
507483 // value to its children.
@@ -515,15 +491,15 @@ void DisplayListBuilder::restore() {
515491 // Once built, the DisplayList records must remain read only to
516492 // ensure consistency of rendering and |Equals()| behavior.
517493 SaveLayerOp* op = reinterpret_cast <SaveLayerOp*>(
518- storage_.get () + layer_info1 .save_layer_offset );
494+ storage_.get () + layer_info .save_layer_offset );
519495 op->options = op->options .with_can_distribute_opacity ();
520496 }
521497 } else {
522498 // For regular save() ops there was no protecting layer so we have to
523499 // accumulate the values into the enclosing layer.
524- if (layer_info1 .cannot_inherit_opacity ) {
500+ if (layer_info .cannot_inherit_opacity ) {
525501 current_layer_->mark_incompatible ();
526- } else if (layer_info1 .has_compatible_op ) {
502+ } else if (layer_info .has_compatible_op ) {
527503 current_layer_->add_compatible_op ();
528504 }
529505 }
@@ -561,15 +537,13 @@ void DisplayListBuilder::saveLayer(const SkRect* bounds,
561537 // We will fill the clip of the outer layer when we restore
562538 AccumulateUnbounded ();
563539 }
564- layer_stack_.emplace_back (current_layer_, accumulator_, save_layer_offset ,
565- true , current_.getImageFilter ());
540+ layer_stack_.emplace_back (current_layer_, save_layer_offset, true ,
541+ current_.getImageFilter ());
566542 } else {
567- layer_stack_.emplace_back (current_layer_, accumulator_, save_layer_offset,
568- true , nullptr );
543+ layer_stack_.emplace_back (current_layer_, save_layer_offset, true , nullptr );
569544 }
570-
545+ accumulator ()-> save ();
571546 current_layer_ = &layer_stack_.back ();
572- accumulator_ = layer_stack_.back ().layer_accumulator ();
573547 if (options.renders_with_attributes ()) {
574548 // |current_opacity_compatibility_| does not take an ImageFilter into
575549 // account because an individual primitive with an ImageFilter can apply
@@ -936,7 +910,7 @@ void DisplayListBuilder::drawPoints(SkCanvas::PointMode mode,
936910 UpdateLayerOpacityCompatibility (false );
937911
938912 if (count > 0 ) {
939- BoundsAccumulator ptBounds;
913+ RectBoundsAccumulator ptBounds;
940914 for (size_t i = 0 ; i < count; i++) {
941915 ptBounds.accumulate (pts[i]);
942916 }
@@ -1152,7 +1126,7 @@ void DisplayListBuilder::drawAtlas(const sk_sp<DlImage> atlas,
11521126 UpdateLayerOpacityCompatibility (false );
11531127
11541128 SkPoint quad[4 ];
1155- BoundsAccumulator atlasBounds;
1129+ RectBoundsAccumulator atlasBounds;
11561130 for (int i = 0 ; i < count; i++) {
11571131 const SkRect& src = tex[i];
11581132 xform[i].toQuad (src.width (), src.height (), quad);
@@ -1322,7 +1296,7 @@ bool DisplayListBuilder::AdjustBoundsForPaint(SkRect& bounds,
13221296
13231297void DisplayListBuilder::AccumulateUnbounded () {
13241298 if (has_clip ()) {
1325- accumulator_ ->accumulate (clip_bounds ());
1299+ accumulator () ->accumulate (clip_bounds ());
13261300 } else {
13271301 layer_stack_.back ().set_unbounded ();
13281302 }
@@ -1339,7 +1313,7 @@ void DisplayListBuilder::AccumulateOpBounds(SkRect& bounds,
13391313void DisplayListBuilder::AccumulateBounds (SkRect& bounds) {
13401314 matrix ().mapRect (&bounds);
13411315 if (!has_clip () || bounds.intersect (clip_bounds ())) {
1342- accumulator_ ->accumulate (bounds);
1316+ accumulator () ->accumulate (bounds);
13431317 }
13441318}
13451319
0 commit comments