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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
|
/*
(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.
*/
#define DIRECT_ENABLE_DEBUG
#include <config.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <direct/messages.h>
#include <direct/util.h>
#include <directfb.h>
#include <directfb_strings.h>
#include <directfb_util.h>
static const DirectFBPixelFormatNames( format_names );
static const DirectFBWindowCapabilitiesNames( caps_names );
static const DirectFBWindowOptionsNames( options_names );
/**********************************************************************************************************************/
static DFBWindowDescription m_desc_top = {
/* .flags =*/ DWDESC_CAPS | DWDESC_POSX | DWDESC_POSY |
DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT | DWDESC_OPTIONS,
/* .caps =*/ DWCAPS_NONE,
/* .width =*/ 200,
/* .height =*/ 200,
/* .pixelformat =*/ DSPF_UNKNOWN,
/* .posx =*/ 100,
/* .posy =*/ 100,
};
static DFBWindowDescription m_desc_sub = {
/* .flags =*/ DWDESC_CAPS | DWDESC_POSX | DWDESC_POSY |
DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT | DWDESC_OPTIONS | DWDESC_TOPLEVEL_ID,
/* .caps =*/ DWCAPS_NONE,
/* .width =*/ 120,
/* .height =*/ 120,
/* .pixelformat =*/ DSPF_UNKNOWN,
/* .posx =*/ 40,
/* .posy =*/ 40,
};
static struct {
bool valid;
DFBColor color;
} m_topcolor, m_subcolor;
static IDirectFBWindow *m_toplevel = NULL;
static DFBWindowID m_toplevel_id = 0;
static IDirectFBWindow *m_subwindow = NULL;
static DFBWindowID m_subwindow_id = 0;
static DFBBoolean m_wait_at_end = DFB_FALSE;
/**********************************************************************************************************************/
typedef DFBResult (*TestFunc)( IDirectFBDisplayLayer *layer, void *arg );
/**********************************************************************************************************************/
static DFBResult Test_CreateWindow( IDirectFBDisplayLayer *layer, void *arg );
static DFBResult Test_CreateSubWindow( IDirectFBDisplayLayer *layer, void *arg );
/**********************************************************************************************************************/
static DFBResult Test_WarpCursor( IDirectFBDisplayLayer *layer, void *arg );
/**********************************************************************************************************************/
static DFBResult Test_MoveWindow( IDirectFBDisplayLayer *layer, void *arg );
static DFBResult Test_ScaleWindow( IDirectFBDisplayLayer *layer, void *arg );
/**********************************************************************************************************************/
static DFBResult Test_RestackWindow( IDirectFBDisplayLayer *layer, void *arg );
/**********************************************************************************************************************/
static DFBResult Test_SrcGeometry( IDirectFBDisplayLayer *layer, void *arg );
static DFBResult Test_DstGeometry( IDirectFBDisplayLayer *layer, void *arg );
/**********************************************************************************************************************/
static DFBResult Test_HideWindow( IDirectFBDisplayLayer *layer, void *arg );
static DFBResult Test_DestroyWindow( IDirectFBDisplayLayer *layer, void *arg );
/**********************************************************************************************************************/
typedef struct {
const char *name;
TestFunc func;
bool run_top;
bool run_sub;
} Test;
static Test m_tests[] = {
{ "WarpCursor", Test_WarpCursor },
{ "Restack", Test_RestackWindow },
{ "Move", Test_MoveWindow },
{ "Scale", Test_ScaleWindow },
{ "SrcGeometry", Test_SrcGeometry },
{ "DstGeometry", Test_DstGeometry },
{ "Hide", Test_HideWindow },
{ "Destroy", Test_DestroyWindow },
};
/**********************************************************************************************************************/
static DFBResult RunTest( TestFunc func, const char *func_name, IDirectFBDisplayLayer *layer, void *arg );
/**********************************************************************************************************************/
static void ShowMessage( unsigned int ms, const char *name,
const char *prefix, const char *format, ... ) D_FORMAT_PRINTF(4);
#define SHOW_TEST(...) ShowMessage( 2000, __FUNCTION__, \
"===============================================================\n\n", __VA_ARGS__ )
#define SHOW_INFO(...) ShowMessage( 500, __FUNCTION__, "", __VA_ARGS__ )
#define SHOW_RESULT(...) ShowMessage( 3000, __FUNCTION__, "", __VA_ARGS__ )
/**********************************************************************************************************************/
static bool parse_command_line( int argc, char *argv[] );
/**********************************************************************************************************************/
int
main( int argc, char *argv[] )
{
DFBResult ret;
int i;
IDirectFB *dfb;
IDirectFBDisplayLayer *layer;
/* Initialize DirectFB including command line parsing. */
ret = DirectFBInit( &argc, &argv );
if (ret) {
DirectFBError( "DirectFBInit() failed", ret );
return -1;
}
/* Parse the command line. */
if (!parse_command_line( argc, argv ))
return -2;
SHOW_INFO( "Starting up..." );
/* Create the super interface. */
ret = DirectFBCreate( &dfb );
if (ret) {
DirectFBError( "DirectFBCreate() failed", ret );
return -3;
}
/* Get the primary layer interface. */
ret = dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );
if (ret) {
D_DERROR( ret, "IDirectFB::GetDisplayLayer() failed!\n" );
dfb->Release( dfb );
return -4;
}
if (!m_toplevel_id)
RunTest( Test_CreateWindow, "CreateWindow", layer, NULL );
RunTest( Test_CreateSubWindow, "CreateSubWindow", layer, NULL );
for (i=0; i<D_ARRAY_SIZE(m_tests); i++) {
if (m_tests[i].run_top)
RunTest( m_tests[i].func, m_tests[i].name, layer, NULL );
if (m_tests[i].run_sub)
RunTest( m_tests[i].func, m_tests[i].name, layer, (void*) (unsigned long) m_subwindow_id );
}
while (m_wait_at_end)
direct_thread_sleep( 1000000 );
SHOW_INFO( "Shutting down..." );
/* Release the sub window. */
if (m_subwindow)
m_subwindow->Release( m_subwindow );
/* Release the top level. */
if (m_toplevel)
m_toplevel->Release( m_toplevel );
/* Release the layer. */
layer->Release( layer );
/* Release the super interface. */
dfb->Release( dfb );
return EXIT_SUCCESS;
}
/**********************************************************************************************************************/
static void
print_usage (const char *prg_name)
{
int i = 0;
fprintf (stderr, "\n");
fprintf (stderr, "== DirectFB Window 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, "Known window capabilities:\n");
for (i=0; caps_names[i].capability != DWCAPS_NONE; i++)
fprintf (stderr, " %s\n", caps_names[i].name);
fprintf (stderr, "\n");
fprintf (stderr, "Known window options:\n");
for (i=0; options_names[i].option != DWOP_NONE; i++)
fprintf (stderr, " %s\n", options_names[i].name);
fprintf (stderr, "\n");
fprintf (stderr, "\n");
fprintf (stderr, "Usage: %s [options]\n", prg_name);
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, " -T, --top-level <toplevel_id> WindowID (skips top creation)\n");
fprintf (stderr, " -W, --wait-at-end Wait at the end (don't exit)\n");
fprintf (stderr, "\n");
fprintf (stderr, "Top window:\n");
fprintf (stderr, " -r, --run <test> Run test (see list below)\n");
fprintf (stderr, " -p, --pos <posx>,<posy> Position (%d,%d)\n", m_desc_top.posx, m_desc_top.posy);
fprintf (stderr, " -s, --size <width>x<height> Size (%dx%d)\n", m_desc_top.width, m_desc_top.height);
fprintf (stderr, " -f, --format <pixelformat> Pixel Format (%s)\n", dfb_pixelformat_name(m_desc_top.pixelformat));
fprintf (stderr, " -c, --caps <window_caps> Capabilities (NONE)\n");
fprintf (stderr, " -l, --color <aarrggbb> Fixed Color (NONE)\n");
fprintf (stderr, " -o, --option <window_option> Options (NONE)\n");
fprintf (stderr, " -a, --associate <parent_id> Association (N/A)\n");
fprintf (stderr, "\n");
fprintf (stderr, "Sub window:\n");
fprintf (stderr, " -R, --sub-run <test> Run test (see list below)\n");
fprintf (stderr, " -P, --sub-pos <posx>,<posy> Position (%d,%d)\n", m_desc_sub.posx, m_desc_sub.posy);
fprintf (stderr, " -S, --sub-size <width>x<height> Size (%dx%d)\n", m_desc_sub.width, m_desc_sub.height);
fprintf (stderr, " -F, --sub-format <pixelformat> Format (%s)\n", dfb_pixelformat_name(m_desc_sub.pixelformat));
fprintf (stderr, " -C, --sub-caps <window_caps> Capabilities (NONE)\n");
fprintf (stderr, " -L, --sub-color <aarrggbb> Fixed Color (NONE)\n");
fprintf (stderr, " -O, --sub-option <window_option> Options (NONE)\n");
fprintf (stderr, " -A, --sub-associate <parent_id> Association (N/A)\n");
fprintf (stderr, "\n");
fprintf (stderr, "Available tests:\n");
for (i=0; i<D_ARRAY_SIZE(m_tests); i++)
fprintf (stderr, " %s\n", m_tests[i].name);
fprintf (stderr, "\n");
}
static DFBBoolean
parse_test( const char *arg, bool sub )
{
int i;
for (i=0; i<D_ARRAY_SIZE(m_tests); i++) {
if (!direct_strncasecmp( arg, m_tests[i].name, strlen(arg) )) {
if (sub)
m_tests[i].run_sub = true;
else
m_tests[i].run_top = true;
return DFB_TRUE;
}
}
fprintf (stderr, "\nInvalid test specified!\n\n" );
return DFB_FALSE;
}
static DFBBoolean
parse_position( const char *arg, int *_x, int *_y )
{
if (sscanf( arg, "%d,%d", _x, _y ) != 2) {
fprintf (stderr, "\nInvalid position specified!\n\n" );
return DFB_FALSE;
}
return DFB_TRUE;
}
static DFBBoolean
parse_size( const char *arg, int *_w, int *_h )
{
if (sscanf( arg, "%dx%d", _w, _h ) != 2 || *_w < 1 || *_h < 1) {
fprintf (stderr, "\nInvalid size specified!\n\n" );
return DFB_FALSE;
}
return DFB_TRUE;
}
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 DFBBoolean
parse_caps( const char *arg, DFBWindowCapabilities *_c )
{
int i = 0;
while (caps_names[i].capability != DWCAPS_NONE) {
if (!direct_strncasecmp( arg, caps_names[i].name, strlen(arg) )) {
*_c |= caps_names[i].capability;
return DFB_TRUE;
}
++i;
}
fprintf (stderr, "\nInvalid caps specified!\n\n" );
return DFB_FALSE;
}
static DFBBoolean
parse_color( const char *arg, DFBColor *_c )
{
long int l = 0;
char *end = 0;
DFBColor c;
l = strtol( arg, &end, 16 );
if( strlen(arg)>8 || (end && *end!=0) ) {
fprintf (stderr, "\nInvalid color specified!\n\n" );
return DFB_FALSE;
}
c.a = (l >> 24) ;
c.r = (l >> 16) & 0xff;
c.g = (l >> 8) & 0xff;
c.b = (l ) & 0xff;
*_c = c;
return DFB_TRUE;
}
static DFBBoolean
parse_option( const char *arg, DFBWindowOptions *_o )
{
int i = 0;
while (options_names[i].option != DWOP_NONE) {
if (!direct_strncasecmp( arg, options_names[i].name, strlen(arg) )) {
*_o |= options_names[i].option;
return DFB_TRUE;
}
++i;
}
fprintf (stderr, "\nInvalid options specified!\n\n" );
return DFB_FALSE;
}
static DFBBoolean
parse_id( const char *arg, unsigned int *_id )
{
if (sscanf( arg, "%u", _id ) != 1) {
fprintf (stderr, "\nInvalid ID specified!\n\n" );
return DFB_FALSE;
}
return DFB_TRUE;
}
static bool
parse_command_line( int argc, char *argv[] )
{
int n;
for (n = 1; n < argc; n++) {
const char *arg = argv[n];
if (strcmp (arg, "-h") == 0 || strcmp (arg, "--help") == 0) {
print_usage (argv[0]);
return false;
}
if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) {
fprintf (stderr, "dfbg version %s\n", DIRECTFB_VERSION);
return false;
}
if (strcmp (arg, "-T") == 0 || strcmp (arg, "--top-level") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_id( argv[n], &m_toplevel_id ))
return false;
continue;
}
if (strcmp (arg, "-W") == 0 || strcmp (arg, "--wait-at-end") == 0) {
m_wait_at_end = DFB_TRUE;
continue;
}
if (strcmp (arg, "-r") == 0 || strcmp (arg, "--run") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_test( argv[n], false ))
return false;
continue;
}
if (strcmp (arg, "-p") == 0 || strcmp (arg, "--pos") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_position( argv[n], &m_desc_top.posx, &m_desc_top.posy ))
return false;
continue;
}
if (strcmp (arg, "-s") == 0 || strcmp (arg, "--size") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_size( argv[n], &m_desc_top.width, &m_desc_top.height ))
return false;
continue;
}
if (strcmp (arg, "-f") == 0 || strcmp (arg, "--format") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_format( argv[n], &m_desc_top.pixelformat ))
return false;
continue;
}
if (strcmp (arg, "-c") == 0 || strcmp (arg, "--caps") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_caps( argv[n], &m_desc_top.caps ))
return false;
continue;
}
if (strcmp (arg, "-l") == 0 || strcmp (arg, "--color") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_color( argv[n], &m_topcolor.color ))
return false;
m_topcolor.valid = true;
continue;
}
if (strcmp (arg, "-o") == 0 || strcmp (arg, "--option") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_option( argv[n], &m_desc_top.options ))
return false;
continue;
}
if (strcmp (arg, "-a") == 0 || strcmp (arg, "--associate") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_id( argv[n], &m_desc_top.parent_id ))
return false;
// m_desc_top.flags |= DWDESC_PARENT;
m_desc_top.options |= DWOP_FOLLOW_BOUNDS;
continue;
}
if (strcmp (arg, "-R") == 0 || strcmp (arg, "--sub-run") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_test( argv[n], true ))
return false;
continue;
}
if (strcmp (arg, "-P") == 0 || strcmp (arg, "--sub-pos") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_position( argv[n], &m_desc_sub.posx, &m_desc_sub.posy ))
return false;
continue;
}
if (strcmp (arg, "-S") == 0 || strcmp (arg, "--sub-size") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_size( argv[n], &m_desc_sub.width, &m_desc_sub.height ))
return false;
continue;
}
if (strcmp (arg, "-F") == 0 || strcmp (arg, "--sub-format") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_format( argv[n], &m_desc_sub.pixelformat ))
return false;
continue;
}
if (strcmp (arg, "-C") == 0 || strcmp (arg, "--sub-caps") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_caps( argv[n], &m_desc_sub.caps ))
return false;
continue;
}
if (strcmp (arg, "-L") == 0 || strcmp (arg, "--sub-color") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_color( argv[n], &m_subcolor.color ))
return false;
m_subcolor.valid = true;
continue;
}
if (strcmp (arg, "-O") == 0 || strcmp (arg, "--sub-option") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_option( argv[n], &m_desc_sub.options ))
return false;
continue;
}
if (strcmp (arg, "-A") == 0 || strcmp (arg, "--sub-associate") == 0) {
if (++n == argc) {
print_usage (argv[0]);
return false;
}
if (!parse_id( argv[n], &m_desc_sub.parent_id ))
return false;
// m_desc_sub.flags |= DWDESC_PARENT;
m_desc_sub.options |= DWOP_FOLLOW_BOUNDS;
continue;
}
print_usage (argv[0]);
return false;
}
return true;
}
/**********************************************************************************************************************/
static DFBResult
RunTest( TestFunc func,
const char *test_name,
IDirectFBDisplayLayer *layer,
void *arg )
{
DFBResult ret;
/* Run the actual test... */
ret = func( layer, arg );
if (ret)
D_DERROR( ret, "RunTest: '%s' failed!\n", test_name );
return ret;
}
/**********************************************************************************************************************/
static void
ShowMessage( unsigned int ms, const char *name, const char *prefix, const char *format, ... )
{
char buf[512];
va_list ap;
va_start( ap, format );
vsnprintf( buf, sizeof(buf), format, ap );
va_end( ap );
direct_log_printf( NULL, "%s [[ %-30s ]] %s\n", prefix, name, buf );
direct_thread_sleep( ms * 1000 );
}
/**********************************************************************************************************************/
#define _T(...) \
do { \
DFBResult ret = __VA_ARGS__; \
\
if (ret) { \
D_DERROR( ret, "Tests/Window: '%s' failed!\n", #__VA_ARGS__ ); \
return ret; \
} \
} while (0)
/**********************************************************************************************************************/
static DFBResult
Test_CreateWindow( IDirectFBDisplayLayer *layer, void *arg )
{
IDirectFBSurface *surface = NULL;
IDirectFBWindow *window;
DFBWindowID window_id;
DFBDimension size = { m_desc_top.width, m_desc_top.height };
D_ASSERT( m_toplevel_id == 0 );
/*
* Create a new top level window
*/
SHOW_TEST( "CreateWindow( %d,%d - %dx%d %s, options 0x%08x )...",
m_desc_top.posx, m_desc_top.posy, m_desc_top.width, m_desc_top.height,
dfb_pixelformat_name( m_desc_top.pixelformat ), m_desc_top.options );
_T( layer->CreateWindow( layer, &m_desc_top, &window ) );
if (m_topcolor.valid) {
DFBColor c = m_topcolor.color;
SHOW_INFO( " - SetColor( 0x%02x, 0x%02x, 0x%02x, 0x%02x )...", c.r, c.g, c.b, c.a );
_T( window->SetColor( window, c.r, c.g, c.b, c.a ) );
}
/*
* Query its surface and clear it with light blue (if not input or color only)
*/
if (!(m_desc_top.caps & (DWCAPS_INPUTONLY | DWCAPS_COLOR) )) {
SHOW_INFO( " - GetSurface()..." );
_T( window->GetSurface( window, &surface ) );
SHOW_INFO( " - Clear( 0x20, 0x50, 0xC0, 0xFF )..." );
_T( surface->Clear( surface, 0x20, 0x50, 0xC0, 0xFF ) );
_T( surface->SetColor( surface, 0x90, 0xF0, 0xC0, 0xFF ) );
_T( surface->DrawRectangle( surface, 0, 0, size.w, size.h ) );
_T( surface->FillRectangle( surface, size.w / 2, 1, 1, size.h - 2 ) );
_T( surface->FillRectangle( surface, 1, size.h / 2, size.w - 2, 1 ) );
}
/*
* Show the window
*/
SHOW_INFO( " - SetOpacity( 255 )..." );
_T( window->SetOpacity( window, 0xff ) );
/*
* Query and print ID of new window
*/
SHOW_INFO( " - GetID()..." );
_T( window->GetID( window, &window_id ) );
/*
* Set association of new window
*/
if (m_desc_top.parent_id) {
SHOW_INFO( " - SetAssociation( %u )...", m_desc_top.parent_id );
_T( window->SetAssociation( window, m_desc_top.parent_id ) );
}
/*
* Set top level window ID (user hasn't specified one)
*/
m_toplevel_id = window_id;
m_toplevel = window;
SHOW_RESULT( "...CreateWindow( %d,%d - %dx%d %s ) done. => Top Window ID %u",
m_desc_top.posx, m_desc_top.posy, m_desc_top.width, m_desc_top.height,
dfb_pixelformat_name( m_desc_top.pixelformat ), window_id );
if (surface)
surface->Release( surface );
return DFB_OK;
}
static DFBResult
Test_CreateSubWindow( IDirectFBDisplayLayer *layer, void *arg )
{
IDirectFBWindow *window;
DFBWindowID window_id;
DFBDimension size = { m_desc_sub.width, m_desc_sub.height };
D_ASSERT( m_toplevel_id != 0 );
/* Write window ID of top level into description */
m_desc_sub.toplevel_id = m_toplevel_id;
/*
* Create a new sub window with 75% width/height and positioned at 20,20 within top level window
*/
SHOW_TEST( "CreateWindow( %d,%d - %dx%d %s + toplevel ID %u, options 0x%08x )...",
m_desc_sub.posx, m_desc_sub.posy, m_desc_sub.width, m_desc_sub.height,
dfb_pixelformat_name( m_desc_sub.pixelformat ), m_desc_sub.toplevel_id, m_desc_top.options );
_T( layer->CreateWindow( layer, &m_desc_sub, &window ) );
if (m_subcolor.valid) {
DFBColor c = m_subcolor.color;
SHOW_INFO( " - SetColor( 0x%02x, 0x%02x, 0x%02x, 0x%02x )...", c.r, c.g, c.b, c.a );
_T( window->SetColor( window, c.r, c.g, c.b, c.a ) );
}
/*
* Query its surface and clear it with light gray (if not input or color only)
*/
if (!(m_desc_sub.caps & (DWCAPS_INPUTONLY | DWCAPS_COLOR) )) {
IDirectFBSurface *surface;
SHOW_INFO( " - GetSurface()..." );
_T( window->GetSurface( window, &surface ) );
SHOW_INFO( " - Clear( 0xC0, 0xC0, 0xC0, 0xFF )..." );
_T( surface->Clear( surface, 0xC0, 0xC0, 0xC0, 0xFF ) );
_T( surface->DrawRectangle( surface, 0, 0, size.w, size.h ) );
_T( surface->FillRectangle( surface, size.w / 2, 1, 1, size.h - 2 ) );
_T( surface->FillRectangle( surface, 1, size.h / 2, size.w - 2, 1 ) );
surface->Release( surface );
}
/*
* Show the window
*/
SHOW_INFO( " - SetOpacity( 255 )..." );
_T( window->SetOpacity( window, 0xff ) );
/*
* Query and print ID of new window
*/
SHOW_INFO( " - GetID()..." );
_T( window->GetID( window, &window_id ) );
/*
* Set association of new window
*/
if (m_desc_sub.parent_id) {
SHOW_INFO( " - SetAssociation( %u )...", m_desc_sub.parent_id );
_T( window->SetAssociation( window, m_desc_sub.parent_id ) );
}
/*
* Set top level window ID (user hasn't specified one)
*/
m_subwindow_id = window_id;
m_subwindow = window;
SHOW_RESULT( "...CreateWindow( %d,%d - %dx%d %s + toplevel ID %u ) done. => Sub Window ID %u",
m_desc_sub.posx, m_desc_sub.posy, m_desc_sub.width, m_desc_sub.height,
dfb_pixelformat_name( m_desc_sub.pixelformat ), m_desc_sub.toplevel_id, window_id );
return DFB_OK;
}
static DFBResult
Test_WarpCursor( IDirectFBDisplayLayer *layer, void *arg )
{
int i;
DFBPoint pos;
/*
* Warp the cursor
*/
_T( layer->SetCooperativeLevel( layer, DLSCL_ADMINISTRATIVE ) );
_T( layer->GetCursorPosition( layer, &pos.x, &pos.y ) );
{
DFBPoint poss[] = { { pos.x - 40, pos.y - 40 },
{ pos.x + 40, pos.y - 40 },
{ pos.x + 40, pos.y + 40 },
{ pos.x - 40, pos.y + 40 },
{ pos.x , pos.y } };
for (i=0; i<D_ARRAY_SIZE(poss); i++) {
SHOW_TEST( "WarpCursor( %4d,%4d - [%02d] )...", poss[i].x, poss[i].y, i );
_T( layer->WarpCursor( layer, poss[i].x, poss[i].y ) );
SHOW_RESULT( "...WarpCursor( %4d,%4d - [%02d] ) done.", poss[i].x, poss[i].y, i );
}
}
return DFB_OK;
}
static DFBResult
Test_MoveWindow( IDirectFBDisplayLayer *layer, void *arg )
{
int i;
DFBPoint pos;
IDirectFBWindow *window;
D_ASSERT( m_toplevel_id != 0 );
/*
* Get the top level window
*/
_T( layer->GetWindow( layer, arg ? (unsigned long) arg : m_toplevel_id, &window ) );
window->GetPosition( window, &pos.x, &pos.y );
/*
* Move the window
*/
{
DFBPoint poss[] = { { pos.x - 40, pos.y - 40 },
{ pos.x + 40, pos.y - 40 },
{ pos.x + 40, pos.y + 40 },
{ pos.x - 40, pos.y + 40 },
{ pos.x , pos.y } };
for (i=0; i<D_ARRAY_SIZE(poss); i++) {
SHOW_TEST( "MoveTo( %4d,%4d - [%02d] )...", poss[i].x, poss[i].y, i );
_T( window->MoveTo( window, poss[i].x, poss[i].y ) );
SHOW_RESULT( "...MoveTo( %4d,%4d - [%02d] ) done.", poss[i].x, poss[i].y, i );
}
}
window->Release( window );
return DFB_OK;
}
static DFBResult
Test_ScaleWindow( IDirectFBDisplayLayer *layer, void *arg )
{
int i;
IDirectFBWindow *window;
DFBWindowOptions opts;
DFBDimension size;
D_ASSERT( m_toplevel_id != 0 );
/*
* Get the top level window
*/
_T( layer->GetWindow( layer, arg ? (unsigned long) arg : m_toplevel_id, &window ) );
window->GetSize( window, &size.w, &size.h );
/*
* Enable scaling
*/
_T( window->GetOptions( window, &opts ) );
_T( window->SetOptions( window, opts | DWOP_SCALE ) );
/*
* Scale the window
*/
{
DFBDimension sizes[] = { { size.w + 40, size.h },
{ size.w + 40, size.h + 40 },
{ size.w, size.h + 40 },
{ size.w + 40, size.h - 40 },
{ size.w - 40, size.h + 40 },
{ size.w, size.h } };
for (i=0; i<D_ARRAY_SIZE(sizes); i++) {
SHOW_TEST( "Resize( %4d,%4d - [%02d] )...", sizes[i].w, sizes[i].h, i );
_T( window->Resize( window, sizes[i].w, sizes[i].h ) );
SHOW_RESULT( "...Resize( %4d,%4d - [%02d] ) done.", sizes[i].w, sizes[i].h, i );
}
}
/*
* Restore options
*/
_T( window->SetOptions( window, opts ) );
window->Release( window );
return DFB_OK;
}
static DFBResult
Test_RestackWindow( IDirectFBDisplayLayer *layer, void *arg )
{
int i;
IDirectFBWindow *window;
D_ASSERT( m_toplevel_id != 0 );
/*
* Get the top level window
*/
_T( layer->GetWindow( layer, arg ? (unsigned long) arg : m_toplevel_id, &window ) );
/*
* Lower it a few times
*/
for (i=0; i<2; i++) {
SHOW_TEST( "Lower() #%d...", i+1 );
_T( window->Lower( window ) );
SHOW_RESULT( "...Lower() #%d done.", i+1 );
}
/*
* Raise it a few times
*/
for (i=0; i<2; i++) {
SHOW_TEST( "Raise() #%d...", i+1 );
_T( window->Raise( window ) );
SHOW_RESULT( "...Raise() #%d done.", i+1 );
}
/*
* Lower it to the bottom
*/
SHOW_TEST( "LowerToBottom()..." );
_T( window->LowerToBottom( window ) );
SHOW_RESULT( "...LowerToBottom() done." );
/*
* Raise it to the top
*/
SHOW_TEST( "RaiseToTop()..." );
_T( window->RaiseToTop( window ) );
SHOW_RESULT( "...RaiseToTop() done." );
window->Release( window );
return DFB_OK;
}
static DFBResult
Test_SrcGeometry( IDirectFBDisplayLayer *layer, void *arg )
{
int i;
IDirectFBWindow *window;
DFBWindowGeometry geometry;
DFBDimension size;
D_ASSERT( m_toplevel_id != 0 );
/*
* Get the top level window
*/
_T( layer->GetWindow( layer, arg ? (unsigned long) arg : m_toplevel_id, &window ) );
window->GetSize( window, &size.w, &size.h );
/*
* Change source geometry
*/
{
DFBRectangle rects[] = { { 0, 0, size.w / 2, size.h / 2 },
{ size.w / 2, 0, size.w / 2, size.h / 2 },
{ size.w / 2, size.h / 2, size.w / 2, size.h / 2 },
{ 0, size.h / 2, size.w / 2, size.h / 2 } };
for (i=0; i<D_ARRAY_SIZE(rects); i++) {
SHOW_TEST( "SetSrcGeometry( %4d,%4d-%4dx%4d - [%02d] )...", DFB_RECTANGLE_VALS(&rects[i]), i );
geometry.mode = DWGM_RECTANGLE;
geometry.rectangle = rects[i];
_T( window->SetSrcGeometry( window, &geometry ) );
SHOW_RESULT( "...SetSrcGeometry( %4d,%4d-%4dx%4d - [%02d] ) done.", DFB_RECTANGLE_VALS(&rects[i]), i );
}
}
SHOW_TEST( "SetSrcGeometry( DEFAULT )..." );
geometry.mode = DWGM_DEFAULT;
_T( window->SetSrcGeometry( window, &geometry ) );
SHOW_RESULT( "...SetSrcGeometry( DEFAULT ) done." );
window->Release( window );
return DFB_OK;
}
static DFBResult
Test_DstGeometry( IDirectFBDisplayLayer *layer, void *arg )
{
int i;
IDirectFBWindow *window;
DFBWindowGeometry geometry;
DFBDimension size;
D_ASSERT( m_toplevel_id != 0 );
/*
* Get the top level window
*/
_T( layer->GetWindow( layer, arg ? (unsigned long) arg : m_toplevel_id, &window ) );
window->GetSize( window, &size.w, &size.h );
/*
* Change destination geometry
*/
{
DFBRectangle rects[] = { { 0, 0, size.w / 2, size.h / 2 },
{ size.w / 2, 0, size.w / 2, size.h / 2 },
{ size.w / 2, size.h / 2, size.w / 2, size.h / 2 },
{ 0, size.h / 2, size.w / 2, size.h / 2 } };
for (i=0; i<D_ARRAY_SIZE(rects); i++) {
SHOW_TEST( "SetDstGeometry( %4d,%4d-%4dx%4d - [%02d] )...", DFB_RECTANGLE_VALS(&rects[i]), i );
geometry.mode = DWGM_RECTANGLE;
geometry.rectangle = rects[i];
_T( window->SetDstGeometry( window, &geometry ) );
SHOW_RESULT( "...SetDstGeometry( %4d,%4d-%4dx%4d - [%02d] ) done.", DFB_RECTANGLE_VALS(&rects[i]), i );
}
}
SHOW_TEST( "SetDstGeometry( DEFAULT )..." );
geometry.mode = DWGM_DEFAULT;
_T( window->SetDstGeometry( window, &geometry ) );
SHOW_RESULT( "...SetDstGeometry( DEFAULT ) done." );
window->Release( window );
return DFB_OK;
}
static DFBResult
Test_HideWindow( IDirectFBDisplayLayer *layer, void *arg )
{
IDirectFBWindow *window;
D_ASSERT( m_toplevel_id != 0 );
/*
* Get the top level window
*/
_T( layer->GetWindow( layer, arg ? (unsigned long) arg : m_toplevel_id, &window ) );
/*
* Hide it
*/
SHOW_TEST( "SetOpacity( 0 )..." );
_T( window->SetOpacity( window, 0 ) );
SHOW_RESULT( "...SetOpacity( 0 ) done." );
/*
* Show it again
*/
SHOW_TEST( "SetOpacity( 0xff )..." );
_T( window->SetOpacity( window, 0xff ) );
SHOW_RESULT( "...SetOpacity( 0xff ) done." );
window->Release( window );
return DFB_OK;
}
static DFBResult
Test_DestroyWindow( IDirectFBDisplayLayer *layer, void *arg )
{
IDirectFBWindow *window;
D_ASSERT( m_toplevel_id != 0 );
/*
* Get the top level window
*/
_T( layer->GetWindow( layer, arg ? (unsigned long) arg : m_toplevel_id, &window ) );
/*
* Destroy it
*/
SHOW_TEST( "Destroy()..." );
_T( window->Destroy( window ) );
SHOW_RESULT( "...Destroy() done." );
window->Release( window );
return DFB_OK;
}
|