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

Side by Side Diff: ui/compositor/layer_unittest.cc

Issue 11415089: ui/compositor: use cc/ directly instead of webkit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac Created 8 years, 1 month 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 | Annotate | Revision Log
« cc/proxy.h ('K') | « ui/compositor/layer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "cc/layer.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/compositor/compositor_observer.h" 15 #include "ui/compositor/compositor_observer.h"
15 #include "ui/compositor/compositor_setup.h" 16 #include "ui/compositor/compositor_setup.h"
16 #include "ui/compositor/layer.h" 17 #include "ui/compositor/layer.h"
17 #include "ui/compositor/layer_animation_sequence.h" 18 #include "ui/compositor/layer_animation_sequence.h"
18 #include "ui/compositor/test/test_compositor_host.h" 19 #include "ui/compositor/test/test_compositor_host.h"
19 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/codec/png_codec.h" 21 #include "ui/gfx/codec/png_codec.h"
21 #include "ui/gfx/gfx_paths.h" 22 #include "ui/gfx/gfx_paths.h"
22 #include "ui/gfx/skia_util.h" 23 #include "ui/gfx/skia_util.h"
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 686
686 NullLayerDelegate delegate; 687 NullLayerDelegate delegate;
687 l1->set_delegate(&delegate); 688 l1->set_delegate(&delegate);
688 l2->set_delegate(&delegate); 689 l2->set_delegate(&delegate);
689 l3->set_delegate(&delegate); 690 l3->set_delegate(&delegate);
690 691
691 // Layers should initially be drawn. 692 // Layers should initially be drawn.
692 EXPECT_TRUE(l1->IsDrawn()); 693 EXPECT_TRUE(l1->IsDrawn());
693 EXPECT_TRUE(l2->IsDrawn()); 694 EXPECT_TRUE(l2->IsDrawn());
694 EXPECT_TRUE(l3->IsDrawn()); 695 EXPECT_TRUE(l3->IsDrawn());
695 EXPECT_EQ(1.f, l1->web_layer()->opacity()); 696 EXPECT_EQ(1.f, l1->cc_layer()->opacity());
696 EXPECT_EQ(1.f, l2->web_layer()->opacity()); 697 EXPECT_EQ(1.f, l2->cc_layer()->opacity());
697 EXPECT_EQ(1.f, l3->web_layer()->opacity()); 698 EXPECT_EQ(1.f, l3->cc_layer()->opacity());
698 699
699 compositor()->SetRootLayer(l1.get()); 700 compositor()->SetRootLayer(l1.get());
700 701
701 Draw(); 702 Draw();
702 703
703 l1->SetVisible(false); 704 l1->SetVisible(false);
704 EXPECT_FALSE(l1->IsDrawn()); 705 EXPECT_FALSE(l1->IsDrawn());
705 EXPECT_FALSE(l2->IsDrawn()); 706 EXPECT_FALSE(l2->IsDrawn());
706 EXPECT_FALSE(l3->IsDrawn()); 707 EXPECT_FALSE(l3->IsDrawn());
707 EXPECT_EQ(0.f, l1->web_layer()->opacity()); 708 EXPECT_EQ(0.f, l1->cc_layer()->opacity());
708 709
709 l3->SetVisible(false); 710 l3->SetVisible(false);
710 EXPECT_FALSE(l1->IsDrawn()); 711 EXPECT_FALSE(l1->IsDrawn());
711 EXPECT_FALSE(l2->IsDrawn()); 712 EXPECT_FALSE(l2->IsDrawn());
712 EXPECT_FALSE(l3->IsDrawn()); 713 EXPECT_FALSE(l3->IsDrawn());
713 EXPECT_EQ(0.f, l3->web_layer()->opacity()); 714 EXPECT_EQ(0.f, l3->cc_layer()->opacity());
714 715
715 l1->SetVisible(true); 716 l1->SetVisible(true);
716 EXPECT_TRUE(l1->IsDrawn()); 717 EXPECT_TRUE(l1->IsDrawn());
717 EXPECT_TRUE(l2->IsDrawn()); 718 EXPECT_TRUE(l2->IsDrawn());
718 EXPECT_FALSE(l3->IsDrawn()); 719 EXPECT_FALSE(l3->IsDrawn());
719 EXPECT_EQ(1.f, l1->web_layer()->opacity()); 720 EXPECT_EQ(1.f, l1->cc_layer()->opacity());
720 } 721 }
721 722
722 // Checks that stacking-related methods behave as advertised. 723 // Checks that stacking-related methods behave as advertised.
723 TEST_F(LayerWithNullDelegateTest, Stacking) { 724 TEST_F(LayerWithNullDelegateTest, Stacking) {
724 scoped_ptr<Layer> root(new Layer(LAYER_NOT_DRAWN)); 725 scoped_ptr<Layer> root(new Layer(LAYER_NOT_DRAWN));
725 scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); 726 scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED));
726 scoped_ptr<Layer> l2(new Layer(LAYER_TEXTURED)); 727 scoped_ptr<Layer> l2(new Layer(LAYER_TEXTURED));
727 scoped_ptr<Layer> l3(new Layer(LAYER_TEXTURED)); 728 scoped_ptr<Layer> l3(new Layer(LAYER_TEXTURED));
728 l1->set_name("1"); 729 l1->set_name("1");
729 l2->set_name("2"); 730 l2->set_name("2");
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 l1_delegate.AddColor(SK_ColorWHITE); 1119 l1_delegate.AddColor(SK_ColorWHITE);
1119 l1->set_delegate(&l1_delegate); 1120 l1->set_delegate(&l1_delegate);
1120 1121
1121 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); 1122 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
1122 GetCompositor()->SetRootLayer(root.get()); 1123 GetCompositor()->SetRootLayer(root.get());
1123 root->Add(l1.get()); 1124 root->Add(l1.get());
1124 RunPendingMessages(); 1125 RunPendingMessages();
1125 1126
1126 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1127 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1127 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1128 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1128 gfx::Size size_in_pixel = root->web_layer()->bounds(); 1129 gfx::Size size_in_pixel = root->cc_layer()->bounds();
1129 EXPECT_EQ("200x220", size_in_pixel.ToString()); 1130 EXPECT_EQ("200x220", size_in_pixel.ToString());
1130 size_in_pixel = l1->web_layer()->bounds(); 1131 size_in_pixel = l1->cc_layer()->bounds();
1131 EXPECT_EQ("140x180", size_in_pixel.ToString()); 1132 EXPECT_EQ("140x180", size_in_pixel.ToString());
1132 // No scale change, so no scale notification. 1133 // No scale change, so no scale notification.
1133 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); 1134 EXPECT_EQ(0.0f, root_delegate.device_scale_factor());
1134 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); 1135 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor());
1135 1136
1136 RunPendingMessages(); 1137 RunPendingMessages();
1137 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); 1138 EXPECT_EQ("200x220", root_delegate.paint_size().ToString());
1138 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); 1139 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
1139 1140
1140 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. 1141 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP.
1141 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); 1142 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500));
1142 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1143 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1143 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1144 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1144 // Pixel size must have been scaled up. 1145 // Pixel size must have been scaled up.
1145 size_in_pixel = root->web_layer()->bounds(); 1146 size_in_pixel = root->cc_layer()->bounds();
1146 EXPECT_EQ("400x440", size_in_pixel.ToString()); 1147 EXPECT_EQ("400x440", size_in_pixel.ToString());
1147 size_in_pixel = l1->web_layer()->bounds(); 1148 size_in_pixel = l1->cc_layer()->bounds();
1148 EXPECT_EQ("280x360", size_in_pixel.ToString()); 1149 EXPECT_EQ("280x360", size_in_pixel.ToString());
1149 // New scale factor must have been notified. 1150 // New scale factor must have been notified.
1150 EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); 1151 EXPECT_EQ(2.0f, root_delegate.device_scale_factor());
1151 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); 1152 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor());
1152 1153
1153 // Canvas size must have been scaled down up. 1154 // Canvas size must have been scaled down up.
1154 RunPendingMessages(); 1155 RunPendingMessages();
1155 EXPECT_EQ("400x440", root_delegate.paint_size().ToString()); 1156 EXPECT_EQ("400x440", root_delegate.paint_size().ToString());
1156 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString()); 1157 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString());
1157 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); 1158 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
1158 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); 1159 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString());
1159 1160
1160 // Scale down back to 1.0f. 1161 // Scale down back to 1.0f.
1161 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); 1162 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
1162 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1163 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1163 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1164 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1164 // Pixel size must have been scaled down. 1165 // Pixel size must have been scaled down.
1165 size_in_pixel = root->web_layer()->bounds(); 1166 size_in_pixel = root->cc_layer()->bounds();
1166 EXPECT_EQ("200x220", size_in_pixel.ToString()); 1167 EXPECT_EQ("200x220", size_in_pixel.ToString());
1167 size_in_pixel = l1->web_layer()->bounds(); 1168 size_in_pixel = l1->cc_layer()->bounds();
1168 EXPECT_EQ("140x180", size_in_pixel.ToString()); 1169 EXPECT_EQ("140x180", size_in_pixel.ToString());
1169 // New scale factor must have been notified. 1170 // New scale factor must have been notified.
1170 EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); 1171 EXPECT_EQ(1.0f, root_delegate.device_scale_factor());
1171 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); 1172 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor());
1172 1173
1173 // Canvas size must have been scaled down too. 1174 // Canvas size must have been scaled down too.
1174 RunPendingMessages(); 1175 RunPendingMessages();
1175 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); 1176 EXPECT_EQ("200x220", root_delegate.paint_size().ToString());
1176 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString()); 1177 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString());
1177 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); 1178 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
(...skipping 22 matching lines...) Expand all
1200 TestLayerDelegate l1_delegate; 1201 TestLayerDelegate l1_delegate;
1201 l1_delegate.AddColor(SK_ColorWHITE); 1202 l1_delegate.AddColor(SK_ColorWHITE);
1202 l1->set_delegate(&l1_delegate); 1203 l1->set_delegate(&l1_delegate);
1203 1204
1204 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); 1205 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
1205 GetCompositor()->SetRootLayer(root.get()); 1206 GetCompositor()->SetRootLayer(root.get());
1206 RunPendingMessages(); 1207 RunPendingMessages();
1207 1208
1208 root->Add(l1.get()); 1209 root->Add(l1.get());
1209 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1210 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1210 gfx::Size size_in_pixel = l1->web_layer()->bounds(); 1211 gfx::Size size_in_pixel = l1->cc_layer()->bounds();
1211 EXPECT_EQ("140x180", size_in_pixel.ToString()); 1212 EXPECT_EQ("140x180", size_in_pixel.ToString());
1212 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); 1213 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor());
1213 1214
1214 RunPendingMessages(); 1215 RunPendingMessages();
1215 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); 1216 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
1216 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); 1217 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString());
1217 1218
1218 // Remove l1 from root and change the scale. 1219 // Remove l1 from root and change the scale.
1219 root->Remove(l1.get()); 1220 root->Remove(l1.get());
1220 EXPECT_EQ(NULL, l1->parent()); 1221 EXPECT_EQ(NULL, l1->parent());
1221 EXPECT_EQ(NULL, l1->GetCompositor()); 1222 EXPECT_EQ(NULL, l1->GetCompositor());
1222 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); 1223 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500));
1223 // Sanity check on root and l1. 1224 // Sanity check on root and l1.
1224 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1225 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1225 size_in_pixel = l1->web_layer()->bounds(); 1226 size_in_pixel = l1->cc_layer()->bounds();
1226 EXPECT_EQ("140x180", size_in_pixel.ToString()); 1227 EXPECT_EQ("140x180", size_in_pixel.ToString());
1227 1228
1228 1229
1229 root->Add(l1.get()); 1230 root->Add(l1.get());
1230 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1231 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1231 size_in_pixel = l1->web_layer()->bounds(); 1232 size_in_pixel = l1->cc_layer()->bounds();
1232 EXPECT_EQ("280x360", size_in_pixel.ToString()); 1233 EXPECT_EQ("280x360", size_in_pixel.ToString());
1233 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); 1234 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor());
1234 RunPendingMessages(); 1235 RunPendingMessages();
1235 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); 1236 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
1236 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); 1237 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString());
1237 } 1238 }
1238 1239
1239 // Tests layer::set_scale_content(false). 1240 // Tests layer::set_scale_content(false).
1240 TEST_F(LayerWithRealCompositorTest, MAYBE_NoScaleCanvas) { 1241 TEST_F(LayerWithRealCompositorTest, MAYBE_NoScaleCanvas) {
1241 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, 1242 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 1297
1297 // Resize layer. 1298 // Resize layer.
1298 child->SetBounds(gfx::Rect(200, 200, 400, 400)); 1299 child->SetBounds(gfx::Rect(200, 200, 400, 400));
1299 child->SetVisible(true); 1300 child->SetVisible(true);
1300 EXPECT_TRUE(schedule_draw_invoked_); 1301 EXPECT_TRUE(schedule_draw_invoked_);
1301 DrawTree(root.get()); 1302 DrawTree(root.get());
1302 EXPECT_TRUE(delegate.painted()); 1303 EXPECT_TRUE(delegate.painted());
1303 } 1304 }
1304 1305
1305 } // namespace ui 1306 } // namespace ui
OLDNEW
« cc/proxy.h ('K') | « ui/compositor/layer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698