summaryrefslogtreecommitdiffstats
path: root/cc/layers/layer_utils_unittest.cc
blob: e915c41f6b574d8ab204070cafd6816df9f472ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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
220
221
222
223
224
225
226
227
228
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/layers/layer_utils.h"

#include "cc/animation/animation_host.h"
#include "cc/animation/animation_id_provider.h"
#include "cc/animation/transform_operations.h"
#include "cc/layers/layer_impl.h"
#include "cc/test/animation_test_common.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/box_f.h"
#include "ui/gfx/test/gfx_util.h"

namespace cc {
namespace {

float diagonal(float width, float height) {
  return std::sqrt(width * width + height * height);
}

class LayerUtilsGetAnimationBoundsTest : public testing::Test {
 public:
  LayerUtilsGetAnimationBoundsTest()
      : host_impl_(&task_runner_provider_,
                   &shared_bitmap_manager_,
                   &task_graph_runner_),
        root_(CreateTwoForkTree(&host_impl_)),
        parent1_(root_->children()[0].get()),
        parent2_(root_->children()[1].get()),
        child1_(parent1_->children()[0].get()),
        child2_(parent2_->children()[0].get()),
        grand_child_(child2_->children()[0].get()),
        great_grand_child_(grand_child_->children()[0].get()) {
    timeline_ =
        AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
    host_impl_.animation_host()->AddAnimationTimeline(timeline_);
  }

  LayerImpl* root() { return root_; }
  LayerImpl* parent1() { return parent1_; }
  LayerImpl* child1() { return child1_; }
  LayerImpl* parent2() { return parent2_; }
  LayerImpl* child2() { return child2_; }
  LayerImpl* grand_child() { return grand_child_; }
  LayerImpl* great_grand_child() { return great_grand_child_; }

  scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
  FakeLayerTreeHostImpl& host_impl() { return host_impl_; }

 private:
  static LayerImpl* CreateTwoForkTree(LayerTreeHostImpl* host_impl) {
    scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl->active_tree(), 1);
    LayerImpl* root_ptr = root.get();
    root->AddChild(LayerImpl::Create(host_impl->active_tree(), 2));
    root->children()[0]->AddChild(
        LayerImpl::Create(host_impl->active_tree(), 3));
    root->AddChild(LayerImpl::Create(host_impl->active_tree(), 4));
    root->children()[1]->AddChild(
        LayerImpl::Create(host_impl->active_tree(), 5));
    root->children()[1]->children()[0]->AddChild(
        LayerImpl::Create(host_impl->active_tree(), 6));
    root->children()[1]->children()[0]->children()[0]->AddChild(
        LayerImpl::Create(host_impl->active_tree(), 7));
    host_impl->active_tree()->SetRootLayer(std::move(root));
    return root_ptr;
  }

