layers_test.dart 21.1 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

7 8
import 'dart:ui';

9
import 'package:flutter/foundation.dart';
10 11 12 13 14 15 16 17
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';

import 'rendering_tester.dart';

void main() {
  test('non-painted layers are detached', () {
    RenderObject boundary, inner;
18 19 20
    final RenderOpacity root = RenderOpacity(
      child: boundary = RenderRepaintBoundary(
        child: inner = RenderDecoratedBox(
21 22 23 24 25 26
          decoration: const BoxDecoration(),
        ),
      ),
    );
    layout(root, phase: EnginePhase.paint);
    expect(inner.isRepaintBoundary, isFalse);
27
    expect(inner.debugLayer, null);
28
    expect(boundary.isRepaintBoundary, isTrue);
29 30
    expect(boundary.debugLayer, isNotNull);
    expect(boundary.debugLayer.attached, isTrue); // this time it painted...
31 32 33 34

    root.opacity = 0.0;
    pumpFrame(phase: EnginePhase.paint);
    expect(inner.isRepaintBoundary, isFalse);
35
    expect(inner.debugLayer, null);
36
    expect(boundary.isRepaintBoundary, isTrue);
37 38
    expect(boundary.debugLayer, isNotNull);
    expect(boundary.debugLayer.attached, isFalse); // this time it did not.
39 40 41 42

    root.opacity = 0.5;
    pumpFrame(phase: EnginePhase.paint);
    expect(inner.isRepaintBoundary, isFalse);
43
    expect(inner.debugLayer, null);
44
    expect(boundary.isRepaintBoundary, isTrue);
45 46
    expect(boundary.debugLayer, isNotNull);
    expect(boundary.debugLayer.attached, isTrue); // this time it did again!
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
  test('updateSubtreeNeedsAddToScene propagates Layer.alwaysNeedsAddToScene up the tree', () {
    final ContainerLayer a = ContainerLayer();
    final ContainerLayer b = ContainerLayer();
    final ContainerLayer c = ContainerLayer();
    final _TestAlwaysNeedsAddToSceneLayer d = _TestAlwaysNeedsAddToSceneLayer();
    final ContainerLayer e = ContainerLayer();
    final ContainerLayer f = ContainerLayer();

    // Tree structure:
    //        a
    //       / \
    //      b   c
    //     / \
    // (x)d   e
    //   /
    //  f
    a.append(b);
    a.append(c);
    b.append(d);
    b.append(e);
    d.append(f);

    a.debugMarkClean();
    b.debugMarkClean();
    c.debugMarkClean();
    d.debugMarkClean();
    e.debugMarkClean();
    f.debugMarkClean();

    expect(a.debugSubtreeNeedsAddToScene, false);
    expect(b.debugSubtreeNeedsAddToScene, false);
    expect(c.debugSubtreeNeedsAddToScene, false);
    expect(d.debugSubtreeNeedsAddToScene, false);
    expect(e.debugSubtreeNeedsAddToScene, false);
    expect(f.debugSubtreeNeedsAddToScene, false);

    a.updateSubtreeNeedsAddToScene();

    expect(a.debugSubtreeNeedsAddToScene, true);
    expect(b.debugSubtreeNeedsAddToScene, true);
    expect(c.debugSubtreeNeedsAddToScene, false);
    expect(d.debugSubtreeNeedsAddToScene, true);
    expect(e.debugSubtreeNeedsAddToScene, false);
    expect(f.debugSubtreeNeedsAddToScene, false);
  });

  test('updateSubtreeNeedsAddToScene propagates Layer._needsAddToScene up the tree', () {
96 97 98 99 100 101 102
    final ContainerLayer a = ContainerLayer();
    final ContainerLayer b = ContainerLayer();
    final ContainerLayer c = ContainerLayer();
    final ContainerLayer d = ContainerLayer();
    final ContainerLayer e = ContainerLayer();
    final ContainerLayer f = ContainerLayer();
    final ContainerLayer g = ContainerLayer();
103
    final List<ContainerLayer> allLayers = <ContainerLayer>[a, b, c, d, e, f, g];
104 105 106 107 108 109

    // The tree is like the following where b and j are dirty:
    //        a____
    //       /     \
    //   (x)b___    c
    //     / \  \   |
110
    //    d   e  f  g(x)
111 112 113 114 115 116 117
    a.append(b);
    a.append(c);
    b.append(d);
    b.append(e);
    b.append(f);
    c.append(g);

118
    for (final ContainerLayer layer in allLayers) {
119 120 121
      expect(layer.debugSubtreeNeedsAddToScene, true);
    }

122
    for (final ContainerLayer layer in allLayers) {
123 124 125
      layer.debugMarkClean();
    }

126
    for (final ContainerLayer layer in allLayers) {
127 128 129
      expect(layer.debugSubtreeNeedsAddToScene, false);
    }

130
    b.markNeedsAddToScene();
131 132 133 134 135 136 137 138 139
    a.updateSubtreeNeedsAddToScene();

    expect(a.debugSubtreeNeedsAddToScene, true);
    expect(b.debugSubtreeNeedsAddToScene, true);
    expect(c.debugSubtreeNeedsAddToScene, false);
    expect(d.debugSubtreeNeedsAddToScene, false);
    expect(e.debugSubtreeNeedsAddToScene, false);
    expect(f.debugSubtreeNeedsAddToScene, false);
    expect(g.debugSubtreeNeedsAddToScene, false);
140

141
    g.markNeedsAddToScene();
142 143 144 145 146 147 148 149
    a.updateSubtreeNeedsAddToScene();

    expect(a.debugSubtreeNeedsAddToScene, true);
    expect(b.debugSubtreeNeedsAddToScene, true);
    expect(c.debugSubtreeNeedsAddToScene, true);
    expect(d.debugSubtreeNeedsAddToScene, false);
    expect(e.debugSubtreeNeedsAddToScene, false);
    expect(f.debugSubtreeNeedsAddToScene, false);
150 151 152
    expect(g.debugSubtreeNeedsAddToScene, true);

    a.buildScene(SceneBuilder());
153
    for (final ContainerLayer layer in allLayers) {
154 155
      expect(layer.debugSubtreeNeedsAddToScene, false);
    }
156 157 158 159 160 161 162 163 164 165 166 167 168
  });

  test('leader and follower layers are always dirty', () {
    final LayerLink link = LayerLink();
    final LeaderLayer leaderLayer = LeaderLayer(link: link);
    final FollowerLayer followerLayer = FollowerLayer(link: link);
    leaderLayer.debugMarkClean();
    followerLayer.debugMarkClean();
    leaderLayer.updateSubtreeNeedsAddToScene();
    followerLayer.updateSubtreeNeedsAddToScene();
    expect(leaderLayer.debugSubtreeNeedsAddToScene, true);
    expect(followerLayer.debugSubtreeNeedsAddToScene, true);
  });
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
  test('depthFirstIterateChildren', () {
    final ContainerLayer a = ContainerLayer();
    final ContainerLayer b = ContainerLayer();
    final ContainerLayer c = ContainerLayer();
    final ContainerLayer d = ContainerLayer();
    final ContainerLayer e = ContainerLayer();
    final ContainerLayer f = ContainerLayer();
    final ContainerLayer g = ContainerLayer();

    final PictureLayer h = PictureLayer(Rect.zero);
    final PictureLayer i = PictureLayer(Rect.zero);
    final PictureLayer j = PictureLayer(Rect.zero);

    // The tree is like the following:
    //        a____
    //       /     \
    //      b___    c
    //     / \  \   |
    //    d   e  f  g
    //   / \        |
    //  h   i       j
    a.append(b);
    a.append(c);
    b.append(d);
    b.append(e);
    b.append(f);
    d.append(h);
    d.append(i);
    c.append(g);
    g.append(j);

    expect(
      a.depthFirstIterateChildren(),
      <Layer>[b, d, h, i, e, f, c, g, j],
    );

    d.remove();
    //        a____
    //       /     \
    //      b___    c
    //       \  \   |
    //        e  f  g
    //              |
    //              j
    expect(
      a.depthFirstIterateChildren(),
      <Layer>[b, e, f, c, g, j],
    );
  });

220 221
  void checkNeedsAddToScene(Layer layer, void mutateCallback()) {
    layer.debugMarkClean();
222
    layer.updateSubtreeNeedsAddToScene();
223 224
    expect(layer.debugSubtreeNeedsAddToScene, false);
    mutateCallback();
225
    layer.updateSubtreeNeedsAddToScene();
226 227 228
    expect(layer.debugSubtreeNeedsAddToScene, true);
  }

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
  List<String> _getDebugInfo(Layer layer) {
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
    layer.debugFillProperties(builder);
    return builder.properties
        .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
        .map((DiagnosticsNode node) => node.toString()).toList();
  }

  test('ClipRectLayer prints clipBehavior in debug info', () {
    expect(_getDebugInfo(ClipRectLayer()), contains('clipBehavior: Clip.hardEdge'));
    expect(
      _getDebugInfo(ClipRectLayer(clipBehavior: Clip.antiAliasWithSaveLayer)),
      contains('clipBehavior: Clip.antiAliasWithSaveLayer'),
    );
  });

  test('ClipRRectLayer prints clipBehavior in debug info', () {
    expect(_getDebugInfo(ClipRRectLayer()), contains('clipBehavior: Clip.antiAlias'));
    expect(
      _getDebugInfo(ClipRRectLayer(clipBehavior: Clip.antiAliasWithSaveLayer)),
      contains('clipBehavior: Clip.antiAliasWithSaveLayer'),
    );
  });

  test('ClipPathLayer prints clipBehavior in debug info', () {
    expect(_getDebugInfo(ClipPathLayer()), contains('clipBehavior: Clip.antiAlias'));
    expect(
      _getDebugInfo(ClipPathLayer(clipBehavior: Clip.antiAliasWithSaveLayer)),
      contains('clipBehavior: Clip.antiAliasWithSaveLayer'),
    );
  });

261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
  test('PictureLayer prints picture, engine layer, and raster cache hints in debug info', () {
    final PictureRecorder recorder = PictureRecorder();
    final Canvas canvas = Canvas(recorder);
    canvas.drawPaint(Paint());
    final Picture picture = recorder.endRecording();
    final PictureLayer layer = PictureLayer(const Rect.fromLTRB(0, 0, 1, 1));
    layer.picture = picture;
    layer.isComplexHint = true;
    layer.willChangeHint = false;
    final List<String> info = _getDebugInfo(layer);
    expect(info, contains('picture: ${describeIdentity(picture)}'));
    expect(info, contains('engine layer: ${describeIdentity(null)}'));
    expect(info, contains('raster cache hints: isComplex = true, willChange = false'));
  });

276 277 278 279
  test('mutating PictureLayer fields triggers needsAddToScene', () {
    final PictureLayer pictureLayer = PictureLayer(Rect.zero);
    checkNeedsAddToScene(pictureLayer, () {
      final PictureRecorder recorder = PictureRecorder();
280
      Canvas(recorder);
281 282 283 284 285 286 287 288 289 290 291 292 293 294
      pictureLayer.picture = recorder.endRecording();
    });

    pictureLayer.isComplexHint = false;
    checkNeedsAddToScene(pictureLayer, () {
      pictureLayer.isComplexHint = true;
    });

    pictureLayer.willChangeHint = false;
    checkNeedsAddToScene(pictureLayer, () {
      pictureLayer.willChangeHint = true;
    });
  });

Dan Field's avatar
Dan Field committed
295
  const Rect unitRect = Rect.fromLTRB(0, 0, 1, 1);
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

  test('mutating PerformanceOverlayLayer fields triggers needsAddToScene', () {
    final PerformanceOverlayLayer layer = PerformanceOverlayLayer(
        overlayRect: Rect.zero, optionsMask: 0, rasterizerThreshold: 0,
        checkerboardRasterCacheImages: false, checkerboardOffscreenLayers: false);
    checkNeedsAddToScene(layer, () {
      layer.overlayRect = unitRect;
    });
  });

  test('mutating OffsetLayer fields triggers needsAddToScene', () {
    final OffsetLayer layer = OffsetLayer();
    checkNeedsAddToScene(layer, () {
      layer.offset = const Offset(1, 1);
    });
  });

  test('mutating ClipRectLayer fields triggers needsAddToScene', () {
    final ClipRectLayer layer = ClipRectLayer(clipRect: Rect.zero);
    checkNeedsAddToScene(layer, () {
      layer.clipRect = unitRect;
    });
    checkNeedsAddToScene(layer, () {
      layer.clipBehavior = Clip.antiAliasWithSaveLayer;
    });
  });

  test('mutating ClipRRectLayer fields triggers needsAddToScene', () {
    final ClipRRectLayer layer = ClipRRectLayer(clipRRect: RRect.zero);
    checkNeedsAddToScene(layer, () {
      layer.clipRRect = RRect.fromRectAndRadius(unitRect, const Radius.circular(0));
    });
    checkNeedsAddToScene(layer, () {
      layer.clipBehavior = Clip.antiAliasWithSaveLayer;
    });
  });

  test('mutating ClipPath fields triggers needsAddToScene', () {
    final ClipPathLayer layer = ClipPathLayer(clipPath: Path());
    checkNeedsAddToScene(layer, () {
      final Path newPath = Path();
      newPath.addRect(unitRect);
      layer.clipPath = newPath;
    });
    checkNeedsAddToScene(layer, () {
      layer.clipBehavior = Clip.antiAliasWithSaveLayer;
    });
  });

  test('mutating OpacityLayer fields triggers needsAddToScene', () {
    final OpacityLayer layer = OpacityLayer(alpha: 0);
    checkNeedsAddToScene(layer, () {
      layer.alpha = 1;
    });
    checkNeedsAddToScene(layer, () {
      layer.offset = const Offset(1, 1);
    });
  });

355 356 357 358 359 360 361 362 363
  test('mutating ColorFilterLayer fields triggers needsAddToScene', () {
    final ColorFilterLayer layer = ColorFilterLayer(
      colorFilter: const ColorFilter.mode(Color(0xFFFF0000), BlendMode.color),
    );
    checkNeedsAddToScene(layer, () {
      layer.colorFilter = const ColorFilter.mode(Color(0xFF00FF00), BlendMode.color);
    });
  });

364
  test('mutating ShaderMaskLayer fields triggers needsAddToScene', () {
365
    const Gradient gradient = RadialGradient(colors: <Color>[Color(0x00000000), Color(0x00000001)]);
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
    final Shader shader = gradient.createShader(Rect.zero);
    final ShaderMaskLayer layer = ShaderMaskLayer(shader: shader, maskRect: Rect.zero, blendMode: BlendMode.clear);
    checkNeedsAddToScene(layer, () {
      layer.maskRect = unitRect;
    });
    checkNeedsAddToScene(layer, () {
      layer.blendMode = BlendMode.color;
    });
    checkNeedsAddToScene(layer, () {
      layer.shader = gradient.createShader(unitRect);
    });
  });

  test('mutating BackdropFilterLayer fields triggers needsAddToScene', () {
    final BackdropFilterLayer layer = BackdropFilterLayer(filter: ImageFilter.blur());
    checkNeedsAddToScene(layer, () {
      layer.filter = ImageFilter.blur(sigmaX: 1.0);
    });
  });

  test('mutating PhysicalModelLayer fields triggers needsAddToScene', () {
    final PhysicalModelLayer layer = PhysicalModelLayer(
388
        clipPath: Path(), elevation: 0, color: const Color(0x00000000), shadowColor: const Color(0x00000000));
389 390 391 392 393 394 395 396 397
    checkNeedsAddToScene(layer, () {
      final Path newPath = Path();
      newPath.addRect(unitRect);
      layer.clipPath = newPath;
    });
    checkNeedsAddToScene(layer, () {
      layer.elevation = 1;
    });
    checkNeedsAddToScene(layer, () {
398
      layer.color = const Color(0x00000001);
399 400
    });
    checkNeedsAddToScene(layer, () {
401
      layer.shadowColor = const Color(0x00000001);
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

  group('PhysicalModelLayer checks elevations', () {
    /// Adds the layers to a container where A paints before B.
    ///
    /// Expects there to be `expectedErrorCount` errors.  Checking elevations is
    /// enabled by default.
    void _testConflicts(
      PhysicalModelLayer layerA,
      PhysicalModelLayer layerB, {
      @required int expectedErrorCount,
      bool enableCheck = true,
    }) {
      assert(expectedErrorCount != null);
      assert(enableCheck || expectedErrorCount == 0, 'Cannot disable check and expect non-zero error count.');
      final OffsetLayer container = OffsetLayer();
      container.append(layerA);
      container.append(layerB);
      debugCheckElevationsEnabled = enableCheck;
      debugDisableShadows = false;
      int errors = 0;
      if (enableCheck) {
        FlutterError.onError = (FlutterErrorDetails details) {
          errors++;
        };
      }
      container.buildScene(SceneBuilder());
      expect(errors, expectedErrorCount);
      debugCheckElevationsEnabled = false;
    }

    // Tests:
    //
    //  ─────────────                    (LayerA, paints first)
    //      │     ─────────────          (LayerB, paints second)
    //      │          │
    // ───────────────────────────
    test('Overlapping layers at wrong elevation', () {
      final PhysicalModelLayer layerA = PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
442
        clipPath: Path()..addRect(const Rect.fromLTWH(0, 0, 20, 20)),
443
        elevation: 3.0,
444 445
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
446 447
      );
      final PhysicalModelLayer layerB =PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
448
        clipPath: Path()..addRect(const Rect.fromLTWH(10, 10, 20, 20)),
449
        elevation: 2.0,
450 451
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
452 453
      );
      _testConflicts(layerA, layerB, expectedErrorCount: 1);
454
    }, skip: isBrowser); // https://github.com/flutter/flutter/issues/44572
455 456 457 458 459 460 461 462 463 464 465

    // Tests:
    //
    //  ─────────────                    (LayerA, paints first)
    //      │     ─────────────          (LayerB, paints second)
    //      │         │
    // ───────────────────────────
    //
    // Causes no error if check is disabled.
    test('Overlapping layers at wrong elevation, check disabled', () {
      final PhysicalModelLayer layerA = PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
466
        clipPath: Path()..addRect(const Rect.fromLTWH(0, 0, 20, 20)),
467
        elevation: 3.0,
468 469
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
470 471
      );
      final PhysicalModelLayer layerB =PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
472
        clipPath: Path()..addRect(const Rect.fromLTWH(10, 10, 20, 20)),
473
        elevation: 2.0,
474 475
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
476 477 478 479 480 481 482 483 484 485 486 487
      );
      _testConflicts(layerA, layerB, expectedErrorCount: 0, enableCheck: false);
    });

    // Tests:
    //
    //   ──────────                      (LayerA, paints first)
    //        │       ───────────        (LayerB, paints second)
    //        │            │
    // ────────────────────────────
    test('Non-overlapping layers at wrong elevation', () {
      final PhysicalModelLayer layerA = PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
488
        clipPath: Path()..addRect(const Rect.fromLTWH(0, 0, 20, 20)),
489
        elevation: 3.0,
490 491
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
492 493
      );
      final PhysicalModelLayer layerB =PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
494
        clipPath: Path()..addRect(const Rect.fromLTWH(20, 20, 20, 20)),
495
        elevation: 2.0,
496 497
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
498 499
      );
      _testConflicts(layerA, layerB, expectedErrorCount: 0);
500
    }, skip: isBrowser); // https://github.com/flutter/flutter/issues/44572
501 502 503 504 505 506 507 508 509 510 511

    // Tests:
    //
    //     ───────                       (Child of A, paints second)
    //        │
    //   ───────────                     (LayerA, paints first)
    //        │       ────────────       (LayerB, paints third)
    //        │             │
    // ────────────────────────────
    test('Non-overlapping layers at wrong elevation, child at lower elevation', () {
      final PhysicalModelLayer layerA = PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
512
        clipPath: Path()..addRect(const Rect.fromLTWH(0, 0, 20, 20)),
513
        elevation: 3.0,
514 515
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
516 517 518
      );

      layerA.append(PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
519
        clipPath: Path()..addRect(const Rect.fromLTWH(2, 2, 10, 10)),
520
        elevation: 1.0,
521 522
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
523 524 525
      ));

      final PhysicalModelLayer layerB =PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
526
        clipPath: Path()..addRect(const Rect.fromLTWH(20, 20, 20, 20)),
527
        elevation: 2.0,
528 529
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
530 531
      );
      _testConflicts(layerA, layerB, expectedErrorCount: 0);
532
    }, skip: isBrowser); // https://github.com/flutter/flutter/issues/44572
