| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/memory/ref_counted_memory.h" | 23 #include "base/memory/ref_counted_memory.h" |
| 24 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
| 25 #include "base/run_loop.h" | 25 #include "base/run_loop.h" |
| 26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
| 27 #include "base/synchronization/waitable_event.h" | 27 #include "base/synchronization/waitable_event.h" |
| 28 #include "base/test/launcher/unit_test_launcher.h" | 28 #include "base/test/launcher/unit_test_launcher.h" |
| 29 #include "base/test/test_suite.h" | 29 #include "base/test/test_suite.h" |
| 30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
| 31 #include "base/trace_event/trace_event.h" | 31 #include "base/trace_event/trace_event.h" |
| 32 #include "content/common/gpu/client/gl_helper.h" | 32 #include "content/browser/compositor/gl_helper.h" |
| 33 #include "content/common/gpu/client/gl_helper_readback_support.h" | 33 #include "content/browser/compositor/gl_helper_readback_support.h" |
| 34 #include "content/common/gpu/client/gl_helper_scaling.h" | 34 #include "content/browser/compositor/gl_helper_scaling.h" |
| 35 #include "gpu/command_buffer/client/gl_in_process_context.h" | 35 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 36 #include "gpu/command_buffer/client/gles2_implementation.h" | 36 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 37 #include "media/base/video_frame.h" | 37 #include "media/base/video_frame.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 39 #include "third_party/skia/include/core/SkBitmap.h" | 39 #include "third_party/skia/include/core/SkBitmap.h" |
| 40 #include "third_party/skia/include/core/SkTypes.h" | 40 #include "third_party/skia/include/core/SkTypes.h" |
| 41 #include "ui/gl/gl_implementation.h" | 41 #include "ui/gl/gl_implementation.h" |
| 42 | 42 |
| 43 namespace content { | 43 namespace content { |
| 44 | 44 |
| 45 content::GLHelper::ScalerQuality kQualities[] = { | 45 content::GLHelper::ScalerQuality kQualities[] = { |
| 46 content::GLHelper::SCALER_QUALITY_BEST, | 46 content::GLHelper::SCALER_QUALITY_BEST, |
| 47 content::GLHelper::SCALER_QUALITY_GOOD, | 47 content::GLHelper::SCALER_QUALITY_GOOD, |
| 48 content::GLHelper::SCALER_QUALITY_FAST, }; | 48 content::GLHelper::SCALER_QUALITY_FAST, |
| 49 }; |
| 49 | 50 |
| 50 const char* kQualityNames[] = {"best", "good", "fast", }; | 51 const char* kQualityNames[] = { |
| 52 "best", "good", "fast", |
| 53 }; |
| 51 | 54 |
| 52 class GLHelperTest : public testing::Test { | 55 class GLHelperTest : public testing::Test { |
| 53 protected: | 56 protected: |
| 54 void SetUp() override { | 57 void SetUp() override { |
| 55 gpu::gles2::ContextCreationAttribHelper attributes; | 58 gpu::gles2::ContextCreationAttribHelper attributes; |
| 56 attributes.alpha_size = 8; | 59 attributes.alpha_size = 8; |
| 57 attributes.depth_size = 24; | 60 attributes.depth_size = 24; |
| 58 attributes.red_size = 8; | 61 attributes.red_size = 8; |
| 59 attributes.green_size = 8; | 62 attributes.green_size = 8; |
| 60 attributes.blue_size = 8; | 63 attributes.blue_size = 8; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 112 } |
| 110 } | 113 } |
| 111 | 114 |
| 112 // End tracing, return tracing data in a simple map | 115 // End tracing, return tracing data in a simple map |
| 113 // of event name->counts. | 116 // of event name->counts. |
| 114 void EndTracing(std::map<std::string, int>* event_counts) { | 117 void EndTracing(std::map<std::string, int>* event_counts) { |
| 115 std::string json_data = "["; | 118 std::string json_data = "["; |
| 116 base::trace_event::TraceLog::GetInstance()->SetDisabled(); | 119 base::trace_event::TraceLog::GetInstance()->SetDisabled(); |
| 117 base::RunLoop run_loop; | 120 base::RunLoop run_loop; |
| 118 base::trace_event::TraceLog::GetInstance()->Flush( | 121 base::trace_event::TraceLog::GetInstance()->Flush( |
| 119 base::Bind(&GLHelperTest::TraceDataCB, | 122 base::Bind(&GLHelperTest::TraceDataCB, run_loop.QuitClosure(), |
| 120 run_loop.QuitClosure(), | |
| 121 base::Unretained(&json_data))); | 123 base::Unretained(&json_data))); |
| 122 run_loop.Run(); | 124 run_loop.Run(); |
| 123 json_data.append("]"); | 125 json_data.append("]"); |
| 124 | 126 |
| 125 std::string error_msg; | 127 std::string error_msg; |
| 126 scoped_ptr<base::Value> trace_data = | 128 scoped_ptr<base::Value> trace_data = |
| 127 base::JSONReader::ReadAndReturnError(json_data, 0, NULL, &error_msg); | 129 base::JSONReader::ReadAndReturnError(json_data, 0, NULL, &error_msg); |
| 128 CHECK(trace_data) | 130 CHECK(trace_data) << "JSON parsing failed (" << error_msg |
| 129 << "JSON parsing failed (" << error_msg << ") JSON data:" << std::endl | 131 << ") JSON data:" << std::endl |
| 130 << json_data; | 132 << json_data; |
| 131 | 133 |
| 132 base::ListValue* list; | 134 base::ListValue* list; |
| 133 CHECK(trace_data->GetAsList(&list)); | 135 CHECK(trace_data->GetAsList(&list)); |
| 134 for (size_t i = 0; i < list->GetSize(); i++) { | 136 for (size_t i = 0; i < list->GetSize(); i++) { |
| 135 base::Value* item = NULL; | 137 base::Value* item = NULL; |
| 136 if (list->Get(i, &item)) { | 138 if (list->Get(i, &item)) { |
| 137 base::DictionaryValue* dict; | 139 base::DictionaryValue* dict; |
| 138 CHECK(item->GetAsDictionary(&dict)); | 140 CHECK(item->GetAsDictionary(&dict)); |
| 139 std::string name; | 141 std::string name; |
| 140 CHECK(dict->GetString("name", &name)); | 142 CHECK(dict->GetString("name", &name)); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 211 } |
| 210 LOG(ERROR) << formatted; | 212 LOG(ERROR) << formatted; |
| 211 } | 213 } |
| 212 } | 214 } |
| 213 | 215 |
| 214 // Print out the individual steps of a scaler pipeline. | 216 // Print out the individual steps of a scaler pipeline. |
| 215 std::string PrintStages( | 217 std::string PrintStages( |
| 216 const std::vector<GLHelperScaling::ScalerStage>& scaler_stages) { | 218 const std::vector<GLHelperScaling::ScalerStage>& scaler_stages) { |
| 217 std::string ret; | 219 std::string ret; |
| 218 for (size_t i = 0; i < scaler_stages.size(); i++) { | 220 for (size_t i = 0; i < scaler_stages.size(); i++) { |
| 219 ret.append(base::StringPrintf("%dx%d -> %dx%d ", | 221 ret.append(base::StringPrintf( |
| 220 scaler_stages[i].src_size.width(), | 222 "%dx%d -> %dx%d ", scaler_stages[i].src_size.width(), |
| 221 scaler_stages[i].src_size.height(), | 223 scaler_stages[i].src_size.height(), scaler_stages[i].dst_size.width(), |
| 222 scaler_stages[i].dst_size.width(), | 224 scaler_stages[i].dst_size.height())); |
| 223 scaler_stages[i].dst_size.height())); | |
| 224 bool xy_matters = false; | 225 bool xy_matters = false; |
| 225 switch (scaler_stages[i].shader) { | 226 switch (scaler_stages[i].shader) { |
| 226 case GLHelperScaling::SHADER_BILINEAR: | 227 case GLHelperScaling::SHADER_BILINEAR: |
| 227 ret.append("bilinear"); | 228 ret.append("bilinear"); |
| 228 break; | 229 break; |
| 229 case GLHelperScaling::SHADER_BILINEAR2: | 230 case GLHelperScaling::SHADER_BILINEAR2: |
| 230 ret.append("bilinear2"); | 231 ret.append("bilinear2"); |
| 231 xy_matters = true; | 232 xy_matters = true; |
| 232 break; | 233 break; |
| 233 case GLHelperScaling::SHADER_BILINEAR3: | 234 case GLHelperScaling::SHADER_BILINEAR3: |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 EXPECT_EQ(y_scale, 2.0); | 389 EXPECT_EQ(y_scale, 2.0); |
| 389 } | 390 } |
| 390 break; | 391 break; |
| 391 } | 392 } |
| 392 | 393 |
| 393 if (!scaler_stages[i].scale_x) { | 394 if (!scaler_stages[i].scale_x) { |
| 394 std::swap(x_samples, y_samples); | 395 std::swap(x_samples, y_samples); |
| 395 } | 396 } |
| 396 | 397 |
| 397 if (x_samples) { | 398 if (x_samples) { |
| 398 EXPECT_TRUE(CheckScale(x_scale, x_samples, scaled_x)) | 399 EXPECT_TRUE(CheckScale(x_scale, x_samples, scaled_x)) << "x_scale = " |
| 399 << "x_scale = " << x_scale; | 400 << x_scale; |
| 400 } | 401 } |
| 401 if (y_samples) { | 402 if (y_samples) { |
| 402 EXPECT_TRUE(CheckScale(y_scale, y_samples, scaled_y)) | 403 EXPECT_TRUE(CheckScale(y_scale, y_samples, scaled_y)) << "y_scale = " |
| 403 << "y_scale = " << y_scale; | 404 << y_scale; |
| 404 } | 405 } |
| 405 | 406 |
| 406 if (x_scale != 1.0) { | 407 if (x_scale != 1.0) { |
| 407 scaled_x = true; | 408 scaled_x = true; |
| 408 } | 409 } |
| 409 if (y_scale != 1.0) { | 410 if (y_scale != 1.0) { |
| 410 scaled_y = true; | 411 scaled_y = true; |
| 411 } | 412 } |
| 412 } | 413 } |
| 413 | 414 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 CHECK_EQ(input->colorType(), kRGBA_8888_SkColorType); | 504 CHECK_EQ(input->colorType(), kRGBA_8888_SkColorType); |
| 504 | 505 |
| 505 for (int dst_y = 0; dst_y < output->height(); dst_y++) { | 506 for (int dst_y = 0; dst_y < output->height(); dst_y++) { |
| 506 for (int dst_x = 0; dst_x < output->width(); dst_x++) { | 507 for (int dst_x = 0; dst_x < output->width(); dst_x++) { |
| 507 float c0 = ChannelAsFloat(input, dst_x, dst_y, 0); | 508 float c0 = ChannelAsFloat(input, dst_x, dst_y, 0); |
| 508 float c1 = ChannelAsFloat(input, dst_x, dst_y, 1); | 509 float c1 = ChannelAsFloat(input, dst_x, dst_y, 1); |
| 509 float c2 = ChannelAsFloat(input, dst_x, dst_y, 2); | 510 float c2 = ChannelAsFloat(input, dst_x, dst_y, 2); |
| 510 float value = c0 * kRGBtoGrayscaleColorWeights[0] + | 511 float value = c0 * kRGBtoGrayscaleColorWeights[0] + |
| 511 c1 * kRGBtoGrayscaleColorWeights[1] + | 512 c1 * kRGBtoGrayscaleColorWeights[1] + |
| 512 c2 * kRGBtoGrayscaleColorWeights[2]; | 513 c2 * kRGBtoGrayscaleColorWeights[2]; |
| 513 SetChannel( | 514 SetChannel(output, dst_x, dst_y, 0, |
| 514 output, dst_x, dst_y, 0, static_cast<int>(value * 255.0f + 0.5f)); | 515 static_cast<int>(value * 255.0f + 0.5f)); |
| 515 } | 516 } |
| 516 } | 517 } |
| 517 } | 518 } |
| 518 | 519 |
| 519 // Very slow bicubic / bilinear scaler for reference. | 520 // Very slow bicubic / bilinear scaler for reference. |
| 520 void ScaleSlow(SkBitmap* input, | 521 void ScaleSlow(SkBitmap* input, |
| 521 SkBitmap* output, | 522 SkBitmap* output, |
| 522 content::GLHelper::ScalerQuality quality) { | 523 content::GLHelper::ScalerQuality quality) { |
| 523 float xscale = static_cast<float>(input->width()) / output->width(); | 524 float xscale = static_cast<float>(input->width()) / output->width(); |
| 524 float yscale = static_cast<float>(input->height()) / output->height(); | 525 float yscale = static_cast<float>(input->height()) / output->height(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 int xmag = 1 << xshift; | 566 int xmag = 1 << xshift; |
| 566 int ymag = 1 << yshift; | 567 int ymag = 1 << yshift; |
| 567 if (xmag == 4 && output->width() * 3 >= input->width()) { | 568 if (xmag == 4 && output->width() * 3 >= input->width()) { |
| 568 xmag = 3; | 569 xmag = 3; |
| 569 } | 570 } |
| 570 if (ymag == 4 && output->height() * 3 >= input->height()) { | 571 if (ymag == 4 && output->height() * 3 >= input->height()) { |
| 571 ymag = 3; | 572 ymag = 3; |
| 572 } | 573 } |
| 573 for (int x = 0; x < xmag; x++) { | 574 for (int x = 0; x < xmag; x++) { |
| 574 for (int y = 0; y < ymag; y++) { | 575 for (int y = 0; y < ymag; y++) { |
| 575 value += Bilinear(input, | 576 value += Bilinear( |
| 576 (dst_x * xmag + x + 0.5) * xscale / xmag, | 577 input, (dst_x * xmag + x + 0.5) * xscale / xmag, |
| 577 (dst_y * ymag + y + 0.5) * yscale / ymag, | 578 (dst_y * ymag + y + 0.5) * yscale / ymag, channel); |
| 578 channel); | |
| 579 sum += 1.0; | 579 sum += 1.0; |
| 580 } | 580 } |
| 581 } | 581 } |
| 582 break; | 582 break; |
| 583 } | 583 } |
| 584 | 584 |
| 585 case content::GLHelper::SCALER_QUALITY_FAST: | 585 case content::GLHelper::SCALER_QUALITY_FAST: |
| 586 value = Bilinear(input, dst_x_in_src, dst_y_in_src, channel); | 586 value = Bilinear(input, dst_x_in_src, dst_y_in_src, channel); |
| 587 sum = 1.0; | 587 sum = 1.0; |
| 588 } | 588 } |
| 589 value /= sum; | 589 value /= sum; |
| 590 SetChannel(output, | 590 SetChannel(output, dst_x, dst_y, channel, |
| 591 dst_x, | |
| 592 dst_y, | |
| 593 channel, | |
| 594 static_cast<int>(value * 255.0f + 0.5f)); | 591 static_cast<int>(value * 255.0f + 0.5f)); |
| 595 } | 592 } |
| 596 } | 593 } |
| 597 } | 594 } |
| 598 } | 595 } |
| 599 | 596 |
| 600 void FlipSKBitmap(SkBitmap* bitmap) { | 597 void FlipSKBitmap(SkBitmap* bitmap) { |
| 601 int bpp = bitmap->bytesPerPixel(); | 598 int bpp = bitmap->bytesPerPixel(); |
| 602 DCHECK(bpp == 4 || bpp == 1); | 599 DCHECK(bpp == 4 || bpp == 1); |
| 603 int top_line = 0; | 600 int top_line = 0; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 | 672 |
| 676 ScaleSlowRecursive(input, &tmp, quality); | 673 ScaleSlowRecursive(input, &tmp, quality); |
| 677 ScaleSlowRecursive(&tmp, output, quality); | 674 ScaleSlowRecursive(&tmp, output, quality); |
| 678 } | 675 } |
| 679 | 676 |
| 680 // Creates an RGBA SkBitmap | 677 // Creates an RGBA SkBitmap |
| 681 scoped_ptr<SkBitmap> CreateTestBitmap(int width, | 678 scoped_ptr<SkBitmap> CreateTestBitmap(int width, |
| 682 int height, | 679 int height, |
| 683 int test_pattern) { | 680 int test_pattern) { |
| 684 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 681 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
| 685 bitmap->allocPixels(SkImageInfo::Make( | 682 bitmap->allocPixels(SkImageInfo::Make(width, height, kRGBA_8888_SkColorType, |
| 686 width, height, kRGBA_8888_SkColorType, kPremul_SkAlphaType)); | 683 kPremul_SkAlphaType)); |
| 687 | 684 |
| 688 for (int x = 0; x < width; ++x) { | 685 for (int x = 0; x < width; ++x) { |
| 689 for (int y = 0; y < height; ++y) { | 686 for (int y = 0; y < height; ++y) { |
| 690 switch (test_pattern) { | 687 switch (test_pattern) { |
| 691 case 0: // Smooth test pattern | 688 case 0: // Smooth test pattern |
| 692 SetChannel(bitmap.get(), x, y, 0, x * 10); | 689 SetChannel(bitmap.get(), x, y, 0, x * 10); |
| 693 SetChannel(bitmap.get(), x, y, 0, y == 0 ? x * 50 : x * 10); | 690 SetChannel(bitmap.get(), x, y, 0, y == 0 ? x * 50 : x * 10); |
| 694 SetChannel(bitmap.get(), x, y, 1, y * 10); | 691 SetChannel(bitmap.get(), x, y, 1, y * 10); |
| 695 SetChannel(bitmap.get(), x, y, 2, (x + y) * 10); | 692 SetChannel(bitmap.get(), x, y, 2, (x + y) * 10); |
| 696 SetChannel(bitmap.get(), x, y, 3, 255); | 693 SetChannel(bitmap.get(), x, y, 3, 255); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 size_t quality_index) { | 735 size_t quality_index) { |
| 739 DCHECK(out_color_type == kAlpha_8_SkColorType || | 736 DCHECK(out_color_type == kAlpha_8_SkColorType || |
| 740 out_color_type == kRGBA_8888_SkColorType || | 737 out_color_type == kRGBA_8888_SkColorType || |
| 741 out_color_type == kBGRA_8888_SkColorType); | 738 out_color_type == kBGRA_8888_SkColorType); |
| 742 GLuint src_texture; | 739 GLuint src_texture; |
| 743 gl_->GenTextures(1, &src_texture); | 740 gl_->GenTextures(1, &src_texture); |
| 744 GLuint framebuffer; | 741 GLuint framebuffer; |
| 745 gl_->GenFramebuffers(1, &framebuffer); | 742 gl_->GenFramebuffers(1, &framebuffer); |
| 746 scoped_ptr<SkBitmap> input_pixels = | 743 scoped_ptr<SkBitmap> input_pixels = |
| 747 CreateTestBitmap(xsize, ysize, test_pattern); | 744 CreateTestBitmap(xsize, ysize, test_pattern); |
| 748 BindTextureAndFrameBuffer( | 745 BindTextureAndFrameBuffer(src_texture, framebuffer, input_pixels.get(), |
| 749 src_texture, framebuffer, input_pixels.get(), xsize, ysize); | 746 xsize, ysize); |
| 750 | 747 |
| 751 std::string message = base::StringPrintf( | 748 std::string message = base::StringPrintf( |
| 752 "input size: %dx%d " | 749 "input size: %dx%d " |
| 753 "output size: %dx%d " | 750 "output size: %dx%d " |
| 754 "pattern: %d , quality: %s, " | 751 "pattern: %d , quality: %s, " |
| 755 "out_color_type: %d", | 752 "out_color_type: %d", |
| 756 xsize, | 753 xsize, ysize, scaled_xsize, scaled_ysize, test_pattern, |
| 757 ysize, | 754 kQualityNames[quality_index], out_color_type); |
| 758 scaled_xsize, | |
| 759 scaled_ysize, | |
| 760 test_pattern, | |
| 761 kQualityNames[quality_index], | |
| 762 out_color_type); | |
| 763 | 755 |
| 764 // Transform the bitmap using GLHelper::CropScaleReadbackAndCleanTexture. | 756 // Transform the bitmap using GLHelper::CropScaleReadbackAndCleanTexture. |
| 765 SkBitmap output_pixels; | 757 SkBitmap output_pixels; |
| 766 output_pixels.allocPixels(SkImageInfo::Make( | 758 output_pixels.allocPixels(SkImageInfo::Make( |
| 767 scaled_xsize, scaled_ysize, out_color_type, kPremul_SkAlphaType)); | 759 scaled_xsize, scaled_ysize, out_color_type, kPremul_SkAlphaType)); |
| 768 base::RunLoop run_loop; | 760 base::RunLoop run_loop; |
| 769 gfx::Size encoded_texture_size; | 761 gfx::Size encoded_texture_size; |
| 770 helper_->CropScaleReadbackAndCleanTexture( | 762 helper_->CropScaleReadbackAndCleanTexture( |
| 771 src_texture, | 763 src_texture, gfx::Size(xsize, ysize), gfx::Rect(xsize, ysize), |
| 772 gfx::Size(xsize, ysize), | |
| 773 gfx::Rect(xsize, ysize), | |
| 774 gfx::Size(scaled_xsize, scaled_ysize), | 764 gfx::Size(scaled_xsize, scaled_ysize), |
| 775 static_cast<unsigned char*>(output_pixels.getPixels()), | 765 static_cast<unsigned char*>(output_pixels.getPixels()), out_color_type, |
| 776 out_color_type, | |
| 777 base::Bind(&callcallback, run_loop.QuitClosure()), | 766 base::Bind(&callcallback, run_loop.QuitClosure()), |
| 778 kQualities[quality_index]); | 767 kQualities[quality_index]); |
| 779 run_loop.Run(); | 768 run_loop.Run(); |
| 780 // CropScaleReadbackAndCleanTexture flips the pixels. Flip them back. | 769 // CropScaleReadbackAndCleanTexture flips the pixels. Flip them back. |
| 781 FlipSKBitmap(&output_pixels); | 770 FlipSKBitmap(&output_pixels); |
| 782 | 771 |
| 783 // If the bitmap shouldn't have changed - compare against input. | 772 // If the bitmap shouldn't have changed - compare against input. |
| 784 if (xsize == scaled_xsize && ysize == scaled_ysize && | 773 if (xsize == scaled_xsize && ysize == scaled_ysize && |
| 785 out_color_type != kAlpha_8_SkColorType) { | 774 out_color_type != kAlpha_8_SkColorType) { |
| 786 const std::vector<GLHelperScaling::ScalerStage> dummy_stages; | 775 const std::vector<GLHelperScaling::ScalerStage> dummy_stages; |
| 787 Compare(input_pixels.get(), | 776 Compare(input_pixels.get(), &output_pixels, 0, NULL, dummy_stages, |
| 788 &output_pixels, | |
| 789 0, | |
| 790 NULL, | |
| 791 dummy_stages, | |
| 792 message + " comparing against input"); | 777 message + " comparing against input"); |
| 793 return; | 778 return; |
| 794 } | 779 } |
| 795 | 780 |
| 796 // Now transform the bitmap using the reference implementation. | 781 // Now transform the bitmap using the reference implementation. |
| 797 SkBitmap scaled_pixels; | 782 SkBitmap scaled_pixels; |
| 798 scaled_pixels.allocPixels(SkImageInfo::Make(scaled_xsize, | 783 scaled_pixels.allocPixels(SkImageInfo::Make(scaled_xsize, scaled_ysize, |
| 799 scaled_ysize, | |
| 800 kRGBA_8888_SkColorType, | 784 kRGBA_8888_SkColorType, |
| 801 kPremul_SkAlphaType)); | 785 kPremul_SkAlphaType)); |
| 802 SkBitmap truth_pixels; | 786 SkBitmap truth_pixels; |
| 803 // Step 1: Scale | 787 // Step 1: Scale |
| 804 ScaleSlowRecursive( | 788 ScaleSlowRecursive(input_pixels.get(), &scaled_pixels, |
| 805 input_pixels.get(), &scaled_pixels, kQualities[quality_index]); | 789 kQualities[quality_index]); |
| 806 // Step 2: Encode to grayscale if needed. | 790 // Step 2: Encode to grayscale if needed. |
| 807 if (out_color_type == kAlpha_8_SkColorType) { | 791 if (out_color_type == kAlpha_8_SkColorType) { |
| 808 truth_pixels.allocPixels(SkImageInfo::Make( | 792 truth_pixels.allocPixels(SkImageInfo::Make( |
| 809 scaled_xsize, scaled_ysize, out_color_type, kPremul_SkAlphaType)); | 793 scaled_xsize, scaled_ysize, out_color_type, kPremul_SkAlphaType)); |
| 810 EncodeToGrayscaleSlow(&scaled_pixels, &truth_pixels); | 794 EncodeToGrayscaleSlow(&scaled_pixels, &truth_pixels); |
| 811 } else { | 795 } else { |
| 812 truth_pixels = scaled_pixels; | 796 truth_pixels = scaled_pixels; |
| 813 } | 797 } |
| 814 | 798 |
| 815 // Now compare the results. | 799 // Now compare the results. |
| 816 SkAutoLockPixels lock_input(truth_pixels); | 800 SkAutoLockPixels lock_input(truth_pixels); |
| 817 const std::vector<GLHelperScaling::ScalerStage> dummy_stages; | 801 const std::vector<GLHelperScaling::ScalerStage> dummy_stages; |
| 818 Compare(&truth_pixels, | 802 Compare(&truth_pixels, &output_pixels, 2, input_pixels.get(), dummy_stages, |
| 819 &output_pixels, | |
| 820 2, | |
| 821 input_pixels.get(), | |
| 822 dummy_stages, | |
| 823 message + " comparing against transformed/scaled"); | 803 message + " comparing against transformed/scaled"); |
| 824 | 804 |
| 825 gl_->DeleteTextures(1, &src_texture); | 805 gl_->DeleteTextures(1, &src_texture); |
| 826 gl_->DeleteFramebuffers(1, &framebuffer); | 806 gl_->DeleteFramebuffers(1, &framebuffer); |
| 827 } | 807 } |
| 828 | 808 |
| 829 // Scaling test: Create a test image, scale it using GLHelperScaling | 809 // Scaling test: Create a test image, scale it using GLHelperScaling |
| 830 // and a reference implementation and compare the results. | 810 // and a reference implementation and compare the results. |
| 831 void TestScale(int xsize, | 811 void TestScale(int xsize, |
| 832 int ysize, | 812 int ysize, |
| 833 int scaled_xsize, | 813 int scaled_xsize, |
| 834 int scaled_ysize, | 814 int scaled_ysize, |
| 835 int test_pattern, | 815 int test_pattern, |
| 836 size_t quality_index, | 816 size_t quality_index, |
| 837 bool flip) { | 817 bool flip) { |
| 838 GLuint src_texture; | 818 GLuint src_texture; |
| 839 gl_->GenTextures(1, &src_texture); | 819 gl_->GenTextures(1, &src_texture); |
| 840 GLuint framebuffer; | 820 GLuint framebuffer; |
| 841 gl_->GenFramebuffers(1, &framebuffer); | 821 gl_->GenFramebuffers(1, &framebuffer); |
| 842 scoped_ptr<SkBitmap> input_pixels = | 822 scoped_ptr<SkBitmap> input_pixels = |
| 843 CreateTestBitmap(xsize, ysize, test_pattern); | 823 CreateTestBitmap(xsize, ysize, test_pattern); |
| 844 BindTextureAndFrameBuffer( | 824 BindTextureAndFrameBuffer(src_texture, framebuffer, input_pixels.get(), |
| 845 src_texture, framebuffer, input_pixels.get(), xsize, ysize); | 825 xsize, ysize); |
| 846 | 826 |
| 847 std::string message = base::StringPrintf( | 827 std::string message = base::StringPrintf( |
| 848 "input size: %dx%d " | 828 "input size: %dx%d " |
| 849 "output size: %dx%d " | 829 "output size: %dx%d " |
| 850 "pattern: %d quality: %s", | 830 "pattern: %d quality: %s", |
| 851 xsize, | 831 xsize, ysize, scaled_xsize, scaled_ysize, test_pattern, |
| 852 ysize, | |
| 853 scaled_xsize, | |
| 854 scaled_ysize, | |
| 855 test_pattern, | |
| 856 kQualityNames[quality_index]); | 832 kQualityNames[quality_index]); |
| 857 | 833 |
| 858 std::vector<GLHelperScaling::ScalerStage> stages; | 834 std::vector<GLHelperScaling::ScalerStage> stages; |
| 859 helper_scaling_->ComputeScalerStages(kQualities[quality_index], | 835 helper_scaling_->ComputeScalerStages(kQualities[quality_index], |
| 860 gfx::Size(xsize, ysize), | 836 gfx::Size(xsize, ysize), |
| 861 gfx::Rect(0, 0, xsize, ysize), | 837 gfx::Rect(0, 0, xsize, ysize), |
| 862 gfx::Size(scaled_xsize, scaled_ysize), | 838 gfx::Size(scaled_xsize, scaled_ysize), |
| 863 flip, | 839 flip, |
| 864 false, | 840 false, |
| 865 &stages); | 841 &stages); |
| 866 ValidateScalerStages(kQualities[quality_index], | 842 ValidateScalerStages(kQualities[quality_index], |
| 867 stages, | 843 stages, |
| 868 gfx::Size(scaled_xsize, scaled_ysize), | 844 gfx::Size(scaled_xsize, scaled_ysize), |
| 869 message); | 845 message); |
| 870 | 846 |
| 871 GLuint dst_texture = helper_->CopyAndScaleTexture( | 847 GLuint dst_texture = helper_->CopyAndScaleTexture( |
| 872 src_texture, gfx::Size(xsize, ysize), | 848 src_texture, gfx::Size(xsize, ysize), |
| 873 gfx::Size(scaled_xsize, scaled_ysize), flip, kQualities[quality_index]); | 849 gfx::Size(scaled_xsize, scaled_ysize), flip, kQualities[quality_index]); |
| 874 | 850 |
| 875 SkBitmap output_pixels; | 851 SkBitmap output_pixels; |
| 876 output_pixels.allocPixels(SkImageInfo::Make(scaled_xsize, | 852 output_pixels.allocPixels(SkImageInfo::Make(scaled_xsize, scaled_ysize, |
| 877 scaled_ysize, | |
| 878 kRGBA_8888_SkColorType, | 853 kRGBA_8888_SkColorType, |
| 879 kPremul_SkAlphaType)); | 854 kPremul_SkAlphaType)); |
| 880 | 855 |
| 881 helper_->ReadbackTextureSync( | 856 helper_->ReadbackTextureSync( |
| 882 dst_texture, | 857 dst_texture, gfx::Rect(0, 0, scaled_xsize, scaled_ysize), |
| 883 gfx::Rect(0, 0, scaled_xsize, scaled_ysize), | |
| 884 static_cast<unsigned char*>(output_pixels.getPixels()), | 858 static_cast<unsigned char*>(output_pixels.getPixels()), |
| 885 kRGBA_8888_SkColorType); | 859 kRGBA_8888_SkColorType); |
| 886 if (flip) { | 860 if (flip) { |
| 887 // Flip the pixels back. | 861 // Flip the pixels back. |
| 888 FlipSKBitmap(&output_pixels); | 862 FlipSKBitmap(&output_pixels); |
| 889 } | 863 } |
| 890 | 864 |
| 891 // If the bitmap shouldn't have changed - compare against input. | 865 // If the bitmap shouldn't have changed - compare against input. |
| 892 if (xsize == scaled_xsize && ysize == scaled_ysize) { | 866 if (xsize == scaled_xsize && ysize == scaled_ysize) { |
| 893 Compare(input_pixels.get(), | 867 Compare(input_pixels.get(), &output_pixels, 0, NULL, stages, |
| 894 &output_pixels, | |
| 895 0, | |
| 896 NULL, | |
| 897 stages, | |
| 898 message + " comparing against input"); | 868 message + " comparing against input"); |
| 899 return; | 869 return; |
| 900 } | 870 } |
| 901 | 871 |
| 902 // Now scale the bitmap using the reference implementation. | 872 // Now scale the bitmap using the reference implementation. |
| 903 SkBitmap truth_pixels; | 873 SkBitmap truth_pixels; |
| 904 truth_pixels.allocPixels(SkImageInfo::Make(scaled_xsize, | 874 truth_pixels.allocPixels(SkImageInfo::Make(scaled_xsize, scaled_ysize, |
| 905 scaled_ysize, | |
| 906 kRGBA_8888_SkColorType, | 875 kRGBA_8888_SkColorType, |
| 907 kPremul_SkAlphaType)); | 876 kPremul_SkAlphaType)); |
| 908 ScaleSlowRecursive( | 877 ScaleSlowRecursive(input_pixels.get(), &truth_pixels, |
| 909 input_pixels.get(), &truth_pixels, kQualities[quality_index]); | 878 kQualities[quality_index]); |
| 910 Compare(&truth_pixels, | 879 Compare(&truth_pixels, &output_pixels, 2, input_pixels.get(), stages, |
| 911 &output_pixels, | |
| 912 2, | |
| 913 input_pixels.get(), | |
| 914 stages, | |
| 915 message + " comparing against scaled"); | 880 message + " comparing against scaled"); |
| 916 | 881 |
| 917 gl_->DeleteTextures(1, &src_texture); | 882 gl_->DeleteTextures(1, &src_texture); |
| 918 gl_->DeleteTextures(1, &dst_texture); | 883 gl_->DeleteTextures(1, &dst_texture); |
| 919 gl_->DeleteFramebuffers(1, &framebuffer); | 884 gl_->DeleteFramebuffers(1, &framebuffer); |
| 920 } | 885 } |
| 921 | 886 |
| 922 // Create a scaling pipeline and check that it is made up of | 887 // Create a scaling pipeline and check that it is made up of |
| 923 // valid scaling operations. | 888 // valid scaling operations. |
| 924 void TestScalerPipeline(size_t quality, | 889 void TestScalerPipeline(size_t quality, |
| 925 int xsize, | 890 int xsize, |
| 926 int ysize, | 891 int ysize, |
| 927 int dst_xsize, | 892 int dst_xsize, |
| 928 int dst_ysize) { | 893 int dst_ysize) { |
| 929 std::vector<GLHelperScaling::ScalerStage> stages; | 894 std::vector<GLHelperScaling::ScalerStage> stages; |
| 930 helper_scaling_->ComputeScalerStages(kQualities[quality], | 895 helper_scaling_->ComputeScalerStages( |
| 931 gfx::Size(xsize, ysize), | 896 kQualities[quality], gfx::Size(xsize, ysize), |
| 932 gfx::Rect(0, 0, xsize, ysize), | 897 gfx::Rect(0, 0, xsize, ysize), gfx::Size(dst_xsize, dst_ysize), false, |
| 933 gfx::Size(dst_xsize, dst_ysize), | 898 false, &stages); |
| 934 false, | 899 ValidateScalerStages(kQualities[quality], stages, |
| 935 false, | |
| 936 &stages); | |
| 937 ValidateScalerStages(kQualities[quality], | |
| 938 stages, | |
| 939 gfx::Size(dst_xsize, dst_ysize), | 900 gfx::Size(dst_xsize, dst_ysize), |
| 940 base::StringPrintf( | 901 base::StringPrintf("input size: %dx%d " |
| 941 "input size: %dx%d " | 902 "output size: %dx%d " |
| 942 "output size: %dx%d " | 903 "quality: %s", |
| 943 "quality: %s", | 904 xsize, ysize, dst_xsize, dst_ysize, |
| 944 xsize, | 905 kQualityNames[quality])); |
| 945 ysize, | |
| 946 dst_xsize, | |
| 947 dst_ysize, | |
| 948 kQualityNames[quality])); | |
| 949 } | 906 } |
| 950 | 907 |
| 951 // Create a scaling pipeline and make sure that the steps | 908 // Create a scaling pipeline and make sure that the steps |
| 952 // are exactly the steps we expect. | 909 // are exactly the steps we expect. |
| 953 void CheckPipeline(content::GLHelper::ScalerQuality quality, | 910 void CheckPipeline(content::GLHelper::ScalerQuality quality, |
| 954 int xsize, | 911 int xsize, |
| 955 int ysize, | 912 int ysize, |
| 956 int dst_xsize, | 913 int dst_xsize, |
| 957 int dst_ysize, | 914 int dst_ysize, |
| 958 const std::string& description) { | 915 const std::string& description) { |
| 959 std::vector<GLHelperScaling::ScalerStage> stages; | 916 std::vector<GLHelperScaling::ScalerStage> stages; |
| 960 helper_scaling_->ComputeScalerStages(quality, | 917 helper_scaling_->ComputeScalerStages( |
| 961 gfx::Size(xsize, ysize), | 918 quality, gfx::Size(xsize, ysize), gfx::Rect(0, 0, xsize, ysize), |
| 962 gfx::Rect(0, 0, xsize, ysize), | 919 gfx::Size(dst_xsize, dst_ysize), false, false, &stages); |
| 963 gfx::Size(dst_xsize, dst_ysize), | 920 ValidateScalerStages(content::GLHelper::SCALER_QUALITY_GOOD, stages, |
| 964 false, | 921 gfx::Size(dst_xsize, dst_ysize), ""); |
| 965 false, | |
| 966 &stages); | |
| 967 ValidateScalerStages(content::GLHelper::SCALER_QUALITY_GOOD, | |
| 968 stages, | |
| 969 gfx::Size(dst_xsize, dst_ysize), | |
| 970 ""); | |
| 971 EXPECT_EQ(PrintStages(stages), description); | 922 EXPECT_EQ(PrintStages(stages), description); |
| 972 } | 923 } |
| 973 | 924 |
| 974 // Note: Left/Right means Top/Bottom when used for Y dimension. | 925 // Note: Left/Right means Top/Bottom when used for Y dimension. |
| 975 enum Margin { | 926 enum Margin { |
| 976 MarginLeft, | 927 MarginLeft, |
| 977 MarginMiddle, | 928 MarginMiddle, |
| 978 MarginRight, | 929 MarginRight, |
| 979 MarginInvalid, | 930 MarginInvalid, |
| 980 }; | 931 }; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 PrintChannel(source, 1); | 1014 PrintChannel(source, 1); |
| 1064 LOG(ERROR) << "-------before yuv conversion: blue-------"; | 1015 LOG(ERROR) << "-------before yuv conversion: blue-------"; |
| 1065 PrintChannel(source, 2); | 1016 PrintChannel(source, 2); |
| 1066 } | 1017 } |
| 1067 return; | 1018 return; |
| 1068 } | 1019 } |
| 1069 } | 1020 } |
| 1070 } | 1021 } |
| 1071 } | 1022 } |
| 1072 | 1023 |
| 1073 void DrawGridToBitmap(int w, int h, | 1024 void DrawGridToBitmap(int w, |
| 1025 int h, |
| 1074 SkColor background_color, | 1026 SkColor background_color, |
| 1075 SkColor grid_color, | 1027 SkColor grid_color, |
| 1076 int grid_pitch, | 1028 int grid_pitch, |
| 1077 int grid_width, | 1029 int grid_width, |
| 1078 SkBitmap& bmp) { | 1030 SkBitmap& bmp) { |
| 1079 ASSERT_GT(grid_pitch, 0); | 1031 ASSERT_GT(grid_pitch, 0); |
| 1080 ASSERT_GT(grid_width, 0); | 1032 ASSERT_GT(grid_width, 0); |
| 1081 ASSERT_NE(background_color, grid_color); | 1033 ASSERT_NE(background_color, grid_color); |
| 1082 | 1034 |
| 1083 for (int y = 0; y < h; ++y) { | 1035 for (int y = 0; y < h; ++y) { |
| 1084 bool y_on_grid = ((y % grid_pitch) < grid_width); | 1036 bool y_on_grid = ((y % grid_pitch) < grid_width); |
| 1085 | 1037 |
| 1086 for (int x = 0; x < w; ++x) { | 1038 for (int x = 0; x < w; ++x) { |
| 1087 bool on_grid = (y_on_grid || ((x % grid_pitch) < grid_width)); | 1039 bool on_grid = (y_on_grid || ((x % grid_pitch) < grid_width)); |
| 1088 | 1040 |
| 1089 if (bmp.colorType() == kRGBA_8888_SkColorType || | 1041 if (bmp.colorType() == kRGBA_8888_SkColorType || |
| 1090 bmp.colorType() == kBGRA_8888_SkColorType) { | 1042 bmp.colorType() == kBGRA_8888_SkColorType) { |
| 1091 *bmp.getAddr32(x, y) = (on_grid ? grid_color : background_color); | 1043 *bmp.getAddr32(x, y) = (on_grid ? grid_color : background_color); |
| 1092 } else if (bmp.colorType() == kRGB_565_SkColorType) { | 1044 } else if (bmp.colorType() == kRGB_565_SkColorType) { |
| 1093 *bmp.getAddr16(x, y) = (on_grid ? grid_color : background_color); | 1045 *bmp.getAddr16(x, y) = (on_grid ? grid_color : background_color); |
| 1094 } | 1046 } |
| 1095 } | 1047 } |
| 1096 } | 1048 } |
| 1097 } | 1049 } |
| 1098 | 1050 |
| 1099 void DrawCheckerToBitmap(int w, int h, | 1051 void DrawCheckerToBitmap(int w, |
| 1100 SkColor color1, SkColor color2, | 1052 int h, |
| 1101 int rect_w, int rect_h, | 1053 SkColor color1, |
| 1054 SkColor color2, |
| 1055 int rect_w, |
| 1056 int rect_h, |
| 1102 SkBitmap& bmp) { | 1057 SkBitmap& bmp) { |
| 1103 ASSERT_GT(rect_w, 0); | 1058 ASSERT_GT(rect_w, 0); |
| 1104 ASSERT_GT(rect_h, 0); | 1059 ASSERT_GT(rect_h, 0); |
| 1105 ASSERT_NE(color1, color2); | 1060 ASSERT_NE(color1, color2); |
| 1106 | 1061 |
| 1107 for (int y = 0; y < h; ++y) { | 1062 for (int y = 0; y < h; ++y) { |
| 1108 bool y_bit = (((y / rect_h) & 0x1) == 0); | 1063 bool y_bit = (((y / rect_h) & 0x1) == 0); |
| 1109 | 1064 |
| 1110 for (int x = 0; x < w; ++x) { | 1065 for (int x = 0; x < w; ++x) { |
| 1111 bool x_bit = (((x / rect_w) & 0x1) == 0); | 1066 bool x_bit = (((x / rect_w) & 0x1) == 0); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1135 case kRGB_565_SkColorType: | 1090 case kRGB_565_SkColorType: |
| 1136 result = (std::abs(c1 - c2) <= 7); | 1091 result = (std::abs(c1 - c2) <= 7); |
| 1137 break; | 1092 break; |
| 1138 default: | 1093 default: |
| 1139 break; | 1094 break; |
| 1140 } | 1095 } |
| 1141 return result; | 1096 return result; |
| 1142 } | 1097 } |
| 1143 | 1098 |
| 1144 bool ColorsClose(SkColor color1, SkColor color2, SkColorType color_type) { | 1099 bool ColorsClose(SkColor color1, SkColor color2, SkColorType color_type) { |
| 1145 bool red = ColorComponentsClose(SkColorGetR(color1), | 1100 bool red = ColorComponentsClose(SkColorGetR(color1), SkColorGetR(color2), |
| 1146 SkColorGetR(color2), color_type); | 1101 color_type); |
| 1147 bool green = ColorComponentsClose(SkColorGetG(color1), | 1102 bool green = ColorComponentsClose(SkColorGetG(color1), SkColorGetG(color2), |
| 1148 SkColorGetG(color2), color_type); | 1103 color_type); |
| 1149 bool blue = ColorComponentsClose(SkColorGetB(color1), | 1104 bool blue = ColorComponentsClose(SkColorGetB(color1), SkColorGetB(color2), |
| 1150 SkColorGetB(color2), color_type); | 1105 color_type); |
| 1151 bool alpha = ColorComponentsClose(SkColorGetA(color1), | 1106 bool alpha = ColorComponentsClose(SkColorGetA(color1), SkColorGetA(color2), |
| 1152 SkColorGetA(color2), color_type); | 1107 color_type); |
| 1153 if (color_type == kRGB_565_SkColorType) { | 1108 if (color_type == kRGB_565_SkColorType) { |
| 1154 return red && blue && green; | 1109 return red && blue && green; |
| 1155 } | 1110 } |
| 1156 return red && blue && green && alpha; | 1111 return red && blue && green && alpha; |
| 1157 } | 1112 } |
| 1158 | 1113 |
| 1159 bool IsEqual(const SkBitmap& bmp1, const SkBitmap& bmp2) { | 1114 bool IsEqual(const SkBitmap& bmp1, const SkBitmap& bmp2) { |
| 1160 if (bmp1.isNull() && bmp2.isNull()) | 1115 if (bmp1.isNull() && bmp2.isNull()) |
| 1161 return true; | 1116 return true; |
| 1162 if (bmp1.width() != bmp2.width() || | 1117 if (bmp1.width() != bmp2.width() || bmp1.height() != bmp2.height()) { |
| 1163 bmp1.height() != bmp2.height()) { | 1118 LOG(ERROR) << "Bitmap geometry check failure"; |
| 1164 LOG(ERROR) << "Bitmap geometry check failure"; | 1119 return false; |
| 1165 return false; | |
| 1166 } | 1120 } |
| 1167 if (bmp1.colorType() != bmp2.colorType()) | 1121 if (bmp1.colorType() != bmp2.colorType()) |
| 1168 return false; | 1122 return false; |
| 1169 | 1123 |
| 1170 SkAutoLockPixels lock1(bmp1); | 1124 SkAutoLockPixels lock1(bmp1); |
| 1171 SkAutoLockPixels lock2(bmp2); | 1125 SkAutoLockPixels lock2(bmp2); |
| 1172 if (!bmp1.getPixels() || !bmp2.getPixels()) { | 1126 if (!bmp1.getPixels() || !bmp2.getPixels()) { |
| 1173 LOG(ERROR) << "Empty Bitmap!"; | 1127 LOG(ERROR) << "Empty Bitmap!"; |
| 1174 return false; | 1128 return false; |
| 1175 } | 1129 } |
| 1176 for (int y = 0; y < bmp1.height(); ++y) { | 1130 for (int y = 0; y < bmp1.height(); ++y) { |
| 1177 for (int x = 0; x < bmp1.width(); ++x) { | 1131 for (int x = 0; x < bmp1.width(); ++x) { |
| 1178 if (!ColorsClose(bmp1.getColor(x,y), | 1132 if (!ColorsClose(bmp1.getColor(x, y), bmp2.getColor(x, y), |
| 1179 bmp2.getColor(x,y), | |
| 1180 bmp1.colorType())) { | 1133 bmp1.colorType())) { |
| 1181 LOG(ERROR) << "Bitmap color comparision failure"; | 1134 LOG(ERROR) << "Bitmap color comparision failure"; |
| 1182 return false; | 1135 return false; |
| 1183 } | 1136 } |
| 1184 } | 1137 } |
| 1185 } | 1138 } |
| 1186 return true; | 1139 return true; |
| 1187 } | 1140 } |
| 1188 | 1141 |
| 1189 void BindAndAttachTextureWithPixels(GLuint src_texture, | 1142 void BindAndAttachTextureWithPixels(GLuint src_texture, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1212 input_pixels.getPixels()); | 1165 input_pixels.getPixels()); |
| 1213 } | 1166 } |
| 1214 | 1167 |
| 1215 void ReadBackTexture(GLuint src_texture, | 1168 void ReadBackTexture(GLuint src_texture, |
| 1216 const gfx::Size& src_size, | 1169 const gfx::Size& src_size, |
| 1217 unsigned char* pixels, | 1170 unsigned char* pixels, |
| 1218 SkColorType color_type, | 1171 SkColorType color_type, |
| 1219 bool async) { | 1172 bool async) { |
| 1220 if (async) { | 1173 if (async) { |
| 1221 base::RunLoop run_loop; | 1174 base::RunLoop run_loop; |
| 1222 helper_->ReadbackTextureAsync(src_texture, | 1175 helper_->ReadbackTextureAsync( |
| 1223 src_size, | 1176 src_texture, src_size, pixels, color_type, |
| 1224 pixels, | 1177 base::Bind(&callcallback, run_loop.QuitClosure())); |
| 1225 color_type, | |
| 1226 base::Bind(&callcallback, | |
| 1227 run_loop.QuitClosure())); | |
| 1228 run_loop.Run(); | 1178 run_loop.Run(); |
| 1229 } else { | 1179 } else { |
| 1230 helper_->ReadbackTextureSync(src_texture, | 1180 helper_->ReadbackTextureSync(src_texture, gfx::Rect(src_size), pixels, |
| 1231 gfx::Rect(src_size), | |
| 1232 pixels, | |
| 1233 color_type); | 1181 color_type); |
| 1234 } | 1182 } |
| 1235 } | 1183 } |
| 1236 // Test basic format readback. | 1184 // Test basic format readback. |
| 1237 bool TestTextureFormatReadback(const gfx::Size& src_size, | 1185 bool TestTextureFormatReadback(const gfx::Size& src_size, |
| 1238 SkColorType color_type, | 1186 SkColorType color_type, |
| 1239 bool async) { | 1187 bool async) { |
| 1240 SkImageInfo info = | 1188 SkImageInfo info = SkImageInfo::Make(src_size.width(), src_size.height(), |
| 1241 SkImageInfo::Make(src_size.width(), | 1189 color_type, kPremul_SkAlphaType); |
| 1242 src_size.height(), | |
| 1243 color_type, | |
| 1244 kPremul_SkAlphaType); | |
| 1245 if (!helper_->IsReadbackConfigSupported(color_type)) { | 1190 if (!helper_->IsReadbackConfigSupported(color_type)) { |
| 1246 LOG(INFO) << "Skipping test format not supported" << color_type; | 1191 LOG(INFO) << "Skipping test format not supported" << color_type; |
| 1247 return true; | 1192 return true; |
| 1248 } | 1193 } |
| 1249 GLuint src_texture; | 1194 GLuint src_texture; |
| 1250 gl_->GenTextures(1, &src_texture); | 1195 gl_->GenTextures(1, &src_texture); |
| 1251 SkBitmap input_pixels; | 1196 SkBitmap input_pixels; |
| 1252 input_pixels.allocPixels(info); | 1197 input_pixels.allocPixels(info); |
| 1253 // Test Pattern-1, Fill with Plain color pattern. | 1198 // Test Pattern-1, Fill with Plain color pattern. |
| 1254 // Erase the input bitmap with red color. | 1199 // Erase the input bitmap with red color. |
| 1255 input_pixels.eraseColor(SK_ColorRED); | 1200 input_pixels.eraseColor(SK_ColorRED); |
| 1256 BindAndAttachTextureWithPixels(src_texture, | 1201 BindAndAttachTextureWithPixels(src_texture, color_type, src_size, |
| 1257 color_type, | |
| 1258 src_size, | |
| 1259 input_pixels); | 1202 input_pixels); |
| 1260 SkBitmap output_pixels; | 1203 SkBitmap output_pixels; |
| 1261 output_pixels.allocPixels(info); | 1204 output_pixels.allocPixels(info); |
| 1262 // Initialize the output bitmap with Green color. | 1205 // Initialize the output bitmap with Green color. |
| 1263 // When the readback is over output bitmap should have the red color. | 1206 // When the readback is over output bitmap should have the red color. |
| 1264 output_pixels.eraseColor(SK_ColorGREEN); | 1207 output_pixels.eraseColor(SK_ColorGREEN); |
| 1265 uint8_t* pixels = static_cast<uint8_t*>(output_pixels.getPixels()); | 1208 uint8_t* pixels = static_cast<uint8_t*>(output_pixels.getPixels()); |
| 1266 ReadBackTexture(src_texture, src_size, pixels, color_type, async); | 1209 ReadBackTexture(src_texture, src_size, pixels, color_type, async); |
| 1267 bool result = IsEqual(input_pixels, output_pixels); | 1210 bool result = IsEqual(input_pixels, output_pixels); |
| 1268 if (!result) { | 1211 if (!result) { |
| 1269 LOG(ERROR) << "Bitmap comparision failure Pattern-1"; | 1212 LOG(ERROR) << "Bitmap comparision failure Pattern-1"; |
| 1270 return false; | 1213 return false; |
| 1271 } | 1214 } |
| 1272 const int rect_w = 10, rect_h = 4, src_grid_pitch = 10, src_grid_width = 4; | 1215 const int rect_w = 10, rect_h = 4, src_grid_pitch = 10, src_grid_width = 4; |
| 1273 const SkColor color1 = SK_ColorRED, color2 = SK_ColorBLUE; | 1216 const SkColor color1 = SK_ColorRED, color2 = SK_ColorBLUE; |
| 1274 // Test Pattern-2, Fill with Grid Pattern. | 1217 // Test Pattern-2, Fill with Grid Pattern. |
| 1275 DrawGridToBitmap(src_size.width(), src_size.height(), | 1218 DrawGridToBitmap(src_size.width(), src_size.height(), color2, color1, |
| 1276 color2, color1, | 1219 src_grid_pitch, src_grid_width, input_pixels); |
| 1277 src_grid_pitch, src_grid_width, | 1220 BindAndAttachTextureWithPixels(src_texture, color_type, src_size, |
| 1278 input_pixels); | |
| 1279 BindAndAttachTextureWithPixels(src_texture, | |
| 1280 color_type, | |
| 1281 src_size, | |
| 1282 input_pixels); | 1221 input_pixels); |
| 1283 ReadBackTexture(src_texture, src_size, pixels, color_type, async); | 1222 ReadBackTexture(src_texture, src_size, pixels, color_type, async); |
| 1284 result = IsEqual(input_pixels, output_pixels); | 1223 result = IsEqual(input_pixels, output_pixels); |
| 1285 if (!result) { | 1224 if (!result) { |
| 1286 LOG(ERROR) << "Bitmap comparision failure Pattern-2"; | 1225 LOG(ERROR) << "Bitmap comparision failure Pattern-2"; |
| 1287 return false; | 1226 return false; |
| 1288 } | 1227 } |
| 1289 // Test Pattern-3, Fill with CheckerBoard Pattern. | 1228 // Test Pattern-3, Fill with CheckerBoard Pattern. |
| 1290 DrawCheckerToBitmap(src_size.width(), | 1229 DrawCheckerToBitmap(src_size.width(), src_size.height(), color1, color2, |
| 1291 src_size.height(), | 1230 rect_w, rect_h, input_pixels); |
| 1292 color1, | 1231 BindAndAttachTextureWithPixels(src_texture, color_type, src_size, |
| 1293 color2, rect_w, rect_h, input_pixels); | |
| 1294 BindAndAttachTextureWithPixels(src_texture, | |
| 1295 color_type, | |
| 1296 src_size, | |
| 1297 input_pixels); | 1232 input_pixels); |
| 1298 ReadBackTexture(src_texture, src_size, pixels, color_type, async); | 1233 ReadBackTexture(src_texture, src_size, pixels, color_type, async); |
| 1299 result = IsEqual(input_pixels, output_pixels); | 1234 result = IsEqual(input_pixels, output_pixels); |
| 1300 if (!result) { | 1235 if (!result) { |
| 1301 LOG(ERROR) << "Bitmap comparision failure Pattern-3"; | 1236 LOG(ERROR) << "Bitmap comparision failure Pattern-3"; |
| 1302 return false; | 1237 return false; |
| 1303 } | 1238 } |
| 1304 gl_->DeleteTextures(1, &src_texture); | 1239 gl_->DeleteTextures(1, &src_texture); |
| 1305 if (HasFailure()) { | 1240 if (HasFailure()) { |
| 1306 return false; | 1241 return false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 gl_->ShallowFlushCHROMIUM(); | 1298 gl_->ShallowFlushCHROMIUM(); |
| 1364 | 1299 |
| 1365 gpu::SyncToken sync_token; | 1300 gpu::SyncToken sync_token; |
| 1366 gl_->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 1301 gl_->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 1367 | 1302 |
| 1368 std::string message = base::StringPrintf( | 1303 std::string message = base::StringPrintf( |
| 1369 "input size: %dx%d " | 1304 "input size: %dx%d " |
| 1370 "output size: %dx%d " | 1305 "output size: %dx%d " |
| 1371 "margin: %dx%d " | 1306 "margin: %dx%d " |
| 1372 "pattern: %d %s %s", | 1307 "pattern: %d %s %s", |
| 1373 xsize, | 1308 xsize, ysize, output_xsize, output_ysize, xmargin, ymargin, |
| 1374 ysize, | 1309 test_pattern, flip ? "flip" : "noflip", flip ? "mrt" : "nomrt"); |
| 1375 output_xsize, | |
| 1376 output_ysize, | |
| 1377 xmargin, | |
| 1378 ymargin, | |
| 1379 test_pattern, | |
| 1380 flip ? "flip" : "noflip", | |
| 1381 flip ? "mrt" : "nomrt"); | |
| 1382 scoped_ptr<ReadbackYUVInterface> yuv_reader( | 1310 scoped_ptr<ReadbackYUVInterface> yuv_reader( |
| 1383 helper_->CreateReadbackPipelineYUV( | 1311 helper_->CreateReadbackPipelineYUV( |
| 1384 quality, | 1312 quality, gfx::Size(xsize, ysize), gfx::Rect(0, 0, xsize, ysize), |
| 1385 gfx::Size(xsize, ysize), | 1313 gfx::Size(xsize, ysize), flip, use_mrt)); |
| 1386 gfx::Rect(0, 0, xsize, ysize), | |
| 1387 gfx::Size(xsize, ysize), | |
| 1388 flip, | |
| 1389 use_mrt)); | |
| 1390 | 1314 |
| 1391 scoped_refptr<media::VideoFrame> output_frame = | 1315 scoped_refptr<media::VideoFrame> output_frame = |
| 1392 media::VideoFrame::CreateFrame( | 1316 media::VideoFrame::CreateFrame( |
| 1393 media::PIXEL_FORMAT_YV12, | 1317 media::PIXEL_FORMAT_YV12, |
| 1394 // The coded size of the output frame is rounded up to the next | 1318 // The coded size of the output frame is rounded up to the next |
| 1395 // 16-byte boundary. This tests that the readback is being | 1319 // 16-byte boundary. This tests that the readback is being |
| 1396 // positioned inside the frame's visible region, and not dependent | 1320 // positioned inside the frame's visible region, and not dependent |
| 1397 // on its coded size. | 1321 // on its coded size. |
| 1398 gfx::Size((output_xsize + 15) & ~15, (output_ysize + 15) & ~15), | 1322 gfx::Size((output_xsize + 15) & ~15, (output_ysize + 15) & ~15), |
| 1399 gfx::Rect(0, 0, output_xsize, output_ysize), | 1323 gfx::Rect(0, 0, output_xsize, output_ysize), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 float_to_byte(Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 0) * | 1378 float_to_byte(Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 0) * |
| 1455 kRGBtoVColorWeights[0] + | 1379 kRGBtoVColorWeights[0] + |
| 1456 Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 1) * | 1380 Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 1) * |
| 1457 kRGBtoVColorWeights[1] + | 1381 kRGBtoVColorWeights[1] + |
| 1458 Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 2) * | 1382 Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 2) * |
| 1459 kRGBtoVColorWeights[2] + | 1383 kRGBtoVColorWeights[2] + |
| 1460 kRGBtoVColorWeights[3]); | 1384 kRGBtoVColorWeights[3]); |
| 1461 } | 1385 } |
| 1462 } | 1386 } |
| 1463 | 1387 |
| 1464 ComparePlane(Y, | 1388 ComparePlane( |
| 1465 y_stride, | 1389 Y, y_stride, output_frame->visible_data(media::VideoFrame::kYPlane), |
| 1466 output_frame->visible_data(media::VideoFrame::kYPlane), | 1390 output_frame->stride(media::VideoFrame::kYPlane), 2, output_xsize, |
| 1467 output_frame->stride(media::VideoFrame::kYPlane), | 1391 output_ysize, &input_pixels, message + " Y plane"); |
| 1468 2, | 1392 ComparePlane( |
| 1469 output_xsize, | 1393 U, u_stride, output_frame->visible_data(media::VideoFrame::kUPlane), |
| 1470 output_ysize, | 1394 output_frame->stride(media::VideoFrame::kUPlane), 2, output_xsize / 2, |
| 1471 &input_pixels, | 1395 output_ysize / 2, &input_pixels, message + " U plane"); |
| 1472 message + " Y plane"); | 1396 ComparePlane( |
| 1473 ComparePlane(U, | 1397 V, v_stride, output_frame->visible_data(media::VideoFrame::kVPlane), |
| 1474 u_stride, | 1398 output_frame->stride(media::VideoFrame::kVPlane), 2, output_xsize / 2, |
| 1475 output_frame->visible_data(media::VideoFrame::kUPlane), | 1399 output_ysize / 2, &input_pixels, message + " V plane"); |
| 1476 output_frame->stride(media::VideoFrame::kUPlane), | |
| 1477 2, | |
| 1478 output_xsize / 2, | |
| 1479 output_ysize / 2, | |
| 1480 &input_pixels, | |
| 1481 message + " U plane"); | |
| 1482 ComparePlane(V, | |
| 1483 v_stride, | |
| 1484 output_frame->visible_data(media::VideoFrame::kVPlane), | |
| 1485 output_frame->stride(media::VideoFrame::kVPlane), | |
| 1486 2, | |
| 1487 output_xsize / 2, | |
| 1488 output_ysize / 2, | |
| 1489 &input_pixels, | |
| 1490 message + " V plane"); | |
| 1491 | 1400 |
| 1492 gl_->DeleteTextures(1, &src_texture); | 1401 gl_->DeleteTextures(1, &src_texture); |
| 1493 } | 1402 } |
| 1494 | 1403 |
| 1495 void TestAddOps(int src, int dst, bool scale_x, bool allow3) { | 1404 void TestAddOps(int src, int dst, bool scale_x, bool allow3) { |
| 1496 std::deque<GLHelperScaling::ScaleOp> ops; | 1405 std::deque<GLHelperScaling::ScaleOp> ops; |
| 1497 GLHelperScaling::ScaleOp::AddOps(src, dst, scale_x, allow3, &ops); | 1406 GLHelperScaling::ScaleOp::AddOps(src, dst, scale_x, allow3, &ops); |
| 1498 // Scale factor 3 is a special case. | 1407 // Scale factor 3 is a special case. |
| 1499 // It is currently only allowed by itself. | 1408 // It is currently only allowed by itself. |
| 1500 if (allow3 && dst * 3 >= src && dst * 2 < src) { | 1409 if (allow3 && dst * 3 >= src && dst * 2 < src) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1531 EXPECT_EQ(tmp, src); | 1440 EXPECT_EQ(tmp, src); |
| 1532 } | 1441 } |
| 1533 | 1442 |
| 1534 void CheckPipeline2(int xsize, | 1443 void CheckPipeline2(int xsize, |
| 1535 int ysize, | 1444 int ysize, |
| 1536 int dst_xsize, | 1445 int dst_xsize, |
| 1537 int dst_ysize, | 1446 int dst_ysize, |
| 1538 const std::string& description) { | 1447 const std::string& description) { |
| 1539 std::vector<GLHelperScaling::ScalerStage> stages; | 1448 std::vector<GLHelperScaling::ScalerStage> stages; |
| 1540 helper_scaling_->ConvertScalerOpsToScalerStages( | 1449 helper_scaling_->ConvertScalerOpsToScalerStages( |
| 1541 content::GLHelper::SCALER_QUALITY_GOOD, | 1450 content::GLHelper::SCALER_QUALITY_GOOD, gfx::Size(xsize, ysize), |
| 1542 gfx::Size(xsize, ysize), | 1451 gfx::Rect(0, 0, xsize, ysize), gfx::Size(dst_xsize, dst_ysize), false, |
| 1543 gfx::Rect(0, 0, xsize, ysize), | 1452 false, &x_ops_, &y_ops_, &stages); |
| 1544 gfx::Size(dst_xsize, dst_ysize), | |
| 1545 false, | |
| 1546 false, | |
| 1547 &x_ops_, | |
| 1548 &y_ops_, | |
| 1549 &stages); | |
| 1550 EXPECT_EQ(x_ops_.size(), 0U); | 1453 EXPECT_EQ(x_ops_.size(), 0U); |
| 1551 EXPECT_EQ(y_ops_.size(), 0U); | 1454 EXPECT_EQ(y_ops_.size(), 0U); |
| 1552 ValidateScalerStages(content::GLHelper::SCALER_QUALITY_GOOD, | 1455 ValidateScalerStages(content::GLHelper::SCALER_QUALITY_GOOD, stages, |
| 1553 stages, | 1456 gfx::Size(dst_xsize, dst_ysize), ""); |
| 1554 gfx::Size(dst_xsize, dst_ysize), | |
| 1555 ""); | |
| 1556 EXPECT_EQ(PrintStages(stages), description); | 1457 EXPECT_EQ(PrintStages(stages), description); |
| 1557 } | 1458 } |
| 1558 | 1459 |
| 1559 void CheckOptimizationsTest() { | 1460 void CheckOptimizationsTest() { |
| 1560 // Basic upscale. X and Y should be combined into one pass. | 1461 // Basic upscale. X and Y should be combined into one pass. |
| 1561 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 2000)); | 1462 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 2000)); |
| 1562 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 2000)); | 1463 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 2000)); |
| 1563 CheckPipeline2(1024, 768, 2000, 2000, "1024x768 -> 2000x2000 bilinear\n"); | 1464 CheckPipeline2(1024, 768, 2000, 2000, "1024x768 -> 2000x2000 bilinear\n"); |
| 1564 | 1465 |
| 1565 // X scaled 1/2, Y upscaled, should still be one pass. | 1466 // X scaled 1/2, Y upscaled, should still be one pass. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1592 // X scaled to 60%, Y scaled 60%, one bilinear2x2 pass. | 1493 // X scaled to 60%, Y scaled 60%, one bilinear2x2 pass. |
| 1593 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 120)); | 1494 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 120)); |
| 1594 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 60)); | 1495 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 60)); |
| 1595 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); | 1496 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); |
| 1596 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); | 1497 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); |
| 1597 CheckPipeline2(100, 100, 60, 60, "100x100 -> 60x60 bilinear2x2\n"); | 1498 CheckPipeline2(100, 100, 60, 60, "100x100 -> 60x60 bilinear2x2\n"); |
| 1598 | 1499 |
| 1599 // X scaled to 40%, Y scaled 40%, two bilinear3 passes. | 1500 // X scaled to 40%, Y scaled 40%, two bilinear3 passes. |
| 1600 x_ops_.push_back(GLHelperScaling::ScaleOp(3, true, 40)); | 1501 x_ops_.push_back(GLHelperScaling::ScaleOp(3, true, 40)); |
| 1601 y_ops_.push_back(GLHelperScaling::ScaleOp(3, false, 40)); | 1502 y_ops_.push_back(GLHelperScaling::ScaleOp(3, false, 40)); |
| 1602 CheckPipeline2(100, | 1503 CheckPipeline2(100, 100, 40, 40, |
| 1603 100, | |
| 1604 40, | |
| 1605 40, | |
| 1606 "100x100 -> 100x40 bilinear3 Y\n" | 1504 "100x100 -> 100x40 bilinear3 Y\n" |
| 1607 "100x40 -> 40x40 bilinear3 X\n"); | 1505 "100x40 -> 40x40 bilinear3 X\n"); |
| 1608 | 1506 |
| 1609 // X scaled to 60%, Y scaled 40% | 1507 // X scaled to 60%, Y scaled 40% |
| 1610 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 120)); | 1508 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 120)); |
| 1611 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 60)); | 1509 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 60)); |
| 1612 y_ops_.push_back(GLHelperScaling::ScaleOp(3, false, 40)); | 1510 y_ops_.push_back(GLHelperScaling::ScaleOp(3, false, 40)); |
| 1613 CheckPipeline2(100, | 1511 CheckPipeline2(100, 100, 60, 40, |
| 1614 100, | |
| 1615 60, | |
| 1616 40, | |
| 1617 "100x100 -> 100x40 bilinear3 Y\n" | 1512 "100x100 -> 100x40 bilinear3 Y\n" |
| 1618 "100x40 -> 60x40 bilinear2 X\n"); | 1513 "100x40 -> 60x40 bilinear2 X\n"); |
| 1619 | 1514 |
| 1620 // X scaled to 40%, Y scaled 60% | 1515 // X scaled to 40%, Y scaled 60% |
| 1621 x_ops_.push_back(GLHelperScaling::ScaleOp(3, true, 40)); | 1516 x_ops_.push_back(GLHelperScaling::ScaleOp(3, true, 40)); |
| 1622 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); | 1517 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); |
| 1623 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); | 1518 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); |
| 1624 CheckPipeline2(100, | 1519 CheckPipeline2(100, 100, 40, 60, |
| 1625 100, | |
| 1626 40, | |
| 1627 60, | |
| 1628 "100x100 -> 100x60 bilinear2 Y\n" | 1520 "100x100 -> 100x60 bilinear2 Y\n" |
| 1629 "100x60 -> 40x60 bilinear3 X\n"); | 1521 "100x60 -> 40x60 bilinear3 X\n"); |
| 1630 | 1522 |
| 1631 // X scaled to 30%, Y scaled 30% | 1523 // X scaled to 30%, Y scaled 30% |
| 1632 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 120)); | 1524 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 120)); |
| 1633 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 60)); | 1525 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 60)); |
| 1634 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 30)); | 1526 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 30)); |
| 1635 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); | 1527 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); |
| 1636 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); | 1528 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); |
| 1637 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 30)); | 1529 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 30)); |
| 1638 CheckPipeline2(100, | 1530 CheckPipeline2(100, 100, 30, 30, |
| 1639 100, | |
| 1640 30, | |
| 1641 30, | |
| 1642 "100x100 -> 100x30 bilinear4 Y\n" | 1531 "100x100 -> 100x30 bilinear4 Y\n" |
| 1643 "100x30 -> 30x30 bilinear4 X\n"); | 1532 "100x30 -> 30x30 bilinear4 X\n"); |
| 1644 | 1533 |
| 1645 // X scaled to 50%, Y scaled 30% | 1534 // X scaled to 50%, Y scaled 30% |
| 1646 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 50)); | 1535 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 50)); |
| 1647 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); | 1536 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); |
| 1648 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); | 1537 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); |
| 1649 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 30)); | 1538 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 30)); |
| 1650 CheckPipeline2(100, 100, 50, 30, "100x100 -> 50x30 bilinear4 Y\n"); | 1539 CheckPipeline2(100, 100, 50, 30, "100x100 -> 50x30 bilinear4 Y\n"); |
| 1651 | 1540 |
| 1652 // X scaled to 150%, Y scaled 30% | 1541 // X scaled to 150%, Y scaled 30% |
| 1653 // Note that we avoid combinding X and Y passes | 1542 // Note that we avoid combinding X and Y passes |
| 1654 // as that would probably be LESS efficient here. | 1543 // as that would probably be LESS efficient here. |
| 1655 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 150)); | 1544 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 150)); |
| 1656 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); | 1545 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 120)); |
| 1657 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); | 1546 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 60)); |
| 1658 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 30)); | 1547 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 30)); |
| 1659 CheckPipeline2(100, | 1548 CheckPipeline2(100, 100, 150, 30, |
| 1660 100, | |
| 1661 150, | |
| 1662 30, | |
| 1663 "100x100 -> 100x30 bilinear4 Y\n" | 1549 "100x100 -> 100x30 bilinear4 Y\n" |
| 1664 "100x30 -> 150x30 bilinear\n"); | 1550 "100x30 -> 150x30 bilinear\n"); |
| 1665 | 1551 |
| 1666 // X scaled to 1%, Y scaled 1% | 1552 // X scaled to 1%, Y scaled 1% |
| 1667 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 128)); | 1553 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 128)); |
| 1668 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 64)); | 1554 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 64)); |
| 1669 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 32)); | 1555 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 32)); |
| 1670 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 16)); | 1556 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 16)); |
| 1671 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 8)); | 1557 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 8)); |
| 1672 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 4)); | 1558 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 4)); |
| 1673 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 2)); | 1559 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 2)); |
| 1674 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 1)); | 1560 x_ops_.push_back(GLHelperScaling::ScaleOp(2, true, 1)); |
| 1675 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 128)); | 1561 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 128)); |
| 1676 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 64)); | 1562 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 64)); |
| 1677 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 32)); | 1563 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 32)); |
| 1678 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 16)); | 1564 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 16)); |
| 1679 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 8)); | 1565 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 8)); |
| 1680 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 4)); | 1566 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 4)); |
| 1681 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 2)); | 1567 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 2)); |
| 1682 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 1)); | 1568 y_ops_.push_back(GLHelperScaling::ScaleOp(2, false, 1)); |
| 1683 CheckPipeline2(100, | 1569 CheckPipeline2(100, 100, 1, 1, |
| 1684 100, | |
| 1685 1, | |
| 1686 1, | |
| 1687 "100x100 -> 100x32 bilinear4 Y\n" | 1570 "100x100 -> 100x32 bilinear4 Y\n" |
| 1688 "100x32 -> 100x4 bilinear4 Y\n" | 1571 "100x32 -> 100x4 bilinear4 Y\n" |
| 1689 "100x4 -> 64x1 bilinear2x2\n" | 1572 "100x4 -> 64x1 bilinear2x2\n" |
| 1690 "64x1 -> 8x1 bilinear4 X\n" | 1573 "64x1 -> 8x1 bilinear4 X\n" |
| 1691 "8x1 -> 1x1 bilinear4 X\n"); | 1574 "8x1 -> 1x1 bilinear4 X\n"); |
| 1692 } | 1575 } |
| 1693 | 1576 |
| 1694 scoped_ptr<gpu::GLInProcessContext> context_; | 1577 scoped_ptr<gpu::GLInProcessContext> context_; |
| 1695 gpu::gles2::GLES2Interface* gl_; | 1578 gpu::gles2::GLES2Interface* gl_; |
| 1696 scoped_ptr<content::GLHelper> helper_; | 1579 scoped_ptr<content::GLHelper> helper_; |
| 1697 scoped_ptr<content::GLHelperScaling> helper_scaling_; | 1580 scoped_ptr<content::GLHelperScaling> helper_scaling_; |
| 1698 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 1581 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
| 1699 }; | 1582 }; |
| 1700 | 1583 |
| 1701 class GLHelperPixelTest : public GLHelperTest { | 1584 class GLHelperPixelTest : public GLHelperTest { |
| 1702 private: | 1585 private: |
| 1703 gfx::DisableNullDrawGLBindings enable_pixel_output_; | 1586 gfx::DisableNullDrawGLBindings enable_pixel_output_; |
| 1704 }; | 1587 }; |
| 1705 | 1588 |
| 1706 TEST_F(GLHelperTest, RGBASyncReadbackTest) { | 1589 TEST_F(GLHelperTest, RGBASyncReadbackTest) { |
| 1707 const int kTestSize = 64; | 1590 const int kTestSize = 64; |
| 1708 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1591 bool result = TestTextureFormatReadback(gfx::Size(kTestSize, kTestSize), |
| 1709 kRGBA_8888_SkColorType, | 1592 kRGBA_8888_SkColorType, false); |
| 1710 false); | |
| 1711 EXPECT_EQ(result, true); | 1593 EXPECT_EQ(result, true); |
| 1712 } | 1594 } |
| 1713 | 1595 |
| 1714 | |
| 1715 TEST_F(GLHelperTest, BGRASyncReadbackTest) { | 1596 TEST_F(GLHelperTest, BGRASyncReadbackTest) { |
| 1716 const int kTestSize = 64; | 1597 const int kTestSize = 64; |
| 1717 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1598 bool result = TestTextureFormatReadback(gfx::Size(kTestSize, kTestSize), |
| 1718 kBGRA_8888_SkColorType, | 1599 kBGRA_8888_SkColorType, false); |
| 1719 false); | |
| 1720 EXPECT_EQ(result, true); | 1600 EXPECT_EQ(result, true); |
| 1721 } | 1601 } |
| 1722 | 1602 |
| 1723 TEST_F(GLHelperTest, RGB565SyncReadbackTest) { | 1603 TEST_F(GLHelperTest, RGB565SyncReadbackTest) { |
| 1724 const int kTestSize = 64; | 1604 const int kTestSize = 64; |
| 1725 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1605 bool result = TestTextureFormatReadback(gfx::Size(kTestSize, kTestSize), |
| 1726 kRGB_565_SkColorType, | 1606 kRGB_565_SkColorType, false); |
| 1727 false); | |
| 1728 EXPECT_EQ(result, true); | 1607 EXPECT_EQ(result, true); |
| 1729 } | 1608 } |
| 1730 | 1609 |
| 1731 TEST_F(GLHelperTest, RGBAASyncReadbackTest) { | 1610 TEST_F(GLHelperTest, RGBAASyncReadbackTest) { |
| 1732 const int kTestSize = 64; | 1611 const int kTestSize = 64; |
| 1733 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1612 bool result = TestTextureFormatReadback(gfx::Size(kTestSize, kTestSize), |
| 1734 kRGBA_8888_SkColorType, | 1613 kRGBA_8888_SkColorType, true); |
| 1735 true); | |
| 1736 EXPECT_EQ(result, true); | 1614 EXPECT_EQ(result, true); |
| 1737 } | 1615 } |
| 1738 | 1616 |
| 1739 TEST_F(GLHelperTest, BGRAASyncReadbackTest) { | 1617 TEST_F(GLHelperTest, BGRAASyncReadbackTest) { |
| 1740 const int kTestSize = 64; | 1618 const int kTestSize = 64; |
| 1741 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1619 bool result = TestTextureFormatReadback(gfx::Size(kTestSize, kTestSize), |
| 1742 kBGRA_8888_SkColorType, | 1620 kBGRA_8888_SkColorType, true); |
| 1743 true); | |
| 1744 EXPECT_EQ(result, true); | 1621 EXPECT_EQ(result, true); |
| 1745 } | 1622 } |
| 1746 | 1623 |
| 1747 TEST_F(GLHelperTest, RGB565ASyncReadbackTest) { | 1624 TEST_F(GLHelperTest, RGB565ASyncReadbackTest) { |
| 1748 const int kTestSize = 64; | 1625 const int kTestSize = 64; |
| 1749 bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize), | 1626 bool result = TestTextureFormatReadback(gfx::Size(kTestSize, kTestSize), |
| 1750 kRGB_565_SkColorType, | 1627 kRGB_565_SkColorType, true); |
| 1751 true); | |
| 1752 EXPECT_EQ(result, true); | 1628 EXPECT_EQ(result, true); |
| 1753 } | 1629 } |
| 1754 | 1630 |
| 1755 TEST_F(GLHelperPixelTest, YUVReadbackOptTest) { | 1631 TEST_F(GLHelperPixelTest, YUVReadbackOptTest) { |
| 1756 // This test uses the gpu.service/gpu_decoder tracing events to detect how | 1632 // This test uses the gpu.service/gpu_decoder tracing events to detect how |
| 1757 // many scaling passes are actually performed by the YUV readback pipeline. | 1633 // many scaling passes are actually performed by the YUV readback pipeline. |
| 1758 StartTracing(TRACE_DISABLED_BY_DEFAULT("gpu.service") "," | 1634 StartTracing(TRACE_DISABLED_BY_DEFAULT( |
| 1759 TRACE_DISABLED_BY_DEFAULT("gpu_decoder")); | 1635 "gpu.service") "," TRACE_DISABLED_BY_DEFAULT("gpu_decoder")); |
| 1760 | 1636 |
| 1761 TestYUVReadback(800, | 1637 TestYUVReadback(800, 400, 800, 400, 0, 0, 1, false, true, |
| 1762 400, | |
| 1763 800, | |
| 1764 400, | |
| 1765 0, | |
| 1766 0, | |
| 1767 1, | |
| 1768 false, | |
| 1769 true, | |
| 1770 content::GLHelper::SCALER_QUALITY_FAST); | 1638 content::GLHelper::SCALER_QUALITY_FAST); |
| 1771 | 1639 |
| 1772 std::map<std::string, int> event_counts; | 1640 std::map<std::string, int> event_counts; |
| 1773 EndTracing(&event_counts); | 1641 EndTracing(&event_counts); |
| 1774 int draw_buffer_calls = event_counts["kDrawBuffersEXTImmediate"]; | 1642 int draw_buffer_calls = event_counts["kDrawBuffersEXTImmediate"]; |
| 1775 int draw_arrays_calls = event_counts["kDrawArrays"]; | 1643 int draw_arrays_calls = event_counts["kDrawArrays"]; |
| 1776 VLOG(1) << "Draw buffer calls: " << draw_buffer_calls; | 1644 VLOG(1) << "Draw buffer calls: " << draw_buffer_calls; |
| 1777 VLOG(1) << "DrawArrays calls: " << draw_arrays_calls; | 1645 VLOG(1) << "DrawArrays calls: " << draw_arrays_calls; |
| 1778 | 1646 |
| 1779 if (draw_buffer_calls) { | 1647 if (draw_buffer_calls) { |
| 1780 // When using MRT, the YUV readback code should only | 1648 // When using MRT, the YUV readback code should only |
| 1781 // execute two draw arrays, and scaling should be integrated | 1649 // execute two draw arrays, and scaling should be integrated |
| 1782 // into those two calls since we are using the FAST scalign | 1650 // into those two calls since we are using the FAST scalign |
| 1783 // quality. | 1651 // quality. |
| 1784 EXPECT_EQ(2, draw_arrays_calls); | 1652 EXPECT_EQ(2, draw_arrays_calls); |
| 1785 } else { | 1653 } else { |
| 1786 // When not using MRT, there are three passes for the YUV, | 1654 // When not using MRT, there are three passes for the YUV, |
| 1787 // and one for the scaling. | 1655 // and one for the scaling. |
| 1788 EXPECT_EQ(4, draw_arrays_calls); | 1656 EXPECT_EQ(4, draw_arrays_calls); |
| 1789 } | 1657 } |
| 1790 } | 1658 } |
| 1791 | 1659 |
| 1792 class GLHelperPixelYuvReadback : | 1660 class GLHelperPixelYuvReadback |
| 1793 public GLHelperPixelTest, | 1661 : public GLHelperPixelTest, |
| 1794 public ::testing::WithParamInterface< | 1662 public ::testing::WithParamInterface< |
| 1795 std::tr1::tuple<bool, bool, unsigned int, unsigned int>> {}; | 1663 std::tr1::tuple<bool, bool, unsigned int, unsigned int>> {}; |
| 1796 | 1664 |
| 1797 int kYUVReadBackSizes[] = {2, 4, 14}; | 1665 int kYUVReadBackSizes[] = {2, 4, 14}; |
| 1798 | 1666 |
| 1799 TEST_P(GLHelperPixelYuvReadback, Test) { | 1667 TEST_P(GLHelperPixelYuvReadback, Test) { |
| 1800 bool flip = std::tr1::get<0>(GetParam()); | 1668 bool flip = std::tr1::get<0>(GetParam()); |
| 1801 bool use_mrt = std::tr1::get<1>(GetParam()); | 1669 bool use_mrt = std::tr1::get<1>(GetParam()); |
| 1802 unsigned int x = std::tr1::get<2>(GetParam()); | 1670 unsigned int x = std::tr1::get<2>(GetParam()); |
| 1803 unsigned int y = std::tr1::get<3>(GetParam()); | 1671 unsigned int y = std::tr1::get<3>(GetParam()); |
| 1804 | 1672 |
| 1805 for (unsigned int ox = x; ox < arraysize(kYUVReadBackSizes); ox++) { | 1673 for (unsigned int ox = x; ox < arraysize(kYUVReadBackSizes); ox++) { |
| 1806 for (unsigned int oy = y; oy < arraysize(kYUVReadBackSizes); oy++) { | 1674 for (unsigned int oy = y; oy < arraysize(kYUVReadBackSizes); oy++) { |
| 1807 // If output is a subsection of the destination frame, (letterbox) | 1675 // If output is a subsection of the destination frame, (letterbox) |
| 1808 // then try different variations of where the subsection goes. | 1676 // then try different variations of where the subsection goes. |
| 1809 for (Margin xm = x < ox ? MarginLeft : MarginRight; | 1677 for (Margin xm = x < ox ? MarginLeft : MarginRight; xm <= MarginRight; |
| 1810 xm <= MarginRight; | |
| 1811 xm = NextMargin(xm)) { | 1678 xm = NextMargin(xm)) { |
| 1812 for (Margin ym = y < oy ? MarginLeft : MarginRight; | 1679 for (Margin ym = y < oy ? MarginLeft : MarginRight; ym <= MarginRight; |
| 1813 ym <= MarginRight; | |
| 1814 ym = NextMargin(ym)) { | 1680 ym = NextMargin(ym)) { |
| 1815 for (int pattern = 0; pattern < 3; pattern++) { | 1681 for (int pattern = 0; pattern < 3; pattern++) { |
| 1816 TestYUVReadback(kYUVReadBackSizes[x], | 1682 TestYUVReadback( |
| 1817 kYUVReadBackSizes[y], | 1683 kYUVReadBackSizes[x], kYUVReadBackSizes[y], |
| 1818 kYUVReadBackSizes[ox], | 1684 kYUVReadBackSizes[ox], kYUVReadBackSizes[oy], |
| 1819 kYUVReadBackSizes[oy], | 1685 compute_margin(kYUVReadBackSizes[x], kYUVReadBackSizes[ox], xm), |
| 1820 compute_margin(kYUVReadBackSizes[x], | 1686 compute_margin(kYUVReadBackSizes[y], kYUVReadBackSizes[oy], ym), |
| 1821 kYUVReadBackSizes[ox], xm), | 1687 pattern, flip, use_mrt, content::GLHelper::SCALER_QUALITY_GOOD); |
| 1822 compute_margin(kYUVReadBackSizes[y], | |
| 1823 kYUVReadBackSizes[oy], ym), | |
| 1824 pattern, | |
| 1825 flip, | |
| 1826 use_mrt, | |
| 1827 content::GLHelper::SCALER_QUALITY_GOOD); | |
| 1828 if (HasFailure()) { | 1688 if (HasFailure()) { |
| 1829 return; | 1689 return; |
| 1830 } | 1690 } |
| 1831 } | 1691 } |
| 1832 } | 1692 } |
| 1833 } | 1693 } |
| 1834 } | 1694 } |
| 1835 } | 1695 } |
| 1836 } | 1696 } |
| 1837 | 1697 |
| 1838 // First argument is intentionally empty. | 1698 // First argument is intentionally empty. |
| 1839 INSTANTIATE_TEST_CASE_P( | 1699 INSTANTIATE_TEST_CASE_P( |
| 1840 , | 1700 , |
| 1841 GLHelperPixelYuvReadback, | 1701 GLHelperPixelYuvReadback, |
| 1842 ::testing::Combine( | 1702 ::testing::Combine( |
| 1843 ::testing::Bool(), | 1703 ::testing::Bool(), |
| 1844 ::testing::Bool(), | 1704 ::testing::Bool(), |
| 1845 ::testing::Range<unsigned int>(0, arraysize(kYUVReadBackSizes)), | 1705 ::testing::Range<unsigned int>(0, arraysize(kYUVReadBackSizes)), |
| 1846 ::testing::Range<unsigned int>(0, arraysize(kYUVReadBackSizes)))); | 1706 ::testing::Range<unsigned int>(0, arraysize(kYUVReadBackSizes)))); |
| 1847 | |
| 1848 | 1707 |
| 1849 int kRGBReadBackSizes[] = {3, 6, 16}; | 1708 int kRGBReadBackSizes[] = {3, 6, 16}; |
| 1850 | 1709 |
| 1851 class GLHelperPixelReadbackTest : | 1710 class GLHelperPixelReadbackTest |
| 1852 public GLHelperPixelTest, | 1711 : public GLHelperPixelTest, |
| 1853 public ::testing::WithParamInterface< | 1712 public ::testing::WithParamInterface<std::tr1::tuple<unsigned int, |
| 1854 std::tr1::tuple<unsigned int, | 1713 unsigned int, |
| 1855 unsigned int, | 1714 unsigned int, |
| 1856 unsigned int, | 1715 unsigned int, |
| 1857 unsigned int, | 1716 unsigned int>> {}; |
| 1858 unsigned int>> {}; | |
| 1859 | 1717 |
| 1860 // Per pixel tests, all sizes are small so that we can print | 1718 // Per pixel tests, all sizes are small so that we can print |
| 1861 // out the generated bitmaps. | 1719 // out the generated bitmaps. |
| 1862 TEST_P(GLHelperPixelReadbackTest, ScaleTest) { | 1720 TEST_P(GLHelperPixelReadbackTest, ScaleTest) { |
| 1863 unsigned int q_index = std::tr1::get<0>(GetParam()); | 1721 unsigned int q_index = std::tr1::get<0>(GetParam()); |
| 1864 unsigned int x = std::tr1::get<1>(GetParam()); | 1722 unsigned int x = std::tr1::get<1>(GetParam()); |
| 1865 unsigned int y = std::tr1::get<2>(GetParam()); | 1723 unsigned int y = std::tr1::get<2>(GetParam()); |
| 1866 unsigned int dst_x = std::tr1::get<3>(GetParam()); | 1724 unsigned int dst_x = std::tr1::get<3>(GetParam()); |
| 1867 unsigned int dst_y = std::tr1::get<4>(GetParam()); | 1725 unsigned int dst_y = std::tr1::get<4>(GetParam()); |
| 1868 | 1726 |
| 1869 for (int flip = 0; flip <= 1; flip++) { | 1727 for (int flip = 0; flip <= 1; flip++) { |
| 1870 for (int pattern = 0; pattern < 3; pattern++) { | 1728 for (int pattern = 0; pattern < 3; pattern++) { |
| 1871 TestScale(kRGBReadBackSizes[x], | 1729 TestScale(kRGBReadBackSizes[x], kRGBReadBackSizes[y], |
| 1872 kRGBReadBackSizes[y], | 1730 kRGBReadBackSizes[dst_x], kRGBReadBackSizes[dst_y], pattern, |
| 1873 kRGBReadBackSizes[dst_x], | 1731 q_index, flip == 1); |
| 1874 kRGBReadBackSizes[dst_y], | |
| 1875 pattern, | |
| 1876 q_index, | |
| 1877 flip == 1); | |
| 1878 if (HasFailure()) { | 1732 if (HasFailure()) { |
| 1879 return; | 1733 return; |
| 1880 } | 1734 } |
| 1881 } | 1735 } |
| 1882 } | 1736 } |
| 1883 } | 1737 } |
| 1884 | 1738 |
| 1885 | |
| 1886 // Per pixel tests, all sizes are small so that we can print | 1739 // Per pixel tests, all sizes are small so that we can print |
| 1887 // out the generated bitmaps. | 1740 // out the generated bitmaps. |
| 1888 TEST_P(GLHelperPixelReadbackTest, CropScaleReadbackAndCleanTextureTest) { | 1741 TEST_P(GLHelperPixelReadbackTest, CropScaleReadbackAndCleanTextureTest) { |
| 1889 unsigned int q_index = std::tr1::get<0>(GetParam()); | 1742 unsigned int q_index = std::tr1::get<0>(GetParam()); |
| 1890 unsigned int x = std::tr1::get<1>(GetParam()); | 1743 unsigned int x = std::tr1::get<1>(GetParam()); |
| 1891 unsigned int y = std::tr1::get<2>(GetParam()); | 1744 unsigned int y = std::tr1::get<2>(GetParam()); |
| 1892 unsigned int dst_x = std::tr1::get<3>(GetParam()); | 1745 unsigned int dst_x = std::tr1::get<3>(GetParam()); |
| 1893 unsigned int dst_y = std::tr1::get<4>(GetParam()); | 1746 unsigned int dst_y = std::tr1::get<4>(GetParam()); |
| 1894 | 1747 |
| 1895 const SkColorType kColorTypes[] = { | 1748 const SkColorType kColorTypes[] = { |
| 1896 kAlpha_8_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType}; | 1749 kAlpha_8_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType}; |
| 1897 for (size_t color_type = 0; color_type < arraysize(kColorTypes); | 1750 for (size_t color_type = 0; color_type < arraysize(kColorTypes); |
| 1898 color_type++) { | 1751 color_type++) { |
| 1899 for (int pattern = 0; pattern < 3; pattern++) { | 1752 for (int pattern = 0; pattern < 3; pattern++) { |
| 1900 TestCropScaleReadbackAndCleanTexture(kRGBReadBackSizes[x], | 1753 TestCropScaleReadbackAndCleanTexture( |
| 1901 kRGBReadBackSizes[y], | 1754 kRGBReadBackSizes[x], kRGBReadBackSizes[y], kRGBReadBackSizes[dst_x], |
| 1902 kRGBReadBackSizes[dst_x], | 1755 kRGBReadBackSizes[dst_y], pattern, kColorTypes[color_type], false, |
| 1903 kRGBReadBackSizes[dst_y], | 1756 q_index); |
| 1904 pattern, | |
| 1905 kColorTypes[color_type], | |
| 1906 false, | |
| 1907 q_index); | |
| 1908 if (HasFailure()) | 1757 if (HasFailure()) |
| 1909 return; | 1758 return; |
| 1910 } | 1759 } |
| 1911 } | 1760 } |
| 1912 } | 1761 } |
| 1913 | 1762 |
| 1914 INSTANTIATE_TEST_CASE_P( | 1763 INSTANTIATE_TEST_CASE_P( |
| 1915 , | 1764 , |
| 1916 GLHelperPixelReadbackTest, | 1765 GLHelperPixelReadbackTest, |
| 1917 ::testing::Combine( | 1766 ::testing::Combine( |
| 1918 ::testing::Range<unsigned int>(0, arraysize(kQualities)), | 1767 ::testing::Range<unsigned int>(0, arraysize(kQualities)), |
| 1919 ::testing::Range<unsigned int>(0, arraysize(kRGBReadBackSizes)), | 1768 ::testing::Range<unsigned int>(0, arraysize(kRGBReadBackSizes)), |
| 1920 ::testing::Range<unsigned int>(0, arraysize(kRGBReadBackSizes)), | 1769 ::testing::Range<unsigned int>(0, arraysize(kRGBReadBackSizes)), |
| 1921 ::testing::Range<unsigned int>(0, arraysize(kRGBReadBackSizes)), | 1770 ::testing::Range<unsigned int>(0, arraysize(kRGBReadBackSizes)), |
| 1922 ::testing::Range<unsigned int>(0, arraysize(kRGBReadBackSizes)))); | 1771 ::testing::Range<unsigned int>(0, arraysize(kRGBReadBackSizes)))); |
| 1923 | 1772 |
| 1924 // Validate that all scaling generates valid pipelines. | 1773 // Validate that all scaling generates valid pipelines. |
| 1925 TEST_F(GLHelperTest, ValidateScalerPipelines) { | 1774 TEST_F(GLHelperTest, ValidateScalerPipelines) { |
| 1926 int sizes[] = {7, 99, 128, 256, 512, 719, 720, 721, 1920, 2011, 3217, 4096}; | 1775 int sizes[] = {7, 99, 128, 256, 512, 719, 720, 721, 1920, 2011, 3217, 4096}; |
| 1927 for (size_t q = 0; q < arraysize(kQualities); q++) { | 1776 for (size_t q = 0; q < arraysize(kQualities); q++) { |
| 1928 for (size_t x = 0; x < arraysize(sizes); x++) { | 1777 for (size_t x = 0; x < arraysize(sizes); x++) { |
| 1929 for (size_t y = 0; y < arraysize(sizes); y++) { | 1778 for (size_t y = 0; y < arraysize(sizes); y++) { |
| 1930 for (size_t dst_x = 0; dst_x < arraysize(sizes); dst_x++) { | 1779 for (size_t dst_x = 0; dst_x < arraysize(sizes); dst_x++) { |
| 1931 for (size_t dst_y = 0; dst_y < arraysize(sizes); dst_y++) { | 1780 for (size_t dst_y = 0; dst_y < arraysize(sizes); dst_y++) { |
| 1932 TestScalerPipeline( | 1781 TestScalerPipeline(q, sizes[x], sizes[y], sizes[dst_x], |
| 1933 q, sizes[x], sizes[y], sizes[dst_x], sizes[dst_y]); | 1782 sizes[dst_y]); |
| 1934 if (HasFailure()) { | 1783 if (HasFailure()) { |
| 1935 return; | 1784 return; |
| 1936 } | 1785 } |
| 1937 } | 1786 } |
| 1938 } | 1787 } |
| 1939 } | 1788 } |
| 1940 } | 1789 } |
| 1941 } | 1790 } |
| 1942 } | 1791 } |
| 1943 | 1792 |
| 1944 // Make sure we don't create overly complicated pipelines | 1793 // Make sure we don't create overly complicated pipelines |
| 1945 // for a few common use cases. | 1794 // for a few common use cases. |
| 1946 TEST_F(GLHelperTest, CheckSpecificPipelines) { | 1795 TEST_F(GLHelperTest, CheckSpecificPipelines) { |
| 1947 // Upscale should be single pass. | 1796 // Upscale should be single pass. |
| 1948 CheckPipeline(content::GLHelper::SCALER_QUALITY_GOOD, | 1797 CheckPipeline(content::GLHelper::SCALER_QUALITY_GOOD, 1024, 700, 1280, 720, |
| 1949 1024, | |
| 1950 700, | |
| 1951 1280, | |
| 1952 720, | |
| 1953 "1024x700 -> 1280x720 bilinear\n"); | 1798 "1024x700 -> 1280x720 bilinear\n"); |
| 1954 // Slight downscale should use BILINEAR2X2. | 1799 // Slight downscale should use BILINEAR2X2. |
| 1955 CheckPipeline(content::GLHelper::SCALER_QUALITY_GOOD, | 1800 CheckPipeline(content::GLHelper::SCALER_QUALITY_GOOD, 1280, 720, 1024, 700, |
| 1956 1280, | |
| 1957 720, | |
| 1958 1024, | |
| 1959 700, | |
| 1960 "1280x720 -> 1024x700 bilinear2x2\n"); | 1801 "1280x720 -> 1024x700 bilinear2x2\n"); |
| 1961 // Most common tab capture pipeline on the Pixel. | 1802 // Most common tab capture pipeline on the Pixel. |
| 1962 // Should be using two BILINEAR3 passes. | 1803 // Should be using two BILINEAR3 passes. |
| 1963 CheckPipeline(content::GLHelper::SCALER_QUALITY_GOOD, | 1804 CheckPipeline(content::GLHelper::SCALER_QUALITY_GOOD, 2560, 1476, 1249, 720, |
| 1964 2560, | |
| 1965 1476, | |
| 1966 1249, | |
| 1967 720, | |
| 1968 "2560x1476 -> 2560x720 bilinear3 Y\n" | 1805 "2560x1476 -> 2560x720 bilinear3 Y\n" |
| 1969 "2560x720 -> 1249x720 bilinear3 X\n"); | 1806 "2560x720 -> 1249x720 bilinear3 X\n"); |
| 1970 } | 1807 } |
| 1971 | 1808 |
| 1972 TEST_F(GLHelperTest, ScalerOpTest) { | 1809 TEST_F(GLHelperTest, ScalerOpTest) { |
| 1973 for (int allow3 = 0; allow3 <= 1; allow3++) { | 1810 for (int allow3 = 0; allow3 <= 1; allow3++) { |
| 1974 for (int dst = 1; dst < 2049; dst += 1 + (dst >> 3)) { | 1811 for (int dst = 1; dst < 2049; dst += 1 + (dst >> 3)) { |
| 1975 for (int src = 1; src < 2049; src++) { | 1812 for (int src = 1; src < 2049; src++) { |
| 1976 TestAddOps(src, dst, allow3 == 1, (src & 1) == 1); | 1813 TestAddOps(src, dst, allow3 == 1, (src & 1) == 1); |
| 1977 if (HasFailure()) { | 1814 if (HasFailure()) { |
| 1978 LOG(ERROR) << "Failed for src=" << src << " dst=" << dst | 1815 LOG(ERROR) << "Failed for src=" << src << " dst=" << dst |
| 1979 << " allow3=" << allow3; | 1816 << " allow3=" << allow3; |
| 1980 return; | 1817 return; |
| 1981 } | 1818 } |
| 1982 } | 1819 } |
| 1983 } | 1820 } |
| 1984 } | 1821 } |
| 1985 } | 1822 } |
| 1986 | 1823 |
| 1987 TEST_F(GLHelperTest, CheckOptimizations) { | 1824 TEST_F(GLHelperTest, CheckOptimizations) { |
| 1988 // Test in baseclass since it is friends with GLHelperScaling | 1825 // Test in baseclass since it is friends with GLHelperScaling |
| 1989 CheckOptimizationsTest(); | 1826 CheckOptimizationsTest(); |
| 1990 } | 1827 } |
| 1991 | 1828 |
| 1992 } // namespace content | 1829 } // namespace content |
| OLD | NEW |