OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) { | 164 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) { |
165 return gfx::Canvas::CreateCanvas(layer->bounds().size(), false); | 165 return gfx::Canvas::CreateCanvas(layer->bounds().size(), false); |
166 } | 166 } |
167 | 167 |
168 void DrawTree(Layer* root) { | 168 void DrawTree(Layer* root) { |
169 GetCompositor()->SetRootLayer(root); | 169 GetCompositor()->SetRootLayer(root); |
170 GetCompositor()->Draw(false); | 170 GetCompositor()->Draw(false); |
171 } | 171 } |
172 | 172 |
173 bool ReadPixels(SkBitmap* bitmap) { | |
174 return GetCompositor()->ReadPixels(bitmap, | |
175 gfx::Rect(GetCompositor()->size())); | |
176 } | |
177 | |
178 void RunPendingMessages() { | 173 void RunPendingMessages() { |
179 MessageLoopForUI::current()->RunAllPending(); | 174 MessageLoopForUI::current()->RunAllPending(); |
180 } | 175 } |
181 | 176 |
182 // Invalidates the entire contents of the layer. | 177 // Invalidates the entire contents of the layer. |
183 void SchedulePaintForLayer(Layer* layer) { | 178 void SchedulePaintForLayer(Layer* layer) { |
184 layer->SchedulePaint( | 179 layer->SchedulePaint( |
185 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); | 180 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); |
186 } | 181 } |
187 | 182 |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); | 1081 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); |
1087 | 1082 |
1088 // The CompositorDelegate (us) should have been told to draw for a resize. | 1083 // The CompositorDelegate (us) should have been told to draw for a resize. |
1089 EXPECT_TRUE(schedule_draw_invoked_); | 1084 EXPECT_TRUE(schedule_draw_invoked_); |
1090 } | 1085 } |
1091 | 1086 |
1092 // Checks that pixels are actually drawn to the screen with a read back. | 1087 // Checks that pixels are actually drawn to the screen with a read back. |
1093 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) { | 1088 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) { |
1094 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, | 1089 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, |
1095 gfx::Rect(0, 0, 500, 500))); | 1090 gfx::Rect(0, 0, 500, 500))); |
1096 scoped_ptr<Layer> layer2(CreateColorLayer(SK_ColorBLUE, | |
1097 gfx::Rect(0, 0, 500, 10))); | |
1098 | |
1099 layer->Add(layer2.get()); | |
1100 | |
1101 DrawTree(layer.get()); | 1091 DrawTree(layer.get()); |
1102 | 1092 |
1103 SkBitmap bitmap; | 1093 SkBitmap bitmap; |
1104 gfx::Size size = GetCompositor()->size(); | 1094 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap)); |
1105 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap, | |
1106 gfx::Rect(0, 10, | |
1107 size.width(), size.height() - 10))); | |
1108 ASSERT_FALSE(bitmap.empty()); | 1095 ASSERT_FALSE(bitmap.empty()); |
1109 | 1096 |
1110 SkAutoLockPixels lock(bitmap); | 1097 SkAutoLockPixels lock(bitmap); |
1111 bool is_all_red = true; | 1098 bool is_all_red = true; |
1112 for (int x = 0; is_all_red && x < 500; x++) | 1099 for (int x = 0; is_all_red && x < 500; x++) |
1113 for (int y = 0; is_all_red && y < 490; y++) | 1100 for (int y = 0; is_all_red && y < 500; y++) |
1114 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); | 1101 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); |
1115 | 1102 |
1116 EXPECT_TRUE(is_all_red); | 1103 EXPECT_TRUE(is_all_red); |
1117 } | 1104 } |
1118 | 1105 |
1119 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. | 1106 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. |
1120 TEST_F(LayerWithRealCompositorTest, MAYBE_SetRootLayer) { | 1107 TEST_F(LayerWithRealCompositorTest, MAYBE_SetRootLayer) { |
1121 Compositor* compositor = GetCompositor(); | 1108 Compositor* compositor = GetCompositor(); |
1122 Layer l1; | 1109 Layer l1; |
1123 EXPECT_EQ(NULL, l1.GetCompositor()); | 1110 EXPECT_EQ(NULL, l1.GetCompositor()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 gfx::Rect(10, 10, 25, 25))); | 1216 gfx::Rect(10, 10, 25, 25))); |
1230 | 1217 |
1231 FilePath ref_img1 = test_data_directory().AppendASCII("ModifyHierarchy1.png"); | 1218 FilePath ref_img1 = test_data_directory().AppendASCII("ModifyHierarchy1.png"); |
1232 FilePath ref_img2 = test_data_directory().AppendASCII("ModifyHierarchy2.png"); | 1219 FilePath ref_img2 = test_data_directory().AppendASCII("ModifyHierarchy2.png"); |
1233 SkBitmap bitmap; | 1220 SkBitmap bitmap; |
1234 | 1221 |
1235 l0->Add(l11.get()); | 1222 l0->Add(l11.get()); |
1236 l11->Add(l21.get()); | 1223 l11->Add(l21.get()); |
1237 l0->Add(l12.get()); | 1224 l0->Add(l12.get()); |
1238 DrawTree(l0.get()); | 1225 DrawTree(l0.get()); |
1239 ASSERT_TRUE(ReadPixels(&bitmap)); | 1226 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap)); |
1240 ASSERT_FALSE(bitmap.empty()); | 1227 ASSERT_FALSE(bitmap.empty()); |
1241 // WritePNGFile(bitmap, ref_img1); | 1228 // WritePNGFile(bitmap, ref_img1); |
1242 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img1)); | 1229 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img1)); |
1243 | 1230 |
1244 l0->MoveToFront(l11.get()); | 1231 l0->MoveToFront(l11.get()); |
1245 DrawTree(l0.get()); | 1232 DrawTree(l0.get()); |
1246 ASSERT_TRUE(ReadPixels(&bitmap)); | 1233 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap)); |
1247 ASSERT_FALSE(bitmap.empty()); | 1234 ASSERT_FALSE(bitmap.empty()); |
1248 // WritePNGFile(bitmap, ref_img2); | 1235 // WritePNGFile(bitmap, ref_img2); |
1249 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img2)); | 1236 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img2)); |
1250 | 1237 |
1251 // l11 is already at the front, should have no effect. | 1238 // l11 is already at the front, should have no effect. |
1252 l0->MoveToFront(l11.get()); | 1239 l0->MoveToFront(l11.get()); |
1253 DrawTree(l0.get()); | 1240 DrawTree(l0.get()); |
1254 ASSERT_TRUE(ReadPixels(&bitmap)); | 1241 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap)); |
1255 ASSERT_FALSE(bitmap.empty()); | 1242 ASSERT_FALSE(bitmap.empty()); |
1256 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img2)); | 1243 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img2)); |
1257 | 1244 |
1258 // l11 is already at the front, should have no effect. | 1245 // l11 is already at the front, should have no effect. |
1259 l0->MoveAbove(l11.get(), l12.get()); | 1246 l0->MoveAbove(l11.get(), l12.get()); |
1260 DrawTree(l0.get()); | 1247 DrawTree(l0.get()); |
1261 ASSERT_TRUE(ReadPixels(&bitmap)); | 1248 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap)); |
1262 ASSERT_FALSE(bitmap.empty()); | 1249 ASSERT_FALSE(bitmap.empty()); |
1263 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img2)); | 1250 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img2)); |
1264 | 1251 |
1265 // should restore to original configuration | 1252 // should restore to original configuration |
1266 l0->MoveAbove(l12.get(), l11.get()); | 1253 l0->MoveAbove(l12.get(), l11.get()); |
1267 DrawTree(l0.get()); | 1254 DrawTree(l0.get()); |
1268 ASSERT_TRUE(ReadPixels(&bitmap)); | 1255 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap)); |
1269 ASSERT_FALSE(bitmap.empty()); | 1256 ASSERT_FALSE(bitmap.empty()); |
1270 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img1)); | 1257 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img1)); |
1271 } | 1258 } |
1272 | 1259 |
1273 // Opacity is rendered correctly. | 1260 // Opacity is rendered correctly. |
1274 // Checks that modifying the hierarchy correctly affects final composite. | 1261 // Checks that modifying the hierarchy correctly affects final composite. |
1275 TEST_F(LayerWithRealCompositorTest, MAYBE_Opacity) { | 1262 TEST_F(LayerWithRealCompositorTest, MAYBE_Opacity) { |
1276 GetCompositor()->WidgetSizeChanged(gfx::Size(50, 50)); | 1263 GetCompositor()->WidgetSizeChanged(gfx::Size(50, 50)); |
1277 | 1264 |
1278 // l0 | 1265 // l0 |
1279 // +-l11 | 1266 // +-l11 |
1280 scoped_ptr<Layer> l0(CreateColorLayer(SK_ColorRED, | 1267 scoped_ptr<Layer> l0(CreateColorLayer(SK_ColorRED, |
1281 gfx::Rect(0, 0, 50, 50))); | 1268 gfx::Rect(0, 0, 50, 50))); |
1282 scoped_ptr<Layer> l11(CreateColorLayer(SK_ColorGREEN, | 1269 scoped_ptr<Layer> l11(CreateColorLayer(SK_ColorGREEN, |
1283 gfx::Rect(0, 0, 25, 25))); | 1270 gfx::Rect(0, 0, 25, 25))); |
1284 | 1271 |
1285 FilePath ref_img = test_data_directory().AppendASCII("Opacity.png"); | 1272 FilePath ref_img = test_data_directory().AppendASCII("Opacity.png"); |
1286 | 1273 |
1287 l11->SetOpacity(0.75); | 1274 l11->SetOpacity(0.75); |
1288 l0->Add(l11.get()); | 1275 l0->Add(l11.get()); |
1289 DrawTree(l0.get()); | 1276 DrawTree(l0.get()); |
1290 SkBitmap bitmap; | 1277 SkBitmap bitmap; |
1291 ASSERT_TRUE(ReadPixels(&bitmap)); | 1278 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap)); |
1292 ASSERT_FALSE(bitmap.empty()); | 1279 ASSERT_FALSE(bitmap.empty()); |
1293 // WritePNGFile(bitmap, ref_img); | 1280 // WritePNGFile(bitmap, ref_img); |
1294 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img)); | 1281 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img)); |
1295 } | 1282 } |
1296 | 1283 |
1297 } // namespace ui | 1284 } // namespace ui |
OLD | NEW |