0030939: Draw Harness, ViewerTest - AIS_ViewCube animation does not work on Linux...
[occt.git] / src / ViewerTest / ViewerTest_ContinuousRedrawer.hxx
CommitLineData
08b7a39f 1// Copyright (c) 2019-2020 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#ifndef _ViewerTest_ContinuousRedrawer_HeaderFile
15#define _ViewerTest_ContinuousRedrawer_HeaderFile
16
17#include <OSD_Thread.hxx>
18#include <Standard_Condition.hxx>
19#include <Standard_Mutex.hxx>
20#include <Standard_Type.hxx>
21
22class Aspect_Window;
23
24//! Auxiliary tool performing continuous redraws of specified window.
25//! Tool creates an extra working thread pushing content invalidation messages to specific window using Aspect_Window::InvalidateContent() method.
26//! Normally, GUI application should done continuous rendering in simple fashion - just by drawing next frame without waiting for new events from windowing system;
27//! however, implementation of this approach is problematic in context of ViewerTest due to message loop binding mechanism implied by Tcl/Tk.
28class ViewerTest_ContinuousRedrawer
29{
30public:
31 //! Return global instance.
32 Standard_EXPORT static ViewerTest_ContinuousRedrawer& Instance();
33public:
34
35 //! Destructor.
36 Standard_EXPORT ~ViewerTest_ContinuousRedrawer();
37
38 //! Return TRUE if redrawer thread is started.
39 bool IsStarted() const { return myThread.GetId() != 0; }
40
41 //! Start thread.
42 Standard_EXPORT void Start (const Handle(Aspect_Window)& theWindow,
43 Standard_Real theTargetFps);
44
45 //! Stop thread.
46 Standard_EXPORT void Stop (const Handle(Aspect_Window)& theWindow = NULL);
47
48 //! Return TRUE if redrawer thread is in paused state.
49 bool IsPaused() const { return myToPause; }
50
51 //! Pause working thread, but does not terminate it.
52 Standard_EXPORT void Pause();
53
54private:
55
56 //! Thread loop.
57 void doThreadLoop();
58
59 //! Thread creation callback.
60 static Standard_Address doThreadWrapper (Standard_Address theData)
61 {
62 ViewerTest_ContinuousRedrawer* aThis = (ViewerTest_ContinuousRedrawer* )theData;
63 aThis->doThreadLoop();
64 return 0;
65 }
66
67 //! Empty constructor.
68 ViewerTest_ContinuousRedrawer();
69
70private:
71 Handle(Aspect_Window) myWindow; //!< window to invalidate
72 OSD_Thread myThread; //!< working thread
73 Standard_Mutex myMutex; //!< mutex for accessing common variables
74 Standard_Condition myWakeEvent; //!< event to wake up working thread
75 Standard_Real myTargetFps; //!< desired update framerate
76 volatile bool myToStop; //!< flag to stop working thread
77 volatile bool myToPause; //!< flag to put working thread asleep without stopping
78};
79
80#endif // _ViewerTest_ContinuousRedrawer_HeaderFile