diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -127,6 +127,25 @@ public: return static_cast(*DriverFactoryBase::GetActiveDriver(Driver::DT_VIDEO)); } + /** + * Helper struct to ensure the video buffer is locked and ready for drawing. The destructor + * will make sure the buffer is unlocked no matter how the scope is exited. + */ + struct VideoBufferLocker { + VideoBufferLocker() + { + this->unlock = VideoDriver::GetInstance()->LockVideoBuffer(); + } + + ~VideoBufferLocker() + { + if (this->unlock) VideoDriver::GetInstance()->UnlockVideoBuffer(); + } + + private: + bool unlock; ///< Stores if the lock did anything that has to be undone. + }; + protected: const uint ALLOWED_DRIFT = 5; ///< How many times videodriver can miss deadlines without it being overly compensated.