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

Side by Side Diff: components/viz/display_compositor/yuv_readback_unittest.cc

Issue 2873243002: Move components/display_compositor to components/viz/display_compositor (Closed)
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/memory/ref_counted_memory.h" 6 #include "base/memory/ref_counted_memory.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/test/launcher/unit_test_launcher.h" 9 #include "base/test/launcher/unit_test_launcher.h"
10 #include "base/test/scoped_task_environment.h" 10 #include "base/test/scoped_task_environment.h"
11 #include "base/test/test_suite.h" 11 #include "base/test/test_suite.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "components/display_compositor/gl_helper.h" 14 #include "components/viz/display_compositor/gl_helper.h"
15 #include "gpu/command_buffer/client/gles2_implementation.h" 15 #include "gpu/command_buffer/client/gles2_implementation.h"
16 #include "gpu/command_buffer/client/shared_memory_limits.h" 16 #include "gpu/command_buffer/client/shared_memory_limits.h"
17 #include "gpu/ipc/common/surface_handle.h" 17 #include "gpu/ipc/common/surface_handle.h"
18 #include "gpu/ipc/gl_in_process_context.h" 18 #include "gpu/ipc/gl_in_process_context.h"
19 #include "media/base/video_frame.h" 19 #include "media/base/video_frame.h"
20 #include "media/base/video_util.h" 20 #include "media/base/video_util.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
23 #include "ui/gl/gl_implementation.h" 23 #include "ui/gl/gl_implementation.h"
24 24
25 namespace display_compositor { 25 namespace viz {
26 26
27 namespace { 27 namespace {
28 int kYUVReadbackSizes[] = {2, 4, 14}; 28 int kYUVReadbackSizes[] = {2, 4, 14};
29 } 29 }
30 30
31 class YUVReadbackTest : public testing::Test { 31 class YUVReadbackTest : public testing::Test {
32 protected: 32 protected:
33 void SetUp() override { 33 void SetUp() override {
34 gpu::gles2::ContextCreationAttribHelper attributes; 34 gpu::gles2::ContextCreationAttribHelper attributes;
35 attributes.alpha_size = 8; 35 attributes.alpha_size = 8;
(...skipping 12 matching lines...) Expand all
48 true, /* offscreen */ 48 true, /* offscreen */
49 gpu::kNullSurfaceHandle, /* window */ 49 gpu::kNullSurfaceHandle, /* window */
50 nullptr, /* share_context */ 50 nullptr, /* share_context */
51 attributes, gpu::SharedMemoryLimits(), 51 attributes, gpu::SharedMemoryLimits(),
52 nullptr, /* gpu_memory_buffer_manager */ 52 nullptr, /* gpu_memory_buffer_manager */
53 nullptr, /* image_factory */ 53 nullptr, /* image_factory */
54 base::ThreadTaskRunnerHandle::Get())); 54 base::ThreadTaskRunnerHandle::Get()));
55 gl_ = context_->GetImplementation(); 55 gl_ = context_->GetImplementation();
56 gpu::ContextSupport* support = context_->GetImplementation(); 56 gpu::ContextSupport* support = context_->GetImplementation();
57 57
58 helper_.reset(new display_compositor::GLHelper(gl_, support)); 58 helper_.reset(new GLHelper(gl_, support));
59 } 59 }
60 60
61 void TearDown() override { 61 void TearDown() override {
62 helper_.reset(NULL); 62 helper_.reset(NULL);
63 context_.reset(NULL); 63 context_.reset(NULL);
64 } 64 }
65 65
66 void StartTracing(const std::string& filter) { 66 void StartTracing(const std::string& filter) {
67 base::trace_event::TraceLog::GetInstance()->SetEnabled( 67 base::trace_event::TraceLog::GetInstance()->SetEnabled(
68 base::trace_event::TraceConfig(filter, 68 base::trace_event::TraceConfig(filter,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 int other_stride, 277 int other_stride,
278 int maxdiff, 278 int maxdiff,
279 int xsize, 279 int xsize,
280 int ysize, 280 int ysize,
281 SkBitmap* source, 281 SkBitmap* source,
282 std::string message) { 282 std::string message) {
283 for (int x = 0; x < xsize; x++) { 283 for (int x = 0; x < xsize; x++) {
284 for (int y = 0; y < ysize; y++) { 284 for (int y = 0; y < ysize; y++) {
285 int a = other[y * other_stride + x]; 285 int a = other[y * other_stride + x];
286 int b = truth[y * truth_stride + x]; 286 int b = truth[y * truth_stride + x];
287 EXPECT_NEAR(a, b, maxdiff) << " x=" << x << " y=" << y << " " 287 EXPECT_NEAR(a, b, maxdiff)
288 << message; 288 << " x=" << x << " y=" << y << " " << message;
289 if (std::abs(a - b) > maxdiff) { 289 if (std::abs(a - b) > maxdiff) {
290 LOG(ERROR) << "-------expected--------"; 290 LOG(ERROR) << "-------expected--------";
291 PrintPlane(truth, xsize, truth_stride, ysize); 291 PrintPlane(truth, xsize, truth_stride, ysize);
292 LOG(ERROR) << "-------actual--------"; 292 LOG(ERROR) << "-------actual--------";
293 PrintPlane(other, xsize, other_stride, ysize); 293 PrintPlane(other, xsize, other_stride, ysize);
294 if (source) { 294 if (source) {
295 LOG(ERROR) << "-------before yuv conversion: red--------"; 295 LOG(ERROR) << "-------before yuv conversion: red--------";
296 PrintChannel(source, 0); 296 PrintChannel(source, 0);
297 LOG(ERROR) << "-------before yuv conversion: green------"; 297 LOG(ERROR) << "-------before yuv conversion: green------";
298 PrintChannel(source, 1); 298 PrintChannel(source, 1);
(...skipping 11 matching lines...) Expand all
310 // returns. 310 // returns.
311 void TestYUVReadback(int xsize, 311 void TestYUVReadback(int xsize,
312 int ysize, 312 int ysize,
313 int output_xsize, 313 int output_xsize,
314 int output_ysize, 314 int output_ysize,
315 int xmargin, 315 int xmargin,
316 int ymargin, 316 int ymargin,
317 int test_pattern, 317 int test_pattern,
318 bool flip, 318 bool flip,
319 bool use_mrt, 319 bool use_mrt,
320 display_compositor::GLHelper::ScalerQuality quality) { 320 GLHelper::ScalerQuality quality) {
321 GLuint src_texture; 321 GLuint src_texture;
322 gl_->GenTextures(1, &src_texture); 322 gl_->GenTextures(1, &src_texture);
323 SkBitmap input_pixels; 323 SkBitmap input_pixels;
324 input_pixels.allocN32Pixels(xsize, ysize); 324 input_pixels.allocN32Pixels(xsize, ysize);
325 325
326 for (int x = 0; x < xsize; ++x) { 326 for (int x = 0; x < xsize; ++x) {
327 for (int y = 0; y < ysize; ++y) { 327 for (int y = 0; y < ysize; ++y) {
328 switch (test_pattern) { 328 switch (test_pattern) {
329 case 0: // Smooth test pattern 329 case 0: // Smooth test pattern
330 SetChannel(&input_pixels, x, y, 0, x * 10); 330 SetChannel(&input_pixels, x, y, 0, x * 10);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 ComparePlane( 468 ComparePlane(
469 V, v_stride, output_frame->visible_data(media::VideoFrame::kVPlane), 469 V, v_stride, output_frame->visible_data(media::VideoFrame::kVPlane),
470 output_frame->stride(media::VideoFrame::kVPlane), 2, output_xsize / 2, 470 output_frame->stride(media::VideoFrame::kVPlane), 2, output_xsize / 2,
471 output_ysize / 2, &input_pixels, message + " V plane"); 471 output_ysize / 2, &input_pixels, message + " V plane");
472 472
473 gl_->DeleteTextures(1, &src_texture); 473 gl_->DeleteTextures(1, &src_texture);
474 } 474 }
475 475
476 std::unique_ptr<gpu::GLInProcessContext> context_; 476 std::unique_ptr<gpu::GLInProcessContext> context_;
477 gpu::gles2::GLES2Interface* gl_; 477 gpu::gles2::GLES2Interface* gl_;
478 std::unique_ptr<display_compositor::GLHelper> helper_; 478 std::unique_ptr<GLHelper> helper_;
479 gl::DisableNullDrawGLBindings enable_pixel_output_; 479 gl::DisableNullDrawGLBindings enable_pixel_output_;
480 base::test::ScopedTaskEnvironment scoped_task_environment_; 480 base::test::ScopedTaskEnvironment scoped_task_environment_;
481 }; 481 };
482 482
483 TEST_F(YUVReadbackTest, YUVReadbackOptTest) { 483 TEST_F(YUVReadbackTest, YUVReadbackOptTest) {
484 // This test uses the gpu.service/gpu_decoder tracing events to detect how 484 // This test uses the gpu.service/gpu_decoder tracing events to detect how
485 // many scaling passes are actually performed by the YUV readback pipeline. 485 // many scaling passes are actually performed by the YUV readback pipeline.
486 StartTracing(TRACE_DISABLED_BY_DEFAULT( 486 StartTracing(TRACE_DISABLED_BY_DEFAULT(
487 "gpu.service") "," TRACE_DISABLED_BY_DEFAULT("gpu_decoder")); 487 "gpu.service") "," TRACE_DISABLED_BY_DEFAULT("gpu_decoder"));
488 488
489 TestYUVReadback(800, 400, 800, 400, 0, 0, 1, false, true, 489 TestYUVReadback(800, 400, 800, 400, 0, 0, 1, false, true,
490 display_compositor::GLHelper::SCALER_QUALITY_FAST); 490 GLHelper::SCALER_QUALITY_FAST);
491 491
492 std::map<std::string, int> event_counts; 492 std::map<std::string, int> event_counts;
493 EndTracing(&event_counts); 493 EndTracing(&event_counts);
494 int draw_buffer_calls = event_counts["kDrawBuffersEXTImmediate"]; 494 int draw_buffer_calls = event_counts["kDrawBuffersEXTImmediate"];
495 int draw_arrays_calls = event_counts["kDrawArrays"]; 495 int draw_arrays_calls = event_counts["kDrawArrays"];
496 VLOG(1) << "Draw buffer calls: " << draw_buffer_calls; 496 VLOG(1) << "Draw buffer calls: " << draw_buffer_calls;
497 VLOG(1) << "DrawArrays calls: " << draw_arrays_calls; 497 VLOG(1) << "DrawArrays calls: " << draw_arrays_calls;
498 498
499 if (draw_buffer_calls) { 499 if (draw_buffer_calls) {
500 // When using MRT, the YUV readback code should only 500 // When using MRT, the YUV readback code should only
(...skipping 26 matching lines...) Expand all
527 for (Margin xm = x < ox ? MarginLeft : MarginRight; xm <= MarginRight; 527 for (Margin xm = x < ox ? MarginLeft : MarginRight; xm <= MarginRight;
528 xm = NextMargin(xm)) { 528 xm = NextMargin(xm)) {
529 for (Margin ym = y < oy ? MarginLeft : MarginRight; ym <= MarginRight; 529 for (Margin ym = y < oy ? MarginLeft : MarginRight; ym <= MarginRight;
530 ym = NextMargin(ym)) { 530 ym = NextMargin(ym)) {
531 for (int pattern = 0; pattern < 3; pattern++) { 531 for (int pattern = 0; pattern < 3; pattern++) {
532 TestYUVReadback( 532 TestYUVReadback(
533 kYUVReadbackSizes[x], kYUVReadbackSizes[y], 533 kYUVReadbackSizes[x], kYUVReadbackSizes[y],
534 kYUVReadbackSizes[ox], kYUVReadbackSizes[oy], 534 kYUVReadbackSizes[ox], kYUVReadbackSizes[oy],
535 compute_margin(kYUVReadbackSizes[x], kYUVReadbackSizes[ox], xm), 535 compute_margin(kYUVReadbackSizes[x], kYUVReadbackSizes[ox], xm),
536 compute_margin(kYUVReadbackSizes[y], kYUVReadbackSizes[oy], ym), 536 compute_margin(kYUVReadbackSizes[y], kYUVReadbackSizes[oy], ym),
537 pattern, flip, use_mrt, 537 pattern, flip, use_mrt, GLHelper::SCALER_QUALITY_GOOD);
538 display_compositor::GLHelper::SCALER_QUALITY_GOOD);
539 if (HasFailure()) { 538 if (HasFailure()) {
540 return; 539 return;
541 } 540 }
542 } 541 }
543 } 542 }
544 } 543 }
545 } 544 }
546 } 545 }
547 } 546 }
548 547
549 // First argument is intentionally empty. 548 // First argument is intentionally empty.
550 INSTANTIATE_TEST_CASE_P( 549 INSTANTIATE_TEST_CASE_P(
551 , 550 ,
552 YUVReadbackPixelTest, 551 YUVReadbackPixelTest,
553 ::testing::Combine( 552 ::testing::Combine(
554 ::testing::Bool(), 553 ::testing::Bool(),
555 ::testing::Bool(), 554 ::testing::Bool(),
556 ::testing::Range<unsigned int>(0, arraysize(kYUVReadbackSizes)), 555 ::testing::Range<unsigned int>(0, arraysize(kYUVReadbackSizes)),
557 ::testing::Range<unsigned int>(0, arraysize(kYUVReadbackSizes)))); 556 ::testing::Range<unsigned int>(0, arraysize(kYUVReadbackSizes))));
558 557
559 } // namespace display_compositor 558 } // namespace viz
OLDNEW
« no previous file with comments | « components/viz/display_compositor/run_all_unittests.cc ('k') | components/viz/frame_sinks/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698