Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:31

0001 // Copyright (c) 2019-2020 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _ViewerTest_ContinuousRedrawer_HeaderFile
0015 #define _ViewerTest_ContinuousRedrawer_HeaderFile
0016 
0017 #include <OSD_Thread.hxx>
0018 #include <Standard_Condition.hxx>
0019 #include <Standard_Mutex.hxx>
0020 #include <Standard_Type.hxx>
0021 
0022 class V3d_View;
0023 
0024 //! Auxiliary tool performing continuous redraws of specified window.
0025 //! Tool creates an extra working thread pushing content invalidation messages to specific window using Aspect_Window::InvalidateContent() method.
0026 //! Normally, GUI application should done continuous rendering in simple fashion - just by drawing next frame without waiting for new events from windowing system;
0027 //! however, implementation of this approach is problematic in context of ViewerTest due to message loop binding mechanism implied by Tcl/Tk.
0028 class ViewerTest_ContinuousRedrawer
0029 {
0030 public:
0031   //! Return global instance.
0032   Standard_EXPORT static ViewerTest_ContinuousRedrawer& Instance();
0033 public:
0034 
0035   //! Destructor.
0036   Standard_EXPORT ~ViewerTest_ContinuousRedrawer();
0037 
0038   //! Return TRUE if redrawer thread is started.
0039   bool IsStarted() const { return myThread.GetId() != 0; }
0040 
0041   //! Start thread.
0042   Standard_EXPORT void Start (const Handle(V3d_View)& theView,
0043                               Standard_Real theTargetFps);
0044 
0045   //! Stop thread.
0046   Standard_EXPORT void Stop (const Handle(V3d_View)& theView = NULL);
0047 
0048   //! Return TRUE if redrawer thread is in paused state.
0049   bool IsPaused() const { return myToPause; }
0050 
0051   //! Pause working thread, but does not terminate it.
0052   Standard_EXPORT void Pause();
0053 
0054 private:
0055 
0056   //! Thread loop.
0057   void doThreadLoop();
0058 
0059   //! Thread creation callback.
0060   static Standard_Address doThreadWrapper (Standard_Address theData)
0061   {
0062     ViewerTest_ContinuousRedrawer* aThis = (ViewerTest_ContinuousRedrawer* )theData;
0063     aThis->doThreadLoop();
0064     return 0;
0065   }
0066 
0067   //! Empty constructor.
0068   ViewerTest_ContinuousRedrawer();
0069 
0070 private:
0071   Handle(V3d_View)   myView;      //!< view to invalidate
0072   OSD_Thread         myThread;    //!< working thread
0073   Standard_Mutex     myMutex;     //!< mutex for accessing common variables
0074   Standard_Condition myWakeEvent; //!< event to wake up working thread
0075   Standard_Real      myTargetFps; //!< desired update framerate
0076   volatile bool      myToStop;    //!< flag to stop working thread
0077   volatile bool      myToPause;   //!< flag to put  working thread asleep without stopping
0078 };
0079 
0080 #endif // _ViewerTest_ContinuousRedrawer_HeaderFile