  FakeImplTaskRunnerProvider task_runner_provider_;
  TestSharedBitmapManager shared_bitmap_manager_;
  TestTaskGraphRunner task_graph_runner_;
  FakeLayerTreeHostImpl host_impl_;
  LayerImpl* root_;
  LayerImpl* parent1_;
  LayerImpl* parent2_;
  LayerImpl* child1_;
  LayerImpl* child2_;
  LayerImpl* grand_child_;
  LayerImpl* great_grand_child_;
  scoped_refptr<AnimationTimeline> timeline_;
};

TEST_F(LayerUtilsGetAnimationBoundsTest, ScaleRoot) {
  double duration = 1.0;

  TransformOperations start;
  start.AppendScale(1.f, 1.f, 1.f);
  TransformOperations end;
  end.AppendScale(2.f, 2.f, 1.f);
  AddAnimatedTransformToLayerWithPlayer(root()->id(), timeline(), duration,
                                        start, end);

  root()->SetPosition(gfx::PointF());
  parent1()->SetPosition(gfx::PointF());
  parent1()->SetBounds(gfx::Size(350, 200));

  child1()->SetDrawsContent(true);
  child1()->SetPosition(gfx::PointF(150.f, 50.f));
  child1()->SetBounds(gfx::Size(100, 200));

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
  EXPECT_TRUE(success);
  gfx::BoxF expected(150.f, 50.f, 0.f, 350.f, 450.f, 0.f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest, TranslateParentLayer) {
  double duration = 1.0;

  TransformOperations start;
  start.AppendTranslate(0.f, 0.f, 0.f);
  TransformOperations end;
  end.AppendTranslate(50.f, 50.f, 0.f);
  AddAnimatedTransformToLayerWithPlayer(parent1()->id(), timeline(), duration,
                                        start, end);

  parent1()->SetBounds(gfx::Size(350, 200));

  child1()->SetDrawsContent(true);
  child1()->SetPosition(gfx::PointF(150.f, 50.f));
  child1()->SetBounds(gfx::Size(100, 200));

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
  EXPECT_TRUE(success);
  gfx::BoxF expected(150.f, 50.f, 0.f, 150.f, 250.f, 0.f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest, TranslateChildLayer) {
  double duration = 1.0;

  TransformOperations start;
  start.AppendTranslate(0.f, 0.f, 0.f);
  TransformOperations end;
  end.AppendTranslate(50.f, 50.f, 0.f);
  AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration,
                                        start, end);
  parent1()->SetBounds(gfx::Size(350, 200));

  child1()->SetDrawsContent(true);
  child1()->SetPosition(gfx::PointF(150.f, 50.f));
  child1()->SetBounds(gfx::Size(100, 200));

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
  EXPECT_TRUE(success);
  gfx::BoxF expected(150.f, 50.f, 0.f, 150.f, 250.f, 0.f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest, TranslateBothLayers) {
  double duration = 1.0;

  TransformOperations start;
  start.AppendTranslate(0.f, 0.f, 0.f);
  TransformOperations child_end;
  child_end.AppendTranslate(50.f, 0.f, 0.f);
  AddAnimatedTransformToLayerWithPlayer(parent1()->id(), timeline(), duration,
                                        start, child_end);

  TransformOperations grand_child_end;
  grand_child_end.AppendTranslate(0.f, 50.f, 0.f);
  AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration,
                                        start, grand_child_end);

  parent1()->SetBounds(gfx::Size(350, 200));

  child1()->SetDrawsContent(true);
  child1()->SetPosition(gfx::PointF(150.f, 50.f));
  child1()->SetBounds(gfx::Size(100, 200));

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
  EXPECT_TRUE(success);
  gfx::BoxF expected(150.f, 50.f, 0.f, 150.f, 250.f, 0.f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXNoPerspective) {
  double duration = 1.0;

  TransformOperations start;
  start.AppendRotate(1.f, 0.f, 0.f, 0.f);
  TransformOperations end;
  end.AppendRotate(1.f, 0.f, 0.f, 90.f);

  AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration,
                                        start, end);

  parent1()->SetBounds(gfx::Size(350, 200));

  gfx::Size bounds(100, 100);
  child1()->SetDrawsContent(true);
  child1()->SetPosition(gfx::PointF(150.f, 50.f));
  child1()->SetBounds(bounds);
  child1()->SetTransformOrigin(
      gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0));

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
  EXPECT_TRUE(success);
  gfx::BoxF expected(150.f, 50.f, -50.f, 100.f, 100.f, 100.f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspective) {
  double duration = 1.0;

  TransformOperations start;
  start.AppendRotate(1.f, 0.f, 0.f, 0.f);
  TransformOperations end;
  end.AppendRotate(1.f, 0.f, 0.f, 90.f);

  AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration,
                                        start, end);

  // Make the anchor point not the default 0.5 value and line up with the
  // child center to make the math easier.
  parent1()->SetTransformOrigin(
      gfx::Point3F(0.375f * 400.f, 0.375f * 400.f, 0.f));
  parent1()->SetBounds(gfx::Size(400, 400));

  gfx::Transform perspective;
  perspective.ApplyPerspectiveDepth(100.f);
  parent1()->SetTransform(perspective);

  gfx::Size bounds(100, 100);
  child1()->SetDrawsContent(true);
  child1()->SetPosition(gfx::PointF(100.f, 100.f));
  child1()->SetBounds(bounds);
  child1()->SetTransformOrigin(
      gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0));

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
  EXPECT_TRUE(success);
  gfx::BoxF expected(50.f, 50.f, -33.333336f, 200.f, 200.f, 133.333344f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspectiveOnSameLayer) {
  // This test is used to check whether GetAnimationBounds correctly ignores the
  // local transform when there is an animation applied to the layer / node.
  // The intended behavior is that the animation should overwrite the transform.

  double duration = 1.0;

  TransformOperations start;
  start.AppendRotate(1.f, 0.f, 0.f, 0.f);
  TransformOperations end;
  end.AppendRotate(1.f, 0.f, 0.f, 90.f);

  AddAnimatedTransformToLayerWithPlayer(parent1()->id(), timeline(), duration,
                                        start, end);

  // Make the anchor point not the default 0.5 value and line up
  // with the child center to make the math easier.
  parent1()->SetTransformOrigin(
      gfx::Point3F(0.375f * 400.f, 0.375f * 400.f, 0.f));
  parent1()->SetBounds(gfx::Size(400, 400));

  gfx::Transform perspective;
  perspective.ApplyPerspectiveDepth(100.f);
  parent1()->SetTransform(perspective);

  gfx::Size bounds(100, 100);
  child1()->SetDrawsContent(true);
  child1()->SetPosition(gfx::PointF(100.f, 100.f));
  child1()->SetBounds(bounds);
  child1()->SetTransformOrigin(
      gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0));

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
  EXPECT_TRUE(success);
  gfx::BoxF expected(100.f, 100.f, -50.f, 100.f, 100.f, 100.f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest, RotateZ) {
  double duration = 1.0;

  TransformOperations start;
  start.AppendRotate(0.f, 0.f, 1.f, 0.f);
  TransformOperations end;
  end.AppendRotate(0.f, 0.f, 1.f, 90.f);
  AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration,
                                        start, end);

