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

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

Issue 271533011: cc: Move tiling management out of draw properties calculation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + review commnets Created 6 years, 6 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_image_layer_impl.h" 5 #include "cc/layers/picture_image_layer_impl.h"
6 6
7 #include "cc/layers/append_quads_data.h" 7 #include "cc/layers/append_quads_data.h"
8 #include "cc/resources/tile_priority.h" 8 #include "cc/resources/tile_priority.h"
9 #include "cc/test/fake_impl_proxy.h" 9 #include "cc/test/fake_impl_proxy.h"
10 #include "cc/test/fake_layer_tree_host_impl.h" 10 #include "cc/test/fake_layer_tree_host_impl.h"
11 #include "cc/test/fake_output_surface.h" 11 #include "cc/test/fake_output_surface.h"
12 #include "cc/test/fake_picture_layer_tiling_client.h" 12 #include "cc/test/fake_picture_layer_tiling_client.h"
13 #include "cc/test/impl_side_painting_settings.h" 13 #include "cc/test/impl_side_painting_settings.h"
14 #include "cc/test/mock_quad_culler.h" 14 #include "cc/test/mock_quad_culler.h"
15 #include "cc/test/test_shared_bitmap_manager.h" 15 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "cc/trees/layer_tree_impl.h" 16 #include "cc/trees/layer_tree_impl.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace cc { 19 namespace cc {
20 namespace { 20 namespace {
21 21
22 class TestablePictureImageLayerImpl : public PictureImageLayerImpl { 22 class TestablePictureImageLayerImpl : public PictureImageLayerImpl {
23 public: 23 public:
24 TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id) 24 TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id)
25 : PictureImageLayerImpl(tree_impl, id) { 25 : PictureImageLayerImpl(tree_impl, id) {
26 } 26 }
27 using PictureLayerImpl::UpdateIdealScales;
28 using PictureLayerImpl::MaximumTilingContentScale;
29 using PictureLayerImpl::ManageTilings;
30 using PictureLayerImpl::DoPostCommitInitializationIfNeeded;
27 31
32 void ScaleAndManageTilings(bool animating_transform_to_screen,
danakj 2014/06/02 11:22:11 Is there a reason the test can't call UpdateTilePr
sohanjg 2014/06/02 11:36:15 Using UpdateTileprios directly (as we did in initi
33 float maximum_animation_contents_scale) {
34 DoPostCommitInitializationIfNeeded();
35 UpdateIdealScales();
36 if (CanHaveTilings()) {
37 ManageTilings(animating_transform_to_screen,
38 maximum_animation_contents_scale);
39 }
40 }
28 PictureLayerTilingSet* tilings() { return tilings_.get(); } 41 PictureLayerTilingSet* tilings() { return tilings_.get(); }
29 42
30 friend class PictureImageLayerImplTest; 43 friend class PictureImageLayerImplTest;
31 }; 44 };
32 45
33 class PictureImageLayerImplTest : public testing::Test { 46 class PictureImageLayerImplTest : public testing::Test {
34 public: 47 public:
35 PictureImageLayerImplTest() 48 PictureImageLayerImplTest()
36 : proxy_(base::MessageLoopProxy::current()), 49 : proxy_(base::MessageLoopProxy::current()),
37 host_impl_(ImplSidePaintingSettings(), 50 host_impl_(ImplSidePaintingSettings(),
(...skipping 15 matching lines...) Expand all
53 case PENDING_TREE: 66 case PENDING_TREE:
54 tree = host_impl_.pending_tree(); 67 tree = host_impl_.pending_tree();
55 break; 68 break;
56 case NUM_TREES: 69 case NUM_TREES:
57 NOTREACHED(); 70 NOTREACHED();
58 break; 71 break;
59 } 72 }
60 TestablePictureImageLayerImpl* layer = 73 TestablePictureImageLayerImpl* layer =
61 new TestablePictureImageLayerImpl(tree, id); 74 new TestablePictureImageLayerImpl(tree, id);
62 layer->SetBounds(gfx::Size(100, 200)); 75 layer->SetBounds(gfx::Size(100, 200));
76 layer->SetContentBounds(gfx::Size(100, 200));
63 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_, 77 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_,
64 layer->bounds())); 78 layer->bounds()));
65 layer->pile_ = tiling_client_.pile(); 79 layer->pile_ = tiling_client_.pile();
66 return make_scoped_ptr(layer); 80 return make_scoped_ptr(layer);
67 } 81 }
68 82
69 void UpdateDrawProperties() { 83 void UpdateDrawProperties() {
70 host_impl_.pending_tree()->UpdateDrawProperties(); 84 host_impl_.pending_tree()->UpdateDrawProperties();
71 } 85 }
72 86
87 void SetupDrawPropertiesAndManageTilings(
88 TestablePictureImageLayerImpl* layer,
89 float ideal_contents_scale,
90 float device_scale_factor,
91 float page_scale_factor,
92 float maximum_animation_contents_scale,
93 bool animating_transform_to_screen) {
94 layer->draw_properties().ideal_contents_scale = ideal_contents_scale;
95 layer->draw_properties().device_scale_factor = device_scale_factor;
96 layer->draw_properties().page_scale_factor = page_scale_factor;
97 layer->draw_properties().maximum_animation_contents_scale =
98 maximum_animation_contents_scale;
99 layer->draw_properties().screen_space_transform_is_animating =
100 animating_transform_to_screen;
101 layer->ScaleAndManageTilings(animating_transform_to_screen,
102 maximum_animation_contents_scale);
103 }
104
73 protected: 105 protected:
74 FakeImplProxy proxy_; 106 FakeImplProxy proxy_;
75 FakeLayerTreeHostImpl host_impl_; 107 FakeLayerTreeHostImpl host_impl_;
76 TestSharedBitmapManager shared_bitmap_manager_; 108 TestSharedBitmapManager shared_bitmap_manager_;
77 FakePictureLayerTilingClient tiling_client_; 109 FakePictureLayerTilingClient tiling_client_;
78 }; 110 };
79 111
80 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { 112 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) {
81 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); 113 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE));
82 layer->SetDrawsContent(true); 114 layer->SetDrawsContent(true);
83 115
84 float contents_scale_x; 116 SetupDrawPropertiesAndManageTilings(layer.get(), 2.f, 3.f, 4.f, 1.f, false);
85 float contents_scale_y; 117
86 gfx::Size content_bounds; 118 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_x());
87 layer->CalculateContentsScale(2.f, 119 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_y());
88 3.f, 120 EXPECT_FLOAT_EQ(1.f, layer->MaximumTilingContentScale());
89 4.f,
90 1.f,
91 false,
92 &contents_scale_x,
93 &contents_scale_y,
94 &content_bounds);
95 EXPECT_FLOAT_EQ(1.f, contents_scale_x);
96 EXPECT_FLOAT_EQ(1.f, contents_scale_y);
97 EXPECT_EQ(layer->bounds(), content_bounds);
98 } 121 }
99 122
100 TEST_F(PictureImageLayerImplTest, AreVisibleResourcesReady) { 123 TEST_F(PictureImageLayerImplTest, AreVisibleResourcesReady) {
101 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); 124 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE));
102 layer->SetBounds(gfx::Size(100, 200)); 125 layer->SetBounds(gfx::Size(100, 200));
103 layer->SetDrawsContent(true); 126 layer->SetDrawsContent(true);
104 127
105 UpdateDrawProperties(); 128 UpdateDrawProperties();
106 129
107 float contents_scale_x; 130 SetupDrawPropertiesAndManageTilings(layer.get(), 2.f, 3.f, 4.f, 1.f, false);
108 float contents_scale_y;
109 gfx::Size content_bounds;
110 layer->CalculateContentsScale(2.f,
111 3.f,
112 4.f,
113 1.f,
114 false,
115 &contents_scale_x,
116 &contents_scale_y,
117 &content_bounds);
118 layer->UpdateTilePriorities();
119 131
120 EXPECT_TRUE(layer->AreVisibleResourcesReady()); 132 EXPECT_TRUE(layer->AreVisibleResourcesReady());
121 } 133 }
122 134
123 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { 135 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) {
124 scoped_ptr<TestablePictureImageLayerImpl> pending_layer( 136 scoped_ptr<TestablePictureImageLayerImpl> pending_layer(
125 CreateLayer(1, PENDING_TREE)); 137 CreateLayer(1, PENDING_TREE));
126 pending_layer->SetDrawsContent(true); 138 pending_layer->SetDrawsContent(true);
127 139
128 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal 140 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal
129 // to the content scale used by PictureImageLayerImpl. 141 // to the content scale used by PictureImageLayerImpl.
130 const float suggested_ideal_contents_scale = 2.f; 142 const float suggested_ideal_contents_scale = 2.f;
131 const float device_scale_factor = 3.f; 143 const float device_scale_factor = 3.f;
132 const float page_scale_factor = 4.f; 144 const float page_scale_factor = 4.f;
133 const float maximum_animation_contents_scale = 1.f; 145 const float maximum_animation_contents_scale = 1.f;
134 const bool animating_transform_to_screen = false; 146 const bool animating_transform_to_screen = false;
135 float contents_scale_x; 147 SetupDrawPropertiesAndManageTilings(pending_layer.get(),
136 float contents_scale_y; 148 suggested_ideal_contents_scale,
137 gfx::Size content_bounds; 149 device_scale_factor,
138 pending_layer->CalculateContentsScale(suggested_ideal_contents_scale, 150 page_scale_factor,
139 device_scale_factor, 151 maximum_animation_contents_scale,
140 page_scale_factor, 152 animating_transform_to_screen);
141 maximum_animation_contents_scale,
142 animating_transform_to_screen,
143 &contents_scale_x,
144 &contents_scale_y,
145 &content_bounds);
146 153
147 // Push to active layer. 154 // Push to active layer.
148 host_impl_.ActivatePendingTree(); 155 host_impl_.ActivatePendingTree();
149 scoped_ptr<TestablePictureImageLayerImpl> active_layer( 156 scoped_ptr<TestablePictureImageLayerImpl> active_layer(
150 CreateLayer(1, ACTIVE_TREE)); 157 CreateLayer(1, ACTIVE_TREE));
151 pending_layer->PushPropertiesTo(active_layer.get()); 158 pending_layer->PushPropertiesTo(active_layer.get());
152 active_layer->CalculateContentsScale(suggested_ideal_contents_scale, 159 SetupDrawPropertiesAndManageTilings(active_layer.get(),
153 device_scale_factor, 160 suggested_ideal_contents_scale,
154 page_scale_factor, 161 device_scale_factor,
155 maximum_animation_contents_scale, 162 page_scale_factor,
156 animating_transform_to_screen, 163 maximum_animation_contents_scale,
157 &contents_scale_x, 164 animating_transform_to_screen);
158 &contents_scale_y,
159 &content_bounds);
160 165
161 // Create tile and resource. 166 // Create tile and resource.
162 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 167 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting();
163 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( 168 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
164 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); 169 active_layer->tilings()->tiling_at(0)->AllTilesForTesting());
165 170
166 // Draw. 171 // Draw.
167 active_layer->draw_properties().visible_content_rect = 172 active_layer->draw_properties().visible_content_rect =
168 gfx::Rect(active_layer->bounds()); 173 gfx::Rect(active_layer->bounds());
169 MockQuadCuller quad_culler; 174 MockQuadCuller quad_culler;
170 AppendQuadsData data; 175 AppendQuadsData data;
171 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL); 176 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL);
172 active_layer->AppendQuads(&quad_culler, &data); 177 active_layer->AppendQuads(&quad_culler, &data);
173 active_layer->DidDraw(NULL); 178 active_layer->DidDraw(NULL);
174 179
175 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material); 180 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material);
176 181
177 // Tiles are ready at correct scale, so should not set had_incomplete_tile. 182 // Tiles are ready at correct scale, so should not set had_incomplete_tile.
178 EXPECT_FALSE(data.had_incomplete_tile); 183 EXPECT_FALSE(data.had_incomplete_tile);
179 } 184 }
180 185
181 } // namespace 186 } // namespace
182 } // namespace cc 187 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698