OLD | NEW |
1 // Copyright 2016 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> |
(...skipping 12 matching lines...) Expand all Loading... |
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/threading/thread_task_runner_handle.h" | 30 #include "base/threading/thread_task_runner_handle.h" |
31 #include "base/time/time.h" | 31 #include "base/time/time.h" |
32 #include "base/trace_event/trace_event.h" | 32 #include "base/trace_event/trace_event.h" |
33 #include "components/display_compositor/gl_helper.h" | 33 #include "components/viz/display_compositor/gl_helper.h" |
34 #include "components/display_compositor/gl_helper_readback_support.h" | 34 #include "components/viz/display_compositor/gl_helper_readback_support.h" |
35 #include "components/display_compositor/gl_helper_scaling.h" | 35 #include "components/viz/display_compositor/gl_helper_scaling.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 "gpu/ipc/gl_in_process_context.h" | 38 #include "gpu/ipc/gl_in_process_context.h" |
39 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
40 #include "third_party/skia/include/core/SkBitmap.h" | 40 #include "third_party/skia/include/core/SkBitmap.h" |
41 #include "third_party/skia/include/core/SkTypes.h" | 41 #include "third_party/skia/include/core/SkTypes.h" |
42 #include "ui/gl/gl_implementation.h" | 42 #include "ui/gl/gl_implementation.h" |
43 | 43 |
44 namespace display_compositor { | 44 namespace viz { |
45 | 45 |
46 display_compositor::GLHelper::ScalerQuality kQualities[] = { | 46 GLHelper::ScalerQuality kQualities[] = { |
47 display_compositor::GLHelper::SCALER_QUALITY_BEST, | 47 GLHelper::SCALER_QUALITY_BEST, GLHelper::SCALER_QUALITY_GOOD, |
48 display_compositor::GLHelper::SCALER_QUALITY_GOOD, | 48 GLHelper::SCALER_QUALITY_FAST, |
49 display_compositor::GLHelper::SCALER_QUALITY_FAST, | |
50 }; | 49 }; |
51 | 50 |
52 const char* kQualityNames[] = { | 51 const char* kQualityNames[] = { |
53 "best", "good", "fast", | 52 "best", "good", "fast", |
54 }; | 53 }; |
55 | 54 |
56 class GLHelperTest : public testing::Test { | 55 class GLHelperTest : public testing::Test { |
57 protected: | 56 protected: |
58 void SetUp() override { | 57 void SetUp() override { |
59 gpu::gles2::ContextCreationAttribHelper attributes; | 58 gpu::gles2::ContextCreationAttribHelper attributes; |
(...skipping 13 matching lines...) Expand all Loading... |
73 true, /* offscreen */ | 72 true, /* offscreen */ |
74 gpu::kNullSurfaceHandle, /* window */ | 73 gpu::kNullSurfaceHandle, /* window */ |
75 nullptr, /* share_context */ | 74 nullptr, /* share_context */ |
76 attributes, gpu::SharedMemoryLimits(), | 75 attributes, gpu::SharedMemoryLimits(), |
77 nullptr, /* gpu_memory_buffer_manager */ | 76 nullptr, /* gpu_memory_buffer_manager */ |
78 nullptr, /* image_factory */ | 77 nullptr, /* image_factory */ |
79 base::ThreadTaskRunnerHandle::Get())); | 78 base::ThreadTaskRunnerHandle::Get())); |
80 gl_ = context_->GetImplementation(); | 79 gl_ = context_->GetImplementation(); |
81 gpu::ContextSupport* support = context_->GetImplementation(); | 80 gpu::ContextSupport* support = context_->GetImplementation(); |
82 | 81 |
83 helper_.reset(new display_compositor::GLHelper(gl_, support)); | 82 helper_.reset(new GLHelper(gl_, support)); |
84 helper_scaling_.reset( | 83 helper_scaling_.reset(new GLHelperScaling(gl_, helper_.get())); |
85 new display_compositor::GLHelperScaling(gl_, helper_.get())); | |
86 } | 84 } |
87 | 85 |
88 void TearDown() override { | 86 void TearDown() override { |
89 helper_scaling_.reset(nullptr); | 87 helper_scaling_.reset(nullptr); |
90 helper_.reset(nullptr); | 88 helper_.reset(nullptr); |
91 context_.reset(nullptr); | 89 context_.reset(nullptr); |
92 } | 90 } |
93 | 91 |
94 // Bicubic filter kernel function. | 92 // Bicubic filter kernel function. |
95 static float Bicubic(float x) { | 93 static float Bicubic(float x) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // Multi-sample upscale-downscale combination? | 230 // Multi-sample upscale-downscale combination? |
233 if (scale > samples / 2.0 && scale < samples) { | 231 if (scale > samples / 2.0 && scale < samples) { |
234 return true; | 232 return true; |
235 } | 233 } |
236 } | 234 } |
237 return false; | 235 return false; |
238 } | 236 } |
239 | 237 |
240 // Make sure that the stages of the scaler pipeline are sane. | 238 // Make sure that the stages of the scaler pipeline are sane. |
241 void ValidateScalerStages( | 239 void ValidateScalerStages( |
242 display_compositor::GLHelper::ScalerQuality quality, | 240 GLHelper::ScalerQuality quality, |
243 const std::vector<GLHelperScaling::ScalerStage>& scaler_stages, | 241 const std::vector<GLHelperScaling::ScalerStage>& scaler_stages, |
244 const gfx::Size& dst_size, | 242 const gfx::Size& dst_size, |
245 const std::string& message) { | 243 const std::string& message) { |
246 bool previous_error = HasFailure(); | 244 bool previous_error = HasFailure(); |
247 // First, check that the input size for each stage is equal to | 245 // First, check that the input size for each stage is equal to |
248 // the output size of the previous stage. | 246 // the output size of the previous stage. |
249 for (size_t i = 1; i < scaler_stages.size(); i++) { | 247 for (size_t i = 1; i < scaler_stages.size(); i++) { |
250 EXPECT_EQ(scaler_stages[i - 1].dst_size.width(), | 248 EXPECT_EQ(scaler_stages[i - 1].dst_size.width(), |
251 scaler_stages[i].src_size.width()); | 249 scaler_stages[i].src_size.width()); |
252 EXPECT_EQ(scaler_stages[i - 1].dst_size.height(), | 250 EXPECT_EQ(scaler_stages[i - 1].dst_size.height(), |
(...skipping 29 matching lines...) Expand all Loading... |
282 | 280 |
283 // Codify valid scale operations. | 281 // Codify valid scale operations. |
284 switch (scaler_stages[i].shader) { | 282 switch (scaler_stages[i].shader) { |
285 case GLHelperScaling::SHADER_PLANAR: | 283 case GLHelperScaling::SHADER_PLANAR: |
286 case GLHelperScaling::SHADER_YUV_MRT_PASS1: | 284 case GLHelperScaling::SHADER_YUV_MRT_PASS1: |
287 case GLHelperScaling::SHADER_YUV_MRT_PASS2: | 285 case GLHelperScaling::SHADER_YUV_MRT_PASS2: |
288 EXPECT_TRUE(false) << "Invalid shader."; | 286 EXPECT_TRUE(false) << "Invalid shader."; |
289 break; | 287 break; |
290 | 288 |
291 case GLHelperScaling::SHADER_BILINEAR: | 289 case GLHelperScaling::SHADER_BILINEAR: |
292 if (quality != display_compositor::GLHelper::SCALER_QUALITY_FAST) { | 290 if (quality != GLHelper::SCALER_QUALITY_FAST) { |
293 x_samples = 1; | 291 x_samples = 1; |
294 y_samples = 1; | 292 y_samples = 1; |
295 } | 293 } |
296 break; | 294 break; |
297 case GLHelperScaling::SHADER_BILINEAR2: | 295 case GLHelperScaling::SHADER_BILINEAR2: |
298 x_samples = 2; | 296 x_samples = 2; |
299 y_samples = 1; | 297 y_samples = 1; |
300 break; | 298 break; |
301 case GLHelperScaling::SHADER_BILINEAR3: | 299 case GLHelperScaling::SHADER_BILINEAR3: |
302 x_samples = 3; | 300 x_samples = 3; |
(...skipping 25 matching lines...) Expand all Loading... |
328 EXPECT_EQ(y_scale, 2.0); | 326 EXPECT_EQ(y_scale, 2.0); |
329 } | 327 } |
330 break; | 328 break; |
331 } | 329 } |
332 | 330 |
333 if (!scaler_stages[i].scale_x) { | 331 if (!scaler_stages[i].scale_x) { |
334 std::swap(x_samples, y_samples); | 332 std::swap(x_samples, y_samples); |
335 } | 333 } |
336 | 334 |
337 if (x_samples) { | 335 if (x_samples) { |
338 EXPECT_TRUE(CheckScale(x_scale, x_samples, scaled_x)) << "x_scale = " | 336 EXPECT_TRUE(CheckScale(x_scale, x_samples, scaled_x)) |
339 << x_scale; | 337 << "x_scale = " << x_scale; |
340 } | 338 } |
341 if (y_samples) { | 339 if (y_samples) { |
342 EXPECT_TRUE(CheckScale(y_scale, y_samples, scaled_y)) << "y_scale = " | 340 EXPECT_TRUE(CheckScale(y_scale, y_samples, scaled_y)) |
343 << y_scale; | 341 << "y_scale = " << y_scale; |
344 } | 342 } |
345 | 343 |
346 if (x_scale != 1.0) { | 344 if (x_scale != 1.0) { |
347 scaled_x = true; | 345 scaled_x = true; |
348 } | 346 } |
349 if (y_scale != 1.0) { | 347 if (y_scale != 1.0) { |
350 scaled_y = true; | 348 scaled_y = true; |
351 } | 349 } |
352 } | 350 } |
353 | 351 |
(...skipping 23 matching lines...) Expand all Loading... |
377 EXPECT_TRUE(swizzle || truth->colorType() == other->colorType()); | 375 EXPECT_TRUE(swizzle || truth->colorType() == other->colorType()); |
378 int bpp = truth->bytesPerPixel(); | 376 int bpp = truth->bytesPerPixel(); |
379 for (int x = 0; x < truth->width(); x++) { | 377 for (int x = 0; x < truth->width(); x++) { |
380 for (int y = 0; y < truth->height(); y++) { | 378 for (int y = 0; y < truth->height(); y++) { |
381 for (int c = 0; c < bpp; c++) { | 379 for (int c = 0; c < bpp; c++) { |
382 int a = Channel(truth, x, y, c); | 380 int a = Channel(truth, x, y, c); |
383 // swizzle when comparing if needed | 381 // swizzle when comparing if needed |
384 int b = swizzle && (c == 0 || c == 2) | 382 int b = swizzle && (c == 0 || c == 2) |
385 ? Channel(other, x, y, (c + 2) & 2) | 383 ? Channel(other, x, y, (c + 2) & 2) |
386 : Channel(other, x, y, c); | 384 : Channel(other, x, y, c); |
387 EXPECT_NEAR(a, b, maxdiff) << " x=" << x << " y=" << y << " c=" << c | 385 EXPECT_NEAR(a, b, maxdiff) |
388 << " " << message; | 386 << " x=" << x << " y=" << y << " c=" << c << " " << message; |
389 if (std::abs(a - b) > maxdiff) { | 387 if (std::abs(a - b) > maxdiff) { |
390 LOG(ERROR) << "-------expected--------"; | 388 LOG(ERROR) << "-------expected--------"; |
391 for (int i = 0; i < bpp; i++) { | 389 for (int i = 0; i < bpp; i++) { |
392 LOG(ERROR) << "Channel " << i << ":"; | 390 LOG(ERROR) << "Channel " << i << ":"; |
393 PrintChannel(truth, i); | 391 PrintChannel(truth, i); |
394 } | 392 } |
395 LOG(ERROR) << "-------actual--------"; | 393 LOG(ERROR) << "-------actual--------"; |
396 for (int i = 0; i < bpp; i++) { | 394 for (int i = 0; i < bpp; i++) { |
397 LOG(ERROR) << "Channel " << i << ":"; | 395 LOG(ERROR) << "Channel " << i << ":"; |
398 PrintChannel(other, i); | 396 PrintChannel(other, i); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 c2 * kRGBtoGrayscaleColorWeights[2]; | 450 c2 * kRGBtoGrayscaleColorWeights[2]; |
453 SetChannel(output, dst_x, dst_y, 0, | 451 SetChannel(output, dst_x, dst_y, 0, |
454 static_cast<int>(value * 255.0f + 0.5f)); | 452 static_cast<int>(value * 255.0f + 0.5f)); |
455 } | 453 } |
456 } | 454 } |
457 } | 455 } |
458 | 456 |
459 // Very slow bicubic / bilinear scaler for reference. | 457 // Very slow bicubic / bilinear scaler for reference. |
460 void ScaleSlow(SkBitmap* input, | 458 void ScaleSlow(SkBitmap* input, |
461 SkBitmap* output, | 459 SkBitmap* output, |
462 display_compositor::GLHelper::ScalerQuality quality) { | 460 GLHelper::ScalerQuality quality) { |
463 float xscale = static_cast<float>(input->width()) / output->width(); | 461 float xscale = static_cast<float>(input->width()) / output->width(); |
464 float yscale = static_cast<float>(input->height()) / output->height(); | 462 float yscale = static_cast<float>(input->height()) / output->height(); |
465 float clamped_xscale = xscale < 1.0 ? 1.0 : 1.0 / xscale; | 463 float clamped_xscale = xscale < 1.0 ? 1.0 : 1.0 / xscale; |
466 float clamped_yscale = yscale < 1.0 ? 1.0 : 1.0 / yscale; | 464 float clamped_yscale = yscale < 1.0 ? 1.0 : 1.0 / yscale; |
467 for (int dst_y = 0; dst_y < output->height(); dst_y++) { | 465 for (int dst_y = 0; dst_y < output->height(); dst_y++) { |
468 for (int dst_x = 0; dst_x < output->width(); dst_x++) { | 466 for (int dst_x = 0; dst_x < output->width(); dst_x++) { |
469 for (int channel = 0; channel < 4; channel++) { | 467 for (int channel = 0; channel < 4; channel++) { |
470 float dst_x_in_src = (dst_x + 0.5f) * xscale; | 468 float dst_x_in_src = (dst_x + 0.5f) * xscale; |
471 float dst_y_in_src = (dst_y + 0.5f) * yscale; | 469 float dst_y_in_src = (dst_y + 0.5f) * yscale; |
472 | 470 |
473 float value = 0.0f; | 471 float value = 0.0f; |
474 float sum = 0.0f; | 472 float sum = 0.0f; |
475 switch (quality) { | 473 switch (quality) { |
476 case display_compositor::GLHelper::SCALER_QUALITY_BEST: | 474 case GLHelper::SCALER_QUALITY_BEST: |
477 for (int src_y = -10; src_y < input->height() + 10; ++src_y) { | 475 for (int src_y = -10; src_y < input->height() + 10; ++src_y) { |
478 float coeff_y = | 476 float coeff_y = |
479 Bicubic((src_y + 0.5f - dst_y_in_src) * clamped_yscale); | 477 Bicubic((src_y + 0.5f - dst_y_in_src) * clamped_yscale); |
480 if (coeff_y == 0.0f) { | 478 if (coeff_y == 0.0f) { |
481 continue; | 479 continue; |
482 } | 480 } |
483 for (int src_x = -10; src_x < input->width() + 10; ++src_x) { | 481 for (int src_x = -10; src_x < input->width() + 10; ++src_x) { |
484 float coeff = | 482 float coeff = |
485 coeff_y * | 483 coeff_y * |
486 Bicubic((src_x + 0.5f - dst_x_in_src) * clamped_xscale); | 484 Bicubic((src_x + 0.5f - dst_x_in_src) * clamped_xscale); |
487 if (coeff == 0.0f) { | 485 if (coeff == 0.0f) { |
488 continue; | 486 continue; |
489 } | 487 } |
490 sum += coeff; | 488 sum += coeff; |
491 float c = ChannelAsFloat(input, src_x, src_y, channel); | 489 float c = ChannelAsFloat(input, src_x, src_y, channel); |
492 value += c * coeff; | 490 value += c * coeff; |
493 } | 491 } |
494 } | 492 } |
495 break; | 493 break; |
496 | 494 |
497 case display_compositor::GLHelper::SCALER_QUALITY_GOOD: { | 495 case GLHelper::SCALER_QUALITY_GOOD: { |
498 int xshift = 0, yshift = 0; | 496 int xshift = 0, yshift = 0; |
499 while ((output->width() << xshift) < input->width()) { | 497 while ((output->width() << xshift) < input->width()) { |
500 xshift++; | 498 xshift++; |
501 } | 499 } |
502 while ((output->height() << yshift) < input->height()) { | 500 while ((output->height() << yshift) < input->height()) { |
503 yshift++; | 501 yshift++; |
504 } | 502 } |
505 int xmag = 1 << xshift; | 503 int xmag = 1 << xshift; |
506 int ymag = 1 << yshift; | 504 int ymag = 1 << yshift; |
507 if (xmag == 4 && output->width() * 3 >= input->width()) { | 505 if (xmag == 4 && output->width() * 3 >= input->width()) { |
508 xmag = 3; | 506 xmag = 3; |
509 } | 507 } |
510 if (ymag == 4 && output->height() * 3 >= input->height()) { | 508 if (ymag == 4 && output->height() * 3 >= input->height()) { |
511 ymag = 3; | 509 ymag = 3; |
512 } | 510 } |
513 for (int x = 0; x < xmag; x++) { | 511 for (int x = 0; x < xmag; x++) { |
514 for (int y = 0; y < ymag; y++) { | 512 for (int y = 0; y < ymag; y++) { |
515 value += Bilinear( | 513 value += Bilinear( |
516 input, (dst_x * xmag + x + 0.5) * xscale / xmag, | 514 input, (dst_x * xmag + x + 0.5) * xscale / xmag, |
517 (dst_y * ymag + y + 0.5) * yscale / ymag, channel); | 515 (dst_y * ymag + y + 0.5) * yscale / ymag, channel); |
518 sum += 1.0; | 516 sum += 1.0; |
519 } | 517 } |
520 } | 518 } |
521 break; | 519 break; |
522 } | 520 } |
523 | 521 |
524 case display_compositor::GLHelper::SCALER_QUALITY_FAST: | 522 case GLHelper::SCALER_QUALITY_FAST: |
525 value = Bilinear(input, dst_x_in_src, dst_y_in_src, channel); | 523 value = Bilinear(input, dst_x_in_src, dst_y_in_src, channel); |
526 sum = 1.0; | 524 sum = 1.0; |
527 } | 525 } |
528 value /= sum; | 526 value /= sum; |
529 SetChannel(output, dst_x, dst_y, channel, | 527 SetChannel(output, dst_x, dst_y, channel, |
530 static_cast<int>(value * 255.0f + 0.5f)); | 528 static_cast<int>(value * 255.0f + 0.5f)); |
531 } | 529 } |
532 } | 530 } |
533 } | 531 } |
534 } | 532 } |
(...skipping 11 matching lines...) Expand all Loading... |
546 *bitmap->getAddr8(x, bottom_line)); | 544 *bitmap->getAddr8(x, bottom_line)); |
547 } | 545 } |
548 top_line++; | 546 top_line++; |
549 bottom_line--; | 547 bottom_line--; |
550 } | 548 } |
551 } | 549 } |
552 | 550 |
553 // Swaps red and blue channels in each pixel in a 32-bit bitmap. | 551 // Swaps red and blue channels in each pixel in a 32-bit bitmap. |
554 void SwizzleSKBitmap(SkBitmap* bitmap) { | 552 void SwizzleSKBitmap(SkBitmap* bitmap) { |
555 int bpp = bitmap->bytesPerPixel(); | 553 int bpp = bitmap->bytesPerPixel(); |
556 DCHECK(bpp == 4); | 554 DCHECK_EQ(bpp, 4); |
557 for (int y = 0; y < bitmap->height(); y++) { | 555 for (int y = 0; y < bitmap->height(); y++) { |
558 for (int x = 0; x < bitmap->width(); x++) { | 556 for (int x = 0; x < bitmap->width(); x++) { |
559 // Swap channels 0 and 2 (red and blue) | 557 // Swap channels 0 and 2 (red and blue) |
560 int c0 = Channel(bitmap, x, y, 0); | 558 int c0 = Channel(bitmap, x, y, 0); |
561 int c2 = Channel(bitmap, x, y, 2); | 559 int c2 = Channel(bitmap, x, y, 2); |
562 SetChannel(bitmap, x, y, 2, c0); | 560 SetChannel(bitmap, x, y, 2, c0); |
563 SetChannel(bitmap, x, y, 0, c2); | 561 SetChannel(bitmap, x, y, 0, c2); |
564 } | 562 } |
565 } | 563 } |
566 } | 564 } |
567 | 565 |
568 // gl_helper scales recursively, so we'll need to do that | 566 // gl_helper scales recursively, so we'll need to do that |
569 // in the reference implementation too. | 567 // in the reference implementation too. |
570 void ScaleSlowRecursive(SkBitmap* input, | 568 void ScaleSlowRecursive(SkBitmap* input, |
571 SkBitmap* output, | 569 SkBitmap* output, |
572 display_compositor::GLHelper::ScalerQuality quality) { | 570 GLHelper::ScalerQuality quality) { |
573 if (quality == display_compositor::GLHelper::SCALER_QUALITY_FAST || | 571 if (quality == GLHelper::SCALER_QUALITY_FAST || |
574 quality == display_compositor::GLHelper::SCALER_QUALITY_GOOD) { | 572 quality == GLHelper::SCALER_QUALITY_GOOD) { |
575 ScaleSlow(input, output, quality); | 573 ScaleSlow(input, output, quality); |
576 return; | 574 return; |
577 } | 575 } |
578 | 576 |
579 float xscale = static_cast<float>(output->width()) / input->width(); | 577 float xscale = static_cast<float>(output->width()) / input->width(); |
580 | 578 |
581 // This corresponds to all the operations we can do directly. | 579 // This corresponds to all the operations we can do directly. |
582 float yscale = static_cast<float>(output->height()) / input->height(); | 580 float yscale = static_cast<float>(output->height()) / input->height(); |
583 if ((xscale == 1.0f && yscale == 1.0f) || | 581 if ((xscale == 1.0f && yscale == 1.0f) || |
584 (xscale == 0.5f && yscale == 1.0f) || | 582 (xscale == 0.5f && yscale == 1.0f) || |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 gfx::Size(dst_xsize, dst_ysize), | 831 gfx::Size(dst_xsize, dst_ysize), |
834 base::StringPrintf("input size: %dx%d " | 832 base::StringPrintf("input size: %dx%d " |
835 "output size: %dx%d " | 833 "output size: %dx%d " |
836 "quality: %s", | 834 "quality: %s", |
837 xsize, ysize, dst_xsize, dst_ysize, | 835 xsize, ysize, dst_xsize, dst_ysize, |
838 kQualityNames[quality])); | 836 kQualityNames[quality])); |
839 } | 837 } |
840 | 838 |
841 // Create a scaling pipeline and make sure that the steps | 839 // Create a scaling pipeline and make sure that the steps |
842 // are exactly the steps we expect. | 840 // are exactly the steps we expect. |
843 void CheckPipeline(display_compositor::GLHelper::ScalerQuality quality, | 841 void CheckPipeline(GLHelper::ScalerQuality quality, |
844 int xsize, | 842 int xsize, |
845 int ysize, | 843 int ysize, |
846 int dst_xsize, | 844 int dst_xsize, |
847 int dst_ysize, | 845 int dst_ysize, |
848 const std::string& description) { | 846 const std::string& description) { |
849 std::vector<GLHelperScaling::ScalerStage> stages; | 847 std::vector<GLHelperScaling::ScalerStage> stages; |
850 helper_scaling_->ComputeScalerStages( | 848 helper_scaling_->ComputeScalerStages( |
851 quality, gfx::Size(xsize, ysize), gfx::Rect(0, 0, xsize, ysize), | 849 quality, gfx::Size(xsize, ysize), gfx::Rect(0, 0, xsize, ysize), |
852 gfx::Size(dst_xsize, dst_ysize), false, false, &stages); | 850 gfx::Size(dst_xsize, dst_ysize), false, false, &stages); |
853 ValidateScalerStages(display_compositor::GLHelper::SCALER_QUALITY_GOOD, | 851 ValidateScalerStages(GLHelper::SCALER_QUALITY_GOOD, stages, |
854 stages, gfx::Size(dst_xsize, dst_ysize), ""); | 852 gfx::Size(dst_xsize, dst_ysize), ""); |
855 EXPECT_EQ(PrintStages(stages), description); | 853 EXPECT_EQ(PrintStages(stages), description); |
856 } | 854 } |
857 | 855 |
858 static void callcallback(const base::Callback<void()>& callback, | 856 static void callcallback(const base::Callback<void()>& callback, |
859 bool result) { | 857 bool result) { |
860 callback.Run(); | 858 callback.Run(); |
861 } | 859 } |
862 | 860 |
863 void DrawGridToBitmap(int w, | 861 void DrawGridToBitmap(int w, |
864 int h, | 862 int h, |
865 SkColor background_color, | 863 SkColor background_color, |
866 SkColor grid_color, | 864 SkColor grid_color, |
867 int grid_pitch, | 865 int grid_pitch, |
868 int grid_width, | 866 int grid_width, |
869 SkBitmap& bmp) { | 867 const SkBitmap& bmp) { |
870 ASSERT_GT(grid_pitch, 0); | 868 ASSERT_GT(grid_pitch, 0); |
871 ASSERT_GT(grid_width, 0); | 869 ASSERT_GT(grid_width, 0); |
872 ASSERT_NE(background_color, grid_color); | 870 ASSERT_NE(background_color, grid_color); |
873 | 871 |
874 for (int y = 0; y < h; ++y) { | 872 for (int y = 0; y < h; ++y) { |
875 bool y_on_grid = ((y % grid_pitch) < grid_width); | 873 bool y_on_grid = ((y % grid_pitch) < grid_width); |
876 | 874 |
877 for (int x = 0; x < w; ++x) { | 875 for (int x = 0; x < w; ++x) { |
878 bool on_grid = (y_on_grid || ((x % grid_pitch) < grid_width)); | 876 bool on_grid = (y_on_grid || ((x % grid_pitch) < grid_width)); |
879 | 877 |
880 if (bmp.colorType() == kRGBA_8888_SkColorType || | 878 if (bmp.colorType() == kRGBA_8888_SkColorType || |
881 bmp.colorType() == kBGRA_8888_SkColorType) { | 879 bmp.colorType() == kBGRA_8888_SkColorType) { |
882 *bmp.getAddr32(x, y) = (on_grid ? grid_color : background_color); | 880 *bmp.getAddr32(x, y) = (on_grid ? grid_color : background_color); |
883 } else if (bmp.colorType() == kRGB_565_SkColorType) { | 881 } else if (bmp.colorType() == kRGB_565_SkColorType) { |
884 *bmp.getAddr16(x, y) = (on_grid ? grid_color : background_color); | 882 *bmp.getAddr16(x, y) = (on_grid ? grid_color : background_color); |
885 } | 883 } |
886 } | 884 } |
887 } | 885 } |
888 } | 886 } |
889 | 887 |
890 void DrawCheckerToBitmap(int w, | 888 void DrawCheckerToBitmap(int w, |
891 int h, | 889 int h, |
892 SkColor color1, | 890 SkColor color1, |
893 SkColor color2, | 891 SkColor color2, |
894 int rect_w, | 892 int rect_w, |
895 int rect_h, | 893 int rect_h, |
896 SkBitmap& bmp) { | 894 const SkBitmap& bmp) { |
897 ASSERT_GT(rect_w, 0); | 895 ASSERT_GT(rect_w, 0); |
898 ASSERT_GT(rect_h, 0); | 896 ASSERT_GT(rect_h, 0); |
899 ASSERT_NE(color1, color2); | 897 ASSERT_NE(color1, color2); |
900 | 898 |
901 for (int y = 0; y < h; ++y) { | 899 for (int y = 0; y < h; ++y) { |
902 bool y_bit = (((y / rect_h) & 0x1) == 0); | 900 bool y_bit = (((y / rect_h) & 0x1) == 0); |
903 | 901 |
904 for (int x = 0; x < w; ++x) { | 902 for (int x = 0; x < w; ++x) { |
905 bool x_bit = (((x / rect_w) & 0x1) == 0); | 903 bool x_bit = (((x / rect_w) & 0x1) == 0); |
906 | 904 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 EXPECT_EQ(tmp, src); | 1117 EXPECT_EQ(tmp, src); |
1120 } | 1118 } |
1121 | 1119 |
1122 void CheckPipeline2(int xsize, | 1120 void CheckPipeline2(int xsize, |
1123 int ysize, | 1121 int ysize, |
1124 int dst_xsize, | 1122 int dst_xsize, |
1125 int dst_ysize, | 1123 int dst_ysize, |
1126 const std::string& description) { | 1124 const std::string& description) { |
1127 std::vector<GLHelperScaling::ScalerStage> stages; | 1125 std::vector<GLHelperScaling::ScalerStage> stages; |
1128 helper_scaling_->ConvertScalerOpsToScalerStages( | 1126 helper_scaling_->ConvertScalerOpsToScalerStages( |
1129 display_compositor::GLHelper::SCALER_QUALITY_GOOD, | 1127 GLHelper::SCALER_QUALITY_GOOD, gfx::Size(xsize, ysize), |
1130 gfx::Size(xsize, ysize), gfx::Rect(0, 0, xsize, ysize), | 1128 gfx::Rect(0, 0, xsize, ysize), gfx::Size(dst_xsize, dst_ysize), false, |
1131 gfx::Size(dst_xsize, dst_ysize), false, false, &x_ops_, &y_ops_, | 1129 false, &x_ops_, &y_ops_, &stages); |
1132 &stages); | |
1133 EXPECT_EQ(x_ops_.size(), 0U); | 1130 EXPECT_EQ(x_ops_.size(), 0U); |
1134 EXPECT_EQ(y_ops_.size(), 0U); | 1131 EXPECT_EQ(y_ops_.size(), 0U); |
1135 ValidateScalerStages(display_compositor::GLHelper::SCALER_QUALITY_GOOD, | 1132 ValidateScalerStages(GLHelper::SCALER_QUALITY_GOOD, stages, |
1136 stages, gfx::Size(dst_xsize, dst_ysize), ""); | 1133 gfx::Size(dst_xsize, dst_ysize), ""); |
1137 EXPECT_EQ(PrintStages(stages), description); | 1134 EXPECT_EQ(PrintStages(stages), description); |
1138 } | 1135 } |
1139 | 1136 |
1140 void CheckOptimizationsTest() { | 1137 void CheckOptimizationsTest() { |
1141 // Basic upscale. X and Y should be combined into one pass. | 1138 // Basic upscale. X and Y should be combined into one pass. |
1142 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 2000)); | 1139 x_ops_.push_back(GLHelperScaling::ScaleOp(0, true, 2000)); |
1143 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 2000)); | 1140 y_ops_.push_back(GLHelperScaling::ScaleOp(0, false, 2000)); |
1144 CheckPipeline2(1024, 768, 2000, 2000, "1024x768 -> 2000x2000 bilinear\n"); | 1141 CheckPipeline2(1024, 768, 2000, 2000, "1024x768 -> 2000x2000 bilinear\n"); |
1145 | 1142 |
1146 // X scaled 1/2, Y upscaled, should still be one pass. | 1143 // X scaled 1/2, Y upscaled, should still be one pass. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 CheckPipeline2(100, 100, 1, 1, | 1246 CheckPipeline2(100, 100, 1, 1, |
1250 "100x100 -> 100x32 bilinear4 Y\n" | 1247 "100x100 -> 100x32 bilinear4 Y\n" |
1251 "100x32 -> 100x4 bilinear4 Y\n" | 1248 "100x32 -> 100x4 bilinear4 Y\n" |
1252 "100x4 -> 64x1 bilinear2x2\n" | 1249 "100x4 -> 64x1 bilinear2x2\n" |
1253 "64x1 -> 8x1 bilinear4 X\n" | 1250 "64x1 -> 8x1 bilinear4 X\n" |
1254 "8x1 -> 1x1 bilinear4 X\n"); | 1251 "8x1 -> 1x1 bilinear4 X\n"); |
1255 } | 1252 } |
1256 | 1253 |
1257 std::unique_ptr<gpu::GLInProcessContext> context_; | 1254 std::unique_ptr<gpu::GLInProcessContext> context_; |
1258 gpu::gles2::GLES2Interface* gl_; | 1255 gpu::gles2::GLES2Interface* gl_; |
1259 std::unique_ptr<display_compositor::GLHelper> helper_; | 1256 std::unique_ptr<GLHelper> helper_; |
1260 std::unique_ptr<display_compositor::GLHelperScaling> helper_scaling_; | 1257 std::unique_ptr<GLHelperScaling> helper_scaling_; |
1261 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; | 1258 std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_; |
1262 base::MessageLoop message_loop_; | 1259 base::MessageLoop message_loop_; |
1263 }; | 1260 }; |
1264 | 1261 |
1265 class GLHelperPixelTest : public GLHelperTest { | 1262 class GLHelperPixelTest : public GLHelperTest { |
1266 private: | 1263 private: |
1267 gl::DisableNullDrawGLBindings enable_pixel_output_; | 1264 gl::DisableNullDrawGLBindings enable_pixel_output_; |
1268 }; | 1265 }; |
1269 | 1266 |
1270 TEST_F(GLHelperTest, RGBASyncReadbackTest) { | 1267 TEST_F(GLHelperTest, RGBASyncReadbackTest) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 } | 1388 } |
1392 } | 1389 } |
1393 } | 1390 } |
1394 } | 1391 } |
1395 } | 1392 } |
1396 | 1393 |
1397 // Make sure we don't create overly complicated pipelines | 1394 // Make sure we don't create overly complicated pipelines |
1398 // for a few common use cases. | 1395 // for a few common use cases. |
1399 TEST_F(GLHelperTest, CheckSpecificPipelines) { | 1396 TEST_F(GLHelperTest, CheckSpecificPipelines) { |
1400 // Upscale should be single pass. | 1397 // Upscale should be single pass. |
1401 CheckPipeline(display_compositor::GLHelper::SCALER_QUALITY_GOOD, 1024, 700, | 1398 CheckPipeline(GLHelper::SCALER_QUALITY_GOOD, 1024, 700, 1280, 720, |
1402 1280, 720, "1024x700 -> 1280x720 bilinear\n"); | 1399 "1024x700 -> 1280x720 bilinear\n"); |
1403 // Slight downscale should use BILINEAR2X2. | 1400 // Slight downscale should use BILINEAR2X2. |
1404 CheckPipeline(display_compositor::GLHelper::SCALER_QUALITY_GOOD, 1280, 720, | 1401 CheckPipeline(GLHelper::SCALER_QUALITY_GOOD, 1280, 720, 1024, 700, |
1405 1024, 700, "1280x720 -> 1024x700 bilinear2x2\n"); | 1402 "1280x720 -> 1024x700 bilinear2x2\n"); |
1406 // Most common tab capture pipeline on the Pixel. | 1403 // Most common tab capture pipeline on the Pixel. |
1407 // Should be using two BILINEAR3 passes. | 1404 // Should be using two BILINEAR3 passes. |
1408 CheckPipeline(display_compositor::GLHelper::SCALER_QUALITY_GOOD, 2560, 1476, | 1405 CheckPipeline(GLHelper::SCALER_QUALITY_GOOD, 2560, 1476, 1249, 720, |
1409 1249, 720, | |
1410 "2560x1476 -> 2560x720 bilinear3 Y\n" | 1406 "2560x1476 -> 2560x720 bilinear3 Y\n" |
1411 "2560x720 -> 1249x720 bilinear3 X\n"); | 1407 "2560x720 -> 1249x720 bilinear3 X\n"); |
1412 } | 1408 } |
1413 | 1409 |
1414 TEST_F(GLHelperTest, ScalerOpTest) { | 1410 TEST_F(GLHelperTest, ScalerOpTest) { |
1415 for (int allow3 = 0; allow3 <= 1; allow3++) { | 1411 for (int allow3 = 0; allow3 <= 1; allow3++) { |
1416 for (int dst = 1; dst < 2049; dst += 1 + (dst >> 3)) { | 1412 for (int dst = 1; dst < 2049; dst += 1 + (dst >> 3)) { |
1417 for (int src = 1; src < 2049; src++) { | 1413 for (int src = 1; src < 2049; src++) { |
1418 TestAddOps(src, dst, allow3 == 1, (src & 1) == 1); | 1414 TestAddOps(src, dst, allow3 == 1, (src & 1) == 1); |
1419 if (HasFailure()) { | 1415 if (HasFailure()) { |
1420 LOG(ERROR) << "Failed for src=" << src << " dst=" << dst | 1416 LOG(ERROR) << "Failed for src=" << src << " dst=" << dst |
1421 << " allow3=" << allow3; | 1417 << " allow3=" << allow3; |
1422 return; | 1418 return; |
1423 } | 1419 } |
1424 } | 1420 } |
1425 } | 1421 } |
1426 } | 1422 } |
1427 } | 1423 } |
1428 | 1424 |
1429 TEST_F(GLHelperTest, CheckOptimizations) { | 1425 TEST_F(GLHelperTest, CheckOptimizations) { |
1430 // Test in baseclass since it is friends with GLHelperScaling | 1426 // Test in baseclass since it is friends with GLHelperScaling |
1431 CheckOptimizationsTest(); | 1427 CheckOptimizationsTest(); |
1432 } | 1428 } |
1433 | 1429 |
1434 } // namespace display_compositor | 1430 } // namespace viz |
OLD | NEW |