  parent1()->SetBounds(gfx::Size(350, 200));

  gfx::Size bounds(100, 100);
  child1()->SetDrawsContent(true);
  child1()->SetPosition(gfx::PointF(150.f, 50.f));
  child1()->SetBounds(bounds);
  child1()->SetTransformOrigin(
      gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0));

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
  EXPECT_TRUE(success);
  float diag = diagonal(bounds.width(), bounds.height());
  gfx::BoxF expected(150.f + 0.5f * (bounds.width() - diag),
                     50.f + 0.5f * (bounds.height() - diag),
                     0.f,
                     diag,
                     diag,
                     0.f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest, MismatchedTransforms) {
  double duration = 1.0;

  TransformOperations start;
  start.AppendTranslate(5, 6, 7);
  TransformOperations end;
  end.AppendRotate(0.f, 0.f, 1.f, 90.f);
  AddAnimatedTransformToLayerWithPlayer(child1()->id(), timeline(), duration,
                                        start, end);

  parent1()->SetBounds(gfx::Size(350, 200));

  gfx::Size bounds(100, 100);
  child1()->SetDrawsContent(true);
  child1()->SetPosition(gfx::PointF(150.f, 50.f));
  child1()->SetBounds(bounds);

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
  EXPECT_FALSE(success);
}

