speedtst.cpp

Go to the documentation of this file.
00001 // $Id: speedtst.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // operation(s) to test Camelot speed
00100 
00101 /*
00102 */
00103 
00104 #include "camtypes.h"
00105 //#include "camconfig.h"
00106 #include "speedtst.h"
00107 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "convert.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 
00110 //#include "andy.h"
00111 //#include "will.h"
00112 //#include "richard2.h"
00113 //#include "phil.h"
00114 //#include "resource.h"
00115 #include "camprofile.h"
00116 
00117 /*
00118 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00119 #include <time.h>
00120 #include "mainfrm.h"
00121 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00122 //#include "rgnlist.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00123 
00124 #include "xadraw.h"
00125 #include "zoomops.h"
00126 #include "wrkrect.h"
00127 //#include "bitmapcache.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00128 */
00129 
00130 CC_IMPLEMENT_DYNCREATE(OpTimeDraw, Operation)
00131 CC_IMPLEMENT_DYNCREATE(OpClearCache, Operation)
00132 CC_IMPLEMENT_DYNCREATE(OpThrottleCache, Operation)
00133 
00134 #define new CAM_DEBUG_NEW
00135 
00136 
00137 // This global var is incremented every time the speed test op is executed.
00138 // It was put in so I could test the speed increase of the path point caching inside 
00139 // the NodeBlendPath object. When SpeedTest_Count was even I checked the cache, 
00140 // when odd I ignored it
00141 // I've left it in as I'm sure others will find it useful
00142 // Markn - 14-5-99
00143 
00144 //INT32 SpeedTest_Count = 0;
00145 
00146 /********************************************************************************************
00147 
00148 >   BOOL OpTimeDraw::Init()
00149 
00150     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00151     Created:    18/1/94
00152     Inputs:     None
00153     Outputs:    None
00154     Returns:    TRUE if worked, FALSE if failed (out of memory)
00155     Purpose:    Declares op descriptors for time testing
00156     Errors:     Returns FALSE on failure.
00157     Scope:      Static
00158 
00159 ********************************************************************************************/
00160 
00161 
00162 BOOL OpTimeDraw::Init()
00163 {
00164     BOOL bOK = TRUE;
00165     if (bOK) bOK = RegisterOpDescriptor(
00166                                         0,
00167                                         _R(IDS_TIMEDRAW),
00168                                         CC_RUNTIME_CLASS(OpTimeDraw),
00169                                         OPTOKEN_TIMEDRAW,
00170                                         GetState,
00171                                         _R(IDS_TIMEDRAW),
00172                                         _R(IDBBL_TIMEDRAW)
00173                                       );
00174 
00175     if (bOK) bOK = RegisterOpDescriptor(
00176                                         0,
00177                                         _R(IDS_CLEARCACHE),
00178                                         CC_RUNTIME_CLASS(OpClearCache),
00179                                         OPTOKEN_CLEARCACHE,
00180                                         GetState,
00181                                         _R(IDS_CLEARCACHE),
00182                                         _R(IDBBL_CLEARCACHE)
00183                                       );
00184 
00185     if (bOK) bOK = RegisterOpDescriptor(
00186                                         0,
00187                                         _R(IDS_THROTTLECACHE),
00188                                         CC_RUNTIME_CLASS(OpThrottleCache),
00189                                         OPTOKEN_THROTTLECACHE,
00190                                         GetState,
00191                                         _R(IDS_THROTTLECACHE),
00192                                         _R(IDBBL_THROTTLECACHE)
00193                                       );
00194 
00195     return bOK;
00196 }
00197 
00198 /********************************************************************************************
00199 
00200 >   void OpTimeDraw::Do(OpDescriptor*)
00201 
00202     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00203     Created:    18/1/94
00204     Inputs:     None
00205     Outputs:    None
00206     Returns:    None
00207     Purpose:    Forces a redraw of the current document and displays the time taken to do
00208     Errors:     None
00209 
00210 ********************************************************************************************/
00211 
00212 #ifdef CONFIG_DEBUG_XADRAW
00213 INT32 _cdecl XaTimingSortFunc(const void *arg1, const void *arg2)
00214 {
00215     DWORD *p1 = (DWORD*)arg1;
00216     DWORD *p2 = (DWORD*)arg2;
00217     if (g_XaTimes[*p2].QuadPart - g_XaTimes[*p1].QuadPart)
00218         return((INT32)(g_XaTimes[*p2].QuadPart - g_XaTimes[*p1].QuadPart));
00219     else
00220         return((INT32)g_XaCalls[*p2] - (INT32)g_XaCalls[*p1]);
00221 }
00222 #endif
00223 
00224 void OpTimeDraw::Do(OpDescriptor*)
00225 {
00226 //  SpeedTest_Count++;
00227 
00228     DocView *pDocView = DocView::GetSelected();
00229     if (pDocView == NULL)
00230         return;
00231 
00232     wxYield(); // let through some wxPaint events
00233 
00234     CamProfiler Profiler;
00235     // clock() measures system time so excludes (e.g.) X-Windows blit time
00236     // so this is rather a peculiar test
00237     clock_t Timer = clock();                                            // start clock
00238 
00239     pDocView->ForceRedraw();                                            // posts the paint message
00240 
00241     wxWindow* pWnd = DocView::GetCurrentRenderWindow();
00242     if (pWnd)
00243         pWnd->Update();                                         // do the paint
00244 
00245     // now we wait until all rendering has finished
00246     while ( Camelot.ServiceRendering() )
00247     {
00248     }
00249 
00250     Timer = clock() - Timer;                                            // stop clock
00251 
00252     double Results[CAMPROFILE_NONE];
00253     double total = Profiler.Read(Results);
00254 
00255     // as this is for our use only, it is permitted to hard-code English strings
00256 
00257     // this lovely line translates the clock_t value into a useful value without using
00258     // floats
00259     String_256 Buf; // "Redraw took %d.%03d secs"
00260 
00261     Buf.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK), (INT32)(Timer / CLOCKS_PER_SEC),
00262                                 (INT32)((Timer % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC) );
00263 #if 1
00264 
00265     // All this because MakeMsg doesn't do floating point
00266 #define PFORM(x) ((INT32)((x<0)?ceil(x):floor(x))) , ((INT32)(floor(0.5+( ( (x<0)?(ceil(x)-x):(x - floor(x)) ) * 1000 ))))
00267 
00268     double error=Results[CAMPROFILE_OTHER ]+
00269                  Results[CAMPROFILE_GDRAW ]+
00270                  Results[CAMPROFILE_SHADOW]+
00271                  Results[CAMPROFILE_BEVEL ]+
00272                  Results[CAMPROFILE_BLIT  ]-total;
00273 
00274     String_256 Buf2;
00275     
00276     Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("TOTAL"), PFORM(total));
00277     Buf += _T(", ");
00278     Buf += Buf2;
00279     Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("GDRAW"), PFORM(Results[CAMPROFILE_GDRAW]));
00280     Buf += _T(", ");
00281     Buf += Buf2;
00282     Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("SHADOW"), PFORM(Results[CAMPROFILE_SHADOW]));
00283     Buf += _T(", ");
00284     Buf += Buf2;
00285     Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("BEVEL"), PFORM(Results[CAMPROFILE_BEVEL]));
00286     Buf += _T(", ");
00287     Buf += Buf2;
00288     Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("BLIT"), PFORM(Results[CAMPROFILE_BLIT]));
00289     Buf += _T(", ");
00290     Buf += Buf2;
00291     Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("OTHER"), PFORM(Results[CAMPROFILE_OTHER]));
00292     Buf += _T(", ");
00293     Buf += Buf2;
00294     
00295     // Only report error if it is significant. With current code, it shouldn't actually exist at all bar
00296     // floating point to INT32 rounding error.
00297     if (fabs(error) > 0.5/1000.0)
00298     {
00299         Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("ERROR"), PFORM(error));
00300         Buf += _T(", ");
00301         Buf += Buf2;
00302     }
00303 
00304 #endif
00305     Convert::ReplaceDecimalPoint(&Buf);                                 // Just to keep Neville happy... :-
00306 
00307 
00308     // URGH! This should use the proper Camelot dialog box system but we don't have it available right now
00309     ::wxMessageBox( (TCHAR *)Buf );
00310 
00311     End();                                                              // cleanup memory   
00312 }
00313 /********************************************************************************************
00314 
00315 >   OpTimeDraw::OpTimeDraw()
00316 
00317     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00318     Created:    18/1/94
00319     Inputs:
00320     Outputs:
00321     Returns:
00322     Purpose:    Constructor for OpTimeDraw operation. It is not undoable.
00323     Errors:     None
00324 
00325 ********************************************************************************************/
00326 
00327 OpTimeDraw::OpTimeDraw()
00328 {
00329 }
00330 
00331 
00332 /********************************************************************************************
00333 
00334 >   OpState OpTimeDraw::GetState(String_256*, OpDescriptor*)
00335 
00336     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00337     Created:    18/1/94
00338     Inputs:
00339     Outputs:
00340     Returns:
00341     Purpose:    This item is always available, so long as a document is visible.
00342     Errors:     None
00343 
00344 ********************************************************************************************/
00345 
00346 OpState OpTimeDraw::GetState(String_256*, OpDescriptor*)
00347 {
00348     OpState OpSt;
00349 
00350     return OpSt;
00351 }
00352 
00353 /********************************************************************************************
00354 
00355 >   void OpClearCache::Do(OpDescriptor*)
00356 
00357     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00358     Created:    23/06/2004
00359     Inputs:     None
00360     Outputs:    None
00361     Returns:    None
00362     Purpose:    Toggles bitmap cache enabled pref also Clears the bitmap cache for performance testing
00363     Errors:     None
00364 
00365 ********************************************************************************************/
00366 
00367 void OpClearCache::Do(OpDescriptor*)
00368 {
00369     if (NodeRenderableBounded::bEnableCacheing)
00370     {
00371         InformWarning(_R(IDS_WARN_DISABLECACHEING), _R(IDS_OK));
00372     }
00373 
00374     NodeRenderableBounded::bEnableCacheing = ! NodeRenderableBounded::bEnableCacheing;
00375 
00376     CBitmapCache* pBitmapCache = Camelot.GetBitmapCache();
00377     if (pBitmapCache)
00378     {
00379         pBitmapCache->DeInitialise();
00380     }
00381 
00382     End();                                                              // cleanup memory   
00383 }
00384 
00385 /********************************************************************************************
00386 
00387 >   OpClearCache::OpClearCache()
00388 
00389     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00390     Created:    18/1/94
00391     Inputs:
00392     Outputs:
00393     Returns:
00394     Purpose:    Constructor for OpTimeDraw operation. It is not undoable.
00395     Errors:     None
00396 
00397 ********************************************************************************************/
00398 
00399 OpClearCache::OpClearCache()
00400 {
00401 }
00402 
00403 
00404 /********************************************************************************************
00405 
00406 >   OpState OpClearCache::GetState(String_256*, OpDescriptor*)
00407 
00408     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00409     Created:    18/1/94
00410     Inputs:
00411     Outputs:
00412     Returns:
00413     Purpose:    This item is always available, so long as a document is visible.
00414     Errors:     None
00415 
00416 ********************************************************************************************/
00417 
00418 OpState OpClearCache::GetState(String_256*, OpDescriptor*)
00419 {
00420     OpState OpSt;
00421 
00422     OpSt.Ticked = NodeRenderableBounded::bEnableCacheing;
00423 
00424     return OpSt;
00425 }
00426 
00427 
00428 
00429 
00430 /********************************************************************************************
00431 
00432 >   void OpThrottleCache::Do(OpDescriptor*)
00433 
00434     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00435     Created:    23/06/2004
00436     Inputs:     None
00437     Outputs:    None
00438     Returns:    None
00439     Purpose:    Toggles bitmap cache enabled pref also Clears the bitmap cache for performance testing
00440     Errors:     None
00441 
00442 ********************************************************************************************/
00443 
00444 void OpThrottleCache::Do(OpDescriptor*)
00445 {
00446     if (NodeRenderableBounded::bThrottleCacheing)
00447     {
00448         InformWarning(_R(IDS_WARN_DISABLE_THROTTLING), _R(IDS_OK));
00449     }
00450     else
00451     {
00452         InformWarning(_R(IDS_WARN_ENABLE_THROTTLING), _R(IDS_OK));
00453     }
00454 
00455     NodeRenderableBounded::bThrottleCacheing = ! NodeRenderableBounded::bThrottleCacheing;
00456 
00457     End();                                                              // cleanup memory   
00458 }
00459 
00460 /********************************************************************************************
00461 
00462 >   OpThrottleCache::OpThrottleCache()
00463 
00464     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00465     Created:    18/1/94
00466     Inputs:
00467     Outputs:
00468     Returns:
00469     Purpose:    Constructor for OpTimeDraw operation. It is not undoable.
00470     Errors:     None
00471 
00472 ********************************************************************************************/
00473 
00474 OpThrottleCache::OpThrottleCache()
00475 {
00476 }
00477 
00478 
00479 /********************************************************************************************
00480 
00481 >   OpState OpThrottleCache::GetState(String_256*, OpDescriptor*)
00482 
00483     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00484     Created:    18/1/94
00485     Inputs:
00486     Outputs:
00487     Returns:
00488     Purpose:    This item is always available, so long as a document is visible.
00489     Errors:     None
00490 
00491 ********************************************************************************************/
00492 
00493 OpState OpThrottleCache::GetState(String_256*, OpDescriptor*)
00494 {
00495     OpState OpSt;
00496 
00497     OpSt.Ticked = NodeRenderableBounded::bThrottleCacheing;
00498 
00499     return OpSt;
00500 }
00501 
00502 
00503 
00504 

Generated on Sat Nov 10 03:48:56 2007 for Camelot by  doxygen 1.4.4