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

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: debug build unit test failures addressed 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"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 case PENDING_TREE: 53 case PENDING_TREE:
54 tree = host_impl_.pending_tree(); 54 tree = host_impl_.pending_tree();
55 break; 55 break;
56 case NUM_TREES: 56 case NUM_TREES:
57 NOTREACHED(); 57 NOTREACHED();
58 break; 58 break;
59 } 59 }
60 TestablePictureImageLayerImpl* layer = 60 TestablePictureImageLayerImpl* layer =
61 new TestablePictureImageLayerImpl(tree, id); 61 new TestablePictureImageLayerImpl(tree, id);
62 layer->SetBounds(gfx::Size(100, 200)); 62 layer->SetBounds(gfx::Size(100, 200));
63 layer->SetContentBounds(gfx::Size(100, 200));
63 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_, 64 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_,
64 layer->bounds())); 65 layer->bounds()));
65 layer->pile_ = tiling_client_.pile(); 66 layer->pile_ = tiling_client_.pile();
66 return make_scoped_ptr(layer); 67 return make_scoped_ptr(layer);
67 } 68 }
68 69
69 void UpdateDrawProperties() { 70 void UpdateDrawProperties() {
70 host_impl_.pending_tree()->UpdateDrawProperties(); 71 host_impl_.pending_tree()->UpdateDrawProperties();
71 } 72 }
72 73
74 void SetupDrawPropertiesAndManageTilings(
75 TestablePictureImageLayerImpl* layer,
76 float ideal_contents_scale,
77 float device_scale_factor,
78 float page_scale_factor,
79 float maximum_animation_contents_scale,
80 bool animating_transform_to_screen) {
81 layer->draw_properties().ideal_contents_scale = ideal_contents_scale;
82 layer->draw_properties().device_scale_factor = device_scale_factor;
83 layer->draw_properties().page_scale_factor = page_scale_factor;
84 layer->draw_properties().maximum_animation_contents_scale =
85 maximum_animation_contents_scale;
86 layer->draw_properties().screen_space_transform_is_animating =
87 animating_transform_to_screen;
88 layer->UpdateIdealScales();
enne (OOO) 2014/05/29 17:55:48 Don't make these functions public in PictureLayerI
sohanjg 2014/05/30 16:52:43 Done.
89 if (layer->CanHaveTilings())
90 layer->ManageTilings(animating_transform_to_screen,
91 maximum_animation_contents_scale);
92 }
93
73 protected: 94 protected:
74 FakeImplProxy proxy_; 95 FakeImplProxy proxy_;
75 FakeLayerTreeHostImpl host_impl_; 96 FakeLayerTreeHostImpl host_impl_;
76 TestSharedBitmapManager shared_bitmap_manager_; 97 TestSharedBitmapManager shared_bitmap_manager_;
77 FakePictureLayerTilingClient tiling_client_; 98 FakePictureLayerTilingClient tiling_client_;
78 }; 99 };
79 100
80 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { 101 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) {
81 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); 102 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE));
82 layer->SetDrawsContent(true); 103 layer->SetDrawsContent(true);
83 104
84 float contents_scale_x; 105 SetupDrawPropertiesAndManageTilings(layer.get(), 2.f, 3.f, 4.f, 1.f, false);
85 float contents_scale_y; 106
86 gfx::Size content_bounds; 107 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_x());
87 layer->CalculateContentsScale(2.f, 108 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_y());
88 3.f, 109 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 } 110 }
99 111
100 TEST_F(PictureImageLayerImplTest, AreVisibleResourcesReady) { 112 TEST_F(PictureImageLayerImplTest, AreVisibleResourcesReady) {
101 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); 113 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE));
102 layer->SetBounds(gfx::Size(100, 200)); 114 layer->SetBounds(gfx::Size(100, 200));
103 layer->SetDrawsContent(true); 115 layer->SetDrawsContent(true);
104 116
105 UpdateDrawProperties(); 117 UpdateDrawProperties();
106 118
107 float contents_scale_x; 119 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 120
120 EXPECT_TRUE(layer->AreVisibleResourcesReady()); 121 EXPECT_TRUE(layer->AreVisibleResourcesReady());
121 } 122 }
122 123
123 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { 124 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) {
124 scoped_ptr<TestablePictureImageLayerImpl> pending_layer( 125 scoped_ptr<TestablePictureImageLayerImpl> pending_layer(
125 CreateLayer(1, PENDING_TREE)); 126 CreateLayer(1, PENDING_TREE));
126 pending_layer->SetDrawsContent(true); 127 pending_layer->SetDrawsContent(true);
127 128
128 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal 129 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal
129 // to the content scale used by PictureImageLayerImpl. 130 // to the content scale used by PictureImageLayerImpl.
130 const float suggested_ideal_contents_scale = 2.f; 131 const float suggested_ideal_contents_scale = 2.f;
131 const float device_scale_factor = 3.f; 132 const float device_scale_factor = 3.f;
132 const float page_scale_factor = 4.f; 133 const float page_scale_factor = 4.f;
133 const float maximum_animation_contents_scale = 1.f; 134 const float maximum_animation_contents_scale = 1.f;
134 const bool animating_transform_to_screen = false; 135 const bool animating_transform_to_screen = false;
135 float contents_scale_x; 136 SetupDrawPropertiesAndManageTilings(pending_layer.get(),
136 float contents_scale_y; 137 suggested_ideal_contents_scale,
137 gfx::Size content_bounds; 138 device_scale_factor,
138 pending_layer->CalculateContentsScale(suggested_ideal_contents_scale, 139 page_scale_factor,
139 device_scale_factor, 140 maximum_animation_contents_scale,
140 page_scale_factor, 141 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 142
147 // Push to active layer. 143 // Push to active layer.
148 host_impl_.ActivatePendingTree(); 144 host_impl_.ActivatePendingTree();
149 scoped_ptr<TestablePictureImageLayerImpl> active_layer( 145 scoped_ptr<TestablePictureImageLayerImpl> active_layer(
150 CreateLayer(1, ACTIVE_TREE)); 146 CreateLayer(1, ACTIVE_TREE));
151 pending_layer->PushPropertiesTo(active_layer.get()); 147 pending_layer->PushPropertiesTo(active_layer.get());
152 active_layer->CalculateContentsScale(suggested_ideal_contents_scale, 148 SetupDrawPropertiesAndManageTilings(active_layer.get(),
153 device_scale_factor, 149 suggested_ideal_contents_scale,
154 page_scale_factor, 150 device_scale_factor,
155 maximum_animation_contents_scale, 151 page_scale_factor,
156 animating_transform_to_screen, 152 maximum_animation_contents_scale,
157 &contents_scale_x, 153 animating_transform_to_screen);
158 &contents_scale_y,
159 &content_bounds);
160 154
161 // Create tile and resource. 155 // Create tile and resource.
162 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 156 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting();
163 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( 157 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
164 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); 158 active_layer->tilings()->tiling_at(0)->AllTilesForTesting());
165 159
166 // Draw. 160 // Draw.
167 active_layer->draw_properties().visible_content_rect = 161 active_layer->draw_properties().visible_content_rect =
168 gfx::Rect(active_layer->bounds()); 162 gfx::Rect(active_layer->bounds());
169 MockQuadCuller quad_culler; 163 MockQuadCuller quad_culler;
170 AppendQuadsData data; 164 AppendQuadsData data;
171 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL); 165 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL);
172 active_layer->AppendQuads(&quad_culler, &data); 166 active_layer->AppendQuads(&quad_culler, &data);
173 active_layer->DidDraw(NULL); 167 active_layer->DidDraw(NULL);
174 168
175 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material); 169 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material);
176 170
177 // Tiles are ready at correct scale, so should not set had_incomplete_tile. 171 // Tiles are ready at correct scale, so should not set had_incomplete_tile.
178 EXPECT_FALSE(data.had_incomplete_tile); 172 EXPECT_FALSE(data.had_incomplete_tile);
179 } 173 }
180 174
181 } // namespace 175 } // namespace
182 } // namespace cc 176 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698