TEST_F(LayerUtilsGetAnimationBoundsTest,
       TransformUnderAncestorsWithPositionOr2DTransform) {
  // Tree topology:
  // +root (Bounds)
  // +--parent2 (Position)
  // +----child2 (2d transform)
  // +------grand_child (Transform animation)
  // +--------great_grand_child (DrawsContent)
  // This test is used to check if GetAnimationBounds correctly skips layers and
  // take layers which do not own a transform_node into consideration.
  // Under this topology, only root and grand_child own transform_nodes.

  double duration = 1.0;

  TransformOperations start;
  start.AppendTranslate(0.f, 0.f, 0.f);
  TransformOperations great_grand_child_end;
  great_grand_child_end.AppendTranslate(50.f, 0.f, 0.f);
  AddAnimatedTransformToLayerWithPlayer(grand_child()->id(), timeline(),
                                        duration, start, great_grand_child_end);

  gfx::Transform translate_2d_transform;
  translate_2d_transform.Translate(80.f, 60.f);
  root()->SetBounds(gfx::Size(350, 200));
  parent2()->SetPosition(gfx::PointF(40.f, 45.f));
  child2()->SetTransform(translate_2d_transform);
  great_grand_child()->SetDrawsContent(true);
  great_grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
  great_grand_child()->SetBounds(gfx::Size(100, 200));
  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
  EXPECT_TRUE(success);
  gfx::BoxF expected(270.f, 155.f, 0.f, 150.f, 200.f, 0.f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest,
       RotateZUnderAncestorsWithPositionOr2DTransform) {
  double duration = 1.0;

  TransformOperations start;
  start.AppendRotate(0.f, 0.f, 1.f, 0.f);
  TransformOperations great_grand_child_end;
  great_grand_child_end.AppendRotate(0.f, 0.f, 1.f, 90.f);
  AddAnimatedTransformToLayerWithPlayer(grand_child()->id(), timeline(),
                                        duration, start, great_grand_child_end);

  gfx::Transform translate_2d_transform;
  translate_2d_transform.Translate(80.f, 60.f);
  root()->SetBounds(gfx::Size(350, 200));
  parent2()->SetPosition(gfx::PointF(40.f, 45.f));
  child2()->SetTransform(translate_2d_transform);

  gfx::Size bounds(100, 100);
  grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
  grand_child()->SetBounds(bounds);
  grand_child()->SetTransformOrigin(
      gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0));

  great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f));
  great_grand_child()->SetBounds(gfx::Size(50.f, 50.f));
  great_grand_child()->SetDrawsContent(true);

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
  EXPECT_TRUE(success);

  float diag = diagonal(50.f, 50.f);
  gfx::BoxF expected(320.f - 0.5f * diag, 205.f - 0.5f * diag, 0.f, diag, diag,
                     0.f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest,
       RotateXWithPerspectiveUnderAncestorsWithPositionOr2DTransform) {
  // Tree topology:
  // +root (Bounds)
  // +--parent2 (Position)
  // +----child2 (2d transform)
  // +------grand_child (Perspective)
  // +--------great_grand_child (RotateX, DrawsContent)
  // Due to the RotateX animation, great_grand_child also owns a transform_node

  double duration = 1.0;

  TransformOperations start;
  start.AppendRotate(1.f, 0.f, 0.f, 0.f);
  TransformOperations great_grand_child_end;
  great_grand_child_end.AppendRotate(1.f, 0.f, 0.f, 90.f);
  AddAnimatedTransformToLayerWithPlayer(great_grand_child()->id(), timeline(),
                                        duration, start, great_grand_child_end);

  gfx::Transform translate_2d_transform;
  translate_2d_transform.Translate(80.f, 60.f);

  root()->SetBounds(gfx::Size(350, 200));
  parent2()->SetPosition(gfx::PointF(40.f, 45.f));
  child2()->SetTransform(translate_2d_transform);

  gfx::Transform perspective;
  perspective.ApplyPerspectiveDepth(100.f);

  gfx::Size bounds(100.f, 100.f);
  grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
  grand_child()->SetBounds(bounds);
  grand_child()->SetTransform(perspective);
  grand_child()->SetTransformOrigin(
      gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0));

  great_grand_child()->SetTransformOrigin(
      gfx::Point3F(bounds.width() * 0.25f, bounds.height() * 0.25f, 0));
  great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f));
  great_grand_child()->SetBounds(gfx::Size(50.f, 50.f));
  great_grand_child()->SetDrawsContent(true);

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
  EXPECT_TRUE(success);

  // Translate and position offset to the root:
  //   40 + 150 + 80 + 25 = 295
  //   45 + 60 +50 + 25 = 180
  //   0
  // Animation Bounds Before Perspective:
  //   0, 0, -25, 50, 50, 50
  // Apply Perspective:
  //   When RotateX theta:
  //                          y
  //                          ^
  //              d1          |
  //             |  /         |
  //             | /          |
  //             |/           |
  //            /|            |
  //           / |            |
  //          /  |            |
  //         theta            |
  //  z<----------------------X
  //          d2
  //
  //     the diag is 25 * 2
  //
  //     box w: 2 * 25 * 100 / (100 - 25 * sin(theta)), max = 200 / 3 = 66.67
  //         h: same as w, 66.67
  //         d1: 25 * 100 * sin(theta) / (100 + 25 * sin(theta)), max = 100 / 5
  //             = 20
  //         d2: 25 * 100 * sin(theta) / (100 - 25 * sin(theta)), max = 100 / 3
  //             = 33.33
  //         d = d1 + d2 = 53.33
  //
  // Position Fix:
  //   295 - (66.67 - 50) / 2 = 286.67
  //   180 - (66.67 - 50) / 2 = 171.67
  //   0 - 20 = -20

  gfx::BoxF expected(286.666687f, 171.666672f, -20.f, 66.666656f, 66.666672f,
                     53.333336f);
  EXPECT_BOXF_EQ(expected, box);
}

TEST_F(LayerUtilsGetAnimationBoundsTest,
       RotateXNoPerspectiveUnderAncestorsWithPositionOr2DTransform) {
  double duration = 1.0;

  TransformOperations start;
  start.AppendRotate(1.f, 0.f, 0.f, 0.f);
  TransformOperations rotate_x_end;
  rotate_x_end.AppendRotate(1.f, 0.f, 0.f, 90.f);
  AddAnimatedTransformToLayerWithPlayer(great_grand_child()->id(), timeline(),
                                        duration, start, rotate_x_end);

  gfx::Transform translate_2d_transform;
  translate_2d_transform.Translate(80.f, 60.f);

  root()->SetBounds(gfx::Size(350, 200));
  parent2()->SetPosition(gfx::PointF(40.f, 45.f));
  child2()->SetTransform(translate_2d_transform);

  gfx::Size bounds(100.f, 100.f);
  grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
  grand_child()->SetBounds(bounds);

  great_grand_child()->SetTransformOrigin(
      gfx::Point3F(bounds.width() * 0.25f, bounds.height() * 0.25f, 0));
  great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f));
  great_grand_child()->SetBounds(
      gfx::Size(bounds.width() * 0.5f, bounds.height() * 0.5f));
  great_grand_child()->SetDrawsContent(true);

  host_impl().active_tree()->BuildPropertyTreesForTesting();

  gfx::BoxF box;
  bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
  EXPECT_TRUE(success);

  // Same as RotateXWithPerspectiveUnderAncestorsWithPositionOr2DTransform test,
  // except for the perspective calculations.

  gfx::BoxF expected(295.f, 180.f, -25.f, 50.f, 50.f, 50.f);
  EXPECT_BOXF_EQ(expected, box);
}

}  // namespace

}  // namespace cc