| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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> |
| 11 #include <vector> | 11 #include <vector> |
| (...skipping 10 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/browser/compositor/gl_helper.h" | 32 #include "components/display_compositor/gl_helper.h" |
| 33 #include "content/browser/compositor/gl_helper_readback_support.h" | 33 #include "components/display_compositor/gl_helper_readback_support.h" |
| 34 #include "content/browser/compositor/gl_helper_scaling.h" | 34 #include "components/display_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 "gpu/command_buffer/client/shared_memory_limits.h" | 37 #include "gpu/command_buffer/client/shared_memory_limits.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 display_compositor { |
| 44 | 44 |
| 45 content::GLHelper::ScalerQuality kQualities[] = { | 45 display_compositor::GLHelper::ScalerQuality kQualities[] = { |
| 46 content::GLHelper::SCALER_QUALITY_BEST, | 46 display_compositor::GLHelper::SCALER_QUALITY_BEST, |
| 47 content::GLHelper::SCALER_QUALITY_GOOD, | 47 display_compositor::GLHelper::SCALER_QUALITY_GOOD, |
| 48 content::GLHelper::SCALER_QUALITY_FAST, | 48 display_compositor::GLHelper::SCALER_QUALITY_FAST, |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 const char* kQualityNames[] = { | 51 const char* kQualityNames[] = { |
| 52 "best", "good", "fast", | 52 "best", "good", "fast", |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 class GLHelperTest : public testing::Test { | 55 class GLHelperTest : public testing::Test { |
| 56 protected: | 56 protected: |
| 57 void SetUp() override { | 57 void SetUp() override { |
| 58 gpu::gles2::ContextCreationAttribHelper attributes; | 58 gpu::gles2::ContextCreationAttribHelper attributes; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 72 true, /* offscreen */ | 72 true, /* offscreen */ |
| 73 gfx::kNullAcceleratedWidget, /* window */ | 73 gfx::kNullAcceleratedWidget, /* window */ |
| 74 gfx::Size(1, 1), /* size */ | 74 gfx::Size(1, 1), /* size */ |
| 75 nullptr, /* share_context */ | 75 nullptr, /* share_context */ |
| 76 attributes, gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(), | 76 attributes, gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(), |
| 77 nullptr, /* gpu_memory_buffer_manager */ | 77 nullptr, /* gpu_memory_buffer_manager */ |
| 78 nullptr /* image_factory */)); | 78 nullptr /* image_factory */)); |
| 79 gl_ = context_->GetImplementation(); | 79 gl_ = context_->GetImplementation(); |
| 80 gpu::ContextSupport* support = context_->GetImplementation(); | 80 gpu::ContextSupport* support = context_->GetImplementation(); |
| 81 | 81 |
| 82 helper_.reset(new content::GLHelper(gl_, support)); | 82 helper_.reset(new display_compositor::GLHelper(gl_, support)); |
| 83 helper_scaling_.reset(new content::GLHelperScaling(gl_, helper_.get())); | 83 helper_scaling_.reset( |
| 84 new display_compositor::GLHelperScaling(gl_, helper_.get())); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void TearDown() override { | 87 void TearDown() override { |
| 87 helper_scaling_.reset(nullptr); | 88 helper_scaling_.reset(nullptr); |
| 88 helper_.reset(nullptr); | 89 helper_.reset(nullptr); |
| 89 context_.reset(nullptr); | 90 context_.reset(nullptr); |
| 90 } | 91 } |
| 91 | 92 |
| 92 // Bicubic filter kernel function. | 93 // Bicubic filter kernel function. |
| 93 static float Bicubic(float x) { | 94 static float Bicubic(float x) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // Multi-sample upscale-downscale combination? | 231 // Multi-sample upscale-downscale combination? |
| 231 if (scale > samples / 2.0 && scale < samples) { | 232 if (scale > samples / 2.0 && scale < samples) { |
| 232 return true; | 233 return true; |
| 233 } | 234 } |
| 234 } | 235 } |
| 235 return false; | 236 return false; |
| 236 } | 237 } |
| 237 | 238 |
| 238 // Make sure that the stages of the scaler pipeline are sane. | 239 // Make sure that the stages of the scaler pipeline are sane. |
| 239 void ValidateScalerStages( | 240 void ValidateScalerStages( |
| 240 content::GLHelper::ScalerQuality quality, | 241 display_compositor::GLHelper::ScalerQuality quality, |
| 241 const std::vector<GLHelperScaling::ScalerStage>& scaler_stages, | 242 const std::vector<GLHelperScaling::ScalerStage>& scaler_stages, |
| 242 const gfx::Size& dst_size, | 243 const gfx::Size& dst_size, |
| 243 const std::string& message) { | 244 const std::string& message) { |
| 244 bool previous_error = HasFailure(); | 245 bool previous_error = HasFailure(); |
| 245 // First, check that the input size for each stage is equal to | 246 // First, check that the input size for each stage is equal to |
| 246 // the output size of the previous stage. | 247 // the output size of the previous stage. |
| 247 for (size_t i = 1; i < scaler_stages.size(); i++) { | 248 for (size_t i = 1; i < scaler_stages.size(); i++) { |
| 248 EXPECT_EQ(scaler_stages[i - 1].dst_size.width(), | 249 EXPECT_EQ(scaler_stages[i - 1].dst_size.width(), |
| 249 scaler_stages[i].src_size.width()); | 250 scaler_stages[i].src_size.width()); |
| 250 EXPECT_EQ(scaler_stages[i - 1].dst_size.height(), | 251 EXPECT_EQ(scaler_stages[i - 1].dst_size.height(), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 283 |
| 283 // Codify valid scale operations. | 284 // Codify valid scale operations. |
| 284 switch (scaler_stages[i].shader) { | 285 switch (scaler_stages[i].shader) { |
| 285 case GLHelperScaling::SHADER_PLANAR: | 286 case GLHelperScaling::SHADER_PLANAR: |
| 286 case GLHelperScaling::SHADER_YUV_MRT_PASS1: | 287 case GLHelperScaling::SHADER_YUV_MRT_PASS1: |
| 287 case GLHelperScaling::SHADER_YUV_MRT_PASS2: | 288 case GLHelperScaling::SHADER_YUV_MRT_PASS2: |
| 288 EXPECT_TRUE(false) << "Invalid shader."; | 289 EXPECT_TRUE(false) << "Invalid shader."; |
| 289 break; | 290 break; |
| 290 | 291 |
| 291 case GLHelperScaling::SHADER_BILINEAR: | 292 case GLHelperScaling::SHADER_BILINEAR: |
| 292 if (quality != content::GLHelper::SCALER_QUALITY_FAST) { | 293 if (quality != display_compositor::GLHelper::SCALER_QUALITY_FAST) { |
| 293 x_samples = 1; | 294 x_samples = 1; |
| 294 y_samples = 1; | 295 y_samples = 1; |
| 295 } | 296 } |
| 296 break; | 297 break; |
| 297 case GLHelperScaling::SHADER_BILINEAR2: | 298 case GLHelperScaling::SHADER_BILINEAR2: |
| 298 x_samples = 2; | 299 x_samples = 2; |
| 299 y_samples = 1; | 300 y_samples = 1; |
| 300 break; | 301 break; |
| 301 case GLHelperScaling::SHADER_BILINEAR3: | 302 case GLHelperScaling::SHADER_BILINEAR3: |
| 302 x_samples = 3; | 303 x_samples = 3; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 c2 * kRGBtoGrayscaleColorWeights[2]; | 453 c2 * kRGBtoGrayscaleColorWeights[2]; |
| 453 SetChannel(output, dst_x, dst_y, 0, | 454 SetChannel(output, dst_x, dst_y, 0, |
| 454 static_cast<int>(value * 255.0f + 0.5f)); | 455 static_cast<int>(value * 255.0f + 0.5f)); |
| 455 } | 456 } |
| 456 } | 457 } |
| 457 } | 458 } |
| 458 | 459 |
| 459 // Very slow bicubic / bilinear scaler for reference. | 460 // Very slow bicubic / bilinear scaler for reference. |
| 460 void ScaleSlow(SkBitmap* input, | 461 void ScaleSlow(SkBitmap* input, |
| 461 SkBitmap* output, | 462 SkBitmap* output, |
| 462 content::GLHelper::ScalerQuality quality) { | 463 display_compositor::GLHelper::ScalerQuality quality) { |
| 463 float xscale = static_cast<float>(input->width()) / output->width(); | 464 float xscale = static_cast<float>(input->width()) / output->width(); |
| 464 float yscale = static_cast<float>(input->height()) / output->height(); | 465 float yscale = static_cast<float>(input->height()) / output->height(); |
| 465 float clamped_xscale = xscale < 1.0 ? 1.0 : 1.0 / xscale; | 466 float clamped_xscale = xscale < 1.0 ? 1.0 : 1.0 / xscale; |
| 466 float clamped_yscale = yscale < 1.0 ? 1.0 : 1.0 / yscale; | 467 float clamped_yscale = yscale < 1.0 ? 1.0 : 1.0 / yscale; |
| 467 for (int dst_y = 0; dst_y < output->height(); dst_y++) { | 468 for (int dst_y = 0; dst_y < output->height(); dst_y++) { |
| 468 for (int dst_x = 0; dst_x < output->width(); dst_x++) { | 469 for (int dst_x = 0; dst_x < output->width(); dst_x++) { |
| 469 for (int channel = 0; channel < 4; channel++) { | 470 for (int channel = 0; channel < 4; channel++) { |
| 470 float dst_x_in_src = (dst_x + 0.5f) * xscale; | 471 float dst_x_in_src = (dst_x + 0.5f) * xscale; |
| 471 float dst_y_in_src = (dst_y + 0.5f) * yscale; | 472 float dst_y_in_src = (dst_y + 0.5f) * yscale; |
| 472 | 473 |
| 473 float value = 0.0f; | 474 float value = 0.0f; |
| 474 float sum = 0.0f; | 475 float sum = 0.0f; |
| 475 switch (quality) { | 476 switch (quality) { |
| 476 case content::GLHelper::SCALER_QUALITY_BEST: | 477 case display_compositor::GLHelper::SCALER_QUALITY_BEST: |
| 477 for (int src_y = -10; src_y < input->height() + 10; ++src_y) { | 478 for (int src_y = -10; src_y < input->height() + 10; ++src_y) { |
| 478 float coeff_y = | 479 float coeff_y = |
| 479 Bicubic((src_y + 0.5f - dst_y_in_src) * clamped_yscale); | 480 Bicubic((src_y + 0.5f - dst_y_in_src) * clamped_yscale); |
| 480 if (coeff_y == 0.0f) { | 481 if (coeff_y == 0.0f) { |
| 481 continue; | 482 continue; |
| 482 } | 483 } |
| 483 for (int src_x = -10; src_x < input->width() + 10; ++src_x) { | 484 for (int src_x = -10; src_x < input->width() + 10; ++src_x) { |
| 484 float coeff = | 485 float coeff = |
| 485 coeff_y * | 486 coeff_y * |
| 486 Bicubic((src_x + 0.5f - dst_x_in_src) * clamped_xscale); | 487 Bicubic((src_x + 0.5f - dst_x_in_src) * clamped_xscale); |
| 487 if (coeff == 0.0f) { | 488 if (coeff == 0.0f) { |
| 488 continue; | 489 continue; |
| 489 } | 490 } |
| 490 sum += coeff; | 491 sum += coeff; |
| 491 float c = ChannelAsFloat(input, src_x, src_y, channel); | 492 float c = ChannelAsFloat(input, src_x, src_y, channel); |
| 492 value += c * coeff; | 493 value += c * coeff; |
| 493 } | 494 } |
| 494 } | 495 } |
| 495 break; | 496 break; |
| 496 | 497 |
| 497 case content::GLHelper::SCALER_QUALITY_GOOD: { | 498 case display_compositor::GLHelper::SCALER_QUALITY_GOOD: { |
| 498 int xshift = 0, yshift = 0; | 499 int xshift = 0, yshift = 0; |
| 499 while ((output->width() << xshift) < input->width()) { | 500 while ((output->width() << xshift) < input->width()) { |
| 500 xshift++; | 501 xshift++; |
| 501 } | 502 } |
| 502 while ((output->height() << yshift) < input->height()) { | 503 while ((output->height() << yshift) < input->height()) { |
| 503 yshift++; | 504 yshift++; |
| 504 } | 505 } |
| 505 int xmag = 1 << xshift; | 506 int xmag = 1 << xshift; |
| 506 int ymag = 1 << yshift; | 507 int ymag = 1 << yshift; |
| 507 if (xmag == 4 && output->width() * 3 >= input->width()) { | 508 if (xmag == 4 && output->width() * 3 >= input->width()) { |
| 508 xmag = 3; | 509 xmag = 3; |
| 509 } | 510 } |
| 510 if (ymag == 4 && output->height() * 3 >= input->height()) { | 511 if (ymag == 4 && output->height() * 3 >= input->height()) { |
| 511 ymag = 3; | 512 ymag = 3; |
| 512 } | 513 } |
| 513 for (int x = 0; x < xmag; x++) { | 514 for (int x = 0; x < xmag; x++) { |
| 514 for (int y = 0; y < ymag; y++) { | 515 for (int y = 0; y < ymag; y++) { |
| 515 value += Bilinear( | 516 value += Bilinear( |
| 516 input, (dst_x * xmag + x + 0.5) * xscale / xmag, | 517 input, (dst_x * xmag + x + 0.5) * xscale / xmag, |
| 517 (dst_y * ymag + y + 0.5) * yscale / ymag, channel); | 518 (dst_y * ymag + y + 0.5) * yscale / ymag, channel); |
| 518 sum += 1.0; | 519 sum += 1.0; |
| 519 } | 520 } |
| 520 } | 521 } |
| 521 break; | 522 break; |
| 522 } | 523 } |
| 523 | 524 |
| 524 case content::GLHelper::SCALER_QUALITY_FAST: | 525 case display_compositor::GLHelper::SCALER_QUALITY_FAST: |
| 525 value = Bilinear(input, dst_x_in_src, dst_y_in_src, channel); | 526 value = Bilinear(input, dst_x_in_src, dst_y_in_src, channel); |
| 526 sum = 1.0; | 527 sum = 1.0; |
| 527 } | 528 } |
| 528 value /= sum; | 529 value /= sum; |
| 529 SetChannel(output, dst_x, dst_y, channel, | 530 SetChannel(output, dst_x, dst_y, channel, |
| 530 static_cast<int>(value * 255.0f + 0.5f)); | 531 static_cast<int>(value * 255.0f + 0.5f)); |
| 531 } | 532 } |
| 532 } | 533 } |
| 533 } | 534 } |
| 534 } | 535 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 562 SetChannel(bitmap, x, y, 2, c0); | 563 SetChannel(bitmap, x, y, 2, c0); |
| 563 SetChannel(bitmap, x, y, 0, c2); | 564 SetChannel(bitmap, x, y, 0, c2); |
| 564 } | 565 } |
| 565 } | 566 } |
| 566 } | 567 } |
| 567 | 568 |
| 568 // gl_helper scales recursively, so we'll need to do that | 569 // gl_helper scales recursively, so we'll need to do that |
| 569 // in the reference implementation too. | 570 // in the reference implementation too. |
| 570 void ScaleSlowRecursive(SkBitmap* input, | 571 void ScaleSlowRecursive(SkBitmap* input, |
| 571 SkBitmap* output, | 572 SkBitmap* output, |
| 572 content::GLHelper::ScalerQuality quality) { | 573 display_compositor::GLHelper::ScalerQuality quality) { |
| 573 if (quality == content::GLHelper::SCALER_QUALITY_FAST || | 574 if (quality == display_compositor::GLHelper::SCALER_QUALITY_FAST || |
| 574 quality == content::GLHelper::SCALER_QUALITY_GOOD) { | 575 quality == display_compositor::GLHelper::SCALER_QUALITY_GOOD) { |
| 575 ScaleSlow(input, output, quality); | 576 ScaleSlow(input, output, quality); |
| 576 return; | 577 return; |
| 577 } | 578 } |
| 578 | 579 |
| 579 float xscale = static_cast<float>(output->width()) / input->width(); | 580 float xscale = static_cast<float>(output->width()) / input->width(); |
| 580 | 581 |
| 581 // This corresponds to all the operations we can do directly. | 582 // This corresponds to all the operations we can do directly. |
| 582 float yscale = static_cast<float>(output->height()) / input->height(); | 583 float yscale = static_cast<float>(output->height()) / input->height(); |
| 583 if ((xscale == 1.0f && yscale == 1.0f) || | 584 if ((xscale == 1.0f && yscale == 1.0f) || |
| 584 (xscale == 0.5f && yscale == 1.0f) || | 585 (xscale == 0.5f && yscale == 1.0f) || |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 xsize, ysize); | 765 xsize, ysize); |
| 765 | 766 |
| 766 std::string message = base::StringPrintf( | 767 std::string message = base::StringPrintf( |
| 767 "input size: %dx%d " | 768 "input size: %dx%d " |
| 768 "output size: %dx%d " | 769 "output size: %dx%d " |
| 769 "pattern: %d quality: %s", | 770 "pattern: %d quality: %s", |
| 770 xsize, ysize, scaled_xsize, scaled_ysize, test_pattern, | 771 xsize, ysize, scaled_xsize, scaled_ysize, test_pattern, |
| 771 kQualityNames[quality_index]); | 772 kQualityNames[quality_index]); |
| 772 | 773 |
| 773 std::vector<GLHelperScaling::ScalerStage> stages; | 774 std::vector<GLHelperScaling::ScalerStage> stages; |
| 774 helper_scaling_->ComputeScalerStages(kQualities[quality_index], | 775 helper_scaling_->ComputeScalerStages( |
| 775 gfx::Size(xsize, ysize), | 776 kQualities[quality_index], gfx::Size(xsize, ysize), |
| 776 gfx::Rect(0, 0, xsize, ysize), | 777 gfx::Rect(0, 0, xsize, ysize), gfx::Size(scaled_xsize, scaled_ysize), |
| 777 gfx::Size(scaled_xsize, scaled_ysize), | 778 flip, false, &stages); |
| 778 flip, | 779 ValidateScalerStages(kQualities[quality_index], stages, |
| 779 false, | 780 gfx::Size(scaled_xsize, scaled_ysize), message); |
| 780 &stages); | |
| 781 ValidateScalerStages(kQualities[quality_index], | |
| 782 stages, | |
| 783 gfx::Size(scaled_xsize, scaled_ysize), | |
| 784 message); | |
| 785 | 781 |
| 786 GLuint dst_texture = helper_->CopyAndScaleTexture( | 782 GLuint dst_texture = helper_->CopyAndScaleTexture( |
| 787 src_texture, gfx::Size(xsize, ysize), | 783 src_texture, gfx::Size(xsize, ysize), |
| 788 gfx::Size(scaled_xsize, scaled_ysize), flip, kQualities[quality_index]); | 784 gfx::Size(scaled_xsize, scaled_ysize), flip, kQualities[quality_index]); |
| 789 | 785 |
| 790 SkBitmap output_pixels; | 786 SkBitmap output_pixels; |
| 791 output_pixels.allocPixels(SkImageInfo::Make(scaled_xsize, scaled_ysize, | 787 output_pixels.allocPixels(SkImageInfo::Make(scaled_xsize, scaled_ysize, |
| 792 kRGBA_8888_SkColorType, | 788 kRGBA_8888_SkColorType, |
| 793 kPremul_SkAlphaType)); | 789 kPremul_SkAlphaType)); |
| 794 | 790 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 gfx::Size(dst_xsize, dst_ysize), | 835 gfx::Size(dst_xsize, dst_ysize), |
| 840 base::StringPrintf("input size: %dx%d " | 836 base::StringPrintf("input size: %dx%d " |
| 841 "output size: %dx%d " | 837 "output size: %dx%d " |
| 842 "quality: %s", | 838 "quality: %s", |
| 843 xsize, ysize, dst_xsize, dst_ysize, | 839 xsize, ysize, dst_xsize, dst_ysize, |
| 844 kQualityNames[quality])); | 840 kQualityNames[quality])); |
| 845 } | 841 } |
| 846 | 842 |
| 847 // Create a scaling pipeline and make sure that the steps | 843 // Create a scaling pipeline and make sure that the steps |
| 848 // are exactly the steps we expect. | 844 // are exactly the steps we expect. |
| 849 void CheckPipeline(content::GLHelper::ScalerQuality quality, | 845 void CheckPipeline(display_compositor::GLHelper::ScalerQuality quality, |
| 850 int xsize, | 846 int xsize, |
| 851 int ysize, | 847 int ysize, |
| 852 int dst_xsize, | 848 int dst_xsize, |
| 853 int dst_ysize, | 849 int dst_ysize, |
| 854 const std::string& description) { | 850 const std::string& description) { |
| 855 std::vector<GLHelperScaling::ScalerStage> stages; | 851 std::vector<GLHelperScaling::ScalerStage> stages; |
| 856 helper_scaling_->ComputeScalerStages( | 852 helper_scaling_->ComputeScalerStages( |
| 857 quality, gfx::Size(xsize, ysize), gfx::Rect(0, 0, xsize, ysize), | 853 quality, gfx::Size(xsize, ysize), gfx::Rect(0, 0, xsize, ysize), |
| 858 gfx::Size(dst_xsize, dst_ysize), false, false, &stages); | 854 gfx::Size(dst_xsize, dst_ysize), false, false, &stages); |
| 859 ValidateScalerStages(content::GLHelper::SCALER_QUALITY_GOOD, stages, | 855 ValidateScalerStages(display_compositor::GLHelper::SCALER_QUALITY_GOOD, |
| 860 gfx::Size(dst_xsize, dst_ysize), ""); | 856 stages, gfx::Size(dst_xsize, dst_ysize), ""); |
| 861 EXPECT_EQ(PrintStages(stages), description); | 857 EXPECT_EQ(PrintStages(stages), description); |
| 862 } | 858 } |
| 863 | 859 |
| 864 static void callcallback(const base::Callback<void()>& callback, | 860 static void callcallback(const base::Callback<void()>& callback, |
| 865 bool result) { | 861 bool result) { |
| 866 callback.Run(); | 862 callback.Run(); |
| 867 } | 863 } |
| 868 | 864 |
| 869 void DrawGridToBitmap(int w, | 865 void DrawGridToBitmap(int w, |
| 870 int h, | 866 int h, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 break; | 992 break; |
| 997 case kRGBA_8888_SkColorType: | 993 case kRGBA_8888_SkColorType: |
| 998 format = GL_RGBA; | 994 format = GL_RGBA; |
| 999 break; | 995 break; |
| 1000 case kRGB_565_SkColorType: | 996 case kRGB_565_SkColorType: |
| 1001 format = GL_RGB; | 997 format = GL_RGB; |
| 1002 break; | 998 break; |
| 1003 default: | 999 default: |
| 1004 NOTREACHED(); | 1000 NOTREACHED(); |
| 1005 } | 1001 } |
| 1006 GLenum type = (color_type == kRGB_565_SkColorType) ? | 1002 GLenum type = (color_type == kRGB_565_SkColorType) ? GL_UNSIGNED_SHORT_5_6_5 |
| 1007 GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; | 1003 : GL_UNSIGNED_BYTE; |
| 1008 gl_->TexImage2D(GL_TEXTURE_2D, 0, format, src_size.width(), | 1004 gl_->TexImage2D(GL_TEXTURE_2D, 0, format, src_size.width(), |
| 1009 src_size.height(), 0, format, type, | 1005 src_size.height(), 0, format, type, |
| 1010 input_pixels.getPixels()); | 1006 input_pixels.getPixels()); |
| 1011 } | 1007 } |
| 1012 | 1008 |
| 1013 void ReadBackTexture(GLuint src_texture, | 1009 void ReadBackTexture(GLuint src_texture, |
| 1014 const gfx::Size& src_size, | 1010 const gfx::Size& src_size, |
| 1015 unsigned char* pixels, | 1011 unsigned char* pixels, |
| 1016 SkColorType color_type, | 1012 SkColorType color_type, |
| 1017 bool async) { | 1013 bool async) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 EXPECT_EQ(tmp, src); | 1123 EXPECT_EQ(tmp, src); |
| 1128 } | 1124 } |
| 1129 | 1125 |
| 1130 void CheckPipeline2(int xsize, | 1126 void CheckPipeline2(int xsize, |
| 1131 int ysize, | 1127 int ysize, |
| 1132 int dst_xsize, | 1128 int dst_xsize, |
| 1133 int dst_ysize, | 1129 int dst_ysize, |
| 1134 const std::string& description) { | 1130 const std::string& description) { |
| 1135 std::vector<GLHelperScaling::ScalerStage> stages; | 1131 std::vector<GLHelperScaling::ScalerStage> stages; |
| 1136 helper_scaling_->ConvertScalerOpsToScalerStages( | 1132 helper_scaling_->ConvertScalerOpsToScalerStages( |
| 1137 content::GLHelper::SCALER_QUALITY_GOOD, gfx::Size(xsize, ysize), | 1133 display_compositor::GLHelper::SCALER_QUALITY_GOOD, |
| 1138 gfx::Rect(0, 0, xsize, ysize), gfx::Size(dst_xsize, dst_ysize), false, | 1134 gfx::Size(xsize, ysize), gfx::Rect(0, 0, xsize, ysize), |
| 1139 false, &x_ops_, &y_ops_, &stages); | 1135 gfx::Size(dst_xsize, dst_ysize), false, false, &x_ops_, &y_ops_, |
| 1136 &stages); |
| 1140 EXPECT_EQ(x_ops_.size(), 0U); | 1137 EXPECT_EQ(x_ops_.size(), 0U); |
| 1141 EXPECT_EQ(y_ops_.size(), 0U); | 1138 EXPECT_EQ(y_ops_.size(), 0U); |
| 1142 ValidateScalerStages(content::GLHelper::SCALER_QUALITY_GOOD, stages, | 1139 ValidateScalerStages(display_compositor::GLHelper::SCALER_QUALITY_GOOD, |
| 1143 gfx::Size(dst_xsize, dst_ysize), ""); | 1140 stages, gfx::Size(dst_xsize, dst_ysize), ""); |
| 1144 EXPECT_EQ(PrintStages(stages), description); | 1141 EXPECT_EQ(PrintStages(stages), description); |
| 1145 } | 1142 } |
| 1146 | 1143 |
| 1147 void CheckOptimizationsTest() { | 1144 void CheckOptimizationsTest() { |
| 1148 // Basic upscale. X and Y should be combined into one pass. | 1145 // Basic upscale. X and Y should be combined into one pass. |
| 1149 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 2000)); | 1146 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 2000)); |
| 1150 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 2000)); | 1147 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 2000)); |
| 1151 CheckPipeline2(1024, 768, 2000, 2000, "1024x768 -> 2000x2000 bilinear\n"); | 1148 CheckPipeline2(1024, 768, 2000, 2000, "1024x768 -> 2000x2000 bilinear\n"); |
| 1152 | 1149 |
| 1153 // X scaled 1/2, Y upscaled, should still be one pass. | 1150 // X scaled 1/2, Y upscaled, should still be one pass. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 CheckPipeline2(100, 100, 1, 1, | 1253 CheckPipeline2(100, 100, 1, 1, |
| 1257 "100x100 -> 100x32 bilinear4 Y\n" | 1254 "100x100 -> 100x32 bilinear4 Y\n" |
| 1258 "100x32 -> 100x4 bilinear4 Y\n" | 1255 "100x32 -> 100x4 bilinear4 Y\n" |
| 1259 "100x4 -> 64x1 bilinear2x2\n" | 1256 "100x4 -> 64x1 bilinear2x2\n" |
| 1260 "64x1 -> 8x1 bilinear4 X\n" | 1257 "64x1 -> 8x1 bilinear4 X\n" |
| 1261 "8x1 -> 1x1 bilinear4 X\n"); | 1258 "8x1 -> 1x1 bilinear4 X\n"); |
| 1262 } | 1259 } |
| 1263 | 1260 |
| 1264 std::unique_ptr<gpu::GLInProcessContext> context_; | 1261 std::unique_ptr<gpu::GLInProcessContext> context_; |
| 1265 gpu::gles2::GLES2Interface* gl_; | 1262 gpu::gles2::GLES2Interface* gl_; |
| 1266 std::unique_ptr<content::GLHelper> helper_; | 1263 std::unique_ptr<display_compositor::GLHelper> helper_; |
| 1267 std::unique_ptr<content::GLHelperScaling> helper_scaling_; | 1264 std::unique_ptr<display_compositor::GLHelperScaling> helper_scaling_; |
| 1268 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 1265 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
| 1269 }; | 1266 }; |
| 1270 | 1267 |
| 1271 class GLHelperPixelTest : public GLHelperTest { | 1268 class GLHelperPixelTest : public GLHelperTest { |
| 1272 private: | 1269 private: |
| 1273 gfx::DisableNullDrawGLBindings enable_pixel_output_; | 1270 gfx::DisableNullDrawGLBindings enable_pixel_output_; |
| 1274 }; | 1271 }; |
| 1275 | 1272 |
| 1276 TEST_F(GLHelperTest, RGBASyncReadbackTest) { | 1273 TEST_F(GLHelperTest, RGBASyncReadbackTest) { |
| 1277 const int kTestSize = 64; | 1274 const int kTestSize = 64; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 } | 1394 } |
| 1398 } | 1395 } |
| 1399 } | 1396 } |
| 1400 } | 1397 } |
| 1401 } | 1398 } |
| 1402 | 1399 |
| 1403 // Make sure we don't create overly complicated pipelines | 1400 // Make sure we don't create overly complicated pipelines |
| 1404 // for a few common use cases. | 1401 // for a few common use cases. |
| 1405 TEST_F(GLHelperTest, CheckSpecificPipelines) { | 1402 TEST_F(GLHelperTest, CheckSpecificPipelines) { |
| 1406 // Upscale should be single pass. | 1403 // Upscale should be single pass. |
| 1407 CheckPipeline(content::GLHelper::SCALER_QUALITY_GOOD, 1024, 700, 1280, 720, | 1404 CheckPipeline(display_compositor::GLHelper::SCALER_QUALITY_GOOD, 1024, 700, |
| 1408 "1024x700 -> 1280x720 bilinear\n"); | 1405 1280, 720, "1024x700 -> 1280x720 bilinear\n"); |
| 1409 // Slight downscale should use BILINEAR2X2. | 1406 // Slight downscale should use BILINEAR2X2. |
| 1410 CheckPipeline(content::GLHelper::SCALER_QUALITY_GOOD, 1280, 720, 1024, 700, | 1407 CheckPipeline(display_compositor::GLHelper::SCALER_QUALITY_GOOD, 1280, 720, |
| 1411 "1280x720 -> 1024x700 bilinear2x2\n"); | 1408 1024, 700, "1280x720 -> 1024x700 bilinear2x2\n"); |
| 1412 // Most common tab capture pipeline on the Pixel. | 1409 // Most common tab capture pipeline on the Pixel. |
| 1413 // Should be using two BILINEAR3 passes. | 1410 // Should be using two BILINEAR3 passes. |
| 1414 CheckPipeline(content::GLHelper::SCALER_QUALITY_GOOD, 2560, 1476, 1249, 720, | 1411 CheckPipeline(display_compositor::GLHelper::SCALER_QUALITY_GOOD, 2560, 1476, |
| 1412 1249, 720, |
| 1415 "2560x1476 -> 2560x720 bilinear3 Y\n" | 1413 "2560x1476 -> 2560x720 bilinear3 Y\n" |
| 1416 "2560x720 -> 1249x720 bilinear3 X\n"); | 1414 "2560x720 -> 1249x720 bilinear3 X\n"); |
| 1417 } | 1415 } |
| 1418 | 1416 |
| 1419 TEST_F(GLHelperTest, ScalerOpTest) { | 1417 TEST_F(GLHelperTest, ScalerOpTest) { |
| 1420 for (int allow3 = 0; allow3 <= 1; allow3++) { | 1418 for (int allow3 = 0; allow3 <= 1; allow3++) { |
| 1421 for (int dst = 1; dst < 2049; dst += 1 + (dst >> 3)) { | 1419 for (int dst = 1; dst < 2049; dst += 1 + (dst >> 3)) { |
| 1422 for (int src = 1; src < 2049; src++) { | 1420 for (int src = 1; src < 2049; src++) { |
| 1423 TestAddOps(src, dst, allow3 == 1, (src & 1) == 1); | 1421 TestAddOps(src, dst, allow3 == 1, (src & 1) == 1); |
| 1424 if (HasFailure()) { | 1422 if (HasFailure()) { |
| 1425 LOG(ERROR) << "Failed for src=" << src << " dst=" << dst | 1423 LOG(ERROR) << "Failed for src=" << src << " dst=" << dst |
| 1426 << " allow3=" << allow3; | 1424 << " allow3=" << allow3; |
| 1427 return; | 1425 return; |
| 1428 } | 1426 } |
| 1429 } | 1427 } |
| 1430 } | 1428 } |
| 1431 } | 1429 } |
| 1432 } | 1430 } |
| 1433 | 1431 |
| 1434 TEST_F(GLHelperTest, CheckOptimizations) { | 1432 TEST_F(GLHelperTest, CheckOptimizations) { |
| 1435 // Test in baseclass since it is friends with GLHelperScaling | 1433 // Test in baseclass since it is friends with GLHelperScaling |
| 1436 CheckOptimizationsTest(); | 1434 CheckOptimizationsTest(); |
| 1437 } | 1435 } |
| 1438 | 1436 |
| 1439 } // namespace content | 1437 } // namespace display_compositor |
| OLD | NEW |