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

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 to TOT 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
« no previous file with comments | « cc/layers/picture_image_layer_impl.cc ('k') | cc/layers/picture_layer_impl.h » ('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_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::MaximumTilingContentsScale;
29 using PictureLayerImpl::ManageTilings;
30 using PictureLayerImpl::DoPostCommitInitializationIfNeeded;
27 31
32 void ScaleAndManageTilings(bool animating_transform_to_screen,
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
83 void SetupDrawPropertiesAndManageTilings(
84 TestablePictureImageLayerImpl* layer,
85 float ideal_contents_scale,
86 float device_scale_factor,
87 float page_scale_factor,
88 float maximum_animation_contents_scale,
89 bool animating_transform_to_screen) {
90 layer->draw_properties().ideal_contents_scale = ideal_contents_scale;
91 layer->draw_properties().device_scale_factor = device_scale_factor;
92 layer->draw_properties().page_scale_factor = page_scale_factor;
93 layer->draw_properties().maximum_animation_contents_scale =
94 maximum_animation_contents_scale;
95 layer->draw_properties().screen_space_transform_is_animating =
96 animating_transform_to_screen;
97 layer->ScaleAndManageTilings(animating_transform_to_screen,
98 maximum_animation_contents_scale);
99 }
100
69 protected: 101 protected:
70 FakeImplProxy proxy_; 102 FakeImplProxy proxy_;
71 FakeLayerTreeHostImpl host_impl_; 103 FakeLayerTreeHostImpl host_impl_;
72 TestSharedBitmapManager shared_bitmap_manager_; 104 TestSharedBitmapManager shared_bitmap_manager_;
73 FakePictureLayerTilingClient tiling_client_; 105 FakePictureLayerTilingClient tiling_client_;
74 }; 106 };
75 107
76 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { 108 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) {
77 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); 109 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE));
78 layer->SetDrawsContent(true); 110 layer->SetDrawsContent(true);
79 111
80 float contents_scale_x; 112 SetupDrawPropertiesAndManageTilings(layer.get(), 2.f, 3.f, 4.f, 1.f, false);
81 float contents_scale_y; 113
82 gfx::Size content_bounds; 114 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_x());
83 layer->CalculateContentsScale(2.f, 115 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_y());
84 3.f, 116 EXPECT_FLOAT_EQ(1.f, layer->MaximumTilingContentsScale());
85 4.f,
86 1.f,
87 false,
88 &contents_scale_x,
89 &contents_scale_y,
90 &content_bounds);
91 EXPECT_FLOAT_EQ(1.f, contents_scale_x);
92 EXPECT_FLOAT_EQ(1.f, contents_scale_y);
93 EXPECT_EQ(layer->bounds(), content_bounds);
94 } 117 }
95 118
96 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { 119 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) {
97 scoped_ptr<TestablePictureImageLayerImpl> pending_layer( 120 scoped_ptr<TestablePictureImageLayerImpl> pending_layer(
98 CreateLayer(1, PENDING_TREE)); 121 CreateLayer(1, PENDING_TREE));
99 pending_layer->SetDrawsContent(true); 122 pending_layer->SetDrawsContent(true);
100 123
101 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal 124 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal
102 // to the content scale used by PictureImageLayerImpl. 125 // to the content scale used by PictureImageLayerImpl.
103 const float suggested_ideal_contents_scale = 2.f; 126 const float suggested_ideal_contents_scale = 2.f;
104 const float device_scale_factor = 3.f; 127 const float device_scale_factor = 3.f;
105 const float page_scale_factor = 4.f; 128 const float page_scale_factor = 4.f;
106 const float maximum_animation_contents_scale = 1.f; 129 const float maximum_animation_contents_scale = 1.f;
107 const bool animating_transform_to_screen = false; 130 const bool animating_transform_to_screen = false;
108 float contents_scale_x; 131 SetupDrawPropertiesAndManageTilings(pending_layer.get(),
109 float contents_scale_y; 132 suggested_ideal_contents_scale,
110 gfx::Size content_bounds; 133 device_scale_factor,
111 pending_layer->CalculateContentsScale(suggested_ideal_contents_scale, 134 page_scale_factor,
112 device_scale_factor, 135 maximum_animation_contents_scale,
113 page_scale_factor, 136 animating_transform_to_screen);
114 maximum_animation_contents_scale,
115 animating_transform_to_screen,
116 &contents_scale_x,
117 &contents_scale_y,
118 &content_bounds);
119 137
120 // Push to active layer. 138 // Push to active layer.
121 host_impl_.ActivatePendingTree(); 139 host_impl_.ActivatePendingTree();
122 scoped_ptr<TestablePictureImageLayerImpl> active_layer( 140 scoped_ptr<TestablePictureImageLayerImpl> active_layer(
123 CreateLayer(1, ACTIVE_TREE)); 141 CreateLayer(1, ACTIVE_TREE));
124 pending_layer->PushPropertiesTo(active_layer.get()); 142 pending_layer->PushPropertiesTo(active_layer.get());
125 active_layer->CalculateContentsScale(suggested_ideal_contents_scale, 143 SetupDrawPropertiesAndManageTilings(active_layer.get(),
126 device_scale_factor, 144 suggested_ideal_contents_scale,
127 page_scale_factor, 145 device_scale_factor,
128 maximum_animation_contents_scale, 146 page_scale_factor,
129 animating_transform_to_screen, 147 maximum_animation_contents_scale,
130 &contents_scale_x, 148 animating_transform_to_screen);
131 &contents_scale_y,
132 &content_bounds);
133 149
134 // Create tile and resource. 150 // Create tile and resource.
135 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 151 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting();
136 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( 152 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
137 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); 153 active_layer->tilings()->tiling_at(0)->AllTilesForTesting());
138 154
139 // Draw. 155 // Draw.
140 active_layer->draw_properties().visible_content_rect = 156 active_layer->draw_properties().visible_content_rect =
141 gfx::Rect(active_layer->bounds()); 157 gfx::Rect(active_layer->bounds());
142 MockQuadCuller quad_culler; 158 MockQuadCuller quad_culler;
143 AppendQuadsData data; 159 AppendQuadsData data;
144 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL); 160 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL);
145 active_layer->AppendQuads(&quad_culler, &data); 161 active_layer->AppendQuads(&quad_culler, &data);
146 active_layer->DidDraw(NULL); 162 active_layer->DidDraw(NULL);
147 163
148 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material); 164 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material);
149 165
150 // Tiles are ready at correct scale, so should not set had_incomplete_tile. 166 // Tiles are ready at correct scale, so should not set had_incomplete_tile.
151 EXPECT_FALSE(data.had_incomplete_tile); 167 EXPECT_FALSE(data.had_incomplete_tile);
152 } 168 }
153 169
154 } // namespace 170 } // namespace
155 } // namespace cc 171 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_image_layer_impl.cc ('k') | cc/layers/picture_layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698