| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 void set_update_source_frame_number(int number) { | 54 void set_update_source_frame_number(int number) { |
| 55 update_source_frame_number_ = number; | 55 update_source_frame_number_ = number; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void set_is_mask(bool is_mask) { is_mask_ = is_mask; } | 58 void set_is_mask(bool is_mask) { is_mask_ = is_mask; } |
| 59 | 59 |
| 60 void set_nearest_neighbor(bool nearest_neighbor) { | 60 void set_nearest_neighbor(bool nearest_neighbor) { |
| 61 nearest_neighbor_ = nearest_neighbor; | 61 nearest_neighbor_ = nearest_neighbor; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ValidateSerialization() { | 64 void ValidateSerialization( |
| 65 proto::LayerProperties proto; | 65 ImageSerializationProcessor* image_serialization_processor) { |
| 66 LayerSpecificPropertiesToProto(&proto); | |
| 67 | |
| 68 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 66 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 69 TestTaskGraphRunner task_graph_runner; | 67 TestTaskGraphRunner task_graph_runner; |
| 70 LayerTreeSettings settings; | 68 LayerTreeSettings settings; |
| 71 std::unique_ptr<FakeImageSerializationProcessor> | 69 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 72 fake_image_serialization_processor = | 70 &host_client, &task_graph_runner, settings, |
| 73 base::WrapUnique(new FakeImageSerializationProcessor); | 71 CompositorMode::SINGLE_THREADED, image_serialization_processor); |
| 74 std::unique_ptr<FakeLayerTreeHost> host = | 72 host->InitializePictureCacheForTesting(); |
| 75 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, | |
| 76 CompositorMode::SINGLE_THREADED, | |
| 77 fake_image_serialization_processor.get()); | |
| 78 scoped_refptr<TestSerializationPictureLayer> layer = | 73 scoped_refptr<TestSerializationPictureLayer> layer = |
| 79 TestSerializationPictureLayer::Create(recording_source_viewport_); | 74 TestSerializationPictureLayer::Create(recording_source_viewport_); |
| 80 host->SetRootLayer(layer); | 75 host->SetRootLayer(layer); |
| 76 |
| 77 recording_source()->SetEnginePictureCache(host->engine_picture_cache()); |
| 78 |
| 79 proto::LayerProperties proto; |
| 80 LayerSpecificPropertiesToProto(&proto); |
| 81 // The EnginePictureCache will be invalid after this method ends, so ensure |
| 82 // the recording source does not use it when the layer under test is |
| 83 // destructed. |
| 84 recording_source()->SetEnginePictureCache(nullptr); |
| 85 |
| 86 // The client must have the ClientPictureCache available during |
| 87 // deserialization. |
| 88 layer->recording_source()->SetClientPictureCache( |
| 89 host->client_picture_cache()); |
| 90 |
| 81 layer->FromLayerSpecificPropertiesProto(proto); | 91 layer->FromLayerSpecificPropertiesProto(proto); |
| 82 | 92 |
| 83 // Validate that the PictureLayer specific fields are properly set. | 93 // Validate that the PictureLayer specific fields are properly set. |
| 84 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); | 94 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); |
| 85 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); | 95 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); |
| 86 EXPECT_EQ(is_mask_, layer->is_mask_); | 96 EXPECT_EQ(is_mask_, layer->is_mask_); |
| 87 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); | 97 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); |
| 88 } | 98 } |
| 89 | 99 |
| 90 private: | 100 private: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 106 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 116 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 107 TestTaskGraphRunner task_graph_runner; | 117 TestTaskGraphRunner task_graph_runner; |
| 108 LayerTreeSettings settings; | 118 LayerTreeSettings settings; |
| 109 std::unique_ptr<FakeImageSerializationProcessor> | 119 std::unique_ptr<FakeImageSerializationProcessor> |
| 110 fake_image_serialization_processor = | 120 fake_image_serialization_processor = |
| 111 base::WrapUnique(new FakeImageSerializationProcessor); | 121 base::WrapUnique(new FakeImageSerializationProcessor); |
| 112 std::unique_ptr<FakeLayerTreeHost> host = | 122 std::unique_ptr<FakeLayerTreeHost> host = |
| 113 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, | 123 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, |
| 114 CompositorMode::SINGLE_THREADED, | 124 CompositorMode::SINGLE_THREADED, |
| 115 fake_image_serialization_processor.get()); | 125 fake_image_serialization_processor.get()); |
| 126 host->InitializePictureCacheForTesting(); |
| 116 | 127 |
| 117 gfx::Size recording_source_viewport(256, 256); | 128 gfx::Size recording_source_viewport(256, 256); |
| 118 scoped_refptr<TestSerializationPictureLayer> layer = | 129 scoped_refptr<TestSerializationPictureLayer> layer = |
| 119 TestSerializationPictureLayer::Create(recording_source_viewport); | 130 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 120 host->SetRootLayer(layer); | 131 host->SetRootLayer(layer); |
| 121 | 132 |
| 122 Region region(gfx::Rect(14, 15, 16, 17)); | 133 Region region(gfx::Rect(14, 15, 16, 17)); |
| 123 layer->set_invalidation(region); | 134 layer->set_invalidation(region); |
| 124 layer->set_is_mask(true); | 135 layer->set_is_mask(true); |
| 125 layer->set_nearest_neighbor(true); | 136 layer->set_nearest_neighbor(true); |
| 126 | 137 |
| 127 layer->SetBounds(recording_source_viewport); | 138 layer->SetBounds(recording_source_viewport); |
| 128 layer->set_update_source_frame_number(0); | 139 layer->set_update_source_frame_number(0); |
| 129 layer->recording_source()->SetDisplayListUsesCachedPicture(false); | 140 layer->recording_source()->SetDisplayListUsesCachedPicture(false); |
| 130 layer->recording_source()->add_draw_rect( | 141 layer->recording_source()->add_draw_rect( |
| 131 gfx::Rect(recording_source_viewport)); | 142 gfx::Rect(recording_source_viewport)); |
| 132 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); | 143 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); |
| 133 layer->recording_source()->Rerecord(); | 144 layer->recording_source()->Rerecord(); |
| 134 layer->ValidateSerialization(); | 145 layer->ValidateSerialization(fake_image_serialization_processor.get()); |
| 135 } | 146 } |
| 136 | 147 |
| 137 TEST(PictureLayerTest, TestSerializationDeserialization) { | 148 TEST(PictureLayerTest, TestSerializationDeserialization) { |
| 138 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 149 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 139 TestTaskGraphRunner task_graph_runner; | 150 TestTaskGraphRunner task_graph_runner; |
| 140 std::unique_ptr<FakeImageSerializationProcessor> | 151 std::unique_ptr<FakeImageSerializationProcessor> |
| 141 fake_image_serialization_processor = | 152 fake_image_serialization_processor = |
| 142 base::WrapUnique(new FakeImageSerializationProcessor); | 153 base::WrapUnique(new FakeImageSerializationProcessor); |
| 143 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( | 154 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 144 &host_client, &task_graph_runner, LayerTreeSettings(), | 155 &host_client, &task_graph_runner, LayerTreeSettings(), |
| 145 CompositorMode::SINGLE_THREADED, | 156 CompositorMode::SINGLE_THREADED, |
| 146 fake_image_serialization_processor.get()); | 157 fake_image_serialization_processor.get()); |
| 158 host->InitializePictureCacheForTesting(); |
| 159 |
| 147 gfx::Size recording_source_viewport(256, 256); | 160 gfx::Size recording_source_viewport(256, 256); |
| 148 scoped_refptr<TestSerializationPictureLayer> layer = | 161 scoped_refptr<TestSerializationPictureLayer> layer = |
| 149 TestSerializationPictureLayer::Create(recording_source_viewport); | 162 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 150 host->SetRootLayer(layer); | 163 host->SetRootLayer(layer); |
| 151 | 164 |
| 152 layer->SetBounds(recording_source_viewport); | 165 layer->SetBounds(recording_source_viewport); |
| 153 layer->set_update_source_frame_number(0); | 166 layer->set_update_source_frame_number(0); |
| 154 layer->recording_source()->SetDisplayListUsesCachedPicture(false); | 167 layer->recording_source()->SetDisplayListUsesCachedPicture(false); |
| 155 layer->recording_source()->add_draw_rect( | 168 layer->recording_source()->add_draw_rect( |
| 156 gfx::Rect(recording_source_viewport)); | 169 gfx::Rect(recording_source_viewport)); |
| 157 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); | 170 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); |
| 158 layer->recording_source()->Rerecord(); | 171 layer->recording_source()->Rerecord(); |
| 159 layer->ValidateSerialization(); | 172 layer->ValidateSerialization(fake_image_serialization_processor.get()); |
| 160 } | 173 } |
| 161 | 174 |
| 162 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { | 175 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { |
| 176 std::unique_ptr<FakeImageSerializationProcessor> |
| 177 fake_image_serialization_processor = |
| 178 base::WrapUnique(new FakeImageSerializationProcessor); |
| 163 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 179 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 164 TestTaskGraphRunner task_graph_runner; | 180 TestTaskGraphRunner task_graph_runner; |
| 165 std::unique_ptr<FakeLayerTreeHost> host = | 181 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 166 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 182 &host_client, &task_graph_runner, LayerTreeSettings(), |
| 183 CompositorMode::SINGLE_THREADED, |
| 184 fake_image_serialization_processor.get()); |
| 167 | 185 |
| 168 gfx::Size recording_source_viewport(256, 256); | 186 gfx::Size recording_source_viewport(256, 256); |
| 169 scoped_refptr<TestSerializationPictureLayer> layer = | 187 scoped_refptr<TestSerializationPictureLayer> layer = |
| 170 TestSerializationPictureLayer::Create(recording_source_viewport); | 188 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 171 host->SetRootLayer(layer); | 189 host->SetRootLayer(layer); |
| 172 layer->ValidateSerialization(); | 190 layer->ValidateSerialization(fake_image_serialization_processor.get()); |
| 173 } | 191 } |
| 174 | 192 |
| 175 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { | 193 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { |
| 176 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); | 194 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
| 177 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); | 195 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); |
| 178 layer->SetBounds(gfx::Size(10, 10)); | 196 layer->SetBounds(gfx::Size(10, 10)); |
| 179 | 197 |
| 180 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 198 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 181 TestTaskGraphRunner task_graph_runner; | 199 TestTaskGraphRunner task_graph_runner; |
| 182 std::unique_ptr<FakeLayerTreeHost> host = | 200 std::unique_ptr<FakeLayerTreeHost> host = |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 // Do a main frame, record the picture layers. The frame number has changed | 497 // Do a main frame, record the picture layers. The frame number has changed |
| 480 // non-monotonically. | 498 // non-monotonically. |
| 481 layer->SetNeedsDisplay(); | 499 layer->SetNeedsDisplay(); |
| 482 host2->Composite(base::TimeTicks::Now()); | 500 host2->Composite(base::TimeTicks::Now()); |
| 483 EXPECT_EQ(3, layer->update_count()); | 501 EXPECT_EQ(3, layer->update_count()); |
| 484 EXPECT_EQ(1, host2->source_frame_number()); | 502 EXPECT_EQ(1, host2->source_frame_number()); |
| 485 } | 503 } |
| 486 | 504 |
| 487 } // namespace | 505 } // namespace |
| 488 } // namespace cc | 506 } // namespace cc |
| OLD | NEW |