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

Side by Side Diff: content/common/gpu/client/gl_helper_unittest.cc

Issue 394203002: GLHelper: validate destination size matches last scale size in test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 | « no previous file | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stdio.h> 5 #include <stdio.h>
6 #include <cmath> 6 #include <cmath>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include <GLES2/gl2.h> 10 #include <GLES2/gl2.h>
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 return true; 251 return true;
252 } 252 }
253 } 253 }
254 return false; 254 return false;
255 } 255 }
256 256
257 // Make sure that the stages of the scaler pipeline are sane. 257 // Make sure that the stages of the scaler pipeline are sane.
258 void ValidateScalerStages( 258 void ValidateScalerStages(
259 content::GLHelper::ScalerQuality quality, 259 content::GLHelper::ScalerQuality quality,
260 const std::vector<GLHelperScaling::ScalerStage>& scaler_stages, 260 const std::vector<GLHelperScaling::ScalerStage>& scaler_stages,
261 const gfx::Size& dst_size,
261 const std::string& message) { 262 const std::string& message) {
262 bool previous_error = HasFailure(); 263 bool previous_error = HasFailure();
263 // First, check that the input size for each stage is equal to 264 // First, check that the input size for each stage is equal to
264 // the output size of the previous stage. 265 // the output size of the previous stage.
265 for (size_t i = 1; i < scaler_stages.size(); i++) { 266 for (size_t i = 1; i < scaler_stages.size(); i++) {
266 EXPECT_EQ(scaler_stages[i - 1].dst_size.width(), 267 EXPECT_EQ(scaler_stages[i - 1].dst_size.width(),
267 scaler_stages[i].src_size.width()); 268 scaler_stages[i].src_size.width());
268 EXPECT_EQ(scaler_stages[i - 1].dst_size.height(), 269 EXPECT_EQ(scaler_stages[i - 1].dst_size.height(),
269 scaler_stages[i].src_size.height()); 270 scaler_stages[i].src_size.height());
270 EXPECT_EQ(scaler_stages[i].src_subrect.x(), 0); 271 EXPECT_EQ(scaler_stages[i].src_subrect.x(), 0);
271 EXPECT_EQ(scaler_stages[i].src_subrect.y(), 0); 272 EXPECT_EQ(scaler_stages[i].src_subrect.y(), 0);
272 EXPECT_EQ(scaler_stages[i].src_subrect.width(), 273 EXPECT_EQ(scaler_stages[i].src_subrect.width(),
273 scaler_stages[i].src_size.width()); 274 scaler_stages[i].src_size.width());
274 EXPECT_EQ(scaler_stages[i].src_subrect.height(), 275 EXPECT_EQ(scaler_stages[i].src_subrect.height(),
275 scaler_stages[i].src_size.height()); 276 scaler_stages[i].src_size.height());
276 } 277 }
277 278
279 // Check the output size matches the destination of the last stage
280 EXPECT_EQ(scaler_stages[scaler_stages.size() - 1].dst_size.width(),
281 dst_size.width());
282 EXPECT_EQ(scaler_stages[scaler_stages.size() - 1].dst_size.height(),
283 dst_size.height());
284
278 // Used to verify that up-scales are not attempted after some 285 // Used to verify that up-scales are not attempted after some
279 // other scale. 286 // other scale.
280 bool scaled_x = false; 287 bool scaled_x = false;
281 bool scaled_y = false; 288 bool scaled_y = false;
282 289
283 for (size_t i = 0; i < scaler_stages.size(); i++) { 290 for (size_t i = 0; i < scaler_stages.size(); i++) {
284 // Note: 2.0 means scaling down by 50% 291 // Note: 2.0 means scaling down by 50%
285 double x_scale = 292 double x_scale =
286 static_cast<double>(scaler_stages[i].src_subrect.width()) / 293 static_cast<double>(scaler_stages[i].src_subrect.width()) /
287 static_cast<double>(scaler_stages[i].dst_size.width()); 294 static_cast<double>(scaler_stages[i].dst_size.width());
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 kQualityNames[quality]); 637 kQualityNames[quality]);
631 638
632 std::vector<GLHelperScaling::ScalerStage> stages; 639 std::vector<GLHelperScaling::ScalerStage> stages;
633 helper_scaling_->ComputeScalerStages(kQualities[quality], 640 helper_scaling_->ComputeScalerStages(kQualities[quality],
634 gfx::Size(xsize, ysize), 641 gfx::Size(xsize, ysize),
635 gfx::Rect(0, 0, xsize, ysize), 642 gfx::Rect(0, 0, xsize, ysize),
636 gfx::Size(scaled_xsize, scaled_ysize), 643 gfx::Size(scaled_xsize, scaled_ysize),
637 flip, 644 flip,
638 false, 645 false,
639 &stages); 646 &stages);
640 ValidateScalerStages(kQualities[quality], stages, message); 647 ValidateScalerStages(kQualities[quality],
648 stages,
649 gfx::Size(scaled_xsize, scaled_ysize),
650 message);
641 651
642 WebGLId dst_texture = 652 WebGLId dst_texture =
643 helper_->CopyAndScaleTexture(src_texture, 653 helper_->CopyAndScaleTexture(src_texture,
644 gfx::Size(xsize, ysize), 654 gfx::Size(xsize, ysize),
645 gfx::Size(scaled_xsize, scaled_ysize), 655 gfx::Size(scaled_xsize, scaled_ysize),
646 flip, 656 flip,
647 kQualities[quality]); 657 kQualities[quality]);
648 658
649 SkBitmap output_pixels; 659 SkBitmap output_pixels;
650 output_pixels.allocN32Pixels(scaled_xsize, scaled_ysize); 660 output_pixels.allocN32Pixels(scaled_xsize, scaled_ysize);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 std::vector<GLHelperScaling::ScalerStage> stages; 702 std::vector<GLHelperScaling::ScalerStage> stages;
693 helper_scaling_->ComputeScalerStages(kQualities[quality], 703 helper_scaling_->ComputeScalerStages(kQualities[quality],
694 gfx::Size(xsize, ysize), 704 gfx::Size(xsize, ysize),
695 gfx::Rect(0, 0, xsize, ysize), 705 gfx::Rect(0, 0, xsize, ysize),
696 gfx::Size(dst_xsize, dst_ysize), 706 gfx::Size(dst_xsize, dst_ysize),
697 false, 707 false,
698 false, 708 false,
699 &stages); 709 &stages);
700 ValidateScalerStages(kQualities[quality], 710 ValidateScalerStages(kQualities[quality],
701 stages, 711 stages,
712 gfx::Size(dst_xsize, dst_ysize),
702 base::StringPrintf( 713 base::StringPrintf(
703 "input size: %dx%d " 714 "input size: %dx%d "
704 "output size: %dx%d " 715 "output size: %dx%d "
705 "quality: %s", 716 "quality: %s",
706 xsize, 717 xsize,
707 ysize, 718 ysize,
708 dst_xsize, 719 dst_xsize,
709 dst_ysize, 720 dst_ysize,
710 kQualityNames[quality])); 721 kQualityNames[quality]));
711 } 722 }
712 723
713 // Create a scaling pipeline and make sure that the steps 724 // Create a scaling pipeline and make sure that the steps
714 // are exactly the steps we expect. 725 // are exactly the steps we expect.
715 void CheckPipeline(content::GLHelper::ScalerQuality quality, 726 void CheckPipeline(content::GLHelper::ScalerQuality quality,
716 int xsize, 727 int xsize,
717 int ysize, 728 int ysize,
718 int dst_xsize, 729 int dst_xsize,
719 int dst_ysize, 730 int dst_ysize,
720 const std::string& description) { 731 const std::string& description) {
721 std::vector<GLHelperScaling::ScalerStage> stages; 732 std::vector<GLHelperScaling::ScalerStage> stages;
722 helper_scaling_->ComputeScalerStages(quality, 733 helper_scaling_->ComputeScalerStages(quality,
723 gfx::Size(xsize, ysize), 734 gfx::Size(xsize, ysize),
724 gfx::Rect(0, 0, xsize, ysize), 735 gfx::Rect(0, 0, xsize, ysize),
725 gfx::Size(dst_xsize, dst_ysize), 736 gfx::Size(dst_xsize, dst_ysize),
726 false, 737 false,
727 false, 738 false,
728 &stages); 739 &stages);
729 ValidateScalerStages(content::GLHelper::SCALER_QUALITY_GOOD, stages, ""); 740 ValidateScalerStages(content::GLHelper::SCALER_QUALITY_GOOD,
741 stages,
742 gfx::Size(dst_xsize, dst_ysize),
743 "");
730 EXPECT_EQ(PrintStages(stages), description); 744 EXPECT_EQ(PrintStages(stages), description);
731 } 745 }
732 746
733 // Note: Left/Right means Top/Bottom when used for Y dimension. 747 // Note: Left/Right means Top/Bottom when used for Y dimension.
734 enum Margin { 748 enum Margin {
735 MarginLeft, 749 MarginLeft,
736 MarginMiddle, 750 MarginMiddle,
737 MarginRight, 751 MarginRight,
738 MarginInvalid, 752 MarginInvalid,
739 }; 753 };
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 gfx::Size(xsize, ysize), 1292 gfx::Size(xsize, ysize),
1279 gfx::Rect(0, 0, xsize, ysize), 1293 gfx::Rect(0, 0, xsize, ysize),
1280 gfx::Size(dst_xsize, dst_ysize), 1294 gfx::Size(dst_xsize, dst_ysize),
1281 false, 1295 false,
1282 false, 1296 false,
1283 &x_ops_, 1297 &x_ops_,
1284 &y_ops_, 1298 &y_ops_,
1285 &stages); 1299 &stages);
1286 EXPECT_EQ(x_ops_.size(), 0U); 1300 EXPECT_EQ(x_ops_.size(), 0U);
1287 EXPECT_EQ(y_ops_.size(), 0U); 1301 EXPECT_EQ(y_ops_.size(), 0U);
1288 ValidateScalerStages(content::GLHelper::SCALER_QUALITY_GOOD, stages, ""); 1302 ValidateScalerStages(content::GLHelper::SCALER_QUALITY_GOOD,
1303 stages,
1304 gfx::Size(dst_xsize, dst_ysize),
1305 "");
1289 EXPECT_EQ(PrintStages(stages), description); 1306 EXPECT_EQ(PrintStages(stages), description);
1290 } 1307 }
1291 1308
1292 void CheckOptimizationsTest() { 1309 void CheckOptimizationsTest() {
1293 // Basic upscale. X and Y should be combined into one pass. 1310 // Basic upscale. X and Y should be combined into one pass.
1294 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 2000)); 1311 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 2000));
1295 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 2000)); 1312 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 2000));
1296 CheckPipeline2(1024, 768, 2000, 2000, "1024x768 -> 2000x2000 bilinear\n"); 1313 CheckPipeline2(1024, 768, 2000, 2000, "1024x768 -> 2000x2000 bilinear\n");
1297 1314
1298 // X scaled 1/2, Y upscaled, should still be one pass. 1315 // X scaled 1/2, Y upscaled, should still be one pass.
1299 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 512)); 1316 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 512));
1300 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 2000)); 1317 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 2000));
1301 CheckPipeline2(1024, 768, 512, 2000, "1024x768 -> 512x2000 bilinear\n"); 1318 CheckPipeline2(1024, 768, 512, 2000, "1024x768 -> 512x2000 bilinear\n");
1302 1319
1303 // X upscaled, Y scaled 1/2, one bilinear pass 1320 // X upscaled, Y scaled 1/2, one bilinear pass
1304 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 2000)); 1321 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 2000));
1305 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 384)); 1322 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 384));
1306 CheckPipeline2(1024, 768, 2000, 384, "1024x768 -> 2000x384 bilinear\n"); 1323 CheckPipeline2(1024, 768, 2000, 384, "1024x768 -> 2000x384 bilinear\n");
1307 1324
1308 // X scaled 1/2, Y scaled 1/2, one bilinear pass 1325 // X scaled 1/2, Y scaled 1/2, one bilinear pass
1309 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 512)); 1326 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 512));
1310 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 384)); 1327 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 384));
1311 CheckPipeline2(1024, 768, 2000, 384, "1024x768 -> 512x384 bilinear\n"); 1328 CheckPipeline2(1024, 768, 512, 384, "1024x768 -> 512x384 bilinear\n");
1312 1329
1313 // X scaled 1/2, Y scaled to 60%, one bilinear2 pass. 1330 // X scaled 1/2, Y scaled to 60%, one bilinear2 pass.
1314 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 50)); 1331 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 50));
1315 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); 1332 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120));
1316 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); 1333 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60));
1317 CheckPipeline2(100, 100, 50, 60, "100x100 -> 50x60 bilinear2 Y\n"); 1334 CheckPipeline2(100, 100, 50, 60, "100x100 -> 50x60 bilinear2 Y\n");
1318 1335
1319 // X scaled to 60%, Y scaled 1/2, one bilinear2 pass. 1336 // X scaled to 60%, Y scaled 1/2, one bilinear2 pass.
1320 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 120)); 1337 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 120));
1321 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 60)); 1338 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 60));
1322 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 50)); 1339 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 50));
1323 CheckPipeline2(100, 100, 50, 60, "100x100 -> 60x50 bilinear2 X\n"); 1340 CheckPipeline2(100, 100, 60, 50, "100x100 -> 60x50 bilinear2 X\n");
1324 1341
1325 // X scaled to 60%, Y scaled 60%, one bilinear2x2 pass. 1342 // X scaled to 60%, Y scaled 60%, one bilinear2x2 pass.
1326 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 120)); 1343 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 120));
1327 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 60)); 1344 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 60));
1328 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); 1345 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120));
1329 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); 1346 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60));
1330 CheckPipeline2(100, 100, 60, 60, "100x100 -> 60x60 bilinear2x2\n"); 1347 CheckPipeline2(100, 100, 60, 60, "100x100 -> 60x60 bilinear2x2\n");
1331 1348
1332 // X scaled to 40%, Y scaled 40%, two bilinear3 passes. 1349 // X scaled to 40%, Y scaled 40%, two bilinear3 passes.
1333 x_ops_.push_back(GLHelperScaling::ScaleOp(3, true, 40)); 1350 x_ops_.push_back(GLHelperScaling::ScaleOp(3, true, 40));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 128)); 1425 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 128));
1409 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 64)); 1426 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 64));
1410 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 32)); 1427 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 32));
1411 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 16)); 1428 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 16));
1412 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 8)); 1429 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 8));
1413 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 4)); 1430 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 4));
1414 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 2)); 1431 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 2));
1415 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 1)); 1432 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 1));
1416 CheckPipeline2(100, 1433 CheckPipeline2(100,
1417 100, 1434 100,
1418 30, 1435 1,
1419 30, 1436 1,
1420 "100x100 -> 100x32 bilinear4 Y\n" 1437 "100x100 -> 100x32 bilinear4 Y\n"
1421 "100x32 -> 100x4 bilinear4 Y\n" 1438 "100x32 -> 100x4 bilinear4 Y\n"
1422 "100x4 -> 64x1 bilinear2x2\n" 1439 "100x4 -> 64x1 bilinear2x2\n"
1423 "64x1 -> 8x1 bilinear4 X\n" 1440 "64x1 -> 8x1 bilinear4 X\n"
1424 "8x1 -> 1x1 bilinear4 X\n"); 1441 "8x1 -> 1x1 bilinear4 X\n");
1425 } 1442 }
1426 1443
1427 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_; 1444 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context_;
1428 gpu::ContextSupport* context_support_; 1445 gpu::ContextSupport* context_support_;
1429 scoped_ptr<content::GLHelper> helper_; 1446 scoped_ptr<content::GLHelper> helper_;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 CommandLine::Init(argc, argv); 1668 CommandLine::Init(argc, argv);
1652 base::TestSuite* suite = new content::ContentTestSuite(argc, argv); 1669 base::TestSuite* suite = new content::ContentTestSuite(argc, argv);
1653 #if defined(OS_MACOSX) 1670 #if defined(OS_MACOSX)
1654 base::mac::ScopedNSAutoreleasePool pool; 1671 base::mac::ScopedNSAutoreleasePool pool;
1655 #endif 1672 #endif
1656 1673
1657 content::UnitTestTestSuite runner(suite); 1674 content::UnitTestTestSuite runner(suite);
1658 base::MessageLoop message_loop; 1675 base::MessageLoop message_loop;
1659 return runner.Run(); 1676 return runner.Run();
1660 } 1677 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698