1 // $Id: speedtst.cpp 1282 2006-06-09 09:46:49Z alex $
2 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
3 ================================XARAHEADERSTART===========================
5 Xara LX, a vector drawing and manipulation program.
6 Copyright (C) 1993-2006 Xara Group Ltd.
7 Copyright on certain contributions may be held in joint with their
8 respective authors. See AUTHORS file for details.
10 LICENSE TO USE AND MODIFY SOFTWARE
11 ----------------------------------
13 This file is part of Xara LX.
15 Xara LX is free software; you can redistribute it and/or modify it
16 under the terms of the GNU General Public License version 2 as published
17 by the Free Software Foundation.
19 Xara LX and its component source files are distributed in the hope
20 that it will be useful, but WITHOUT ANY WARRANTY; without even the
21 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 See the GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License along
25 with Xara LX (see the file GPL in the root directory of the
26 distribution); if not, write to the Free Software Foundation, Inc., 51
27 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 Conditional upon your continuing compliance with the GNU General Public
34 License described above, Xara Group Ltd grants to you certain additional
37 The additional rights are to use, modify, and distribute the software
38 together with the wxWidgets library, the wxXtra library, and the "CDraw"
39 library and any other such library that any version of Xara LX relased
40 by Xara Group Ltd requires in order to compile and execute, including
41 the static linking of that library to XaraLX. In the case of the
42 "CDraw" library, you may satisfy obligation under the GNU General Public
43 License to provide source code by providing a binary copy of the library
44 concerned and a copy of the license accompanying it.
46 Nothing in this section restricts any of the rights you have under
47 the GNU General Public License.
53 This license applies to this program (XaraLX) and its constituent source
54 files only, and does not necessarily apply to other Xara products which may
55 in part share the same code base, and are subject to their own licensing
58 This license does not apply to files in the wxXtra directory, which
59 are built into a separate library, and are subject to the wxWindows
60 license contained within that directory in the file "WXXTRA-LICENSE".
62 This license does not apply to the binary libraries (if any) within
63 the "libs" directory, which are subject to a separate license contained
64 within that directory in the file "LIBS-LICENSE".
67 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
68 ----------------------------------------------
70 Subject to the terms of the GNU Public License (see above), you are
71 free to do whatever you like with your modifications. However, you may
72 (at your option) wish contribute them to Xara's source tree. You can
73 find details of how to do this at:
74 http://www.xaraxtreme.org/developers/
76 Prior to contributing your modifications, you will need to complete our
77 contributor agreement. This can be found at:
78 http://www.xaraxtreme.org/developers/contribute/
80 Please note that Xara will not accept modifications which modify any of
81 the text between the start and end of this header (marked
82 XARAHEADERSTART and XARAHEADEREND).
88 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
89 designs are registered or unregistered trademarks, design-marks, and/or
90 service marks of Xara Group Ltd. All rights in these marks are reserved.
93 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
96 =================================XARAHEADEREND============================
99 // operation(s) to test Camelot speed
104 #include "camtypes.h"
105 //#include "camconfig.h"
106 #include "speedtst.h"
107 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
108 //#include "convert.h" - in camtypes.h [AUTOMATICALLY REMOVED]
112 //#include "richard2.h"
114 //#include "resource.h"
115 #include "camprofile.h"
118 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
121 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
122 //#include "rgnlist.h" - in camtypes.h [AUTOMATICALLY REMOVED]
127 //#include "bitmapcache.h" - in camtypes.h [AUTOMATICALLY REMOVED]
130 CC_IMPLEMENT_DYNCREATE(OpTimeDraw
, Operation
)
131 CC_IMPLEMENT_DYNCREATE(OpClearCache
, Operation
)
132 CC_IMPLEMENT_DYNCREATE(OpThrottleCache
, Operation
)
134 #define new CAM_DEBUG_NEW
137 // This global var is incremented every time the speed test op is executed.
138 // It was put in so I could test the speed increase of the path point caching inside
139 // the NodeBlendPath object. When SpeedTest_Count was even I checked the cache,
140 // when odd I ignored it
141 // I've left it in as I'm sure others will find it useful
144 //INT32 SpeedTest_Count = 0;
146 /********************************************************************************************
148 > BOOL OpTimeDraw::Init()
150 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
154 Returns: TRUE if worked, FALSE if failed (out of memory)
155 Purpose: Declares op descriptors for time testing
156 Errors: Returns FALSE on failure.
159 ********************************************************************************************/
162 BOOL
OpTimeDraw::Init()
165 if (bOK
) bOK
= RegisterOpDescriptor(
168 CC_RUNTIME_CLASS(OpTimeDraw
),
175 if (bOK
) bOK
= RegisterOpDescriptor(
178 CC_RUNTIME_CLASS(OpClearCache
),
185 if (bOK
) bOK
= RegisterOpDescriptor(
187 _R(IDS_THROTTLECACHE
),
188 CC_RUNTIME_CLASS(OpThrottleCache
),
189 OPTOKEN_THROTTLECACHE
,
191 _R(IDS_THROTTLECACHE
),
192 _R(IDBBL_THROTTLECACHE
)
198 /********************************************************************************************
200 > void OpTimeDraw::Do(OpDescriptor*)
202 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
207 Purpose: Forces a redraw of the current document and displays the time taken to do
210 ********************************************************************************************/
212 #ifdef CONFIG_DEBUG_XADRAW
213 INT32 _cdecl
XaTimingSortFunc(const void *arg1
, const void *arg2
)
215 DWORD
*p1
= (DWORD
*)arg1
;
216 DWORD
*p2
= (DWORD
*)arg2
;
217 if (g_XaTimes
[*p2
].QuadPart
- g_XaTimes
[*p1
].QuadPart
)
218 return((INT32
)(g_XaTimes
[*p2
].QuadPart
- g_XaTimes
[*p1
].QuadPart
));
220 return((INT32
)g_XaCalls
[*p2
] - (INT32
)g_XaCalls
[*p1
]);
224 void OpTimeDraw::Do(OpDescriptor
*)
226 // SpeedTest_Count++;
228 DocView
*pDocView
= DocView::GetSelected();
229 if (pDocView
== NULL
)
232 wxYield(); // let through some wxPaint events
234 CamProfiler Profiler
;
235 // clock() measures system time so excludes (e.g.) X-Windows blit time
236 // so this is rather a peculiar test
237 clock_t Timer
= clock(); // start clock
239 pDocView
->ForceRedraw(); // posts the paint message
241 wxWindow
* pWnd
= DocView::GetCurrentRenderWindow();
243 pWnd
->Update(); // do the paint
245 // now we wait until all rendering has finished
246 while ( Camelot
.ServiceRendering() )
250 Timer
= clock() - Timer
; // stop clock
252 double Results
[CAMPROFILE_NONE
];
253 double total
= Profiler
.Read(Results
);
255 // as this is for our use only, it is permitted to hard-code English strings
257 // this lovely line translates the clock_t value into a useful value without using
259 String_256 Buf
; // "Redraw took %d.%03d secs"
261 Buf
.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK
), (INT32
)(Timer
/ CLOCKS_PER_SEC
),
262 (INT32
)((Timer
% CLOCKS_PER_SEC
) * 1000 / CLOCKS_PER_SEC
) );
265 // All this because MakeMsg doesn't do floating point
266 #define PFORM(x) ((INT32)((x<0)?ceil(x):floor(x))) , ((INT32)(floor(0.5+( ( (x<0)?(ceil(x)-x):(x - floor(x)) ) * 1000 ))))
268 double error
=Results
[CAMPROFILE_OTHER
]+
269 Results
[CAMPROFILE_GDRAW
]+
270 Results
[CAMPROFILE_SHADOW
]+
271 Results
[CAMPROFILE_BEVEL
]+
272 Results
[CAMPROFILE_BLIT
]-total
;
276 Buf2
.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2
), _T("TOTAL"), PFORM(total
));
279 Buf2
.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2
), _T("GDRAW"), PFORM(Results
[CAMPROFILE_GDRAW
]));
282 Buf2
.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2
), _T("SHADOW"), PFORM(Results
[CAMPROFILE_SHADOW
]));
285 Buf2
.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2
), _T("BEVEL"), PFORM(Results
[CAMPROFILE_BEVEL
]));
288 Buf2
.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2
), _T("BLIT"), PFORM(Results
[CAMPROFILE_BLIT
]));
291 Buf2
.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2
), _T("OTHER"), PFORM(Results
[CAMPROFILE_OTHER
]));
295 // Only report error if it is significant. With current code, it shouldn't actually exist at all bar
296 // floating point to INT32 rounding error.
297 if (fabs(error
) > 0.5/1000.0)
299 Buf2
.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2
), _T("ERROR"), PFORM(error
));
305 Convert::ReplaceDecimalPoint(&Buf
); // Just to keep Neville happy... :-
308 // URGH! This should use the proper Camelot dialog box system but we don't have it available right now
309 ::wxMessageBox( (TCHAR
*)Buf
);
311 End(); // cleanup memory
313 /********************************************************************************************
315 > OpTimeDraw::OpTimeDraw()
317 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
322 Purpose: Constructor for OpTimeDraw operation. It is not undoable.
325 ********************************************************************************************/
327 OpTimeDraw::OpTimeDraw()
332 /********************************************************************************************
334 > OpState OpTimeDraw::GetState(String_256*, OpDescriptor*)
336 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
341 Purpose: This item is always available, so long as a document is visible.
344 ********************************************************************************************/
346 OpState
OpTimeDraw::GetState(String_256
*, OpDescriptor
*)
353 /********************************************************************************************
355 > void OpClearCache::Do(OpDescriptor*)
357 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
362 Purpose: Toggles bitmap cache enabled pref also Clears the bitmap cache for performance testing
365 ********************************************************************************************/
367 void OpClearCache::Do(OpDescriptor
*)
369 if (NodeRenderableBounded::bEnableCacheing
)
371 InformWarning(_R(IDS_WARN_DISABLECACHEING
), _R(IDS_OK
));
374 NodeRenderableBounded::bEnableCacheing
= ! NodeRenderableBounded::bEnableCacheing
;
376 CBitmapCache
* pBitmapCache
= Camelot
.GetBitmapCache();
379 pBitmapCache
->DeInitialise();
382 End(); // cleanup memory
385 /********************************************************************************************
387 > OpClearCache::OpClearCache()
389 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
394 Purpose: Constructor for OpTimeDraw operation. It is not undoable.
397 ********************************************************************************************/
399 OpClearCache::OpClearCache()
404 /********************************************************************************************
406 > OpState OpClearCache::GetState(String_256*, OpDescriptor*)
408 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
413 Purpose: This item is always available, so long as a document is visible.
416 ********************************************************************************************/
418 OpState
OpClearCache::GetState(String_256
*, OpDescriptor
*)
422 OpSt
.Ticked
= NodeRenderableBounded::bEnableCacheing
;
430 /********************************************************************************************
432 > void OpThrottleCache::Do(OpDescriptor*)
434 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
439 Purpose: Toggles bitmap cache enabled pref also Clears the bitmap cache for performance testing
442 ********************************************************************************************/
444 void OpThrottleCache::Do(OpDescriptor
*)
446 if (NodeRenderableBounded::bThrottleCacheing
)
448 InformWarning(_R(IDS_WARN_DISABLE_THROTTLING
), _R(IDS_OK
));
452 InformWarning(_R(IDS_WARN_ENABLE_THROTTLING
), _R(IDS_OK
));
455 NodeRenderableBounded::bThrottleCacheing
= ! NodeRenderableBounded::bThrottleCacheing
;
457 End(); // cleanup memory
460 /********************************************************************************************
462 > OpThrottleCache::OpThrottleCache()
464 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
469 Purpose: Constructor for OpTimeDraw operation. It is not undoable.
472 ********************************************************************************************/
474 OpThrottleCache::OpThrottleCache()
479 /********************************************************************************************
481 > OpState OpThrottleCache::GetState(String_256*, OpDescriptor*)
483 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
488 Purpose: This item is always available, so long as a document is visible.
491 ********************************************************************************************/
493 OpState
OpThrottleCache::GetState(String_256
*, OpDescriptor
*)
497 OpSt
.Ticked
= NodeRenderableBounded::bThrottleCacheing
;