| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium 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 |
| 5 #include <memory> |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "cc/animation/animation_host.h" |
| 10 #include "cc/blimp/layer_tree_host_remote.h" |
| 11 #include "cc/layers/empty_content_layer_client.h" |
| 12 #include "cc/layers/heads_up_display_layer.h" |
| 13 #include "cc/layers/layer.h" |
| 14 #include "cc/proto/layer.pb.h" |
| 15 #include "cc/proto/layer_tree_host.pb.h" |
| 16 #include "cc/test/fake_image_serialization_processor.h" |
| 17 #include "cc/test/fake_layer_tree_host.h" |
| 18 #include "cc/test/fake_layer_tree_host_client.h" |
| 19 #include "cc/test/fake_picture_layer.h" |
| 20 #include "cc/test/fake_recording_source.h" |
| 21 #include "cc/test/remote_client_layer_factory.h" |
| 22 #include "cc/test/remote_compositor_test.h" |
| 23 #include "cc/test/serialization_test_utils.h" |
| 24 #include "cc/test/skia_common.h" |
| 25 #include "cc/trees/layer_tree.h" |
| 26 #include "cc/trees/layer_tree_host_common.h" |
| 27 #include "cc/trees/layer_tree_settings.h" |
| 28 #include "third_party/skia/include/core/SkColor.h" |
| 29 #include "ui/gfx/geometry/point.h" |
| 30 #include "ui/gfx/geometry/size.h" |
| 31 #include "ui/gfx/geometry/vector2d_f.h" |
| 32 |
| 33 namespace cc { |
| 34 |
| 35 class LayerTreeHostSerializationTest : public RemoteCompositorTest { |
| 36 protected: |
| 37 void VerifySerializationAndDeserialization() { |
| 38 // Synchronize state. |
| 39 base::RunLoop().RunUntilIdle(); |
| 40 VerifySerializedTreesAreIdentical( |
| 41 layer_tree_host_remote_->GetLayerTree(), |
| 42 layer_tree_host_in_process_->GetLayerTree(), |
| 43 compositor_state_deserializer_.get()); |
| 44 } |
| 45 |
| 46 void SetUpViewportLayers(LayerTree* engine_layer_tree) { |
| 47 scoped_refptr<Layer> overscroll_elasticity_layer = Layer::Create(); |
| 48 scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
| 49 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
| 50 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
| 51 |
| 52 engine_layer_tree->root_layer()->AddChild(overscroll_elasticity_layer); |
| 53 engine_layer_tree->root_layer()->AddChild(page_scale_layer); |
| 54 engine_layer_tree->root_layer()->AddChild(inner_viewport_scroll_layer); |
| 55 engine_layer_tree->root_layer()->AddChild(outer_viewport_scroll_layer); |
| 56 |
| 57 engine_layer_tree->RegisterViewportLayers( |
| 58 overscroll_elasticity_layer, page_scale_layer, |
| 59 inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
| 60 } |
| 61 }; |
| 62 |
| 63 TEST_F(LayerTreeHostSerializationTest, AllMembersChanged) { |
| 64 LayerTree* engine_layer_tree = layer_tree_host_remote_->GetLayerTree(); |
| 65 |
| 66 engine_layer_tree->SetRootLayer(Layer::Create()); |
| 67 scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 68 engine_layer_tree->root_layer()->SetMaskLayer(mask_layer.get()); |
| 69 SetUpViewportLayers(engine_layer_tree); |
| 70 |
| 71 engine_layer_tree->SetViewportSize(gfx::Size(3, 14)); |
| 72 engine_layer_tree->SetDeviceScaleFactor(4.f); |
| 73 engine_layer_tree->SetPaintedDeviceScaleFactor(2.f); |
| 74 engine_layer_tree->SetPageScaleFactorAndLimits(2.f, 0.5f, 3.f); |
| 75 engine_layer_tree->set_background_color(SK_ColorMAGENTA); |
| 76 engine_layer_tree->set_has_transparent_background(true); |
| 77 LayerSelectionBound sel_bound; |
| 78 sel_bound.edge_top = gfx::Point(14, 3); |
| 79 LayerSelection selection; |
| 80 selection.start = sel_bound; |
| 81 engine_layer_tree->RegisterSelection(selection); |
| 82 VerifySerializationAndDeserialization(); |
| 83 } |
| 84 |
| 85 TEST_F(LayerTreeHostSerializationTest, LayersChangedMultipleSerializations) { |
| 86 LayerTree* engine_layer_tree = layer_tree_host_remote_->GetLayerTree(); |
| 87 engine_layer_tree->SetRootLayer(Layer::Create()); |
| 88 SetUpViewportLayers(engine_layer_tree); |
| 89 |
| 90 VerifySerializationAndDeserialization(); |
| 91 |
| 92 scoped_refptr<Layer> new_child = Layer::Create(); |
| 93 engine_layer_tree->root_layer()->AddChild(new_child); |
| 94 engine_layer_tree->RegisterViewportLayers(nullptr, nullptr, nullptr, nullptr); |
| 95 VerifySerializationAndDeserialization(); |
| 96 |
| 97 engine_layer_tree->SetRootLayer(nullptr); |
| 98 VerifySerializationAndDeserialization(); |
| 99 } |
| 100 |
| 101 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) { |
| 102 /* Testing serialization when the tree hierarchy changes like this: |
| 103 root root |
| 104 / \ / \ |
| 105 a b => a c |
| 106 \ \ |
| 107 c d |
| 108 */ |
| 109 LayerTree* engine_layer_tree = layer_tree_host_remote_->GetLayerTree(); |
| 110 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
| 111 engine_layer_tree->SetRootLayer(layer_src_root); |
| 112 |
| 113 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
| 114 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
| 115 scoped_refptr<Layer> layer_src_c = Layer::Create(); |
| 116 scoped_refptr<Layer> layer_src_d = Layer::Create(); |
| 117 |
| 118 layer_src_root->AddChild(layer_src_a); |
| 119 layer_src_root->AddChild(layer_src_b); |
| 120 layer_src_b->AddChild(layer_src_c); |
| 121 VerifySerializationAndDeserialization(); |
| 122 |
| 123 // Now change the Layer Hierarchy |
| 124 layer_src_c->RemoveFromParent(); |
| 125 layer_src_b->RemoveFromParent(); |
| 126 layer_src_root->AddChild(layer_src_c); |
| 127 layer_src_c->AddChild(layer_src_d); |
| 128 VerifySerializationAndDeserialization(); |
| 129 } |
| 130 |
| 131 TEST_F(LayerTreeHostSerializationTest, PictureLayerSerialization) { |
| 132 // Override the layer factor to create FakePictureLayers in the deserializer. |
| 133 compositor_state_deserializer_->SetLayerFactoryForTesting( |
| 134 base::MakeUnique<RemoteClientLayerFactory>()); |
| 135 |
| 136 LayerTree* engine_layer_tree = layer_tree_host_remote_->GetLayerTree(); |
| 137 scoped_refptr<Layer> root_layer_src = Layer::Create(); |
| 138 engine_layer_tree->SetRootLayer(root_layer_src); |
| 139 |
| 140 // Ensure that a PictureLayer work correctly for multiple rounds of |
| 141 // serialization and deserialization. |
| 142 FakeContentLayerClient content_client; |
| 143 gfx::Size bounds(256, 256); |
| 144 content_client.set_bounds(bounds); |
| 145 SkPaint simple_paint; |
| 146 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34)); |
| 147 content_client.add_draw_rect(gfx::Rect(bounds), simple_paint); |
| 148 scoped_refptr<FakePictureLayer> picture_layer_src = |
| 149 FakePictureLayer::Create(&content_client); |
| 150 |
| 151 root_layer_src->AddChild(picture_layer_src); |
| 152 picture_layer_src->SetNeedsDisplay(); |
| 153 VerifySerializationAndDeserialization(); |
| 154 |
| 155 layer_tree_host_in_process_->UpdateLayers(); |
| 156 PictureLayer* picture_layer_dst = reinterpret_cast<PictureLayer*>( |
| 157 compositor_state_deserializer_->GetLayerForEngineId( |
| 158 picture_layer_src->id())); |
| 159 EXPECT_TRUE(AreDisplayListDrawingResultsSame( |
| 160 gfx::Rect(gfx::Rect(picture_layer_src->bounds())), |
| 161 picture_layer_src->GetDisplayItemList(), |
| 162 picture_layer_dst->GetDisplayItemList())); |
| 163 |
| 164 // Another round. |
| 165 picture_layer_src->SetNeedsDisplay(); |
| 166 VerifySerializationAndDeserialization(); |
| 167 layer_tree_host_in_process_->UpdateLayers(); |
| 168 EXPECT_TRUE(AreDisplayListDrawingResultsSame( |
| 169 gfx::Rect(gfx::Rect(picture_layer_src->bounds())), |
| 170 picture_layer_src->GetDisplayItemList(), |
| 171 picture_layer_dst->GetDisplayItemList())); |
| 172 } |
| 173 |
| 174 } // namespace cc |
| OLD | NEW |