2021-04-04 16:10:54 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Oleg Sikorskiy <olegsik@gmail.com>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-04-04 16:10:54 +03:00
|
|
|
*/
|
|
|
|
|
2021-04-25 08:53:23 +03:00
|
|
|
#include <LibTest/TestCase.h>
|
2021-04-04 16:10:54 +03:00
|
|
|
|
|
|
|
#include <LibGfx/Bitmap.h>
|
2021-07-01 06:31:25 +03:00
|
|
|
#include <LibGfx/FontDatabase.h>
|
2021-04-04 16:10:54 +03:00
|
|
|
#include <LibGfx/Painter.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2021-07-01 06:31:25 +03:00
|
|
|
// Make sure that no matter what order tests are run in, we've got some
|
|
|
|
// default fonts for the application to use without talking to WindowServer
|
|
|
|
static struct FontDatabaseSpoofer {
|
|
|
|
FontDatabaseSpoofer()
|
|
|
|
{
|
2022-02-01 04:18:15 +03:00
|
|
|
Gfx::FontDatabase::the().set_default_font_query("Katica 10 400 0"sv);
|
2021-07-01 06:31:25 +03:00
|
|
|
}
|
|
|
|
} g_spoof;
|
|
|
|
|
2021-04-04 16:10:54 +03:00
|
|
|
BENCHMARK_CASE(diagonal_lines)
|
|
|
|
{
|
2022-04-01 20:58:27 +03:00
|
|
|
int const run_count = 50;
|
|
|
|
int const bitmap_size = 2000;
|
2021-04-04 16:10:54 +03:00
|
|
|
|
2021-11-06 21:30:59 +03:00
|
|
|
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size }).release_value_but_fixme_should_propagate_errors();
|
|
|
|
Gfx::Painter painter(bitmap);
|
2021-04-04 16:10:54 +03:00
|
|
|
|
|
|
|
for (int run = 0; run < run_count; run++) {
|
|
|
|
for (int i = 0; i < bitmap_size; i++) {
|
|
|
|
painter.draw_line({ 0, 0 }, { i, bitmap_size - 1 }, Color::Blue);
|
|
|
|
painter.draw_line({ 0, 0 }, { bitmap_size - 1, i }, Color::Blue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK_CASE(fill)
|
|
|
|
{
|
2022-04-01 20:58:27 +03:00
|
|
|
int const run_count = 1000;
|
|
|
|
int const bitmap_size = 2000;
|
2021-04-04 16:10:54 +03:00
|
|
|
|
2021-11-06 21:30:59 +03:00
|
|
|
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size }).release_value_but_fixme_should_propagate_errors();
|
|
|
|
Gfx::Painter painter(bitmap);
|
2021-04-04 16:10:54 +03:00
|
|
|
|
|
|
|
for (int run = 0; run < run_count; run++) {
|
|
|
|
painter.fill_rect(bitmap->rect(), Color::Blue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK_CASE(fill_with_gradient)
|
|
|
|
{
|
2022-04-01 20:58:27 +03:00
|
|
|
int const run_count = 50;
|
|
|
|
int const bitmap_size = 2000;
|
2021-04-04 16:10:54 +03:00
|
|
|
|
2021-11-06 21:30:59 +03:00
|
|
|
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { bitmap_size, bitmap_size }).release_value_but_fixme_should_propagate_errors();
|
|
|
|
Gfx::Painter painter(bitmap);
|
2021-04-04 16:10:54 +03:00
|
|
|
|
|
|
|
for (int run = 0; run < run_count; run++) {
|
|
|
|
painter.fill_rect_with_gradient(bitmap->rect(), Color::Blue, Color::Red);
|
|
|
|
}
|
|
|
|
}
|