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

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

Powered by Google App Engine
This is Rietveld 408576698