Bugfix : Zooming works correct, no more errors on screen.
[xara-cairo.git] / wxOil / speedtst.cpp
blobe150679ad3fa36006a64f2e7e10387b5da56b99f
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
30 ADDITIONAL RIGHTS
31 -----------------
33 Conditional upon your continuing compliance with the GNU General Public
34 License described above, Xara Group Ltd grants to you certain additional
35 rights.
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.
50 SCOPE OF LICENSE
51 ----------------
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
56 terms.
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).
85 MARKS
86 -----
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.
94 http://www.xara.com/
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]
110 //#include "andy.h"
111 //#include "will.h"
112 //#include "richard2.h"
113 //#include "phil.h"
114 //#include "resource.h"
115 #include "camprofile.h"
118 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
119 #include <time.h>
120 #include "mainfrm.h"
121 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
122 //#include "rgnlist.h" - in camtypes.h [AUTOMATICALLY REMOVED]
124 #include "xadraw.h"
125 #include "zoomops.h"
126 #include "wrkrect.h"
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
142 // Markn - 14-5-99
144 //INT32 SpeedTest_Count = 0;
146 /********************************************************************************************
148 > BOOL OpTimeDraw::Init()
150 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
151 Created: 18/1/94
152 Inputs: None
153 Outputs: None
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.
157 Scope: Static
159 ********************************************************************************************/
162 BOOL OpTimeDraw::Init()
164 BOOL bOK = TRUE;
165 if (bOK) bOK = RegisterOpDescriptor(
167 _R(IDS_TIMEDRAW),
168 CC_RUNTIME_CLASS(OpTimeDraw),
169 OPTOKEN_TIMEDRAW,
170 GetState,
171 _R(IDS_TIMEDRAW),
172 _R(IDBBL_TIMEDRAW)
175 if (bOK) bOK = RegisterOpDescriptor(
177 _R(IDS_CLEARCACHE),
178 CC_RUNTIME_CLASS(OpClearCache),
179 OPTOKEN_CLEARCACHE,
180 GetState,
181 _R(IDS_CLEARCACHE),
182 _R(IDBBL_CLEARCACHE)
185 if (bOK) bOK = RegisterOpDescriptor(
187 _R(IDS_THROTTLECACHE),
188 CC_RUNTIME_CLASS(OpThrottleCache),
189 OPTOKEN_THROTTLECACHE,
190 GetState,
191 _R(IDS_THROTTLECACHE),
192 _R(IDBBL_THROTTLECACHE)
195 return bOK;
198 /********************************************************************************************
200 > void OpTimeDraw::Do(OpDescriptor*)
202 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
203 Created: 18/1/94
204 Inputs: None
205 Outputs: None
206 Returns: None
207 Purpose: Forces a redraw of the current document and displays the time taken to do
208 Errors: None
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));
219 else
220 return((INT32)g_XaCalls[*p2] - (INT32)g_XaCalls[*p1]);
222 #endif
224 void OpTimeDraw::Do(OpDescriptor*)
226 // SpeedTest_Count++;
228 DocView *pDocView = DocView::GetSelected();
229 if (pDocView == NULL)
230 return;
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();
242 if (pWnd)
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
258 // floats
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) );
263 #if 1
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;
274 String_256 Buf2;
276 Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("TOTAL"), PFORM(total));
277 Buf += _T(", ");
278 Buf += Buf2;
279 Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("GDRAW"), PFORM(Results[CAMPROFILE_GDRAW]));
280 Buf += _T(", ");
281 Buf += Buf2;
282 Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("SHADOW"), PFORM(Results[CAMPROFILE_SHADOW]));
283 Buf += _T(", ");
284 Buf += Buf2;
285 Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("BEVEL"), PFORM(Results[CAMPROFILE_BEVEL]));
286 Buf += _T(", ");
287 Buf += Buf2;
288 Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("BLIT"), PFORM(Results[CAMPROFILE_BLIT]));
289 Buf += _T(", ");
290 Buf += Buf2;
291 Buf2.MakeMsg(_R(IDS_SPEEDTST_REDRAW_TOOK2), _T("OTHER"), PFORM(Results[CAMPROFILE_OTHER]));
292 Buf += _T(", ");
293 Buf += Buf2;
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));
300 Buf += _T(", ");
301 Buf += Buf2;
304 #endif
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>
318 Created: 18/1/94
319 Inputs:
320 Outputs:
321 Returns:
322 Purpose: Constructor for OpTimeDraw operation. It is not undoable.
323 Errors: None
325 ********************************************************************************************/
327 OpTimeDraw::OpTimeDraw()
332 /********************************************************************************************
334 > OpState OpTimeDraw::GetState(String_256*, OpDescriptor*)
336 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
337 Created: 18/1/94
338 Inputs:
339 Outputs:
340 Returns:
341 Purpose: This item is always available, so long as a document is visible.
342 Errors: None
344 ********************************************************************************************/
346 OpState OpTimeDraw::GetState(String_256*, OpDescriptor*)
348 OpState OpSt;
350 return OpSt;
353 /********************************************************************************************
355 > void OpClearCache::Do(OpDescriptor*)
357 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
358 Created: 23/06/2004
359 Inputs: None
360 Outputs: None
361 Returns: None
362 Purpose: Toggles bitmap cache enabled pref also Clears the bitmap cache for performance testing
363 Errors: None
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();
377 if (pBitmapCache)
379 pBitmapCache->DeInitialise();
382 End(); // cleanup memory
385 /********************************************************************************************
387 > OpClearCache::OpClearCache()
389 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
390 Created: 18/1/94
391 Inputs:
392 Outputs:
393 Returns:
394 Purpose: Constructor for OpTimeDraw operation. It is not undoable.
395 Errors: None
397 ********************************************************************************************/
399 OpClearCache::OpClearCache()
404 /********************************************************************************************
406 > OpState OpClearCache::GetState(String_256*, OpDescriptor*)
408 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
409 Created: 18/1/94
410 Inputs:
411 Outputs:
412 Returns:
413 Purpose: This item is always available, so long as a document is visible.
414 Errors: None
416 ********************************************************************************************/
418 OpState OpClearCache::GetState(String_256*, OpDescriptor*)
420 OpState OpSt;
422 OpSt.Ticked = NodeRenderableBounded::bEnableCacheing;
424 return OpSt;
430 /********************************************************************************************
432 > void OpThrottleCache::Do(OpDescriptor*)
434 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
435 Created: 23/06/2004
436 Inputs: None
437 Outputs: None
438 Returns: None
439 Purpose: Toggles bitmap cache enabled pref also Clears the bitmap cache for performance testing
440 Errors: None
442 ********************************************************************************************/
444 void OpThrottleCache::Do(OpDescriptor*)
446 if (NodeRenderableBounded::bThrottleCacheing)
448 InformWarning(_R(IDS_WARN_DISABLE_THROTTLING), _R(IDS_OK));
450 else
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>
465 Created: 18/1/94
466 Inputs:
467 Outputs:
468 Returns:
469 Purpose: Constructor for OpTimeDraw operation. It is not undoable.
470 Errors: None
472 ********************************************************************************************/
474 OpThrottleCache::OpThrottleCache()
479 /********************************************************************************************
481 > OpState OpThrottleCache::GetState(String_256*, OpDescriptor*)
483 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
484 Created: 18/1/94
485 Inputs:
486 Outputs:
487 Returns:
488 Purpose: This item is always available, so long as a document is visible.
489 Errors: None
491 ********************************************************************************************/
493 OpState OpThrottleCache::GetState(String_256*, OpDescriptor*)
495 OpState OpSt;
497 OpSt.Ticked = NodeRenderableBounded::bThrottleCacheing;
499 return OpSt;