+
+
+ void BenchmarkRectangles(const wxString& msg, wxDC& dc)
+ {
+ if ( !opts.testRectangles )
+ return;
+
+ if ( opts.mapMode != 0 )
+ dc.SetMapMode((wxMappingMode)opts.mapMode);
+ if ( opts.penWidth != 0 )
+ dc.SetPen(wxPen(*wxWHITE, opts.penWidth));
+
+ dc.SetBrush( *wxRED_BRUSH );
+
+ wxPrintf("Benchmarking %s: ", msg);
+ fflush(stdout);
+
+ wxStopWatch sw;
+ for ( int n = 0; n < opts.numIters; n++ )
+ {
+ int x = rand() % opts.width,
+ y = rand() % opts.height;
+
+ dc.DrawRectangle(x, y, 32, 32);
+ }
+
+ const long t = sw.Time();
+
+ wxPrintf("%ld rects done in %ldms = %gus/rect\n",
+ opts.numIters, t, (1000. * t)/opts.numIters);
+ }
+
+ void BenchmarkBitmaps(const wxString& msg, wxDC& dc)
+ {
+ if ( !opts.testBitmaps )
+ return;
+
+ if ( opts.mapMode != 0 )
+ dc.SetMapMode((wxMappingMode)opts.mapMode);
+ if ( opts.penWidth != 0 )
+ dc.SetPen(wxPen(*wxWHITE, opts.penWidth));
+
+ wxPrintf("Benchmarking %s: ", msg);
+ fflush(stdout);
+
+ wxStopWatch sw;
+ for ( int n = 0; n < opts.numIters; n++ )
+ {
+ int x = rand() % opts.width,
+ y = rand() % opts.height;
+
+ dc.DrawBitmap(m_bitmap, x, y, true);
+ }
+
+ const long t = sw.Time();
+
+ wxPrintf("%ld bitmaps done in %ldms = %gus/bitmap\n",
+ opts.numIters, t, (1000. * t)/opts.numIters);
+ }
+
+ void BenchmarkImages(const wxString& msg, wxDC& dc)
+ {
+ if ( !opts.testImages )
+ return;
+
+ if ( opts.mapMode != 0 )
+ dc.SetMapMode((wxMappingMode)opts.mapMode);
+
+ wxPrintf("Benchmarking %s: ", msg);
+ fflush(stdout);
+
+ wxImage image(wxSize(opts.width, opts.height), false /* don't clear */);
+
+ wxStopWatch sw;
+ for ( int n = 0; n < opts.numIters; n++ )
+ {
+ UpdateRGB(image.GetData(), n);
+ dc.DrawBitmap(image, 0, 0);
+ }
+
+ const long t = sw.Time();
+
+ wxPrintf("%ld images done in %ldms = %gus/image or %ld FPS\n",
+ opts.numIters, t, (1000. * t)/opts.numIters,
+ (1000*opts.numIters + t - 1)/t);
+ }
+
+ void BenchmarkRawBitmaps(const wxString& msg, wxDC& dc)
+ {
+ if ( !opts.testRawBitmaps )
+ return;
+
+ if ( opts.mapMode != 0 )
+ dc.SetMapMode((wxMappingMode)opts.mapMode);
+
+ wxPrintf("Benchmarking %s: ", msg);
+ fflush(stdout);
+
+ wxBitmap bitmap(opts.width, opts.height, 24);
+ wxNativePixelData data(bitmap);
+
+ wxStopWatch sw;
+ for ( int n = 0; n < opts.numIters; n++ )
+ {
+ unsigned char c = n % 256;
+ {
+ wxNativePixelData::Iterator p(data);
+ for ( int y = 0; y < opts.height; ++y )
+ {
+ wxNativePixelData::Iterator rowStart = p;
+
+ for ( int x = 0; x < opts.width; ++x )
+ {
+ p.Red() =
+ p.Green() =
+ p.Blue() = c;
+ ++p;
+ }
+
+ p = rowStart;
+ p.OffsetY(data, 1);
+ c++;
+ }
+ }
+
+ dc.DrawBitmap(bitmap, 0, 0);
+ }
+
+ const long t = sw.Time();
+
+ wxPrintf("%ld raw bitmaps done in %ldms = %gus/bitmap or %ld FPS\n",
+ opts.numIters, t, (1000. * t)/opts.numIters,
+ (1000*opts.numIters + t - 1)/t);
+ }
+
+
+ wxBitmap m_bitmap;
+#if wxUSE_GLCANVAS
+ wxGLCanvas* m_glCanvas;
+ wxGLContext* m_glContext;
+#endif // wxUSE_GLCANVAS