Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: cc/layers/picture_layer_unittest.cc

Issue 2738613006: Remove non-leaky LazyInstances in cc. (Closed)
Patch Set: cc-remove-non-leaky-singletons: globals Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/empty_content_layer_client.cc ('k') | cc/test/fake_tile_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "cc/animation/animation_host.h" 11 #include "cc/animation/animation_host.h"
12 #include "cc/layers/append_quads_data.h" 12 #include "cc/layers/append_quads_data.h"
13 #include "cc/layers/content_layer_client.h" 13 #include "cc/layers/content_layer_client.h"
14 #include "cc/layers/empty_content_layer_client.h"
15 #include "cc/layers/picture_layer_impl.h" 14 #include "cc/layers/picture_layer_impl.h"
16 #include "cc/paint/paint_flags.h" 15 #include "cc/paint/paint_flags.h"
17 #include "cc/test/fake_compositor_frame_sink.h" 16 #include "cc/test/fake_compositor_frame_sink.h"
17 #include "cc/test/fake_content_layer_client.h"
18 #include "cc/test/fake_layer_tree_host.h" 18 #include "cc/test/fake_layer_tree_host.h"
19 #include "cc/test/fake_picture_layer.h" 19 #include "cc/test/fake_picture_layer.h"
20 #include "cc/test/fake_picture_layer_impl.h" 20 #include "cc/test/fake_picture_layer_impl.h"
21 #include "cc/test/fake_proxy.h" 21 #include "cc/test/fake_proxy.h"
22 #include "cc/test/fake_recording_source.h" 22 #include "cc/test/fake_recording_source.h"
23 #include "cc/test/layer_tree_settings_for_testing.h" 23 #include "cc/test/layer_tree_settings_for_testing.h"
24 #include "cc/test/skia_common.h" 24 #include "cc/test/skia_common.h"
25 #include "cc/test/stub_layer_tree_host_single_thread_client.h" 25 #include "cc/test/stub_layer_tree_host_single_thread_client.h"
26 #include "cc/test/test_task_graph_runner.h" 26 #include "cc/test/test_task_graph_runner.h"
27 #include "cc/trees/single_thread_proxy.h" 27 #include "cc/trees/single_thread_proxy.h"
28 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "third_party/skia/include/core/SkRefCnt.h" 30 #include "third_party/skia/include/core/SkRefCnt.h"
31 31
32 namespace cc { 32 namespace cc {
33 33
34 namespace { 34 namespace {
35 35
36 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { 36 TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
37 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); 37 FakeContentLayerClient client;
38 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); 38 client.set_bounds(gfx::Size());
39 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
39 layer->SetBounds(gfx::Size(10, 10)); 40 layer->SetBounds(gfx::Size(10, 10));
40 41
41 FakeLayerTreeHostClient host_client; 42 FakeLayerTreeHostClient host_client;
42 TestTaskGraphRunner task_graph_runner; 43 TestTaskGraphRunner task_graph_runner;
43 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); 44 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
44 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( 45 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
45 &host_client, &task_graph_runner, animation_host.get()); 46 &host_client, &task_graph_runner, animation_host.get());
46 host->SetRootLayer(layer); 47 host->SetRootLayer(layer);
47 layer->SetIsDrawable(true); 48 layer->SetIsDrawable(true);
48 layer->SavePaintProperties(); 49 layer->SavePaintProperties();
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 host_impl.active_tree()->root_layer_for_testing()->AppendQuads( 241 host_impl.active_tree()->root_layer_for_testing()->AppendQuads(
241 render_pass.get(), &data); 242 render_pass.get(), &data);
242 host_impl.active_tree()->root_layer_for_testing()->DidDraw(nullptr); 243 host_impl.active_tree()->root_layer_for_testing()->DidDraw(nullptr);
243 } 244 }
244 245
245 TEST(PictureLayerTest, SuitableForGpuRasterization) { 246 TEST(PictureLayerTest, SuitableForGpuRasterization) {
246 std::unique_ptr<FakeRecordingSource> recording_source_owned( 247 std::unique_ptr<FakeRecordingSource> recording_source_owned(
247 new FakeRecordingSource); 248 new FakeRecordingSource);
248 FakeRecordingSource* recording_source = recording_source_owned.get(); 249 FakeRecordingSource* recording_source = recording_source_owned.get();
249 250
250 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); 251 FakeContentLayerClient client;
252 client.set_bounds(gfx::Size());
251 scoped_refptr<FakePictureLayer> layer = 253 scoped_refptr<FakePictureLayer> layer =
252 FakePictureLayer::CreateWithRecordingSource( 254 FakePictureLayer::CreateWithRecordingSource(
253 client, std::move(recording_source_owned)); 255 &client, std::move(recording_source_owned));
254 256
255 FakeLayerTreeHostClient host_client; 257 FakeLayerTreeHostClient host_client;
256 TestTaskGraphRunner task_graph_runner; 258 TestTaskGraphRunner task_graph_runner;
257 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); 259 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
258 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( 260 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
259 &host_client, &task_graph_runner, animation_host.get()); 261 &host_client, &task_graph_runner, animation_host.get());
260 host->SetRootLayer(layer); 262 host->SetRootLayer(layer);
261 263
262 // Update layers to initialize the recording source. 264 // Update layers to initialize the recording source.
263 gfx::Size layer_bounds(200, 200); 265 gfx::Size layer_bounds(200, 200);
264 gfx::Rect layer_rect(layer_bounds); 266 gfx::Rect layer_rect(layer_bounds);
265 Region invalidation(layer_rect); 267 Region invalidation(layer_rect);
266 268
267 gfx::Rect new_recorded_viewport = client->PaintableRegion(); 269 gfx::Rect new_recorded_viewport = client.PaintableRegion();
268 scoped_refptr<DisplayItemList> display_list = 270 scoped_refptr<DisplayItemList> display_list =
269 client->PaintContentsToDisplayList( 271 client.PaintContentsToDisplayList(
270 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); 272 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
271 size_t painter_reported_memory_usage = 273 size_t painter_reported_memory_usage =
272 client->GetApproximateUnsharedMemoryUsage(); 274 client.GetApproximateUnsharedMemoryUsage();
273 recording_source->UpdateAndExpandInvalidation(&invalidation, layer_bounds, 275 recording_source->UpdateAndExpandInvalidation(&invalidation, layer_bounds,
274 new_recorded_viewport); 276 new_recorded_viewport);
275 recording_source->UpdateDisplayItemList(display_list, 277 recording_source->UpdateDisplayItemList(display_list,
276 painter_reported_memory_usage); 278 painter_reported_memory_usage);
277 279
278 // Layer is suitable for gpu rasterization by default. 280 // Layer is suitable for gpu rasterization by default.
279 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); 281 EXPECT_TRUE(layer->IsSuitableForGpuRasterization());
280 282
281 // Veto gpu rasterization. 283 // Veto gpu rasterization.
282 layer->set_force_unsuitable_for_gpu_rasterization(true); 284 layer->set_force_unsuitable_for_gpu_rasterization(true);
283 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); 285 EXPECT_FALSE(layer->IsSuitableForGpuRasterization());
284 } 286 }
285 287
286 // PicturePile uses the source frame number as a unit for measuring invalidation 288 // PicturePile uses the source frame number as a unit for measuring invalidation
287 // frequency. When a pile moves between compositors, the frame number increases 289 // frequency. When a pile moves between compositors, the frame number increases
288 // non-monotonically. This executes that code path under this scenario allowing 290 // non-monotonically. This executes that code path under this scenario allowing
289 // for the code to verify correctness with DCHECKs. 291 // for the code to verify correctness with DCHECKs.
290 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { 292 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) {
291 LayerTreeSettings settings = LayerTreeSettingsForTesting(); 293 LayerTreeSettings settings = LayerTreeSettingsForTesting();
292 settings.single_thread_proxy_scheduler = false; 294 settings.single_thread_proxy_scheduler = false;
293 settings.use_zero_copy = true; 295 settings.use_zero_copy = true;
294 296
295 StubLayerTreeHostSingleThreadClient single_thread_client; 297 StubLayerTreeHostSingleThreadClient single_thread_client;
296 FakeLayerTreeHostClient host_client1; 298 FakeLayerTreeHostClient host_client1;
297 FakeLayerTreeHostClient host_client2; 299 FakeLayerTreeHostClient host_client2;
298 TestTaskGraphRunner task_graph_runner; 300 TestTaskGraphRunner task_graph_runner;
299 301
300 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); 302 FakeContentLayerClient client;
301 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(client); 303 client.set_bounds(gfx::Size());
304 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(&client);
302 305
303 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); 306 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
304 307
305 LayerTreeHost::InitParams params; 308 LayerTreeHost::InitParams params;
306 params.client = &host_client1; 309 params.client = &host_client1;
307 params.settings = &settings; 310 params.settings = &settings;
308 params.task_graph_runner = &task_graph_runner; 311 params.task_graph_runner = &task_graph_runner;
309 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); 312 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
310 params.mutator_host = animation_host.get(); 313 params.mutator_host = animation_host.get();
311 std::unique_ptr<LayerTreeHost> host1 = 314 std::unique_ptr<LayerTreeHost> host1 =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 host2->Composite(base::TimeTicks::Now()); 356 host2->Composite(base::TimeTicks::Now());
354 EXPECT_EQ(3, layer->update_count()); 357 EXPECT_EQ(3, layer->update_count());
355 EXPECT_EQ(1, host2->SourceFrameNumber()); 358 EXPECT_EQ(1, host2->SourceFrameNumber());
356 359
357 animation_host->SetMutatorHostClient(nullptr); 360 animation_host->SetMutatorHostClient(nullptr);
358 animation_host2->SetMutatorHostClient(nullptr); 361 animation_host2->SetMutatorHostClient(nullptr);
359 } 362 }
360 363
361 } // namespace 364 } // namespace
362 } // namespace cc 365 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/empty_content_layer_client.cc ('k') | cc/test/fake_tile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698