| 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/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 10 #include "cc/layers/append_quads_data.h" | 11 #include "cc/layers/append_quads_data.h" |
| 11 #include "cc/layers/content_layer_client.h" | 12 #include "cc/layers/content_layer_client.h" |
| 12 #include "cc/layers/empty_content_layer_client.h" | 13 #include "cc/layers/empty_content_layer_client.h" |
| 13 #include "cc/layers/picture_layer_impl.h" | 14 #include "cc/layers/picture_layer_impl.h" |
| 14 #include "cc/playback/display_item_list_settings.h" | 15 #include "cc/playback/display_item_list_settings.h" |
| 15 #include "cc/proto/layer.pb.h" | 16 #include "cc/proto/layer.pb.h" |
| 16 #include "cc/test/fake_image_serialization_processor.h" | 17 #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.h" |
| 18 #include "cc/test/fake_output_surface.h" | 19 #include "cc/test/fake_output_surface.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 nearest_neighbor_ = nearest_neighbor; | 58 nearest_neighbor_ = nearest_neighbor; |
| 58 } | 59 } |
| 59 | 60 |
| 60 void ValidateSerialization() { | 61 void ValidateSerialization() { |
| 61 proto::LayerProperties proto; | 62 proto::LayerProperties proto; |
| 62 LayerSpecificPropertiesToProto(&proto); | 63 LayerSpecificPropertiesToProto(&proto); |
| 63 | 64 |
| 64 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 65 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 65 TestTaskGraphRunner task_graph_runner; | 66 TestTaskGraphRunner task_graph_runner; |
| 66 LayerTreeSettings settings; | 67 LayerTreeSettings settings; |
| 67 scoped_ptr<FakeImageSerializationProcessor> | 68 std::unique_ptr<FakeImageSerializationProcessor> |
| 68 fake_image_serialization_processor = | 69 fake_image_serialization_processor = |
| 69 make_scoped_ptr(new FakeImageSerializationProcessor); | 70 base::WrapUnique(new FakeImageSerializationProcessor); |
| 70 scoped_ptr<FakeLayerTreeHost> host = | 71 std::unique_ptr<FakeLayerTreeHost> host = |
| 71 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, | 72 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, |
| 72 CompositorMode::SINGLE_THREADED, | 73 CompositorMode::SINGLE_THREADED, |
| 73 fake_image_serialization_processor.get()); | 74 fake_image_serialization_processor.get()); |
| 74 scoped_refptr<TestSerializationPictureLayer> layer = | 75 scoped_refptr<TestSerializationPictureLayer> layer = |
| 75 TestSerializationPictureLayer::Create(recording_source_viewport_); | 76 TestSerializationPictureLayer::Create(recording_source_viewport_); |
| 76 host->SetRootLayer(layer); | 77 host->SetRootLayer(layer); |
| 77 layer->FromLayerSpecificPropertiesProto(proto); | 78 layer->FromLayerSpecificPropertiesProto(proto); |
| 78 | 79 |
| 79 // Validate that the PictureLayer specific fields are properly set. | 80 // Validate that the PictureLayer specific fields are properly set. |
| 80 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); | 81 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); |
| 81 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); | 82 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); |
| 82 EXPECT_EQ(is_mask_, layer->is_mask_); | 83 EXPECT_EQ(is_mask_, layer->is_mask_); |
| 83 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); | 84 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); |
| 84 } | 85 } |
| 85 | 86 |
| 86 private: | 87 private: |
| 87 TestSerializationPictureLayer(ContentLayerClient* client, | 88 TestSerializationPictureLayer(ContentLayerClient* client, |
| 88 scoped_ptr<RecordingSource> source, | 89 std::unique_ptr<RecordingSource> source, |
| 89 const gfx::Size& recording_source_viewport) | 90 const gfx::Size& recording_source_viewport) |
| 90 : PictureLayer(client, std::move(source)), | 91 : PictureLayer(client, std::move(source)), |
| 91 recording_source_viewport_(recording_source_viewport) {} | 92 recording_source_viewport_(recording_source_viewport) {} |
| 92 ~TestSerializationPictureLayer() override {} | 93 ~TestSerializationPictureLayer() override {} |
| 93 | 94 |
| 94 gfx::Size recording_source_viewport_; | 95 gfx::Size recording_source_viewport_; |
| 95 | 96 |
| 96 DISALLOW_COPY_AND_ASSIGN(TestSerializationPictureLayer); | 97 DISALLOW_COPY_AND_ASSIGN(TestSerializationPictureLayer); |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 namespace { | 100 namespace { |
| 100 | 101 |
| 101 TEST(PictureLayerTest, TestSetAllPropsSerializationDeserialization) { | 102 TEST(PictureLayerTest, TestSetAllPropsSerializationDeserialization) { |
| 102 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 103 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 103 TestTaskGraphRunner task_graph_runner; | 104 TestTaskGraphRunner task_graph_runner; |
| 104 LayerTreeSettings settings; | 105 LayerTreeSettings settings; |
| 105 scoped_ptr<FakeImageSerializationProcessor> | 106 std::unique_ptr<FakeImageSerializationProcessor> |
| 106 fake_image_serialization_processor = | 107 fake_image_serialization_processor = |
| 107 make_scoped_ptr(new FakeImageSerializationProcessor); | 108 base::WrapUnique(new FakeImageSerializationProcessor); |
| 108 scoped_ptr<FakeLayerTreeHost> host = | 109 std::unique_ptr<FakeLayerTreeHost> host = |
| 109 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, | 110 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, |
| 110 CompositorMode::SINGLE_THREADED, | 111 CompositorMode::SINGLE_THREADED, |
| 111 fake_image_serialization_processor.get()); | 112 fake_image_serialization_processor.get()); |
| 112 | 113 |
| 113 gfx::Size recording_source_viewport(256, 256); | 114 gfx::Size recording_source_viewport(256, 256); |
| 114 scoped_refptr<TestSerializationPictureLayer> layer = | 115 scoped_refptr<TestSerializationPictureLayer> layer = |
| 115 TestSerializationPictureLayer::Create(recording_source_viewport); | 116 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 116 host->SetRootLayer(layer); | 117 host->SetRootLayer(layer); |
| 117 | 118 |
| 118 Region region(gfx::Rect(14, 15, 16, 17)); | 119 Region region(gfx::Rect(14, 15, 16, 17)); |
| 119 layer->set_invalidation(region); | 120 layer->set_invalidation(region); |
| 120 layer->set_is_mask(true); | 121 layer->set_is_mask(true); |
| 121 layer->set_nearest_neighbor(true); | 122 layer->set_nearest_neighbor(true); |
| 122 | 123 |
| 123 layer->SetBounds(recording_source_viewport); | 124 layer->SetBounds(recording_source_viewport); |
| 124 layer->set_update_source_frame_number(0); | 125 layer->set_update_source_frame_number(0); |
| 125 layer->recording_source()->SetDisplayListUsesCachedPicture(false); | 126 layer->recording_source()->SetDisplayListUsesCachedPicture(false); |
| 126 layer->recording_source()->add_draw_rect( | 127 layer->recording_source()->add_draw_rect( |
| 127 gfx::Rect(recording_source_viewport)); | 128 gfx::Rect(recording_source_viewport)); |
| 128 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); | 129 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); |
| 129 layer->recording_source()->Rerecord(); | 130 layer->recording_source()->Rerecord(); |
| 130 layer->ValidateSerialization(); | 131 layer->ValidateSerialization(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 TEST(PictureLayerTest, TestSerializationDeserialization) { | 134 TEST(PictureLayerTest, TestSerializationDeserialization) { |
| 134 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 135 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 135 TestTaskGraphRunner task_graph_runner; | 136 TestTaskGraphRunner task_graph_runner; |
| 136 scoped_ptr<FakeImageSerializationProcessor> | 137 std::unique_ptr<FakeImageSerializationProcessor> |
| 137 fake_image_serialization_processor = | 138 fake_image_serialization_processor = |
| 138 make_scoped_ptr(new FakeImageSerializationProcessor); | 139 base::WrapUnique(new FakeImageSerializationProcessor); |
| 139 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( | 140 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 140 &host_client, &task_graph_runner, LayerTreeSettings(), | 141 &host_client, &task_graph_runner, LayerTreeSettings(), |
| 141 CompositorMode::SINGLE_THREADED, | 142 CompositorMode::SINGLE_THREADED, |
| 142 fake_image_serialization_processor.get()); | 143 fake_image_serialization_processor.get()); |
| 143 gfx::Size recording_source_viewport(256, 256); | 144 gfx::Size recording_source_viewport(256, 256); |
| 144 scoped_refptr<TestSerializationPictureLayer> layer = | 145 scoped_refptr<TestSerializationPictureLayer> layer = |
| 145 TestSerializationPictureLayer::Create(recording_source_viewport); | 146 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 146 host->SetRootLayer(layer); | 147 host->SetRootLayer(layer); |
| 147 | 148 |
| 148 layer->SetBounds(recording_source_viewport); | 149 layer->SetBounds(recording_source_viewport); |
| 149 layer->set_update_source_frame_number(0); | 150 layer->set_update_source_frame_number(0); |
| 150 layer->recording_source()->SetDisplayListUsesCachedPicture(false); | 151 layer->recording_source()->SetDisplayListUsesCachedPicture(false); |
| 151 layer->recording_source()->add_draw_rect( | 152 layer->recording_source()->add_draw_rect( |
| 152 gfx::Rect(recording_source_viewport)); | 153 gfx::Rect(recording_source_viewport)); |
| 153 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); | 154 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); |
| 154 layer->recording_source()->Rerecord(); | 155 layer->recording_source()->Rerecord(); |
| 155 layer->ValidateSerialization(); | 156 layer->ValidateSerialization(); |
| 156 } | 157 } |
| 157 | 158 |
| 158 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { | 159 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { |
| 159 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 160 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 160 TestTaskGraphRunner task_graph_runner; | 161 TestTaskGraphRunner task_graph_runner; |
| 161 scoped_ptr<FakeLayerTreeHost> host = | 162 std::unique_ptr<FakeLayerTreeHost> host = |
| 162 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 163 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
| 163 | 164 |
| 164 gfx::Size recording_source_viewport(256, 256); | 165 gfx::Size recording_source_viewport(256, 256); |
| 165 scoped_refptr<TestSerializationPictureLayer> layer = | 166 scoped_refptr<TestSerializationPictureLayer> layer = |
| 166 TestSerializationPictureLayer::Create(recording_source_viewport); | 167 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 167 host->SetRootLayer(layer); | 168 host->SetRootLayer(layer); |
| 168 layer->ValidateSerialization(); | 169 layer->ValidateSerialization(); |
| 169 } | 170 } |
| 170 | 171 |
| 171 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { | 172 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { |
| 172 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); | 173 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
| 173 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); | 174 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); |
| 174 layer->SetBounds(gfx::Size(10, 10)); | 175 layer->SetBounds(gfx::Size(10, 10)); |
| 175 | 176 |
| 176 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 177 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 177 TestTaskGraphRunner task_graph_runner; | 178 TestTaskGraphRunner task_graph_runner; |
| 178 scoped_ptr<FakeLayerTreeHost> host = | 179 std::unique_ptr<FakeLayerTreeHost> host = |
| 179 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 180 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
| 180 host->SetRootLayer(layer); | 181 host->SetRootLayer(layer); |
| 181 layer->SetIsDrawable(true); | 182 layer->SetIsDrawable(true); |
| 182 layer->SavePaintProperties(); | 183 layer->SavePaintProperties(); |
| 183 layer->Update(); | 184 layer->Update(); |
| 184 | 185 |
| 185 EXPECT_EQ(0, host->source_frame_number()); | 186 EXPECT_EQ(0, host->source_frame_number()); |
| 186 host->CommitComplete(); | 187 host->CommitComplete(); |
| 187 EXPECT_EQ(1, host->source_frame_number()); | 188 EXPECT_EQ(1, host->source_frame_number()); |
| 188 | 189 |
| 189 layer->SetBounds(gfx::Size(0, 0)); | 190 layer->SetBounds(gfx::Size(0, 0)); |
| 190 layer->SavePaintProperties(); | 191 layer->SavePaintProperties(); |
| 191 // Intentionally skipping Update since it would normally be skipped on | 192 // Intentionally skipping Update since it would normally be skipped on |
| 192 // a layer with empty bounds. | 193 // a layer with empty bounds. |
| 193 | 194 |
| 194 FakeImplTaskRunnerProvider impl_task_runner_provider; | 195 FakeImplTaskRunnerProvider impl_task_runner_provider; |
| 195 | 196 |
| 196 TestSharedBitmapManager shared_bitmap_manager; | 197 TestSharedBitmapManager shared_bitmap_manager; |
| 197 scoped_ptr<FakeOutputSurface> output_surface = | 198 std::unique_ptr<FakeOutputSurface> output_surface = |
| 198 FakeOutputSurface::CreateSoftware( | 199 FakeOutputSurface::CreateSoftware( |
| 199 make_scoped_ptr(new SoftwareOutputDevice)); | 200 base::WrapUnique(new SoftwareOutputDevice)); |
| 200 FakeLayerTreeHostImpl host_impl(LayerTreeSettings(), | 201 FakeLayerTreeHostImpl host_impl(LayerTreeSettings(), |
| 201 &impl_task_runner_provider, | 202 &impl_task_runner_provider, |
| 202 &shared_bitmap_manager, &task_graph_runner); | 203 &shared_bitmap_manager, &task_graph_runner); |
| 203 host_impl.InitializeRenderer(output_surface.get()); | 204 host_impl.InitializeRenderer(output_surface.get()); |
| 204 host_impl.CreatePendingTree(); | 205 host_impl.CreatePendingTree(); |
| 205 scoped_ptr<FakePictureLayerImpl> layer_impl = | 206 std::unique_ptr<FakePictureLayerImpl> layer_impl = |
| 206 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1); | 207 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1); |
| 207 | 208 |
| 208 layer->PushPropertiesTo(layer_impl.get()); | 209 layer->PushPropertiesTo(layer_impl.get()); |
| 209 EXPECT_FALSE(layer_impl->CanHaveTilings()); | 210 EXPECT_FALSE(layer_impl->CanHaveTilings()); |
| 210 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0)); | 211 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0)); |
| 211 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); | 212 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); |
| 212 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); | 213 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); |
| 213 } | 214 } |
| 214 | 215 |
| 215 TEST(PictureLayerTest, InvalidateRasterAfterUpdate) { | 216 TEST(PictureLayerTest, InvalidateRasterAfterUpdate) { |
| 216 gfx::Size layer_size(50, 50); | 217 gfx::Size layer_size(50, 50); |
| 217 FakeContentLayerClient client; | 218 FakeContentLayerClient client; |
| 218 client.set_bounds(layer_size); | 219 client.set_bounds(layer_size); |
| 219 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | 220 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); |
| 220 layer->SetBounds(gfx::Size(50, 50)); | 221 layer->SetBounds(gfx::Size(50, 50)); |
| 221 | 222 |
| 222 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 223 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 223 TestTaskGraphRunner task_graph_runner; | 224 TestTaskGraphRunner task_graph_runner; |
| 224 scoped_ptr<FakeLayerTreeHost> host = | 225 std::unique_ptr<FakeLayerTreeHost> host = |
| 225 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 226 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
| 226 host->SetRootLayer(layer); | 227 host->SetRootLayer(layer); |
| 227 layer->SetIsDrawable(true); | 228 layer->SetIsDrawable(true); |
| 228 layer->SavePaintProperties(); | 229 layer->SavePaintProperties(); |
| 229 | 230 |
| 230 gfx::Rect invalidation_bounds(layer_size); | 231 gfx::Rect invalidation_bounds(layer_size); |
| 231 | 232 |
| 232 // The important two lines are the following: | 233 // The important two lines are the following: |
| 233 layer->SetNeedsDisplayRect(invalidation_bounds); | 234 layer->SetNeedsDisplayRect(invalidation_bounds); |
| 234 layer->Update(); | 235 layer->Update(); |
| 235 | 236 |
| 236 host->CommitComplete(); | 237 host->CommitComplete(); |
| 237 FakeImplTaskRunnerProvider impl_task_runner_provider; | 238 FakeImplTaskRunnerProvider impl_task_runner_provider; |
| 238 TestSharedBitmapManager shared_bitmap_manager; | 239 TestSharedBitmapManager shared_bitmap_manager; |
| 239 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 240 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 240 LayerTreeSettings layer_tree_settings = LayerTreeSettings(); | 241 LayerTreeSettings layer_tree_settings = LayerTreeSettings(); |
| 241 layer_tree_settings.image_decode_tasks_enabled = true; | 242 layer_tree_settings.image_decode_tasks_enabled = true; |
| 242 FakeLayerTreeHostImpl host_impl(layer_tree_settings, | 243 FakeLayerTreeHostImpl host_impl(layer_tree_settings, |
| 243 &impl_task_runner_provider, | 244 &impl_task_runner_provider, |
| 244 &shared_bitmap_manager, &task_graph_runner); | 245 &shared_bitmap_manager, &task_graph_runner); |
| 245 host_impl.SetVisible(true); | 246 host_impl.SetVisible(true); |
| 246 host_impl.InitializeRenderer(output_surface.get()); | 247 host_impl.InitializeRenderer(output_surface.get()); |
| 247 host_impl.CreatePendingTree(); | 248 host_impl.CreatePendingTree(); |
| 248 host_impl.pending_tree()->SetRootLayer( | 249 host_impl.pending_tree()->SetRootLayer( |
| 249 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); | 250 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); |
| 250 FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( | 251 FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( |
| 251 host_impl.pending_tree()->root_layer()); | 252 host_impl.pending_tree()->root_layer()); |
| 252 layer->PushPropertiesTo(layer_impl); | 253 layer->PushPropertiesTo(layer_impl); |
| 253 | 254 |
| 254 EXPECT_EQ(invalidation_bounds, | 255 EXPECT_EQ(invalidation_bounds, |
| 255 layer_impl->GetPendingInvalidation()->bounds()); | 256 layer_impl->GetPendingInvalidation()->bounds()); |
| 256 } | 257 } |
| 257 | 258 |
| 258 TEST(PictureLayerTest, InvalidateRasterWithoutUpdate) { | 259 TEST(PictureLayerTest, InvalidateRasterWithoutUpdate) { |
| 259 gfx::Size layer_size(50, 50); | 260 gfx::Size layer_size(50, 50); |
| 260 FakeContentLayerClient client; | 261 FakeContentLayerClient client; |
| 261 client.set_bounds(layer_size); | 262 client.set_bounds(layer_size); |
| 262 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | 263 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); |
| 263 layer->SetBounds(gfx::Size(50, 50)); | 264 layer->SetBounds(gfx::Size(50, 50)); |
| 264 | 265 |
| 265 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 266 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 266 TestTaskGraphRunner task_graph_runner; | 267 TestTaskGraphRunner task_graph_runner; |
| 267 scoped_ptr<FakeLayerTreeHost> host = | 268 std::unique_ptr<FakeLayerTreeHost> host = |
| 268 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 269 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
| 269 host->SetRootLayer(layer); | 270 host->SetRootLayer(layer); |
| 270 layer->SetIsDrawable(true); | 271 layer->SetIsDrawable(true); |
| 271 layer->SavePaintProperties(); | 272 layer->SavePaintProperties(); |
| 272 | 273 |
| 273 gfx::Rect invalidation_bounds(layer_size); | 274 gfx::Rect invalidation_bounds(layer_size); |
| 274 | 275 |
| 275 // The important line is the following (note that we do not call Update): | 276 // The important line is the following (note that we do not call Update): |
| 276 layer->SetNeedsDisplayRect(invalidation_bounds); | 277 layer->SetNeedsDisplayRect(invalidation_bounds); |
| 277 | 278 |
| 278 host->CommitComplete(); | 279 host->CommitComplete(); |
| 279 FakeImplTaskRunnerProvider impl_task_runner_provider; | 280 FakeImplTaskRunnerProvider impl_task_runner_provider; |
| 280 TestSharedBitmapManager shared_bitmap_manager; | 281 TestSharedBitmapManager shared_bitmap_manager; |
| 281 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 282 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 282 LayerTreeSettings layer_tree_settings = LayerTreeSettings(); | 283 LayerTreeSettings layer_tree_settings = LayerTreeSettings(); |
| 283 layer_tree_settings.image_decode_tasks_enabled = true; | 284 layer_tree_settings.image_decode_tasks_enabled = true; |
| 284 FakeLayerTreeHostImpl host_impl(layer_tree_settings, | 285 FakeLayerTreeHostImpl host_impl(layer_tree_settings, |
| 285 &impl_task_runner_provider, | 286 &impl_task_runner_provider, |
| 286 &shared_bitmap_manager, &task_graph_runner); | 287 &shared_bitmap_manager, &task_graph_runner); |
| 287 host_impl.SetVisible(true); | 288 host_impl.SetVisible(true); |
| 288 host_impl.InitializeRenderer(output_surface.get()); | 289 host_impl.InitializeRenderer(output_surface.get()); |
| 289 host_impl.CreatePendingTree(); | 290 host_impl.CreatePendingTree(); |
| 290 host_impl.pending_tree()->SetRootLayer( | 291 host_impl.pending_tree()->SetRootLayer( |
| 291 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); | 292 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); |
| 292 FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( | 293 FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( |
| 293 host_impl.pending_tree()->root_layer()); | 294 host_impl.pending_tree()->root_layer()); |
| 294 layer->PushPropertiesTo(layer_impl); | 295 layer->PushPropertiesTo(layer_impl); |
| 295 | 296 |
| 296 EXPECT_EQ(gfx::Rect(), layer_impl->GetPendingInvalidation()->bounds()); | 297 EXPECT_EQ(gfx::Rect(), layer_impl->GetPendingInvalidation()->bounds()); |
| 297 } | 298 } |
| 298 | 299 |
| 299 TEST(PictureLayerTest, ClearVisibleRectWhenNoTiling) { | 300 TEST(PictureLayerTest, ClearVisibleRectWhenNoTiling) { |
| 300 gfx::Size layer_size(50, 50); | 301 gfx::Size layer_size(50, 50); |
| 301 FakeContentLayerClient client; | 302 FakeContentLayerClient client; |
| 302 client.set_bounds(layer_size); | 303 client.set_bounds(layer_size); |
| 303 skia::RefPtr<SkImage> image = CreateDiscardableImage(layer_size); | 304 skia::RefPtr<SkImage> image = CreateDiscardableImage(layer_size); |
| 304 client.add_draw_image(image.get(), gfx::Point(), SkPaint()); | 305 client.add_draw_image(image.get(), gfx::Point(), SkPaint()); |
| 305 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | 306 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); |
| 306 layer->SetBounds(gfx::Size(10, 10)); | 307 layer->SetBounds(gfx::Size(10, 10)); |
| 307 | 308 |
| 308 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 309 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 309 TestTaskGraphRunner task_graph_runner; | 310 TestTaskGraphRunner task_graph_runner; |
| 310 scoped_ptr<FakeLayerTreeHost> host = | 311 std::unique_ptr<FakeLayerTreeHost> host = |
| 311 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 312 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
| 312 host->SetRootLayer(layer); | 313 host->SetRootLayer(layer); |
| 313 layer->SetIsDrawable(true); | 314 layer->SetIsDrawable(true); |
| 314 layer->SavePaintProperties(); | 315 layer->SavePaintProperties(); |
| 315 layer->Update(); | 316 layer->Update(); |
| 316 | 317 |
| 317 EXPECT_EQ(0, host->source_frame_number()); | 318 EXPECT_EQ(0, host->source_frame_number()); |
| 318 host->CommitComplete(); | 319 host->CommitComplete(); |
| 319 EXPECT_EQ(1, host->source_frame_number()); | 320 EXPECT_EQ(1, host->source_frame_number()); |
| 320 | 321 |
| 321 layer->SavePaintProperties(); | 322 layer->SavePaintProperties(); |
| 322 layer->Update(); | 323 layer->Update(); |
| 323 | 324 |
| 324 FakeImplTaskRunnerProvider impl_task_runner_provider; | 325 FakeImplTaskRunnerProvider impl_task_runner_provider; |
| 325 | 326 |
| 326 TestSharedBitmapManager shared_bitmap_manager; | 327 TestSharedBitmapManager shared_bitmap_manager; |
| 327 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); | 328 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d()); |
| 328 LayerTreeSettings layer_tree_settings = LayerTreeSettings(); | 329 LayerTreeSettings layer_tree_settings = LayerTreeSettings(); |
| 329 layer_tree_settings.image_decode_tasks_enabled = true; | 330 layer_tree_settings.image_decode_tasks_enabled = true; |
| 330 FakeLayerTreeHostImpl host_impl(layer_tree_settings, | 331 FakeLayerTreeHostImpl host_impl(layer_tree_settings, |
| 331 &impl_task_runner_provider, | 332 &impl_task_runner_provider, |
| 332 &shared_bitmap_manager, &task_graph_runner); | 333 &shared_bitmap_manager, &task_graph_runner); |
| 333 host_impl.SetVisible(true); | 334 host_impl.SetVisible(true); |
| 334 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); | 335 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); |
| 335 | 336 |
| 336 host_impl.CreatePendingTree(); | 337 host_impl.CreatePendingTree(); |
| 337 host_impl.pending_tree()->SetRootLayer( | 338 host_impl.pending_tree()->SetRootLayer( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 360 host_impl.CreatePendingTree(); | 361 host_impl.CreatePendingTree(); |
| 361 layer_impl = static_cast<FakePictureLayerImpl*>( | 362 layer_impl = static_cast<FakePictureLayerImpl*>( |
| 362 host_impl.pending_tree()->root_layer()); | 363 host_impl.pending_tree()->root_layer()); |
| 363 | 364 |
| 364 // We should now have invalid contents and should therefore clear the | 365 // We should now have invalid contents and should therefore clear the |
| 365 // recording source. | 366 // recording source. |
| 366 layer->PushPropertiesTo(layer_impl); | 367 layer->PushPropertiesTo(layer_impl); |
| 367 | 368 |
| 368 host_impl.ActivateSyncTree(); | 369 host_impl.ActivateSyncTree(); |
| 369 | 370 |
| 370 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 371 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 371 AppendQuadsData data; | 372 AppendQuadsData data; |
| 372 host_impl.active_tree()->root_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); | 373 host_impl.active_tree()->root_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr); |
| 373 host_impl.active_tree()->root_layer()->AppendQuads(render_pass.get(), &data); | 374 host_impl.active_tree()->root_layer()->AppendQuads(render_pass.get(), &data); |
| 374 host_impl.active_tree()->root_layer()->DidDraw(nullptr); | 375 host_impl.active_tree()->root_layer()->DidDraw(nullptr); |
| 375 } | 376 } |
| 376 | 377 |
| 377 TEST(PictureLayerTest, SuitableForGpuRasterization) { | 378 TEST(PictureLayerTest, SuitableForGpuRasterization) { |
| 378 scoped_ptr<FakeRecordingSource> recording_source_owned( | 379 std::unique_ptr<FakeRecordingSource> recording_source_owned( |
| 379 new FakeRecordingSource); | 380 new FakeRecordingSource); |
| 380 FakeRecordingSource* recording_source = recording_source_owned.get(); | 381 FakeRecordingSource* recording_source = recording_source_owned.get(); |
| 381 | 382 |
| 382 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); | 383 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
| 383 scoped_refptr<FakePictureLayer> layer = | 384 scoped_refptr<FakePictureLayer> layer = |
| 384 FakePictureLayer::CreateWithRecordingSource( | 385 FakePictureLayer::CreateWithRecordingSource( |
| 385 client, std::move(recording_source_owned)); | 386 client, std::move(recording_source_owned)); |
| 386 | 387 |
| 387 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 388 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 388 TestTaskGraphRunner task_graph_runner; | 389 TestTaskGraphRunner task_graph_runner; |
| 389 scoped_ptr<FakeLayerTreeHost> host = | 390 std::unique_ptr<FakeLayerTreeHost> host = |
| 390 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 391 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
| 391 host->SetRootLayer(layer); | 392 host->SetRootLayer(layer); |
| 392 | 393 |
| 393 // Update layers to initialize the recording source. | 394 // Update layers to initialize the recording source. |
| 394 gfx::Size layer_bounds(200, 200); | 395 gfx::Size layer_bounds(200, 200); |
| 395 gfx::Rect layer_rect(layer_bounds); | 396 gfx::Rect layer_rect(layer_bounds); |
| 396 Region invalidation(layer_rect); | 397 Region invalidation(layer_rect); |
| 397 recording_source->UpdateAndExpandInvalidation( | 398 recording_source->UpdateAndExpandInvalidation( |
| 398 client, &invalidation, layer_bounds, 1, RecordingSource::RECORD_NORMALLY); | 399 client, &invalidation, layer_bounds, 1, RecordingSource::RECORD_NORMALLY); |
| 399 | 400 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 423 | 424 |
| 424 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); | 425 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
| 425 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(client); | 426 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(client); |
| 426 | 427 |
| 427 LayerTreeHost::InitParams params; | 428 LayerTreeHost::InitParams params; |
| 428 params.client = &host_client1; | 429 params.client = &host_client1; |
| 429 params.shared_bitmap_manager = &shared_bitmap_manager; | 430 params.shared_bitmap_manager = &shared_bitmap_manager; |
| 430 params.settings = &settings; | 431 params.settings = &settings; |
| 431 params.task_graph_runner = &task_graph_runner; | 432 params.task_graph_runner = &task_graph_runner; |
| 432 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 433 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 433 scoped_ptr<LayerTreeHost> host1 = | 434 std::unique_ptr<LayerTreeHost> host1 = |
| 434 LayerTreeHost::CreateSingleThreaded(&host_client1, ¶ms); | 435 LayerTreeHost::CreateSingleThreaded(&host_client1, ¶ms); |
| 435 host1->SetVisible(true); | 436 host1->SetVisible(true); |
| 436 host_client1.SetLayerTreeHost(host1.get()); | 437 host_client1.SetLayerTreeHost(host1.get()); |
| 437 | 438 |
| 438 params.client = &host_client2; | 439 params.client = &host_client2; |
| 439 scoped_ptr<LayerTreeHost> host2 = | 440 std::unique_ptr<LayerTreeHost> host2 = |
| 440 LayerTreeHost::CreateSingleThreaded(&host_client2, ¶ms); | 441 LayerTreeHost::CreateSingleThreaded(&host_client2, ¶ms); |
| 441 host2->SetVisible(true); | 442 host2->SetVisible(true); |
| 442 host_client2.SetLayerTreeHost(host2.get()); | 443 host_client2.SetLayerTreeHost(host2.get()); |
| 443 | 444 |
| 444 // The PictureLayer is put in one LayerTreeHost. | 445 // The PictureLayer is put in one LayerTreeHost. |
| 445 host1->SetRootLayer(layer); | 446 host1->SetRootLayer(layer); |
| 446 // Do a main frame, record the picture layers. | 447 // Do a main frame, record the picture layers. |
| 447 EXPECT_EQ(0, layer->update_count()); | 448 EXPECT_EQ(0, layer->update_count()); |
| 448 layer->SetNeedsDisplay(); | 449 layer->SetNeedsDisplay(); |
| 449 host1->Composite(base::TimeTicks::Now()); | 450 host1->Composite(base::TimeTicks::Now()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 463 // Do a main frame, record the picture layers. The frame number has changed | 464 // Do a main frame, record the picture layers. The frame number has changed |
| 464 // non-monotonically. | 465 // non-monotonically. |
| 465 layer->SetNeedsDisplay(); | 466 layer->SetNeedsDisplay(); |
| 466 host2->Composite(base::TimeTicks::Now()); | 467 host2->Composite(base::TimeTicks::Now()); |
| 467 EXPECT_EQ(3, layer->update_count()); | 468 EXPECT_EQ(3, layer->update_count()); |
| 468 EXPECT_EQ(1, host2->source_frame_number()); | 469 EXPECT_EQ(1, host2->source_frame_number()); |
| 469 } | 470 } |
| 470 | 471 |
| 471 } // namespace | 472 } // namespace |
| 472 } // namespace cc | 473 } // namespace cc |
| OLD | NEW |