Non reinvents the DAW. Powerful enough to form a complete studio, fast and light enough to run on low-end hardware like the eeePC or Raspberry Pi, and so reliable that it can be used live https://non.tuxfamily.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
4.4KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2012 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include <FL/Fl.H>
  19. #include <FL/Fl_Double_Window.H>
  20. #include <FL/Fl_Single_Window.H>
  21. #include <FL/Fl_Pack.H>
  22. #include <FL/Fl_Choice.H>
  23. #include <FL/fl_draw.H>
  24. #include <sys/time.h>
  25. #include <stdio.h>
  26. static Fl_Boxtype boxtype = FL_UP_BOX;
  27. #include <unistd.h>
  28. unsigned long long tv_to_ts ( timeval *tv )
  29. {
  30. return tv->tv_sec * 1e6 + tv->tv_usec;
  31. }
  32. unsigned long long get_ts ( void )
  33. {
  34. struct timeval then;
  35. gettimeofday( &then, NULL );
  36. return tv_to_ts( &then );
  37. }
  38. class PerfTest : public Fl_Widget
  39. {
  40. public:
  41. PerfTest ( int X, int Y, int W, int H, const char *L=0 ) : Fl_Widget( X, Y, W, H, L )
  42. {
  43. align(FL_ALIGN_TOP | FL_ALIGN_RIGHT |FL_ALIGN_INSIDE);
  44. box(FL_UP_BOX);
  45. labelcolor( FL_WHITE );
  46. use_cairo = false;
  47. }
  48. bool use_cairo;
  49. void draw ( void )
  50. {
  51. if ( use_cairo )
  52. fl_push_use_cairo(true);
  53. fl_rectf( x(), y(), w(), h(), FL_BLACK );
  54. unsigned long long then = get_ts();
  55. fl_push_clip( x(), y(), w(), h() );
  56. int count = 400;
  57. /* draw stuff */
  58. int i = 0;
  59. for ( ; i < count; ++i )
  60. fl_draw_box( boxtype, x(), y(), w(), h(), fl_lighter( FL_BLACK ) );
  61. fl_pop_clip();
  62. unsigned long long now = get_ts();
  63. double elapsedms = (now - then) / 1000.0;
  64. static char text[256];
  65. sprintf( text, "Drew %i boxes in in %fms", i, elapsedms );
  66. fl_color( FL_RED );
  67. fl_draw( text, x(), y(), w(), h(), FL_ALIGN_CENTER | FL_ALIGN_INSIDE );
  68. draw_label();
  69. if ( use_cairo )
  70. fl_pop_use_cairo();
  71. }
  72. };
  73. void
  74. boxtype_cb ( Fl_Widget *w, void *v )
  75. {
  76. const char *picked = ((Fl_Choice*)w)->mvalue()->label();
  77. if ( !strcmp( picked, "UP_BOX" ) )
  78. boxtype = FL_UP_BOX;
  79. else if ( !strcmp( picked, "FLAT_BOX" ) )
  80. boxtype = FL_FLAT_BOX;
  81. else if ( !strcmp( picked, "ROUNDED_BOX" ) )
  82. boxtype = FL_ROUNDED_BOX;
  83. else if ( !strcmp( picked, "OVAL_BOX" ) )
  84. boxtype = FL_OVAL_BOX;
  85. w->window()->redraw();
  86. }
  87. int
  88. main ( int argc, char **argv )
  89. {
  90. {
  91. Fl_Single_Window *w = new Fl_Single_Window( 800, 600 );
  92. { Fl_Choice *o = new Fl_Choice( 0, 0, 200, 24, "Boxtype" );
  93. o->align( FL_ALIGN_RIGHT );
  94. o->callback( boxtype_cb, NULL );
  95. o->add( "UP_BOX" );
  96. o->add( "FLAT_BOX" );
  97. o->add( "ROUNDED_BOX" );
  98. o->add( "OVAL_BOX" );
  99. }
  100. {
  101. Fl_Pack *o = new Fl_Pack( 0, 24, 800, 600 - 24 );
  102. o->type( 0 );
  103. {
  104. PerfTest *o = new PerfTest( 0,0, 800, 400, "Xlib" );
  105. }
  106. {
  107. PerfTest *o = new PerfTest( 0,0, 800, 400, "Cairo" );
  108. o->use_cairo = true;
  109. }
  110. o->end();
  111. }
  112. w->end();
  113. w->show();
  114. }
  115. /* { */
  116. /* Fl_Single_Window *w = new Fl_Single_Window( 800, 600 ); */
  117. /* PerfTest *o = new PerfTest( 0,0, 800, 600 ); */
  118. /* w->end(); */
  119. /* w->show(); */
  120. /* } */
  121. Fl::run();
  122. }