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

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

Issue 1902463002: Introduce components/display_compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove bot changes. Will do in a separate CL Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/display_compositor/run_all_unittests.cc ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 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/test_suite.h" 10 #include "base/test/test_suite.h"
11 #include "content/browser/compositor/gl_helper.h" 11 #include "components/display_compositor/gl_helper.h"
12 #include "gpu/command_buffer/client/gl_in_process_context.h" 12 #include "gpu/command_buffer/client/gl_in_process_context.h"
13 #include "gpu/command_buffer/client/gles2_implementation.h" 13 #include "gpu/command_buffer/client/gles2_implementation.h"
14 #include "gpu/command_buffer/client/shared_memory_limits.h" 14 #include "gpu/command_buffer/client/shared_memory_limits.h"
15 #include "media/base/video_frame.h" 15 #include "media/base/video_frame.h"
16 #include "media/base/video_util.h" 16 #include "media/base/video_util.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/skia/include/core/SkBitmap.h" 18 #include "third_party/skia/include/core/SkBitmap.h"
19 #include "ui/gl/gl_implementation.h" 19 #include "ui/gl/gl_implementation.h"
20 20
21 namespace content { 21 namespace display_compositor {
22 22
23 namespace { 23 namespace {
24
25 int kYUVReadbackSizes[] = {2, 4, 14}; 24 int kYUVReadbackSizes[] = {2, 4, 14};
26 } 25 }
27 26
28 class YUVReadbackTest : public testing::Test { 27 class YUVReadbackTest : public testing::Test {
29 protected: 28 protected:
30 void SetUp() override { 29 void SetUp() override {
31 gpu::gles2::ContextCreationAttribHelper attributes; 30 gpu::gles2::ContextCreationAttribHelper attributes;
32 attributes.alpha_size = 8; 31 attributes.alpha_size = 8;
33 attributes.depth_size = 24; 32 attributes.depth_size = 24;
34 attributes.red_size = 8; 33 attributes.red_size = 8;
(...skipping 10 matching lines...) Expand all
45 true, /* offscreen */ 44 true, /* offscreen */
46 gfx::kNullAcceleratedWidget, /* window */ 45 gfx::kNullAcceleratedWidget, /* window */
47 gfx::Size(1, 1), /* size */ 46 gfx::Size(1, 1), /* size */
48 nullptr, /* share_context */ 47 nullptr, /* share_context */
49 attributes, gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(), 48 attributes, gfx::PreferDiscreteGpu, gpu::SharedMemoryLimits(),
50 nullptr, /* gpu_memory_buffer_manager */ 49 nullptr, /* gpu_memory_buffer_manager */
51 nullptr /* image_factory */)); 50 nullptr /* image_factory */));
52 gl_ = context_->GetImplementation(); 51 gl_ = context_->GetImplementation();
53 gpu::ContextSupport* support = context_->GetImplementation(); 52 gpu::ContextSupport* support = context_->GetImplementation();
54 53
55 helper_.reset(new content::GLHelper(gl_, support)); 54 helper_.reset(new display_compositor::GLHelper(gl_, support));
56 } 55 }
57 56
58 void TearDown() override { 57 void TearDown() override {
59 helper_.reset(NULL); 58 helper_.reset(NULL);
60 context_.reset(NULL); 59 context_.reset(NULL);
61 } 60 }
62 61
63 void StartTracing(const std::string& filter) { 62 void StartTracing(const std::string& filter) {
64 base::trace_event::TraceLog::GetInstance()->SetEnabled( 63 base::trace_event::TraceLog::GetInstance()->SetEnabled(
65 base::trace_event::TraceConfig(filter, 64 base::trace_event::TraceConfig(filter,
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // returns. 306 // returns.
308 void TestYUVReadback(int xsize, 307 void TestYUVReadback(int xsize,
309 int ysize, 308 int ysize,
310 int output_xsize, 309 int output_xsize,
311 int output_ysize, 310 int output_ysize,
312 int xmargin, 311 int xmargin,
313 int ymargin, 312 int ymargin,
314 int test_pattern, 313 int test_pattern,
315 bool flip, 314 bool flip,
316 bool use_mrt, 315 bool use_mrt,
317 content::GLHelper::ScalerQuality quality) { 316 display_compositor::GLHelper::ScalerQuality quality) {
318 GLuint src_texture; 317 GLuint src_texture;
319 gl_->GenTextures(1, &src_texture); 318 gl_->GenTextures(1, &src_texture);
320 SkBitmap input_pixels; 319 SkBitmap input_pixels;
321 input_pixels.allocN32Pixels(xsize, ysize); 320 input_pixels.allocN32Pixels(xsize, ysize);
322 321
323 for (int x = 0; x < xsize; ++x) { 322 for (int x = 0; x < xsize; ++x) {
324 for (int y = 0; y < ysize; ++y) { 323 for (int y = 0; y < ysize; ++y) {
325 switch (test_pattern) { 324 switch (test_pattern) {
326 case 0: // Smooth test pattern 325 case 0: // Smooth test pattern
327 SetChannel(&input_pixels, x, y, 0, x * 10); 326 SetChannel(&input_pixels, x, y, 0, x * 10);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 ComparePlane( 464 ComparePlane(
466 V, v_stride, output_frame->visible_data(media::VideoFrame::kVPlane), 465 V, v_stride, output_frame->visible_data(media::VideoFrame::kVPlane),
467 output_frame->stride(media::VideoFrame::kVPlane), 2, output_xsize / 2, 466 output_frame->stride(media::VideoFrame::kVPlane), 2, output_xsize / 2,
468 output_ysize / 2, &input_pixels, message + " V plane"); 467 output_ysize / 2, &input_pixels, message + " V plane");
469 468
470 gl_->DeleteTextures(1, &src_texture); 469 gl_->DeleteTextures(1, &src_texture);
471 } 470 }
472 471
473 std::unique_ptr<gpu::GLInProcessContext> context_; 472 std::unique_ptr<gpu::GLInProcessContext> context_;
474 gpu::gles2::GLES2Interface* gl_; 473 gpu::gles2::GLES2Interface* gl_;
475 std::unique_ptr<content::GLHelper> helper_; 474 std::unique_ptr<display_compositor::GLHelper> helper_;
476 gfx::DisableNullDrawGLBindings enable_pixel_output_; 475 gfx::DisableNullDrawGLBindings enable_pixel_output_;
477 }; 476 };
478 477
479 TEST_F(YUVReadbackTest, YUVReadbackOptTest) { 478 TEST_F(YUVReadbackTest, YUVReadbackOptTest) {
480 // This test uses the gpu.service/gpu_decoder tracing events to detect how 479 // This test uses the gpu.service/gpu_decoder tracing events to detect how
481 // many scaling passes are actually performed by the YUV readback pipeline. 480 // many scaling passes are actually performed by the YUV readback pipeline.
482 StartTracing(TRACE_DISABLED_BY_DEFAULT( 481 StartTracing(TRACE_DISABLED_BY_DEFAULT(
483 "gpu.service") "," TRACE_DISABLED_BY_DEFAULT("gpu_decoder")); 482 "gpu.service") "," TRACE_DISABLED_BY_DEFAULT("gpu_decoder"));
484 483
485 TestYUVReadback(800, 400, 800, 400, 0, 0, 1, false, true, 484 TestYUVReadback(800, 400, 800, 400, 0, 0, 1, false, true,
486 content::GLHelper::SCALER_QUALITY_FAST); 485 display_compositor::GLHelper::SCALER_QUALITY_FAST);
487 486
488 std::map<std::string, int> event_counts; 487 std::map<std::string, int> event_counts;
489 EndTracing(&event_counts); 488 EndTracing(&event_counts);
490 int draw_buffer_calls = event_counts["kDrawBuffersEXTImmediate"]; 489 int draw_buffer_calls = event_counts["kDrawBuffersEXTImmediate"];
491 int draw_arrays_calls = event_counts["kDrawArrays"]; 490 int draw_arrays_calls = event_counts["kDrawArrays"];
492 VLOG(1) << "Draw buffer calls: " << draw_buffer_calls; 491 VLOG(1) << "Draw buffer calls: " << draw_buffer_calls;
493 VLOG(1) << "DrawArrays calls: " << draw_arrays_calls; 492 VLOG(1) << "DrawArrays calls: " << draw_arrays_calls;
494 493
495 if (draw_buffer_calls) { 494 if (draw_buffer_calls) {
496 // When using MRT, the YUV readback code should only 495 // When using MRT, the YUV readback code should only
(...skipping 26 matching lines...) Expand all
523 for (Margin xm = x < ox ? MarginLeft : MarginRight; xm <= MarginRight; 522 for (Margin xm = x < ox ? MarginLeft : MarginRight; xm <= MarginRight;
524 xm = NextMargin(xm)) { 523 xm = NextMargin(xm)) {
525 for (Margin ym = y < oy ? MarginLeft : MarginRight; ym <= MarginRight; 524 for (Margin ym = y < oy ? MarginLeft : MarginRight; ym <= MarginRight;
526 ym = NextMargin(ym)) { 525 ym = NextMargin(ym)) {
527 for (int pattern = 0; pattern < 3; pattern++) { 526 for (int pattern = 0; pattern < 3; pattern++) {
528 TestYUVReadback( 527 TestYUVReadback(
529 kYUVReadbackSizes[x], kYUVReadbackSizes[y], 528 kYUVReadbackSizes[x], kYUVReadbackSizes[y],
530 kYUVReadbackSizes[ox], kYUVReadbackSizes[oy], 529 kYUVReadbackSizes[ox], kYUVReadbackSizes[oy],
531 compute_margin(kYUVReadbackSizes[x], kYUVReadbackSizes[ox], xm), 530 compute_margin(kYUVReadbackSizes[x], kYUVReadbackSizes[ox], xm),
532 compute_margin(kYUVReadbackSizes[y], kYUVReadbackSizes[oy], ym), 531 compute_margin(kYUVReadbackSizes[y], kYUVReadbackSizes[oy], ym),
533 pattern, flip, use_mrt, content::GLHelper::SCALER_QUALITY_GOOD); 532 pattern, flip, use_mrt,
533 display_compositor::GLHelper::SCALER_QUALITY_GOOD);
534 if (HasFailure()) { 534 if (HasFailure()) {
535 return; 535 return;
536 } 536 }
537 } 537 }
538 } 538 }
539 } 539 }
540 } 540 }
541 } 541 }
542 } 542 }
543 543
544 // First argument is intentionally empty. 544 // First argument is intentionally empty.
545 INSTANTIATE_TEST_CASE_P( 545 INSTANTIATE_TEST_CASE_P(
546 , 546 ,
547 YUVReadbackPixelTest, 547 YUVReadbackPixelTest,
548 ::testing::Combine( 548 ::testing::Combine(
549 ::testing::Bool(), 549 ::testing::Bool(),
550 ::testing::Bool(), 550 ::testing::Bool(),
551 ::testing::Range<unsigned int>(0, arraysize(kYUVReadbackSizes)), 551 ::testing::Range<unsigned int>(0, arraysize(kYUVReadbackSizes)),
552 ::testing::Range<unsigned int>(0, arraysize(kYUVReadbackSizes)))); 552 ::testing::Range<unsigned int>(0, arraysize(kYUVReadbackSizes))));
553 553
554 } // namespace content 554 } // namespace display_compositor
OLDNEW
« no previous file with comments | « components/display_compositor/run_all_unittests.cc ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698