summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2012-04-27 10:43:05 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2012-04-27 10:43:05 -0400
commit3ff1df243f66eda2f1702601903277d57c3badbb (patch)
treeece54a12237ba25956650bc4e2c10668dee719b4
parentd9a932ac871372ffd7550290e0849a258cc98ce0 (diff)
-rw-r--r--trace/Makefile.am7
-rw-r--r--trace/polygon-replay.c114
2 files changed, 106 insertions, 15 deletions
diff --git a/trace/Makefile.am b/trace/Makefile.am
index 2531be8d..d6d41aef 100644
--- a/trace/Makefile.am
+++ b/trace/Makefile.am
@@ -1,3 +1,6 @@
+AM_CFLAGS = $(OPENMP_CFLAGS)
+AM_LDFLAGS = $(OPENMP_CFLAGS)
+
lib_LTLIBRARIES = libpixman-trace.la libpolygon-extractor.la
INCLUDES = -I$(top_srcdir)/pixman -I$(top_builddir)/pixman $(PNG_CFLAGS)
libpixman_trace_la_SOURCES = pixman-trace.c
@@ -13,5 +16,5 @@ bin_PROGRAMS = pixman-replay polygon-replay
pixman_replay_LDADD = $(top_builddir)/pixman/libpixman-1.la -lm
pixman_replay_SOURCES = pixman-replay.c
-polygon_replay_LDADD = $(top_builddir)/pixman/libpixman-1.la -lm
-polygon_replay_SOURCES = polygon-replay.c
+polygon_replay_LDADD = $(top_builddir)/pixman/libpixman-1.la -lm $(PNG_LIBS)
+polygon_replay_SOURCES = polygon-replay.c ../test/utils.h ../test/utils.c
diff --git a/trace/polygon-replay.c b/trace/polygon-replay.c
index 41b88a60..aeb48e07 100644
--- a/trace/polygon-replay.c
+++ b/trace/polygon-replay.c
@@ -8,6 +8,7 @@
#include <unistd.h>
#include "pixman-private.h"
#include "trace.h"
+#include "../test/utils.h"
#define debugf(...)
//#define debugf printf
@@ -106,19 +107,33 @@ get_segment_24_8 (uint32_t **buffer, pixman_segment_24_8_t *segment)
get_int (buffer, &(segment->dir));
}
-static void
+static uint32_t
get_segments_24_8 (uint32_t **buffer, int *n_segments, pixman_segment_24_8_t **segments)
{
+ uint32_t *before = *buffer;
int i;
*n_segments = read_int (buffer);
+
*segments = realloc (*segments, *n_segments * sizeof (pixman_segment_24_8_t));
for (i = 0; i < *n_segments; ++i)
get_segment_24_8 (buffer, &((*segments)[i]));
+
+ return compute_crc32 (0, before, (*buffer - before) * sizeof (uint32_t));
+}
+
+static inline uint64_t
+rdtsc (void)
+{
+ uint32_t hi, lo;
+
+ __asm__ __volatile__ ("rdtsc\n" : "=a" (lo), "=d" (hi));
+
+ return lo | (((uint64_t)hi) << 32);
}
static void
-polygon_replay (const char *filename)
+polygon_replay (const char *filename, uint32_t only_crc32, int n_iterations)
{
char *error;
uint32_t *buffer, *end;
@@ -145,15 +160,21 @@ polygon_replay (const char *filename)
pixman_segment_24_8_t *segments = NULL;
pixman_image_t *polygon;
pixman_image_t *destination;
+ pixman_color_t zero = { 0x0000, 0x0000, 0x0000, 0x0000 };
+ pixman_image_t *solid;
int width, height;
pixman_region32_t clip;
int src_x, src_y;
int dest_x, dest_y;
+ uint32_t crc32;
+ int i;
+ solid = pixman_image_create_solid_fill (&zero);
+
/* Polygon */
get_int (&buffer, &resample);
get_int (&buffer, &fill_rule);
- get_segments_24_8 (&buffer, &n_segments, &segments);
+ crc32 = get_segments_24_8 (&buffer, &n_segments, &segments);
polygon = pixman_image_create_polygon_from_segments (segments, n_segments);
pixman_image_set_fill_rule (polygon, fill_rule);
pixman_image_set_resample (polygon, resample);
@@ -164,11 +185,10 @@ polygon_replay (const char *filename)
get_int (&buffer, &height);
get_region32 (&buffer, &clip);
- destination = pixman_image_create_bits (PIXMAN_a8r8g8b8, width, height, NULL, -1);
+ destination = pixman_image_create_bits (
+ PIXMAN_a8r8g8b8, width, height, NULL, -1);
pixman_image_set_clip_region32 (destination, &clip);
- pixman_region32_fini (&clip);
- /* Composite */
get_int (&buffer, &src_x);
get_int (&buffer, &src_y);
get_int (&buffer, &dest_x);
@@ -176,11 +196,65 @@ polygon_replay (const char *filename)
get_int (&buffer, &width);
get_int (&buffer, &height);
- pixman_image_composite32 (PIXMAN_OP_SRC,
- polygon, NULL, destination,
- src_x, src_y, 0, 0, dest_x, dest_y,
- width, height);
+ uint64_t total;
+
+ if (n_segments == 4 && dest_x == 0 && dest_y == 0 &&
+ width == 6 && height == 6)
+ {
+#if 0
+ for (i = 0; i < n_segments; ++i)
+ {
+ pixman_segment_24_8_t *segment = &(polygon->polygon.segments[i]);
+
+ printf (" - segment %x %x %x %x (%x %x) ",
+ segment->line.p1.x,
+ segment->line.p1.y,
+ segment->line.p2.x,
+ segment->line.p2.y,
+ segment->top,
+ segment->bottom);
+ }
+ printf ("\n");
+#endif
+ }
+
+ total = 0;
+
+ /* Composite */
+ if (only_crc32 == 0 || (crc32 == only_crc32))
+ {
+ uint64_t before = rdtsc();
+
+ printf ("%d clip rects; %d %d %d %d %d %d\n",
+ pixman_region32_n_rects (&clip),
+ src_x, src_y, dest_x, dest_y, width, height);
+
+ for (i = 0; i < n_iterations; ++i)
+ {
+ pixman_image_composite32 (PIXMAN_OP_SRC,
+ polygon, NULL, destination,
+ src_x, src_y, 0, 0, dest_x, dest_y,
+ width, height);
+
+
+#if 0
+ pixman_image_composite32 (PIXMAN_OP_SRC,
+ solid, NULL, destination,
+ 0, 0, 0, 0, dest_x, dest_y,
+ width, height);
+#endif
+ }
+
+ total += rdtsc() - before;
+
+ printf ("%10ld: crc32: %x (%d segments)\n", total, crc32, n_segments);
+ write_png (destination, "output.png");
+ if (only_crc32)
+ return;
+ }
+
+ pixman_region32_fini (&clip);
pixman_image_unref (polygon);
pixman_image_unref (destination);
}
@@ -191,12 +265,26 @@ polygon_replay (const char *filename)
int
main (int argc, char **argv)
{
- if (argc != 2)
+ uint32_t crc32 = 0;
+ int n_iterations = 1;
+ char *end;
+
+ if (argc == 1)
{
- printf ("Usage: pixman-replay filename\n");
+ printf ("Usage: %s filename\n", argv[0]);
return -1;
}
- polygon_replay (argv[1]);
+ if (argc > 2)
+ {
+ crc32 = strtol (argv[2], &end, 0);
+ }
+
+ if (argc > 3)
+ {
+ n_iterations = strtol (argv[3], &end, 0);
+ }
+
+ polygon_replay (argv[1], crc32, n_iterations);
return 0;
}