BenchmarkGfxPainter.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2021, Oleg Sikorskiy <olegsik@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibTest/TestCase.h>
  7. #include <LibGfx/Bitmap.h>
  8. #include <LibGfx/Font/FontDatabase.h>
  9. #include <LibGfx/Painter.h>
  10. #include <stdio.h>
  11. // Make sure that no matter what order tests are run in, we've got some
  12. // default fonts for the application to use without talking to WindowServer
  13. static struct FontDatabaseSpoofer {
  14. FontDatabaseSpoofer()
  15. {
  16. Gfx::FontDatabase::the().set_default_font_query("Katica 10 400 0"sv);
  17. }
  18. } g_spoof;
  19. BENCHMARK_CASE(diagonal_lines)
  20. {
  21. int const run_count = 50;
  22. int const bitmap_size = 2000;
  23. auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size }).release_value_but_fixme_should_propagate_errors();
  24. Gfx::Painter painter(bitmap);
  25. for (int run = 0; run < run_count; run++) {
  26. for (int i = 0; i < bitmap_size; i++) {
  27. painter.draw_line({ 0, 0 }, { i, bitmap_size - 1 }, Color::Blue);
  28. painter.draw_line({ 0, 0 }, { bitmap_size - 1, i }, Color::Blue);
  29. }
  30. }
  31. }
  32. BENCHMARK_CASE(fill)
  33. {
  34. int const run_count = 1000;
  35. int const bitmap_size = 2000;
  36. auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size }).release_value_but_fixme_should_propagate_errors();
  37. Gfx::Painter painter(bitmap);
  38. for (int run = 0; run < run_count; run++) {
  39. painter.fill_rect(bitmap->rect(), Color::Blue);
  40. }
  41. }
  42. BENCHMARK_CASE(fill_with_gradient)
  43. {
  44. int const run_count = 50;
  45. int const bitmap_size = 2000;
  46. auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size }).release_value_but_fixme_should_propagate_errors();
  47. Gfx::Painter painter(bitmap);
  48. for (int run = 0; run < run_count; run++) {
  49. painter.fill_rect_with_gradient(bitmap->rect(), Color::Blue, Color::Red);
  50. }
  51. }