| 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 // Implementation of a client that produces output in the form of RGBA | 5 // Implementation of a client that produces output in the form of RGBA |
| 6 // buffers when receiving pointer/touch events. RGB contains the lower | 6 // buffers when receiving pointer/touch events. RGB contains the lower |
| 7 // 24 bits of the event timestamp and A is 0xff. | 7 // 24 bits of the event timestamp and A is 0xff. |
| 8 | 8 |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <linux-dmabuf-unstable-v1-client-protocol.h> | 10 #include <linux-dmabuf-unstable-v1-client-protocol.h> |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } // namespace | 376 } // namespace |
| 377 | 377 |
| 378 class MotionEvents { | 378 class MotionEvents { |
| 379 public: | 379 public: |
| 380 MotionEvents(size_t width, | 380 MotionEvents(size_t width, |
| 381 size_t height, | 381 size_t height, |
| 382 int scale, | 382 int scale, |
| 383 size_t num_rects, | 383 size_t num_rects, |
| 384 size_t max_frames_pending, | 384 size_t max_frames_pending, |
| 385 bool fullscreen, | 385 bool fullscreen, |
| 386 bool transparent_background, |
| 386 bool show_fps_counter, | 387 bool show_fps_counter, |
| 387 size_t num_benchmark_runs, | 388 size_t num_benchmark_runs, |
| 388 base::TimeDelta benchmark_interval, | 389 base::TimeDelta benchmark_interval, |
| 389 const std::string* use_drm) | 390 const std::string* use_drm) |
| 390 : width_(width), | 391 : width_(width), |
| 391 height_(height), | 392 height_(height), |
| 392 scale_(scale), | 393 scale_(scale), |
| 393 num_rects_(num_rects), | 394 num_rects_(num_rects), |
| 394 max_frames_pending_(max_frames_pending), | 395 max_frames_pending_(max_frames_pending), |
| 395 fullscreen_(fullscreen), | 396 fullscreen_(fullscreen), |
| 397 transparent_background_(transparent_background), |
| 396 show_fps_counter_(show_fps_counter), | 398 show_fps_counter_(show_fps_counter), |
| 397 num_benchmark_runs_(num_benchmark_runs), | 399 num_benchmark_runs_(num_benchmark_runs), |
| 398 benchmark_interval_(benchmark_interval), | 400 benchmark_interval_(benchmark_interval), |
| 399 use_drm_(use_drm) {} | 401 use_drm_(use_drm) {} |
| 400 | 402 |
| 401 // Initialize and run client main loop. | 403 // Initialize and run client main loop. |
| 402 int Run(); | 404 int Run(); |
| 403 | 405 |
| 404 private: | 406 private: |
| 405 bool CreateBuffer(Buffer* buffer); | 407 bool CreateBuffer(Buffer* buffer); |
| 406 | 408 |
| 407 const size_t width_; | 409 const size_t width_; |
| 408 const size_t height_; | 410 const size_t height_; |
| 409 const int scale_; | 411 const int scale_; |
| 410 const size_t num_rects_; | 412 const size_t num_rects_; |
| 411 const size_t max_frames_pending_; | 413 const size_t max_frames_pending_; |
| 412 const bool fullscreen_; | 414 const bool fullscreen_; |
| 415 const bool transparent_background_; |
| 413 const bool show_fps_counter_; | 416 const bool show_fps_counter_; |
| 414 const size_t num_benchmark_runs_; | 417 const size_t num_benchmark_runs_; |
| 415 const base::TimeDelta benchmark_interval_; | 418 const base::TimeDelta benchmark_interval_; |
| 416 const std::string* use_drm_; | 419 const std::string* use_drm_; |
| 417 | 420 |
| 418 std::unique_ptr<wl_display> display_; | 421 std::unique_ptr<wl_display> display_; |
| 419 Globals globals_; | 422 Globals globals_; |
| 420 | 423 |
| 421 #if defined(OZONE_PLATFORM_GBM) | 424 #if defined(OZONE_PLATFORM_GBM) |
| 422 base::ScopedFD drm_fd_; | 425 base::ScopedFD drm_fd_; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 &buffers_[i]); | 556 &buffers_[i]); |
| 554 } | 557 } |
| 555 | 558 |
| 556 std::unique_ptr<wl_surface> surface(static_cast<wl_surface*>( | 559 std::unique_ptr<wl_surface> surface(static_cast<wl_surface*>( |
| 557 wl_compositor_create_surface(globals_.compositor.get()))); | 560 wl_compositor_create_surface(globals_.compositor.get()))); |
| 558 if (!surface) { | 561 if (!surface) { |
| 559 LOG(ERROR) << "Can't create surface"; | 562 LOG(ERROR) << "Can't create surface"; |
| 560 return 1; | 563 return 1; |
| 561 } | 564 } |
| 562 | 565 |
| 563 std::unique_ptr<wl_region> opaque_region(static_cast<wl_region*>( | 566 if (!transparent_background_) { |
| 564 wl_compositor_create_region(globals_.compositor.get()))); | 567 std::unique_ptr<wl_region> opaque_region(static_cast<wl_region*>( |
| 565 if (!opaque_region) { | 568 wl_compositor_create_region(globals_.compositor.get()))); |
| 566 LOG(ERROR) << "Can't create region"; | 569 if (!opaque_region) { |
| 567 return 1; | 570 LOG(ERROR) << "Can't create region"; |
| 571 return 1; |
| 572 } |
| 573 |
| 574 wl_region_add(opaque_region.get(), 0, 0, width_, height_); |
| 575 wl_surface_set_opaque_region(surface.get(), opaque_region.get()); |
| 568 } | 576 } |
| 569 | 577 |
| 570 wl_region_add(opaque_region.get(), 0, 0, width_, height_); | |
| 571 wl_surface_set_opaque_region(surface.get(), opaque_region.get()); | |
| 572 | |
| 573 std::unique_ptr<wl_shell_surface> shell_surface( | 578 std::unique_ptr<wl_shell_surface> shell_surface( |
| 574 static_cast<wl_shell_surface*>( | 579 static_cast<wl_shell_surface*>( |
| 575 wl_shell_get_shell_surface(globals_.shell.get(), surface.get()))); | 580 wl_shell_get_shell_surface(globals_.shell.get(), surface.get()))); |
| 576 if (!shell_surface) { | 581 if (!shell_surface) { |
| 577 LOG(ERROR) << "Can't get shell surface"; | 582 LOG(ERROR) << "Can't get shell surface"; |
| 578 return 1; | 583 return 1; |
| 579 } | 584 } |
| 580 | 585 |
| 581 wl_shell_surface_set_title(shell_surface.get(), kClientTitle); | 586 wl_shell_surface_set_title(shell_surface.get(), kClientTitle); |
| 582 | 587 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 presentation.latency_time = base::TimeDelta(); | 689 presentation.latency_time = base::TimeDelta(); |
| 685 presentation.num_frames_presented = kBenchmarkWarmupFrames; | 690 presentation.num_frames_presented = kBenchmarkWarmupFrames; |
| 686 presentation.num_events_presented = 0; | 691 presentation.num_events_presented = 0; |
| 687 } | 692 } |
| 688 | 693 |
| 689 cpu_time_start = base::ThreadTicks::Now(); | 694 cpu_time_start = base::ThreadTicks::Now(); |
| 690 } | 695 } |
| 691 | 696 |
| 692 SkCanvas* canvas = buffer->sk_surface->getCanvas(); | 697 SkCanvas* canvas = buffer->sk_surface->getCanvas(); |
| 693 if (event_times.empty()) { | 698 if (event_times.empty()) { |
| 694 canvas->clear(SK_ColorBLACK); | 699 canvas->clear(transparent_background_ ? SK_ColorTRANSPARENT |
| 700 : SK_ColorBLACK); |
| 695 } else { | 701 } else { |
| 696 // Split buffer into one horizontal rectangle for each event received | 702 // Split buffer into one horizontal rectangle for each event received |
| 697 // since last frame. Latest event at the top. | 703 // since last frame. Latest event at the top. |
| 698 int y = 0; | 704 int y = 0; |
| 699 // Note: Rounding up to ensure we cover the whole canvas. | 705 // Note: Rounding up to ensure we cover the whole canvas. |
| 700 int h = (height_ + (event_times.size() / 2)) / event_times.size(); | 706 int h = (height_ + (event_times.size() / 2)) / event_times.size(); |
| 701 while (!event_times.empty()) { | 707 while (!event_times.empty()) { |
| 702 SkIRect rect = SkIRect::MakeXYWH(0, y, width_, h); | 708 SkIRect rect = SkIRect::MakeXYWH(0, y, width_, h); |
| 703 SkPaint paint; | 709 SkPaint paint; |
| 704 paint.setColor(SkColorSetRGB((event_times.back() & 0x0000ff) >> 0, | 710 paint.setColor(SkColorSetRGB((event_times.back() & 0x0000ff) >> 0, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 | 910 |
| 905 // Specifies the number of rotating rects to draw. | 911 // Specifies the number of rotating rects to draw. |
| 906 const char kNumRects[] = "num-rects"; | 912 const char kNumRects[] = "num-rects"; |
| 907 | 913 |
| 908 // Specifies the maximum number of pending frames. | 914 // Specifies the maximum number of pending frames. |
| 909 const char kMaxFramesPending[] = "max-frames-pending"; | 915 const char kMaxFramesPending[] = "max-frames-pending"; |
| 910 | 916 |
| 911 // Specifies if client should be fullscreen. | 917 // Specifies if client should be fullscreen. |
| 912 const char kFullscreen[] = "fullscreen"; | 918 const char kFullscreen[] = "fullscreen"; |
| 913 | 919 |
| 920 // Specifies if the background should be transparent. |
| 921 const char kTransparentBackground[] = "transparent-background"; |
| 922 |
| 914 // Specifies if FPS counter should be shown. | 923 // Specifies if FPS counter should be shown. |
| 915 const char kShowFpsCounter[] = "show-fps-counter"; | 924 const char kShowFpsCounter[] = "show-fps-counter"; |
| 916 | 925 |
| 917 // Enables benchmark mode and specifies the number of benchmark runs to | 926 // Enables benchmark mode and specifies the number of benchmark runs to |
| 918 // perform before client will exit. Client will print the results to | 927 // perform before client will exit. Client will print the results to |
| 919 // standard output as a tab seperated list. | 928 // standard output as a tab seperated list. |
| 920 // | 929 // |
| 921 // The output format is: | 930 // The output format is: |
| 922 // "frames wall-time-ms cpu-time-ms" | 931 // "frames wall-time-ms cpu-time-ms" |
| 923 const char kBenchmark[] = "benchmark"; | 932 const char kBenchmark[] = "benchmark"; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 | 999 |
| 991 std::unique_ptr<std::string> use_drm; | 1000 std::unique_ptr<std::string> use_drm; |
| 992 if (command_line->HasSwitch(switches::kUseDrm)) { | 1001 if (command_line->HasSwitch(switches::kUseDrm)) { |
| 993 use_drm.reset( | 1002 use_drm.reset( |
| 994 new std::string(command_line->GetSwitchValueASCII(switches::kUseDrm))); | 1003 new std::string(command_line->GetSwitchValueASCII(switches::kUseDrm))); |
| 995 } | 1004 } |
| 996 | 1005 |
| 997 exo::wayland::clients::MotionEvents client( | 1006 exo::wayland::clients::MotionEvents client( |
| 998 width, height, scale, num_rects, max_frames_pending, | 1007 width, height, scale, num_rects, max_frames_pending, |
| 999 command_line->HasSwitch(switches::kFullscreen), | 1008 command_line->HasSwitch(switches::kFullscreen), |
| 1009 command_line->HasSwitch(switches::kTransparentBackground), |
| 1000 command_line->HasSwitch(switches::kShowFpsCounter), num_benchmark_runs, | 1010 command_line->HasSwitch(switches::kShowFpsCounter), num_benchmark_runs, |
| 1001 base::TimeDelta::FromMilliseconds(benchmark_interval_ms), use_drm.get()); | 1011 base::TimeDelta::FromMilliseconds(benchmark_interval_ms), use_drm.get()); |
| 1002 return client.Run(); | 1012 return client.Run(); |
| 1003 } | 1013 } |
| OLD | NEW |