| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layers/picture_layer.h" | 5 #include "cc/layers/picture_layer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 void set_update_source_frame_number(int number) { | 53 void set_update_source_frame_number(int number) { |
| 54 update_source_frame_number_ = number; | 54 update_source_frame_number_ = number; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void set_is_mask(bool is_mask) { is_mask_ = is_mask; } | 57 void set_is_mask(bool is_mask) { is_mask_ = is_mask; } |
| 58 | 58 |
| 59 void set_nearest_neighbor(bool nearest_neighbor) { | 59 void set_nearest_neighbor(bool nearest_neighbor) { |
| 60 nearest_neighbor_ = nearest_neighbor; | 60 nearest_neighbor_ = nearest_neighbor; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void ValidateSerialization() { | 63 void ValidateSerialization( |
| 64 proto::LayerProperties proto; | 64 ImageSerializationProcessor* image_serialization_processor) { |
| 65 LayerSpecificPropertiesToProto(&proto); | |
| 66 | |
| 67 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 65 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 68 TestTaskGraphRunner task_graph_runner; | 66 TestTaskGraphRunner task_graph_runner; |
| 69 LayerTreeSettings settings; | 67 LayerTreeSettings settings; |
| 70 std::unique_ptr<FakeImageSerializationProcessor> | 68 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 71 fake_image_serialization_processor = | 69 &host_client, &task_graph_runner, settings, |
| 72 base::WrapUnique(new FakeImageSerializationProcessor); | 70 CompositorMode::SINGLE_THREADED, image_serialization_processor); |
| 73 std::unique_ptr<FakeLayerTreeHost> host = | 71 host->InitializePictureCacheForTesting(); |
| 74 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, | |
| 75 CompositorMode::SINGLE_THREADED, | |
| 76 fake_image_serialization_processor.get()); | |
| 77 scoped_refptr<TestSerializationPictureLayer> layer = | 72 scoped_refptr<TestSerializationPictureLayer> layer = |
| 78 TestSerializationPictureLayer::Create(recording_source_viewport_); | 73 TestSerializationPictureLayer::Create(recording_source_viewport_); |
| 79 host->SetRootLayer(layer); | 74 host->SetRootLayer(layer); |
| 75 |
| 76 recording_source()->SetEnginePictureCache(host->engine_picture_cache()); |
| 77 |
| 78 proto::LayerProperties proto; |
| 79 LayerSpecificPropertiesToProto(&proto); |
| 80 // The EnginePictureCache will be invalid after this method ends, so ensure |
| 81 // the recording source does not use it when the layer under test is |
| 82 // destructed. |
| 83 recording_source()->SetEnginePictureCache(nullptr); |
| 84 |
| 85 // The client must have the ClientPictureCache available during |
| 86 // deserialization. |
| 87 layer->recording_source()->SetClientPictureCache( |
| 88 host->client_picture_cache()); |
| 89 |
| 80 layer->FromLayerSpecificPropertiesProto(proto); | 90 layer->FromLayerSpecificPropertiesProto(proto); |
| 81 | 91 |
| 82 // Validate that the PictureLayer specific fields are properly set. | 92 // Validate that the PictureLayer specific fields are properly set. |
| 83 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); | 93 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); |
| 84 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); | 94 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); |
| 85 EXPECT_EQ(is_mask_, layer->is_mask_); | 95 EXPECT_EQ(is_mask_, layer->is_mask_); |
| 86 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); | 96 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); |
| 87 } | 97 } |
| 88 | 98 |
| 89 private: | 99 private: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 105 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 115 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 106 TestTaskGraphRunner task_graph_runner; | 116 TestTaskGraphRunner task_graph_runner; |
| 107 LayerTreeSettings settings; | 117 LayerTreeSettings settings; |
| 108 std::unique_ptr<FakeImageSerializationProcessor> | 118 std::unique_ptr<FakeImageSerializationProcessor> |
| 109 fake_image_serialization_processor = | 119 fake_image_serialization_processor = |
| 110 base::WrapUnique(new FakeImageSerializationProcessor); | 120 base::WrapUnique(new FakeImageSerializationProcessor); |
| 111 std::unique_ptr<FakeLayerTreeHost> host = | 121 std::unique_ptr<FakeLayerTreeHost> host = |
| 112 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, | 122 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, |
| 113 CompositorMode::SINGLE_THREADED, | 123 CompositorMode::SINGLE_THREADED, |
| 114 fake_image_serialization_processor.get()); | 124 fake_image_serialization_processor.get()); |
| 125 host->InitializePictureCacheForTesting(); |
| 115 | 126 |
| 116 gfx::Size recording_source_viewport(256, 256); | 127 gfx::Size recording_source_viewport(256, 256); |
| 117 scoped_refptr<TestSerializationPictureLayer> layer = | 128 scoped_refptr<TestSerializationPictureLayer> layer = |
| 118 TestSerializationPictureLayer::Create(recording_source_viewport); | 129 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 119 host->SetRootLayer(layer); | 130 host->SetRootLayer(layer); |
| 120 | 131 |
| 121 Region region(gfx::Rect(14, 15, 16, 17)); | 132 Region region(gfx::Rect(14, 15, 16, 17)); |
| 122 layer->set_invalidation(region); | 133 layer->set_invalidation(region); |
| 123 layer->set_is_mask(true); | 134 layer->set_is_mask(true); |
| 124 layer->set_nearest_neighbor(true); | 135 layer->set_nearest_neighbor(true); |
| 125 | 136 |
| 126 layer->SetBounds(recording_source_viewport); | 137 layer->SetBounds(recording_source_viewport); |
| 127 layer->set_update_source_frame_number(0); | 138 layer->set_update_source_frame_number(0); |
| 128 layer->recording_source()->SetDisplayListUsesCachedPicture(false); | 139 layer->recording_source()->SetDisplayListUsesCachedPicture(false); |
| 129 layer->recording_source()->add_draw_rect( | 140 layer->recording_source()->add_draw_rect( |
| 130 gfx::Rect(recording_source_viewport)); | 141 gfx::Rect(recording_source_viewport)); |
| 131 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); | 142 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); |
| 132 layer->recording_source()->Rerecord(); | 143 layer->recording_source()->Rerecord(); |
| 133 layer->ValidateSerialization(); | 144 layer->ValidateSerialization(fake_image_serialization_processor.get()); |
| 134 } | 145 } |
| 135 | 146 |
| 136 TEST(PictureLayerTest, TestSerializationDeserialization) { | 147 TEST(PictureLayerTest, TestSerializationDeserialization) { |
| 137 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 148 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 138 TestTaskGraphRunner task_graph_runner; | 149 TestTaskGraphRunner task_graph_runner; |
| 139 std::unique_ptr<FakeImageSerializationProcessor> | 150 std::unique_ptr<FakeImageSerializationProcessor> |
| 140 fake_image_serialization_processor = | 151 fake_image_serialization_processor = |
| 141 base::WrapUnique(new FakeImageSerializationProcessor); | 152 base::WrapUnique(new FakeImageSerializationProcessor); |
| 142 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( | 153 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 143 &host_client, &task_graph_runner, LayerTreeSettings(), | 154 &host_client, &task_graph_runner, LayerTreeSettings(), |
| 144 CompositorMode::SINGLE_THREADED, | 155 CompositorMode::SINGLE_THREADED, |
| 145 fake_image_serialization_processor.get()); | 156 fake_image_serialization_processor.get()); |
| 157 host->InitializePictureCacheForTesting(); |
| 158 |
| 146 gfx::Size recording_source_viewport(256, 256); | 159 gfx::Size recording_source_viewport(256, 256); |
| 147 scoped_refptr<TestSerializationPictureLayer> layer = | 160 scoped_refptr<TestSerializationPictureLayer> layer = |
| 148 TestSerializationPictureLayer::Create(recording_source_viewport); | 161 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 149 host->SetRootLayer(layer); | 162 host->SetRootLayer(layer); |
| 150 | 163 |
| 151 layer->SetBounds(recording_source_viewport); | 164 layer->SetBounds(recording_source_viewport); |
| 152 layer->set_update_source_frame_number(0); | 165 layer->set_update_source_frame_number(0); |
| 153 layer->recording_source()->SetDisplayListUsesCachedPicture(false); | 166 layer->recording_source()->SetDisplayListUsesCachedPicture(false); |
| 154 layer->recording_source()->add_draw_rect( | 167 layer->recording_source()->add_draw_rect( |
| 155 gfx::Rect(recording_source_viewport)); | 168 gfx::Rect(recording_source_viewport)); |
| 156 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); | 169 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); |
| 157 layer->recording_source()->Rerecord(); | 170 layer->recording_source()->Rerecord(); |
| 158 layer->ValidateSerialization(); | 171 layer->ValidateSerialization(fake_image_serialization_processor.get()); |
| 159 } | 172 } |
| 160 | 173 |
| 161 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { | 174 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { |
| 175 std::unique_ptr<FakeImageSerializationProcessor> |
| 176 fake_image_serialization_processor = |
| 177 base::WrapUnique(new FakeImageSerializationProcessor); |
| 162 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 178 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 163 TestTaskGraphRunner task_graph_runner; | 179 TestTaskGraphRunner task_graph_runner; |
| 164 std::unique_ptr<FakeLayerTreeHost> host = | 180 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 165 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 181 &host_client, &task_graph_runner, LayerTreeSettings(), |
| 182 CompositorMode::SINGLE_THREADED, |
| 183 fake_image_serialization_processor.get()); |
| 166 | 184 |
| 167 gfx::Size recording_source_viewport(256, 256); | 185 gfx::Size recording_source_viewport(256, 256); |
| 168 scoped_refptr<TestSerializationPictureLayer> layer = | 186 scoped_refptr<TestSerializationPictureLayer> layer = |
| 169 TestSerializationPictureLayer::Create(recording_source_viewport); | 187 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 170 host->SetRootLayer(layer); | 188 host->SetRootLayer(layer); |
| 171 layer->ValidateSerialization(); | 189 layer->ValidateSerialization(fake_image_serialization_processor.get()); |
| 172 } | 190 } |
| 173 | 191 |
| 174 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { | 192 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { |
| 175 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); | 193 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
| 176 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); | 194 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); |
| 177 layer->SetBounds(gfx::Size(10, 10)); | 195 layer->SetBounds(gfx::Size(10, 10)); |
| 178 | 196 |
| 179 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 197 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 180 TestTaskGraphRunner task_graph_runner; | 198 TestTaskGraphRunner task_graph_runner; |
| 181 std::unique_ptr<FakeLayerTreeHost> host = | 199 std::unique_ptr<FakeLayerTreeHost> host = |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // Do a main frame, record the picture layers. The frame number has changed | 485 // Do a main frame, record the picture layers. The frame number has changed |
| 468 // non-monotonically. | 486 // non-monotonically. |
| 469 layer->SetNeedsDisplay(); | 487 layer->SetNeedsDisplay(); |
| 470 host2->Composite(base::TimeTicks::Now()); | 488 host2->Composite(base::TimeTicks::Now()); |
| 471 EXPECT_EQ(3, layer->update_count()); | 489 EXPECT_EQ(3, layer->update_count()); |
| 472 EXPECT_EQ(1, host2->source_frame_number()); | 490 EXPECT_EQ(1, host2->source_frame_number()); |
| 473 } | 491 } |
| 474 | 492 |
| 475 } // namespace | 493 } // namespace |
| 476 } // namespace cc | 494 } // namespace cc |
| OLD | NEW |