[cairo-commit] 3 commits - boilerplate/cairo-boilerplate.c
test/make-html.pl
Vladimir Vukicevic
vladimir at kemper.freedesktop.org
Sat Sep 9 19:05:41 PDT 2006
boilerplate/cairo-boilerplate.c | 46 ++++--------------
test/make-html.pl | 100 ++++++++++++++++++++++++++++++++--------
2 files changed, 92 insertions(+), 54 deletions(-)
New commits:
diff-tree d3076a1843bc2f05bab0df913d0c27f125bea162 (from parents)
Merge: dfe3e20a4a44db71270dd50b2e4bac84ff97dbb8 78b8555c9a7181ebee59a6fbdefe671d97dc9535
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date: Sat Sep 9 18:57:57 2006 -0700
Merge branch 'master' of git+ssh://git.cairographics.org/git/cairo into cairo-master
diff --cc boilerplate/cairo-boilerplate.c
index b8cad03,4b86d61..e525766
mode 100755,100644..100755
@@@ -708,24 -715,46 +715,25 @@@
*/
#if CAIRO_HAS_WIN32_SURFACE
#include "cairo-win32.h"
-typedef struct _win32_target_closure
-{
- HDC dc;
- HBITMAP bmp;
-} win32_target_closure_t;
-
static cairo_surface_t *
- create_win32_surface (const char *name,
- cairo_content_t content,
- int width,
- int height,
- void **closure)
+ create_win32_surface (const char *name,
+ cairo_content_t content,
+ int width,
+ int height,
+ cairo_boilerplate_mode_t mode,
+ void **closure)
{
- BITMAPINFO bmpInfo;
- unsigned char *bits = NULL;
- win32_target_closure_t *data = malloc(sizeof(win32_target_closure_t));
- *closure = data;
-
- data->dc = CreateCompatibleDC(NULL);
-
- /* initialize the bitmapinfoheader */
- memset(&bmpInfo.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
- bmpInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
- bmpInfo.bmiHeader.biWidth = width;
- bmpInfo.bmiHeader.biHeight = -height;
- bmpInfo.bmiHeader.biPlanes = 1;
- bmpInfo.bmiHeader.biBitCount = 24;
- bmpInfo.bmiHeader.biCompression = BI_RGB;
-
- /* create a DIBSection */
- data->bmp = CreateDIBSection(data->dc, &bmpInfo, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
-
- /* Flush GDI to make sure the DIBSection is actually created */
- GdiFlush();
+ cairo_format_t format;
- /* Select the bitmap in to the DC */
- SelectObject(data->dc, data->bmp);
+ if (content == CAIRO_CONTENT_COLOR)
+ format = CAIRO_FORMAT_RGB24;
+ else if (content == CAIRO_CONTENT_COLOR_ALPHA)
+ format = CAIRO_FORMAT_ARGB32;
+ else
+ return NULL;
- return cairo_win32_surface_create(data->dc);
+ *closure = NULL;
+ return cairo_win32_surface_create_with_dib (format, width, height);
}
static void
diff-tree dfe3e20a4a44db71270dd50b2e4bac84ff97dbb8 (from 9735cb9a246627c9e4710c0f7d2955e3e0fbec69)
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date: Sat Sep 9 18:56:58 2006 -0700
[win32] Fix boilerplate for win32 surfaces to use new _with_dib function
Create test surfaces for win32 using _with_dib instead of creating the
dib locally; also test CONTENT_COLOR and CONTENT_COLOR_ALPHA.
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
old mode 100644
new mode 100755
index 0137f6e..b8cad03
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -708,12 +708,6 @@ cleanup_quartz (void *closure)
*/
#if CAIRO_HAS_WIN32_SURFACE
#include "cairo-win32.h"
-typedef struct _win32_target_closure
-{
- HDC dc;
- HBITMAP bmp;
-} win32_target_closure_t;
-
static cairo_surface_t *
create_win32_surface (const char *name,
cairo_content_t content,
@@ -721,42 +715,22 @@ create_win32_surface (const char *name,
int height,
void **closure)
{
- BITMAPINFO bmpInfo;
- unsigned char *bits = NULL;
- win32_target_closure_t *data = malloc(sizeof(win32_target_closure_t));
- *closure = data;
-
- data->dc = CreateCompatibleDC(NULL);
-
- /* initialize the bitmapinfoheader */
- memset(&bmpInfo.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
- bmpInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
- bmpInfo.bmiHeader.biWidth = width;
- bmpInfo.bmiHeader.biHeight = -height;
- bmpInfo.bmiHeader.biPlanes = 1;
- bmpInfo.bmiHeader.biBitCount = 24;
- bmpInfo.bmiHeader.biCompression = BI_RGB;
-
- /* create a DIBSection */
- data->bmp = CreateDIBSection(data->dc, &bmpInfo, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
-
- /* Flush GDI to make sure the DIBSection is actually created */
- GdiFlush();
+ cairo_format_t format;
- /* Select the bitmap in to the DC */
- SelectObject(data->dc, data->bmp);
+ if (content == CAIRO_CONTENT_COLOR)
+ format = CAIRO_FORMAT_RGB24;
+ else if (content == CAIRO_CONTENT_COLOR_ALPHA)
+ format = CAIRO_FORMAT_ARGB32;
+ else
+ return NULL;
- return cairo_win32_surface_create(data->dc);
+ *closure = NULL;
+ return cairo_win32_surface_create_with_dib (format, width, height);
}
static void
cleanup_win32 (void *closure)
{
- win32_target_closure_t *data = (win32_target_closure_t*)closure;
- DeleteObject(data->bmp);
- DeleteDC(data->dc);
-
- free(closure);
}
#endif
@@ -1407,6 +1381,8 @@ cairo_boilerplate_target_t targets[] =
#if CAIRO_HAS_WIN32_SURFACE
{ "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR, 0,
create_win32_surface, cairo_surface_write_to_png, cleanup_win32 },
+ { "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR_ALPHA, 0,
+ create_win32_surface, cairo_surface_write_to_png, cleanup_win32 },
#endif
#if CAIRO_HAS_XCB_SURFACE
{ "xcb", CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA, 0,
diff-tree 9735cb9a246627c9e4710c0f7d2955e3e0fbec69 (from 97f26c523590dcb208a7c0e4d00fd66f4ca58605)
Author: Vladimir Vukicevic <vladimir at pobox.com>
Date: Sat Sep 9 18:55:46 2006 -0700
Improve make-html.pl, add self-contained output format
Setting CAIRO_TEST_SHOW_INLINE in the environment before running
make-html.pl will generate a html file with all the logs and necessary
images inlined as data URI's.
diff --git a/test/make-html.pl b/test/make-html.pl
index 82d2edf..299f07f 100755
--- a/test/make-html.pl
+++ b/test/make-html.pl
@@ -24,6 +24,8 @@
# Author: Vladimir Vukicevic <vladimir at pobox.com>
#
+use MIME::Base64;
+
##
## Takes all the *.log files in the current directory (or those provided
## on the command line) and spits out html to stdout that can be used to
@@ -31,26 +33,32 @@
##
# show reference images
-my $config_show_ref = 0;
+$config_show_ref = $ENV{'CAIRO_TEST_SHOW_REF'} || 0;
# show fail images
-my $config_show_fail = 1;
+$config_show_fail = $ENV{'CAIRO_TEST_SHOW_FAIL'} || 1;
# show all results, even passes
-my $config_show_all = 0;
+$config_show_all = $ENV{'CAIRO_TEST_SHOW_ALL'} || 0;
-# end of config options
+# include test results inline
+$config_show_inline = $ENV{'CAIRO_TEST_SHOW_INLINE'} || 0;
-my $tests = {};
+# end of config options
-my $teststats = {};
+$tests = {};
+$teststats = {};
+$logs = {};
if ($#ARGV >= 0) { @files = @ARGV; } else { @files = <*.log>; }
foreach (<@files>) {
- (open LOG, "$_") || next;
+ my $testname;
+ my $fn = $_;
+ (open LOG, $fn) || next;
while (<LOG>) {
- next unless /^TEST: (.*) TARGET: (.*) FORMAT: (.*) OFFSET: (.*) RESULT: (.*)$/;
+ next unless /^TEST: (.*) TARGET: (.*) FORMAT: (.*) OFFSET: (.*) RESULT: ([A-Z]*).*$/;
+ $testname = $1 if !defined($testname);
$tests->{$1} = {} unless $tests->{$1};
$tests->{$1}->{$2} = {} unless $tests->{$1}->{$2};
$tests->{$1}->{$2}->{$3} = {} unless $tests->{$1}->{$2}->{$3};
@@ -61,6 +69,13 @@ foreach (<@files>) {
($teststats->{$2}->{$5})++;
}
close LOG;
+
+ (open LOG, $fn) || die "I could open it earlier, but I can't now: $!";
+ {
+ local $/;
+ $logs->{$testname} = <LOG>;
+ }
+ close LOG;
}
my $targeth = {};
@@ -92,6 +107,26 @@ sub printl {
print @_, "\n";
}
+# convert file into a data URI
+sub file_to_data {
+ my ($ctype,$fname) = @_;
+ my $fdata;
+ open FILE, $fname || return "data:" . $ctype . ",";
+ {
+ local $/;
+ $fdata = encode_base64(<FILE>);
+ }
+ close FILE;
+ return "data:" . $ctype . ";base64," . $fdata;
+}
+
+# convert string into a data URI
+sub string_to_data {
+ my ($ctype,$str) = @_;
+ $str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
+ return "data:" . $ctype . "," . $str;
+}
+
printl '<html><head>';
printl '<title>Cairo Test Results</title>';
printl '<style type="text/css">';
@@ -109,6 +144,8 @@ printl '.UNTESTEDstr { color: #555; }';
printl 'img { max-width: 15em; min-width: 3em; margin: 3px; }';
printl 'td { vertical-align: top; }';
printl '</style>';
+printl '</script>';
+printl '</head>';
printl '<body>';
printl '<table border="1">';
@@ -128,7 +165,7 @@ foreach my $target (@targets) {
print '<span class="PASSstr">', $teststats->{$target}->{"PASS"}, '</span>/';
print '<span class="FAILstr">', $teststats->{$target}->{"FAIL"} + $teststats->{$target}->{"CRASHED"}, '</span>/';
print '<span class="XFAILstr">', $teststats->{$target}->{"XFAIL"}, '</span>/';
- print '<span class="UNTESTEDstr">', $teststats->{$target}->{"UNTESTED"}; '</span>';
+ print '<span class="UNTESTEDstr">', $teststats->{$target}->{"UNTESTED"}, '</span>';
print '</td>';
}
printl '</tr>';
@@ -160,6 +197,23 @@ sub testfiles {
"diff" => "$test-$target$fmtstr$offstr-diff.png");
}
+sub img_for {
+ my ($fn, $withlink) = @_;
+
+ if ($config_show_inline) {
+ $fn = file_to_data("image/png", $fn);
+ # never return links, people can just right-click view image,
+ # and we don't clutter the document
+ return '<img src="' . $fn . '">';
+ } else {
+ if ($withlink) {
+ return '<a href="' . $fn . '"><img src="' . $fn . '"></a>';
+ } else {
+ return '<img src="' . $fn . '">';
+ }
+ }
+}
+
foreach my $test (sort(keys %$tests)) {
foreach my $offset (@offsets) {
foreach my $format (@formats) {
@@ -172,27 +226,26 @@ foreach my $test (sort(keys %$tests)) {
if ($testres) {
my %testfiles = testfiles($test, $target, $format, $offset);
$testline .= "<td class=\"$testres\">";
- $stats{$target}{$testres}++;
+ $teststats{$target}{$testres}++;
if ($testres eq "PASS") {
if ($config_show_all) {
- $testline .= "<a href=\"" . $testfiles{"out"} . "\"><img src=\"" . $testfiles{"out"} . "\"></a>";
+ $testline .= img_for($testfiles{'out'},1);
}
} elsif ($testres eq "FAIL") {
if ($config_show_fail || $config_show_all) {
- $testline .= "<a href=\"" . $testfiles{"out"} . "\"><img src=\"" . $testfiles{"out"} . "\"></a>";
- #$testline .= "<hr size=\"1\">";
+ $testline .= img_for($testfiles{'out'},1);
$testline .= " ";
- $testline .= "<a href=\"" . $testfiles{"diff"} . "\"><img src=\"" . $testfiles{"diff"} . "\"></a>";
+ $testline .= img_for($testfiles{'diff'},1);
}
} elsif ($testres eq "CRASHED") {
$testline .= "!!!CRASHED!!!";
} elsif ($testres eq "XFAIL") {
#nothing
if ($config_show_all) {
- $testline .= "<a href=\"" . $testfiles{"out"} . "\"><img src=\"" . $testfiles{"out"} . "\"></a>";
+ $testline .= img_for($testfiles{'out'},1);
#$testline .= "<hr size=\"1\">";
$testline .= " ";
- $testline .= "<a href=\"" . $testfiles{"diff"} . "\"><img src=\"" . $testfiles{"diff"} . "\"></a>";
+ $testline .= img_for($testfiles{'diff'},1);
}
} elsif ($testres eq "UNTESTED") {
#nothing
@@ -210,11 +263,20 @@ foreach my $test (sort(keys %$tests)) {
}
my $testref = testref($test, $format);
- print '<tr><td>', "<a href=\"$testref\">", $test, ' (', $format, '/', $offset, ')</a>',
- "(<a href=\"$test.log\">log</a>)", '</td>';
+ print '<tr><td>';
+
+ if ($config_show_inline) {
+ print "$test ($format/$offset) ";
+ print "(<a href=\"" . string_to_data("text/plain",$logs->{$test}) . "\">log</a>)";
+ } else {
+ print "<a href=\"$testref\">", $test, ' (', $format, '/', $offset, ')</a> ';
+ print "(<a href=\"$test.log\">log</a>)";
+ }
+
+ print '</td>';
if ($config_show_ref) {
- print "<td><a href=\"$testref\"><img src=\"$testref\"></img></a></td>";
+ print "<td>" . img_for($testref,1) . "</td>";
}
print $testline;
More information about the cairo-commit
mailing list