--- /dev/null
+/*
+ (c) Copyright 2008 Denis Oliver Kropp
+
+ All rights reserved.
+
+ This file is subject to the terms and conditions of the MIT License:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include <config.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <direct/messages.h>
+
+#include <directfb.h>
+#include <directfb_strings.h>
+#include <directfb_util.h>
+
+static const DirectFBPixelFormatNames( format_names );
+
+/**********************************************************************************************************************/
+
+static DFBBoolean
+parse_format( const char *arg, DFBSurfacePixelFormat *_f )
+{
+ int i = 0;
+
+ while (format_names[i].format != DSPF_UNKNOWN) {
+ if (!strcasecmp( arg, format_names[i].name )) {
+ *_f = format_names[i].format;
+ return DFB_TRUE;
+ }
+
+ ++i;
+ }
+
+ fprintf (stderr, "\nInvalid format specified!\n\n" );
+
+ return DFB_FALSE;
+}
+
+static int
+print_usage( const char *prg )
+{
+ int i = 0;
+
+ fprintf (stderr, "\n");
+ fprintf (stderr, "== DirectFB Fill Rectangle Test (version %s) ==\n", DIRECTFB_VERSION);
+ fprintf (stderr, "\n");
+ fprintf (stderr, "Known pixel formats:\n");
+
+ while (format_names[i].format != DSPF_UNKNOWN) {
+ DFBSurfacePixelFormat format = format_names[i].format;
+
+ fprintf (stderr, " %-10s %2d bits, %d bytes",
+ format_names[i].name, DFB_BITS_PER_PIXEL(format),
+ DFB_BYTES_PER_PIXEL(format));
+
+ if (DFB_PIXELFORMAT_HAS_ALPHA(format))
+ fprintf (stderr, " ALPHA");
+
+ if (DFB_PIXELFORMAT_IS_INDEXED(format))
+ fprintf (stderr, " INDEXED");
+
+ if (DFB_PLANAR_PIXELFORMAT(format)) {
+ int planes = DFB_PLANE_MULTIPLY(format, 1000);
+
+ fprintf (stderr, " PLANAR (x%d.%03d)",
+ planes / 1000, planes % 1000);
+ }
+
+ fprintf (stderr, "\n");
+
+ ++i;
+ }
+
+ fprintf (stderr, "\n");
+
+ fprintf (stderr, "\n");
+ fprintf (stderr, "Usage: %s [options]\n", prg);
+ fprintf (stderr, "\n");
+ fprintf (stderr, "Options:\n");
+ fprintf (stderr, " -h, --help Show this help message\n");
+ fprintf (stderr, " -v, --version Print version information\n");
+ fprintf (stderr, " -d, --dest <pixelformat> Destination pixel format\n");
+
+ return -1;
+}
+
+/**********************************************************************************************************************/
+
+int
+main( int argc, char *argv[] )
+{
+ DFBResult ret;
+ int i;
+ DFBSurfaceDescription desc;
+ IDirectFB *dfb;
+ IDirectFBSurface *dest = NULL;
+ DFBSurfacePixelFormat dest_format = DSPF_UNKNOWN;
+
+ /* Initialize DirectFB. */
+ ret = DirectFBInit( &argc, &argv );
+ if (ret) {
+ D_DERROR( ret, "DFBTest/FillRectangle: DirectFBInit() failed!\n" );
+ return ret;
+ }
+
+ /* Parse arguments. */
+ for (i=1; i<argc; i++) {
+ const char *arg = argv[i];
+
+ if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0)
+ return print_usage( argv[0] );
+ else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) {
+ fprintf (stderr, "dfbtest_blit version %s\n", DIRECTFB_VERSION);
+ return false;
+ }
+ else if (strcmp (arg, "-d") == 0 || strcmp (arg, "--dest") == 0) {
+ if (++i == argc) {
+ print_usage (argv[0]);
+ return false;
+ }
+
+ if (!parse_format( argv[i], &dest_format ))
+ return false;
+ }
+ else
+ return print_usage( argv[0] );
+ }
+
+ /* Create super interface. */
+ ret = DirectFBCreate( &dfb );
+ if (ret) {
+ D_DERROR( ret, "DFBTest/FillRectangle: DirectFBCreate() failed!\n" );
+ return ret;
+ }
+
+ /* Fill description for a primary surface. */
+ desc.flags = DSDESC_CAPS;
+ desc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
+
+ if (dest_format != DSPF_UNKNOWN) {
+ desc.flags |= DSDESC_PIXELFORMAT;
+ desc.pixelformat = dest_format;
+ }
+
+ dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );
+
+ /* Create a primary surface. */
+ ret = dfb->CreateSurface( dfb, &desc, &dest );
+ if (ret) {
+ D_DERROR( ret, "DFBTest/FillRectangle: IDirectFB::CreateSurface() failed!\n" );
+ goto out;
+ }
+
+ dest->GetSize( dest, &desc.width, &desc.height );
+ dest->GetPixelFormat( dest, &desc.pixelformat );
+
+ D_INFO( "DFBTest/FillRectangle: Destination is %dx%d using %s\n",
+ desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );
+
+ while (true) {
+ for (i=0; i<100000; i++) {
+ dest->SetColor( dest, rand()%256, rand()%256, rand()%256, rand()%256 );
+ dest->FillRectangle( dest, rand()%100, rand()%100, rand()%100, rand()%100 );
+ }
+
+ dest->Flip( dest, NULL, DSFLIP_NONE );
+ }
+
+out:
+ if (dest)
+ dest->Release( dest );
+
+ /* Shutdown DirectFB. */
+ dfb->Release( dfb );
+
+ return ret;
+}
+