1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
/*
(c) Copyright 2012-2013 DirectFB integrated media GmbH
(c) Copyright 2001-2013 The world wide DirectFB Open Source Community (directfb.org)
(c) Copyright 2000-2004 Convergence (integrated media) GmbH
All rights reserved.
Written by Denis Oliver Kropp <dok@directfb.org>,
Andreas Shimokawa <andi@directfb.org>,
Marek Pikarski <mass@directfb.org>,
Sven Neumann <neo@directfb.org>,
Ville Syrjälä <syrjala@sci.fi> and
Claudio Ciccani <klan@users.sf.net>.
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 <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 (!direct_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;
long long ms;
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) );
ms = direct_clock_get_abs_millis();
while (true) {
long long now;
dest->Clear( dest, 0, 0, 0, 0 );
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 );
now = direct_clock_get_abs_millis();
D_INFO( "Took %lld ms\n", now - ms );
ms = now;
}
out:
if (dest)
dest->Release( dest );
/* Shutdown DirectFB. */
dfb->Release( dfb );
return ret;
}
|