#!/usr/bin/env perl

use strict;

use Time::HiRes qw(time);
use Graphics::Framebuffer;

my $mali = 0;
my $file = 0;

my $arg = join('',@ARGV);
$mali = 1 if ($arg =~ /mali/i); # Mali GPU correction mode
$file = 1 if ($arg =~ /file/i); # File Handle drawing mode

my $f = Graphics::Framebuffer->new('MALI' => $mali);

my $fm = Graphics::Framebuffer->new('FILE_MODE' => $file,'MALI' => $mali,'FB_DEVICE' => '/dev/fb0');

$f->cls();
my @t;
my $x = $f->{'XRES'} / 2;
my $y = $f->{'YRES'} / 2;
my $start = time;

$f->set_color({'red' => 255,'green' => 0,'blue' => 0});
foreach my $radius (10 .. $y) {
    $f->circle({'x' => $x, 'y' => $y, 'radius' => $radius, 'filled' => 1});
}

push(@t,sprintf('%.02f',time-$start));

$start = time;

$fm->set_color({'red' => 0,'green' => 0,'blue' => 255});
foreach my $radius (10 .. $y) {
    $fm->circle({'x' => $x, 'y' => $y, 'radius' => $radius, 'filled' => 1});
}

push(@t,sprintf('%.02f',time-$start));

$f->set_color({'red' => 255,'green' => 255,'blue' => 0});
$start = time;
for(my $xx=$y;$xx>=0;$xx--) {
    $f->box({'x' => $xx, 'y' => $xx, 'xx' => $f->{'XRES'} - $xx,'yy' => $f->{'YRES'} - $xx});
}

push(@t,sprintf('%.02f',time-$start));

$fm->set_color({'red' => 0,'green' => 255,'blue' => 255});
$start = time;

for(my $xx=$y;$xx>=0;$xx--) {
    $fm->box({'x' => $xx, 'y' => $xx, 'xx' => $fm->{'XRES'} - $xx,'yy' => $fm->{'YRES'} - $xx});
}

push(@t,sprintf('%.02f',time-$start));

$start = time;
$f->set_color({'red' => 0,'green' => 255,'blue' => 0});

foreach my $xx (0..$f->{'XRES'}) {
    $f->line({'x' => $xx,'y' => 0,'xx' => $xx, 'yy' => $f->{'YRES'}});
}
push(@t,sprintf('%.02f',time-$start));

$start = time;
$fm->set_color({'red' => 255,'green' => 0,'blue' => 255});

foreach my $xx (0..$f->{'XRES'}) {
    $fm->line({'x' => $xx,'y' => 0,'xx' => $xx, 'yy' => $f->{'YRES'}});
}
push(@t,sprintf('%.02f',time-$start));

print "CIRCLE STRING: $t[0]\n  CIRCLE FILE: $t[1]\n   BOX STRING: $t[2]\n     BOX FILE: $t[3]\n  LINE STRING: $t[4]\n    LINE FILE: $t[5]\n\n";
