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

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

Issue 519583003: Use the solid color detection to create solid layers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a unit test for solid color on picturelayerimpl Created 6 years, 3 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
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 "cc/layers/content_layer_client.h" 7 #include "cc/layers/content_layer_client.h"
8 #include "cc/layers/picture_layer_impl.h" 8 #include "cc/layers/picture_layer_impl.h"
9 #include "cc/resources/resource_update_queue.h" 9 #include "cc/resources/resource_update_queue.h"
10 #include "cc/test/fake_content_layer_client.h"
10 #include "cc/test/fake_layer_tree_host.h" 11 #include "cc/test/fake_layer_tree_host.h"
11 #include "cc/test/fake_picture_layer_impl.h" 12 #include "cc/test/fake_picture_layer_impl.h"
12 #include "cc/test/fake_proxy.h" 13 #include "cc/test/fake_proxy.h"
13 #include "cc/test/impl_side_painting_settings.h" 14 #include "cc/test/impl_side_painting_settings.h"
14 #include "cc/trees/occlusion_tracker.h" 15 #include "cc/trees/occlusion_tracker.h"
15 #include "cc/trees/single_thread_proxy.h" 16 #include "cc/trees/single_thread_proxy.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace cc { 19 namespace cc {
19 namespace { 20 namespace {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 ImplSidePaintingSettings(), &proxy, &shared_bitmap_manager); 60 ImplSidePaintingSettings(), &proxy, &shared_bitmap_manager);
60 host_impl.CreatePendingTree(); 61 host_impl.CreatePendingTree();
61 scoped_ptr<FakePictureLayerImpl> layer_impl = 62 scoped_ptr<FakePictureLayerImpl> layer_impl =
62 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1); 63 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1);
63 64
64 layer->PushPropertiesTo(layer_impl.get()); 65 layer->PushPropertiesTo(layer_impl.get());
65 EXPECT_FALSE(layer_impl->CanHaveTilings()); 66 EXPECT_FALSE(layer_impl->CanHaveTilings());
66 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0)); 67 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0));
67 EXPECT_EQ(gfx::Size(), layer_impl->pile()->tiling_size()); 68 EXPECT_EQ(gfx::Size(), layer_impl->pile()->tiling_size());
68 EXPECT_FALSE(layer_impl->pile()->HasRecordings()); 69 EXPECT_FALSE(layer_impl->pile()->HasRecordings());
70 EXPECT_TRUE(layer_impl->IsSolidColor());
69 } 71 }
70 } 72 }
71 73
72 TEST(PictureLayerTest, SuitableForGpuRasterization) { 74 TEST(PictureLayerTest, SuitableForGpuRasterization) {
73 MockContentLayerClient client; 75 MockContentLayerClient client;
74 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 76 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
75 PicturePile* pile = layer->GetPicturePileForTesting(); 77 PicturePile* pile = layer->GetPicturePileForTesting();
76 78
77 // Layer is suitable for gpu rasterization by default. 79 // Layer is suitable for gpu rasterization by default.
78 EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization()); 80 EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization());
(...skipping 13 matching lines...) Expand all
92 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(settings); 94 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(settings);
93 host->SetRootLayer(layer); 95 host->SetRootLayer(layer);
94 EXPECT_EQ(Picture::RECORD_NORMALLY, layer->RecordingMode()); 96 EXPECT_EQ(Picture::RECORD_NORMALLY, layer->RecordingMode());
95 97
96 settings.recording_mode = LayerTreeSettings::RecordWithSkRecord; 98 settings.recording_mode = LayerTreeSettings::RecordWithSkRecord;
97 host = FakeLayerTreeHost::Create(settings); 99 host = FakeLayerTreeHost::Create(settings);
98 host->SetRootLayer(layer); 100 host->SetRootLayer(layer);
99 EXPECT_EQ(Picture::RECORD_WITH_SKRECORD, layer->RecordingMode()); 101 EXPECT_EQ(Picture::RECORD_WITH_SKRECORD, layer->RecordingMode());
100 } 102 }
101 103
104 TEST(PictureLayerTest, SolidColorAnalysisForPictureLayer) {
105 FakeContentLayerClient client;
106 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
107 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
108 host->SetRootLayer(layer);
109 PicturePile* pile = layer->GetPicturePileForTesting();
110 pile->SetMinContentsScale(0.125);
111 pile->SetTileGridSize(gfx::Size(1000, 1000));
112 pile->tiling().SetTilingSize(pile->tiling().max_texture_size());
113
114 FakeProxy proxy;
115 DebugScopedSetImplThread impl_thread(&proxy);
116
117 TestSharedBitmapManager shared_bitmap_manager;
118 FakeLayerTreeHostImpl host_impl(
119 ImplSidePaintingSettings(), &proxy, &shared_bitmap_manager);
120 host_impl.CreatePendingTree();
121 scoped_ptr<FakePictureLayerImpl> layer_impl =
122 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1);
123
124 gfx::Size tiling_size = pile->tiling_size();
125 gfx::Rect tiling_rect = gfx::Rect(tiling_size);
126 int frame_number = 0;
127 FakeRenderingStatsInstrumentation stats_instrumentation;
128
129 Region invalidation1(tiling_rect);
130 pile->UpdateAndExpandInvalidation(&client,
131 &invalidation1,
132 SK_ColorWHITE,
133 false,
134 false,
135 tiling_size,
136 tiling_rect,
137 frame_number++,
138 Picture::RECORD_NORMALLY,
139 &stats_instrumentation);
140
141 // We haven't drawn anything yet, so it should be solid.
142 EXPECT_TRUE(pile->IsSolidColor());
143 layer->PushPropertiesTo(layer_impl.get());
144 EXPECT_TRUE(layer_impl->IsSolidColor());
145
146 // Draw a rectangle that doesn't cover the viewport.
147 gfx::Rect smallRect = tiling_rect;
148 smallRect.Inset(10, 10, 10, 10);
149 SkPaint paint;
150 paint.setColor(SK_ColorCYAN);
151 client.add_draw_rect(smallRect, paint);
152 Region invalidation2(tiling_rect);
153 pile->UpdateAndExpandInvalidation(&client,
154 &invalidation2,
155 SK_ColorWHITE,
156 false,
157 false,
158 tiling_size,
159 tiling_rect,
160 frame_number++,
161 Picture::RECORD_NORMALLY,
162 &stats_instrumentation);
163
164 // Since the rectangle doesn't cover the entire layer, we should no be solid
165 EXPECT_FALSE(pile->IsSolidColor());
166 layer->PushPropertiesTo(layer_impl.get());
167 EXPECT_FALSE(layer_impl->IsSolidColor());
168 }
169
102 } // namespace 170 } // namespace
103 } // namespace cc 171 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698