533 534 535 536 537 538 539 540 541 542 543 544 545 546

    // Tests:
    //
    //        ───────────                (Child of A, paints second, overflows)
    //           │    ────────────       (LayerB, paints third)
    //   ───────────       │             (LayerA, paints first)
    //         │           │
    //         │           │
    // ────────────────────────────
    //
    // Which fails because the overflowing child overlaps something that paints
    // after it at a lower elevation.
    test('Child overflows parent and overlaps another physical layer', () {
      final PhysicalModelLayer layerA = PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
547
        clipPath: Path()..addRect(const Rect.fromLTWH(0, 0, 20, 20)),
548
        elevation: 3.0,
549 550
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
551 552 553
      );

      layerA.append(PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
554
        clipPath: Path()..addRect(const Rect.fromLTWH(15, 15, 25, 25)),
555
        elevation: 2.0,
556 557
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
558 559 560
      ));

      final PhysicalModelLayer layerB =PhysicalModelLayer(
Dan Field's avatar
Dan Field committed
561
        clipPath: Path()..addRect(const Rect.fromLTWH(20, 20, 20, 20)),
562
        elevation: 4.0,
563 564
        color: const Color(0x00000000),
        shadowColor: const Color(0x00000000),
565 566 567
      );

      _testConflicts(layerA, layerB, expectedErrorCount: 1);
568 569
    }, skip: isBrowser); // https://github.com/flutter/flutter/issues/44572
  });
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586

  test('ContainerLayer.toImage can render interior layer', () {
    final OffsetLayer parent = OffsetLayer();
    final OffsetLayer child = OffsetLayer();
    final OffsetLayer grandChild = OffsetLayer();
    child.append(grandChild);
    parent.append(child);

    // This renders the layers and generates engine layers.
    parent.buildScene(SceneBuilder());

    // Causes grandChild to pass its engine layer as `oldLayer`
    grandChild.toImage(const Rect.fromLTRB(0, 0, 10, 10));

    // Ensure we can render the same scene again after rendering an interior
    // layer.
    parent.buildScene(SceneBuilder());
587
  }, skip: isBrowser); // TODO(yjbanov): `toImage` doesn't work on the Web: https://github.com/flutter/flutter/issues/42767
588 589 590 591 592
}

class _TestAlwaysNeedsAddToSceneLayer extends ContainerLayer {
  @override
  bool get alwaysNeedsAddToScene => true;
593
}