• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5part of engine;
6
7/// A surface that transforms its children using CSS transform.
8class PersistedTransform extends PersistedContainerSurface
9    implements ui.TransformEngineLayer {
10  PersistedTransform(PersistedTransform oldLayer, this.matrix4)
11      : super(oldLayer);
12
13  final Float64List matrix4;
14
15  @override
16  void recomputeTransformAndClip() {
17    _transform = parent._transform.multiplied(Matrix4.fromFloat64List(matrix4));
18    _globalClip = parent._globalClip;
19  }
20
21  @override
22  html.Element createElement() {
23    return defaultCreateElement('flt-transform')
24      ..style.transformOrigin = '0 0 0';
25  }
26
27  @override
28  void apply() {
29    rootElement.style.transform = float64ListToCssTransform(matrix4);
30  }
31
32  @override
33  void update(PersistedTransform oldSurface) {
34    super.update(oldSurface);
35
36    if (identical(oldSurface.matrix4, matrix4)) {
37      return;
38    }
39
40    bool matrixChanged = false;
41    for (int i = 0; i < matrix4.length; i++) {
42      if (matrix4[i] != oldSurface.matrix4[i]) {
43        matrixChanged = true;
44        break;
45      }
46    }
47
48    if (matrixChanged) {
49      apply();
50    }
51  }
52}
53